]> git.saurik.com Git - apple/javascriptcore.git/blob - offlineasm/instructions.rb
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / offlineasm / instructions.rb
1 # Copyright (C) 2011 Apple Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
5 # are met:
6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
13 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
14 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
16 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
22 # THE POSSIBILITY OF SUCH DAMAGE.
23
24 # Interesting invariant, which we take advantage of: branching instructions
25 # always begin with "b", and no non-branching instructions begin with "b".
26 # Terminal instructions are "jmp" and "ret".
27
28 MACRO_INSTRUCTIONS =
29 [
30 "addi",
31 "andi",
32 "lshifti",
33 "lshiftp",
34 "muli",
35 "negi",
36 "negp",
37 "noti",
38 "ori",
39 "rshifti",
40 "urshifti",
41 "rshiftp",
42 "urshiftp",
43 "subi",
44 "xori",
45 "loadi",
46 "loadis",
47 "loadb",
48 "loadbs",
49 "loadh",
50 "loadhs",
51 "storei",
52 "storeb",
53 "loadd",
54 "moved",
55 "stored",
56 "addd",
57 "divd",
58 "subd",
59 "muld",
60 "sqrtd",
61 "ci2d",
62 "fii2d", # usage: fii2d <gpr with least significant bits>, <gpr with most significant bits>, <fpr>
63 "fd2ii", # usage: fd2ii <fpr>, <gpr with least significant bits>, <gpr with most significant bits>
64 "fp2d",
65 "fd2p",
66 "bdeq",
67 "bdneq",
68 "bdgt",
69 "bdgteq",
70 "bdlt",
71 "bdlteq",
72 "bdequn",
73 "bdnequn",
74 "bdgtun",
75 "bdgtequn",
76 "bdltun",
77 "bdltequn",
78 "btd2i",
79 "td2i",
80 "bcd2i",
81 "movdz",
82 "pop",
83 "push",
84 "move",
85 "sxi2p",
86 "zxi2p",
87 "nop",
88 "bieq",
89 "bineq",
90 "bia",
91 "biaeq",
92 "bib",
93 "bibeq",
94 "bigt",
95 "bigteq",
96 "bilt",
97 "bilteq",
98 "bbeq",
99 "bbneq",
100 "bba",
101 "bbaeq",
102 "bbb",
103 "bbbeq",
104 "bbgt",
105 "bbgteq",
106 "bblt",
107 "bblteq",
108 "btio",
109 "btis",
110 "btiz",
111 "btinz",
112 "btbo",
113 "btbs",
114 "btbz",
115 "btbnz",
116 "jmp",
117 "baddio",
118 "baddis",
119 "baddiz",
120 "baddinz",
121 "bsubio",
122 "bsubis",
123 "bsubiz",
124 "bsubinz",
125 "bmulio",
126 "bmulis",
127 "bmuliz",
128 "bmulinz",
129 "borio",
130 "boris",
131 "boriz",
132 "borinz",
133 "break",
134 "call",
135 "ret",
136 "cbeq",
137 "cbneq",
138 "cba",
139 "cbaeq",
140 "cbb",
141 "cbbeq",
142 "cbgt",
143 "cbgteq",
144 "cblt",
145 "cblteq",
146 "cieq",
147 "cineq",
148 "cia",
149 "ciaeq",
150 "cib",
151 "cibeq",
152 "cigt",
153 "cigteq",
154 "cilt",
155 "cilteq",
156 "tio",
157 "tis",
158 "tiz",
159 "tinz",
160 "tbo",
161 "tbs",
162 "tbz",
163 "tbnz",
164 "tpo",
165 "tps",
166 "tpz",
167 "tpnz",
168 "peek",
169 "poke",
170 "bpeq",
171 "bpneq",
172 "bpa",
173 "bpaeq",
174 "bpb",
175 "bpbeq",
176 "bpgt",
177 "bpgteq",
178 "bplt",
179 "bplteq",
180 "addp",
181 "mulp",
182 "andp",
183 "orp",
184 "subp",
185 "xorp",
186 "loadp",
187 "cpeq",
188 "cpneq",
189 "cpa",
190 "cpaeq",
191 "cpb",
192 "cpbeq",
193 "cpgt",
194 "cpgteq",
195 "cplt",
196 "cplteq",
197 "storep",
198 "btpo",
199 "btps",
200 "btpz",
201 "btpnz",
202 "baddpo",
203 "baddps",
204 "baddpz",
205 "baddpnz",
206 "bo",
207 "bs",
208 "bz",
209 "bnz",
210 "leai",
211 "leap",
212 ]
213
214 X86_INSTRUCTIONS =
215 [
216 "cdqi",
217 "idivi"
218 ]
219
220 ARMv7_INSTRUCTIONS =
221 [
222 "smulli",
223 "addis",
224 "subis",
225 "oris"
226 ]
227
228 INSTRUCTIONS = MACRO_INSTRUCTIONS + X86_INSTRUCTIONS + ARMv7_INSTRUCTIONS
229
230 INSTRUCTION_PATTERN = Regexp.new('\\A((' + INSTRUCTIONS.join(')|(') + '))\\Z')
231
232 def isBranch(instruction)
233 instruction =~ /^b/
234 end
235
236 def hasFallThrough(instruction)
237 instruction != "ret" and instruction != "jmp"
238 end
239