blob: 758c17a67245914fd10730c0cd6e58582c3c40d2 [file] [log] [blame]
sewardjec6ad592004-06-20 12:26:53 +00001
2/*---------------------------------------------------------------*/
3/*--- ---*/
sewardjc0ee2ed2004-07-27 10:29:41 +00004/*--- This file (ir/irdefs.c) is ---*/
sewardjdbcfae72005-08-02 11:14:04 +00005/*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/
sewardjec6ad592004-06-20 12:26:53 +00006/*--- ---*/
7/*---------------------------------------------------------------*/
8
sewardjf8ed9d82004-11-12 17:40:23 +00009/*
10 This file is part of LibVEX, a library for dynamic binary
11 instrumentation and translation.
12
sewardja26d8202008-02-11 11:35:40 +000013 Copyright (C) 2004-2008 OpenWorks LLP. All rights reserved.
sewardjf8ed9d82004-11-12 17:40:23 +000014
sewardj7bd6ffe2005-08-03 16:07:36 +000015 This library is made available under a dual licensing scheme.
sewardjf8ed9d82004-11-12 17:40:23 +000016
sewardj7bd6ffe2005-08-03 16:07:36 +000017 If you link LibVEX against other code all of which is itself
18 licensed under the GNU General Public License, version 2 dated June
19 1991 ("GPL v2"), then you may use LibVEX under the terms of the GPL
20 v2, as appearing in the file LICENSE.GPL. If the file LICENSE.GPL
21 is missing, you can obtain a copy of the GPL v2 from the Free
22 Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 02110-1301, USA.
24
25 For any other uses of LibVEX, you must first obtain a commercial
26 license from OpenWorks LLP. Please contact info@open-works.co.uk
27 for information about commercial licensing.
28
29 This software is provided by OpenWorks LLP "as is" and any express
30 or implied warranties, including, but not limited to, the implied
31 warranties of merchantability and fitness for a particular purpose
32 are disclaimed. In no event shall OpenWorks LLP be liable for any
33 direct, indirect, incidental, special, exemplary, or consequential
34 damages (including, but not limited to, procurement of substitute
35 goods or services; loss of use, data, or profits; or business
36 interruption) however caused and on any theory of liability,
37 whether in contract, strict liability, or tort (including
38 negligence or otherwise) arising in any way out of the use of this
39 software, even if advised of the possibility of such damage.
sewardjf8ed9d82004-11-12 17:40:23 +000040
41 Neither the names of the U.S. Department of Energy nor the
42 University of California nor the names of its contributors may be
43 used to endorse or promote products derived from this software
44 without prior written permission.
sewardjf8ed9d82004-11-12 17:40:23 +000045*/
46
sewardj887a11a2004-07-05 17:26:47 +000047#include "libvex_basictypes.h"
48#include "libvex_ir.h"
49#include "libvex.h"
sewardjec6ad592004-06-20 12:26:53 +000050
sewardjc0ee2ed2004-07-27 10:29:41 +000051#include "main/vex_util.h"
52
sewardjec6ad592004-06-20 12:26:53 +000053
54/*---------------------------------------------------------------*/
55/*--- Printing the IR ---*/
56/*---------------------------------------------------------------*/
57
sewardj35421a32004-07-05 13:12:34 +000058void ppIRType ( IRType ty )
sewardjec6ad592004-06-20 12:26:53 +000059{
sewardj3e838932005-01-07 12:09:15 +000060 switch (ty) {
61 case Ity_INVALID: vex_printf("Ity_INVALID"); break;
sewardj9b967672005-02-08 11:13:09 +000062 case Ity_I1: vex_printf( "I1"); break;
63 case Ity_I8: vex_printf( "I8"); break;
64 case Ity_I16: vex_printf( "I16"); break;
65 case Ity_I32: vex_printf( "I32"); break;
66 case Ity_I64: vex_printf( "I64"); break;
67 case Ity_I128: vex_printf( "I128"); break;
68 case Ity_F32: vex_printf( "F32"); break;
69 case Ity_F64: vex_printf( "F64"); break;
sewardj3e838932005-01-07 12:09:15 +000070 case Ity_V128: vex_printf( "V128"); break;
71 default: vex_printf("ty = 0x%x\n", (Int)ty);
72 vpanic("ppIRType");
73 }
sewardjec6ad592004-06-20 12:26:53 +000074}
75
sewardj35421a32004-07-05 13:12:34 +000076void ppIRConst ( IRConst* con )
sewardjec6ad592004-06-20 12:26:53 +000077{
sewardja162c2c2005-12-18 03:07:11 +000078 union { ULong i64; Double f64; } u;
sewardj63327402006-01-25 03:26:27 +000079 vassert(sizeof(ULong) == sizeof(Double));
sewardj2d3f77c2004-09-22 23:49:09 +000080 switch (con->tag) {
sewardjba999312004-11-15 15:21:17 +000081 case Ico_U1: vex_printf( "%d:I1", con->Ico.U1 ? 1 : 0); break;
sewardj2d3f77c2004-09-22 23:49:09 +000082 case Ico_U8: vex_printf( "0x%x:I8", (UInt)(con->Ico.U8)); break;
83 case Ico_U16: vex_printf( "0x%x:I16", (UInt)(con->Ico.U16)); break;
84 case Ico_U32: vex_printf( "0x%x:I32", (UInt)(con->Ico.U32)); break;
85 case Ico_U64: vex_printf( "0x%llx:I64", (ULong)(con->Ico.U64)); break;
sewardja162c2c2005-12-18 03:07:11 +000086 case Ico_F64: u.f64 = con->Ico.F64;
87 vex_printf( "F64{0x%llx}", u.i64);
sewardj695cff92004-10-13 14:50:14 +000088 break;
sewardj2d3f77c2004-09-22 23:49:09 +000089 case Ico_F64i: vex_printf( "F64i{0x%llx}", con->Ico.F64i); break;
sewardj1e6ad742004-12-02 16:16:11 +000090 case Ico_V128: vex_printf( "V128{0x%04x}", (UInt)(con->Ico.V128)); break;
sewardj2d3f77c2004-09-22 23:49:09 +000091 default: vpanic("ppIRConst");
92 }
93}
94
sewardj8ea867b2004-10-30 19:03:02 +000095void ppIRCallee ( IRCallee* ce )
96{
97 vex_printf("%s", ce->name);
sewardj77352542004-10-30 20:39:01 +000098 if (ce->regparms > 0)
sewardj43c56462004-11-06 12:17:57 +000099 vex_printf("[rp=%d]", ce->regparms);
100 if (ce->mcx_mask > 0)
101 vex_printf("[mcx=0x%x]", ce->mcx_mask);
sewardj8ea867b2004-10-30 19:03:02 +0000102 vex_printf("{%p}", (void*)ce->addr);
103}
104
sewardjdd40fdf2006-12-24 02:20:24 +0000105void ppIRRegArray ( IRRegArray* arr )
sewardj2d3f77c2004-09-22 23:49:09 +0000106{
sewardj0bfea7f2004-10-04 07:15:48 +0000107 vex_printf("(%d:%dx", arr->base, arr->nElems);
sewardj2d3f77c2004-09-22 23:49:09 +0000108 ppIRType(arr->elemTy);
sewardj0bfea7f2004-10-04 07:15:48 +0000109 vex_printf(")");
sewardje3d0d2e2004-06-27 10:42:44 +0000110}
111
sewardj35421a32004-07-05 13:12:34 +0000112void ppIRTemp ( IRTemp tmp )
sewardje3d0d2e2004-06-27 10:42:44 +0000113{
sewardj92d168d2004-11-15 14:22:12 +0000114 if (tmp == IRTemp_INVALID)
115 vex_printf("IRTemp_INVALID");
sewardjfbcaf332004-07-08 01:46:01 +0000116 else
sewardj41f43bc2004-07-08 14:23:22 +0000117 vex_printf( "t%d", (Int)tmp);
sewardje3d0d2e2004-06-27 10:42:44 +0000118}
119
sewardj35421a32004-07-05 13:12:34 +0000120void ppIROp ( IROp op )
sewardje3d0d2e2004-06-27 10:42:44 +0000121{
sewardjecbaee72008-11-01 23:54:45 +0000122 HChar* str = NULL;
sewardja98bf492005-02-07 01:39:17 +0000123 IROp base;
sewardj41f43bc2004-07-08 14:23:22 +0000124 switch (op) {
125 case Iop_Add8 ... Iop_Add64:
126 str = "Add"; base = Iop_Add8; break;
127 case Iop_Sub8 ... Iop_Sub64:
128 str = "Sub"; base = Iop_Sub8; break;
129 case Iop_Mul8 ... Iop_Mul64:
130 str = "Mul"; base = Iop_Mul8; break;
131 case Iop_Or8 ... Iop_Or64:
132 str = "Or"; base = Iop_Or8; break;
133 case Iop_And8 ... Iop_And64:
134 str = "And"; base = Iop_And8; break;
135 case Iop_Xor8 ... Iop_Xor64:
136 str = "Xor"; base = Iop_Xor8; break;
137 case Iop_Shl8 ... Iop_Shl64:
138 str = "Shl"; base = Iop_Shl8; break;
139 case Iop_Shr8 ... Iop_Shr64:
140 str = "Shr"; base = Iop_Shr8; break;
141 case Iop_Sar8 ... Iop_Sar64:
142 str = "Sar"; base = Iop_Sar8; break;
sewardje90ad6a2004-07-10 19:02:10 +0000143 case Iop_CmpEQ8 ... Iop_CmpEQ64:
144 str = "CmpEQ"; base = Iop_CmpEQ8; break;
145 case Iop_CmpNE8 ... Iop_CmpNE64:
146 str = "CmpNE"; base = Iop_CmpNE8; break;
sewardj41f43bc2004-07-08 14:23:22 +0000147 case Iop_Not8 ... Iop_Not64:
148 str = "Not"; base = Iop_Not8; break;
149 /* other cases must explicitly "return;" */
sewardj9690d922004-07-14 01:39:17 +0000150 case Iop_8Uto16: vex_printf("8Uto16"); return;
151 case Iop_8Uto32: vex_printf("8Uto32"); return;
152 case Iop_16Uto32: vex_printf("16Uto32"); return;
153 case Iop_8Sto16: vex_printf("8Sto16"); return;
154 case Iop_8Sto32: vex_printf("8Sto32"); return;
155 case Iop_16Sto32: vex_printf("16Sto32"); return;
sewardjbb53f8c2004-08-14 11:50:01 +0000156 case Iop_32Sto64: vex_printf("32Sto64"); return;
sewardje5427e82004-09-11 19:43:51 +0000157 case Iop_32Uto64: vex_printf("32Uto64"); return;
sewardja2384712004-07-29 14:36:40 +0000158 case Iop_32to8: vex_printf("32to8"); return;
sewardj291a7e82005-04-27 11:42:44 +0000159 case Iop_16Uto64: vex_printf("16Uto64"); return;
160 case Iop_16Sto64: vex_printf("16Sto64"); return;
161 case Iop_8Uto64: vex_printf("8Uto64"); return;
162 case Iop_8Sto64: vex_printf("8Sto64"); return;
163 case Iop_64to16: vex_printf("64to16"); return;
164 case Iop_64to8: vex_printf("64to8"); return;
sewardj6e797c52004-10-13 15:20:17 +0000165
166 case Iop_Not1: vex_printf("Not1"); return;
sewardj9690d922004-07-14 01:39:17 +0000167 case Iop_32to1: vex_printf("32to1"); return;
sewardj291a7e82005-04-27 11:42:44 +0000168 case Iop_64to1: vex_printf("64to1"); return;
sewardj9690d922004-07-14 01:39:17 +0000169 case Iop_1Uto8: vex_printf("1Uto8"); return;
sewardj84ff0652004-08-23 16:16:08 +0000170 case Iop_1Uto32: vex_printf("1Uto32"); return;
sewardj291a7e82005-04-27 11:42:44 +0000171 case Iop_1Uto64: vex_printf("1Uto64"); return;
sewardjfd332772004-11-09 16:01:40 +0000172 case Iop_1Sto8: vex_printf("1Sto8"); return;
sewardj8eda6302004-11-05 01:55:46 +0000173 case Iop_1Sto16: vex_printf("1Sto16"); return;
sewardj415d9352004-11-04 15:20:15 +0000174 case Iop_1Sto32: vex_printf("1Sto32"); return;
sewardjb5874aa2004-11-04 16:57:50 +0000175 case Iop_1Sto64: vex_printf("1Sto64"); return;
sewardj9690d922004-07-14 01:39:17 +0000176
177 case Iop_MullS8: vex_printf("MullS8"); return;
178 case Iop_MullS16: vex_printf("MullS16"); return;
179 case Iop_MullS32: vex_printf("MullS32"); return;
sewardj9b967672005-02-08 11:13:09 +0000180 case Iop_MullS64: vex_printf("MullS64"); return;
sewardj9690d922004-07-14 01:39:17 +0000181 case Iop_MullU8: vex_printf("MullU8"); return;
182 case Iop_MullU16: vex_printf("MullU16"); return;
183 case Iop_MullU32: vex_printf("MullU32"); return;
sewardj9b967672005-02-08 11:13:09 +0000184 case Iop_MullU64: vex_printf("MullU64"); return;
sewardj9690d922004-07-14 01:39:17 +0000185
sewardjf53b7352005-04-06 20:01:56 +0000186 case Iop_Clz64: vex_printf("Clz64"); return;
sewardjce646f22004-08-31 23:55:54 +0000187 case Iop_Clz32: vex_printf("Clz32"); return;
sewardjf53b7352005-04-06 20:01:56 +0000188 case Iop_Ctz64: vex_printf("Ctz64"); return;
sewardjce646f22004-08-31 23:55:54 +0000189 case Iop_Ctz32: vex_printf("Ctz32"); return;
190
sewardj84ff0652004-08-23 16:16:08 +0000191 case Iop_CmpLT32S: vex_printf("CmpLT32S"); return;
192 case Iop_CmpLE32S: vex_printf("CmpLE32S"); return;
193 case Iop_CmpLT32U: vex_printf("CmpLT32U"); return;
194 case Iop_CmpLE32U: vex_printf("CmpLE32U"); return;
195
sewardj98540072005-04-26 01:52:01 +0000196 case Iop_CmpLT64S: vex_printf("CmpLT64S"); return;
197 case Iop_CmpLE64S: vex_printf("CmpLE64S"); return;
198 case Iop_CmpLT64U: vex_printf("CmpLT64U"); return;
199 case Iop_CmpLE64U: vex_printf("CmpLE64U"); return;
200
sewardj0033ddc2005-04-26 23:34:34 +0000201 case Iop_CmpNEZ8: vex_printf("CmpNEZ8"); return;
202 case Iop_CmpNEZ16: vex_printf("CmpNEZ16"); return;
203 case Iop_CmpNEZ32: vex_printf("CmpNEZ32"); return;
204 case Iop_CmpNEZ64: vex_printf("CmpNEZ64"); return;
205
sewardjeb17e492007-08-25 23:07:44 +0000206 case Iop_CmpwNEZ32: vex_printf("CmpwNEZ32"); return;
207 case Iop_CmpwNEZ64: vex_printf("CmpwNEZ64"); return;
208
209 case Iop_Left8: vex_printf("Left8"); return;
210 case Iop_Left16: vex_printf("Left16"); return;
211 case Iop_Left32: vex_printf("Left32"); return;
212 case Iop_Left64: vex_printf("Left64"); return;
sewardj478646f2008-05-01 20:13:04 +0000213 case Iop_Max32U: vex_printf("Max32U"); return;
sewardjeb17e492007-08-25 23:07:44 +0000214
sewardjb51f0f42005-07-18 11:38:02 +0000215 case Iop_CmpORD32U: vex_printf("CmpORD32U"); return;
216 case Iop_CmpORD32S: vex_printf("CmpORD32S"); return;
217
cerion2831b002005-11-30 19:55:22 +0000218 case Iop_CmpORD64U: vex_printf("CmpORD64U"); return;
219 case Iop_CmpORD64S: vex_printf("CmpORD64S"); return;
220
cerion5c8a0cb2005-02-03 13:59:46 +0000221 case Iop_DivU32: vex_printf("DivU32"); return;
222 case Iop_DivS32: vex_printf("DivS32"); return;
cerionf0de28c2005-12-13 20:21:11 +0000223 case Iop_DivU64: vex_printf("DivU64"); return;
224 case Iop_DivS64: vex_printf("DivS64"); return;
cerion5c8a0cb2005-02-03 13:59:46 +0000225
sewardj9690d922004-07-14 01:39:17 +0000226 case Iop_DivModU64to32: vex_printf("DivModU64to32"); return;
227 case Iop_DivModS64to32: vex_printf("DivModS64to32"); return;
228
sewardj343b9d02005-01-31 18:08:45 +0000229 case Iop_DivModU128to64: vex_printf("DivModU128to64"); return;
230 case Iop_DivModS128to64: vex_printf("DivModS128to64"); return;
231
sewardjb81f8b32004-07-30 10:17:50 +0000232 case Iop_16HIto8: vex_printf("16HIto8"); return;
233 case Iop_16to8: vex_printf("16to8"); return;
234 case Iop_8HLto16: vex_printf("8HLto16"); return;
235
sewardj8c7f1ab2004-07-29 20:31:09 +0000236 case Iop_32HIto16: vex_printf("32HIto16"); return;
237 case Iop_32to16: vex_printf("32to16"); return;
238 case Iop_16HLto32: vex_printf("16HLto32"); return;
239
sewardj9690d922004-07-14 01:39:17 +0000240 case Iop_64HIto32: vex_printf("64HIto32"); return;
sewardj8c7f1ab2004-07-29 20:31:09 +0000241 case Iop_64to32: vex_printf("64to32"); return;
sewardj9690d922004-07-14 01:39:17 +0000242 case Iop_32HLto64: vex_printf("32HLto64"); return;
243
sewardj9b967672005-02-08 11:13:09 +0000244 case Iop_128HIto64: vex_printf("128HIto64"); return;
245 case Iop_128to64: vex_printf("128to64"); return;
246 case Iop_64HLto128: vex_printf("64HLto128"); return;
247
sewardjcfded9a2004-09-09 11:44:16 +0000248 case Iop_AddF64: vex_printf("AddF64"); return;
249 case Iop_SubF64: vex_printf("SubF64"); return;
250 case Iop_MulF64: vex_printf("MulF64"); return;
251 case Iop_DivF64: vex_printf("DivF64"); return;
sewardjb183b852006-02-03 16:08:03 +0000252 case Iop_AddF64r32: vex_printf("AddF64r32"); return;
253 case Iop_SubF64r32: vex_printf("SubF64r32"); return;
254 case Iop_MulF64r32: vex_printf("MulF64r32"); return;
255 case Iop_DivF64r32: vex_printf("DivF64r32"); return;
sewardj46de4072004-09-11 19:23:24 +0000256
sewardj442d0be2004-10-15 22:57:13 +0000257 case Iop_ScaleF64: vex_printf("ScaleF64"); return;
258 case Iop_AtanF64: vex_printf("AtanF64"); return;
259 case Iop_Yl2xF64: vex_printf("Yl2xF64"); return;
260 case Iop_Yl2xp1F64: vex_printf("Yl2xp1F64"); return;
261 case Iop_PRemF64: vex_printf("PRemF64"); return;
262 case Iop_PRemC3210F64: vex_printf("PRemC3210F64"); return;
263 case Iop_PRem1F64: vex_printf("PRem1F64"); return;
264 case Iop_PRem1C3210F64: vex_printf("PRem1C3210F64"); return;
265 case Iop_NegF64: vex_printf("NegF64"); return;
266 case Iop_SqrtF64: vex_printf("SqrtF64"); return;
sewardj46de4072004-09-11 19:23:24 +0000267
sewardj883b00b2004-09-11 09:30:24 +0000268 case Iop_AbsF64: vex_printf("AbsF64"); return;
sewardjcfded9a2004-09-09 11:44:16 +0000269 case Iop_SinF64: vex_printf("SinF64"); return;
270 case Iop_CosF64: vex_printf("CosF64"); return;
sewardj99016a72004-10-15 22:09:17 +0000271 case Iop_TanF64: vex_printf("TanF64"); return;
sewardj06c32a02004-09-12 12:07:34 +0000272 case Iop_2xm1F64: vex_printf("2xm1F64"); return;
sewardjbdc7d212004-09-09 02:46:40 +0000273
sewardj40c80262006-02-08 19:30:46 +0000274 case Iop_MAddF64: vex_printf("MAddF64"); return;
275 case Iop_MSubF64: vex_printf("MSubF64"); return;
276 case Iop_MAddF64r32: vex_printf("MAddF64r32"); return;
277 case Iop_MSubF64r32: vex_printf("MSubF64r32"); return;
278
279 case Iop_Est5FRSqrt: vex_printf("Est5FRSqrt"); return;
sewardj0f1ef862008-08-08 08:37:06 +0000280 case Iop_RoundF64toF64_NEAREST: vex_printf("RoundF64toF64_NEAREST"); return;
281 case Iop_RoundF64toF64_NegINF: vex_printf("RoundF64toF64_NegINF"); return;
282 case Iop_RoundF64toF64_PosINF: vex_printf("RoundF64toF64_PosINF"); return;
283 case Iop_RoundF64toF64_ZERO: vex_printf("RoundF64toF64_ZERO"); return;
284
sewardjb183b852006-02-03 16:08:03 +0000285 case Iop_TruncF64asF32: vex_printf("TruncF64asF32"); return;
sewardja0e3d422007-08-28 06:06:57 +0000286 case Iop_CalcFPRF: vex_printf("CalcFPRF"); return;
sewardjbaf971a2006-01-27 15:09:35 +0000287
sewardj46de4072004-09-11 19:23:24 +0000288 case Iop_CmpF64: vex_printf("CmpF64"); return;
289
sewardj3bca9062004-12-04 14:36:09 +0000290 case Iop_F64toI16: vex_printf("F64toI16"); return;
291 case Iop_F64toI32: vex_printf("F64toI32"); return;
292 case Iop_F64toI64: vex_printf("F64toI64"); return;
293
294 case Iop_I16toF64: vex_printf("I16toF64"); return;
sewardj89cd0932004-09-08 18:23:25 +0000295 case Iop_I32toF64: vex_printf("I32toF64"); return;
sewardjbdc7d212004-09-09 02:46:40 +0000296 case Iop_I64toF64: vex_printf("I64toF64"); return;
sewardjcfded9a2004-09-09 11:44:16 +0000297
sewardj89cd0932004-09-08 18:23:25 +0000298 case Iop_F32toF64: vex_printf("F32toF64"); return;
299 case Iop_F64toF32: vex_printf("F64toF32"); return;
sewardjbb53f8c2004-08-14 11:50:01 +0000300
sewardjb183b852006-02-03 16:08:03 +0000301 case Iop_RoundF64toInt: vex_printf("RoundF64toInt"); return;
302 case Iop_RoundF64toF32: vex_printf("RoundF64toF32"); return;
sewardj3bca9062004-12-04 14:36:09 +0000303
sewardj17442fe2004-09-20 14:54:28 +0000304 case Iop_ReinterpF64asI64: vex_printf("ReinterpF64asI64"); return;
305 case Iop_ReinterpI64asF64: vex_printf("ReinterpI64asF64"); return;
sewardjfc1b5412007-01-09 15:20:07 +0000306 case Iop_ReinterpF32asI32: vex_printf("ReinterpF32asI32"); return;
sewardjfd226452004-12-07 19:02:18 +0000307 case Iop_ReinterpI32asF32: vex_printf("ReinterpI32asF32"); return;
sewardj17442fe2004-09-20 14:54:28 +0000308
sewardj228c7c82008-07-29 09:47:21 +0000309 case Iop_I32UtoFx4: vex_printf("I32UtoFx4"); return;
310 case Iop_I32StoFx4: vex_printf("I32StoFx4"); return;
cerionf294eb32005-11-16 17:21:10 +0000311
sewardj228c7c82008-07-29 09:47:21 +0000312 case Iop_QFtoI32Ux4_RZ: vex_printf("QFtoI32Ux4_RZ"); return;
313 case Iop_QFtoI32Sx4_RZ: vex_printf("QFtoI32Sx4_RZ"); return;
cerionf294eb32005-11-16 17:21:10 +0000314
sewardj228c7c82008-07-29 09:47:21 +0000315 case Iop_RoundF32x4_RM: vex_printf("RoundF32x4_RM"); return;
316 case Iop_RoundF32x4_RP: vex_printf("RoundF32x4_RP"); return;
317 case Iop_RoundF32x4_RN: vex_printf("RoundF32x4_RN"); return;
318 case Iop_RoundF32x4_RZ: vex_printf("RoundF32x4_RZ"); return;
cerionf294eb32005-11-16 17:21:10 +0000319
sewardj38a3f862005-01-13 15:06:51 +0000320 case Iop_Add8x8: vex_printf("Add8x8"); return;
321 case Iop_Add16x4: vex_printf("Add16x4"); return;
322 case Iop_Add32x2: vex_printf("Add32x2"); return;
323 case Iop_QAdd8Ux8: vex_printf("QAdd8Ux8"); return;
324 case Iop_QAdd16Ux4: vex_printf("QAdd16Ux4"); return;
325 case Iop_QAdd8Sx8: vex_printf("QAdd8Sx8"); return;
326 case Iop_QAdd16Sx4: vex_printf("QAdd16Sx4"); return;
327 case Iop_Sub8x8: vex_printf("Sub8x8"); return;
328 case Iop_Sub16x4: vex_printf("Sub16x4"); return;
329 case Iop_Sub32x2: vex_printf("Sub32x2"); return;
330 case Iop_QSub8Ux8: vex_printf("QSub8Ux8"); return;
331 case Iop_QSub16Ux4: vex_printf("QSub16Ux4"); return;
332 case Iop_QSub8Sx8: vex_printf("QSub8Sx8"); return;
333 case Iop_QSub16Sx4: vex_printf("QSub16Sx4"); return;
334 case Iop_Mul16x4: vex_printf("Mul16x4"); return;
sewardjd166e282008-02-06 11:42:45 +0000335 case Iop_Mul32x2: vex_printf("Mul32x2"); return;
sewardj38a3f862005-01-13 15:06:51 +0000336 case Iop_MulHi16Ux4: vex_printf("MulHi16Ux4"); return;
337 case Iop_MulHi16Sx4: vex_printf("MulHi16Sx4"); return;
338 case Iop_Avg8Ux8: vex_printf("Avg8Ux8"); return;
339 case Iop_Avg16Ux4: vex_printf("Avg16Ux4"); return;
340 case Iop_Max16Sx4: vex_printf("Max16Sx4"); return;
341 case Iop_Max8Ux8: vex_printf("Max8Ux8"); return;
342 case Iop_Min16Sx4: vex_printf("Min16Sx4"); return;
343 case Iop_Min8Ux8: vex_printf("Min8Ux8"); return;
344 case Iop_CmpEQ8x8: vex_printf("CmpEQ8x8"); return;
345 case Iop_CmpEQ16x4: vex_printf("CmpEQ16x4"); return;
346 case Iop_CmpEQ32x2: vex_printf("CmpEQ32x2"); return;
347 case Iop_CmpGT8Sx8: vex_printf("CmpGT8Sx8"); return;
348 case Iop_CmpGT16Sx4: vex_printf("CmpGT16Sx4"); return;
349 case Iop_CmpGT32Sx2: vex_printf("CmpGT32Sx2"); return;
sewardjd166e282008-02-06 11:42:45 +0000350 case Iop_ShlN8x8: vex_printf("ShlN8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000351 case Iop_ShlN16x4: vex_printf("ShlN16x4"); return;
352 case Iop_ShlN32x2: vex_printf("ShlN32x2"); return;
353 case Iop_ShrN16x4: vex_printf("ShrN16x4"); return;
354 case Iop_ShrN32x2: vex_printf("ShrN32x2"); return;
sewardjd71ba832006-12-27 01:15:29 +0000355 case Iop_SarN8x8: vex_printf("SarN8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000356 case Iop_SarN16x4: vex_printf("SarN16x4"); return;
357 case Iop_SarN32x2: vex_printf("SarN32x2"); return;
358 case Iop_QNarrow16Ux4: vex_printf("QNarrow16Ux4"); return;
359 case Iop_QNarrow16Sx4: vex_printf("QNarrow16Sx4"); return;
360 case Iop_QNarrow32Sx2: vex_printf("QNarrow32Sx2"); return;
361 case Iop_InterleaveHI8x8: vex_printf("InterleaveHI8x8"); return;
362 case Iop_InterleaveHI16x4: vex_printf("InterleaveHI16x4"); return;
363 case Iop_InterleaveHI32x2: vex_printf("InterleaveHI32x2"); return;
364 case Iop_InterleaveLO8x8: vex_printf("InterleaveLO8x8"); return;
365 case Iop_InterleaveLO16x4: vex_printf("InterleaveLO16x4"); return;
366 case Iop_InterleaveLO32x2: vex_printf("InterleaveLO32x2"); return;
sewardjd166e282008-02-06 11:42:45 +0000367 case Iop_CatOddLanes16x4: vex_printf("CatOddLanes16x4"); return;
368 case Iop_CatEvenLanes16x4: vex_printf("CatEvenLanes16x4"); return;
sewardj228c7c82008-07-29 09:47:21 +0000369 case Iop_Perm8x8: vex_printf("Perm8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000370
sewardj18069182005-01-13 19:16:04 +0000371 case Iop_CmpNEZ32x2: vex_printf("CmpNEZ32x2"); return;
372 case Iop_CmpNEZ16x4: vex_printf("CmpNEZ16x4"); return;
373 case Iop_CmpNEZ8x8: vex_printf("CmpNEZ8x8"); return;
374
sewardj1e6ad742004-12-02 16:16:11 +0000375 case Iop_Add32Fx4: vex_printf("Add32Fx4"); return;
376 case Iop_Add32F0x4: vex_printf("Add32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000377 case Iop_Add64Fx2: vex_printf("Add64Fx2"); return;
378 case Iop_Add64F0x2: vex_printf("Add64F0x2"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000379
sewardj176a59c2004-12-03 20:08:31 +0000380 case Iop_Div32Fx4: vex_printf("Div32Fx4"); return;
381 case Iop_Div32F0x4: vex_printf("Div32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000382 case Iop_Div64Fx2: vex_printf("Div64Fx2"); return;
383 case Iop_Div64F0x2: vex_printf("Div64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000384
385 case Iop_Max32Fx4: vex_printf("Max32Fx4"); return;
386 case Iop_Max32F0x4: vex_printf("Max32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000387 case Iop_Max64Fx2: vex_printf("Max64Fx2"); return;
388 case Iop_Max64F0x2: vex_printf("Max64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000389
390 case Iop_Min32Fx4: vex_printf("Min32Fx4"); return;
391 case Iop_Min32F0x4: vex_printf("Min32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000392 case Iop_Min64Fx2: vex_printf("Min64Fx2"); return;
393 case Iop_Min64F0x2: vex_printf("Min64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000394
sewardj9636b442004-12-04 01:38:37 +0000395 case Iop_Mul32Fx4: vex_printf("Mul32Fx4"); return;
396 case Iop_Mul32F0x4: vex_printf("Mul32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000397 case Iop_Mul64Fx2: vex_printf("Mul64Fx2"); return;
398 case Iop_Mul64F0x2: vex_printf("Mul64F0x2"); return;
sewardj9636b442004-12-04 01:38:37 +0000399
sewardj0bd7ce62004-12-05 02:47:40 +0000400 case Iop_Recip32Fx4: vex_printf("Recip32Fx4"); return;
401 case Iop_Recip32F0x4: vex_printf("Recip32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000402 case Iop_Recip64Fx2: vex_printf("Recip64Fx2"); return;
403 case Iop_Recip64F0x2: vex_printf("Recip64F0x2"); return;
sewardj0bd7ce62004-12-05 02:47:40 +0000404
sewardjc1e7dfc2004-12-05 19:29:45 +0000405 case Iop_RSqrt32Fx4: vex_printf("RSqrt32Fx4"); return;
406 case Iop_RSqrt32F0x4: vex_printf("RSqrt32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000407 case Iop_RSqrt64Fx2: vex_printf("RSqrt64Fx2"); return;
408 case Iop_RSqrt64F0x2: vex_printf("RSqrt64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000409
sewardj636ad762004-12-07 11:16:04 +0000410 case Iop_Sqrt32Fx4: vex_printf("Sqrt32Fx4"); return;
411 case Iop_Sqrt32F0x4: vex_printf("Sqrt32F0x4"); return;
412 case Iop_Sqrt64Fx2: vex_printf("Sqrt64Fx2"); return;
413 case Iop_Sqrt64F0x2: vex_printf("Sqrt64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000414
415 case Iop_Sub32Fx4: vex_printf("Sub32Fx4"); return;
416 case Iop_Sub32F0x4: vex_printf("Sub32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000417 case Iop_Sub64Fx2: vex_printf("Sub64Fx2"); return;
418 case Iop_Sub64F0x2: vex_printf("Sub64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000419
sewardj1e6ad742004-12-02 16:16:11 +0000420 case Iop_CmpEQ32Fx4: vex_printf("CmpEQ32Fx4"); return;
421 case Iop_CmpLT32Fx4: vex_printf("CmpLT32Fx4"); return;
422 case Iop_CmpLE32Fx4: vex_printf("CmpLE32Fx4"); return;
cerion206c3642005-11-14 00:35:59 +0000423 case Iop_CmpGT32Fx4: vex_printf("CmpGT32Fx4"); return;
424 case Iop_CmpGE32Fx4: vex_printf("CmpGE32Fx4"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000425 case Iop_CmpUN32Fx4: vex_printf("CmpUN32Fx4"); return;
sewardj636ad762004-12-07 11:16:04 +0000426 case Iop_CmpEQ64Fx2: vex_printf("CmpEQ64Fx2"); return;
427 case Iop_CmpLT64Fx2: vex_printf("CmpLT64Fx2"); return;
428 case Iop_CmpLE64Fx2: vex_printf("CmpLE64Fx2"); return;
429 case Iop_CmpUN64Fx2: vex_printf("CmpUN64Fx2"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000430
431 case Iop_CmpEQ32F0x4: vex_printf("CmpEQ32F0x4"); return;
432 case Iop_CmpLT32F0x4: vex_printf("CmpLT32F0x4"); return;
433 case Iop_CmpLE32F0x4: vex_printf("CmpLE32F0x4"); return;
434 case Iop_CmpUN32F0x4: vex_printf("CmpUN32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000435 case Iop_CmpEQ64F0x2: vex_printf("CmpEQ64F0x2"); return;
436 case Iop_CmpLT64F0x2: vex_printf("CmpLT64F0x2"); return;
437 case Iop_CmpLE64F0x2: vex_printf("CmpLE64F0x2"); return;
438 case Iop_CmpUN64F0x2: vex_printf("CmpUN64F0x2"); return;
sewardjc9a43662004-11-30 18:51:59 +0000439
sewardjf0c1c582005-02-07 23:47:38 +0000440 case Iop_V128to64: vex_printf("V128to64"); return;
441 case Iop_V128HIto64: vex_printf("V128HIto64"); return;
442 case Iop_64HLtoV128: vex_printf("64HLtoV128"); return;
sewardja0037df2004-12-10 18:56:29 +0000443
sewardjf0c1c582005-02-07 23:47:38 +0000444 case Iop_64UtoV128: vex_printf("64UtoV128"); return;
445 case Iop_SetV128lo64: vex_printf("SetV128lo64"); return;
sewardjc9a43662004-11-30 18:51:59 +0000446
sewardjf0c1c582005-02-07 23:47:38 +0000447 case Iop_32UtoV128: vex_printf("32UtoV128"); return;
448 case Iop_V128to32: vex_printf("V128to32"); return;
449 case Iop_SetV128lo32: vex_printf("SetV128lo32"); return;
sewardj129b3d92004-12-05 15:42:05 +0000450
cerionf887b3e2005-09-13 16:34:28 +0000451 case Iop_Dup8x16: vex_printf("Dup8x16"); return;
452 case Iop_Dup16x8: vex_printf("Dup16x8"); return;
453 case Iop_Dup32x4: vex_printf("Dup32x4"); return;
454
sewardjf0c1c582005-02-07 23:47:38 +0000455 case Iop_NotV128: vex_printf("NotV128"); return;
456 case Iop_AndV128: vex_printf("AndV128"); return;
457 case Iop_OrV128: vex_printf("OrV128"); return;
458 case Iop_XorV128: vex_printf("XorV128"); return;
sewardj18069182005-01-13 19:16:04 +0000459
sewardj2e383862004-12-12 16:46:47 +0000460 case Iop_CmpNEZ8x16: vex_printf("CmpNEZ8x16"); return;
461 case Iop_CmpNEZ16x8: vex_printf("CmpNEZ16x8"); return;
sewardj70f676d2004-12-10 14:59:57 +0000462 case Iop_CmpNEZ32x4: vex_printf("CmpNEZ32x4"); return;
sewardj109ffdb2004-12-10 21:45:38 +0000463 case Iop_CmpNEZ64x2: vex_printf("CmpNEZ64x2"); return;
sewardj164f9272004-12-09 00:39:32 +0000464
465 case Iop_Add8x16: vex_printf("Add8x16"); return;
466 case Iop_Add16x8: vex_printf("Add16x8"); return;
467 case Iop_Add32x4: vex_printf("Add32x4"); return;
468 case Iop_Add64x2: vex_printf("Add64x2"); return;
469 case Iop_QAdd8Ux16: vex_printf("QAdd8Ux16"); return;
470 case Iop_QAdd16Ux8: vex_printf("QAdd16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000471 case Iop_QAdd32Ux4: vex_printf("QAdd32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000472 case Iop_QAdd8Sx16: vex_printf("QAdd8Sx16"); return;
473 case Iop_QAdd16Sx8: vex_printf("QAdd16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000474 case Iop_QAdd32Sx4: vex_printf("QAdd32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000475
476 case Iop_Sub8x16: vex_printf("Sub8x16"); return;
477 case Iop_Sub16x8: vex_printf("Sub16x8"); return;
478 case Iop_Sub32x4: vex_printf("Sub32x4"); return;
479 case Iop_Sub64x2: vex_printf("Sub64x2"); return;
480 case Iop_QSub8Ux16: vex_printf("QSub8Ux16"); return;
481 case Iop_QSub16Ux8: vex_printf("QSub16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000482 case Iop_QSub32Ux4: vex_printf("QSub32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000483 case Iop_QSub8Sx16: vex_printf("QSub8Sx16"); return;
484 case Iop_QSub16Sx8: vex_printf("QSub16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000485 case Iop_QSub32Sx4: vex_printf("QSub32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000486
487 case Iop_Mul16x8: vex_printf("Mul16x8"); return;
488 case Iop_MulHi16Ux8: vex_printf("MulHi16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000489 case Iop_MulHi32Ux4: vex_printf("MulHi32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000490 case Iop_MulHi16Sx8: vex_printf("MulHi16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000491 case Iop_MulHi32Sx4: vex_printf("MulHi32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000492
cerion1ac656a2005-11-04 19:44:48 +0000493 case Iop_MullEven8Ux16: vex_printf("MullEven8Ux16"); return;
494 case Iop_MullEven16Ux8: vex_printf("MullEven16Ux8"); return;
495 case Iop_MullEven8Sx16: vex_printf("MullEven8Sx16"); return;
496 case Iop_MullEven16Sx8: vex_printf("MullEven16Sx8"); return;
497
sewardj164f9272004-12-09 00:39:32 +0000498 case Iop_Avg8Ux16: vex_printf("Avg8Ux16"); return;
499 case Iop_Avg16Ux8: vex_printf("Avg16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000500 case Iop_Avg32Ux4: vex_printf("Avg32Ux4"); return;
501 case Iop_Avg8Sx16: vex_printf("Avg8Sx16"); return;
502 case Iop_Avg16Sx8: vex_printf("Avg16Sx8"); return;
503 case Iop_Avg32Sx4: vex_printf("Avg32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000504
cerionf887b3e2005-09-13 16:34:28 +0000505 case Iop_Max8Sx16: vex_printf("Max8Sx16"); return;
sewardj164f9272004-12-09 00:39:32 +0000506 case Iop_Max16Sx8: vex_printf("Max16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000507 case Iop_Max32Sx4: vex_printf("Max32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000508 case Iop_Max8Ux16: vex_printf("Max8Ux16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000509 case Iop_Max16Ux8: vex_printf("Max16Ux8"); return;
510 case Iop_Max32Ux4: vex_printf("Max32Ux4"); return;
511
512 case Iop_Min8Sx16: vex_printf("Min8Sx16"); return;
sewardj164f9272004-12-09 00:39:32 +0000513 case Iop_Min16Sx8: vex_printf("Min16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000514 case Iop_Min32Sx4: vex_printf("Min32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000515 case Iop_Min8Ux16: vex_printf("Min8Ux16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000516 case Iop_Min16Ux8: vex_printf("Min16Ux8"); return;
517 case Iop_Min32Ux4: vex_printf("Min32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000518
519 case Iop_CmpEQ8x16: vex_printf("CmpEQ8x16"); return;
520 case Iop_CmpEQ16x8: vex_printf("CmpEQ16x8"); return;
521 case Iop_CmpEQ32x4: vex_printf("CmpEQ32x4"); return;
522 case Iop_CmpGT8Sx16: vex_printf("CmpGT8Sx16"); return;
523 case Iop_CmpGT16Sx8: vex_printf("CmpGT16Sx8"); return;
524 case Iop_CmpGT32Sx4: vex_printf("CmpGT32Sx4"); return;
cerionf887b3e2005-09-13 16:34:28 +0000525 case Iop_CmpGT8Ux16: vex_printf("CmpGT8Ux16"); return;
526 case Iop_CmpGT16Ux8: vex_printf("CmpGT16Ux8"); return;
527 case Iop_CmpGT32Ux4: vex_printf("CmpGT32Ux4"); return;
528
529 case Iop_ShlV128: vex_printf("ShlV128"); return;
530 case Iop_ShrV128: vex_printf("ShrV128"); return;
sewardj164f9272004-12-09 00:39:32 +0000531
cerion2a4b8452005-09-15 16:28:36 +0000532 case Iop_ShlN8x16: vex_printf("ShlN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000533 case Iop_ShlN16x8: vex_printf("ShlN16x8"); return;
534 case Iop_ShlN32x4: vex_printf("ShlN32x4"); return;
535 case Iop_ShlN64x2: vex_printf("ShlN64x2"); return;
cerion2a4b8452005-09-15 16:28:36 +0000536 case Iop_ShrN8x16: vex_printf("ShrN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000537 case Iop_ShrN16x8: vex_printf("ShrN16x8"); return;
538 case Iop_ShrN32x4: vex_printf("ShrN32x4"); return;
539 case Iop_ShrN64x2: vex_printf("ShrN64x2"); return;
cerion2a4b8452005-09-15 16:28:36 +0000540 case Iop_SarN8x16: vex_printf("SarN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000541 case Iop_SarN16x8: vex_printf("SarN16x8"); return;
542 case Iop_SarN32x4: vex_printf("SarN32x4"); return;
543
cerionf887b3e2005-09-13 16:34:28 +0000544 case Iop_Shl8x16: vex_printf("Shl8x16"); return;
545 case Iop_Shl16x8: vex_printf("Shl16x8"); return;
546 case Iop_Shl32x4: vex_printf("Shl32x4"); return;
547 case Iop_Shr8x16: vex_printf("Shr8x16"); return;
548 case Iop_Shr16x8: vex_printf("Shr16x8"); return;
549 case Iop_Shr32x4: vex_printf("Shr32x4"); return;
550 case Iop_Sar8x16: vex_printf("Sar8x16"); return;
551 case Iop_Sar16x8: vex_printf("Sar16x8"); return;
552 case Iop_Sar32x4: vex_printf("Sar32x4"); return;
sewardj1bee5612005-11-10 18:10:58 +0000553 case Iop_Rol8x16: vex_printf("Rol8x16"); return;
554 case Iop_Rol16x8: vex_printf("Rol16x8"); return;
555 case Iop_Rol32x4: vex_printf("Rol32x4"); return;
cerionf887b3e2005-09-13 16:34:28 +0000556
sewardj1bee5612005-11-10 18:10:58 +0000557 case Iop_Narrow16x8: vex_printf("Narrow16x8"); return;
558 case Iop_Narrow32x4: vex_printf("Narrow32x4"); return;
sewardj164f9272004-12-09 00:39:32 +0000559 case Iop_QNarrow16Ux8: vex_printf("QNarrow16Ux8"); return;
cerion9e7677b2005-09-13 17:25:41 +0000560 case Iop_QNarrow32Ux4: vex_printf("QNarrow32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000561 case Iop_QNarrow16Sx8: vex_printf("QNarrow16Sx8"); return;
562 case Iop_QNarrow32Sx4: vex_printf("QNarrow32Sx4"); return;
563
564 case Iop_InterleaveHI8x16: vex_printf("InterleaveHI8x16"); return;
565 case Iop_InterleaveHI16x8: vex_printf("InterleaveHI16x8"); return;
566 case Iop_InterleaveHI32x4: vex_printf("InterleaveHI32x4"); return;
567 case Iop_InterleaveHI64x2: vex_printf("InterleaveHI64x2"); return;
568 case Iop_InterleaveLO8x16: vex_printf("InterleaveLO8x16"); return;
569 case Iop_InterleaveLO16x8: vex_printf("InterleaveLO16x8"); return;
570 case Iop_InterleaveLO32x4: vex_printf("InterleaveLO32x4"); return;
571 case Iop_InterleaveLO64x2: vex_printf("InterleaveLO64x2"); return;
572
sewardjdc1f9132005-10-22 12:49:49 +0000573 case Iop_Perm8x16: vex_printf("Perm8x16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000574
sewardjc9a43662004-11-30 18:51:59 +0000575 default: vpanic("ppIROp(1)");
sewardj41f43bc2004-07-08 14:23:22 +0000576 }
577
578 switch (op - base) {
sewardjecbaee72008-11-01 23:54:45 +0000579 case 0: vex_printf("%s",str); vex_printf("8"); break;
580 case 1: vex_printf("%s",str); vex_printf("16"); break;
581 case 2: vex_printf("%s",str); vex_printf("32"); break;
582 case 3: vex_printf("%s",str); vex_printf("64"); break;
sewardj41f43bc2004-07-08 14:23:22 +0000583 default: vpanic("ppIROp(2)");
584 }
sewardje3d0d2e2004-06-27 10:42:44 +0000585}
586
sewardj35421a32004-07-05 13:12:34 +0000587void ppIRExpr ( IRExpr* e )
sewardje3d0d2e2004-06-27 10:42:44 +0000588{
sewardje87b4842004-07-10 12:23:30 +0000589 Int i;
sewardje3d0d2e2004-06-27 10:42:44 +0000590 switch (e->tag) {
sewardj443cd9d2004-07-18 23:06:45 +0000591 case Iex_Binder:
592 vex_printf("BIND-%d", e->Iex.Binder.binder);
593 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000594 case Iex_Get:
sewardjc9a43662004-11-30 18:51:59 +0000595 vex_printf( "GET:" );
sewardjfbcaf332004-07-08 01:46:01 +0000596 ppIRType(e->Iex.Get.ty);
sewardjc9a43662004-11-30 18:51:59 +0000597 vex_printf("(%d)", e->Iex.Get.offset);
sewardjec6ad592004-06-20 12:26:53 +0000598 break;
sewardjbb53f8c2004-08-14 11:50:01 +0000599 case Iex_GetI:
sewardj2d3f77c2004-09-22 23:49:09 +0000600 vex_printf( "GETI" );
sewardjdd40fdf2006-12-24 02:20:24 +0000601 ppIRRegArray(e->Iex.GetI.descr);
sewardj2d3f77c2004-09-22 23:49:09 +0000602 vex_printf("[");
sewardjeeac8412004-11-02 00:26:55 +0000603 ppIRExpr(e->Iex.GetI.ix);
sewardj2d3f77c2004-09-22 23:49:09 +0000604 vex_printf(",%d]", e->Iex.GetI.bias);
sewardjbb53f8c2004-08-14 11:50:01 +0000605 break;
sewardjdd40fdf2006-12-24 02:20:24 +0000606 case Iex_RdTmp:
607 ppIRTemp(e->Iex.RdTmp.tmp);
sewardjec6ad592004-06-20 12:26:53 +0000608 break;
sewardj40c80262006-02-08 19:30:46 +0000609 case Iex_Qop:
610 ppIROp(e->Iex.Qop.op);
611 vex_printf( "(" );
612 ppIRExpr(e->Iex.Qop.arg1);
613 vex_printf( "," );
614 ppIRExpr(e->Iex.Qop.arg2);
615 vex_printf( "," );
616 ppIRExpr(e->Iex.Qop.arg3);
617 vex_printf( "," );
618 ppIRExpr(e->Iex.Qop.arg4);
619 vex_printf( ")" );
620 break;
sewardjb183b852006-02-03 16:08:03 +0000621 case Iex_Triop:
622 ppIROp(e->Iex.Triop.op);
623 vex_printf( "(" );
624 ppIRExpr(e->Iex.Triop.arg1);
625 vex_printf( "," );
626 ppIRExpr(e->Iex.Triop.arg2);
627 vex_printf( "," );
628 ppIRExpr(e->Iex.Triop.arg3);
629 vex_printf( ")" );
630 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000631 case Iex_Binop:
sewardj35421a32004-07-05 13:12:34 +0000632 ppIROp(e->Iex.Binop.op);
633 vex_printf( "(" );
634 ppIRExpr(e->Iex.Binop.arg1);
635 vex_printf( "," );
636 ppIRExpr(e->Iex.Binop.arg2);
637 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000638 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000639 case Iex_Unop:
sewardj35421a32004-07-05 13:12:34 +0000640 ppIROp(e->Iex.Unop.op);
641 vex_printf( "(" );
642 ppIRExpr(e->Iex.Unop.arg);
643 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000644 break;
sewardjaf1ceca2005-06-30 23:31:27 +0000645 case Iex_Load:
sewardje9d8a262009-07-01 08:06:34 +0000646 vex_printf( "LD%s%s:", e->Iex.Load.end==Iend_LE ? "le" : "be",
647 e->Iex.Load.isLL ? "-LL" : "" );
sewardjaf1ceca2005-06-30 23:31:27 +0000648 ppIRType(e->Iex.Load.ty);
sewardje05c42c2004-07-08 20:25:10 +0000649 vex_printf( "(" );
sewardjaf1ceca2005-06-30 23:31:27 +0000650 ppIRExpr(e->Iex.Load.addr);
sewardj35421a32004-07-05 13:12:34 +0000651 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000652 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000653 case Iex_Const:
sewardj35421a32004-07-05 13:12:34 +0000654 ppIRConst(e->Iex.Const.con);
sewardjec6ad592004-06-20 12:26:53 +0000655 break;
sewardje87b4842004-07-10 12:23:30 +0000656 case Iex_CCall:
sewardj8ea867b2004-10-30 19:03:02 +0000657 ppIRCallee(e->Iex.CCall.cee);
658 vex_printf("(");
sewardje87b4842004-07-10 12:23:30 +0000659 for (i = 0; e->Iex.CCall.args[i] != NULL; i++) {
660 ppIRExpr(e->Iex.CCall.args[i]);
661 if (e->Iex.CCall.args[i+1] != NULL)
662 vex_printf(",");
663 }
664 vex_printf("):");
665 ppIRType(e->Iex.CCall.retty);
666 break;
sewardj4042c7e2004-07-18 01:28:30 +0000667 case Iex_Mux0X:
668 vex_printf("Mux0X(");
669 ppIRExpr(e->Iex.Mux0X.cond);
sewardjeeb9ef82004-07-15 12:39:03 +0000670 vex_printf(",");
sewardj4042c7e2004-07-18 01:28:30 +0000671 ppIRExpr(e->Iex.Mux0X.expr0);
sewardjeeb9ef82004-07-15 12:39:03 +0000672 vex_printf(",");
sewardj4042c7e2004-07-18 01:28:30 +0000673 ppIRExpr(e->Iex.Mux0X.exprX);
sewardjeeb9ef82004-07-15 12:39:03 +0000674 vex_printf(")");
675 break;
sewardjec6ad592004-06-20 12:26:53 +0000676 default:
sewardj909c06d2005-02-19 22:47:41 +0000677 vpanic("ppIRExpr");
sewardjec6ad592004-06-20 12:26:53 +0000678 }
679}
680
sewardj17442fe2004-09-20 14:54:28 +0000681void ppIREffect ( IREffect fx )
682{
683 switch (fx) {
684 case Ifx_None: vex_printf("noFX"); return;
685 case Ifx_Read: vex_printf("RdFX"); return;
686 case Ifx_Write: vex_printf("WrFX"); return;
687 case Ifx_Modify: vex_printf("MoFX"); return;
688 default: vpanic("ppIREffect");
689 }
690}
691
692void ppIRDirty ( IRDirty* d )
693{
694 Int i;
sewardj92d168d2004-11-15 14:22:12 +0000695 if (d->tmp != IRTemp_INVALID) {
sewardj4b861de2004-11-03 15:24:42 +0000696 ppIRTemp(d->tmp);
697 vex_printf(" = ");
698 }
sewardjb8385d82004-11-02 01:34:15 +0000699 vex_printf("DIRTY ");
700 ppIRExpr(d->guard);
sewardjc5fc7aa2004-10-27 23:00:55 +0000701 if (d->needsBBP)
702 vex_printf(" NeedsBBP");
sewardj17442fe2004-09-20 14:54:28 +0000703 if (d->mFx != Ifx_None) {
sewardj49651f42004-10-28 22:11:04 +0000704 vex_printf(" ");
sewardj17442fe2004-09-20 14:54:28 +0000705 ppIREffect(d->mFx);
706 vex_printf("-mem(");
707 ppIRExpr(d->mAddr);
sewardj49651f42004-10-28 22:11:04 +0000708 vex_printf(",%d)", d->mSize);
sewardj17442fe2004-09-20 14:54:28 +0000709 }
710 for (i = 0; i < d->nFxState; i++) {
sewardj49651f42004-10-28 22:11:04 +0000711 vex_printf(" ");
sewardj17442fe2004-09-20 14:54:28 +0000712 ppIREffect(d->fxState[i].fx);
sewardj49651f42004-10-28 22:11:04 +0000713 vex_printf("-gst(%d,%d)", d->fxState[i].offset, d->fxState[i].size);
sewardj17442fe2004-09-20 14:54:28 +0000714 }
sewardjc5fc7aa2004-10-27 23:00:55 +0000715 vex_printf(" ::: ");
sewardj8ea867b2004-10-30 19:03:02 +0000716 ppIRCallee(d->cee);
717 vex_printf("(");
sewardj17442fe2004-09-20 14:54:28 +0000718 for (i = 0; d->args[i] != NULL; i++) {
719 ppIRExpr(d->args[i]);
720 if (d->args[i+1] != NULL) {
721 vex_printf(",");
722 }
723 }
724 vex_printf(")");
725}
726
sewardje9d8a262009-07-01 08:06:34 +0000727void ppIRCAS ( IRCAS* cas )
728{
729 /* Print even structurally invalid constructions, as an aid to
730 debugging. */
731 if (cas->oldHi != IRTemp_INVALID) {
732 ppIRTemp(cas->oldHi);
733 vex_printf(",");
734 }
735 ppIRTemp(cas->oldLo);
736 vex_printf(" = CAS%s(", cas->end==Iend_LE ? "le" : "be" );
737 ppIRExpr(cas->addr);
738 vex_printf("::");
739 if (cas->expdHi) {
740 ppIRExpr(cas->expdHi);
741 vex_printf(",");
742 }
743 ppIRExpr(cas->expdLo);
744 vex_printf("->");
745 if (cas->dataHi) {
746 ppIRExpr(cas->dataHi);
747 vex_printf(",");
748 }
749 ppIRExpr(cas->dataLo);
750 vex_printf(")");
751}
752
sewardj893aada2004-11-29 19:57:54 +0000753void ppIRJumpKind ( IRJumpKind kind )
754{
755 switch (kind) {
sewardj4fa325a2005-11-03 13:27:24 +0000756 case Ijk_Boring: vex_printf("Boring"); break;
757 case Ijk_Call: vex_printf("Call"); break;
758 case Ijk_Ret: vex_printf("Return"); break;
759 case Ijk_ClientReq: vex_printf("ClientReq"); break;
760 case Ijk_Yield: vex_printf("Yield"); break;
761 case Ijk_EmWarn: vex_printf("EmWarn"); break;
sewardj9dd9cf12006-01-20 14:13:55 +0000762 case Ijk_EmFail: vex_printf("EmFail"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000763 case Ijk_NoDecode: vex_printf("NoDecode"); break;
764 case Ijk_MapFail: vex_printf("MapFail"); break;
765 case Ijk_TInval: vex_printf("Invalidate"); break;
sewardjce02aa72006-01-12 12:27:58 +0000766 case Ijk_NoRedir: vex_printf("NoRedir"); break;
sewardj0f500042007-08-29 09:09:17 +0000767 case Ijk_SigTRAP: vex_printf("SigTRAP"); break;
768 case Ijk_SigSEGV: vex_printf("SigSEGV"); break;
sewardje9d8a262009-07-01 08:06:34 +0000769 case Ijk_SigBUS: vex_printf("SigBUS"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000770 case Ijk_Sys_syscall: vex_printf("Sys_syscall"); break;
771 case Ijk_Sys_int32: vex_printf("Sys_int32"); break;
772 case Ijk_Sys_int128: vex_printf("Sys_int128"); break;
sewardjd660d412008-12-03 21:29:59 +0000773 case Ijk_Sys_int129: vex_printf("Sys_int129"); break;
774 case Ijk_Sys_int130: vex_printf("Sys_int130"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000775 case Ijk_Sys_sysenter: vex_printf("Sys_sysenter"); break;
776 default: vpanic("ppIRJumpKind");
sewardj893aada2004-11-29 19:57:54 +0000777 }
778}
779
sewardjc4356f02007-11-09 21:15:04 +0000780void ppIRMBusEvent ( IRMBusEvent event )
781{
782 switch (event) {
sewardje9d8a262009-07-01 08:06:34 +0000783 case Imbe_Fence: vex_printf("Fence"); break;
784 default: vpanic("ppIRMBusEvent");
sewardjc4356f02007-11-09 21:15:04 +0000785 }
786}
787
sewardj35421a32004-07-05 13:12:34 +0000788void ppIRStmt ( IRStmt* s )
sewardjec6ad592004-06-20 12:26:53 +0000789{
sewardjd2445f62005-03-21 00:15:53 +0000790 if (!s) {
791 vex_printf("!!! IRStmt* which is NULL !!!");
792 return;
793 }
sewardj17442fe2004-09-20 14:54:28 +0000794 switch (s->tag) {
sewardjd2445f62005-03-21 00:15:53 +0000795 case Ist_NoOp:
796 vex_printf("IR-NoOp");
797 break;
sewardjf1689312005-03-16 18:19:10 +0000798 case Ist_IMark:
sewardj0c12a272005-03-17 09:57:03 +0000799 vex_printf( "------ IMark(0x%llx, %d) ------",
800 s->Ist.IMark.addr, s->Ist.IMark.len);
sewardjf1689312005-03-16 18:19:10 +0000801 break;
sewardj5a9ffab2005-05-12 17:55:01 +0000802 case Ist_AbiHint:
803 vex_printf("====== AbiHint(");
804 ppIRExpr(s->Ist.AbiHint.base);
sewardj478646f2008-05-01 20:13:04 +0000805 vex_printf(", %d, ", s->Ist.AbiHint.len);
806 ppIRExpr(s->Ist.AbiHint.nia);
807 vex_printf(") ======");
sewardj5a9ffab2005-05-12 17:55:01 +0000808 break;
sewardj17442fe2004-09-20 14:54:28 +0000809 case Ist_Put:
810 vex_printf( "PUT(%d) = ", s->Ist.Put.offset);
sewardj6d076362004-09-23 11:06:17 +0000811 ppIRExpr(s->Ist.Put.data);
sewardj17442fe2004-09-20 14:54:28 +0000812 break;
813 case Ist_PutI:
sewardj2d3f77c2004-09-22 23:49:09 +0000814 vex_printf( "PUTI" );
sewardjdd40fdf2006-12-24 02:20:24 +0000815 ppIRRegArray(s->Ist.PutI.descr);
sewardj2d3f77c2004-09-22 23:49:09 +0000816 vex_printf("[");
sewardjeeac8412004-11-02 00:26:55 +0000817 ppIRExpr(s->Ist.PutI.ix);
sewardj2d3f77c2004-09-22 23:49:09 +0000818 vex_printf(",%d] = ", s->Ist.PutI.bias);
819 ppIRExpr(s->Ist.PutI.data);
sewardj17442fe2004-09-20 14:54:28 +0000820 break;
sewardjdd40fdf2006-12-24 02:20:24 +0000821 case Ist_WrTmp:
822 ppIRTemp(s->Ist.WrTmp.tmp);
sewardj17442fe2004-09-20 14:54:28 +0000823 vex_printf( " = " );
sewardjdd40fdf2006-12-24 02:20:24 +0000824 ppIRExpr(s->Ist.WrTmp.data);
sewardj17442fe2004-09-20 14:54:28 +0000825 break;
sewardjaf1ceca2005-06-30 23:31:27 +0000826 case Ist_Store:
sewardje9d8a262009-07-01 08:06:34 +0000827 if (s->Ist.Store.resSC != IRTemp_INVALID) {
828 ppIRTemp(s->Ist.Store.resSC);
829 vex_printf( " = SC( " );
830 }
sewardjaf1ceca2005-06-30 23:31:27 +0000831 vex_printf( "ST%s(", s->Ist.Store.end==Iend_LE ? "le" : "be" );
832 ppIRExpr(s->Ist.Store.addr);
sewardj17442fe2004-09-20 14:54:28 +0000833 vex_printf( ") = ");
sewardjaf1ceca2005-06-30 23:31:27 +0000834 ppIRExpr(s->Ist.Store.data);
sewardje9d8a262009-07-01 08:06:34 +0000835 if (s->Ist.Store.resSC != IRTemp_INVALID)
836 vex_printf( " )" );
837 break;
838 case Ist_CAS:
839 ppIRCAS(s->Ist.CAS.details);
sewardj17442fe2004-09-20 14:54:28 +0000840 break;
841 case Ist_Dirty:
842 ppIRDirty(s->Ist.Dirty.details);
843 break;
sewardjc4356f02007-11-09 21:15:04 +0000844 case Ist_MBE:
845 vex_printf("IR-");
846 ppIRMBusEvent(s->Ist.MBE.event);
sewardj3e838932005-01-07 12:09:15 +0000847 break;
sewardj17442fe2004-09-20 14:54:28 +0000848 case Ist_Exit:
849 vex_printf( "if (" );
sewardj0276d4b2004-11-15 15:30:21 +0000850 ppIRExpr(s->Ist.Exit.guard);
sewardj893aada2004-11-29 19:57:54 +0000851 vex_printf( ") goto {");
852 ppIRJumpKind(s->Ist.Exit.jk);
853 vex_printf("} ");
sewardj17442fe2004-09-20 14:54:28 +0000854 ppIRConst(s->Ist.Exit.dst);
855 break;
856 default:
857 vpanic("ppIRStmt");
858 }
sewardjec6ad592004-06-20 12:26:53 +0000859}
860
sewardj35421a32004-07-05 13:12:34 +0000861void ppIRTypeEnv ( IRTypeEnv* env ) {
sewardjc97096c2004-06-30 09:28:04 +0000862 UInt i;
sewardje539a402004-07-14 18:24:17 +0000863 for (i = 0; i < env->types_used; i++) {
sewardjc97096c2004-06-30 09:28:04 +0000864 if (i % 8 == 0)
sewardj35421a32004-07-05 13:12:34 +0000865 vex_printf( " ");
sewardje539a402004-07-14 18:24:17 +0000866 ppIRTemp(i);
sewardj35421a32004-07-05 13:12:34 +0000867 vex_printf( ":");
sewardje539a402004-07-14 18:24:17 +0000868 ppIRType(env->types[i]);
sewardjc97096c2004-06-30 09:28:04 +0000869 if (i % 8 == 7)
sewardj35421a32004-07-05 13:12:34 +0000870 vex_printf( "\n");
sewardjc97096c2004-06-30 09:28:04 +0000871 else
sewardj35421a32004-07-05 13:12:34 +0000872 vex_printf( " ");
sewardjc97096c2004-06-30 09:28:04 +0000873 }
sewardje539a402004-07-14 18:24:17 +0000874 if (env->types_used > 0 && env->types_used % 8 != 7)
sewardj35421a32004-07-05 13:12:34 +0000875 vex_printf( "\n");
sewardjc97096c2004-06-30 09:28:04 +0000876}
877
sewardjdd40fdf2006-12-24 02:20:24 +0000878void ppIRSB ( IRSB* bb )
sewardjec6ad592004-06-20 12:26:53 +0000879{
sewardjd7cb8532004-08-17 23:59:23 +0000880 Int i;
sewardjdd40fdf2006-12-24 02:20:24 +0000881 vex_printf("IRSB {\n");
sewardj35421a32004-07-05 13:12:34 +0000882 ppIRTypeEnv(bb->tyenv);
sewardj35439212004-07-14 22:36:10 +0000883 vex_printf("\n");
sewardjd7cb8532004-08-17 23:59:23 +0000884 for (i = 0; i < bb->stmts_used; i++) {
sewardjd2445f62005-03-21 00:15:53 +0000885 vex_printf( " ");
886 ppIRStmt(bb->stmts[i]);
sewardj35421a32004-07-05 13:12:34 +0000887 vex_printf( "\n");
sewardjec6ad592004-06-20 12:26:53 +0000888 }
sewardje539a402004-07-14 18:24:17 +0000889 vex_printf( " goto {");
890 ppIRJumpKind(bb->jumpkind);
891 vex_printf( "} ");
892 ppIRExpr( bb->next );
sewardj35439212004-07-14 22:36:10 +0000893 vex_printf( "\n}\n");
sewardjec6ad592004-06-20 12:26:53 +0000894}
895
896
897/*---------------------------------------------------------------*/
898/*--- Constructors ---*/
899/*---------------------------------------------------------------*/
900
sewardjc97096c2004-06-30 09:28:04 +0000901
902/* Constructors -- IRConst */
903
sewardjba999312004-11-15 15:21:17 +0000904IRConst* IRConst_U1 ( Bool bit )
sewardjb8e75862004-08-19 17:58:45 +0000905{
906 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjba999312004-11-15 15:21:17 +0000907 c->tag = Ico_U1;
908 c->Ico.U1 = bit;
sewardj4b861de2004-11-03 15:24:42 +0000909 /* call me paranoid; I don't care :-) */
910 vassert(bit == False || bit == True);
sewardjb8e75862004-08-19 17:58:45 +0000911 return c;
912}
sewardjc97096c2004-06-30 09:28:04 +0000913IRConst* IRConst_U8 ( UChar u8 )
914{
sewardj35421a32004-07-05 13:12:34 +0000915 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000916 c->tag = Ico_U8;
917 c->Ico.U8 = u8;
918 return c;
919}
920IRConst* IRConst_U16 ( UShort u16 )
921{
sewardj35421a32004-07-05 13:12:34 +0000922 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000923 c->tag = Ico_U16;
924 c->Ico.U16 = u16;
925 return c;
926}
927IRConst* IRConst_U32 ( UInt u32 )
928{
sewardj35421a32004-07-05 13:12:34 +0000929 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000930 c->tag = Ico_U32;
931 c->Ico.U32 = u32;
932 return c;
933}
934IRConst* IRConst_U64 ( ULong u64 )
935{
sewardj35421a32004-07-05 13:12:34 +0000936 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000937 c->tag = Ico_U64;
938 c->Ico.U64 = u64;
939 return c;
940}
sewardja58ea662004-08-15 03:12:41 +0000941IRConst* IRConst_F64 ( Double f64 )
942{
943 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
944 c->tag = Ico_F64;
945 c->Ico.F64 = f64;
946 return c;
947}
sewardj17442fe2004-09-20 14:54:28 +0000948IRConst* IRConst_F64i ( ULong f64i )
sewardj207557a2004-08-27 12:00:18 +0000949{
sewardj17442fe2004-09-20 14:54:28 +0000950 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
951 c->tag = Ico_F64i;
952 c->Ico.F64i = f64i;
sewardj207557a2004-08-27 12:00:18 +0000953 return c;
954}
sewardj1e6ad742004-12-02 16:16:11 +0000955IRConst* IRConst_V128 ( UShort con )
956{
957 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
958 c->tag = Ico_V128;
959 c->Ico.V128 = con;
960 return c;
961}
sewardjc97096c2004-06-30 09:28:04 +0000962
sewardj8ea867b2004-10-30 19:03:02 +0000963/* Constructors -- IRCallee */
964
sewardj2d49b432005-02-01 00:37:06 +0000965IRCallee* mkIRCallee ( Int regparms, HChar* name, void* addr )
sewardj8ea867b2004-10-30 19:03:02 +0000966{
967 IRCallee* ce = LibVEX_Alloc(sizeof(IRCallee));
sewardj77352542004-10-30 20:39:01 +0000968 ce->regparms = regparms;
969 ce->name = name;
970 ce->addr = addr;
sewardj43c56462004-11-06 12:17:57 +0000971 ce->mcx_mask = 0;
sewardj77352542004-10-30 20:39:01 +0000972 vassert(regparms >= 0 && regparms <= 3);
sewardj8ea867b2004-10-30 19:03:02 +0000973 vassert(name != NULL);
974 vassert(addr != 0);
975 return ce;
976}
977
978
sewardjdd40fdf2006-12-24 02:20:24 +0000979/* Constructors -- IRRegArray */
sewardje3d0d2e2004-06-27 10:42:44 +0000980
sewardjdd40fdf2006-12-24 02:20:24 +0000981IRRegArray* mkIRRegArray ( Int base, IRType elemTy, Int nElems )
sewardj2d3f77c2004-09-22 23:49:09 +0000982{
sewardjdd40fdf2006-12-24 02:20:24 +0000983 IRRegArray* arr = LibVEX_Alloc(sizeof(IRRegArray));
984 arr->base = base;
985 arr->elemTy = elemTy;
986 arr->nElems = nElems;
sewardj2d3f77c2004-09-22 23:49:09 +0000987 vassert(!(arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */));
sewardjba999312004-11-15 15:21:17 +0000988 vassert(!(arr->elemTy == Ity_I1));
sewardj2d3f77c2004-09-22 23:49:09 +0000989 vassert(!(arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */));
990 return arr;
991}
992
993
994/* Constructors -- IRExpr */
995
sewardj443cd9d2004-07-18 23:06:45 +0000996IRExpr* IRExpr_Binder ( Int binder ) {
997 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
998 e->tag = Iex_Binder;
999 e->Iex.Binder.binder = binder;
1000 return e;
1001}
sewardjfbcaf332004-07-08 01:46:01 +00001002IRExpr* IRExpr_Get ( Int off, IRType ty ) {
sewardj35421a32004-07-05 13:12:34 +00001003 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001004 e->tag = Iex_Get;
1005 e->Iex.Get.offset = off;
sewardjfbcaf332004-07-08 01:46:01 +00001006 e->Iex.Get.ty = ty;
sewardje3d0d2e2004-06-27 10:42:44 +00001007 return e;
1008}
sewardjdd40fdf2006-12-24 02:20:24 +00001009IRExpr* IRExpr_GetI ( IRRegArray* descr, IRExpr* ix, Int bias ) {
sewardj2d3f77c2004-09-22 23:49:09 +00001010 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1011 e->tag = Iex_GetI;
1012 e->Iex.GetI.descr = descr;
sewardjeeac8412004-11-02 00:26:55 +00001013 e->Iex.GetI.ix = ix;
sewardj2d3f77c2004-09-22 23:49:09 +00001014 e->Iex.GetI.bias = bias;
sewardjd1725d12004-08-12 20:46:53 +00001015 return e;
1016}
sewardjdd40fdf2006-12-24 02:20:24 +00001017IRExpr* IRExpr_RdTmp ( IRTemp tmp ) {
1018 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1019 e->tag = Iex_RdTmp;
1020 e->Iex.RdTmp.tmp = tmp;
sewardje3d0d2e2004-06-27 10:42:44 +00001021 return e;
1022}
sewardj40c80262006-02-08 19:30:46 +00001023IRExpr* IRExpr_Qop ( IROp op, IRExpr* arg1, IRExpr* arg2,
1024 IRExpr* arg3, IRExpr* arg4 ) {
1025 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1026 e->tag = Iex_Qop;
1027 e->Iex.Qop.op = op;
1028 e->Iex.Qop.arg1 = arg1;
1029 e->Iex.Qop.arg2 = arg2;
1030 e->Iex.Qop.arg3 = arg3;
1031 e->Iex.Qop.arg4 = arg4;
1032 return e;
1033}
sewardjb183b852006-02-03 16:08:03 +00001034IRExpr* IRExpr_Triop ( IROp op, IRExpr* arg1,
1035 IRExpr* arg2, IRExpr* arg3 ) {
1036 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1037 e->tag = Iex_Triop;
1038 e->Iex.Triop.op = op;
1039 e->Iex.Triop.arg1 = arg1;
1040 e->Iex.Triop.arg2 = arg2;
1041 e->Iex.Triop.arg3 = arg3;
1042 return e;
1043}
sewardjc97096c2004-06-30 09:28:04 +00001044IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 ) {
sewardj35421a32004-07-05 13:12:34 +00001045 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001046 e->tag = Iex_Binop;
1047 e->Iex.Binop.op = op;
1048 e->Iex.Binop.arg1 = arg1;
1049 e->Iex.Binop.arg2 = arg2;
1050 return e;
1051}
sewardjc97096c2004-06-30 09:28:04 +00001052IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg ) {
sewardj35421a32004-07-05 13:12:34 +00001053 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001054 e->tag = Iex_Unop;
1055 e->Iex.Unop.op = op;
1056 e->Iex.Unop.arg = arg;
1057 return e;
1058}
sewardje9d8a262009-07-01 08:06:34 +00001059IRExpr* IRExpr_Load ( Bool isLL, IREndness end, IRType ty, IRExpr* addr ) {
sewardj35421a32004-07-05 13:12:34 +00001060 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardjaf1ceca2005-06-30 23:31:27 +00001061 e->tag = Iex_Load;
sewardje9d8a262009-07-01 08:06:34 +00001062 e->Iex.Load.isLL = isLL;
sewardjaf1ceca2005-06-30 23:31:27 +00001063 e->Iex.Load.end = end;
1064 e->Iex.Load.ty = ty;
1065 e->Iex.Load.addr = addr;
1066 vassert(end == Iend_LE || end == Iend_BE);
sewardje3d0d2e2004-06-27 10:42:44 +00001067 return e;
1068}
sewardjc97096c2004-06-30 09:28:04 +00001069IRExpr* IRExpr_Const ( IRConst* con ) {
sewardj35421a32004-07-05 13:12:34 +00001070 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001071 e->tag = Iex_Const;
1072 e->Iex.Const.con = con;
1073 return e;
sewardjec6ad592004-06-20 12:26:53 +00001074}
sewardj8ea867b2004-10-30 19:03:02 +00001075IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args ) {
sewardje87b4842004-07-10 12:23:30 +00001076 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1077 e->tag = Iex_CCall;
sewardj8ea867b2004-10-30 19:03:02 +00001078 e->Iex.CCall.cee = cee;
sewardje87b4842004-07-10 12:23:30 +00001079 e->Iex.CCall.retty = retty;
1080 e->Iex.CCall.args = args;
1081 return e;
1082}
sewardj4042c7e2004-07-18 01:28:30 +00001083IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX ) {
sewardjeeb9ef82004-07-15 12:39:03 +00001084 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardj4042c7e2004-07-18 01:28:30 +00001085 e->tag = Iex_Mux0X;
1086 e->Iex.Mux0X.cond = cond;
1087 e->Iex.Mux0X.expr0 = expr0;
1088 e->Iex.Mux0X.exprX = exprX;
sewardjeeb9ef82004-07-15 12:39:03 +00001089 return e;
1090}
sewardjec6ad592004-06-20 12:26:53 +00001091
sewardjec6ad592004-06-20 12:26:53 +00001092
sewardjc5fc7aa2004-10-27 23:00:55 +00001093/* Constructors for NULL-terminated IRExpr expression vectors,
1094 suitable for use as arg lists in clean/dirty helper calls. */
1095
1096IRExpr** mkIRExprVec_0 ( void ) {
1097 IRExpr** vec = LibVEX_Alloc(1 * sizeof(IRExpr*));
1098 vec[0] = NULL;
1099 return vec;
1100}
1101IRExpr** mkIRExprVec_1 ( IRExpr* arg1 ) {
1102 IRExpr** vec = LibVEX_Alloc(2 * sizeof(IRExpr*));
1103 vec[0] = arg1;
1104 vec[1] = NULL;
1105 return vec;
1106}
1107IRExpr** mkIRExprVec_2 ( IRExpr* arg1, IRExpr* arg2 ) {
1108 IRExpr** vec = LibVEX_Alloc(3 * sizeof(IRExpr*));
1109 vec[0] = arg1;
1110 vec[1] = arg2;
1111 vec[2] = NULL;
1112 return vec;
1113}
sewardjf9655262004-10-31 20:02:16 +00001114IRExpr** mkIRExprVec_3 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3 ) {
1115 IRExpr** vec = LibVEX_Alloc(4 * sizeof(IRExpr*));
1116 vec[0] = arg1;
1117 vec[1] = arg2;
1118 vec[2] = arg3;
1119 vec[3] = NULL;
1120 return vec;
1121}
sewardj78ec32b2007-01-08 05:09:55 +00001122IRExpr** mkIRExprVec_4 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1123 IRExpr* arg4 ) {
sewardjf9655262004-10-31 20:02:16 +00001124 IRExpr** vec = LibVEX_Alloc(5 * sizeof(IRExpr*));
1125 vec[0] = arg1;
1126 vec[1] = arg2;
1127 vec[2] = arg3;
1128 vec[3] = arg4;
1129 vec[4] = NULL;
1130 return vec;
1131}
sewardj78ec32b2007-01-08 05:09:55 +00001132IRExpr** mkIRExprVec_5 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1133 IRExpr* arg4, IRExpr* arg5 ) {
sewardjf32c67d2004-11-08 13:10:44 +00001134 IRExpr** vec = LibVEX_Alloc(6 * sizeof(IRExpr*));
1135 vec[0] = arg1;
1136 vec[1] = arg2;
1137 vec[2] = arg3;
1138 vec[3] = arg4;
1139 vec[4] = arg5;
1140 vec[5] = NULL;
1141 return vec;
1142}
sewardj78ec32b2007-01-08 05:09:55 +00001143IRExpr** mkIRExprVec_6 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1144 IRExpr* arg4, IRExpr* arg5, IRExpr* arg6 ) {
1145 IRExpr** vec = LibVEX_Alloc(7 * sizeof(IRExpr*));
1146 vec[0] = arg1;
1147 vec[1] = arg2;
1148 vec[2] = arg3;
1149 vec[3] = arg4;
1150 vec[4] = arg5;
1151 vec[5] = arg6;
1152 vec[6] = NULL;
1153 return vec;
1154}
1155IRExpr** mkIRExprVec_7 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1156 IRExpr* arg4, IRExpr* arg5, IRExpr* arg6,
1157 IRExpr* arg7 ) {
1158 IRExpr** vec = LibVEX_Alloc(8 * sizeof(IRExpr*));
1159 vec[0] = arg1;
1160 vec[1] = arg2;
1161 vec[2] = arg3;
1162 vec[3] = arg4;
1163 vec[4] = arg5;
1164 vec[5] = arg6;
1165 vec[6] = arg7;
1166 vec[7] = NULL;
1167 return vec;
1168}
sewardjc5fc7aa2004-10-27 23:00:55 +00001169
1170
sewardj17442fe2004-09-20 14:54:28 +00001171/* Constructors -- IRDirty */
1172
sewardjc5fc7aa2004-10-27 23:00:55 +00001173IRDirty* emptyIRDirty ( void ) {
sewardj17442fe2004-09-20 14:54:28 +00001174 IRDirty* d = LibVEX_Alloc(sizeof(IRDirty));
sewardj8ea867b2004-10-30 19:03:02 +00001175 d->cee = NULL;
sewardjb8385d82004-11-02 01:34:15 +00001176 d->guard = NULL;
sewardj17442fe2004-09-20 14:54:28 +00001177 d->args = NULL;
sewardj92d168d2004-11-15 14:22:12 +00001178 d->tmp = IRTemp_INVALID;
sewardj17442fe2004-09-20 14:54:28 +00001179 d->mFx = Ifx_None;
1180 d->mAddr = NULL;
1181 d->mSize = 0;
sewardjc5fc7aa2004-10-27 23:00:55 +00001182 d->needsBBP = False;
sewardj17442fe2004-09-20 14:54:28 +00001183 d->nFxState = 0;
1184 return d;
1185}
1186
1187
sewardje9d8a262009-07-01 08:06:34 +00001188/* Constructors -- IRCAS */
1189
1190IRCAS* mkIRCAS ( IRTemp oldHi, IRTemp oldLo,
1191 IREndness end, IRExpr* addr,
1192 IRExpr* expdHi, IRExpr* expdLo,
1193 IRExpr* dataHi, IRExpr* dataLo ) {
1194 IRCAS* cas = LibVEX_Alloc(sizeof(IRCAS));
1195 cas->oldHi = oldHi;
1196 cas->oldLo = oldLo;
1197 cas->end = end;
1198 cas->addr = addr;
1199 cas->expdHi = expdHi;
1200 cas->expdLo = expdLo;
1201 cas->dataHi = dataHi;
1202 cas->dataLo = dataLo;
1203 return cas;
1204}
1205
1206
sewardjec6ad592004-06-20 12:26:53 +00001207/* Constructors -- IRStmt */
sewardje3d0d2e2004-06-27 10:42:44 +00001208
sewardjd2445f62005-03-21 00:15:53 +00001209IRStmt* IRStmt_NoOp ( void )
1210{
1211 /* Just use a single static closure. */
1212 static IRStmt static_closure;
1213 static_closure.tag = Ist_NoOp;
1214 return &static_closure;
1215}
sewardjf1689312005-03-16 18:19:10 +00001216IRStmt* IRStmt_IMark ( Addr64 addr, Int len ) {
1217 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1218 s->tag = Ist_IMark;
1219 s->Ist.IMark.addr = addr;
1220 s->Ist.IMark.len = len;
1221 return s;
1222}
sewardj478646f2008-05-01 20:13:04 +00001223IRStmt* IRStmt_AbiHint ( IRExpr* base, Int len, IRExpr* nia ) {
sewardj5a9ffab2005-05-12 17:55:01 +00001224 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1225 s->tag = Ist_AbiHint;
1226 s->Ist.AbiHint.base = base;
1227 s->Ist.AbiHint.len = len;
sewardj478646f2008-05-01 20:13:04 +00001228 s->Ist.AbiHint.nia = nia;
sewardj5a9ffab2005-05-12 17:55:01 +00001229 return s;
1230}
sewardj6d076362004-09-23 11:06:17 +00001231IRStmt* IRStmt_Put ( Int off, IRExpr* data ) {
sewardj35421a32004-07-05 13:12:34 +00001232 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
sewardje3d0d2e2004-06-27 10:42:44 +00001233 s->tag = Ist_Put;
1234 s->Ist.Put.offset = off;
sewardj6d076362004-09-23 11:06:17 +00001235 s->Ist.Put.data = data;
sewardje3d0d2e2004-06-27 10:42:44 +00001236 return s;
sewardjec6ad592004-06-20 12:26:53 +00001237}
sewardjdd40fdf2006-12-24 02:20:24 +00001238IRStmt* IRStmt_PutI ( IRRegArray* descr, IRExpr* ix,
sewardj2d3f77c2004-09-22 23:49:09 +00001239 Int bias, IRExpr* data ) {
1240 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1241 s->tag = Ist_PutI;
1242 s->Ist.PutI.descr = descr;
sewardjeeac8412004-11-02 00:26:55 +00001243 s->Ist.PutI.ix = ix;
sewardj2d3f77c2004-09-22 23:49:09 +00001244 s->Ist.PutI.bias = bias;
1245 s->Ist.PutI.data = data;
sewardjd1725d12004-08-12 20:46:53 +00001246 return s;
1247}
sewardjdd40fdf2006-12-24 02:20:24 +00001248IRStmt* IRStmt_WrTmp ( IRTemp tmp, IRExpr* data ) {
1249 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1250 s->tag = Ist_WrTmp;
1251 s->Ist.WrTmp.tmp = tmp;
1252 s->Ist.WrTmp.data = data;
sewardje3d0d2e2004-06-27 10:42:44 +00001253 return s;
sewardjec6ad592004-06-20 12:26:53 +00001254}
sewardje9d8a262009-07-01 08:06:34 +00001255IRStmt* IRStmt_Store ( IREndness end,
1256 IRTemp resSC, IRExpr* addr, IRExpr* data ) {
1257 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1258 s->tag = Ist_Store;
1259 s->Ist.Store.end = end;
1260 s->Ist.Store.resSC = resSC;
1261 s->Ist.Store.addr = addr;
1262 s->Ist.Store.data = data;
sewardjaf1ceca2005-06-30 23:31:27 +00001263 vassert(end == Iend_LE || end == Iend_BE);
sewardje3d0d2e2004-06-27 10:42:44 +00001264 return s;
sewardjec6ad592004-06-20 12:26:53 +00001265}
sewardje9d8a262009-07-01 08:06:34 +00001266IRStmt* IRStmt_CAS ( IRCAS* cas ) {
1267 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1268 s->tag = Ist_CAS;
1269 s->Ist.CAS.details = cas;
1270 return s;
1271}
sewardj17442fe2004-09-20 14:54:28 +00001272IRStmt* IRStmt_Dirty ( IRDirty* d )
1273{
1274 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1275 s->tag = Ist_Dirty;
1276 s->Ist.Dirty.details = d;
1277 return s;
1278}
sewardjc4356f02007-11-09 21:15:04 +00001279IRStmt* IRStmt_MBE ( IRMBusEvent event )
sewardj3e838932005-01-07 12:09:15 +00001280{
sewardjc4356f02007-11-09 21:15:04 +00001281 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1282 s->tag = Ist_MBE;
1283 s->Ist.MBE.event = event;
1284 return s;
sewardj3e838932005-01-07 12:09:15 +00001285}
sewardj893aada2004-11-29 19:57:54 +00001286IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst ) {
sewardj0276d4b2004-11-15 15:30:21 +00001287 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1288 s->tag = Ist_Exit;
1289 s->Ist.Exit.guard = guard;
sewardj893aada2004-11-29 19:57:54 +00001290 s->Ist.Exit.jk = jk;
sewardj0276d4b2004-11-15 15:30:21 +00001291 s->Ist.Exit.dst = dst;
sewardj64e1d652004-07-12 14:00:46 +00001292 return s;
1293}
sewardje3d0d2e2004-06-27 10:42:44 +00001294
sewardj695cff92004-10-13 14:50:14 +00001295
1296/* Constructors -- IRTypeEnv */
1297
1298IRTypeEnv* emptyIRTypeEnv ( void )
1299{
1300 IRTypeEnv* env = LibVEX_Alloc(sizeof(IRTypeEnv));
1301 env->types = LibVEX_Alloc(8 * sizeof(IRType));
1302 env->types_size = 8;
1303 env->types_used = 0;
1304 return env;
1305}
1306
1307
sewardjdd40fdf2006-12-24 02:20:24 +00001308/* Constructors -- IRSB */
sewardje3d0d2e2004-06-27 10:42:44 +00001309
sewardjdd40fdf2006-12-24 02:20:24 +00001310IRSB* emptyIRSB ( void )
sewardjd7cb8532004-08-17 23:59:23 +00001311{
sewardjdd40fdf2006-12-24 02:20:24 +00001312 IRSB* bb = LibVEX_Alloc(sizeof(IRSB));
sewardjd7cb8532004-08-17 23:59:23 +00001313 bb->tyenv = emptyIRTypeEnv();
1314 bb->stmts_used = 0;
1315 bb->stmts_size = 8;
1316 bb->stmts = LibVEX_Alloc(bb->stmts_size * sizeof(IRStmt*));
1317 bb->next = NULL;
1318 bb->jumpkind = Ijk_Boring;
sewardje3d0d2e2004-06-27 10:42:44 +00001319 return bb;
sewardjec6ad592004-06-20 12:26:53 +00001320}
1321
sewardj695cff92004-10-13 14:50:14 +00001322
1323/*---------------------------------------------------------------*/
1324/*--- (Deep) copy constructors. These make complete copies ---*/
1325/*--- the original, which can be modified without affecting ---*/
1326/*--- the original. ---*/
1327/*---------------------------------------------------------------*/
1328
1329/* Copying IR Expr vectors (for call args). */
1330
1331/* Shallow copy of an IRExpr vector */
1332
sewardjdd40fdf2006-12-24 02:20:24 +00001333IRExpr** shallowCopyIRExprVec ( IRExpr** vec )
sewardjd7cb8532004-08-17 23:59:23 +00001334{
sewardj695cff92004-10-13 14:50:14 +00001335 Int i;
1336 IRExpr** newvec;
1337 for (i = 0; vec[i]; i++)
1338 ;
1339 newvec = LibVEX_Alloc((i+1)*sizeof(IRExpr*));
1340 for (i = 0; vec[i]; i++)
1341 newvec[i] = vec[i];
1342 newvec[i] = NULL;
1343 return newvec;
1344}
1345
1346/* Deep copy of an IRExpr vector */
1347
sewardjdd40fdf2006-12-24 02:20:24 +00001348IRExpr** deepCopyIRExprVec ( IRExpr** vec )
sewardj695cff92004-10-13 14:50:14 +00001349{
1350 Int i;
sewardjdd40fdf2006-12-24 02:20:24 +00001351 IRExpr** newvec = shallowCopyIRExprVec( vec );
sewardj695cff92004-10-13 14:50:14 +00001352 for (i = 0; newvec[i]; i++)
sewardjdd40fdf2006-12-24 02:20:24 +00001353 newvec[i] = deepCopyIRExpr(newvec[i]);
sewardj695cff92004-10-13 14:50:14 +00001354 return newvec;
1355}
1356
1357/* Deep copy constructors for all heap-allocated IR types follow. */
1358
sewardjdd40fdf2006-12-24 02:20:24 +00001359IRConst* deepCopyIRConst ( IRConst* c )
sewardj695cff92004-10-13 14:50:14 +00001360{
1361 switch (c->tag) {
sewardjba999312004-11-15 15:21:17 +00001362 case Ico_U1: return IRConst_U1(c->Ico.U1);
sewardj695cff92004-10-13 14:50:14 +00001363 case Ico_U8: return IRConst_U8(c->Ico.U8);
1364 case Ico_U16: return IRConst_U16(c->Ico.U16);
1365 case Ico_U32: return IRConst_U32(c->Ico.U32);
1366 case Ico_U64: return IRConst_U64(c->Ico.U64);
1367 case Ico_F64: return IRConst_F64(c->Ico.F64);
1368 case Ico_F64i: return IRConst_F64i(c->Ico.F64i);
sewardj1e6ad742004-12-02 16:16:11 +00001369 case Ico_V128: return IRConst_V128(c->Ico.V128);
sewardjdd40fdf2006-12-24 02:20:24 +00001370 default: vpanic("deepCopyIRConst");
sewardjd7cb8532004-08-17 23:59:23 +00001371 }
sewardj695cff92004-10-13 14:50:14 +00001372}
1373
sewardjdd40fdf2006-12-24 02:20:24 +00001374IRCallee* deepCopyIRCallee ( IRCallee* ce )
sewardj8ea867b2004-10-30 19:03:02 +00001375{
sewardj43c56462004-11-06 12:17:57 +00001376 IRCallee* ce2 = mkIRCallee(ce->regparms, ce->name, ce->addr);
1377 ce2->mcx_mask = ce->mcx_mask;
1378 return ce2;
sewardj8ea867b2004-10-30 19:03:02 +00001379}
1380
sewardjdd40fdf2006-12-24 02:20:24 +00001381IRRegArray* deepCopyIRRegArray ( IRRegArray* d )
sewardj695cff92004-10-13 14:50:14 +00001382{
sewardjdd40fdf2006-12-24 02:20:24 +00001383 return mkIRRegArray(d->base, d->elemTy, d->nElems);
sewardj695cff92004-10-13 14:50:14 +00001384}
1385
sewardjdd40fdf2006-12-24 02:20:24 +00001386IRExpr* deepCopyIRExpr ( IRExpr* e )
sewardj695cff92004-10-13 14:50:14 +00001387{
1388 switch (e->tag) {
1389 case Iex_Get:
1390 return IRExpr_Get(e->Iex.Get.offset, e->Iex.Get.ty);
1391 case Iex_GetI:
sewardjdd40fdf2006-12-24 02:20:24 +00001392 return IRExpr_GetI(deepCopyIRRegArray(e->Iex.GetI.descr),
1393 deepCopyIRExpr(e->Iex.GetI.ix),
sewardj695cff92004-10-13 14:50:14 +00001394 e->Iex.GetI.bias);
sewardjdd40fdf2006-12-24 02:20:24 +00001395 case Iex_RdTmp:
1396 return IRExpr_RdTmp(e->Iex.RdTmp.tmp);
sewardj1a866b42006-02-09 02:54:03 +00001397 case Iex_Qop:
1398 return IRExpr_Qop(e->Iex.Qop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001399 deepCopyIRExpr(e->Iex.Qop.arg1),
1400 deepCopyIRExpr(e->Iex.Qop.arg2),
1401 deepCopyIRExpr(e->Iex.Qop.arg3),
1402 deepCopyIRExpr(e->Iex.Qop.arg4));
sewardjb183b852006-02-03 16:08:03 +00001403 case Iex_Triop:
1404 return IRExpr_Triop(e->Iex.Triop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001405 deepCopyIRExpr(e->Iex.Triop.arg1),
1406 deepCopyIRExpr(e->Iex.Triop.arg2),
1407 deepCopyIRExpr(e->Iex.Triop.arg3));
sewardj695cff92004-10-13 14:50:14 +00001408 case Iex_Binop:
1409 return IRExpr_Binop(e->Iex.Binop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001410 deepCopyIRExpr(e->Iex.Binop.arg1),
1411 deepCopyIRExpr(e->Iex.Binop.arg2));
sewardj695cff92004-10-13 14:50:14 +00001412 case Iex_Unop:
1413 return IRExpr_Unop(e->Iex.Unop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001414 deepCopyIRExpr(e->Iex.Unop.arg));
sewardjaf1ceca2005-06-30 23:31:27 +00001415 case Iex_Load:
sewardje9d8a262009-07-01 08:06:34 +00001416 return IRExpr_Load(e->Iex.Load.isLL,
1417 e->Iex.Load.end,
sewardjaf1ceca2005-06-30 23:31:27 +00001418 e->Iex.Load.ty,
sewardjdd40fdf2006-12-24 02:20:24 +00001419 deepCopyIRExpr(e->Iex.Load.addr));
sewardj695cff92004-10-13 14:50:14 +00001420 case Iex_Const:
sewardjdd40fdf2006-12-24 02:20:24 +00001421 return IRExpr_Const(deepCopyIRConst(e->Iex.Const.con));
sewardj695cff92004-10-13 14:50:14 +00001422 case Iex_CCall:
sewardjdd40fdf2006-12-24 02:20:24 +00001423 return IRExpr_CCall(deepCopyIRCallee(e->Iex.CCall.cee),
sewardj695cff92004-10-13 14:50:14 +00001424 e->Iex.CCall.retty,
sewardjdd40fdf2006-12-24 02:20:24 +00001425 deepCopyIRExprVec(e->Iex.CCall.args));
sewardj695cff92004-10-13 14:50:14 +00001426
1427 case Iex_Mux0X:
sewardjdd40fdf2006-12-24 02:20:24 +00001428 return IRExpr_Mux0X(deepCopyIRExpr(e->Iex.Mux0X.cond),
1429 deepCopyIRExpr(e->Iex.Mux0X.expr0),
1430 deepCopyIRExpr(e->Iex.Mux0X.exprX));
sewardj695cff92004-10-13 14:50:14 +00001431 default:
sewardjdd40fdf2006-12-24 02:20:24 +00001432 vpanic("deepCopyIRExpr");
sewardj695cff92004-10-13 14:50:14 +00001433 }
1434}
1435
sewardjdd40fdf2006-12-24 02:20:24 +00001436IRDirty* deepCopyIRDirty ( IRDirty* d )
sewardj695cff92004-10-13 14:50:14 +00001437{
1438 Int i;
1439 IRDirty* d2 = emptyIRDirty();
sewardjdd40fdf2006-12-24 02:20:24 +00001440 d2->cee = deepCopyIRCallee(d->cee);
1441 d2->guard = deepCopyIRExpr(d->guard);
1442 d2->args = deepCopyIRExprVec(d->args);
sewardj695cff92004-10-13 14:50:14 +00001443 d2->tmp = d->tmp;
1444 d2->mFx = d->mFx;
sewardjdd40fdf2006-12-24 02:20:24 +00001445 d2->mAddr = d->mAddr==NULL ? NULL : deepCopyIRExpr(d->mAddr);
sewardj695cff92004-10-13 14:50:14 +00001446 d2->mSize = d->mSize;
sewardjc5fc7aa2004-10-27 23:00:55 +00001447 d2->needsBBP = d->needsBBP;
sewardj695cff92004-10-13 14:50:14 +00001448 d2->nFxState = d->nFxState;
1449 for (i = 0; i < d2->nFxState; i++)
1450 d2->fxState[i] = d->fxState[i];
1451 return d2;
1452}
1453
sewardje9d8a262009-07-01 08:06:34 +00001454IRCAS* deepCopyIRCAS ( IRCAS* cas )
1455{
1456 return mkIRCAS( cas->oldHi, cas->oldLo, cas->end,
1457 deepCopyIRExpr(cas->addr),
1458 deepCopyIRExpr(cas->expdHi),
1459 deepCopyIRExpr(cas->expdLo),
1460 deepCopyIRExpr(cas->dataHi),
1461 deepCopyIRExpr(cas->dataLo) );
1462}
1463
sewardjdd40fdf2006-12-24 02:20:24 +00001464IRStmt* deepCopyIRStmt ( IRStmt* s )
sewardj695cff92004-10-13 14:50:14 +00001465{
1466 switch (s->tag) {
sewardjd2445f62005-03-21 00:15:53 +00001467 case Ist_NoOp:
1468 return IRStmt_NoOp();
sewardj5a9ffab2005-05-12 17:55:01 +00001469 case Ist_AbiHint:
sewardjdd40fdf2006-12-24 02:20:24 +00001470 return IRStmt_AbiHint(deepCopyIRExpr(s->Ist.AbiHint.base),
sewardj478646f2008-05-01 20:13:04 +00001471 s->Ist.AbiHint.len,
1472 deepCopyIRExpr(s->Ist.AbiHint.nia));
sewardjf1689312005-03-16 18:19:10 +00001473 case Ist_IMark:
1474 return IRStmt_IMark(s->Ist.IMark.addr, s->Ist.IMark.len);
sewardj695cff92004-10-13 14:50:14 +00001475 case Ist_Put:
1476 return IRStmt_Put(s->Ist.Put.offset,
sewardjdd40fdf2006-12-24 02:20:24 +00001477 deepCopyIRExpr(s->Ist.Put.data));
sewardj695cff92004-10-13 14:50:14 +00001478 case Ist_PutI:
sewardjdd40fdf2006-12-24 02:20:24 +00001479 return IRStmt_PutI(deepCopyIRRegArray(s->Ist.PutI.descr),
1480 deepCopyIRExpr(s->Ist.PutI.ix),
sewardj695cff92004-10-13 14:50:14 +00001481 s->Ist.PutI.bias,
sewardjdd40fdf2006-12-24 02:20:24 +00001482 deepCopyIRExpr(s->Ist.PutI.data));
1483 case Ist_WrTmp:
1484 return IRStmt_WrTmp(s->Ist.WrTmp.tmp,
1485 deepCopyIRExpr(s->Ist.WrTmp.data));
sewardjaf1ceca2005-06-30 23:31:27 +00001486 case Ist_Store:
1487 return IRStmt_Store(s->Ist.Store.end,
sewardje9d8a262009-07-01 08:06:34 +00001488 s->Ist.Store.resSC,
sewardjdd40fdf2006-12-24 02:20:24 +00001489 deepCopyIRExpr(s->Ist.Store.addr),
1490 deepCopyIRExpr(s->Ist.Store.data));
sewardje9d8a262009-07-01 08:06:34 +00001491 case Ist_CAS:
1492 return IRStmt_CAS(deepCopyIRCAS(s->Ist.CAS.details));
sewardj695cff92004-10-13 14:50:14 +00001493 case Ist_Dirty:
sewardjdd40fdf2006-12-24 02:20:24 +00001494 return IRStmt_Dirty(deepCopyIRDirty(s->Ist.Dirty.details));
sewardjc4356f02007-11-09 21:15:04 +00001495 case Ist_MBE:
1496 return IRStmt_MBE(s->Ist.MBE.event);
sewardj695cff92004-10-13 14:50:14 +00001497 case Ist_Exit:
sewardjdd40fdf2006-12-24 02:20:24 +00001498 return IRStmt_Exit(deepCopyIRExpr(s->Ist.Exit.guard),
sewardj893aada2004-11-29 19:57:54 +00001499 s->Ist.Exit.jk,
sewardjdd40fdf2006-12-24 02:20:24 +00001500 deepCopyIRConst(s->Ist.Exit.dst));
sewardj695cff92004-10-13 14:50:14 +00001501 default:
sewardjdd40fdf2006-12-24 02:20:24 +00001502 vpanic("deepCopyIRStmt");
sewardj695cff92004-10-13 14:50:14 +00001503 }
1504}
1505
sewardjdd40fdf2006-12-24 02:20:24 +00001506IRTypeEnv* deepCopyIRTypeEnv ( IRTypeEnv* src )
sewardj695cff92004-10-13 14:50:14 +00001507{
1508 Int i;
1509 IRTypeEnv* dst = LibVEX_Alloc(sizeof(IRTypeEnv));
1510 dst->types_size = src->types_size;
1511 dst->types_used = src->types_used;
1512 dst->types = LibVEX_Alloc(dst->types_size * sizeof(IRType));
1513 for (i = 0; i < src->types_used; i++)
1514 dst->types[i] = src->types[i];
1515 return dst;
1516}
1517
sewardjdd40fdf2006-12-24 02:20:24 +00001518IRSB* deepCopyIRSB ( IRSB* bb )
sewardj695cff92004-10-13 14:50:14 +00001519{
1520 Int i;
1521 IRStmt** sts2;
sewardjdd40fdf2006-12-24 02:20:24 +00001522 IRSB* bb2 = deepCopyIRSBExceptStmts(bb);
sewardj695cff92004-10-13 14:50:14 +00001523 bb2->stmts_used = bb2->stmts_size = bb->stmts_used;
1524 sts2 = LibVEX_Alloc(bb2->stmts_used * sizeof(IRStmt*));
1525 for (i = 0; i < bb2->stmts_used; i++)
sewardjdd40fdf2006-12-24 02:20:24 +00001526 sts2[i] = deepCopyIRStmt(bb->stmts[i]);
sewardj695cff92004-10-13 14:50:14 +00001527 bb2->stmts = sts2;
sewardj6f2f2832006-11-24 23:32:55 +00001528 return bb2;
1529}
1530
sewardjdd40fdf2006-12-24 02:20:24 +00001531IRSB* deepCopyIRSBExceptStmts ( IRSB* bb )
sewardj6f2f2832006-11-24 23:32:55 +00001532{
sewardjdd40fdf2006-12-24 02:20:24 +00001533 IRSB* bb2 = emptyIRSB();
1534 bb2->tyenv = deepCopyIRTypeEnv(bb->tyenv);
1535 bb2->next = deepCopyIRExpr(bb->next);
sewardj695cff92004-10-13 14:50:14 +00001536 bb2->jumpkind = bb->jumpkind;
1537 return bb2;
sewardjd7cb8532004-08-17 23:59:23 +00001538}
1539
sewardjec6ad592004-06-20 12:26:53 +00001540
sewardjc97096c2004-06-30 09:28:04 +00001541/*---------------------------------------------------------------*/
sewardj6efd4a12004-07-15 03:54:23 +00001542/*--- Primop types ---*/
1543/*---------------------------------------------------------------*/
1544
1545static
sewardjb183b852006-02-03 16:08:03 +00001546void typeOfPrimop ( IROp op,
1547 /*OUTs*/
1548 IRType* t_dst,
sewardj40c80262006-02-08 19:30:46 +00001549 IRType* t_arg1, IRType* t_arg2,
1550 IRType* t_arg3, IRType* t_arg4 )
sewardj6efd4a12004-07-15 03:54:23 +00001551{
sewardjb183b852006-02-03 16:08:03 +00001552# define UNARY(_ta1,_td) \
sewardj6efd4a12004-07-15 03:54:23 +00001553 *t_dst = (_td); *t_arg1 = (_ta1); break
sewardjb183b852006-02-03 16:08:03 +00001554# define BINARY(_ta1,_ta2,_td) \
sewardj6efd4a12004-07-15 03:54:23 +00001555 *t_dst = (_td); *t_arg1 = (_ta1); *t_arg2 = (_ta2); break
sewardjb183b852006-02-03 16:08:03 +00001556# define TERNARY(_ta1,_ta2,_ta3,_td) \
1557 *t_dst = (_td); *t_arg1 = (_ta1); \
1558 *t_arg2 = (_ta2); *t_arg3 = (_ta3); break
sewardj40c80262006-02-08 19:30:46 +00001559# define QUATERNARY(_ta1,_ta2,_ta3,_ta4,_td) \
1560 *t_dst = (_td); *t_arg1 = (_ta1); \
1561 *t_arg2 = (_ta2); *t_arg3 = (_ta3); \
1562 *t_arg4 = (_ta4); break
sewardjb183b852006-02-03 16:08:03 +00001563# define COMPARISON(_ta) \
sewardjba999312004-11-15 15:21:17 +00001564 *t_dst = Ity_I1; *t_arg1 = *t_arg2 = (_ta); break;
sewardjb183b852006-02-03 16:08:03 +00001565# define UNARY_COMPARISON(_ta) \
sewardj0033ddc2005-04-26 23:34:34 +00001566 *t_dst = Ity_I1; *t_arg1 = (_ta); break;
sewardj6efd4a12004-07-15 03:54:23 +00001567
sewardjb183b852006-02-03 16:08:03 +00001568 /* Rounding mode values are always Ity_I32, encoded as per
1569 IRRoundingMode */
1570 const IRType ity_RMode = Ity_I32;
1571
sewardj6efd4a12004-07-15 03:54:23 +00001572 *t_dst = Ity_INVALID;
1573 *t_arg1 = Ity_INVALID;
1574 *t_arg2 = Ity_INVALID;
sewardjb183b852006-02-03 16:08:03 +00001575 *t_arg3 = Ity_INVALID;
sewardj40c80262006-02-08 19:30:46 +00001576 *t_arg4 = Ity_INVALID;
sewardj6efd4a12004-07-15 03:54:23 +00001577 switch (op) {
sewardj17442fe2004-09-20 14:54:28 +00001578 case Iop_Add8: case Iop_Sub8: case Iop_Mul8:
1579 case Iop_Or8: case Iop_And8: case Iop_Xor8:
sewardjb183b852006-02-03 16:08:03 +00001580 BINARY(Ity_I8,Ity_I8, Ity_I8);
sewardj6efd4a12004-07-15 03:54:23 +00001581
sewardj17442fe2004-09-20 14:54:28 +00001582 case Iop_Add16: case Iop_Sub16: case Iop_Mul16:
1583 case Iop_Or16: case Iop_And16: case Iop_Xor16:
sewardjb183b852006-02-03 16:08:03 +00001584 BINARY(Ity_I16,Ity_I16, Ity_I16);
sewardj6efd4a12004-07-15 03:54:23 +00001585
sewardjb51f0f42005-07-18 11:38:02 +00001586 case Iop_CmpORD32U:
1587 case Iop_CmpORD32S:
sewardj17442fe2004-09-20 14:54:28 +00001588 case Iop_Add32: case Iop_Sub32: case Iop_Mul32:
1589 case Iop_Or32: case Iop_And32: case Iop_Xor32:
sewardj478646f2008-05-01 20:13:04 +00001590 case Iop_Max32U:
sewardjb183b852006-02-03 16:08:03 +00001591 BINARY(Ity_I32,Ity_I32, Ity_I32);
sewardj6efd4a12004-07-15 03:54:23 +00001592
sewardj17442fe2004-09-20 14:54:28 +00001593 case Iop_Add64: case Iop_Sub64: case Iop_Mul64:
1594 case Iop_Or64: case Iop_And64: case Iop_Xor64:
cerion2831b002005-11-30 19:55:22 +00001595 case Iop_CmpORD64U:
1596 case Iop_CmpORD64S:
sewardj38a3f862005-01-13 15:06:51 +00001597 case Iop_Avg8Ux8: case Iop_Avg16Ux4:
1598 case Iop_Add8x8: case Iop_Add16x4: case Iop_Add32x2:
1599 case Iop_CmpEQ8x8: case Iop_CmpEQ16x4: case Iop_CmpEQ32x2:
1600 case Iop_CmpGT8Sx8: case Iop_CmpGT16Sx4: case Iop_CmpGT32Sx2:
1601 case Iop_InterleaveHI8x8: case Iop_InterleaveLO8x8:
1602 case Iop_InterleaveHI16x4: case Iop_InterleaveLO16x4:
1603 case Iop_InterleaveHI32x2: case Iop_InterleaveLO32x2:
sewardjd166e282008-02-06 11:42:45 +00001604 case Iop_CatOddLanes16x4: case Iop_CatEvenLanes16x4:
1605 case Iop_Perm8x8:
sewardj38a3f862005-01-13 15:06:51 +00001606 case Iop_Max8Ux8: case Iop_Max16Sx4:
1607 case Iop_Min8Ux8: case Iop_Min16Sx4:
sewardjd166e282008-02-06 11:42:45 +00001608 case Iop_Mul16x4: case Iop_Mul32x2:
1609 case Iop_MulHi16Sx4: case Iop_MulHi16Ux4:
sewardj38a3f862005-01-13 15:06:51 +00001610 case Iop_QAdd8Sx8: case Iop_QAdd16Sx4:
1611 case Iop_QAdd8Ux8: case Iop_QAdd16Ux4:
1612 case Iop_QNarrow32Sx2:
1613 case Iop_QNarrow16Sx4: case Iop_QNarrow16Ux4:
1614 case Iop_Sub8x8: case Iop_Sub16x4: case Iop_Sub32x2:
1615 case Iop_QSub8Sx8: case Iop_QSub16Sx4:
1616 case Iop_QSub8Ux8: case Iop_QSub16Ux4:
sewardjb183b852006-02-03 16:08:03 +00001617 BINARY(Ity_I64,Ity_I64, Ity_I64);
sewardj38a3f862005-01-13 15:06:51 +00001618
sewardjd166e282008-02-06 11:42:45 +00001619 case Iop_ShlN32x2: case Iop_ShlN16x4: case Iop_ShlN8x8:
sewardj38a3f862005-01-13 15:06:51 +00001620 case Iop_ShrN32x2: case Iop_ShrN16x4:
sewardjd71ba832006-12-27 01:15:29 +00001621 case Iop_SarN32x2: case Iop_SarN16x4: case Iop_SarN8x8:
sewardjb183b852006-02-03 16:08:03 +00001622 BINARY(Ity_I64,Ity_I8, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001623
1624 case Iop_Shl8: case Iop_Shr8: case Iop_Sar8:
sewardjb183b852006-02-03 16:08:03 +00001625 BINARY(Ity_I8,Ity_I8, Ity_I8);
sewardj6efd4a12004-07-15 03:54:23 +00001626 case Iop_Shl16: case Iop_Shr16: case Iop_Sar16:
sewardjb183b852006-02-03 16:08:03 +00001627 BINARY(Ity_I16,Ity_I8, Ity_I16);
sewardj6efd4a12004-07-15 03:54:23 +00001628 case Iop_Shl32: case Iop_Shr32: case Iop_Sar32:
sewardjb183b852006-02-03 16:08:03 +00001629 BINARY(Ity_I32,Ity_I8, Ity_I32);
sewardj6efd4a12004-07-15 03:54:23 +00001630 case Iop_Shl64: case Iop_Shr64: case Iop_Sar64:
sewardjb183b852006-02-03 16:08:03 +00001631 BINARY(Ity_I64,Ity_I8, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001632
sewardjeb17e492007-08-25 23:07:44 +00001633 case Iop_Not8:
sewardjb183b852006-02-03 16:08:03 +00001634 UNARY(Ity_I8, Ity_I8);
sewardjeb17e492007-08-25 23:07:44 +00001635 case Iop_Not16:
sewardjb183b852006-02-03 16:08:03 +00001636 UNARY(Ity_I16, Ity_I16);
sewardjeb17e492007-08-25 23:07:44 +00001637 case Iop_Not32:
sewardjb183b852006-02-03 16:08:03 +00001638 UNARY(Ity_I32, Ity_I32);
sewardj18069182005-01-13 19:16:04 +00001639
sewardj0033ddc2005-04-26 23:34:34 +00001640 case Iop_Not64:
sewardj18069182005-01-13 19:16:04 +00001641 case Iop_CmpNEZ32x2: case Iop_CmpNEZ16x4: case Iop_CmpNEZ8x8:
sewardjb183b852006-02-03 16:08:03 +00001642 UNARY(Ity_I64, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001643
1644 case Iop_CmpEQ8: case Iop_CmpNE8:
1645 COMPARISON(Ity_I8);
1646 case Iop_CmpEQ16: case Iop_CmpNE16:
1647 COMPARISON(Ity_I16);
1648 case Iop_CmpEQ32: case Iop_CmpNE32:
sewardj17442fe2004-09-20 14:54:28 +00001649 case Iop_CmpLT32S: case Iop_CmpLE32S:
1650 case Iop_CmpLT32U: case Iop_CmpLE32U:
sewardj6efd4a12004-07-15 03:54:23 +00001651 COMPARISON(Ity_I32);
1652 case Iop_CmpEQ64: case Iop_CmpNE64:
sewardj98540072005-04-26 01:52:01 +00001653 case Iop_CmpLT64S: case Iop_CmpLE64S:
1654 case Iop_CmpLT64U: case Iop_CmpLE64U:
sewardj6efd4a12004-07-15 03:54:23 +00001655 COMPARISON(Ity_I64);
1656
sewardj0033ddc2005-04-26 23:34:34 +00001657 case Iop_CmpNEZ8: UNARY_COMPARISON(Ity_I8);
1658 case Iop_CmpNEZ16: UNARY_COMPARISON(Ity_I16);
1659 case Iop_CmpNEZ32: UNARY_COMPARISON(Ity_I32);
1660 case Iop_CmpNEZ64: UNARY_COMPARISON(Ity_I64);
1661
sewardjeb17e492007-08-25 23:07:44 +00001662 case Iop_Left8: UNARY(Ity_I8, Ity_I8);
1663 case Iop_Left16: UNARY(Ity_I16,Ity_I16);
1664 case Iop_CmpwNEZ32: case Iop_Left32: UNARY(Ity_I32,Ity_I32);
1665 case Iop_CmpwNEZ64: case Iop_Left64: UNARY(Ity_I64,Ity_I64);
1666
sewardjb81f8b32004-07-30 10:17:50 +00001667 case Iop_MullU8: case Iop_MullS8:
sewardjb183b852006-02-03 16:08:03 +00001668 BINARY(Ity_I8,Ity_I8, Ity_I16);
sewardjb81f8b32004-07-30 10:17:50 +00001669 case Iop_MullU16: case Iop_MullS16:
sewardjb183b852006-02-03 16:08:03 +00001670 BINARY(Ity_I16,Ity_I16, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001671 case Iop_MullU32: case Iop_MullS32:
sewardjb183b852006-02-03 16:08:03 +00001672 BINARY(Ity_I32,Ity_I32, Ity_I64);
sewardj9b967672005-02-08 11:13:09 +00001673 case Iop_MullU64: case Iop_MullS64:
sewardjb183b852006-02-03 16:08:03 +00001674 BINARY(Ity_I64,Ity_I64, Ity_I128);
sewardj6d2638e2004-07-15 09:38:27 +00001675
sewardj17442fe2004-09-20 14:54:28 +00001676 case Iop_Clz32: case Iop_Ctz32:
sewardjb183b852006-02-03 16:08:03 +00001677 UNARY(Ity_I32, Ity_I32);
sewardjce646f22004-08-31 23:55:54 +00001678
sewardjf53b7352005-04-06 20:01:56 +00001679 case Iop_Clz64: case Iop_Ctz64:
sewardjb183b852006-02-03 16:08:03 +00001680 UNARY(Ity_I64, Ity_I64);
sewardjf53b7352005-04-06 20:01:56 +00001681
cerion5c8a0cb2005-02-03 13:59:46 +00001682 case Iop_DivU32: case Iop_DivS32:
sewardjb183b852006-02-03 16:08:03 +00001683 BINARY(Ity_I32,Ity_I32, Ity_I32);
cerion5c8a0cb2005-02-03 13:59:46 +00001684
cerionf0de28c2005-12-13 20:21:11 +00001685 case Iop_DivU64: case Iop_DivS64:
sewardjb183b852006-02-03 16:08:03 +00001686 BINARY(Ity_I64,Ity_I64, Ity_I64);
cerionf0de28c2005-12-13 20:21:11 +00001687
sewardj17442fe2004-09-20 14:54:28 +00001688 case Iop_DivModU64to32: case Iop_DivModS64to32:
sewardjb183b852006-02-03 16:08:03 +00001689 BINARY(Ity_I64,Ity_I32, Ity_I64);
sewardj6d2638e2004-07-15 09:38:27 +00001690
sewardj343b9d02005-01-31 18:08:45 +00001691 case Iop_DivModU128to64: case Iop_DivModS128to64:
sewardjb183b852006-02-03 16:08:03 +00001692 BINARY(Ity_I128,Ity_I64, Ity_I128);
sewardj343b9d02005-01-31 18:08:45 +00001693
sewardjb81f8b32004-07-30 10:17:50 +00001694 case Iop_16HIto8: case Iop_16to8:
sewardjb183b852006-02-03 16:08:03 +00001695 UNARY(Ity_I16, Ity_I8);
sewardjb81f8b32004-07-30 10:17:50 +00001696 case Iop_8HLto16:
sewardjb183b852006-02-03 16:08:03 +00001697 BINARY(Ity_I8,Ity_I8, Ity_I16);
sewardjb81f8b32004-07-30 10:17:50 +00001698
sewardj8c7f1ab2004-07-29 20:31:09 +00001699 case Iop_32HIto16: case Iop_32to16:
sewardjb183b852006-02-03 16:08:03 +00001700 UNARY(Ity_I32, Ity_I16);
sewardj8c7f1ab2004-07-29 20:31:09 +00001701 case Iop_16HLto32:
sewardjb183b852006-02-03 16:08:03 +00001702 BINARY(Ity_I16,Ity_I16, Ity_I32);
sewardj8c7f1ab2004-07-29 20:31:09 +00001703
1704 case Iop_64HIto32: case Iop_64to32:
sewardjb183b852006-02-03 16:08:03 +00001705 UNARY(Ity_I64, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001706 case Iop_32HLto64:
sewardjb183b852006-02-03 16:08:03 +00001707 BINARY(Ity_I32,Ity_I32, Ity_I64);
sewardj6d2638e2004-07-15 09:38:27 +00001708
sewardj9b967672005-02-08 11:13:09 +00001709 case Iop_128HIto64: case Iop_128to64:
sewardjb183b852006-02-03 16:08:03 +00001710 UNARY(Ity_I128, Ity_I64);
sewardj9b967672005-02-08 11:13:09 +00001711 case Iop_64HLto128:
sewardjb183b852006-02-03 16:08:03 +00001712 BINARY(Ity_I64,Ity_I64, Ity_I128);
sewardj9b967672005-02-08 11:13:09 +00001713
sewardjb183b852006-02-03 16:08:03 +00001714 case Iop_Not1: UNARY(Ity_I1, Ity_I1);
1715 case Iop_1Uto8: UNARY(Ity_I1, Ity_I8);
1716 case Iop_1Sto8: UNARY(Ity_I1, Ity_I8);
1717 case Iop_1Sto16: UNARY(Ity_I1, Ity_I16);
1718 case Iop_1Uto32: case Iop_1Sto32: UNARY(Ity_I1, Ity_I32);
1719 case Iop_1Sto64: case Iop_1Uto64: UNARY(Ity_I1, Ity_I64);
1720 case Iop_32to1: UNARY(Ity_I32, Ity_I1);
1721 case Iop_64to1: UNARY(Ity_I64, Ity_I1);
sewardj47341042004-09-19 11:55:46 +00001722
sewardj17442fe2004-09-20 14:54:28 +00001723 case Iop_8Uto32: case Iop_8Sto32:
sewardjb183b852006-02-03 16:08:03 +00001724 UNARY(Ity_I8, Ity_I32);
sewardj47341042004-09-19 11:55:46 +00001725
sewardj17442fe2004-09-20 14:54:28 +00001726 case Iop_8Uto16: case Iop_8Sto16:
sewardjb183b852006-02-03 16:08:03 +00001727 UNARY(Ity_I8, Ity_I16);
sewardj47341042004-09-19 11:55:46 +00001728
sewardj17442fe2004-09-20 14:54:28 +00001729 case Iop_16Uto32: case Iop_16Sto32:
sewardjb183b852006-02-03 16:08:03 +00001730 UNARY(Ity_I16, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001731
sewardj17442fe2004-09-20 14:54:28 +00001732 case Iop_32Sto64: case Iop_32Uto64:
sewardjb183b852006-02-03 16:08:03 +00001733 UNARY(Ity_I32, Ity_I64);
sewardj17442fe2004-09-20 14:54:28 +00001734
sewardj291a7e82005-04-27 11:42:44 +00001735 case Iop_8Uto64: case Iop_8Sto64:
sewardjb183b852006-02-03 16:08:03 +00001736 UNARY(Ity_I8, Ity_I64);
sewardj291a7e82005-04-27 11:42:44 +00001737
1738 case Iop_16Uto64: case Iop_16Sto64:
sewardj291a7e82005-04-27 11:42:44 +00001739 UNARY(Ity_I16, Ity_I64);
sewardjb183b852006-02-03 16:08:03 +00001740 case Iop_64to16:
1741 UNARY(Ity_I64, Ity_I16);
sewardj291a7e82005-04-27 11:42:44 +00001742
sewardjb183b852006-02-03 16:08:03 +00001743 case Iop_32to8: UNARY(Ity_I32, Ity_I8);
1744 case Iop_64to8: UNARY(Ity_I64, Ity_I8);
sewardj17442fe2004-09-20 14:54:28 +00001745
sewardjb183b852006-02-03 16:08:03 +00001746 case Iop_AddF64: case Iop_SubF64:
1747 case Iop_MulF64: case Iop_DivF64:
1748 case Iop_AddF64r32: case Iop_SubF64r32:
1749 case Iop_MulF64r32: case Iop_DivF64r32:
1750 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_F64);
1751
1752 case Iop_NegF64: case Iop_AbsF64:
1753 UNARY(Ity_F64, Ity_F64);
1754
1755 case Iop_SqrtF64:
1756 case Iop_SqrtF64r32:
1757 BINARY(ity_RMode,Ity_F64, Ity_F64);
1758
sewardjbdc7d212004-09-09 02:46:40 +00001759 case Iop_CmpF64:
sewardjb183b852006-02-03 16:08:03 +00001760 BINARY(Ity_F64,Ity_F64, Ity_I32);
sewardj8f3debf2004-09-08 23:42:23 +00001761
sewardjb183b852006-02-03 16:08:03 +00001762 case Iop_F64toI16: BINARY(ity_RMode,Ity_F64, Ity_I16);
1763 case Iop_F64toI32: BINARY(ity_RMode,Ity_F64, Ity_I32);
1764 case Iop_F64toI64: BINARY(ity_RMode,Ity_F64, Ity_I64);
sewardj8f3debf2004-09-08 23:42:23 +00001765
sewardjb183b852006-02-03 16:08:03 +00001766 case Iop_I16toF64: UNARY(Ity_I16, Ity_F64);
1767 case Iop_I32toF64: UNARY(Ity_I32, Ity_F64);
1768 case Iop_I64toF64: BINARY(ity_RMode,Ity_I64, Ity_F64);
sewardj3bca9062004-12-04 14:36:09 +00001769
sewardjb183b852006-02-03 16:08:03 +00001770 case Iop_F32toF64: UNARY(Ity_F32, Ity_F64);
1771 case Iop_F64toF32: BINARY(ity_RMode,Ity_F64, Ity_F32);
sewardj4cb918d2004-12-03 19:43:31 +00001772
sewardjb183b852006-02-03 16:08:03 +00001773 case Iop_ReinterpI64asF64: UNARY(Ity_I64, Ity_F64);
1774 case Iop_ReinterpF64asI64: UNARY(Ity_F64, Ity_I64);
1775 case Iop_ReinterpI32asF32: UNARY(Ity_I32, Ity_F32);
sewardjfc1b5412007-01-09 15:20:07 +00001776 case Iop_ReinterpF32asI32: UNARY(Ity_F32, Ity_I32);
sewardj8f3debf2004-09-08 23:42:23 +00001777
sewardjb183b852006-02-03 16:08:03 +00001778 case Iop_AtanF64: case Iop_Yl2xF64: case Iop_Yl2xp1F64:
1779 case Iop_ScaleF64: case Iop_PRemF64: case Iop_PRem1F64:
1780 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_F64);
1781
1782 case Iop_PRemC3210F64: case Iop_PRem1C3210F64:
1783 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_I32);
1784
1785 case Iop_SinF64: case Iop_CosF64: case Iop_TanF64:
1786 case Iop_2xm1F64:
1787 case Iop_RoundF64toInt: BINARY(ity_RMode,Ity_F64, Ity_F64);
1788
sewardj40c80262006-02-08 19:30:46 +00001789 case Iop_MAddF64: case Iop_MSubF64:
1790 case Iop_MAddF64r32: case Iop_MSubF64r32:
1791 QUATERNARY(ity_RMode,Ity_F64,Ity_F64,Ity_F64, Ity_F64);
1792
sewardjb183b852006-02-03 16:08:03 +00001793 case Iop_Est5FRSqrt:
sewardj0f1ef862008-08-08 08:37:06 +00001794 case Iop_RoundF64toF64_NEAREST: case Iop_RoundF64toF64_NegINF:
1795 case Iop_RoundF64toF64_PosINF: case Iop_RoundF64toF64_ZERO:
sewardjb183b852006-02-03 16:08:03 +00001796 UNARY(Ity_F64, Ity_F64);
1797 case Iop_RoundF64toF32:
1798 BINARY(ity_RMode,Ity_F64, Ity_F64);
1799 case Iop_CalcFPRF:
1800 UNARY(Ity_F64, Ity_I32);
1801 case Iop_TruncF64asF32:
1802 UNARY(Ity_F64, Ity_F32);
sewardjbb53f8c2004-08-14 11:50:01 +00001803
cerionf294eb32005-11-16 17:21:10 +00001804 case Iop_I32UtoFx4:
1805 case Iop_I32StoFx4:
1806 case Iop_QFtoI32Ux4_RZ:
1807 case Iop_QFtoI32Sx4_RZ:
1808 case Iop_RoundF32x4_RM:
1809 case Iop_RoundF32x4_RP:
1810 case Iop_RoundF32x4_RN:
1811 case Iop_RoundF32x4_RZ:
1812 UNARY(Ity_V128, Ity_V128);
1813
sewardjb183b852006-02-03 16:08:03 +00001814 case Iop_64HLtoV128: BINARY(Ity_I64,Ity_I64, Ity_V128);
sewardjf0c1c582005-02-07 23:47:38 +00001815 case Iop_V128to64: case Iop_V128HIto64:
sewardjb183b852006-02-03 16:08:03 +00001816 UNARY(Ity_V128, Ity_I64);
sewardjc9a43662004-11-30 18:51:59 +00001817
sewardjb183b852006-02-03 16:08:03 +00001818 case Iop_V128to32: UNARY(Ity_V128, Ity_I32);
1819 case Iop_32UtoV128: UNARY(Ity_I32, Ity_V128);
1820 case Iop_64UtoV128: UNARY(Ity_I64, Ity_V128);
1821 case Iop_SetV128lo32: BINARY(Ity_V128,Ity_I32, Ity_V128);
1822 case Iop_SetV128lo64: BINARY(Ity_V128,Ity_I64, Ity_V128);
sewardj129b3d92004-12-05 15:42:05 +00001823
sewardjb183b852006-02-03 16:08:03 +00001824 case Iop_Dup8x16: UNARY(Ity_I8, Ity_V128);
1825 case Iop_Dup16x8: UNARY(Ity_I16, Ity_V128);
1826 case Iop_Dup32x4: UNARY(Ity_I32, Ity_V128);
cerionf887b3e2005-09-13 16:34:28 +00001827
sewardj1e6ad742004-12-02 16:16:11 +00001828 case Iop_CmpEQ32Fx4: case Iop_CmpLT32Fx4:
sewardj636ad762004-12-07 11:16:04 +00001829 case Iop_CmpEQ64Fx2: case Iop_CmpLT64Fx2:
sewardj1e6ad742004-12-02 16:16:11 +00001830 case Iop_CmpLE32Fx4: case Iop_CmpUN32Fx4:
sewardj636ad762004-12-07 11:16:04 +00001831 case Iop_CmpLE64Fx2: case Iop_CmpUN64Fx2:
cerion206c3642005-11-14 00:35:59 +00001832 case Iop_CmpGT32Fx4: case Iop_CmpGE32Fx4:
sewardj1e6ad742004-12-02 16:16:11 +00001833 case Iop_CmpEQ32F0x4: case Iop_CmpLT32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001834 case Iop_CmpEQ64F0x2: case Iop_CmpLT64F0x2:
sewardj1e6ad742004-12-02 16:16:11 +00001835 case Iop_CmpLE32F0x4: case Iop_CmpUN32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001836 case Iop_CmpLE64F0x2: case Iop_CmpUN64F0x2:
sewardj1e6ad742004-12-02 16:16:11 +00001837 case Iop_Add32Fx4: case Iop_Add32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001838 case Iop_Add64Fx2: case Iop_Add64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001839 case Iop_Div32Fx4: case Iop_Div32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001840 case Iop_Div64Fx2: case Iop_Div64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001841 case Iop_Max32Fx4: case Iop_Max32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001842 case Iop_Max64Fx2: case Iop_Max64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001843 case Iop_Min32Fx4: case Iop_Min32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001844 case Iop_Min64Fx2: case Iop_Min64F0x2:
sewardj9636b442004-12-04 01:38:37 +00001845 case Iop_Mul32Fx4: case Iop_Mul32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001846 case Iop_Mul64Fx2: case Iop_Mul64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001847 case Iop_Sub32Fx4: case Iop_Sub32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001848 case Iop_Sub64Fx2: case Iop_Sub64F0x2:
sewardjf0c1c582005-02-07 23:47:38 +00001849 case Iop_AndV128: case Iop_OrV128: case Iop_XorV128:
sewardj164f9272004-12-09 00:39:32 +00001850 case Iop_Add8x16: case Iop_Add16x8:
1851 case Iop_Add32x4: case Iop_Add64x2:
cerionf887b3e2005-09-13 16:34:28 +00001852 case Iop_QAdd8Ux16: case Iop_QAdd16Ux8: case Iop_QAdd32Ux4:
1853 case Iop_QAdd8Sx16: case Iop_QAdd16Sx8: case Iop_QAdd32Sx4:
sewardj164f9272004-12-09 00:39:32 +00001854 case Iop_Sub8x16: case Iop_Sub16x8:
1855 case Iop_Sub32x4: case Iop_Sub64x2:
cerionf887b3e2005-09-13 16:34:28 +00001856 case Iop_QSub8Ux16: case Iop_QSub16Ux8: case Iop_QSub32Ux4:
1857 case Iop_QSub8Sx16: case Iop_QSub16Sx8: case Iop_QSub32Sx4:
sewardj164f9272004-12-09 00:39:32 +00001858 case Iop_Mul16x8:
cerionf887b3e2005-09-13 16:34:28 +00001859 case Iop_MulHi16Ux8: case Iop_MulHi32Ux4:
1860 case Iop_MulHi16Sx8: case Iop_MulHi32Sx4:
cerion1ac656a2005-11-04 19:44:48 +00001861 case Iop_MullEven8Ux16: case Iop_MullEven16Ux8:
1862 case Iop_MullEven8Sx16: case Iop_MullEven16Sx8:
cerionf887b3e2005-09-13 16:34:28 +00001863 case Iop_Avg8Ux16: case Iop_Avg16Ux8: case Iop_Avg32Ux4:
1864 case Iop_Avg8Sx16: case Iop_Avg16Sx8: case Iop_Avg32Sx4:
1865 case Iop_Max8Sx16: case Iop_Max16Sx8: case Iop_Max32Sx4:
1866 case Iop_Max8Ux16: case Iop_Max16Ux8: case Iop_Max32Ux4:
1867 case Iop_Min8Sx16: case Iop_Min16Sx8: case Iop_Min32Sx4:
1868 case Iop_Min8Ux16: case Iop_Min16Ux8: case Iop_Min32Ux4:
sewardj164f9272004-12-09 00:39:32 +00001869 case Iop_CmpEQ8x16: case Iop_CmpEQ16x8: case Iop_CmpEQ32x4:
1870 case Iop_CmpGT8Sx16: case Iop_CmpGT16Sx8: case Iop_CmpGT32Sx4:
cerionf887b3e2005-09-13 16:34:28 +00001871 case Iop_CmpGT8Ux16: case Iop_CmpGT16Ux8: case Iop_CmpGT32Ux4:
1872 case Iop_Shl8x16: case Iop_Shl16x8: case Iop_Shl32x4:
1873 case Iop_Shr8x16: case Iop_Shr16x8: case Iop_Shr32x4:
1874 case Iop_Sar8x16: case Iop_Sar16x8: case Iop_Sar32x4:
sewardj1bee5612005-11-10 18:10:58 +00001875 case Iop_Rol8x16: case Iop_Rol16x8: case Iop_Rol32x4:
cerion9e7677b2005-09-13 17:25:41 +00001876 case Iop_QNarrow16Ux8: case Iop_QNarrow32Ux4:
sewardj164f9272004-12-09 00:39:32 +00001877 case Iop_QNarrow16Sx8: case Iop_QNarrow32Sx4:
sewardj1bee5612005-11-10 18:10:58 +00001878 case Iop_Narrow16x8: case Iop_Narrow32x4:
sewardj164f9272004-12-09 00:39:32 +00001879 case Iop_InterleaveHI8x16: case Iop_InterleaveHI16x8:
1880 case Iop_InterleaveHI32x4: case Iop_InterleaveHI64x2:
1881 case Iop_InterleaveLO8x16: case Iop_InterleaveLO16x8:
1882 case Iop_InterleaveLO32x4: case Iop_InterleaveLO64x2:
sewardjdc1f9132005-10-22 12:49:49 +00001883 case Iop_Perm8x16:
sewardjb183b852006-02-03 16:08:03 +00001884 BINARY(Ity_V128,Ity_V128, Ity_V128);
sewardjc9a43662004-11-30 18:51:59 +00001885
sewardjf0c1c582005-02-07 23:47:38 +00001886 case Iop_NotV128:
sewardj0bd7ce62004-12-05 02:47:40 +00001887 case Iop_Recip32Fx4: case Iop_Recip32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001888 case Iop_Recip64Fx2: case Iop_Recip64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001889 case Iop_RSqrt32Fx4: case Iop_RSqrt32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001890 case Iop_RSqrt64Fx2: case Iop_RSqrt64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001891 case Iop_Sqrt32Fx4: case Iop_Sqrt32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001892 case Iop_Sqrt64Fx2: case Iop_Sqrt64F0x2:
sewardj2e383862004-12-12 16:46:47 +00001893 case Iop_CmpNEZ8x16: case Iop_CmpNEZ16x8:
sewardj109ffdb2004-12-10 21:45:38 +00001894 case Iop_CmpNEZ32x4: case Iop_CmpNEZ64x2:
sewardj0bd7ce62004-12-05 02:47:40 +00001895 UNARY(Ity_V128, Ity_V128);
1896
cerionf887b3e2005-09-13 16:34:28 +00001897 case Iop_ShlV128: case Iop_ShrV128:
sewardjb183b852006-02-03 16:08:03 +00001898 case Iop_ShlN8x16: case Iop_ShlN16x8:
1899 case Iop_ShlN32x4: case Iop_ShlN64x2:
1900 case Iop_ShrN8x16: case Iop_ShrN16x8:
1901 case Iop_ShrN32x4: case Iop_ShrN64x2:
cerion2a4b8452005-09-15 16:28:36 +00001902 case Iop_SarN8x16: case Iop_SarN16x8: case Iop_SarN32x4:
sewardjb183b852006-02-03 16:08:03 +00001903 BINARY(Ity_V128,Ity_I8, Ity_V128);
sewardj164f9272004-12-09 00:39:32 +00001904
sewardj6efd4a12004-07-15 03:54:23 +00001905 default:
1906 ppIROp(op);
1907 vpanic("typeOfPrimop");
1908 }
1909# undef UNARY
1910# undef BINARY
sewardjb183b852006-02-03 16:08:03 +00001911# undef TERNARY
sewardj6efd4a12004-07-15 03:54:23 +00001912# undef COMPARISON
sewardj0033ddc2005-04-26 23:34:34 +00001913# undef UNARY_COMPARISON
sewardj6efd4a12004-07-15 03:54:23 +00001914}
1915
1916
1917/*---------------------------------------------------------------*/
sewardj695cff92004-10-13 14:50:14 +00001918/*--- Helper functions for the IR -- IR Basic Blocks ---*/
sewardjc97096c2004-06-30 09:28:04 +00001919/*---------------------------------------------------------------*/
1920
sewardjdd40fdf2006-12-24 02:20:24 +00001921void addStmtToIRSB ( IRSB* bb, IRStmt* st )
sewardjd7cb8532004-08-17 23:59:23 +00001922{
1923 Int i;
sewardj695cff92004-10-13 14:50:14 +00001924 if (bb->stmts_used == bb->stmts_size) {
1925 IRStmt** stmts2 = LibVEX_Alloc(2 * bb->stmts_size * sizeof(IRStmt*));
1926 for (i = 0; i < bb->stmts_size; i++)
1927 stmts2[i] = bb->stmts[i];
1928 bb->stmts = stmts2;
1929 bb->stmts_size *= 2;
1930 }
1931 vassert(bb->stmts_used < bb->stmts_size);
1932 bb->stmts[bb->stmts_used] = st;
1933 bb->stmts_used++;
sewardjd7cb8532004-08-17 23:59:23 +00001934}
1935
sewardj695cff92004-10-13 14:50:14 +00001936
1937/*---------------------------------------------------------------*/
1938/*--- Helper functions for the IR -- IR Type Environments ---*/
1939/*---------------------------------------------------------------*/
1940
sewardjd7cb8532004-08-17 23:59:23 +00001941/* Allocate a new IRTemp, given its type. */
sewardje3d0d2e2004-06-27 10:42:44 +00001942
sewardje539a402004-07-14 18:24:17 +00001943IRTemp newIRTemp ( IRTypeEnv* env, IRType ty )
sewardjc97096c2004-06-30 09:28:04 +00001944{
sewardj35421a32004-07-05 13:12:34 +00001945 vassert(env);
sewardje539a402004-07-14 18:24:17 +00001946 vassert(env->types_used >= 0);
1947 vassert(env->types_size >= 0);
1948 vassert(env->types_used <= env->types_size);
1949 if (env->types_used < env->types_size) {
1950 env->types[env->types_used] = ty;
1951 return env->types_used++;
sewardjc97096c2004-06-30 09:28:04 +00001952 } else {
1953 Int i;
sewardje539a402004-07-14 18:24:17 +00001954 Int new_size = env->types_size==0 ? 8 : 2*env->types_size;
1955 IRType* new_types
1956 = LibVEX_Alloc(new_size * sizeof(IRType));
1957 for (i = 0; i < env->types_used; i++)
1958 new_types[i] = env->types[i];
1959 env->types = new_types;
1960 env->types_size = new_size;
1961 return newIRTemp(env, ty);
sewardjc97096c2004-06-30 09:28:04 +00001962 }
1963}
1964
1965
sewardj17442fe2004-09-20 14:54:28 +00001966/*---------------------------------------------------------------*/
1967/*--- Helper functions for the IR -- finding types of exprs ---*/
1968/*---------------------------------------------------------------*/
1969
sewardjedeb4c42004-09-21 23:39:25 +00001970inline
sewardj17442fe2004-09-20 14:54:28 +00001971IRType typeOfIRTemp ( IRTypeEnv* env, IRTemp tmp )
sewardjc97096c2004-06-30 09:28:04 +00001972{
sewardje539a402004-07-14 18:24:17 +00001973 vassert(tmp >= 0);
1974 vassert(tmp < env->types_used);
1975 return env->types[tmp];
sewardjc97096c2004-06-30 09:28:04 +00001976}
1977
1978
sewardj6efd4a12004-07-15 03:54:23 +00001979IRType typeOfIRConst ( IRConst* con )
1980{
1981 switch (con->tag) {
sewardjba999312004-11-15 15:21:17 +00001982 case Ico_U1: return Ity_I1;
sewardj207557a2004-08-27 12:00:18 +00001983 case Ico_U8: return Ity_I8;
1984 case Ico_U16: return Ity_I16;
1985 case Ico_U32: return Ity_I32;
1986 case Ico_U64: return Ity_I64;
1987 case Ico_F64: return Ity_F64;
sewardj17442fe2004-09-20 14:54:28 +00001988 case Ico_F64i: return Ity_F64;
sewardj1e6ad742004-12-02 16:16:11 +00001989 case Ico_V128: return Ity_V128;
sewardj6efd4a12004-07-15 03:54:23 +00001990 default: vpanic("typeOfIRConst");
1991 }
1992}
1993
sewardjc97096c2004-06-30 09:28:04 +00001994IRType typeOfIRExpr ( IRTypeEnv* tyenv, IRExpr* e )
1995{
sewardj40c80262006-02-08 19:30:46 +00001996 IRType t_dst, t_arg1, t_arg2, t_arg3, t_arg4;
sewardjedeb4c42004-09-21 23:39:25 +00001997 start:
sewardjc97096c2004-06-30 09:28:04 +00001998 switch (e->tag) {
sewardjaf1ceca2005-06-30 23:31:27 +00001999 case Iex_Load:
2000 return e->Iex.Load.ty;
sewardjfbcaf332004-07-08 01:46:01 +00002001 case Iex_Get:
2002 return e->Iex.Get.ty;
sewardjbb53f8c2004-08-14 11:50:01 +00002003 case Iex_GetI:
sewardj2d3f77c2004-09-22 23:49:09 +00002004 return e->Iex.GetI.descr->elemTy;
sewardjdd40fdf2006-12-24 02:20:24 +00002005 case Iex_RdTmp:
2006 return typeOfIRTemp(tyenv, e->Iex.RdTmp.tmp);
sewardjc97096c2004-06-30 09:28:04 +00002007 case Iex_Const:
sewardj695cff92004-10-13 14:50:14 +00002008 return typeOfIRConst(e->Iex.Const.con);
sewardj40c80262006-02-08 19:30:46 +00002009 case Iex_Qop:
2010 typeOfPrimop(e->Iex.Qop.op,
2011 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
2012 return t_dst;
sewardjb183b852006-02-03 16:08:03 +00002013 case Iex_Triop:
sewardj40c80262006-02-08 19:30:46 +00002014 typeOfPrimop(e->Iex.Triop.op,
2015 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002016 return t_dst;
sewardjc97096c2004-06-30 09:28:04 +00002017 case Iex_Binop:
sewardj40c80262006-02-08 19:30:46 +00002018 typeOfPrimop(e->Iex.Binop.op,
2019 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardj6efd4a12004-07-15 03:54:23 +00002020 return t_dst;
2021 case Iex_Unop:
sewardj40c80262006-02-08 19:30:46 +00002022 typeOfPrimop(e->Iex.Unop.op,
2023 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardj6efd4a12004-07-15 03:54:23 +00002024 return t_dst;
2025 case Iex_CCall:
2026 return e->Iex.CCall.retty;
sewardj4042c7e2004-07-18 01:28:30 +00002027 case Iex_Mux0X:
sewardjedeb4c42004-09-21 23:39:25 +00002028 e = e->Iex.Mux0X.expr0;
2029 goto start;
2030 /* return typeOfIRExpr(tyenv, e->Iex.Mux0X.expr0); */
sewardj443cd9d2004-07-18 23:06:45 +00002031 case Iex_Binder:
2032 vpanic("typeOfIRExpr: Binder is not a valid expression");
sewardjc97096c2004-06-30 09:28:04 +00002033 default:
sewardj6efd4a12004-07-15 03:54:23 +00002034 ppIRExpr(e);
2035 vpanic("typeOfIRExpr");
sewardjc97096c2004-06-30 09:28:04 +00002036 }
sewardjc97096c2004-06-30 09:28:04 +00002037}
sewardj887a11a2004-07-05 17:26:47 +00002038
sewardj6d2638e2004-07-15 09:38:27 +00002039/* Is this any value actually in the enumeration 'IRType' ? */
sewardj496a58d2005-03-20 18:44:44 +00002040Bool isPlausibleIRType ( IRType ty )
sewardj6d2638e2004-07-15 09:38:27 +00002041{
2042 switch (ty) {
sewardjba999312004-11-15 15:21:17 +00002043 case Ity_INVALID: case Ity_I1:
sewardj9b967672005-02-08 11:13:09 +00002044 case Ity_I8: case Ity_I16: case Ity_I32:
2045 case Ity_I64: case Ity_I128:
sewardjbb53f8c2004-08-14 11:50:01 +00002046 case Ity_F32: case Ity_F64:
sewardjc9a43662004-11-30 18:51:59 +00002047 case Ity_V128:
sewardj6d2638e2004-07-15 09:38:27 +00002048 return True;
2049 default:
2050 return False;
2051 }
2052}
2053
sewardj6efd4a12004-07-15 03:54:23 +00002054
sewardj887a11a2004-07-05 17:26:47 +00002055/*---------------------------------------------------------------*/
sewardjcf787902004-11-03 09:08:33 +00002056/*--- Sanity checking -- FLATNESS ---*/
2057/*---------------------------------------------------------------*/
2058
2059/* Check that the canonical flatness constraints hold on an
2060 IRStmt. The only place where any expression is allowed to be
2061 non-atomic is the RHS of IRStmt_Tmp. */
2062
2063/* Relies on:
2064 inline static Bool isAtom ( IRExpr* e ) {
sewardjdd40fdf2006-12-24 02:20:24 +00002065 return e->tag == Iex_RdTmp || e->tag == Iex_Const;
sewardjcf787902004-11-03 09:08:33 +00002066 }
2067*/
2068
2069Bool isFlatIRStmt ( IRStmt* st )
2070{
2071 Int i;
2072 IRExpr* e;
2073 IRDirty* di;
sewardje9d8a262009-07-01 08:06:34 +00002074 IRCAS* cas;
sewardjcf787902004-11-03 09:08:33 +00002075
2076 switch (st->tag) {
sewardj5a9ffab2005-05-12 17:55:01 +00002077 case Ist_AbiHint:
sewardj478646f2008-05-01 20:13:04 +00002078 return isIRAtom(st->Ist.AbiHint.base)
2079 && isIRAtom(st->Ist.AbiHint.nia);
sewardjcf787902004-11-03 09:08:33 +00002080 case Ist_Put:
sewardj496a58d2005-03-20 18:44:44 +00002081 return isIRAtom(st->Ist.Put.data);
sewardjcf787902004-11-03 09:08:33 +00002082 case Ist_PutI:
sewardj496a58d2005-03-20 18:44:44 +00002083 return toBool( isIRAtom(st->Ist.PutI.ix)
2084 && isIRAtom(st->Ist.PutI.data) );
sewardjdd40fdf2006-12-24 02:20:24 +00002085 case Ist_WrTmp:
sewardjcf787902004-11-03 09:08:33 +00002086 /* This is the only interesting case. The RHS can be any
2087 expression, *but* all its subexpressions *must* be
2088 atoms. */
sewardjdd40fdf2006-12-24 02:20:24 +00002089 e = st->Ist.WrTmp.data;
sewardjcf787902004-11-03 09:08:33 +00002090 switch (e->tag) {
2091 case Iex_Binder: return True;
2092 case Iex_Get: return True;
sewardj496a58d2005-03-20 18:44:44 +00002093 case Iex_GetI: return isIRAtom(e->Iex.GetI.ix);
sewardjdd40fdf2006-12-24 02:20:24 +00002094 case Iex_RdTmp: return True;
sewardj40c80262006-02-08 19:30:46 +00002095 case Iex_Qop: return toBool(
2096 isIRAtom(e->Iex.Qop.arg1)
2097 && isIRAtom(e->Iex.Qop.arg2)
2098 && isIRAtom(e->Iex.Qop.arg3)
2099 && isIRAtom(e->Iex.Qop.arg4));
sewardjb183b852006-02-03 16:08:03 +00002100 case Iex_Triop: return toBool(
2101 isIRAtom(e->Iex.Triop.arg1)
2102 && isIRAtom(e->Iex.Triop.arg2)
2103 && isIRAtom(e->Iex.Triop.arg3));
sewardja98bf492005-02-07 01:39:17 +00002104 case Iex_Binop: return toBool(
sewardj496a58d2005-03-20 18:44:44 +00002105 isIRAtom(e->Iex.Binop.arg1)
2106 && isIRAtom(e->Iex.Binop.arg2));
2107 case Iex_Unop: return isIRAtom(e->Iex.Unop.arg);
sewardjaf1ceca2005-06-30 23:31:27 +00002108 case Iex_Load: return isIRAtom(e->Iex.Load.addr);
sewardjcf787902004-11-03 09:08:33 +00002109 case Iex_Const: return True;
2110 case Iex_CCall: for (i = 0; e->Iex.CCall.args[i]; i++)
sewardj496a58d2005-03-20 18:44:44 +00002111 if (!isIRAtom(e->Iex.CCall.args[i]))
sewardjcf787902004-11-03 09:08:33 +00002112 return False;
2113 return True;
sewardja98bf492005-02-07 01:39:17 +00002114 case Iex_Mux0X: return toBool (
sewardj496a58d2005-03-20 18:44:44 +00002115 isIRAtom(e->Iex.Mux0X.cond)
2116 && isIRAtom(e->Iex.Mux0X.expr0)
2117 && isIRAtom(e->Iex.Mux0X.exprX));
sewardjcf787902004-11-03 09:08:33 +00002118 default: vpanic("isFlatIRStmt(e)");
2119 }
2120 /*notreached*/
2121 vassert(0);
sewardjaf1ceca2005-06-30 23:31:27 +00002122 case Ist_Store:
2123 return toBool( isIRAtom(st->Ist.Store.addr)
2124 && isIRAtom(st->Ist.Store.data) );
sewardje9d8a262009-07-01 08:06:34 +00002125 case Ist_CAS:
2126 cas = st->Ist.CAS.details;
2127 return toBool( isIRAtom(cas->addr)
2128 && (cas->expdHi ? isIRAtom(cas->expdHi) : True)
2129 && isIRAtom(cas->expdLo)
2130 && (cas->dataHi ? isIRAtom(cas->dataHi) : True)
2131 && isIRAtom(cas->dataLo) );
sewardjcf787902004-11-03 09:08:33 +00002132 case Ist_Dirty:
2133 di = st->Ist.Dirty.details;
sewardj496a58d2005-03-20 18:44:44 +00002134 if (!isIRAtom(di->guard))
sewardjcf787902004-11-03 09:08:33 +00002135 return False;
2136 for (i = 0; di->args[i]; i++)
sewardj496a58d2005-03-20 18:44:44 +00002137 if (!isIRAtom(di->args[i]))
sewardjcf787902004-11-03 09:08:33 +00002138 return False;
sewardj496a58d2005-03-20 18:44:44 +00002139 if (di->mAddr && !isIRAtom(di->mAddr))
sewardjcf787902004-11-03 09:08:33 +00002140 return False;
2141 return True;
sewardjd2445f62005-03-21 00:15:53 +00002142 case Ist_NoOp:
sewardjf1689312005-03-16 18:19:10 +00002143 case Ist_IMark:
sewardjc4356f02007-11-09 21:15:04 +00002144 case Ist_MBE:
sewardj3e838932005-01-07 12:09:15 +00002145 return True;
sewardjcf787902004-11-03 09:08:33 +00002146 case Ist_Exit:
sewardj496a58d2005-03-20 18:44:44 +00002147 return isIRAtom(st->Ist.Exit.guard);
sewardjcf787902004-11-03 09:08:33 +00002148 default:
2149 vpanic("isFlatIRStmt(st)");
2150 }
2151}
2152
2153
2154/*---------------------------------------------------------------*/
sewardje539a402004-07-14 18:24:17 +00002155/*--- Sanity checking ---*/
2156/*---------------------------------------------------------------*/
2157
2158/* Checks:
2159
2160 Everything is type-consistent. No ill-typed anything.
sewardj35439212004-07-14 22:36:10 +00002161 The target address at the end of the BB is a 32- or 64-
2162 bit expression, depending on the guest's word size.
sewardje539a402004-07-14 18:24:17 +00002163
2164 Each temp is assigned only once, before its uses.
sewardjc13e2ed2004-10-31 21:44:54 +00002165*/
2166
2167static inline Int countArgs ( IRExpr** args )
2168{
2169 Int i;
2170 for (i = 0; args[i]; i++)
2171 ;
2172 return i;
2173}
sewardje539a402004-07-14 18:24:17 +00002174
sewardj35439212004-07-14 22:36:10 +00002175static
2176__attribute((noreturn))
sewardjdd40fdf2006-12-24 02:20:24 +00002177void sanityCheckFail ( IRSB* bb, IRStmt* stmt, HChar* what )
sewardje539a402004-07-14 18:24:17 +00002178{
sewardj35439212004-07-14 22:36:10 +00002179 vex_printf("\nIR SANITY CHECK FAILURE\n\n");
sewardjdd40fdf2006-12-24 02:20:24 +00002180 ppIRSB(bb);
sewardj35439212004-07-14 22:36:10 +00002181 if (stmt) {
2182 vex_printf("\nIN STATEMENT:\n\n");
2183 ppIRStmt(stmt);
2184 }
2185 vex_printf("\n\nERROR = %s\n\n", what );
2186 vpanic("sanityCheckFail: exiting due to bad IR");
2187}
2188
sewardjdd40fdf2006-12-24 02:20:24 +00002189static Bool saneIRRegArray ( IRRegArray* arr )
sewardj2d3f77c2004-09-22 23:49:09 +00002190{
2191 if (arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */)
2192 return False;
sewardjba999312004-11-15 15:21:17 +00002193 if (arr->elemTy == Ity_I1)
sewardj2d3f77c2004-09-22 23:49:09 +00002194 return False;
2195 if (arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */)
2196 return False;
2197 return True;
2198}
2199
sewardj8ea867b2004-10-30 19:03:02 +00002200static Bool saneIRCallee ( IRCallee* cee )
2201{
2202 if (cee->name == NULL)
2203 return False;
2204 if (cee->addr == 0)
2205 return False;
sewardj77352542004-10-30 20:39:01 +00002206 if (cee->regparms < 0 || cee->regparms > 3)
sewardj8ea867b2004-10-30 19:03:02 +00002207 return False;
2208 return True;
2209}
2210
sewardj49bfe672004-11-15 15:46:26 +00002211static Bool saneIRConst ( IRConst* con )
2212{
2213 switch (con->tag) {
2214 case Ico_U1:
sewardja98bf492005-02-07 01:39:17 +00002215 return toBool( con->Ico.U1 == True || con->Ico.U1 == False );
sewardj49bfe672004-11-15 15:46:26 +00002216 default:
2217 /* Is there anything we can meaningfully check? I don't
2218 think so. */
2219 return True;
2220 }
2221}
sewardj35439212004-07-14 22:36:10 +00002222
2223/* Traverse a Stmt/Expr, inspecting IRTemp uses. Report any out of
2224 range ones. Report any which are read and for which the current
2225 def_count is zero. */
2226
2227static
sewardjdd40fdf2006-12-24 02:20:24 +00002228void useBeforeDef_Temp ( IRSB* bb, IRStmt* stmt, IRTemp tmp, Int* def_counts )
sewardj17442fe2004-09-20 14:54:28 +00002229{
2230 if (tmp < 0 || tmp >= bb->tyenv->types_used)
2231 sanityCheckFail(bb,stmt, "out of range Temp in IRExpr");
2232 if (def_counts[tmp] < 1)
2233 sanityCheckFail(bb,stmt, "IRTemp use before def in IRExpr");
2234}
2235
2236static
sewardjdd40fdf2006-12-24 02:20:24 +00002237void useBeforeDef_Expr ( IRSB* bb, IRStmt* stmt, IRExpr* expr, Int* def_counts )
sewardj35439212004-07-14 22:36:10 +00002238{
2239 Int i;
2240 switch (expr->tag) {
2241 case Iex_Get:
2242 break;
sewardjbb53f8c2004-08-14 11:50:01 +00002243 case Iex_GetI:
sewardjeeac8412004-11-02 00:26:55 +00002244 useBeforeDef_Expr(bb,stmt,expr->Iex.GetI.ix,def_counts);
sewardjbb53f8c2004-08-14 11:50:01 +00002245 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002246 case Iex_RdTmp:
2247 useBeforeDef_Temp(bb,stmt,expr->Iex.RdTmp.tmp,def_counts);
sewardj35439212004-07-14 22:36:10 +00002248 break;
sewardj40c80262006-02-08 19:30:46 +00002249 case Iex_Qop:
2250 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg1,def_counts);
2251 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg2,def_counts);
2252 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg3,def_counts);
2253 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg4,def_counts);
2254 break;
sewardjb183b852006-02-03 16:08:03 +00002255 case Iex_Triop:
2256 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg1,def_counts);
2257 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg2,def_counts);
2258 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg3,def_counts);
2259 break;
sewardj35439212004-07-14 22:36:10 +00002260 case Iex_Binop:
2261 useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg1,def_counts);
2262 useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg2,def_counts);
2263 break;
2264 case Iex_Unop:
2265 useBeforeDef_Expr(bb,stmt,expr->Iex.Unop.arg,def_counts);
2266 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002267 case Iex_Load:
2268 useBeforeDef_Expr(bb,stmt,expr->Iex.Load.addr,def_counts);
sewardj35439212004-07-14 22:36:10 +00002269 break;
2270 case Iex_Const:
2271 break;
2272 case Iex_CCall:
2273 for (i = 0; expr->Iex.CCall.args[i]; i++)
2274 useBeforeDef_Expr(bb,stmt,expr->Iex.CCall.args[i],def_counts);
2275 break;
sewardj4042c7e2004-07-18 01:28:30 +00002276 case Iex_Mux0X:
2277 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.cond,def_counts);
2278 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.expr0,def_counts);
2279 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.exprX,def_counts);
sewardjeeb9ef82004-07-15 12:39:03 +00002280 break;
2281 default:
2282 vpanic("useBeforeDef_Expr");
sewardj35439212004-07-14 22:36:10 +00002283 }
2284}
2285
2286static
sewardjdd40fdf2006-12-24 02:20:24 +00002287void useBeforeDef_Stmt ( IRSB* bb, IRStmt* stmt, Int* def_counts )
sewardj35439212004-07-14 22:36:10 +00002288{
sewardj17442fe2004-09-20 14:54:28 +00002289 Int i;
2290 IRDirty* d;
sewardje9d8a262009-07-01 08:06:34 +00002291 IRCAS* cas;
sewardj35439212004-07-14 22:36:10 +00002292 switch (stmt->tag) {
sewardjf1689312005-03-16 18:19:10 +00002293 case Ist_IMark:
2294 break;
sewardj5a9ffab2005-05-12 17:55:01 +00002295 case Ist_AbiHint:
2296 useBeforeDef_Expr(bb,stmt,stmt->Ist.AbiHint.base,def_counts);
sewardj478646f2008-05-01 20:13:04 +00002297 useBeforeDef_Expr(bb,stmt,stmt->Ist.AbiHint.nia,def_counts);
sewardj5a9ffab2005-05-12 17:55:01 +00002298 break;
sewardj35439212004-07-14 22:36:10 +00002299 case Ist_Put:
sewardj6d076362004-09-23 11:06:17 +00002300 useBeforeDef_Expr(bb,stmt,stmt->Ist.Put.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002301 break;
sewardjd1725d12004-08-12 20:46:53 +00002302 case Ist_PutI:
sewardjeeac8412004-11-02 00:26:55 +00002303 useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.ix,def_counts);
sewardj2d3f77c2004-09-22 23:49:09 +00002304 useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.data,def_counts);
sewardjd1725d12004-08-12 20:46:53 +00002305 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002306 case Ist_WrTmp:
2307 useBeforeDef_Expr(bb,stmt,stmt->Ist.WrTmp.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002308 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002309 case Ist_Store:
2310 useBeforeDef_Expr(bb,stmt,stmt->Ist.Store.addr,def_counts);
2311 useBeforeDef_Expr(bb,stmt,stmt->Ist.Store.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002312 break;
sewardje9d8a262009-07-01 08:06:34 +00002313 case Ist_CAS:
2314 cas = stmt->Ist.CAS.details;
2315 useBeforeDef_Expr(bb,stmt,cas->addr,def_counts);
2316 if (cas->expdHi)
2317 useBeforeDef_Expr(bb,stmt,cas->expdHi,def_counts);
2318 useBeforeDef_Expr(bb,stmt,cas->expdLo,def_counts);
2319 if (cas->dataHi)
2320 useBeforeDef_Expr(bb,stmt,cas->dataHi,def_counts);
2321 useBeforeDef_Expr(bb,stmt,cas->dataLo,def_counts);
2322 break;
sewardj17442fe2004-09-20 14:54:28 +00002323 case Ist_Dirty:
2324 d = stmt->Ist.Dirty.details;
2325 for (i = 0; d->args[i] != NULL; i++)
2326 useBeforeDef_Expr(bb,stmt,d->args[i],def_counts);
2327 if (d->mFx != Ifx_None)
2328 useBeforeDef_Expr(bb,stmt,d->mAddr,def_counts);
2329 break;
sewardjd2445f62005-03-21 00:15:53 +00002330 case Ist_NoOp:
sewardjc4356f02007-11-09 21:15:04 +00002331 case Ist_MBE:
sewardj3e838932005-01-07 12:09:15 +00002332 break;
sewardj35439212004-07-14 22:36:10 +00002333 case Ist_Exit:
sewardj0276d4b2004-11-15 15:30:21 +00002334 useBeforeDef_Expr(bb,stmt,stmt->Ist.Exit.guard,def_counts);
sewardj35439212004-07-14 22:36:10 +00002335 break;
2336 default:
2337 vpanic("useBeforeDef_Stmt");
2338 }
2339}
2340
sewardj6efd4a12004-07-15 03:54:23 +00002341static
sewardjdd40fdf2006-12-24 02:20:24 +00002342void tcExpr ( IRSB* bb, IRStmt* stmt, IRExpr* expr, IRType gWordTy )
sewardj6efd4a12004-07-15 03:54:23 +00002343{
2344 Int i;
sewardj40c80262006-02-08 19:30:46 +00002345 IRType t_dst, t_arg1, t_arg2, t_arg3, t_arg4;
sewardj6efd4a12004-07-15 03:54:23 +00002346 IRTypeEnv* tyenv = bb->tyenv;
2347 switch (expr->tag) {
2348 case Iex_Get:
sewardjdd40fdf2006-12-24 02:20:24 +00002349 case Iex_RdTmp:
sewardj6efd4a12004-07-15 03:54:23 +00002350 break;
sewardjbb53f8c2004-08-14 11:50:01 +00002351 case Iex_GetI:
sewardjeeac8412004-11-02 00:26:55 +00002352 tcExpr(bb,stmt, expr->Iex.GetI.ix, gWordTy );
2353 if (typeOfIRExpr(tyenv,expr->Iex.GetI.ix) != Ity_I32)
2354 sanityCheckFail(bb,stmt,"IRExpr.GetI.ix: not :: Ity_I32");
sewardjdd40fdf2006-12-24 02:20:24 +00002355 if (!saneIRRegArray(expr->Iex.GetI.descr))
sewardj2d3f77c2004-09-22 23:49:09 +00002356 sanityCheckFail(bb,stmt,"IRExpr.GetI.descr: invalid descr");
sewardjbb53f8c2004-08-14 11:50:01 +00002357 break;
sewardj40c80262006-02-08 19:30:46 +00002358 case Iex_Qop: {
2359 IRType ttarg1, ttarg2, ttarg3, ttarg4;
2360 tcExpr(bb,stmt, expr->Iex.Qop.arg1, gWordTy );
2361 tcExpr(bb,stmt, expr->Iex.Qop.arg2, gWordTy );
2362 tcExpr(bb,stmt, expr->Iex.Qop.arg3, gWordTy );
2363 tcExpr(bb,stmt, expr->Iex.Qop.arg4, gWordTy );
2364 typeOfPrimop(expr->Iex.Qop.op,
2365 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
2366 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
2367 || t_arg3 == Ity_INVALID || t_arg4 == Ity_INVALID) {
2368 vex_printf(" op name: " );
2369 ppIROp(expr->Iex.Qop.op);
2370 vex_printf("\n");
2371 sanityCheckFail(bb,stmt,
2372 "Iex.Qop: wrong arity op\n"
2373 "... name of op precedes BB printout\n");
2374 }
2375 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg1);
2376 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg2);
2377 ttarg3 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg3);
2378 ttarg4 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg4);
2379 if (t_arg1 != ttarg1 || t_arg2 != ttarg2
2380 || t_arg3 != ttarg3 || t_arg4 != ttarg4) {
2381 vex_printf(" op name: ");
2382 ppIROp(expr->Iex.Qop.op);
2383 vex_printf("\n");
2384 vex_printf(" op type is (");
2385 ppIRType(t_arg1);
2386 vex_printf(",");
2387 ppIRType(t_arg2);
2388 vex_printf(",");
2389 ppIRType(t_arg3);
2390 vex_printf(",");
2391 ppIRType(t_arg4);
2392 vex_printf(") -> ");
2393 ppIRType (t_dst);
2394 vex_printf("\narg tys are (");
2395 ppIRType(ttarg1);
2396 vex_printf(",");
2397 ppIRType(ttarg2);
2398 vex_printf(",");
2399 ppIRType(ttarg3);
2400 vex_printf(",");
2401 ppIRType(ttarg4);
2402 vex_printf(")\n");
2403 sanityCheckFail(bb,stmt,
2404 "Iex.Qop: arg tys don't match op tys\n"
2405 "... additional details precede BB printout\n");
2406 }
2407 break;
2408 }
sewardjb183b852006-02-03 16:08:03 +00002409 case Iex_Triop: {
2410 IRType ttarg1, ttarg2, ttarg3;
2411 tcExpr(bb,stmt, expr->Iex.Triop.arg1, gWordTy );
2412 tcExpr(bb,stmt, expr->Iex.Triop.arg2, gWordTy );
2413 tcExpr(bb,stmt, expr->Iex.Triop.arg3, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002414 typeOfPrimop(expr->Iex.Triop.op,
2415 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002416 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002417 || t_arg3 == Ity_INVALID || t_arg4 != Ity_INVALID) {
sewardjb183b852006-02-03 16:08:03 +00002418 vex_printf(" op name: " );
2419 ppIROp(expr->Iex.Triop.op);
2420 vex_printf("\n");
2421 sanityCheckFail(bb,stmt,
2422 "Iex.Triop: wrong arity op\n"
2423 "... name of op precedes BB printout\n");
2424 }
2425 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg1);
2426 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg2);
2427 ttarg3 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg3);
2428 if (t_arg1 != ttarg1 || t_arg2 != ttarg2 || t_arg3 != ttarg3) {
2429 vex_printf(" op name: ");
2430 ppIROp(expr->Iex.Triop.op);
2431 vex_printf("\n");
2432 vex_printf(" op type is (");
2433 ppIRType(t_arg1);
2434 vex_printf(",");
2435 ppIRType(t_arg2);
2436 vex_printf(",");
2437 ppIRType(t_arg3);
2438 vex_printf(") -> ");
2439 ppIRType (t_dst);
2440 vex_printf("\narg tys are (");
2441 ppIRType(ttarg1);
2442 vex_printf(",");
2443 ppIRType(ttarg2);
2444 vex_printf(",");
2445 ppIRType(ttarg3);
2446 vex_printf(")\n");
2447 sanityCheckFail(bb,stmt,
2448 "Iex.Triop: arg tys don't match op tys\n"
2449 "... additional details precede BB printout\n");
2450 }
2451 break;
2452 }
sewardj6d2638e2004-07-15 09:38:27 +00002453 case Iex_Binop: {
2454 IRType ttarg1, ttarg2;
sewardj6efd4a12004-07-15 03:54:23 +00002455 tcExpr(bb,stmt, expr->Iex.Binop.arg1, gWordTy );
2456 tcExpr(bb,stmt, expr->Iex.Binop.arg2, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002457 typeOfPrimop(expr->Iex.Binop.op,
2458 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002459 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002460 || t_arg3 != Ity_INVALID || t_arg4 != Ity_INVALID) {
sewardj8f3debf2004-09-08 23:42:23 +00002461 vex_printf(" op name: " );
2462 ppIROp(expr->Iex.Binop.op);
2463 vex_printf("\n");
2464 sanityCheckFail(bb,stmt,
2465 "Iex.Binop: wrong arity op\n"
2466 "... name of op precedes BB printout\n");
2467 }
sewardj6d2638e2004-07-15 09:38:27 +00002468 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg1);
2469 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg2);
2470 if (t_arg1 != ttarg1 || t_arg2 != ttarg2) {
2471 vex_printf(" op name: ");
2472 ppIROp(expr->Iex.Binop.op);
2473 vex_printf("\n");
2474 vex_printf(" op type is (");
2475 ppIRType(t_arg1);
2476 vex_printf(",");
2477 ppIRType(t_arg2);
2478 vex_printf(") -> ");
2479 ppIRType (t_dst);
2480 vex_printf("\narg tys are (");
2481 ppIRType(ttarg1);
2482 vex_printf(",");
2483 ppIRType(ttarg2);
2484 vex_printf(")\n");
2485 sanityCheckFail(bb,stmt,
2486 "Iex.Binop: arg tys don't match op tys\n"
2487 "... additional details precede BB printout\n");
sewardj695cff92004-10-13 14:50:14 +00002488 }
sewardj6efd4a12004-07-15 03:54:23 +00002489 break;
sewardj6d2638e2004-07-15 09:38:27 +00002490 }
sewardj6efd4a12004-07-15 03:54:23 +00002491 case Iex_Unop:
2492 tcExpr(bb,stmt, expr->Iex.Unop.arg, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002493 typeOfPrimop(expr->Iex.Binop.op,
2494 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002495 if (t_arg1 == Ity_INVALID || t_arg2 != Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002496 || t_arg3 != Ity_INVALID || t_arg4 != Ity_INVALID)
sewardj6efd4a12004-07-15 03:54:23 +00002497 sanityCheckFail(bb,stmt,"Iex.Unop: wrong arity op");
2498 if (t_arg1 != typeOfIRExpr(tyenv, expr->Iex.Unop.arg))
2499 sanityCheckFail(bb,stmt,"Iex.Unop: arg ty doesn't match op ty");
2500 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002501 case Iex_Load:
2502 tcExpr(bb,stmt, expr->Iex.Load.addr, gWordTy);
2503 if (typeOfIRExpr(tyenv, expr->Iex.Load.addr) != gWordTy)
2504 sanityCheckFail(bb,stmt,"Iex.Load.addr: not :: guest word type");
2505 if (expr->Iex.Load.end != Iend_LE && expr->Iex.Load.end != Iend_BE)
2506 sanityCheckFail(bb,stmt,"Iex.Load.end: bogus endianness");
sewardj6efd4a12004-07-15 03:54:23 +00002507 break;
2508 case Iex_CCall:
sewardjc13e2ed2004-10-31 21:44:54 +00002509 if (!saneIRCallee(expr->Iex.CCall.cee))
2510 sanityCheckFail(bb,stmt,"Iex.CCall.cee: bad IRCallee");
sewardjcf787902004-11-03 09:08:33 +00002511 if (expr->Iex.CCall.cee->regparms > countArgs(expr->Iex.CCall.args))
sewardjc13e2ed2004-10-31 21:44:54 +00002512 sanityCheckFail(bb,stmt,"Iex.CCall.cee: #regparms > #args");
sewardj43c56462004-11-06 12:17:57 +00002513 for (i = 0; expr->Iex.CCall.args[i]; i++) {
2514 if (i >= 32)
2515 sanityCheckFail(bb,stmt,"Iex.CCall: > 32 args");
sewardj6efd4a12004-07-15 03:54:23 +00002516 tcExpr(bb,stmt, expr->Iex.CCall.args[i], gWordTy);
sewardj43c56462004-11-06 12:17:57 +00002517 }
sewardjba999312004-11-15 15:21:17 +00002518 if (expr->Iex.CCall.retty == Ity_I1)
2519 sanityCheckFail(bb,stmt,"Iex.CCall.retty: cannot return :: Ity_I1");
sewardj6efd4a12004-07-15 03:54:23 +00002520 for (i = 0; expr->Iex.CCall.args[i]; i++)
sewardjba999312004-11-15 15:21:17 +00002521 if (typeOfIRExpr(tyenv, expr->Iex.CCall.args[i]) == Ity_I1)
2522 sanityCheckFail(bb,stmt,"Iex.CCall.arg: arg :: Ity_I1");
sewardj6efd4a12004-07-15 03:54:23 +00002523 break;
2524 case Iex_Const:
sewardj49bfe672004-11-15 15:46:26 +00002525 if (!saneIRConst(expr->Iex.Const.con))
2526 sanityCheckFail(bb,stmt,"Iex.Const.con: invalid const");
sewardj6efd4a12004-07-15 03:54:23 +00002527 break;
sewardj4042c7e2004-07-18 01:28:30 +00002528 case Iex_Mux0X:
2529 tcExpr(bb,stmt, expr->Iex.Mux0X.cond, gWordTy);
2530 tcExpr(bb,stmt, expr->Iex.Mux0X.expr0, gWordTy);
2531 tcExpr(bb,stmt, expr->Iex.Mux0X.exprX, gWordTy);
2532 if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.cond) != Ity_I8)
2533 sanityCheckFail(bb,stmt,"Iex.Mux0X.cond: cond :: Ity_I8");
2534 if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.expr0)
2535 != typeOfIRExpr(tyenv, expr->Iex.Mux0X.exprX))
2536 sanityCheckFail(bb,stmt,"Iex.Mux0X: expr0/exprX mismatch");
sewardjeeb9ef82004-07-15 12:39:03 +00002537 break;
2538 default:
sewardj6efd4a12004-07-15 03:54:23 +00002539 vpanic("tcExpr");
2540 }
2541}
2542
2543
2544static
sewardjdd40fdf2006-12-24 02:20:24 +00002545void tcStmt ( IRSB* bb, IRStmt* stmt, IRType gWordTy )
sewardj6efd4a12004-07-15 03:54:23 +00002546{
sewardj17442fe2004-09-20 14:54:28 +00002547 Int i;
2548 IRDirty* d;
sewardje9d8a262009-07-01 08:06:34 +00002549 IRCAS* cas;
2550 IRType tyExpd, tyData;
sewardj6efd4a12004-07-15 03:54:23 +00002551 IRTypeEnv* tyenv = bb->tyenv;
2552 switch (stmt->tag) {
sewardjf1689312005-03-16 18:19:10 +00002553 case Ist_IMark:
2554 /* Somewhat heuristic, but rule out totally implausible
2555 instruction sizes. */
2556 if (stmt->Ist.IMark.len < 0 || stmt->Ist.IMark.len > 20)
2557 sanityCheckFail(bb,stmt,"IRStmt.IMark.len: implausible");
2558 break;
sewardj5a9ffab2005-05-12 17:55:01 +00002559 case Ist_AbiHint:
2560 if (typeOfIRExpr(tyenv, stmt->Ist.AbiHint.base) != gWordTy)
2561 sanityCheckFail(bb,stmt,"IRStmt.AbiHint.base: "
2562 "not :: guest word type");
sewardj478646f2008-05-01 20:13:04 +00002563 if (typeOfIRExpr(tyenv, stmt->Ist.AbiHint.nia) != gWordTy)
2564 sanityCheckFail(bb,stmt,"IRStmt.AbiHint.nia: "
2565 "not :: guest word type");
sewardj5a9ffab2005-05-12 17:55:01 +00002566 break;
sewardj6efd4a12004-07-15 03:54:23 +00002567 case Ist_Put:
sewardj6d076362004-09-23 11:06:17 +00002568 tcExpr( bb, stmt, stmt->Ist.Put.data, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002569 if (typeOfIRExpr(tyenv,stmt->Ist.Put.data) == Ity_I1)
2570 sanityCheckFail(bb,stmt,"IRStmt.Put.data: cannot Put :: Ity_I1");
sewardj2d3f77c2004-09-22 23:49:09 +00002571 break;
sewardjd1725d12004-08-12 20:46:53 +00002572 case Ist_PutI:
sewardj2d3f77c2004-09-22 23:49:09 +00002573 tcExpr( bb, stmt, stmt->Ist.PutI.data, gWordTy );
sewardjeeac8412004-11-02 00:26:55 +00002574 tcExpr( bb, stmt, stmt->Ist.PutI.ix, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002575 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data) == Ity_I1)
2576 sanityCheckFail(bb,stmt,"IRStmt.PutI.data: cannot PutI :: Ity_I1");
sewardj6d076362004-09-23 11:06:17 +00002577 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data)
2578 != stmt->Ist.PutI.descr->elemTy)
2579 sanityCheckFail(bb,stmt,"IRStmt.PutI.data: data ty != elem ty");
sewardjeeac8412004-11-02 00:26:55 +00002580 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.ix) != Ity_I32)
2581 sanityCheckFail(bb,stmt,"IRStmt.PutI.ix: not :: Ity_I32");
sewardjdd40fdf2006-12-24 02:20:24 +00002582 if (!saneIRRegArray(stmt->Ist.PutI.descr))
sewardj2d3f77c2004-09-22 23:49:09 +00002583 sanityCheckFail(bb,stmt,"IRStmt.PutI.descr: invalid descr");
2584 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002585 case Ist_WrTmp:
2586 tcExpr( bb, stmt, stmt->Ist.WrTmp.data, gWordTy );
2587 if (typeOfIRTemp(tyenv, stmt->Ist.WrTmp.tmp)
2588 != typeOfIRExpr(tyenv, stmt->Ist.WrTmp.data))
sewardj6d2638e2004-07-15 09:38:27 +00002589 sanityCheckFail(bb,stmt,"IRStmt.Put.Tmp: tmp and expr do not match");
sewardj6efd4a12004-07-15 03:54:23 +00002590 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002591 case Ist_Store:
2592 tcExpr( bb, stmt, stmt->Ist.Store.addr, gWordTy );
2593 tcExpr( bb, stmt, stmt->Ist.Store.data, gWordTy );
2594 if (typeOfIRExpr(tyenv, stmt->Ist.Store.addr) != gWordTy)
2595 sanityCheckFail(bb,stmt,"IRStmt.Store.addr: not :: guest word type");
2596 if (typeOfIRExpr(tyenv, stmt->Ist.Store.data) == Ity_I1)
2597 sanityCheckFail(bb,stmt,"IRStmt.Store.data: cannot Store :: Ity_I1");
2598 if (stmt->Ist.Store.end != Iend_LE && stmt->Ist.Store.end != Iend_BE)
2599 sanityCheckFail(bb,stmt,"Ist.Store.end: bogus endianness");
sewardje9d8a262009-07-01 08:06:34 +00002600 if (stmt->Ist.Store.resSC != IRTemp_INVALID
2601 && typeOfIRTemp(tyenv, stmt->Ist.Store.resSC) != Ity_I1)
2602 sanityCheckFail(bb,stmt,"Ist.Store.resSC: not :: Ity_I1");
2603 break;
2604 case Ist_CAS:
2605 cas = stmt->Ist.CAS.details;
2606 /* make sure it's definitely either a CAS or a DCAS */
2607 if (cas->oldHi == IRTemp_INVALID
2608 && cas->expdHi == NULL && cas->dataHi == NULL) {
2609 /* fine; it's a single cas */
2610 }
2611 else
2612 if (cas->oldHi != IRTemp_INVALID
2613 && cas->expdHi != NULL && cas->dataHi != NULL) {
2614 /* fine; it's a double cas */
2615 }
2616 else {
2617 /* it's some el-mutanto hybrid */
2618 goto bad_cas;
2619 }
2620 /* check the address type */
2621 tcExpr( bb, stmt, cas->addr, gWordTy );
2622 if (typeOfIRExpr(tyenv, cas->addr) != gWordTy) goto bad_cas;
2623 /* check types on the {old,expd,data}Lo components agree */
2624 tyExpd = typeOfIRExpr(tyenv, cas->expdLo);
2625 tyData = typeOfIRExpr(tyenv, cas->dataLo);
2626 if (tyExpd != tyData) goto bad_cas;
2627 if (tyExpd != typeOfIRTemp(tyenv, cas->oldLo))
2628 goto bad_cas;
2629 /* check the base element type is sane */
2630 if (tyExpd == Ity_I8 || tyExpd == Ity_I16 || tyExpd == Ity_I32
2631 || (gWordTy == Ity_I64 && tyExpd == Ity_I64)) {
2632 /* fine */
2633 } else {
2634 goto bad_cas;
2635 }
2636 /* If it's a DCAS, check types on the {old,expd,data}Hi
2637 components too */
2638 if (cas->oldHi != IRTemp_INVALID) {
2639 tyExpd = typeOfIRExpr(tyenv, cas->expdHi);
2640 tyData = typeOfIRExpr(tyenv, cas->dataHi);
2641 if (tyExpd != tyData) goto bad_cas;
2642 if (tyExpd != typeOfIRTemp(tyenv, cas->oldHi))
2643 goto bad_cas;
2644 /* and finally check that oldLo and oldHi have the same
2645 type. This forces equivalence amongst all 6 types. */
2646 if (typeOfIRTemp(tyenv, cas->oldHi)
2647 != typeOfIRTemp(tyenv, cas->oldLo))
2648 goto bad_cas;
2649 }
2650 break;
2651 bad_cas:
2652 sanityCheckFail(bb,stmt,"IRStmt.CAS: ill-formed");
sewardj6efd4a12004-07-15 03:54:23 +00002653 break;
sewardj17442fe2004-09-20 14:54:28 +00002654 case Ist_Dirty:
2655 /* Mostly check for various kinds of ill-formed dirty calls. */
2656 d = stmt->Ist.Dirty.details;
sewardj8ea867b2004-10-30 19:03:02 +00002657 if (d->cee == NULL) goto bad_dirty;
2658 if (!saneIRCallee(d->cee)) goto bad_dirty;
sewardjcf787902004-11-03 09:08:33 +00002659 if (d->cee->regparms > countArgs(d->args)) goto bad_dirty;
sewardj17442fe2004-09-20 14:54:28 +00002660 if (d->mFx == Ifx_None) {
2661 if (d->mAddr != NULL || d->mSize != 0)
2662 goto bad_dirty;
2663 } else {
2664 if (d->mAddr == NULL || d->mSize == 0)
2665 goto bad_dirty;
2666 }
2667 if (d->nFxState < 0 || d->nFxState > VEX_N_FXSTATE)
2668 goto bad_dirty;
sewardjc5fc7aa2004-10-27 23:00:55 +00002669 if (d->nFxState == 0 && d->needsBBP)
2670 goto bad_dirty;
sewardj17442fe2004-09-20 14:54:28 +00002671 for (i = 0; i < d->nFxState; i++) {
2672 if (d->fxState[i].fx == Ifx_None) goto bad_dirty;
2673 if (d->fxState[i].size <= 0) goto bad_dirty;
2674 }
2675 /* check types, minimally */
sewardjb8385d82004-11-02 01:34:15 +00002676 if (d->guard == NULL) goto bad_dirty;
sewardj49bfe672004-11-15 15:46:26 +00002677 tcExpr( bb, stmt, d->guard, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002678 if (typeOfIRExpr(tyenv, d->guard) != Ity_I1)
2679 sanityCheckFail(bb,stmt,"IRStmt.Dirty.guard not :: Ity_I1");
sewardj92d168d2004-11-15 14:22:12 +00002680 if (d->tmp != IRTemp_INVALID
sewardjba999312004-11-15 15:21:17 +00002681 && typeOfIRTemp(tyenv, d->tmp) == Ity_I1)
2682 sanityCheckFail(bb,stmt,"IRStmt.Dirty.dst :: Ity_I1");
sewardj17442fe2004-09-20 14:54:28 +00002683 for (i = 0; d->args[i] != NULL; i++) {
sewardj43c56462004-11-06 12:17:57 +00002684 if (i >= 32)
2685 sanityCheckFail(bb,stmt,"IRStmt.Dirty: > 32 args");
sewardjba999312004-11-15 15:21:17 +00002686 if (typeOfIRExpr(tyenv, d->args[i]) == Ity_I1)
2687 sanityCheckFail(bb,stmt,"IRStmt.Dirty.arg[i] :: Ity_I1");
sewardj17442fe2004-09-20 14:54:28 +00002688 }
2689 break;
2690 bad_dirty:
2691 sanityCheckFail(bb,stmt,"IRStmt.Dirty: ill-formed");
sewardje9d8a262009-07-01 08:06:34 +00002692 break;
sewardjd2445f62005-03-21 00:15:53 +00002693 case Ist_NoOp:
sewardjc4356f02007-11-09 21:15:04 +00002694 break;
2695 case Ist_MBE:
2696 switch (stmt->Ist.MBE.event) {
sewardje9d8a262009-07-01 08:06:34 +00002697 case Imbe_Fence:
sewardjc4356f02007-11-09 21:15:04 +00002698 break;
2699 default: sanityCheckFail(bb,stmt,"IRStmt.MBE.event: unknown");
2700 break;
2701 }
sewardj3e838932005-01-07 12:09:15 +00002702 break;
sewardj6efd4a12004-07-15 03:54:23 +00002703 case Ist_Exit:
sewardj0276d4b2004-11-15 15:30:21 +00002704 tcExpr( bb, stmt, stmt->Ist.Exit.guard, gWordTy );
2705 if (typeOfIRExpr(tyenv,stmt->Ist.Exit.guard) != Ity_I1)
2706 sanityCheckFail(bb,stmt,"IRStmt.Exit.guard: not :: Ity_I1");
sewardj49bfe672004-11-15 15:46:26 +00002707 if (!saneIRConst(stmt->Ist.Exit.dst))
2708 sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: bad dst");
sewardj6efd4a12004-07-15 03:54:23 +00002709 if (typeOfIRConst(stmt->Ist.Exit.dst) != gWordTy)
2710 sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: not :: guest word type");
2711 break;
2712 default:
2713 vpanic("tcStmt");
2714 }
2715}
2716
sewardjdd40fdf2006-12-24 02:20:24 +00002717void sanityCheckIRSB ( IRSB* bb, HChar* caller,
sewardjb9230752004-12-29 19:25:06 +00002718 Bool require_flat, IRType guest_word_size )
sewardj35439212004-07-14 22:36:10 +00002719{
2720 Int i;
2721 IRStmt* stmt;
2722 Int n_temps = bb->tyenv->types_used;
2723 Int* def_counts = LibVEX_Alloc(n_temps * sizeof(Int));
2724
sewardjb9230752004-12-29 19:25:06 +00002725 if (0)
2726 vex_printf("sanityCheck: %s\n", caller);
2727
sewardj35439212004-07-14 22:36:10 +00002728 vassert(guest_word_size == Ity_I32
sewardj695cff92004-10-13 14:50:14 +00002729 || guest_word_size == Ity_I64);
sewardj35439212004-07-14 22:36:10 +00002730
sewardjd7cb8532004-08-17 23:59:23 +00002731 if (bb->stmts_used < 0 || bb->stmts_size < 8
2732 || bb->stmts_used > bb->stmts_size)
2733 /* this BB is so strange we can't even print it */
sewardjdd40fdf2006-12-24 02:20:24 +00002734 vpanic("sanityCheckIRSB: stmts array limits wierd");
sewardjd7cb8532004-08-17 23:59:23 +00002735
sewardj6d2638e2004-07-15 09:38:27 +00002736 /* Ensure each temp has a plausible type. */
2737 for (i = 0; i < n_temps; i++) {
sewardj17442fe2004-09-20 14:54:28 +00002738 IRType ty = typeOfIRTemp(bb->tyenv,(IRTemp)i);
sewardj496a58d2005-03-20 18:44:44 +00002739 if (!isPlausibleIRType(ty)) {
sewardj6d2638e2004-07-15 09:38:27 +00002740 vex_printf("Temp t%d declared with implausible type 0x%x\n",
2741 i, (UInt)ty);
2742 sanityCheckFail(bb,NULL,"Temp declared with implausible type");
2743 }
2744 }
sewardj35439212004-07-14 22:36:10 +00002745
sewardjb9230752004-12-29 19:25:06 +00002746 /* Check for flatness, if required. */
2747 if (require_flat) {
2748 for (i = 0; i < bb->stmts_used; i++) {
2749 stmt = bb->stmts[i];
2750 if (!stmt)
sewardjd2445f62005-03-21 00:15:53 +00002751 sanityCheckFail(bb, stmt, "IRStmt: is NULL");
sewardjb9230752004-12-29 19:25:06 +00002752 if (!isFlatIRStmt(stmt))
2753 sanityCheckFail(bb, stmt, "IRStmt: is not flat");
2754 }
sewardj496a58d2005-03-20 18:44:44 +00002755 if (!isIRAtom(bb->next))
sewardjb9230752004-12-29 19:25:06 +00002756 sanityCheckFail(bb, NULL, "bb->next is not an atom");
2757 }
2758
sewardj35439212004-07-14 22:36:10 +00002759 /* Count the defs of each temp. Only one def is allowed.
2760 Also, check that each used temp has already been defd. */
sewardj6d2638e2004-07-15 09:38:27 +00002761
2762 for (i = 0; i < n_temps; i++)
2763 def_counts[i] = 0;
2764
sewardjd7cb8532004-08-17 23:59:23 +00002765 for (i = 0; i < bb->stmts_used; i++) {
sewardje9d8a262009-07-01 08:06:34 +00002766 IRDirty* d;
2767 IRCAS* cas;
sewardjd7cb8532004-08-17 23:59:23 +00002768 stmt = bb->stmts[i];
sewardje9d8a262009-07-01 08:06:34 +00002769 /* Check any temps used by this statement. */
sewardj35439212004-07-14 22:36:10 +00002770 useBeforeDef_Stmt(bb,stmt,def_counts);
sewardj17442fe2004-09-20 14:54:28 +00002771
sewardje9d8a262009-07-01 08:06:34 +00002772 /* Now make note of any temps defd by this statement. */
2773 switch (stmt->tag) {
2774 case Ist_WrTmp:
sewardjdd40fdf2006-12-24 02:20:24 +00002775 if (stmt->Ist.WrTmp.tmp < 0 || stmt->Ist.WrTmp.tmp >= n_temps)
sewardj17442fe2004-09-20 14:54:28 +00002776 sanityCheckFail(bb, stmt,
2777 "IRStmt.Tmp: destination tmp is out of range");
sewardjdd40fdf2006-12-24 02:20:24 +00002778 def_counts[stmt->Ist.WrTmp.tmp]++;
2779 if (def_counts[stmt->Ist.WrTmp.tmp] > 1)
sewardj17442fe2004-09-20 14:54:28 +00002780 sanityCheckFail(bb, stmt,
sewardjcf787902004-11-03 09:08:33 +00002781 "IRStmt.Tmp: destination tmp is assigned more than once");
sewardje9d8a262009-07-01 08:06:34 +00002782 break;
2783 case Ist_Store:
2784 if (stmt->Ist.Store.resSC != IRTemp_INVALID) {
2785 IRTemp resSC = stmt->Ist.Store.resSC;
2786 if (resSC < 0 || resSC >= n_temps)
2787 sanityCheckFail(bb, stmt,
2788 "IRStmt.Store.resSC: destination tmp is out of range");
2789 def_counts[resSC]++;
2790 if (def_counts[resSC] > 1)
2791 sanityCheckFail(bb, stmt,
2792 "IRStmt.Store.resSC: destination tmp "
2793 "is assigned more than once");
2794 }
2795 break;
2796 case Ist_Dirty:
2797 if (stmt->Ist.Dirty.details->tmp != IRTemp_INVALID) {
2798 d = stmt->Ist.Dirty.details;
2799 if (d->tmp < 0 || d->tmp >= n_temps)
2800 sanityCheckFail(bb, stmt,
2801 "IRStmt.Dirty: destination tmp is out of range");
2802 def_counts[d->tmp]++;
2803 if (def_counts[d->tmp] > 1)
2804 sanityCheckFail(bb, stmt,
2805 "IRStmt.Dirty: destination tmp is assigned more than once");
2806 }
2807 break;
2808 case Ist_CAS:
2809 cas = stmt->Ist.CAS.details;
2810
2811 if (cas->oldHi != IRTemp_INVALID) {
2812 if (cas->oldHi < 0 || cas->oldHi >= n_temps)
2813 sanityCheckFail(bb, stmt,
2814 "IRStmt.CAS: destination tmpHi is out of range");
2815 def_counts[cas->oldHi]++;
2816 if (def_counts[cas->oldHi] > 1)
2817 sanityCheckFail(bb, stmt,
2818 "IRStmt.CAS: destination tmpHi is assigned more than once");
2819 }
2820 if (cas->oldLo < 0 || cas->oldLo >= n_temps)
2821 sanityCheckFail(bb, stmt,
2822 "IRStmt.CAS: destination tmpLo is out of range");
2823 def_counts[cas->oldLo]++;
2824 if (def_counts[cas->oldLo] > 1)
2825 sanityCheckFail(bb, stmt,
2826 "IRStmt.CAS: destination tmpLo is assigned more than once");
2827 break;
2828 default:
2829 /* explicitly handle the rest, so as to keep gcc quiet */
2830 break;
sewardj35439212004-07-14 22:36:10 +00002831 }
2832 }
2833
sewardj6efd4a12004-07-15 03:54:23 +00002834 /* Typecheck everything. */
sewardjd7cb8532004-08-17 23:59:23 +00002835 for (i = 0; i < bb->stmts_used; i++)
sewardj39e3f242004-08-18 16:54:52 +00002836 if (bb->stmts[i])
2837 tcStmt( bb, bb->stmts[i], guest_word_size );
sewardj6efd4a12004-07-15 03:54:23 +00002838 if (typeOfIRExpr(bb->tyenv,bb->next) != guest_word_size)
2839 sanityCheckFail(bb, NULL, "bb->next field has wrong type");
sewardje539a402004-07-14 18:24:17 +00002840}
2841
sewardj4345f7a2004-09-22 19:49:27 +00002842/*---------------------------------------------------------------*/
2843/*--- Misc helper functions ---*/
2844/*---------------------------------------------------------------*/
2845
2846Bool eqIRConst ( IRConst* c1, IRConst* c2 )
2847{
2848 if (c1->tag != c2->tag)
2849 return False;
2850
2851 switch (c1->tag) {
sewardja98bf492005-02-07 01:39:17 +00002852 case Ico_U1: return toBool( (1 & c1->Ico.U1) == (1 & c2->Ico.U1) );
2853 case Ico_U8: return toBool( c1->Ico.U8 == c2->Ico.U8 );
2854 case Ico_U16: return toBool( c1->Ico.U16 == c2->Ico.U16 );
2855 case Ico_U32: return toBool( c1->Ico.U32 == c2->Ico.U32 );
2856 case Ico_U64: return toBool( c1->Ico.U64 == c2->Ico.U64 );
2857 case Ico_F64: return toBool( c1->Ico.F64 == c2->Ico.F64 );
sewardj0da5eb82007-01-27 00:46:28 +00002858 case Ico_F64i: return toBool( c1->Ico.F64i == c2->Ico.F64i );
2859 case Ico_V128: return toBool( c1->Ico.V128 == c2->Ico.V128 );
sewardj4345f7a2004-09-22 19:49:27 +00002860 default: vpanic("eqIRConst");
2861 }
2862}
2863
sewardjdd40fdf2006-12-24 02:20:24 +00002864Bool eqIRRegArray ( IRRegArray* descr1, IRRegArray* descr2 )
sewardje98dcf22004-10-04 09:15:11 +00002865{
sewardja98bf492005-02-07 01:39:17 +00002866 return toBool( descr1->base == descr2->base
2867 && descr1->elemTy == descr2->elemTy
2868 && descr1->nElems == descr2->nElems );
sewardje98dcf22004-10-04 09:15:11 +00002869}
2870
sewardj2d3f77c2004-09-22 23:49:09 +00002871Int sizeofIRType ( IRType ty )
2872{
2873 switch (ty) {
sewardjc9a43662004-11-30 18:51:59 +00002874 case Ity_I8: return 1;
2875 case Ity_I16: return 2;
2876 case Ity_I32: return 4;
2877 case Ity_I64: return 8;
2878 case Ity_F32: return 4;
2879 case Ity_F64: return 8;
2880 case Ity_V128: return 16;
sewardj2d3f77c2004-09-22 23:49:09 +00002881 default: vex_printf("\n"); ppIRType(ty); vex_printf("\n");
2882 vpanic("sizeofIRType");
2883 }
2884}
2885
sewardj49651f42004-10-28 22:11:04 +00002886IRExpr* mkIRExpr_HWord ( HWord hw )
2887{
sewardjf9655262004-10-31 20:02:16 +00002888 vassert(sizeof(void*) == sizeof(HWord));
sewardj49651f42004-10-28 22:11:04 +00002889 if (sizeof(HWord) == 4)
2890 return IRExpr_Const(IRConst_U32((UInt)hw));
2891 if (sizeof(HWord) == 8)
sewardjf9655262004-10-31 20:02:16 +00002892 return IRExpr_Const(IRConst_U64((ULong)hw));
sewardj49651f42004-10-28 22:11:04 +00002893 vpanic("mkIRExpr_HWord");
2894}
sewardj6efd4a12004-07-15 03:54:23 +00002895
sewardj2d49b432005-02-01 00:37:06 +00002896IRDirty* unsafeIRDirty_0_N ( Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002897 IRExpr** args )
2898{
2899 IRDirty* d = emptyIRDirty();
sewardjb8385d82004-11-02 01:34:15 +00002900 d->cee = mkIRCallee ( regparms, name, addr );
sewardjba999312004-11-15 15:21:17 +00002901 d->guard = IRExpr_Const(IRConst_U1(True));
sewardjb8385d82004-11-02 01:34:15 +00002902 d->args = args;
sewardjf9655262004-10-31 20:02:16 +00002903 return d;
2904}
2905
2906IRDirty* unsafeIRDirty_1_N ( IRTemp dst,
sewardj2d49b432005-02-01 00:37:06 +00002907 Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002908 IRExpr** args )
2909{
2910 IRDirty* d = emptyIRDirty();
sewardjb8385d82004-11-02 01:34:15 +00002911 d->cee = mkIRCallee ( regparms, name, addr );
sewardjba999312004-11-15 15:21:17 +00002912 d->guard = IRExpr_Const(IRConst_U1(True));
sewardjb8385d82004-11-02 01:34:15 +00002913 d->args = args;
2914 d->tmp = dst;
sewardjf9655262004-10-31 20:02:16 +00002915 return d;
2916}
2917
2918IRExpr* mkIRExprCCall ( IRType retty,
sewardj2d49b432005-02-01 00:37:06 +00002919 Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002920 IRExpr** args )
2921{
2922 return IRExpr_CCall ( mkIRCallee ( regparms, name, addr ),
2923 retty, args );
2924}
2925
sewardj496a58d2005-03-20 18:44:44 +00002926Bool eqIRAtom ( IRExpr* a1, IRExpr* a2 )
2927{
2928 vassert(isIRAtom(a1));
2929 vassert(isIRAtom(a2));
sewardjdd40fdf2006-12-24 02:20:24 +00002930 if (a1->tag == Iex_RdTmp && a2->tag == Iex_RdTmp)
2931 return toBool(a1->Iex.RdTmp.tmp == a2->Iex.RdTmp.tmp);
sewardj496a58d2005-03-20 18:44:44 +00002932 if (a1->tag == Iex_Const && a2->tag == Iex_Const)
2933 return eqIRConst(a1->Iex.Const.con, a2->Iex.Const.con);
2934 return False;
2935}
2936
sewardje539a402004-07-14 18:24:17 +00002937/*---------------------------------------------------------------*/
sewardjc0ee2ed2004-07-27 10:29:41 +00002938/*--- end ir/irdefs.c ---*/
sewardj887a11a2004-07-05 17:26:47 +00002939/*---------------------------------------------------------------*/