blob: f58c60c08a9c099664f17980ae1635fb2a5d72a3 [file] [log] [blame]
sewardjec6ad592004-06-20 12:26:53 +00001
2/*---------------------------------------------------------------*/
3/*--- ---*/
sewardjcef7d3e2009-07-02 12:21:59 +00004/*--- This file (ir_defs.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
sewardjcef7d3e2009-07-02 12:21:59 +000013 Copyright (C) 2004-2009 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
sewardjcef7d3e2009-07-02 12:21:59 +000051#include "main_util.h"
sewardjc0ee2ed2004-07-27 10:29:41 +000052
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;
sewardj1fb8c922009-07-12 12:56:53 +0000147 case Iop_CasCmpEQ8 ... Iop_CasCmpEQ64:
148 str = "CasCmpEQ"; base = Iop_CasCmpEQ8; break;
149 case Iop_CasCmpNE8 ... Iop_CasCmpNE64:
150 str = "CasCmpNE"; base = Iop_CasCmpNE8; break;
sewardj41f43bc2004-07-08 14:23:22 +0000151 case Iop_Not8 ... Iop_Not64:
152 str = "Not"; base = Iop_Not8; break;
153 /* other cases must explicitly "return;" */
sewardj9690d922004-07-14 01:39:17 +0000154 case Iop_8Uto16: vex_printf("8Uto16"); return;
155 case Iop_8Uto32: vex_printf("8Uto32"); return;
156 case Iop_16Uto32: vex_printf("16Uto32"); return;
157 case Iop_8Sto16: vex_printf("8Sto16"); return;
158 case Iop_8Sto32: vex_printf("8Sto32"); return;
159 case Iop_16Sto32: vex_printf("16Sto32"); return;
sewardjbb53f8c2004-08-14 11:50:01 +0000160 case Iop_32Sto64: vex_printf("32Sto64"); return;
sewardje5427e82004-09-11 19:43:51 +0000161 case Iop_32Uto64: vex_printf("32Uto64"); return;
sewardja2384712004-07-29 14:36:40 +0000162 case Iop_32to8: vex_printf("32to8"); return;
sewardj291a7e82005-04-27 11:42:44 +0000163 case Iop_16Uto64: vex_printf("16Uto64"); return;
164 case Iop_16Sto64: vex_printf("16Sto64"); return;
165 case Iop_8Uto64: vex_printf("8Uto64"); return;
166 case Iop_8Sto64: vex_printf("8Sto64"); return;
167 case Iop_64to16: vex_printf("64to16"); return;
168 case Iop_64to8: vex_printf("64to8"); return;
sewardj6e797c52004-10-13 15:20:17 +0000169
170 case Iop_Not1: vex_printf("Not1"); return;
sewardj9690d922004-07-14 01:39:17 +0000171 case Iop_32to1: vex_printf("32to1"); return;
sewardj291a7e82005-04-27 11:42:44 +0000172 case Iop_64to1: vex_printf("64to1"); return;
sewardj9690d922004-07-14 01:39:17 +0000173 case Iop_1Uto8: vex_printf("1Uto8"); return;
sewardj84ff0652004-08-23 16:16:08 +0000174 case Iop_1Uto32: vex_printf("1Uto32"); return;
sewardj291a7e82005-04-27 11:42:44 +0000175 case Iop_1Uto64: vex_printf("1Uto64"); return;
sewardjfd332772004-11-09 16:01:40 +0000176 case Iop_1Sto8: vex_printf("1Sto8"); return;
sewardj8eda6302004-11-05 01:55:46 +0000177 case Iop_1Sto16: vex_printf("1Sto16"); return;
sewardj415d9352004-11-04 15:20:15 +0000178 case Iop_1Sto32: vex_printf("1Sto32"); return;
sewardjb5874aa2004-11-04 16:57:50 +0000179 case Iop_1Sto64: vex_printf("1Sto64"); return;
sewardj9690d922004-07-14 01:39:17 +0000180
181 case Iop_MullS8: vex_printf("MullS8"); return;
182 case Iop_MullS16: vex_printf("MullS16"); return;
183 case Iop_MullS32: vex_printf("MullS32"); return;
sewardj9b967672005-02-08 11:13:09 +0000184 case Iop_MullS64: vex_printf("MullS64"); return;
sewardj9690d922004-07-14 01:39:17 +0000185 case Iop_MullU8: vex_printf("MullU8"); return;
186 case Iop_MullU16: vex_printf("MullU16"); return;
187 case Iop_MullU32: vex_printf("MullU32"); return;
sewardj9b967672005-02-08 11:13:09 +0000188 case Iop_MullU64: vex_printf("MullU64"); return;
sewardj9690d922004-07-14 01:39:17 +0000189
sewardjf53b7352005-04-06 20:01:56 +0000190 case Iop_Clz64: vex_printf("Clz64"); return;
sewardjce646f22004-08-31 23:55:54 +0000191 case Iop_Clz32: vex_printf("Clz32"); return;
sewardjf53b7352005-04-06 20:01:56 +0000192 case Iop_Ctz64: vex_printf("Ctz64"); return;
sewardjce646f22004-08-31 23:55:54 +0000193 case Iop_Ctz32: vex_printf("Ctz32"); return;
194
sewardj84ff0652004-08-23 16:16:08 +0000195 case Iop_CmpLT32S: vex_printf("CmpLT32S"); return;
196 case Iop_CmpLE32S: vex_printf("CmpLE32S"); return;
197 case Iop_CmpLT32U: vex_printf("CmpLT32U"); return;
198 case Iop_CmpLE32U: vex_printf("CmpLE32U"); return;
199
sewardj98540072005-04-26 01:52:01 +0000200 case Iop_CmpLT64S: vex_printf("CmpLT64S"); return;
201 case Iop_CmpLE64S: vex_printf("CmpLE64S"); return;
202 case Iop_CmpLT64U: vex_printf("CmpLT64U"); return;
203 case Iop_CmpLE64U: vex_printf("CmpLE64U"); return;
204
sewardj0033ddc2005-04-26 23:34:34 +0000205 case Iop_CmpNEZ8: vex_printf("CmpNEZ8"); return;
206 case Iop_CmpNEZ16: vex_printf("CmpNEZ16"); return;
207 case Iop_CmpNEZ32: vex_printf("CmpNEZ32"); return;
208 case Iop_CmpNEZ64: vex_printf("CmpNEZ64"); return;
209
sewardjeb17e492007-08-25 23:07:44 +0000210 case Iop_CmpwNEZ32: vex_printf("CmpwNEZ32"); return;
211 case Iop_CmpwNEZ64: vex_printf("CmpwNEZ64"); return;
212
213 case Iop_Left8: vex_printf("Left8"); return;
214 case Iop_Left16: vex_printf("Left16"); return;
215 case Iop_Left32: vex_printf("Left32"); return;
216 case Iop_Left64: vex_printf("Left64"); return;
sewardj478646f2008-05-01 20:13:04 +0000217 case Iop_Max32U: vex_printf("Max32U"); return;
sewardjeb17e492007-08-25 23:07:44 +0000218
sewardjb51f0f42005-07-18 11:38:02 +0000219 case Iop_CmpORD32U: vex_printf("CmpORD32U"); return;
220 case Iop_CmpORD32S: vex_printf("CmpORD32S"); return;
221
cerion2831b002005-11-30 19:55:22 +0000222 case Iop_CmpORD64U: vex_printf("CmpORD64U"); return;
223 case Iop_CmpORD64S: vex_printf("CmpORD64S"); return;
224
cerion5c8a0cb2005-02-03 13:59:46 +0000225 case Iop_DivU32: vex_printf("DivU32"); return;
226 case Iop_DivS32: vex_printf("DivS32"); return;
cerionf0de28c2005-12-13 20:21:11 +0000227 case Iop_DivU64: vex_printf("DivU64"); return;
228 case Iop_DivS64: vex_printf("DivS64"); return;
cerion5c8a0cb2005-02-03 13:59:46 +0000229
sewardj9690d922004-07-14 01:39:17 +0000230 case Iop_DivModU64to32: vex_printf("DivModU64to32"); return;
231 case Iop_DivModS64to32: vex_printf("DivModS64to32"); return;
232
sewardj343b9d02005-01-31 18:08:45 +0000233 case Iop_DivModU128to64: vex_printf("DivModU128to64"); return;
234 case Iop_DivModS128to64: vex_printf("DivModS128to64"); return;
235
sewardjb81f8b32004-07-30 10:17:50 +0000236 case Iop_16HIto8: vex_printf("16HIto8"); return;
237 case Iop_16to8: vex_printf("16to8"); return;
238 case Iop_8HLto16: vex_printf("8HLto16"); return;
239
sewardj8c7f1ab2004-07-29 20:31:09 +0000240 case Iop_32HIto16: vex_printf("32HIto16"); return;
241 case Iop_32to16: vex_printf("32to16"); return;
242 case Iop_16HLto32: vex_printf("16HLto32"); return;
243
sewardj9690d922004-07-14 01:39:17 +0000244 case Iop_64HIto32: vex_printf("64HIto32"); return;
sewardj8c7f1ab2004-07-29 20:31:09 +0000245 case Iop_64to32: vex_printf("64to32"); return;
sewardj9690d922004-07-14 01:39:17 +0000246 case Iop_32HLto64: vex_printf("32HLto64"); return;
247
sewardj9b967672005-02-08 11:13:09 +0000248 case Iop_128HIto64: vex_printf("128HIto64"); return;
249 case Iop_128to64: vex_printf("128to64"); return;
250 case Iop_64HLto128: vex_printf("64HLto128"); return;
251
sewardjcfded9a2004-09-09 11:44:16 +0000252 case Iop_AddF64: vex_printf("AddF64"); return;
253 case Iop_SubF64: vex_printf("SubF64"); return;
254 case Iop_MulF64: vex_printf("MulF64"); return;
255 case Iop_DivF64: vex_printf("DivF64"); return;
sewardjb183b852006-02-03 16:08:03 +0000256 case Iop_AddF64r32: vex_printf("AddF64r32"); return;
257 case Iop_SubF64r32: vex_printf("SubF64r32"); return;
258 case Iop_MulF64r32: vex_printf("MulF64r32"); return;
259 case Iop_DivF64r32: vex_printf("DivF64r32"); return;
sewardj46de4072004-09-11 19:23:24 +0000260
sewardj442d0be2004-10-15 22:57:13 +0000261 case Iop_ScaleF64: vex_printf("ScaleF64"); return;
262 case Iop_AtanF64: vex_printf("AtanF64"); return;
263 case Iop_Yl2xF64: vex_printf("Yl2xF64"); return;
264 case Iop_Yl2xp1F64: vex_printf("Yl2xp1F64"); return;
265 case Iop_PRemF64: vex_printf("PRemF64"); return;
266 case Iop_PRemC3210F64: vex_printf("PRemC3210F64"); return;
267 case Iop_PRem1F64: vex_printf("PRem1F64"); return;
268 case Iop_PRem1C3210F64: vex_printf("PRem1C3210F64"); return;
269 case Iop_NegF64: vex_printf("NegF64"); return;
270 case Iop_SqrtF64: vex_printf("SqrtF64"); return;
sewardj46de4072004-09-11 19:23:24 +0000271
sewardj883b00b2004-09-11 09:30:24 +0000272 case Iop_AbsF64: vex_printf("AbsF64"); return;
sewardjcfded9a2004-09-09 11:44:16 +0000273 case Iop_SinF64: vex_printf("SinF64"); return;
274 case Iop_CosF64: vex_printf("CosF64"); return;
sewardj99016a72004-10-15 22:09:17 +0000275 case Iop_TanF64: vex_printf("TanF64"); return;
sewardj06c32a02004-09-12 12:07:34 +0000276 case Iop_2xm1F64: vex_printf("2xm1F64"); return;
sewardjbdc7d212004-09-09 02:46:40 +0000277
sewardj40c80262006-02-08 19:30:46 +0000278 case Iop_MAddF64: vex_printf("MAddF64"); return;
279 case Iop_MSubF64: vex_printf("MSubF64"); return;
280 case Iop_MAddF64r32: vex_printf("MAddF64r32"); return;
281 case Iop_MSubF64r32: vex_printf("MSubF64r32"); return;
282
283 case Iop_Est5FRSqrt: vex_printf("Est5FRSqrt"); return;
sewardj0f1ef862008-08-08 08:37:06 +0000284 case Iop_RoundF64toF64_NEAREST: vex_printf("RoundF64toF64_NEAREST"); return;
285 case Iop_RoundF64toF64_NegINF: vex_printf("RoundF64toF64_NegINF"); return;
286 case Iop_RoundF64toF64_PosINF: vex_printf("RoundF64toF64_PosINF"); return;
287 case Iop_RoundF64toF64_ZERO: vex_printf("RoundF64toF64_ZERO"); return;
288
sewardjb183b852006-02-03 16:08:03 +0000289 case Iop_TruncF64asF32: vex_printf("TruncF64asF32"); return;
sewardja0e3d422007-08-28 06:06:57 +0000290 case Iop_CalcFPRF: vex_printf("CalcFPRF"); return;
sewardjbaf971a2006-01-27 15:09:35 +0000291
sewardj46de4072004-09-11 19:23:24 +0000292 case Iop_CmpF64: vex_printf("CmpF64"); return;
293
sewardj3bca9062004-12-04 14:36:09 +0000294 case Iop_F64toI16: vex_printf("F64toI16"); return;
295 case Iop_F64toI32: vex_printf("F64toI32"); return;
296 case Iop_F64toI64: vex_printf("F64toI64"); return;
297
298 case Iop_I16toF64: vex_printf("I16toF64"); return;
sewardj89cd0932004-09-08 18:23:25 +0000299 case Iop_I32toF64: vex_printf("I32toF64"); return;
sewardjbdc7d212004-09-09 02:46:40 +0000300 case Iop_I64toF64: vex_printf("I64toF64"); return;
sewardjcfded9a2004-09-09 11:44:16 +0000301
sewardj89cd0932004-09-08 18:23:25 +0000302 case Iop_F32toF64: vex_printf("F32toF64"); return;
303 case Iop_F64toF32: vex_printf("F64toF32"); return;
sewardjbb53f8c2004-08-14 11:50:01 +0000304
sewardjb183b852006-02-03 16:08:03 +0000305 case Iop_RoundF64toInt: vex_printf("RoundF64toInt"); return;
306 case Iop_RoundF64toF32: vex_printf("RoundF64toF32"); return;
sewardj3bca9062004-12-04 14:36:09 +0000307
sewardj17442fe2004-09-20 14:54:28 +0000308 case Iop_ReinterpF64asI64: vex_printf("ReinterpF64asI64"); return;
309 case Iop_ReinterpI64asF64: vex_printf("ReinterpI64asF64"); return;
sewardjfc1b5412007-01-09 15:20:07 +0000310 case Iop_ReinterpF32asI32: vex_printf("ReinterpF32asI32"); return;
sewardjfd226452004-12-07 19:02:18 +0000311 case Iop_ReinterpI32asF32: vex_printf("ReinterpI32asF32"); return;
sewardj17442fe2004-09-20 14:54:28 +0000312
sewardj228c7c82008-07-29 09:47:21 +0000313 case Iop_I32UtoFx4: vex_printf("I32UtoFx4"); return;
314 case Iop_I32StoFx4: vex_printf("I32StoFx4"); return;
cerionf294eb32005-11-16 17:21:10 +0000315
sewardj228c7c82008-07-29 09:47:21 +0000316 case Iop_QFtoI32Ux4_RZ: vex_printf("QFtoI32Ux4_RZ"); return;
317 case Iop_QFtoI32Sx4_RZ: vex_printf("QFtoI32Sx4_RZ"); return;
cerionf294eb32005-11-16 17:21:10 +0000318
sewardj228c7c82008-07-29 09:47:21 +0000319 case Iop_RoundF32x4_RM: vex_printf("RoundF32x4_RM"); return;
320 case Iop_RoundF32x4_RP: vex_printf("RoundF32x4_RP"); return;
321 case Iop_RoundF32x4_RN: vex_printf("RoundF32x4_RN"); return;
322 case Iop_RoundF32x4_RZ: vex_printf("RoundF32x4_RZ"); return;
cerionf294eb32005-11-16 17:21:10 +0000323
sewardj38a3f862005-01-13 15:06:51 +0000324 case Iop_Add8x8: vex_printf("Add8x8"); return;
325 case Iop_Add16x4: vex_printf("Add16x4"); return;
326 case Iop_Add32x2: vex_printf("Add32x2"); return;
327 case Iop_QAdd8Ux8: vex_printf("QAdd8Ux8"); return;
328 case Iop_QAdd16Ux4: vex_printf("QAdd16Ux4"); return;
329 case Iop_QAdd8Sx8: vex_printf("QAdd8Sx8"); return;
330 case Iop_QAdd16Sx4: vex_printf("QAdd16Sx4"); return;
331 case Iop_Sub8x8: vex_printf("Sub8x8"); return;
332 case Iop_Sub16x4: vex_printf("Sub16x4"); return;
333 case Iop_Sub32x2: vex_printf("Sub32x2"); return;
334 case Iop_QSub8Ux8: vex_printf("QSub8Ux8"); return;
335 case Iop_QSub16Ux4: vex_printf("QSub16Ux4"); return;
336 case Iop_QSub8Sx8: vex_printf("QSub8Sx8"); return;
337 case Iop_QSub16Sx4: vex_printf("QSub16Sx4"); return;
338 case Iop_Mul16x4: vex_printf("Mul16x4"); return;
sewardjd166e282008-02-06 11:42:45 +0000339 case Iop_Mul32x2: vex_printf("Mul32x2"); return;
sewardj38a3f862005-01-13 15:06:51 +0000340 case Iop_MulHi16Ux4: vex_printf("MulHi16Ux4"); return;
341 case Iop_MulHi16Sx4: vex_printf("MulHi16Sx4"); return;
342 case Iop_Avg8Ux8: vex_printf("Avg8Ux8"); return;
343 case Iop_Avg16Ux4: vex_printf("Avg16Ux4"); return;
344 case Iop_Max16Sx4: vex_printf("Max16Sx4"); return;
345 case Iop_Max8Ux8: vex_printf("Max8Ux8"); return;
346 case Iop_Min16Sx4: vex_printf("Min16Sx4"); return;
347 case Iop_Min8Ux8: vex_printf("Min8Ux8"); return;
348 case Iop_CmpEQ8x8: vex_printf("CmpEQ8x8"); return;
349 case Iop_CmpEQ16x4: vex_printf("CmpEQ16x4"); return;
350 case Iop_CmpEQ32x2: vex_printf("CmpEQ32x2"); return;
351 case Iop_CmpGT8Sx8: vex_printf("CmpGT8Sx8"); return;
352 case Iop_CmpGT16Sx4: vex_printf("CmpGT16Sx4"); return;
353 case Iop_CmpGT32Sx2: vex_printf("CmpGT32Sx2"); return;
sewardjd166e282008-02-06 11:42:45 +0000354 case Iop_ShlN8x8: vex_printf("ShlN8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000355 case Iop_ShlN16x4: vex_printf("ShlN16x4"); return;
356 case Iop_ShlN32x2: vex_printf("ShlN32x2"); return;
357 case Iop_ShrN16x4: vex_printf("ShrN16x4"); return;
358 case Iop_ShrN32x2: vex_printf("ShrN32x2"); return;
sewardjd71ba832006-12-27 01:15:29 +0000359 case Iop_SarN8x8: vex_printf("SarN8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000360 case Iop_SarN16x4: vex_printf("SarN16x4"); return;
361 case Iop_SarN32x2: vex_printf("SarN32x2"); return;
362 case Iop_QNarrow16Ux4: vex_printf("QNarrow16Ux4"); return;
363 case Iop_QNarrow16Sx4: vex_printf("QNarrow16Sx4"); return;
364 case Iop_QNarrow32Sx2: vex_printf("QNarrow32Sx2"); return;
365 case Iop_InterleaveHI8x8: vex_printf("InterleaveHI8x8"); return;
366 case Iop_InterleaveHI16x4: vex_printf("InterleaveHI16x4"); return;
367 case Iop_InterleaveHI32x2: vex_printf("InterleaveHI32x2"); return;
368 case Iop_InterleaveLO8x8: vex_printf("InterleaveLO8x8"); return;
369 case Iop_InterleaveLO16x4: vex_printf("InterleaveLO16x4"); return;
370 case Iop_InterleaveLO32x2: vex_printf("InterleaveLO32x2"); return;
sewardjd166e282008-02-06 11:42:45 +0000371 case Iop_CatOddLanes16x4: vex_printf("CatOddLanes16x4"); return;
372 case Iop_CatEvenLanes16x4: vex_printf("CatEvenLanes16x4"); return;
sewardj228c7c82008-07-29 09:47:21 +0000373 case Iop_Perm8x8: vex_printf("Perm8x8"); return;
sewardj38a3f862005-01-13 15:06:51 +0000374
sewardj18069182005-01-13 19:16:04 +0000375 case Iop_CmpNEZ32x2: vex_printf("CmpNEZ32x2"); return;
376 case Iop_CmpNEZ16x4: vex_printf("CmpNEZ16x4"); return;
377 case Iop_CmpNEZ8x8: vex_printf("CmpNEZ8x8"); return;
378
sewardj1e6ad742004-12-02 16:16:11 +0000379 case Iop_Add32Fx4: vex_printf("Add32Fx4"); return;
380 case Iop_Add32F0x4: vex_printf("Add32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000381 case Iop_Add64Fx2: vex_printf("Add64Fx2"); return;
382 case Iop_Add64F0x2: vex_printf("Add64F0x2"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000383
sewardj176a59c2004-12-03 20:08:31 +0000384 case Iop_Div32Fx4: vex_printf("Div32Fx4"); return;
385 case Iop_Div32F0x4: vex_printf("Div32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000386 case Iop_Div64Fx2: vex_printf("Div64Fx2"); return;
387 case Iop_Div64F0x2: vex_printf("Div64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000388
389 case Iop_Max32Fx4: vex_printf("Max32Fx4"); return;
390 case Iop_Max32F0x4: vex_printf("Max32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000391 case Iop_Max64Fx2: vex_printf("Max64Fx2"); return;
392 case Iop_Max64F0x2: vex_printf("Max64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000393
394 case Iop_Min32Fx4: vex_printf("Min32Fx4"); return;
395 case Iop_Min32F0x4: vex_printf("Min32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000396 case Iop_Min64Fx2: vex_printf("Min64Fx2"); return;
397 case Iop_Min64F0x2: vex_printf("Min64F0x2"); return;
sewardj176a59c2004-12-03 20:08:31 +0000398
sewardj9636b442004-12-04 01:38:37 +0000399 case Iop_Mul32Fx4: vex_printf("Mul32Fx4"); return;
400 case Iop_Mul32F0x4: vex_printf("Mul32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000401 case Iop_Mul64Fx2: vex_printf("Mul64Fx2"); return;
402 case Iop_Mul64F0x2: vex_printf("Mul64F0x2"); return;
sewardj9636b442004-12-04 01:38:37 +0000403
sewardj0bd7ce62004-12-05 02:47:40 +0000404 case Iop_Recip32Fx4: vex_printf("Recip32Fx4"); return;
405 case Iop_Recip32F0x4: vex_printf("Recip32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000406 case Iop_Recip64Fx2: vex_printf("Recip64Fx2"); return;
407 case Iop_Recip64F0x2: vex_printf("Recip64F0x2"); return;
sewardj0bd7ce62004-12-05 02:47:40 +0000408
sewardjc1e7dfc2004-12-05 19:29:45 +0000409 case Iop_RSqrt32Fx4: vex_printf("RSqrt32Fx4"); return;
410 case Iop_RSqrt32F0x4: vex_printf("RSqrt32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000411 case Iop_RSqrt64Fx2: vex_printf("RSqrt64Fx2"); return;
412 case Iop_RSqrt64F0x2: vex_printf("RSqrt64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000413
sewardj636ad762004-12-07 11:16:04 +0000414 case Iop_Sqrt32Fx4: vex_printf("Sqrt32Fx4"); return;
415 case Iop_Sqrt32F0x4: vex_printf("Sqrt32F0x4"); return;
416 case Iop_Sqrt64Fx2: vex_printf("Sqrt64Fx2"); return;
417 case Iop_Sqrt64F0x2: vex_printf("Sqrt64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000418
419 case Iop_Sub32Fx4: vex_printf("Sub32Fx4"); return;
420 case Iop_Sub32F0x4: vex_printf("Sub32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000421 case Iop_Sub64Fx2: vex_printf("Sub64Fx2"); return;
422 case Iop_Sub64F0x2: vex_printf("Sub64F0x2"); return;
sewardjc1e7dfc2004-12-05 19:29:45 +0000423
sewardj1e6ad742004-12-02 16:16:11 +0000424 case Iop_CmpEQ32Fx4: vex_printf("CmpEQ32Fx4"); return;
425 case Iop_CmpLT32Fx4: vex_printf("CmpLT32Fx4"); return;
426 case Iop_CmpLE32Fx4: vex_printf("CmpLE32Fx4"); return;
cerion206c3642005-11-14 00:35:59 +0000427 case Iop_CmpGT32Fx4: vex_printf("CmpGT32Fx4"); return;
428 case Iop_CmpGE32Fx4: vex_printf("CmpGE32Fx4"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000429 case Iop_CmpUN32Fx4: vex_printf("CmpUN32Fx4"); return;
sewardj636ad762004-12-07 11:16:04 +0000430 case Iop_CmpEQ64Fx2: vex_printf("CmpEQ64Fx2"); return;
431 case Iop_CmpLT64Fx2: vex_printf("CmpLT64Fx2"); return;
432 case Iop_CmpLE64Fx2: vex_printf("CmpLE64Fx2"); return;
433 case Iop_CmpUN64Fx2: vex_printf("CmpUN64Fx2"); return;
sewardj1e6ad742004-12-02 16:16:11 +0000434
435 case Iop_CmpEQ32F0x4: vex_printf("CmpEQ32F0x4"); return;
436 case Iop_CmpLT32F0x4: vex_printf("CmpLT32F0x4"); return;
437 case Iop_CmpLE32F0x4: vex_printf("CmpLE32F0x4"); return;
438 case Iop_CmpUN32F0x4: vex_printf("CmpUN32F0x4"); return;
sewardj636ad762004-12-07 11:16:04 +0000439 case Iop_CmpEQ64F0x2: vex_printf("CmpEQ64F0x2"); return;
440 case Iop_CmpLT64F0x2: vex_printf("CmpLT64F0x2"); return;
441 case Iop_CmpLE64F0x2: vex_printf("CmpLE64F0x2"); return;
442 case Iop_CmpUN64F0x2: vex_printf("CmpUN64F0x2"); return;
sewardjc9a43662004-11-30 18:51:59 +0000443
sewardjf0c1c582005-02-07 23:47:38 +0000444 case Iop_V128to64: vex_printf("V128to64"); return;
445 case Iop_V128HIto64: vex_printf("V128HIto64"); return;
446 case Iop_64HLtoV128: vex_printf("64HLtoV128"); return;
sewardja0037df2004-12-10 18:56:29 +0000447
sewardjf0c1c582005-02-07 23:47:38 +0000448 case Iop_64UtoV128: vex_printf("64UtoV128"); return;
449 case Iop_SetV128lo64: vex_printf("SetV128lo64"); return;
sewardjc9a43662004-11-30 18:51:59 +0000450
sewardjf0c1c582005-02-07 23:47:38 +0000451 case Iop_32UtoV128: vex_printf("32UtoV128"); return;
452 case Iop_V128to32: vex_printf("V128to32"); return;
453 case Iop_SetV128lo32: vex_printf("SetV128lo32"); return;
sewardj129b3d92004-12-05 15:42:05 +0000454
cerionf887b3e2005-09-13 16:34:28 +0000455 case Iop_Dup8x16: vex_printf("Dup8x16"); return;
456 case Iop_Dup16x8: vex_printf("Dup16x8"); return;
457 case Iop_Dup32x4: vex_printf("Dup32x4"); return;
458
sewardjf0c1c582005-02-07 23:47:38 +0000459 case Iop_NotV128: vex_printf("NotV128"); return;
460 case Iop_AndV128: vex_printf("AndV128"); return;
461 case Iop_OrV128: vex_printf("OrV128"); return;
462 case Iop_XorV128: vex_printf("XorV128"); return;
sewardj18069182005-01-13 19:16:04 +0000463
sewardj2e383862004-12-12 16:46:47 +0000464 case Iop_CmpNEZ8x16: vex_printf("CmpNEZ8x16"); return;
465 case Iop_CmpNEZ16x8: vex_printf("CmpNEZ16x8"); return;
sewardj70f676d2004-12-10 14:59:57 +0000466 case Iop_CmpNEZ32x4: vex_printf("CmpNEZ32x4"); return;
sewardj109ffdb2004-12-10 21:45:38 +0000467 case Iop_CmpNEZ64x2: vex_printf("CmpNEZ64x2"); return;
sewardj164f9272004-12-09 00:39:32 +0000468
469 case Iop_Add8x16: vex_printf("Add8x16"); return;
470 case Iop_Add16x8: vex_printf("Add16x8"); return;
471 case Iop_Add32x4: vex_printf("Add32x4"); return;
472 case Iop_Add64x2: vex_printf("Add64x2"); return;
473 case Iop_QAdd8Ux16: vex_printf("QAdd8Ux16"); return;
474 case Iop_QAdd16Ux8: vex_printf("QAdd16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000475 case Iop_QAdd32Ux4: vex_printf("QAdd32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000476 case Iop_QAdd8Sx16: vex_printf("QAdd8Sx16"); return;
477 case Iop_QAdd16Sx8: vex_printf("QAdd16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000478 case Iop_QAdd32Sx4: vex_printf("QAdd32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000479
480 case Iop_Sub8x16: vex_printf("Sub8x16"); return;
481 case Iop_Sub16x8: vex_printf("Sub16x8"); return;
482 case Iop_Sub32x4: vex_printf("Sub32x4"); return;
483 case Iop_Sub64x2: vex_printf("Sub64x2"); return;
484 case Iop_QSub8Ux16: vex_printf("QSub8Ux16"); return;
485 case Iop_QSub16Ux8: vex_printf("QSub16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000486 case Iop_QSub32Ux4: vex_printf("QSub32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000487 case Iop_QSub8Sx16: vex_printf("QSub8Sx16"); return;
488 case Iop_QSub16Sx8: vex_printf("QSub16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000489 case Iop_QSub32Sx4: vex_printf("QSub32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000490
491 case Iop_Mul16x8: vex_printf("Mul16x8"); return;
492 case Iop_MulHi16Ux8: vex_printf("MulHi16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000493 case Iop_MulHi32Ux4: vex_printf("MulHi32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000494 case Iop_MulHi16Sx8: vex_printf("MulHi16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000495 case Iop_MulHi32Sx4: vex_printf("MulHi32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000496
cerion1ac656a2005-11-04 19:44:48 +0000497 case Iop_MullEven8Ux16: vex_printf("MullEven8Ux16"); return;
498 case Iop_MullEven16Ux8: vex_printf("MullEven16Ux8"); return;
499 case Iop_MullEven8Sx16: vex_printf("MullEven8Sx16"); return;
500 case Iop_MullEven16Sx8: vex_printf("MullEven16Sx8"); return;
501
sewardj164f9272004-12-09 00:39:32 +0000502 case Iop_Avg8Ux16: vex_printf("Avg8Ux16"); return;
503 case Iop_Avg16Ux8: vex_printf("Avg16Ux8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000504 case Iop_Avg32Ux4: vex_printf("Avg32Ux4"); return;
505 case Iop_Avg8Sx16: vex_printf("Avg8Sx16"); return;
506 case Iop_Avg16Sx8: vex_printf("Avg16Sx8"); return;
507 case Iop_Avg32Sx4: vex_printf("Avg32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000508
cerionf887b3e2005-09-13 16:34:28 +0000509 case Iop_Max8Sx16: vex_printf("Max8Sx16"); return;
sewardj164f9272004-12-09 00:39:32 +0000510 case Iop_Max16Sx8: vex_printf("Max16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000511 case Iop_Max32Sx4: vex_printf("Max32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000512 case Iop_Max8Ux16: vex_printf("Max8Ux16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000513 case Iop_Max16Ux8: vex_printf("Max16Ux8"); return;
514 case Iop_Max32Ux4: vex_printf("Max32Ux4"); return;
515
516 case Iop_Min8Sx16: vex_printf("Min8Sx16"); return;
sewardj164f9272004-12-09 00:39:32 +0000517 case Iop_Min16Sx8: vex_printf("Min16Sx8"); return;
cerionf887b3e2005-09-13 16:34:28 +0000518 case Iop_Min32Sx4: vex_printf("Min32Sx4"); return;
sewardj164f9272004-12-09 00:39:32 +0000519 case Iop_Min8Ux16: vex_printf("Min8Ux16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000520 case Iop_Min16Ux8: vex_printf("Min16Ux8"); return;
521 case Iop_Min32Ux4: vex_printf("Min32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000522
523 case Iop_CmpEQ8x16: vex_printf("CmpEQ8x16"); return;
524 case Iop_CmpEQ16x8: vex_printf("CmpEQ16x8"); return;
525 case Iop_CmpEQ32x4: vex_printf("CmpEQ32x4"); return;
526 case Iop_CmpGT8Sx16: vex_printf("CmpGT8Sx16"); return;
527 case Iop_CmpGT16Sx8: vex_printf("CmpGT16Sx8"); return;
528 case Iop_CmpGT32Sx4: vex_printf("CmpGT32Sx4"); return;
cerionf887b3e2005-09-13 16:34:28 +0000529 case Iop_CmpGT8Ux16: vex_printf("CmpGT8Ux16"); return;
530 case Iop_CmpGT16Ux8: vex_printf("CmpGT16Ux8"); return;
531 case Iop_CmpGT32Ux4: vex_printf("CmpGT32Ux4"); return;
532
533 case Iop_ShlV128: vex_printf("ShlV128"); return;
534 case Iop_ShrV128: vex_printf("ShrV128"); return;
sewardj164f9272004-12-09 00:39:32 +0000535
cerion2a4b8452005-09-15 16:28:36 +0000536 case Iop_ShlN8x16: vex_printf("ShlN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000537 case Iop_ShlN16x8: vex_printf("ShlN16x8"); return;
538 case Iop_ShlN32x4: vex_printf("ShlN32x4"); return;
539 case Iop_ShlN64x2: vex_printf("ShlN64x2"); return;
cerion2a4b8452005-09-15 16:28:36 +0000540 case Iop_ShrN8x16: vex_printf("ShrN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000541 case Iop_ShrN16x8: vex_printf("ShrN16x8"); return;
542 case Iop_ShrN32x4: vex_printf("ShrN32x4"); return;
543 case Iop_ShrN64x2: vex_printf("ShrN64x2"); return;
cerion2a4b8452005-09-15 16:28:36 +0000544 case Iop_SarN8x16: vex_printf("SarN8x16"); return;
sewardj164f9272004-12-09 00:39:32 +0000545 case Iop_SarN16x8: vex_printf("SarN16x8"); return;
546 case Iop_SarN32x4: vex_printf("SarN32x4"); return;
547
cerionf887b3e2005-09-13 16:34:28 +0000548 case Iop_Shl8x16: vex_printf("Shl8x16"); return;
549 case Iop_Shl16x8: vex_printf("Shl16x8"); return;
550 case Iop_Shl32x4: vex_printf("Shl32x4"); return;
551 case Iop_Shr8x16: vex_printf("Shr8x16"); return;
552 case Iop_Shr16x8: vex_printf("Shr16x8"); return;
553 case Iop_Shr32x4: vex_printf("Shr32x4"); return;
554 case Iop_Sar8x16: vex_printf("Sar8x16"); return;
555 case Iop_Sar16x8: vex_printf("Sar16x8"); return;
556 case Iop_Sar32x4: vex_printf("Sar32x4"); return;
sewardj1bee5612005-11-10 18:10:58 +0000557 case Iop_Rol8x16: vex_printf("Rol8x16"); return;
558 case Iop_Rol16x8: vex_printf("Rol16x8"); return;
559 case Iop_Rol32x4: vex_printf("Rol32x4"); return;
cerionf887b3e2005-09-13 16:34:28 +0000560
sewardj1bee5612005-11-10 18:10:58 +0000561 case Iop_Narrow16x8: vex_printf("Narrow16x8"); return;
562 case Iop_Narrow32x4: vex_printf("Narrow32x4"); return;
sewardj164f9272004-12-09 00:39:32 +0000563 case Iop_QNarrow16Ux8: vex_printf("QNarrow16Ux8"); return;
cerion9e7677b2005-09-13 17:25:41 +0000564 case Iop_QNarrow32Ux4: vex_printf("QNarrow32Ux4"); return;
sewardj164f9272004-12-09 00:39:32 +0000565 case Iop_QNarrow16Sx8: vex_printf("QNarrow16Sx8"); return;
566 case Iop_QNarrow32Sx4: vex_printf("QNarrow32Sx4"); return;
567
568 case Iop_InterleaveHI8x16: vex_printf("InterleaveHI8x16"); return;
569 case Iop_InterleaveHI16x8: vex_printf("InterleaveHI16x8"); return;
570 case Iop_InterleaveHI32x4: vex_printf("InterleaveHI32x4"); return;
571 case Iop_InterleaveHI64x2: vex_printf("InterleaveHI64x2"); return;
572 case Iop_InterleaveLO8x16: vex_printf("InterleaveLO8x16"); return;
573 case Iop_InterleaveLO16x8: vex_printf("InterleaveLO16x8"); return;
574 case Iop_InterleaveLO32x4: vex_printf("InterleaveLO32x4"); return;
575 case Iop_InterleaveLO64x2: vex_printf("InterleaveLO64x2"); return;
576
sewardjdc1f9132005-10-22 12:49:49 +0000577 case Iop_Perm8x16: vex_printf("Perm8x16"); return;
cerionf887b3e2005-09-13 16:34:28 +0000578
sewardjc9a43662004-11-30 18:51:59 +0000579 default: vpanic("ppIROp(1)");
sewardj41f43bc2004-07-08 14:23:22 +0000580 }
sewardj1fb8c922009-07-12 12:56:53 +0000581
582 vassert(str);
sewardj41f43bc2004-07-08 14:23:22 +0000583 switch (op - base) {
sewardjecbaee72008-11-01 23:54:45 +0000584 case 0: vex_printf("%s",str); vex_printf("8"); break;
585 case 1: vex_printf("%s",str); vex_printf("16"); break;
586 case 2: vex_printf("%s",str); vex_printf("32"); break;
587 case 3: vex_printf("%s",str); vex_printf("64"); break;
sewardj41f43bc2004-07-08 14:23:22 +0000588 default: vpanic("ppIROp(2)");
589 }
sewardje3d0d2e2004-06-27 10:42:44 +0000590}
591
sewardj35421a32004-07-05 13:12:34 +0000592void ppIRExpr ( IRExpr* e )
sewardje3d0d2e2004-06-27 10:42:44 +0000593{
sewardje87b4842004-07-10 12:23:30 +0000594 Int i;
sewardje3d0d2e2004-06-27 10:42:44 +0000595 switch (e->tag) {
sewardj443cd9d2004-07-18 23:06:45 +0000596 case Iex_Binder:
597 vex_printf("BIND-%d", e->Iex.Binder.binder);
598 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000599 case Iex_Get:
sewardjc9a43662004-11-30 18:51:59 +0000600 vex_printf( "GET:" );
sewardjfbcaf332004-07-08 01:46:01 +0000601 ppIRType(e->Iex.Get.ty);
sewardjc9a43662004-11-30 18:51:59 +0000602 vex_printf("(%d)", e->Iex.Get.offset);
sewardjec6ad592004-06-20 12:26:53 +0000603 break;
sewardjbb53f8c2004-08-14 11:50:01 +0000604 case Iex_GetI:
sewardj2d3f77c2004-09-22 23:49:09 +0000605 vex_printf( "GETI" );
sewardjdd40fdf2006-12-24 02:20:24 +0000606 ppIRRegArray(e->Iex.GetI.descr);
sewardj2d3f77c2004-09-22 23:49:09 +0000607 vex_printf("[");
sewardjeeac8412004-11-02 00:26:55 +0000608 ppIRExpr(e->Iex.GetI.ix);
sewardj2d3f77c2004-09-22 23:49:09 +0000609 vex_printf(",%d]", e->Iex.GetI.bias);
sewardjbb53f8c2004-08-14 11:50:01 +0000610 break;
sewardjdd40fdf2006-12-24 02:20:24 +0000611 case Iex_RdTmp:
612 ppIRTemp(e->Iex.RdTmp.tmp);
sewardjec6ad592004-06-20 12:26:53 +0000613 break;
sewardj40c80262006-02-08 19:30:46 +0000614 case Iex_Qop:
615 ppIROp(e->Iex.Qop.op);
616 vex_printf( "(" );
617 ppIRExpr(e->Iex.Qop.arg1);
618 vex_printf( "," );
619 ppIRExpr(e->Iex.Qop.arg2);
620 vex_printf( "," );
621 ppIRExpr(e->Iex.Qop.arg3);
622 vex_printf( "," );
623 ppIRExpr(e->Iex.Qop.arg4);
624 vex_printf( ")" );
625 break;
sewardjb183b852006-02-03 16:08:03 +0000626 case Iex_Triop:
627 ppIROp(e->Iex.Triop.op);
628 vex_printf( "(" );
629 ppIRExpr(e->Iex.Triop.arg1);
630 vex_printf( "," );
631 ppIRExpr(e->Iex.Triop.arg2);
632 vex_printf( "," );
633 ppIRExpr(e->Iex.Triop.arg3);
634 vex_printf( ")" );
635 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000636 case Iex_Binop:
sewardj35421a32004-07-05 13:12:34 +0000637 ppIROp(e->Iex.Binop.op);
638 vex_printf( "(" );
639 ppIRExpr(e->Iex.Binop.arg1);
640 vex_printf( "," );
641 ppIRExpr(e->Iex.Binop.arg2);
642 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000643 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000644 case Iex_Unop:
sewardj35421a32004-07-05 13:12:34 +0000645 ppIROp(e->Iex.Unop.op);
646 vex_printf( "(" );
647 ppIRExpr(e->Iex.Unop.arg);
648 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000649 break;
sewardjaf1ceca2005-06-30 23:31:27 +0000650 case Iex_Load:
sewardje9d8a262009-07-01 08:06:34 +0000651 vex_printf( "LD%s%s:", e->Iex.Load.end==Iend_LE ? "le" : "be",
652 e->Iex.Load.isLL ? "-LL" : "" );
sewardjaf1ceca2005-06-30 23:31:27 +0000653 ppIRType(e->Iex.Load.ty);
sewardje05c42c2004-07-08 20:25:10 +0000654 vex_printf( "(" );
sewardjaf1ceca2005-06-30 23:31:27 +0000655 ppIRExpr(e->Iex.Load.addr);
sewardj35421a32004-07-05 13:12:34 +0000656 vex_printf( ")" );
sewardjec6ad592004-06-20 12:26:53 +0000657 break;
sewardje3d0d2e2004-06-27 10:42:44 +0000658 case Iex_Const:
sewardj35421a32004-07-05 13:12:34 +0000659 ppIRConst(e->Iex.Const.con);
sewardjec6ad592004-06-20 12:26:53 +0000660 break;
sewardje87b4842004-07-10 12:23:30 +0000661 case Iex_CCall:
sewardj8ea867b2004-10-30 19:03:02 +0000662 ppIRCallee(e->Iex.CCall.cee);
663 vex_printf("(");
sewardje87b4842004-07-10 12:23:30 +0000664 for (i = 0; e->Iex.CCall.args[i] != NULL; i++) {
665 ppIRExpr(e->Iex.CCall.args[i]);
666 if (e->Iex.CCall.args[i+1] != NULL)
667 vex_printf(",");
668 }
669 vex_printf("):");
670 ppIRType(e->Iex.CCall.retty);
671 break;
sewardj4042c7e2004-07-18 01:28:30 +0000672 case Iex_Mux0X:
673 vex_printf("Mux0X(");
674 ppIRExpr(e->Iex.Mux0X.cond);
sewardjeeb9ef82004-07-15 12:39:03 +0000675 vex_printf(",");
sewardj4042c7e2004-07-18 01:28:30 +0000676 ppIRExpr(e->Iex.Mux0X.expr0);
sewardjeeb9ef82004-07-15 12:39:03 +0000677 vex_printf(",");
sewardj4042c7e2004-07-18 01:28:30 +0000678 ppIRExpr(e->Iex.Mux0X.exprX);
sewardjeeb9ef82004-07-15 12:39:03 +0000679 vex_printf(")");
680 break;
sewardjec6ad592004-06-20 12:26:53 +0000681 default:
sewardj909c06d2005-02-19 22:47:41 +0000682 vpanic("ppIRExpr");
sewardjec6ad592004-06-20 12:26:53 +0000683 }
684}
685
sewardj17442fe2004-09-20 14:54:28 +0000686void ppIREffect ( IREffect fx )
687{
688 switch (fx) {
689 case Ifx_None: vex_printf("noFX"); return;
690 case Ifx_Read: vex_printf("RdFX"); return;
691 case Ifx_Write: vex_printf("WrFX"); return;
692 case Ifx_Modify: vex_printf("MoFX"); return;
693 default: vpanic("ppIREffect");
694 }
695}
696
697void ppIRDirty ( IRDirty* d )
698{
699 Int i;
sewardj92d168d2004-11-15 14:22:12 +0000700 if (d->tmp != IRTemp_INVALID) {
sewardj4b861de2004-11-03 15:24:42 +0000701 ppIRTemp(d->tmp);
702 vex_printf(" = ");
703 }
sewardjb8385d82004-11-02 01:34:15 +0000704 vex_printf("DIRTY ");
705 ppIRExpr(d->guard);
sewardjc5fc7aa2004-10-27 23:00:55 +0000706 if (d->needsBBP)
707 vex_printf(" NeedsBBP");
sewardj17442fe2004-09-20 14:54:28 +0000708 if (d->mFx != Ifx_None) {
sewardj49651f42004-10-28 22:11:04 +0000709 vex_printf(" ");
sewardj17442fe2004-09-20 14:54:28 +0000710 ppIREffect(d->mFx);
711 vex_printf("-mem(");
712 ppIRExpr(d->mAddr);
sewardj49651f42004-10-28 22:11:04 +0000713 vex_printf(",%d)", d->mSize);
sewardj17442fe2004-09-20 14:54:28 +0000714 }
715 for (i = 0; i < d->nFxState; i++) {
sewardj49651f42004-10-28 22:11:04 +0000716 vex_printf(" ");
sewardj17442fe2004-09-20 14:54:28 +0000717 ppIREffect(d->fxState[i].fx);
sewardj49651f42004-10-28 22:11:04 +0000718 vex_printf("-gst(%d,%d)", d->fxState[i].offset, d->fxState[i].size);
sewardj17442fe2004-09-20 14:54:28 +0000719 }
sewardjc5fc7aa2004-10-27 23:00:55 +0000720 vex_printf(" ::: ");
sewardj8ea867b2004-10-30 19:03:02 +0000721 ppIRCallee(d->cee);
722 vex_printf("(");
sewardj17442fe2004-09-20 14:54:28 +0000723 for (i = 0; d->args[i] != NULL; i++) {
724 ppIRExpr(d->args[i]);
725 if (d->args[i+1] != NULL) {
726 vex_printf(",");
727 }
728 }
729 vex_printf(")");
730}
731
sewardje9d8a262009-07-01 08:06:34 +0000732void ppIRCAS ( IRCAS* cas )
733{
734 /* Print even structurally invalid constructions, as an aid to
735 debugging. */
736 if (cas->oldHi != IRTemp_INVALID) {
737 ppIRTemp(cas->oldHi);
738 vex_printf(",");
739 }
740 ppIRTemp(cas->oldLo);
741 vex_printf(" = CAS%s(", cas->end==Iend_LE ? "le" : "be" );
742 ppIRExpr(cas->addr);
743 vex_printf("::");
744 if (cas->expdHi) {
745 ppIRExpr(cas->expdHi);
746 vex_printf(",");
747 }
748 ppIRExpr(cas->expdLo);
749 vex_printf("->");
750 if (cas->dataHi) {
751 ppIRExpr(cas->dataHi);
752 vex_printf(",");
753 }
754 ppIRExpr(cas->dataLo);
755 vex_printf(")");
756}
757
sewardj893aada2004-11-29 19:57:54 +0000758void ppIRJumpKind ( IRJumpKind kind )
759{
760 switch (kind) {
sewardj4fa325a2005-11-03 13:27:24 +0000761 case Ijk_Boring: vex_printf("Boring"); break;
762 case Ijk_Call: vex_printf("Call"); break;
763 case Ijk_Ret: vex_printf("Return"); break;
764 case Ijk_ClientReq: vex_printf("ClientReq"); break;
765 case Ijk_Yield: vex_printf("Yield"); break;
766 case Ijk_EmWarn: vex_printf("EmWarn"); break;
sewardj9dd9cf12006-01-20 14:13:55 +0000767 case Ijk_EmFail: vex_printf("EmFail"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000768 case Ijk_NoDecode: vex_printf("NoDecode"); break;
769 case Ijk_MapFail: vex_printf("MapFail"); break;
770 case Ijk_TInval: vex_printf("Invalidate"); break;
sewardjce02aa72006-01-12 12:27:58 +0000771 case Ijk_NoRedir: vex_printf("NoRedir"); break;
sewardj0f500042007-08-29 09:09:17 +0000772 case Ijk_SigTRAP: vex_printf("SigTRAP"); break;
773 case Ijk_SigSEGV: vex_printf("SigSEGV"); break;
sewardje9d8a262009-07-01 08:06:34 +0000774 case Ijk_SigBUS: vex_printf("SigBUS"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000775 case Ijk_Sys_syscall: vex_printf("Sys_syscall"); break;
776 case Ijk_Sys_int32: vex_printf("Sys_int32"); break;
777 case Ijk_Sys_int128: vex_printf("Sys_int128"); break;
sewardjd660d412008-12-03 21:29:59 +0000778 case Ijk_Sys_int129: vex_printf("Sys_int129"); break;
779 case Ijk_Sys_int130: vex_printf("Sys_int130"); break;
sewardj4fa325a2005-11-03 13:27:24 +0000780 case Ijk_Sys_sysenter: vex_printf("Sys_sysenter"); break;
781 default: vpanic("ppIRJumpKind");
sewardj893aada2004-11-29 19:57:54 +0000782 }
783}
784
sewardjc4356f02007-11-09 21:15:04 +0000785void ppIRMBusEvent ( IRMBusEvent event )
786{
787 switch (event) {
sewardje9d8a262009-07-01 08:06:34 +0000788 case Imbe_Fence: vex_printf("Fence"); break;
789 default: vpanic("ppIRMBusEvent");
sewardjc4356f02007-11-09 21:15:04 +0000790 }
791}
792
sewardj35421a32004-07-05 13:12:34 +0000793void ppIRStmt ( IRStmt* s )
sewardjec6ad592004-06-20 12:26:53 +0000794{
sewardjd2445f62005-03-21 00:15:53 +0000795 if (!s) {
796 vex_printf("!!! IRStmt* which is NULL !!!");
797 return;
798 }
sewardj17442fe2004-09-20 14:54:28 +0000799 switch (s->tag) {
sewardjd2445f62005-03-21 00:15:53 +0000800 case Ist_NoOp:
801 vex_printf("IR-NoOp");
802 break;
sewardjf1689312005-03-16 18:19:10 +0000803 case Ist_IMark:
sewardj0c12a272005-03-17 09:57:03 +0000804 vex_printf( "------ IMark(0x%llx, %d) ------",
805 s->Ist.IMark.addr, s->Ist.IMark.len);
sewardjf1689312005-03-16 18:19:10 +0000806 break;
sewardj5a9ffab2005-05-12 17:55:01 +0000807 case Ist_AbiHint:
808 vex_printf("====== AbiHint(");
809 ppIRExpr(s->Ist.AbiHint.base);
sewardj478646f2008-05-01 20:13:04 +0000810 vex_printf(", %d, ", s->Ist.AbiHint.len);
811 ppIRExpr(s->Ist.AbiHint.nia);
812 vex_printf(") ======");
sewardj5a9ffab2005-05-12 17:55:01 +0000813 break;
sewardj17442fe2004-09-20 14:54:28 +0000814 case Ist_Put:
815 vex_printf( "PUT(%d) = ", s->Ist.Put.offset);
sewardj6d076362004-09-23 11:06:17 +0000816 ppIRExpr(s->Ist.Put.data);
sewardj17442fe2004-09-20 14:54:28 +0000817 break;
818 case Ist_PutI:
sewardj2d3f77c2004-09-22 23:49:09 +0000819 vex_printf( "PUTI" );
sewardjdd40fdf2006-12-24 02:20:24 +0000820 ppIRRegArray(s->Ist.PutI.descr);
sewardj2d3f77c2004-09-22 23:49:09 +0000821 vex_printf("[");
sewardjeeac8412004-11-02 00:26:55 +0000822 ppIRExpr(s->Ist.PutI.ix);
sewardj2d3f77c2004-09-22 23:49:09 +0000823 vex_printf(",%d] = ", s->Ist.PutI.bias);
824 ppIRExpr(s->Ist.PutI.data);
sewardj17442fe2004-09-20 14:54:28 +0000825 break;
sewardjdd40fdf2006-12-24 02:20:24 +0000826 case Ist_WrTmp:
827 ppIRTemp(s->Ist.WrTmp.tmp);
sewardj17442fe2004-09-20 14:54:28 +0000828 vex_printf( " = " );
sewardjdd40fdf2006-12-24 02:20:24 +0000829 ppIRExpr(s->Ist.WrTmp.data);
sewardj17442fe2004-09-20 14:54:28 +0000830 break;
sewardjaf1ceca2005-06-30 23:31:27 +0000831 case Ist_Store:
sewardje9d8a262009-07-01 08:06:34 +0000832 if (s->Ist.Store.resSC != IRTemp_INVALID) {
833 ppIRTemp(s->Ist.Store.resSC);
834 vex_printf( " = SC( " );
835 }
sewardjaf1ceca2005-06-30 23:31:27 +0000836 vex_printf( "ST%s(", s->Ist.Store.end==Iend_LE ? "le" : "be" );
837 ppIRExpr(s->Ist.Store.addr);
sewardj17442fe2004-09-20 14:54:28 +0000838 vex_printf( ") = ");
sewardjaf1ceca2005-06-30 23:31:27 +0000839 ppIRExpr(s->Ist.Store.data);
sewardje9d8a262009-07-01 08:06:34 +0000840 if (s->Ist.Store.resSC != IRTemp_INVALID)
841 vex_printf( " )" );
842 break;
843 case Ist_CAS:
844 ppIRCAS(s->Ist.CAS.details);
sewardj17442fe2004-09-20 14:54:28 +0000845 break;
846 case Ist_Dirty:
847 ppIRDirty(s->Ist.Dirty.details);
848 break;
sewardjc4356f02007-11-09 21:15:04 +0000849 case Ist_MBE:
850 vex_printf("IR-");
851 ppIRMBusEvent(s->Ist.MBE.event);
sewardj3e838932005-01-07 12:09:15 +0000852 break;
sewardj17442fe2004-09-20 14:54:28 +0000853 case Ist_Exit:
854 vex_printf( "if (" );
sewardj0276d4b2004-11-15 15:30:21 +0000855 ppIRExpr(s->Ist.Exit.guard);
sewardj893aada2004-11-29 19:57:54 +0000856 vex_printf( ") goto {");
857 ppIRJumpKind(s->Ist.Exit.jk);
858 vex_printf("} ");
sewardj17442fe2004-09-20 14:54:28 +0000859 ppIRConst(s->Ist.Exit.dst);
860 break;
861 default:
862 vpanic("ppIRStmt");
863 }
sewardjec6ad592004-06-20 12:26:53 +0000864}
865
sewardj35421a32004-07-05 13:12:34 +0000866void ppIRTypeEnv ( IRTypeEnv* env ) {
sewardjc97096c2004-06-30 09:28:04 +0000867 UInt i;
sewardje539a402004-07-14 18:24:17 +0000868 for (i = 0; i < env->types_used; i++) {
sewardjc97096c2004-06-30 09:28:04 +0000869 if (i % 8 == 0)
sewardj35421a32004-07-05 13:12:34 +0000870 vex_printf( " ");
sewardje539a402004-07-14 18:24:17 +0000871 ppIRTemp(i);
sewardj35421a32004-07-05 13:12:34 +0000872 vex_printf( ":");
sewardje539a402004-07-14 18:24:17 +0000873 ppIRType(env->types[i]);
sewardjc97096c2004-06-30 09:28:04 +0000874 if (i % 8 == 7)
sewardj35421a32004-07-05 13:12:34 +0000875 vex_printf( "\n");
sewardjc97096c2004-06-30 09:28:04 +0000876 else
sewardj35421a32004-07-05 13:12:34 +0000877 vex_printf( " ");
sewardjc97096c2004-06-30 09:28:04 +0000878 }
sewardje539a402004-07-14 18:24:17 +0000879 if (env->types_used > 0 && env->types_used % 8 != 7)
sewardj35421a32004-07-05 13:12:34 +0000880 vex_printf( "\n");
sewardjc97096c2004-06-30 09:28:04 +0000881}
882
sewardjdd40fdf2006-12-24 02:20:24 +0000883void ppIRSB ( IRSB* bb )
sewardjec6ad592004-06-20 12:26:53 +0000884{
sewardjd7cb8532004-08-17 23:59:23 +0000885 Int i;
sewardjdd40fdf2006-12-24 02:20:24 +0000886 vex_printf("IRSB {\n");
sewardj35421a32004-07-05 13:12:34 +0000887 ppIRTypeEnv(bb->tyenv);
sewardj35439212004-07-14 22:36:10 +0000888 vex_printf("\n");
sewardjd7cb8532004-08-17 23:59:23 +0000889 for (i = 0; i < bb->stmts_used; i++) {
sewardjd2445f62005-03-21 00:15:53 +0000890 vex_printf( " ");
891 ppIRStmt(bb->stmts[i]);
sewardj35421a32004-07-05 13:12:34 +0000892 vex_printf( "\n");
sewardjec6ad592004-06-20 12:26:53 +0000893 }
sewardje539a402004-07-14 18:24:17 +0000894 vex_printf( " goto {");
895 ppIRJumpKind(bb->jumpkind);
896 vex_printf( "} ");
897 ppIRExpr( bb->next );
sewardj35439212004-07-14 22:36:10 +0000898 vex_printf( "\n}\n");
sewardjec6ad592004-06-20 12:26:53 +0000899}
900
901
902/*---------------------------------------------------------------*/
903/*--- Constructors ---*/
904/*---------------------------------------------------------------*/
905
sewardjc97096c2004-06-30 09:28:04 +0000906
907/* Constructors -- IRConst */
908
sewardjba999312004-11-15 15:21:17 +0000909IRConst* IRConst_U1 ( Bool bit )
sewardjb8e75862004-08-19 17:58:45 +0000910{
911 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjba999312004-11-15 15:21:17 +0000912 c->tag = Ico_U1;
913 c->Ico.U1 = bit;
sewardj4b861de2004-11-03 15:24:42 +0000914 /* call me paranoid; I don't care :-) */
915 vassert(bit == False || bit == True);
sewardjb8e75862004-08-19 17:58:45 +0000916 return c;
917}
sewardjc97096c2004-06-30 09:28:04 +0000918IRConst* IRConst_U8 ( UChar u8 )
919{
sewardj35421a32004-07-05 13:12:34 +0000920 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000921 c->tag = Ico_U8;
922 c->Ico.U8 = u8;
923 return c;
924}
925IRConst* IRConst_U16 ( UShort u16 )
926{
sewardj35421a32004-07-05 13:12:34 +0000927 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000928 c->tag = Ico_U16;
929 c->Ico.U16 = u16;
930 return c;
931}
932IRConst* IRConst_U32 ( UInt u32 )
933{
sewardj35421a32004-07-05 13:12:34 +0000934 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000935 c->tag = Ico_U32;
936 c->Ico.U32 = u32;
937 return c;
938}
939IRConst* IRConst_U64 ( ULong u64 )
940{
sewardj35421a32004-07-05 13:12:34 +0000941 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
sewardjc97096c2004-06-30 09:28:04 +0000942 c->tag = Ico_U64;
943 c->Ico.U64 = u64;
944 return c;
945}
sewardja58ea662004-08-15 03:12:41 +0000946IRConst* IRConst_F64 ( Double f64 )
947{
948 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
949 c->tag = Ico_F64;
950 c->Ico.F64 = f64;
951 return c;
952}
sewardj17442fe2004-09-20 14:54:28 +0000953IRConst* IRConst_F64i ( ULong f64i )
sewardj207557a2004-08-27 12:00:18 +0000954{
sewardj17442fe2004-09-20 14:54:28 +0000955 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
956 c->tag = Ico_F64i;
957 c->Ico.F64i = f64i;
sewardj207557a2004-08-27 12:00:18 +0000958 return c;
959}
sewardj1e6ad742004-12-02 16:16:11 +0000960IRConst* IRConst_V128 ( UShort con )
961{
962 IRConst* c = LibVEX_Alloc(sizeof(IRConst));
963 c->tag = Ico_V128;
964 c->Ico.V128 = con;
965 return c;
966}
sewardjc97096c2004-06-30 09:28:04 +0000967
sewardj8ea867b2004-10-30 19:03:02 +0000968/* Constructors -- IRCallee */
969
sewardj2d49b432005-02-01 00:37:06 +0000970IRCallee* mkIRCallee ( Int regparms, HChar* name, void* addr )
sewardj8ea867b2004-10-30 19:03:02 +0000971{
972 IRCallee* ce = LibVEX_Alloc(sizeof(IRCallee));
sewardj77352542004-10-30 20:39:01 +0000973 ce->regparms = regparms;
974 ce->name = name;
975 ce->addr = addr;
sewardj43c56462004-11-06 12:17:57 +0000976 ce->mcx_mask = 0;
sewardj77352542004-10-30 20:39:01 +0000977 vassert(regparms >= 0 && regparms <= 3);
sewardj8ea867b2004-10-30 19:03:02 +0000978 vassert(name != NULL);
979 vassert(addr != 0);
980 return ce;
981}
982
983
sewardjdd40fdf2006-12-24 02:20:24 +0000984/* Constructors -- IRRegArray */
sewardje3d0d2e2004-06-27 10:42:44 +0000985
sewardjdd40fdf2006-12-24 02:20:24 +0000986IRRegArray* mkIRRegArray ( Int base, IRType elemTy, Int nElems )
sewardj2d3f77c2004-09-22 23:49:09 +0000987{
sewardjdd40fdf2006-12-24 02:20:24 +0000988 IRRegArray* arr = LibVEX_Alloc(sizeof(IRRegArray));
989 arr->base = base;
990 arr->elemTy = elemTy;
991 arr->nElems = nElems;
sewardj2d3f77c2004-09-22 23:49:09 +0000992 vassert(!(arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */));
sewardjba999312004-11-15 15:21:17 +0000993 vassert(!(arr->elemTy == Ity_I1));
sewardj2d3f77c2004-09-22 23:49:09 +0000994 vassert(!(arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */));
995 return arr;
996}
997
998
999/* Constructors -- IRExpr */
1000
sewardj443cd9d2004-07-18 23:06:45 +00001001IRExpr* IRExpr_Binder ( Int binder ) {
1002 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1003 e->tag = Iex_Binder;
1004 e->Iex.Binder.binder = binder;
1005 return e;
1006}
sewardjfbcaf332004-07-08 01:46:01 +00001007IRExpr* IRExpr_Get ( Int off, IRType ty ) {
sewardj35421a32004-07-05 13:12:34 +00001008 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001009 e->tag = Iex_Get;
1010 e->Iex.Get.offset = off;
sewardjfbcaf332004-07-08 01:46:01 +00001011 e->Iex.Get.ty = ty;
sewardje3d0d2e2004-06-27 10:42:44 +00001012 return e;
1013}
sewardjdd40fdf2006-12-24 02:20:24 +00001014IRExpr* IRExpr_GetI ( IRRegArray* descr, IRExpr* ix, Int bias ) {
sewardj2d3f77c2004-09-22 23:49:09 +00001015 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1016 e->tag = Iex_GetI;
1017 e->Iex.GetI.descr = descr;
sewardjeeac8412004-11-02 00:26:55 +00001018 e->Iex.GetI.ix = ix;
sewardj2d3f77c2004-09-22 23:49:09 +00001019 e->Iex.GetI.bias = bias;
sewardjd1725d12004-08-12 20:46:53 +00001020 return e;
1021}
sewardjdd40fdf2006-12-24 02:20:24 +00001022IRExpr* IRExpr_RdTmp ( IRTemp tmp ) {
1023 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1024 e->tag = Iex_RdTmp;
1025 e->Iex.RdTmp.tmp = tmp;
sewardje3d0d2e2004-06-27 10:42:44 +00001026 return e;
1027}
sewardj40c80262006-02-08 19:30:46 +00001028IRExpr* IRExpr_Qop ( IROp op, IRExpr* arg1, IRExpr* arg2,
1029 IRExpr* arg3, IRExpr* arg4 ) {
1030 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1031 e->tag = Iex_Qop;
1032 e->Iex.Qop.op = op;
1033 e->Iex.Qop.arg1 = arg1;
1034 e->Iex.Qop.arg2 = arg2;
1035 e->Iex.Qop.arg3 = arg3;
1036 e->Iex.Qop.arg4 = arg4;
1037 return e;
1038}
sewardjb183b852006-02-03 16:08:03 +00001039IRExpr* IRExpr_Triop ( IROp op, IRExpr* arg1,
1040 IRExpr* arg2, IRExpr* arg3 ) {
1041 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1042 e->tag = Iex_Triop;
1043 e->Iex.Triop.op = op;
1044 e->Iex.Triop.arg1 = arg1;
1045 e->Iex.Triop.arg2 = arg2;
1046 e->Iex.Triop.arg3 = arg3;
1047 return e;
1048}
sewardjc97096c2004-06-30 09:28:04 +00001049IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 ) {
sewardj35421a32004-07-05 13:12:34 +00001050 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001051 e->tag = Iex_Binop;
1052 e->Iex.Binop.op = op;
1053 e->Iex.Binop.arg1 = arg1;
1054 e->Iex.Binop.arg2 = arg2;
1055 return e;
1056}
sewardjc97096c2004-06-30 09:28:04 +00001057IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg ) {
sewardj35421a32004-07-05 13:12:34 +00001058 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001059 e->tag = Iex_Unop;
1060 e->Iex.Unop.op = op;
1061 e->Iex.Unop.arg = arg;
1062 return e;
1063}
sewardje9d8a262009-07-01 08:06:34 +00001064IRExpr* IRExpr_Load ( Bool isLL, IREndness end, IRType ty, IRExpr* addr ) {
sewardj35421a32004-07-05 13:12:34 +00001065 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardjaf1ceca2005-06-30 23:31:27 +00001066 e->tag = Iex_Load;
sewardje9d8a262009-07-01 08:06:34 +00001067 e->Iex.Load.isLL = isLL;
sewardjaf1ceca2005-06-30 23:31:27 +00001068 e->Iex.Load.end = end;
1069 e->Iex.Load.ty = ty;
1070 e->Iex.Load.addr = addr;
1071 vassert(end == Iend_LE || end == Iend_BE);
sewardje3d0d2e2004-06-27 10:42:44 +00001072 return e;
1073}
sewardjc97096c2004-06-30 09:28:04 +00001074IRExpr* IRExpr_Const ( IRConst* con ) {
sewardj35421a32004-07-05 13:12:34 +00001075 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardje3d0d2e2004-06-27 10:42:44 +00001076 e->tag = Iex_Const;
1077 e->Iex.Const.con = con;
1078 return e;
sewardjec6ad592004-06-20 12:26:53 +00001079}
sewardj8ea867b2004-10-30 19:03:02 +00001080IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args ) {
sewardje87b4842004-07-10 12:23:30 +00001081 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
1082 e->tag = Iex_CCall;
sewardj8ea867b2004-10-30 19:03:02 +00001083 e->Iex.CCall.cee = cee;
sewardje87b4842004-07-10 12:23:30 +00001084 e->Iex.CCall.retty = retty;
1085 e->Iex.CCall.args = args;
1086 return e;
1087}
sewardj4042c7e2004-07-18 01:28:30 +00001088IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX ) {
sewardjeeb9ef82004-07-15 12:39:03 +00001089 IRExpr* e = LibVEX_Alloc(sizeof(IRExpr));
sewardj4042c7e2004-07-18 01:28:30 +00001090 e->tag = Iex_Mux0X;
1091 e->Iex.Mux0X.cond = cond;
1092 e->Iex.Mux0X.expr0 = expr0;
1093 e->Iex.Mux0X.exprX = exprX;
sewardjeeb9ef82004-07-15 12:39:03 +00001094 return e;
1095}
sewardjec6ad592004-06-20 12:26:53 +00001096
sewardjec6ad592004-06-20 12:26:53 +00001097
sewardjc5fc7aa2004-10-27 23:00:55 +00001098/* Constructors for NULL-terminated IRExpr expression vectors,
1099 suitable for use as arg lists in clean/dirty helper calls. */
1100
1101IRExpr** mkIRExprVec_0 ( void ) {
1102 IRExpr** vec = LibVEX_Alloc(1 * sizeof(IRExpr*));
1103 vec[0] = NULL;
1104 return vec;
1105}
1106IRExpr** mkIRExprVec_1 ( IRExpr* arg1 ) {
1107 IRExpr** vec = LibVEX_Alloc(2 * sizeof(IRExpr*));
1108 vec[0] = arg1;
1109 vec[1] = NULL;
1110 return vec;
1111}
1112IRExpr** mkIRExprVec_2 ( IRExpr* arg1, IRExpr* arg2 ) {
1113 IRExpr** vec = LibVEX_Alloc(3 * sizeof(IRExpr*));
1114 vec[0] = arg1;
1115 vec[1] = arg2;
1116 vec[2] = NULL;
1117 return vec;
1118}
sewardjf9655262004-10-31 20:02:16 +00001119IRExpr** mkIRExprVec_3 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3 ) {
1120 IRExpr** vec = LibVEX_Alloc(4 * sizeof(IRExpr*));
1121 vec[0] = arg1;
1122 vec[1] = arg2;
1123 vec[2] = arg3;
1124 vec[3] = NULL;
1125 return vec;
1126}
sewardj78ec32b2007-01-08 05:09:55 +00001127IRExpr** mkIRExprVec_4 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1128 IRExpr* arg4 ) {
sewardjf9655262004-10-31 20:02:16 +00001129 IRExpr** vec = LibVEX_Alloc(5 * sizeof(IRExpr*));
1130 vec[0] = arg1;
1131 vec[1] = arg2;
1132 vec[2] = arg3;
1133 vec[3] = arg4;
1134 vec[4] = NULL;
1135 return vec;
1136}
sewardj78ec32b2007-01-08 05:09:55 +00001137IRExpr** mkIRExprVec_5 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1138 IRExpr* arg4, IRExpr* arg5 ) {
sewardjf32c67d2004-11-08 13:10:44 +00001139 IRExpr** vec = LibVEX_Alloc(6 * sizeof(IRExpr*));
1140 vec[0] = arg1;
1141 vec[1] = arg2;
1142 vec[2] = arg3;
1143 vec[3] = arg4;
1144 vec[4] = arg5;
1145 vec[5] = NULL;
1146 return vec;
1147}
sewardj78ec32b2007-01-08 05:09:55 +00001148IRExpr** mkIRExprVec_6 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1149 IRExpr* arg4, IRExpr* arg5, IRExpr* arg6 ) {
1150 IRExpr** vec = LibVEX_Alloc(7 * sizeof(IRExpr*));
1151 vec[0] = arg1;
1152 vec[1] = arg2;
1153 vec[2] = arg3;
1154 vec[3] = arg4;
1155 vec[4] = arg5;
1156 vec[5] = arg6;
1157 vec[6] = NULL;
1158 return vec;
1159}
1160IRExpr** mkIRExprVec_7 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3,
1161 IRExpr* arg4, IRExpr* arg5, IRExpr* arg6,
1162 IRExpr* arg7 ) {
1163 IRExpr** vec = LibVEX_Alloc(8 * sizeof(IRExpr*));
1164 vec[0] = arg1;
1165 vec[1] = arg2;
1166 vec[2] = arg3;
1167 vec[3] = arg4;
1168 vec[4] = arg5;
1169 vec[5] = arg6;
1170 vec[6] = arg7;
1171 vec[7] = NULL;
1172 return vec;
1173}
sewardjc5fc7aa2004-10-27 23:00:55 +00001174
1175
sewardj17442fe2004-09-20 14:54:28 +00001176/* Constructors -- IRDirty */
1177
sewardjc5fc7aa2004-10-27 23:00:55 +00001178IRDirty* emptyIRDirty ( void ) {
sewardj17442fe2004-09-20 14:54:28 +00001179 IRDirty* d = LibVEX_Alloc(sizeof(IRDirty));
sewardj8ea867b2004-10-30 19:03:02 +00001180 d->cee = NULL;
sewardjb8385d82004-11-02 01:34:15 +00001181 d->guard = NULL;
sewardj17442fe2004-09-20 14:54:28 +00001182 d->args = NULL;
sewardj92d168d2004-11-15 14:22:12 +00001183 d->tmp = IRTemp_INVALID;
sewardj17442fe2004-09-20 14:54:28 +00001184 d->mFx = Ifx_None;
1185 d->mAddr = NULL;
1186 d->mSize = 0;
sewardjc5fc7aa2004-10-27 23:00:55 +00001187 d->needsBBP = False;
sewardj17442fe2004-09-20 14:54:28 +00001188 d->nFxState = 0;
1189 return d;
1190}
1191
1192
sewardje9d8a262009-07-01 08:06:34 +00001193/* Constructors -- IRCAS */
1194
1195IRCAS* mkIRCAS ( IRTemp oldHi, IRTemp oldLo,
1196 IREndness end, IRExpr* addr,
1197 IRExpr* expdHi, IRExpr* expdLo,
1198 IRExpr* dataHi, IRExpr* dataLo ) {
1199 IRCAS* cas = LibVEX_Alloc(sizeof(IRCAS));
1200 cas->oldHi = oldHi;
1201 cas->oldLo = oldLo;
1202 cas->end = end;
1203 cas->addr = addr;
1204 cas->expdHi = expdHi;
1205 cas->expdLo = expdLo;
1206 cas->dataHi = dataHi;
1207 cas->dataLo = dataLo;
1208 return cas;
1209}
1210
1211
sewardjec6ad592004-06-20 12:26:53 +00001212/* Constructors -- IRStmt */
sewardje3d0d2e2004-06-27 10:42:44 +00001213
sewardjd2445f62005-03-21 00:15:53 +00001214IRStmt* IRStmt_NoOp ( void )
1215{
1216 /* Just use a single static closure. */
1217 static IRStmt static_closure;
1218 static_closure.tag = Ist_NoOp;
1219 return &static_closure;
1220}
sewardjf1689312005-03-16 18:19:10 +00001221IRStmt* IRStmt_IMark ( Addr64 addr, Int len ) {
1222 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1223 s->tag = Ist_IMark;
1224 s->Ist.IMark.addr = addr;
1225 s->Ist.IMark.len = len;
1226 return s;
1227}
sewardj478646f2008-05-01 20:13:04 +00001228IRStmt* IRStmt_AbiHint ( IRExpr* base, Int len, IRExpr* nia ) {
sewardj5a9ffab2005-05-12 17:55:01 +00001229 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1230 s->tag = Ist_AbiHint;
1231 s->Ist.AbiHint.base = base;
1232 s->Ist.AbiHint.len = len;
sewardj478646f2008-05-01 20:13:04 +00001233 s->Ist.AbiHint.nia = nia;
sewardj5a9ffab2005-05-12 17:55:01 +00001234 return s;
1235}
sewardj6d076362004-09-23 11:06:17 +00001236IRStmt* IRStmt_Put ( Int off, IRExpr* data ) {
sewardj35421a32004-07-05 13:12:34 +00001237 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
sewardje3d0d2e2004-06-27 10:42:44 +00001238 s->tag = Ist_Put;
1239 s->Ist.Put.offset = off;
sewardj6d076362004-09-23 11:06:17 +00001240 s->Ist.Put.data = data;
sewardje3d0d2e2004-06-27 10:42:44 +00001241 return s;
sewardjec6ad592004-06-20 12:26:53 +00001242}
sewardjdd40fdf2006-12-24 02:20:24 +00001243IRStmt* IRStmt_PutI ( IRRegArray* descr, IRExpr* ix,
sewardj2d3f77c2004-09-22 23:49:09 +00001244 Int bias, IRExpr* data ) {
1245 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1246 s->tag = Ist_PutI;
1247 s->Ist.PutI.descr = descr;
sewardjeeac8412004-11-02 00:26:55 +00001248 s->Ist.PutI.ix = ix;
sewardj2d3f77c2004-09-22 23:49:09 +00001249 s->Ist.PutI.bias = bias;
1250 s->Ist.PutI.data = data;
sewardjd1725d12004-08-12 20:46:53 +00001251 return s;
1252}
sewardjdd40fdf2006-12-24 02:20:24 +00001253IRStmt* IRStmt_WrTmp ( IRTemp tmp, IRExpr* data ) {
1254 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1255 s->tag = Ist_WrTmp;
1256 s->Ist.WrTmp.tmp = tmp;
1257 s->Ist.WrTmp.data = data;
sewardje3d0d2e2004-06-27 10:42:44 +00001258 return s;
sewardjec6ad592004-06-20 12:26:53 +00001259}
sewardje9d8a262009-07-01 08:06:34 +00001260IRStmt* IRStmt_Store ( IREndness end,
1261 IRTemp resSC, IRExpr* addr, IRExpr* data ) {
1262 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1263 s->tag = Ist_Store;
1264 s->Ist.Store.end = end;
1265 s->Ist.Store.resSC = resSC;
1266 s->Ist.Store.addr = addr;
1267 s->Ist.Store.data = data;
sewardjaf1ceca2005-06-30 23:31:27 +00001268 vassert(end == Iend_LE || end == Iend_BE);
sewardje3d0d2e2004-06-27 10:42:44 +00001269 return s;
sewardjec6ad592004-06-20 12:26:53 +00001270}
sewardje9d8a262009-07-01 08:06:34 +00001271IRStmt* IRStmt_CAS ( IRCAS* cas ) {
1272 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1273 s->tag = Ist_CAS;
1274 s->Ist.CAS.details = cas;
1275 return s;
1276}
sewardj17442fe2004-09-20 14:54:28 +00001277IRStmt* IRStmt_Dirty ( IRDirty* d )
1278{
1279 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1280 s->tag = Ist_Dirty;
1281 s->Ist.Dirty.details = d;
1282 return s;
1283}
sewardjc4356f02007-11-09 21:15:04 +00001284IRStmt* IRStmt_MBE ( IRMBusEvent event )
sewardj3e838932005-01-07 12:09:15 +00001285{
sewardjc4356f02007-11-09 21:15:04 +00001286 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1287 s->tag = Ist_MBE;
1288 s->Ist.MBE.event = event;
1289 return s;
sewardj3e838932005-01-07 12:09:15 +00001290}
sewardj893aada2004-11-29 19:57:54 +00001291IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst ) {
sewardj0276d4b2004-11-15 15:30:21 +00001292 IRStmt* s = LibVEX_Alloc(sizeof(IRStmt));
1293 s->tag = Ist_Exit;
1294 s->Ist.Exit.guard = guard;
sewardj893aada2004-11-29 19:57:54 +00001295 s->Ist.Exit.jk = jk;
sewardj0276d4b2004-11-15 15:30:21 +00001296 s->Ist.Exit.dst = dst;
sewardj64e1d652004-07-12 14:00:46 +00001297 return s;
1298}
sewardje3d0d2e2004-06-27 10:42:44 +00001299
sewardj695cff92004-10-13 14:50:14 +00001300
1301/* Constructors -- IRTypeEnv */
1302
1303IRTypeEnv* emptyIRTypeEnv ( void )
1304{
1305 IRTypeEnv* env = LibVEX_Alloc(sizeof(IRTypeEnv));
1306 env->types = LibVEX_Alloc(8 * sizeof(IRType));
1307 env->types_size = 8;
1308 env->types_used = 0;
1309 return env;
1310}
1311
1312
sewardjdd40fdf2006-12-24 02:20:24 +00001313/* Constructors -- IRSB */
sewardje3d0d2e2004-06-27 10:42:44 +00001314
sewardjdd40fdf2006-12-24 02:20:24 +00001315IRSB* emptyIRSB ( void )
sewardjd7cb8532004-08-17 23:59:23 +00001316{
sewardjdd40fdf2006-12-24 02:20:24 +00001317 IRSB* bb = LibVEX_Alloc(sizeof(IRSB));
sewardjd7cb8532004-08-17 23:59:23 +00001318 bb->tyenv = emptyIRTypeEnv();
1319 bb->stmts_used = 0;
1320 bb->stmts_size = 8;
1321 bb->stmts = LibVEX_Alloc(bb->stmts_size * sizeof(IRStmt*));
1322 bb->next = NULL;
1323 bb->jumpkind = Ijk_Boring;
sewardje3d0d2e2004-06-27 10:42:44 +00001324 return bb;
sewardjec6ad592004-06-20 12:26:53 +00001325}
1326
sewardj695cff92004-10-13 14:50:14 +00001327
1328/*---------------------------------------------------------------*/
1329/*--- (Deep) copy constructors. These make complete copies ---*/
1330/*--- the original, which can be modified without affecting ---*/
1331/*--- the original. ---*/
1332/*---------------------------------------------------------------*/
1333
1334/* Copying IR Expr vectors (for call args). */
1335
1336/* Shallow copy of an IRExpr vector */
1337
sewardjdd40fdf2006-12-24 02:20:24 +00001338IRExpr** shallowCopyIRExprVec ( IRExpr** vec )
sewardjd7cb8532004-08-17 23:59:23 +00001339{
sewardj695cff92004-10-13 14:50:14 +00001340 Int i;
1341 IRExpr** newvec;
1342 for (i = 0; vec[i]; i++)
1343 ;
1344 newvec = LibVEX_Alloc((i+1)*sizeof(IRExpr*));
1345 for (i = 0; vec[i]; i++)
1346 newvec[i] = vec[i];
1347 newvec[i] = NULL;
1348 return newvec;
1349}
1350
1351/* Deep copy of an IRExpr vector */
1352
sewardjdd40fdf2006-12-24 02:20:24 +00001353IRExpr** deepCopyIRExprVec ( IRExpr** vec )
sewardj695cff92004-10-13 14:50:14 +00001354{
1355 Int i;
sewardjdd40fdf2006-12-24 02:20:24 +00001356 IRExpr** newvec = shallowCopyIRExprVec( vec );
sewardj695cff92004-10-13 14:50:14 +00001357 for (i = 0; newvec[i]; i++)
sewardjdd40fdf2006-12-24 02:20:24 +00001358 newvec[i] = deepCopyIRExpr(newvec[i]);
sewardj695cff92004-10-13 14:50:14 +00001359 return newvec;
1360}
1361
1362/* Deep copy constructors for all heap-allocated IR types follow. */
1363
sewardjdd40fdf2006-12-24 02:20:24 +00001364IRConst* deepCopyIRConst ( IRConst* c )
sewardj695cff92004-10-13 14:50:14 +00001365{
1366 switch (c->tag) {
sewardjba999312004-11-15 15:21:17 +00001367 case Ico_U1: return IRConst_U1(c->Ico.U1);
sewardj695cff92004-10-13 14:50:14 +00001368 case Ico_U8: return IRConst_U8(c->Ico.U8);
1369 case Ico_U16: return IRConst_U16(c->Ico.U16);
1370 case Ico_U32: return IRConst_U32(c->Ico.U32);
1371 case Ico_U64: return IRConst_U64(c->Ico.U64);
1372 case Ico_F64: return IRConst_F64(c->Ico.F64);
1373 case Ico_F64i: return IRConst_F64i(c->Ico.F64i);
sewardj1e6ad742004-12-02 16:16:11 +00001374 case Ico_V128: return IRConst_V128(c->Ico.V128);
sewardjdd40fdf2006-12-24 02:20:24 +00001375 default: vpanic("deepCopyIRConst");
sewardjd7cb8532004-08-17 23:59:23 +00001376 }
sewardj695cff92004-10-13 14:50:14 +00001377}
1378
sewardjdd40fdf2006-12-24 02:20:24 +00001379IRCallee* deepCopyIRCallee ( IRCallee* ce )
sewardj8ea867b2004-10-30 19:03:02 +00001380{
sewardj43c56462004-11-06 12:17:57 +00001381 IRCallee* ce2 = mkIRCallee(ce->regparms, ce->name, ce->addr);
1382 ce2->mcx_mask = ce->mcx_mask;
1383 return ce2;
sewardj8ea867b2004-10-30 19:03:02 +00001384}
1385
sewardjdd40fdf2006-12-24 02:20:24 +00001386IRRegArray* deepCopyIRRegArray ( IRRegArray* d )
sewardj695cff92004-10-13 14:50:14 +00001387{
sewardjdd40fdf2006-12-24 02:20:24 +00001388 return mkIRRegArray(d->base, d->elemTy, d->nElems);
sewardj695cff92004-10-13 14:50:14 +00001389}
1390
sewardjdd40fdf2006-12-24 02:20:24 +00001391IRExpr* deepCopyIRExpr ( IRExpr* e )
sewardj695cff92004-10-13 14:50:14 +00001392{
1393 switch (e->tag) {
1394 case Iex_Get:
1395 return IRExpr_Get(e->Iex.Get.offset, e->Iex.Get.ty);
1396 case Iex_GetI:
sewardjdd40fdf2006-12-24 02:20:24 +00001397 return IRExpr_GetI(deepCopyIRRegArray(e->Iex.GetI.descr),
1398 deepCopyIRExpr(e->Iex.GetI.ix),
sewardj695cff92004-10-13 14:50:14 +00001399 e->Iex.GetI.bias);
sewardjdd40fdf2006-12-24 02:20:24 +00001400 case Iex_RdTmp:
1401 return IRExpr_RdTmp(e->Iex.RdTmp.tmp);
sewardj1a866b42006-02-09 02:54:03 +00001402 case Iex_Qop:
1403 return IRExpr_Qop(e->Iex.Qop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001404 deepCopyIRExpr(e->Iex.Qop.arg1),
1405 deepCopyIRExpr(e->Iex.Qop.arg2),
1406 deepCopyIRExpr(e->Iex.Qop.arg3),
1407 deepCopyIRExpr(e->Iex.Qop.arg4));
sewardjb183b852006-02-03 16:08:03 +00001408 case Iex_Triop:
1409 return IRExpr_Triop(e->Iex.Triop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001410 deepCopyIRExpr(e->Iex.Triop.arg1),
1411 deepCopyIRExpr(e->Iex.Triop.arg2),
1412 deepCopyIRExpr(e->Iex.Triop.arg3));
sewardj695cff92004-10-13 14:50:14 +00001413 case Iex_Binop:
1414 return IRExpr_Binop(e->Iex.Binop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001415 deepCopyIRExpr(e->Iex.Binop.arg1),
1416 deepCopyIRExpr(e->Iex.Binop.arg2));
sewardj695cff92004-10-13 14:50:14 +00001417 case Iex_Unop:
1418 return IRExpr_Unop(e->Iex.Unop.op,
sewardjdd40fdf2006-12-24 02:20:24 +00001419 deepCopyIRExpr(e->Iex.Unop.arg));
sewardjaf1ceca2005-06-30 23:31:27 +00001420 case Iex_Load:
sewardje9d8a262009-07-01 08:06:34 +00001421 return IRExpr_Load(e->Iex.Load.isLL,
1422 e->Iex.Load.end,
sewardjaf1ceca2005-06-30 23:31:27 +00001423 e->Iex.Load.ty,
sewardjdd40fdf2006-12-24 02:20:24 +00001424 deepCopyIRExpr(e->Iex.Load.addr));
sewardj695cff92004-10-13 14:50:14 +00001425 case Iex_Const:
sewardjdd40fdf2006-12-24 02:20:24 +00001426 return IRExpr_Const(deepCopyIRConst(e->Iex.Const.con));
sewardj695cff92004-10-13 14:50:14 +00001427 case Iex_CCall:
sewardjdd40fdf2006-12-24 02:20:24 +00001428 return IRExpr_CCall(deepCopyIRCallee(e->Iex.CCall.cee),
sewardj695cff92004-10-13 14:50:14 +00001429 e->Iex.CCall.retty,
sewardjdd40fdf2006-12-24 02:20:24 +00001430 deepCopyIRExprVec(e->Iex.CCall.args));
sewardj695cff92004-10-13 14:50:14 +00001431
1432 case Iex_Mux0X:
sewardjdd40fdf2006-12-24 02:20:24 +00001433 return IRExpr_Mux0X(deepCopyIRExpr(e->Iex.Mux0X.cond),
1434 deepCopyIRExpr(e->Iex.Mux0X.expr0),
1435 deepCopyIRExpr(e->Iex.Mux0X.exprX));
sewardj695cff92004-10-13 14:50:14 +00001436 default:
sewardjdd40fdf2006-12-24 02:20:24 +00001437 vpanic("deepCopyIRExpr");
sewardj695cff92004-10-13 14:50:14 +00001438 }
1439}
1440
sewardjdd40fdf2006-12-24 02:20:24 +00001441IRDirty* deepCopyIRDirty ( IRDirty* d )
sewardj695cff92004-10-13 14:50:14 +00001442{
1443 Int i;
1444 IRDirty* d2 = emptyIRDirty();
sewardjdd40fdf2006-12-24 02:20:24 +00001445 d2->cee = deepCopyIRCallee(d->cee);
1446 d2->guard = deepCopyIRExpr(d->guard);
1447 d2->args = deepCopyIRExprVec(d->args);
sewardj695cff92004-10-13 14:50:14 +00001448 d2->tmp = d->tmp;
1449 d2->mFx = d->mFx;
sewardjdd40fdf2006-12-24 02:20:24 +00001450 d2->mAddr = d->mAddr==NULL ? NULL : deepCopyIRExpr(d->mAddr);
sewardj695cff92004-10-13 14:50:14 +00001451 d2->mSize = d->mSize;
sewardjc5fc7aa2004-10-27 23:00:55 +00001452 d2->needsBBP = d->needsBBP;
sewardj695cff92004-10-13 14:50:14 +00001453 d2->nFxState = d->nFxState;
1454 for (i = 0; i < d2->nFxState; i++)
1455 d2->fxState[i] = d->fxState[i];
1456 return d2;
1457}
1458
sewardje9d8a262009-07-01 08:06:34 +00001459IRCAS* deepCopyIRCAS ( IRCAS* cas )
1460{
1461 return mkIRCAS( cas->oldHi, cas->oldLo, cas->end,
1462 deepCopyIRExpr(cas->addr),
1463 deepCopyIRExpr(cas->expdHi),
1464 deepCopyIRExpr(cas->expdLo),
1465 deepCopyIRExpr(cas->dataHi),
1466 deepCopyIRExpr(cas->dataLo) );
1467}
1468
sewardjdd40fdf2006-12-24 02:20:24 +00001469IRStmt* deepCopyIRStmt ( IRStmt* s )
sewardj695cff92004-10-13 14:50:14 +00001470{
1471 switch (s->tag) {
sewardjd2445f62005-03-21 00:15:53 +00001472 case Ist_NoOp:
1473 return IRStmt_NoOp();
sewardj5a9ffab2005-05-12 17:55:01 +00001474 case Ist_AbiHint:
sewardjdd40fdf2006-12-24 02:20:24 +00001475 return IRStmt_AbiHint(deepCopyIRExpr(s->Ist.AbiHint.base),
sewardj478646f2008-05-01 20:13:04 +00001476 s->Ist.AbiHint.len,
1477 deepCopyIRExpr(s->Ist.AbiHint.nia));
sewardjf1689312005-03-16 18:19:10 +00001478 case Ist_IMark:
1479 return IRStmt_IMark(s->Ist.IMark.addr, s->Ist.IMark.len);
sewardj695cff92004-10-13 14:50:14 +00001480 case Ist_Put:
1481 return IRStmt_Put(s->Ist.Put.offset,
sewardjdd40fdf2006-12-24 02:20:24 +00001482 deepCopyIRExpr(s->Ist.Put.data));
sewardj695cff92004-10-13 14:50:14 +00001483 case Ist_PutI:
sewardjdd40fdf2006-12-24 02:20:24 +00001484 return IRStmt_PutI(deepCopyIRRegArray(s->Ist.PutI.descr),
1485 deepCopyIRExpr(s->Ist.PutI.ix),
sewardj695cff92004-10-13 14:50:14 +00001486 s->Ist.PutI.bias,
sewardjdd40fdf2006-12-24 02:20:24 +00001487 deepCopyIRExpr(s->Ist.PutI.data));
1488 case Ist_WrTmp:
1489 return IRStmt_WrTmp(s->Ist.WrTmp.tmp,
1490 deepCopyIRExpr(s->Ist.WrTmp.data));
sewardjaf1ceca2005-06-30 23:31:27 +00001491 case Ist_Store:
1492 return IRStmt_Store(s->Ist.Store.end,
sewardje9d8a262009-07-01 08:06:34 +00001493 s->Ist.Store.resSC,
sewardjdd40fdf2006-12-24 02:20:24 +00001494 deepCopyIRExpr(s->Ist.Store.addr),
1495 deepCopyIRExpr(s->Ist.Store.data));
sewardje9d8a262009-07-01 08:06:34 +00001496 case Ist_CAS:
1497 return IRStmt_CAS(deepCopyIRCAS(s->Ist.CAS.details));
sewardj695cff92004-10-13 14:50:14 +00001498 case Ist_Dirty:
sewardjdd40fdf2006-12-24 02:20:24 +00001499 return IRStmt_Dirty(deepCopyIRDirty(s->Ist.Dirty.details));
sewardjc4356f02007-11-09 21:15:04 +00001500 case Ist_MBE:
1501 return IRStmt_MBE(s->Ist.MBE.event);
sewardj695cff92004-10-13 14:50:14 +00001502 case Ist_Exit:
sewardjdd40fdf2006-12-24 02:20:24 +00001503 return IRStmt_Exit(deepCopyIRExpr(s->Ist.Exit.guard),
sewardj893aada2004-11-29 19:57:54 +00001504 s->Ist.Exit.jk,
sewardjdd40fdf2006-12-24 02:20:24 +00001505 deepCopyIRConst(s->Ist.Exit.dst));
sewardj695cff92004-10-13 14:50:14 +00001506 default:
sewardjdd40fdf2006-12-24 02:20:24 +00001507 vpanic("deepCopyIRStmt");
sewardj695cff92004-10-13 14:50:14 +00001508 }
1509}
1510
sewardjdd40fdf2006-12-24 02:20:24 +00001511IRTypeEnv* deepCopyIRTypeEnv ( IRTypeEnv* src )
sewardj695cff92004-10-13 14:50:14 +00001512{
1513 Int i;
1514 IRTypeEnv* dst = LibVEX_Alloc(sizeof(IRTypeEnv));
1515 dst->types_size = src->types_size;
1516 dst->types_used = src->types_used;
1517 dst->types = LibVEX_Alloc(dst->types_size * sizeof(IRType));
1518 for (i = 0; i < src->types_used; i++)
1519 dst->types[i] = src->types[i];
1520 return dst;
1521}
1522
sewardjdd40fdf2006-12-24 02:20:24 +00001523IRSB* deepCopyIRSB ( IRSB* bb )
sewardj695cff92004-10-13 14:50:14 +00001524{
1525 Int i;
1526 IRStmt** sts2;
sewardjdd40fdf2006-12-24 02:20:24 +00001527 IRSB* bb2 = deepCopyIRSBExceptStmts(bb);
sewardj695cff92004-10-13 14:50:14 +00001528 bb2->stmts_used = bb2->stmts_size = bb->stmts_used;
1529 sts2 = LibVEX_Alloc(bb2->stmts_used * sizeof(IRStmt*));
1530 for (i = 0; i < bb2->stmts_used; i++)
sewardjdd40fdf2006-12-24 02:20:24 +00001531 sts2[i] = deepCopyIRStmt(bb->stmts[i]);
sewardj695cff92004-10-13 14:50:14 +00001532 bb2->stmts = sts2;
sewardj6f2f2832006-11-24 23:32:55 +00001533 return bb2;
1534}
1535
sewardjdd40fdf2006-12-24 02:20:24 +00001536IRSB* deepCopyIRSBExceptStmts ( IRSB* bb )
sewardj6f2f2832006-11-24 23:32:55 +00001537{
sewardjdd40fdf2006-12-24 02:20:24 +00001538 IRSB* bb2 = emptyIRSB();
1539 bb2->tyenv = deepCopyIRTypeEnv(bb->tyenv);
1540 bb2->next = deepCopyIRExpr(bb->next);
sewardj695cff92004-10-13 14:50:14 +00001541 bb2->jumpkind = bb->jumpkind;
1542 return bb2;
sewardjd7cb8532004-08-17 23:59:23 +00001543}
1544
sewardjec6ad592004-06-20 12:26:53 +00001545
sewardjc97096c2004-06-30 09:28:04 +00001546/*---------------------------------------------------------------*/
sewardj6efd4a12004-07-15 03:54:23 +00001547/*--- Primop types ---*/
1548/*---------------------------------------------------------------*/
1549
1550static
sewardjb183b852006-02-03 16:08:03 +00001551void typeOfPrimop ( IROp op,
1552 /*OUTs*/
1553 IRType* t_dst,
sewardj40c80262006-02-08 19:30:46 +00001554 IRType* t_arg1, IRType* t_arg2,
1555 IRType* t_arg3, IRType* t_arg4 )
sewardj6efd4a12004-07-15 03:54:23 +00001556{
sewardjb183b852006-02-03 16:08:03 +00001557# define UNARY(_ta1,_td) \
sewardj6efd4a12004-07-15 03:54:23 +00001558 *t_dst = (_td); *t_arg1 = (_ta1); break
sewardjb183b852006-02-03 16:08:03 +00001559# define BINARY(_ta1,_ta2,_td) \
sewardj6efd4a12004-07-15 03:54:23 +00001560 *t_dst = (_td); *t_arg1 = (_ta1); *t_arg2 = (_ta2); break
sewardjb183b852006-02-03 16:08:03 +00001561# define TERNARY(_ta1,_ta2,_ta3,_td) \
1562 *t_dst = (_td); *t_arg1 = (_ta1); \
1563 *t_arg2 = (_ta2); *t_arg3 = (_ta3); break
sewardj40c80262006-02-08 19:30:46 +00001564# define QUATERNARY(_ta1,_ta2,_ta3,_ta4,_td) \
1565 *t_dst = (_td); *t_arg1 = (_ta1); \
1566 *t_arg2 = (_ta2); *t_arg3 = (_ta3); \
1567 *t_arg4 = (_ta4); break
sewardjb183b852006-02-03 16:08:03 +00001568# define COMPARISON(_ta) \
sewardjba999312004-11-15 15:21:17 +00001569 *t_dst = Ity_I1; *t_arg1 = *t_arg2 = (_ta); break;
sewardjb183b852006-02-03 16:08:03 +00001570# define UNARY_COMPARISON(_ta) \
sewardj0033ddc2005-04-26 23:34:34 +00001571 *t_dst = Ity_I1; *t_arg1 = (_ta); break;
sewardj6efd4a12004-07-15 03:54:23 +00001572
sewardjb183b852006-02-03 16:08:03 +00001573 /* Rounding mode values are always Ity_I32, encoded as per
1574 IRRoundingMode */
1575 const IRType ity_RMode = Ity_I32;
1576
sewardj6efd4a12004-07-15 03:54:23 +00001577 *t_dst = Ity_INVALID;
1578 *t_arg1 = Ity_INVALID;
1579 *t_arg2 = Ity_INVALID;
sewardjb183b852006-02-03 16:08:03 +00001580 *t_arg3 = Ity_INVALID;
sewardj40c80262006-02-08 19:30:46 +00001581 *t_arg4 = Ity_INVALID;
sewardj6efd4a12004-07-15 03:54:23 +00001582 switch (op) {
sewardj17442fe2004-09-20 14:54:28 +00001583 case Iop_Add8: case Iop_Sub8: case Iop_Mul8:
1584 case Iop_Or8: case Iop_And8: case Iop_Xor8:
sewardjb183b852006-02-03 16:08:03 +00001585 BINARY(Ity_I8,Ity_I8, Ity_I8);
sewardj6efd4a12004-07-15 03:54:23 +00001586
sewardj17442fe2004-09-20 14:54:28 +00001587 case Iop_Add16: case Iop_Sub16: case Iop_Mul16:
1588 case Iop_Or16: case Iop_And16: case Iop_Xor16:
sewardjb183b852006-02-03 16:08:03 +00001589 BINARY(Ity_I16,Ity_I16, Ity_I16);
sewardj6efd4a12004-07-15 03:54:23 +00001590
sewardjb51f0f42005-07-18 11:38:02 +00001591 case Iop_CmpORD32U:
1592 case Iop_CmpORD32S:
sewardj17442fe2004-09-20 14:54:28 +00001593 case Iop_Add32: case Iop_Sub32: case Iop_Mul32:
1594 case Iop_Or32: case Iop_And32: case Iop_Xor32:
sewardj478646f2008-05-01 20:13:04 +00001595 case Iop_Max32U:
sewardjb183b852006-02-03 16:08:03 +00001596 BINARY(Ity_I32,Ity_I32, Ity_I32);
sewardj6efd4a12004-07-15 03:54:23 +00001597
sewardj17442fe2004-09-20 14:54:28 +00001598 case Iop_Add64: case Iop_Sub64: case Iop_Mul64:
1599 case Iop_Or64: case Iop_And64: case Iop_Xor64:
cerion2831b002005-11-30 19:55:22 +00001600 case Iop_CmpORD64U:
1601 case Iop_CmpORD64S:
sewardj38a3f862005-01-13 15:06:51 +00001602 case Iop_Avg8Ux8: case Iop_Avg16Ux4:
1603 case Iop_Add8x8: case Iop_Add16x4: case Iop_Add32x2:
1604 case Iop_CmpEQ8x8: case Iop_CmpEQ16x4: case Iop_CmpEQ32x2:
1605 case Iop_CmpGT8Sx8: case Iop_CmpGT16Sx4: case Iop_CmpGT32Sx2:
1606 case Iop_InterleaveHI8x8: case Iop_InterleaveLO8x8:
1607 case Iop_InterleaveHI16x4: case Iop_InterleaveLO16x4:
1608 case Iop_InterleaveHI32x2: case Iop_InterleaveLO32x2:
sewardjd166e282008-02-06 11:42:45 +00001609 case Iop_CatOddLanes16x4: case Iop_CatEvenLanes16x4:
1610 case Iop_Perm8x8:
sewardj38a3f862005-01-13 15:06:51 +00001611 case Iop_Max8Ux8: case Iop_Max16Sx4:
1612 case Iop_Min8Ux8: case Iop_Min16Sx4:
sewardjd166e282008-02-06 11:42:45 +00001613 case Iop_Mul16x4: case Iop_Mul32x2:
1614 case Iop_MulHi16Sx4: case Iop_MulHi16Ux4:
sewardj38a3f862005-01-13 15:06:51 +00001615 case Iop_QAdd8Sx8: case Iop_QAdd16Sx4:
1616 case Iop_QAdd8Ux8: case Iop_QAdd16Ux4:
1617 case Iop_QNarrow32Sx2:
1618 case Iop_QNarrow16Sx4: case Iop_QNarrow16Ux4:
1619 case Iop_Sub8x8: case Iop_Sub16x4: case Iop_Sub32x2:
1620 case Iop_QSub8Sx8: case Iop_QSub16Sx4:
1621 case Iop_QSub8Ux8: case Iop_QSub16Ux4:
sewardjb183b852006-02-03 16:08:03 +00001622 BINARY(Ity_I64,Ity_I64, Ity_I64);
sewardj38a3f862005-01-13 15:06:51 +00001623
sewardjd166e282008-02-06 11:42:45 +00001624 case Iop_ShlN32x2: case Iop_ShlN16x4: case Iop_ShlN8x8:
sewardj38a3f862005-01-13 15:06:51 +00001625 case Iop_ShrN32x2: case Iop_ShrN16x4:
sewardjd71ba832006-12-27 01:15:29 +00001626 case Iop_SarN32x2: case Iop_SarN16x4: case Iop_SarN8x8:
sewardjb183b852006-02-03 16:08:03 +00001627 BINARY(Ity_I64,Ity_I8, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001628
1629 case Iop_Shl8: case Iop_Shr8: case Iop_Sar8:
sewardjb183b852006-02-03 16:08:03 +00001630 BINARY(Ity_I8,Ity_I8, Ity_I8);
sewardj6efd4a12004-07-15 03:54:23 +00001631 case Iop_Shl16: case Iop_Shr16: case Iop_Sar16:
sewardjb183b852006-02-03 16:08:03 +00001632 BINARY(Ity_I16,Ity_I8, Ity_I16);
sewardj6efd4a12004-07-15 03:54:23 +00001633 case Iop_Shl32: case Iop_Shr32: case Iop_Sar32:
sewardjb183b852006-02-03 16:08:03 +00001634 BINARY(Ity_I32,Ity_I8, Ity_I32);
sewardj6efd4a12004-07-15 03:54:23 +00001635 case Iop_Shl64: case Iop_Shr64: case Iop_Sar64:
sewardjb183b852006-02-03 16:08:03 +00001636 BINARY(Ity_I64,Ity_I8, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001637
sewardjeb17e492007-08-25 23:07:44 +00001638 case Iop_Not8:
sewardjb183b852006-02-03 16:08:03 +00001639 UNARY(Ity_I8, Ity_I8);
sewardjeb17e492007-08-25 23:07:44 +00001640 case Iop_Not16:
sewardjb183b852006-02-03 16:08:03 +00001641 UNARY(Ity_I16, Ity_I16);
sewardjeb17e492007-08-25 23:07:44 +00001642 case Iop_Not32:
sewardjb183b852006-02-03 16:08:03 +00001643 UNARY(Ity_I32, Ity_I32);
sewardj18069182005-01-13 19:16:04 +00001644
sewardj0033ddc2005-04-26 23:34:34 +00001645 case Iop_Not64:
sewardj18069182005-01-13 19:16:04 +00001646 case Iop_CmpNEZ32x2: case Iop_CmpNEZ16x4: case Iop_CmpNEZ8x8:
sewardjb183b852006-02-03 16:08:03 +00001647 UNARY(Ity_I64, Ity_I64);
sewardj6efd4a12004-07-15 03:54:23 +00001648
1649 case Iop_CmpEQ8: case Iop_CmpNE8:
sewardj1fb8c922009-07-12 12:56:53 +00001650 case Iop_CasCmpEQ8: case Iop_CasCmpNE8:
sewardj6efd4a12004-07-15 03:54:23 +00001651 COMPARISON(Ity_I8);
1652 case Iop_CmpEQ16: case Iop_CmpNE16:
sewardj1fb8c922009-07-12 12:56:53 +00001653 case Iop_CasCmpEQ16: case Iop_CasCmpNE16:
sewardj6efd4a12004-07-15 03:54:23 +00001654 COMPARISON(Ity_I16);
1655 case Iop_CmpEQ32: case Iop_CmpNE32:
sewardj1fb8c922009-07-12 12:56:53 +00001656 case Iop_CasCmpEQ32: case Iop_CasCmpNE32:
sewardj17442fe2004-09-20 14:54:28 +00001657 case Iop_CmpLT32S: case Iop_CmpLE32S:
1658 case Iop_CmpLT32U: case Iop_CmpLE32U:
sewardj6efd4a12004-07-15 03:54:23 +00001659 COMPARISON(Ity_I32);
1660 case Iop_CmpEQ64: case Iop_CmpNE64:
sewardj1fb8c922009-07-12 12:56:53 +00001661 case Iop_CasCmpEQ64: case Iop_CasCmpNE64:
sewardj98540072005-04-26 01:52:01 +00001662 case Iop_CmpLT64S: case Iop_CmpLE64S:
1663 case Iop_CmpLT64U: case Iop_CmpLE64U:
sewardj6efd4a12004-07-15 03:54:23 +00001664 COMPARISON(Ity_I64);
1665
sewardj0033ddc2005-04-26 23:34:34 +00001666 case Iop_CmpNEZ8: UNARY_COMPARISON(Ity_I8);
1667 case Iop_CmpNEZ16: UNARY_COMPARISON(Ity_I16);
1668 case Iop_CmpNEZ32: UNARY_COMPARISON(Ity_I32);
1669 case Iop_CmpNEZ64: UNARY_COMPARISON(Ity_I64);
1670
sewardjeb17e492007-08-25 23:07:44 +00001671 case Iop_Left8: UNARY(Ity_I8, Ity_I8);
1672 case Iop_Left16: UNARY(Ity_I16,Ity_I16);
1673 case Iop_CmpwNEZ32: case Iop_Left32: UNARY(Ity_I32,Ity_I32);
1674 case Iop_CmpwNEZ64: case Iop_Left64: UNARY(Ity_I64,Ity_I64);
1675
sewardjb81f8b32004-07-30 10:17:50 +00001676 case Iop_MullU8: case Iop_MullS8:
sewardjb183b852006-02-03 16:08:03 +00001677 BINARY(Ity_I8,Ity_I8, Ity_I16);
sewardjb81f8b32004-07-30 10:17:50 +00001678 case Iop_MullU16: case Iop_MullS16:
sewardjb183b852006-02-03 16:08:03 +00001679 BINARY(Ity_I16,Ity_I16, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001680 case Iop_MullU32: case Iop_MullS32:
sewardjb183b852006-02-03 16:08:03 +00001681 BINARY(Ity_I32,Ity_I32, Ity_I64);
sewardj9b967672005-02-08 11:13:09 +00001682 case Iop_MullU64: case Iop_MullS64:
sewardjb183b852006-02-03 16:08:03 +00001683 BINARY(Ity_I64,Ity_I64, Ity_I128);
sewardj6d2638e2004-07-15 09:38:27 +00001684
sewardj17442fe2004-09-20 14:54:28 +00001685 case Iop_Clz32: case Iop_Ctz32:
sewardjb183b852006-02-03 16:08:03 +00001686 UNARY(Ity_I32, Ity_I32);
sewardjce646f22004-08-31 23:55:54 +00001687
sewardjf53b7352005-04-06 20:01:56 +00001688 case Iop_Clz64: case Iop_Ctz64:
sewardjb183b852006-02-03 16:08:03 +00001689 UNARY(Ity_I64, Ity_I64);
sewardjf53b7352005-04-06 20:01:56 +00001690
cerion5c8a0cb2005-02-03 13:59:46 +00001691 case Iop_DivU32: case Iop_DivS32:
sewardjb183b852006-02-03 16:08:03 +00001692 BINARY(Ity_I32,Ity_I32, Ity_I32);
cerion5c8a0cb2005-02-03 13:59:46 +00001693
cerionf0de28c2005-12-13 20:21:11 +00001694 case Iop_DivU64: case Iop_DivS64:
sewardjb183b852006-02-03 16:08:03 +00001695 BINARY(Ity_I64,Ity_I64, Ity_I64);
cerionf0de28c2005-12-13 20:21:11 +00001696
sewardj17442fe2004-09-20 14:54:28 +00001697 case Iop_DivModU64to32: case Iop_DivModS64to32:
sewardjb183b852006-02-03 16:08:03 +00001698 BINARY(Ity_I64,Ity_I32, Ity_I64);
sewardj6d2638e2004-07-15 09:38:27 +00001699
sewardj343b9d02005-01-31 18:08:45 +00001700 case Iop_DivModU128to64: case Iop_DivModS128to64:
sewardjb183b852006-02-03 16:08:03 +00001701 BINARY(Ity_I128,Ity_I64, Ity_I128);
sewardj343b9d02005-01-31 18:08:45 +00001702
sewardjb81f8b32004-07-30 10:17:50 +00001703 case Iop_16HIto8: case Iop_16to8:
sewardjb183b852006-02-03 16:08:03 +00001704 UNARY(Ity_I16, Ity_I8);
sewardjb81f8b32004-07-30 10:17:50 +00001705 case Iop_8HLto16:
sewardjb183b852006-02-03 16:08:03 +00001706 BINARY(Ity_I8,Ity_I8, Ity_I16);
sewardjb81f8b32004-07-30 10:17:50 +00001707
sewardj8c7f1ab2004-07-29 20:31:09 +00001708 case Iop_32HIto16: case Iop_32to16:
sewardjb183b852006-02-03 16:08:03 +00001709 UNARY(Ity_I32, Ity_I16);
sewardj8c7f1ab2004-07-29 20:31:09 +00001710 case Iop_16HLto32:
sewardjb183b852006-02-03 16:08:03 +00001711 BINARY(Ity_I16,Ity_I16, Ity_I32);
sewardj8c7f1ab2004-07-29 20:31:09 +00001712
1713 case Iop_64HIto32: case Iop_64to32:
sewardjb183b852006-02-03 16:08:03 +00001714 UNARY(Ity_I64, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001715 case Iop_32HLto64:
sewardjb183b852006-02-03 16:08:03 +00001716 BINARY(Ity_I32,Ity_I32, Ity_I64);
sewardj6d2638e2004-07-15 09:38:27 +00001717
sewardj9b967672005-02-08 11:13:09 +00001718 case Iop_128HIto64: case Iop_128to64:
sewardjb183b852006-02-03 16:08:03 +00001719 UNARY(Ity_I128, Ity_I64);
sewardj9b967672005-02-08 11:13:09 +00001720 case Iop_64HLto128:
sewardjb183b852006-02-03 16:08:03 +00001721 BINARY(Ity_I64,Ity_I64, Ity_I128);
sewardj9b967672005-02-08 11:13:09 +00001722
sewardjb183b852006-02-03 16:08:03 +00001723 case Iop_Not1: UNARY(Ity_I1, Ity_I1);
1724 case Iop_1Uto8: UNARY(Ity_I1, Ity_I8);
1725 case Iop_1Sto8: UNARY(Ity_I1, Ity_I8);
1726 case Iop_1Sto16: UNARY(Ity_I1, Ity_I16);
1727 case Iop_1Uto32: case Iop_1Sto32: UNARY(Ity_I1, Ity_I32);
1728 case Iop_1Sto64: case Iop_1Uto64: UNARY(Ity_I1, Ity_I64);
1729 case Iop_32to1: UNARY(Ity_I32, Ity_I1);
1730 case Iop_64to1: UNARY(Ity_I64, Ity_I1);
sewardj47341042004-09-19 11:55:46 +00001731
sewardj17442fe2004-09-20 14:54:28 +00001732 case Iop_8Uto32: case Iop_8Sto32:
sewardjb183b852006-02-03 16:08:03 +00001733 UNARY(Ity_I8, Ity_I32);
sewardj47341042004-09-19 11:55:46 +00001734
sewardj17442fe2004-09-20 14:54:28 +00001735 case Iop_8Uto16: case Iop_8Sto16:
sewardjb183b852006-02-03 16:08:03 +00001736 UNARY(Ity_I8, Ity_I16);
sewardj47341042004-09-19 11:55:46 +00001737
sewardj17442fe2004-09-20 14:54:28 +00001738 case Iop_16Uto32: case Iop_16Sto32:
sewardjb183b852006-02-03 16:08:03 +00001739 UNARY(Ity_I16, Ity_I32);
sewardj6d2638e2004-07-15 09:38:27 +00001740
sewardj17442fe2004-09-20 14:54:28 +00001741 case Iop_32Sto64: case Iop_32Uto64:
sewardjb183b852006-02-03 16:08:03 +00001742 UNARY(Ity_I32, Ity_I64);
sewardj17442fe2004-09-20 14:54:28 +00001743
sewardj291a7e82005-04-27 11:42:44 +00001744 case Iop_8Uto64: case Iop_8Sto64:
sewardjb183b852006-02-03 16:08:03 +00001745 UNARY(Ity_I8, Ity_I64);
sewardj291a7e82005-04-27 11:42:44 +00001746
1747 case Iop_16Uto64: case Iop_16Sto64:
sewardj291a7e82005-04-27 11:42:44 +00001748 UNARY(Ity_I16, Ity_I64);
sewardjb183b852006-02-03 16:08:03 +00001749 case Iop_64to16:
1750 UNARY(Ity_I64, Ity_I16);
sewardj291a7e82005-04-27 11:42:44 +00001751
sewardjb183b852006-02-03 16:08:03 +00001752 case Iop_32to8: UNARY(Ity_I32, Ity_I8);
1753 case Iop_64to8: UNARY(Ity_I64, Ity_I8);
sewardj17442fe2004-09-20 14:54:28 +00001754
sewardjb183b852006-02-03 16:08:03 +00001755 case Iop_AddF64: case Iop_SubF64:
1756 case Iop_MulF64: case Iop_DivF64:
1757 case Iop_AddF64r32: case Iop_SubF64r32:
1758 case Iop_MulF64r32: case Iop_DivF64r32:
1759 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_F64);
1760
1761 case Iop_NegF64: case Iop_AbsF64:
1762 UNARY(Ity_F64, Ity_F64);
1763
1764 case Iop_SqrtF64:
1765 case Iop_SqrtF64r32:
1766 BINARY(ity_RMode,Ity_F64, Ity_F64);
1767
sewardjbdc7d212004-09-09 02:46:40 +00001768 case Iop_CmpF64:
sewardjb183b852006-02-03 16:08:03 +00001769 BINARY(Ity_F64,Ity_F64, Ity_I32);
sewardj8f3debf2004-09-08 23:42:23 +00001770
sewardjb183b852006-02-03 16:08:03 +00001771 case Iop_F64toI16: BINARY(ity_RMode,Ity_F64, Ity_I16);
1772 case Iop_F64toI32: BINARY(ity_RMode,Ity_F64, Ity_I32);
1773 case Iop_F64toI64: BINARY(ity_RMode,Ity_F64, Ity_I64);
sewardj8f3debf2004-09-08 23:42:23 +00001774
sewardjb183b852006-02-03 16:08:03 +00001775 case Iop_I16toF64: UNARY(Ity_I16, Ity_F64);
1776 case Iop_I32toF64: UNARY(Ity_I32, Ity_F64);
1777 case Iop_I64toF64: BINARY(ity_RMode,Ity_I64, Ity_F64);
sewardj3bca9062004-12-04 14:36:09 +00001778
sewardjb183b852006-02-03 16:08:03 +00001779 case Iop_F32toF64: UNARY(Ity_F32, Ity_F64);
1780 case Iop_F64toF32: BINARY(ity_RMode,Ity_F64, Ity_F32);
sewardj4cb918d2004-12-03 19:43:31 +00001781
sewardjb183b852006-02-03 16:08:03 +00001782 case Iop_ReinterpI64asF64: UNARY(Ity_I64, Ity_F64);
1783 case Iop_ReinterpF64asI64: UNARY(Ity_F64, Ity_I64);
1784 case Iop_ReinterpI32asF32: UNARY(Ity_I32, Ity_F32);
sewardjfc1b5412007-01-09 15:20:07 +00001785 case Iop_ReinterpF32asI32: UNARY(Ity_F32, Ity_I32);
sewardj8f3debf2004-09-08 23:42:23 +00001786
sewardjb183b852006-02-03 16:08:03 +00001787 case Iop_AtanF64: case Iop_Yl2xF64: case Iop_Yl2xp1F64:
1788 case Iop_ScaleF64: case Iop_PRemF64: case Iop_PRem1F64:
1789 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_F64);
1790
1791 case Iop_PRemC3210F64: case Iop_PRem1C3210F64:
1792 TERNARY(ity_RMode,Ity_F64,Ity_F64, Ity_I32);
1793
1794 case Iop_SinF64: case Iop_CosF64: case Iop_TanF64:
1795 case Iop_2xm1F64:
1796 case Iop_RoundF64toInt: BINARY(ity_RMode,Ity_F64, Ity_F64);
1797
sewardj40c80262006-02-08 19:30:46 +00001798 case Iop_MAddF64: case Iop_MSubF64:
1799 case Iop_MAddF64r32: case Iop_MSubF64r32:
1800 QUATERNARY(ity_RMode,Ity_F64,Ity_F64,Ity_F64, Ity_F64);
1801
sewardjb183b852006-02-03 16:08:03 +00001802 case Iop_Est5FRSqrt:
sewardj0f1ef862008-08-08 08:37:06 +00001803 case Iop_RoundF64toF64_NEAREST: case Iop_RoundF64toF64_NegINF:
1804 case Iop_RoundF64toF64_PosINF: case Iop_RoundF64toF64_ZERO:
sewardjb183b852006-02-03 16:08:03 +00001805 UNARY(Ity_F64, Ity_F64);
1806 case Iop_RoundF64toF32:
1807 BINARY(ity_RMode,Ity_F64, Ity_F64);
1808 case Iop_CalcFPRF:
1809 UNARY(Ity_F64, Ity_I32);
1810 case Iop_TruncF64asF32:
1811 UNARY(Ity_F64, Ity_F32);
sewardjbb53f8c2004-08-14 11:50:01 +00001812
cerionf294eb32005-11-16 17:21:10 +00001813 case Iop_I32UtoFx4:
1814 case Iop_I32StoFx4:
1815 case Iop_QFtoI32Ux4_RZ:
1816 case Iop_QFtoI32Sx4_RZ:
1817 case Iop_RoundF32x4_RM:
1818 case Iop_RoundF32x4_RP:
1819 case Iop_RoundF32x4_RN:
1820 case Iop_RoundF32x4_RZ:
1821 UNARY(Ity_V128, Ity_V128);
1822
sewardjb183b852006-02-03 16:08:03 +00001823 case Iop_64HLtoV128: BINARY(Ity_I64,Ity_I64, Ity_V128);
sewardjf0c1c582005-02-07 23:47:38 +00001824 case Iop_V128to64: case Iop_V128HIto64:
sewardjb183b852006-02-03 16:08:03 +00001825 UNARY(Ity_V128, Ity_I64);
sewardjc9a43662004-11-30 18:51:59 +00001826
sewardjb183b852006-02-03 16:08:03 +00001827 case Iop_V128to32: UNARY(Ity_V128, Ity_I32);
1828 case Iop_32UtoV128: UNARY(Ity_I32, Ity_V128);
1829 case Iop_64UtoV128: UNARY(Ity_I64, Ity_V128);
1830 case Iop_SetV128lo32: BINARY(Ity_V128,Ity_I32, Ity_V128);
1831 case Iop_SetV128lo64: BINARY(Ity_V128,Ity_I64, Ity_V128);
sewardj129b3d92004-12-05 15:42:05 +00001832
sewardjb183b852006-02-03 16:08:03 +00001833 case Iop_Dup8x16: UNARY(Ity_I8, Ity_V128);
1834 case Iop_Dup16x8: UNARY(Ity_I16, Ity_V128);
1835 case Iop_Dup32x4: UNARY(Ity_I32, Ity_V128);
cerionf887b3e2005-09-13 16:34:28 +00001836
sewardj1e6ad742004-12-02 16:16:11 +00001837 case Iop_CmpEQ32Fx4: case Iop_CmpLT32Fx4:
sewardj636ad762004-12-07 11:16:04 +00001838 case Iop_CmpEQ64Fx2: case Iop_CmpLT64Fx2:
sewardj1e6ad742004-12-02 16:16:11 +00001839 case Iop_CmpLE32Fx4: case Iop_CmpUN32Fx4:
sewardj636ad762004-12-07 11:16:04 +00001840 case Iop_CmpLE64Fx2: case Iop_CmpUN64Fx2:
cerion206c3642005-11-14 00:35:59 +00001841 case Iop_CmpGT32Fx4: case Iop_CmpGE32Fx4:
sewardj1e6ad742004-12-02 16:16:11 +00001842 case Iop_CmpEQ32F0x4: case Iop_CmpLT32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001843 case Iop_CmpEQ64F0x2: case Iop_CmpLT64F0x2:
sewardj1e6ad742004-12-02 16:16:11 +00001844 case Iop_CmpLE32F0x4: case Iop_CmpUN32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001845 case Iop_CmpLE64F0x2: case Iop_CmpUN64F0x2:
sewardj1e6ad742004-12-02 16:16:11 +00001846 case Iop_Add32Fx4: case Iop_Add32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001847 case Iop_Add64Fx2: case Iop_Add64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001848 case Iop_Div32Fx4: case Iop_Div32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001849 case Iop_Div64Fx2: case Iop_Div64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001850 case Iop_Max32Fx4: case Iop_Max32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001851 case Iop_Max64Fx2: case Iop_Max64F0x2:
sewardj176a59c2004-12-03 20:08:31 +00001852 case Iop_Min32Fx4: case Iop_Min32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001853 case Iop_Min64Fx2: case Iop_Min64F0x2:
sewardj9636b442004-12-04 01:38:37 +00001854 case Iop_Mul32Fx4: case Iop_Mul32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001855 case Iop_Mul64Fx2: case Iop_Mul64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001856 case Iop_Sub32Fx4: case Iop_Sub32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001857 case Iop_Sub64Fx2: case Iop_Sub64F0x2:
sewardjf0c1c582005-02-07 23:47:38 +00001858 case Iop_AndV128: case Iop_OrV128: case Iop_XorV128:
sewardj164f9272004-12-09 00:39:32 +00001859 case Iop_Add8x16: case Iop_Add16x8:
1860 case Iop_Add32x4: case Iop_Add64x2:
cerionf887b3e2005-09-13 16:34:28 +00001861 case Iop_QAdd8Ux16: case Iop_QAdd16Ux8: case Iop_QAdd32Ux4:
1862 case Iop_QAdd8Sx16: case Iop_QAdd16Sx8: case Iop_QAdd32Sx4:
sewardj164f9272004-12-09 00:39:32 +00001863 case Iop_Sub8x16: case Iop_Sub16x8:
1864 case Iop_Sub32x4: case Iop_Sub64x2:
cerionf887b3e2005-09-13 16:34:28 +00001865 case Iop_QSub8Ux16: case Iop_QSub16Ux8: case Iop_QSub32Ux4:
1866 case Iop_QSub8Sx16: case Iop_QSub16Sx8: case Iop_QSub32Sx4:
sewardj164f9272004-12-09 00:39:32 +00001867 case Iop_Mul16x8:
cerionf887b3e2005-09-13 16:34:28 +00001868 case Iop_MulHi16Ux8: case Iop_MulHi32Ux4:
1869 case Iop_MulHi16Sx8: case Iop_MulHi32Sx4:
cerion1ac656a2005-11-04 19:44:48 +00001870 case Iop_MullEven8Ux16: case Iop_MullEven16Ux8:
1871 case Iop_MullEven8Sx16: case Iop_MullEven16Sx8:
cerionf887b3e2005-09-13 16:34:28 +00001872 case Iop_Avg8Ux16: case Iop_Avg16Ux8: case Iop_Avg32Ux4:
1873 case Iop_Avg8Sx16: case Iop_Avg16Sx8: case Iop_Avg32Sx4:
1874 case Iop_Max8Sx16: case Iop_Max16Sx8: case Iop_Max32Sx4:
1875 case Iop_Max8Ux16: case Iop_Max16Ux8: case Iop_Max32Ux4:
1876 case Iop_Min8Sx16: case Iop_Min16Sx8: case Iop_Min32Sx4:
1877 case Iop_Min8Ux16: case Iop_Min16Ux8: case Iop_Min32Ux4:
sewardj164f9272004-12-09 00:39:32 +00001878 case Iop_CmpEQ8x16: case Iop_CmpEQ16x8: case Iop_CmpEQ32x4:
1879 case Iop_CmpGT8Sx16: case Iop_CmpGT16Sx8: case Iop_CmpGT32Sx4:
cerionf887b3e2005-09-13 16:34:28 +00001880 case Iop_CmpGT8Ux16: case Iop_CmpGT16Ux8: case Iop_CmpGT32Ux4:
1881 case Iop_Shl8x16: case Iop_Shl16x8: case Iop_Shl32x4:
1882 case Iop_Shr8x16: case Iop_Shr16x8: case Iop_Shr32x4:
1883 case Iop_Sar8x16: case Iop_Sar16x8: case Iop_Sar32x4:
sewardj1bee5612005-11-10 18:10:58 +00001884 case Iop_Rol8x16: case Iop_Rol16x8: case Iop_Rol32x4:
cerion9e7677b2005-09-13 17:25:41 +00001885 case Iop_QNarrow16Ux8: case Iop_QNarrow32Ux4:
sewardj164f9272004-12-09 00:39:32 +00001886 case Iop_QNarrow16Sx8: case Iop_QNarrow32Sx4:
sewardj1bee5612005-11-10 18:10:58 +00001887 case Iop_Narrow16x8: case Iop_Narrow32x4:
sewardj164f9272004-12-09 00:39:32 +00001888 case Iop_InterleaveHI8x16: case Iop_InterleaveHI16x8:
1889 case Iop_InterleaveHI32x4: case Iop_InterleaveHI64x2:
1890 case Iop_InterleaveLO8x16: case Iop_InterleaveLO16x8:
1891 case Iop_InterleaveLO32x4: case Iop_InterleaveLO64x2:
sewardjdc1f9132005-10-22 12:49:49 +00001892 case Iop_Perm8x16:
sewardjb183b852006-02-03 16:08:03 +00001893 BINARY(Ity_V128,Ity_V128, Ity_V128);
sewardjc9a43662004-11-30 18:51:59 +00001894
sewardjf0c1c582005-02-07 23:47:38 +00001895 case Iop_NotV128:
sewardj0bd7ce62004-12-05 02:47:40 +00001896 case Iop_Recip32Fx4: case Iop_Recip32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001897 case Iop_Recip64Fx2: case Iop_Recip64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001898 case Iop_RSqrt32Fx4: case Iop_RSqrt32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001899 case Iop_RSqrt64Fx2: case Iop_RSqrt64F0x2:
sewardjc1e7dfc2004-12-05 19:29:45 +00001900 case Iop_Sqrt32Fx4: case Iop_Sqrt32F0x4:
sewardj636ad762004-12-07 11:16:04 +00001901 case Iop_Sqrt64Fx2: case Iop_Sqrt64F0x2:
sewardj2e383862004-12-12 16:46:47 +00001902 case Iop_CmpNEZ8x16: case Iop_CmpNEZ16x8:
sewardj109ffdb2004-12-10 21:45:38 +00001903 case Iop_CmpNEZ32x4: case Iop_CmpNEZ64x2:
sewardj0bd7ce62004-12-05 02:47:40 +00001904 UNARY(Ity_V128, Ity_V128);
1905
cerionf887b3e2005-09-13 16:34:28 +00001906 case Iop_ShlV128: case Iop_ShrV128:
sewardjb183b852006-02-03 16:08:03 +00001907 case Iop_ShlN8x16: case Iop_ShlN16x8:
1908 case Iop_ShlN32x4: case Iop_ShlN64x2:
1909 case Iop_ShrN8x16: case Iop_ShrN16x8:
1910 case Iop_ShrN32x4: case Iop_ShrN64x2:
cerion2a4b8452005-09-15 16:28:36 +00001911 case Iop_SarN8x16: case Iop_SarN16x8: case Iop_SarN32x4:
sewardjb183b852006-02-03 16:08:03 +00001912 BINARY(Ity_V128,Ity_I8, Ity_V128);
sewardj164f9272004-12-09 00:39:32 +00001913
sewardj6efd4a12004-07-15 03:54:23 +00001914 default:
1915 ppIROp(op);
1916 vpanic("typeOfPrimop");
1917 }
1918# undef UNARY
1919# undef BINARY
sewardjb183b852006-02-03 16:08:03 +00001920# undef TERNARY
sewardj6efd4a12004-07-15 03:54:23 +00001921# undef COMPARISON
sewardj0033ddc2005-04-26 23:34:34 +00001922# undef UNARY_COMPARISON
sewardj6efd4a12004-07-15 03:54:23 +00001923}
1924
1925
1926/*---------------------------------------------------------------*/
sewardj695cff92004-10-13 14:50:14 +00001927/*--- Helper functions for the IR -- IR Basic Blocks ---*/
sewardjc97096c2004-06-30 09:28:04 +00001928/*---------------------------------------------------------------*/
1929
sewardjdd40fdf2006-12-24 02:20:24 +00001930void addStmtToIRSB ( IRSB* bb, IRStmt* st )
sewardjd7cb8532004-08-17 23:59:23 +00001931{
1932 Int i;
sewardj695cff92004-10-13 14:50:14 +00001933 if (bb->stmts_used == bb->stmts_size) {
1934 IRStmt** stmts2 = LibVEX_Alloc(2 * bb->stmts_size * sizeof(IRStmt*));
1935 for (i = 0; i < bb->stmts_size; i++)
1936 stmts2[i] = bb->stmts[i];
1937 bb->stmts = stmts2;
1938 bb->stmts_size *= 2;
1939 }
1940 vassert(bb->stmts_used < bb->stmts_size);
1941 bb->stmts[bb->stmts_used] = st;
1942 bb->stmts_used++;
sewardjd7cb8532004-08-17 23:59:23 +00001943}
1944
sewardj695cff92004-10-13 14:50:14 +00001945
1946/*---------------------------------------------------------------*/
1947/*--- Helper functions for the IR -- IR Type Environments ---*/
1948/*---------------------------------------------------------------*/
1949
sewardjd7cb8532004-08-17 23:59:23 +00001950/* Allocate a new IRTemp, given its type. */
sewardje3d0d2e2004-06-27 10:42:44 +00001951
sewardje539a402004-07-14 18:24:17 +00001952IRTemp newIRTemp ( IRTypeEnv* env, IRType ty )
sewardjc97096c2004-06-30 09:28:04 +00001953{
sewardj35421a32004-07-05 13:12:34 +00001954 vassert(env);
sewardje539a402004-07-14 18:24:17 +00001955 vassert(env->types_used >= 0);
1956 vassert(env->types_size >= 0);
1957 vassert(env->types_used <= env->types_size);
1958 if (env->types_used < env->types_size) {
1959 env->types[env->types_used] = ty;
1960 return env->types_used++;
sewardjc97096c2004-06-30 09:28:04 +00001961 } else {
1962 Int i;
sewardje539a402004-07-14 18:24:17 +00001963 Int new_size = env->types_size==0 ? 8 : 2*env->types_size;
1964 IRType* new_types
1965 = LibVEX_Alloc(new_size * sizeof(IRType));
1966 for (i = 0; i < env->types_used; i++)
1967 new_types[i] = env->types[i];
1968 env->types = new_types;
1969 env->types_size = new_size;
1970 return newIRTemp(env, ty);
sewardjc97096c2004-06-30 09:28:04 +00001971 }
1972}
1973
1974
sewardj17442fe2004-09-20 14:54:28 +00001975/*---------------------------------------------------------------*/
1976/*--- Helper functions for the IR -- finding types of exprs ---*/
1977/*---------------------------------------------------------------*/
1978
sewardjedeb4c42004-09-21 23:39:25 +00001979inline
sewardj17442fe2004-09-20 14:54:28 +00001980IRType typeOfIRTemp ( IRTypeEnv* env, IRTemp tmp )
sewardjc97096c2004-06-30 09:28:04 +00001981{
sewardje539a402004-07-14 18:24:17 +00001982 vassert(tmp >= 0);
1983 vassert(tmp < env->types_used);
1984 return env->types[tmp];
sewardjc97096c2004-06-30 09:28:04 +00001985}
1986
1987
sewardj6efd4a12004-07-15 03:54:23 +00001988IRType typeOfIRConst ( IRConst* con )
1989{
1990 switch (con->tag) {
sewardjba999312004-11-15 15:21:17 +00001991 case Ico_U1: return Ity_I1;
sewardj207557a2004-08-27 12:00:18 +00001992 case Ico_U8: return Ity_I8;
1993 case Ico_U16: return Ity_I16;
1994 case Ico_U32: return Ity_I32;
1995 case Ico_U64: return Ity_I64;
1996 case Ico_F64: return Ity_F64;
sewardj17442fe2004-09-20 14:54:28 +00001997 case Ico_F64i: return Ity_F64;
sewardj1e6ad742004-12-02 16:16:11 +00001998 case Ico_V128: return Ity_V128;
sewardj6efd4a12004-07-15 03:54:23 +00001999 default: vpanic("typeOfIRConst");
2000 }
2001}
2002
sewardjc97096c2004-06-30 09:28:04 +00002003IRType typeOfIRExpr ( IRTypeEnv* tyenv, IRExpr* e )
2004{
sewardj40c80262006-02-08 19:30:46 +00002005 IRType t_dst, t_arg1, t_arg2, t_arg3, t_arg4;
sewardjedeb4c42004-09-21 23:39:25 +00002006 start:
sewardjc97096c2004-06-30 09:28:04 +00002007 switch (e->tag) {
sewardjaf1ceca2005-06-30 23:31:27 +00002008 case Iex_Load:
2009 return e->Iex.Load.ty;
sewardjfbcaf332004-07-08 01:46:01 +00002010 case Iex_Get:
2011 return e->Iex.Get.ty;
sewardjbb53f8c2004-08-14 11:50:01 +00002012 case Iex_GetI:
sewardj2d3f77c2004-09-22 23:49:09 +00002013 return e->Iex.GetI.descr->elemTy;
sewardjdd40fdf2006-12-24 02:20:24 +00002014 case Iex_RdTmp:
2015 return typeOfIRTemp(tyenv, e->Iex.RdTmp.tmp);
sewardjc97096c2004-06-30 09:28:04 +00002016 case Iex_Const:
sewardj695cff92004-10-13 14:50:14 +00002017 return typeOfIRConst(e->Iex.Const.con);
sewardj40c80262006-02-08 19:30:46 +00002018 case Iex_Qop:
2019 typeOfPrimop(e->Iex.Qop.op,
2020 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
2021 return t_dst;
sewardjb183b852006-02-03 16:08:03 +00002022 case Iex_Triop:
sewardj40c80262006-02-08 19:30:46 +00002023 typeOfPrimop(e->Iex.Triop.op,
2024 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002025 return t_dst;
sewardjc97096c2004-06-30 09:28:04 +00002026 case Iex_Binop:
sewardj40c80262006-02-08 19:30:46 +00002027 typeOfPrimop(e->Iex.Binop.op,
2028 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardj6efd4a12004-07-15 03:54:23 +00002029 return t_dst;
2030 case Iex_Unop:
sewardj40c80262006-02-08 19:30:46 +00002031 typeOfPrimop(e->Iex.Unop.op,
2032 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardj6efd4a12004-07-15 03:54:23 +00002033 return t_dst;
2034 case Iex_CCall:
2035 return e->Iex.CCall.retty;
sewardj4042c7e2004-07-18 01:28:30 +00002036 case Iex_Mux0X:
sewardjedeb4c42004-09-21 23:39:25 +00002037 e = e->Iex.Mux0X.expr0;
2038 goto start;
2039 /* return typeOfIRExpr(tyenv, e->Iex.Mux0X.expr0); */
sewardj443cd9d2004-07-18 23:06:45 +00002040 case Iex_Binder:
2041 vpanic("typeOfIRExpr: Binder is not a valid expression");
sewardjc97096c2004-06-30 09:28:04 +00002042 default:
sewardj6efd4a12004-07-15 03:54:23 +00002043 ppIRExpr(e);
2044 vpanic("typeOfIRExpr");
sewardjc97096c2004-06-30 09:28:04 +00002045 }
sewardjc97096c2004-06-30 09:28:04 +00002046}
sewardj887a11a2004-07-05 17:26:47 +00002047
sewardj6d2638e2004-07-15 09:38:27 +00002048/* Is this any value actually in the enumeration 'IRType' ? */
sewardj496a58d2005-03-20 18:44:44 +00002049Bool isPlausibleIRType ( IRType ty )
sewardj6d2638e2004-07-15 09:38:27 +00002050{
2051 switch (ty) {
sewardjba999312004-11-15 15:21:17 +00002052 case Ity_INVALID: case Ity_I1:
sewardj9b967672005-02-08 11:13:09 +00002053 case Ity_I8: case Ity_I16: case Ity_I32:
2054 case Ity_I64: case Ity_I128:
sewardjbb53f8c2004-08-14 11:50:01 +00002055 case Ity_F32: case Ity_F64:
sewardjc9a43662004-11-30 18:51:59 +00002056 case Ity_V128:
sewardj6d2638e2004-07-15 09:38:27 +00002057 return True;
2058 default:
2059 return False;
2060 }
2061}
2062
sewardj6efd4a12004-07-15 03:54:23 +00002063
sewardj887a11a2004-07-05 17:26:47 +00002064/*---------------------------------------------------------------*/
sewardjcf787902004-11-03 09:08:33 +00002065/*--- Sanity checking -- FLATNESS ---*/
2066/*---------------------------------------------------------------*/
2067
2068/* Check that the canonical flatness constraints hold on an
2069 IRStmt. The only place where any expression is allowed to be
2070 non-atomic is the RHS of IRStmt_Tmp. */
2071
2072/* Relies on:
2073 inline static Bool isAtom ( IRExpr* e ) {
sewardjdd40fdf2006-12-24 02:20:24 +00002074 return e->tag == Iex_RdTmp || e->tag == Iex_Const;
sewardjcf787902004-11-03 09:08:33 +00002075 }
2076*/
2077
2078Bool isFlatIRStmt ( IRStmt* st )
2079{
2080 Int i;
2081 IRExpr* e;
2082 IRDirty* di;
sewardje9d8a262009-07-01 08:06:34 +00002083 IRCAS* cas;
sewardjcf787902004-11-03 09:08:33 +00002084
2085 switch (st->tag) {
sewardj5a9ffab2005-05-12 17:55:01 +00002086 case Ist_AbiHint:
sewardj478646f2008-05-01 20:13:04 +00002087 return isIRAtom(st->Ist.AbiHint.base)
2088 && isIRAtom(st->Ist.AbiHint.nia);
sewardjcf787902004-11-03 09:08:33 +00002089 case Ist_Put:
sewardj496a58d2005-03-20 18:44:44 +00002090 return isIRAtom(st->Ist.Put.data);
sewardjcf787902004-11-03 09:08:33 +00002091 case Ist_PutI:
sewardj496a58d2005-03-20 18:44:44 +00002092 return toBool( isIRAtom(st->Ist.PutI.ix)
2093 && isIRAtom(st->Ist.PutI.data) );
sewardjdd40fdf2006-12-24 02:20:24 +00002094 case Ist_WrTmp:
sewardjcf787902004-11-03 09:08:33 +00002095 /* This is the only interesting case. The RHS can be any
2096 expression, *but* all its subexpressions *must* be
2097 atoms. */
sewardjdd40fdf2006-12-24 02:20:24 +00002098 e = st->Ist.WrTmp.data;
sewardjcf787902004-11-03 09:08:33 +00002099 switch (e->tag) {
2100 case Iex_Binder: return True;
2101 case Iex_Get: return True;
sewardj496a58d2005-03-20 18:44:44 +00002102 case Iex_GetI: return isIRAtom(e->Iex.GetI.ix);
sewardjdd40fdf2006-12-24 02:20:24 +00002103 case Iex_RdTmp: return True;
sewardj40c80262006-02-08 19:30:46 +00002104 case Iex_Qop: return toBool(
2105 isIRAtom(e->Iex.Qop.arg1)
2106 && isIRAtom(e->Iex.Qop.arg2)
2107 && isIRAtom(e->Iex.Qop.arg3)
2108 && isIRAtom(e->Iex.Qop.arg4));
sewardjb183b852006-02-03 16:08:03 +00002109 case Iex_Triop: return toBool(
2110 isIRAtom(e->Iex.Triop.arg1)
2111 && isIRAtom(e->Iex.Triop.arg2)
2112 && isIRAtom(e->Iex.Triop.arg3));
sewardja98bf492005-02-07 01:39:17 +00002113 case Iex_Binop: return toBool(
sewardj496a58d2005-03-20 18:44:44 +00002114 isIRAtom(e->Iex.Binop.arg1)
2115 && isIRAtom(e->Iex.Binop.arg2));
2116 case Iex_Unop: return isIRAtom(e->Iex.Unop.arg);
sewardjaf1ceca2005-06-30 23:31:27 +00002117 case Iex_Load: return isIRAtom(e->Iex.Load.addr);
sewardjcf787902004-11-03 09:08:33 +00002118 case Iex_Const: return True;
2119 case Iex_CCall: for (i = 0; e->Iex.CCall.args[i]; i++)
sewardj496a58d2005-03-20 18:44:44 +00002120 if (!isIRAtom(e->Iex.CCall.args[i]))
sewardjcf787902004-11-03 09:08:33 +00002121 return False;
2122 return True;
sewardja98bf492005-02-07 01:39:17 +00002123 case Iex_Mux0X: return toBool (
sewardj496a58d2005-03-20 18:44:44 +00002124 isIRAtom(e->Iex.Mux0X.cond)
2125 && isIRAtom(e->Iex.Mux0X.expr0)
2126 && isIRAtom(e->Iex.Mux0X.exprX));
sewardjcf787902004-11-03 09:08:33 +00002127 default: vpanic("isFlatIRStmt(e)");
2128 }
2129 /*notreached*/
2130 vassert(0);
sewardjaf1ceca2005-06-30 23:31:27 +00002131 case Ist_Store:
2132 return toBool( isIRAtom(st->Ist.Store.addr)
2133 && isIRAtom(st->Ist.Store.data) );
sewardje9d8a262009-07-01 08:06:34 +00002134 case Ist_CAS:
2135 cas = st->Ist.CAS.details;
2136 return toBool( isIRAtom(cas->addr)
2137 && (cas->expdHi ? isIRAtom(cas->expdHi) : True)
2138 && isIRAtom(cas->expdLo)
2139 && (cas->dataHi ? isIRAtom(cas->dataHi) : True)
2140 && isIRAtom(cas->dataLo) );
sewardjcf787902004-11-03 09:08:33 +00002141 case Ist_Dirty:
2142 di = st->Ist.Dirty.details;
sewardj496a58d2005-03-20 18:44:44 +00002143 if (!isIRAtom(di->guard))
sewardjcf787902004-11-03 09:08:33 +00002144 return False;
2145 for (i = 0; di->args[i]; i++)
sewardj496a58d2005-03-20 18:44:44 +00002146 if (!isIRAtom(di->args[i]))
sewardjcf787902004-11-03 09:08:33 +00002147 return False;
sewardj496a58d2005-03-20 18:44:44 +00002148 if (di->mAddr && !isIRAtom(di->mAddr))
sewardjcf787902004-11-03 09:08:33 +00002149 return False;
2150 return True;
sewardjd2445f62005-03-21 00:15:53 +00002151 case Ist_NoOp:
sewardjf1689312005-03-16 18:19:10 +00002152 case Ist_IMark:
sewardjc4356f02007-11-09 21:15:04 +00002153 case Ist_MBE:
sewardj3e838932005-01-07 12:09:15 +00002154 return True;
sewardjcf787902004-11-03 09:08:33 +00002155 case Ist_Exit:
sewardj496a58d2005-03-20 18:44:44 +00002156 return isIRAtom(st->Ist.Exit.guard);
sewardjcf787902004-11-03 09:08:33 +00002157 default:
2158 vpanic("isFlatIRStmt(st)");
2159 }
2160}
2161
2162
2163/*---------------------------------------------------------------*/
sewardje539a402004-07-14 18:24:17 +00002164/*--- Sanity checking ---*/
2165/*---------------------------------------------------------------*/
2166
2167/* Checks:
2168
2169 Everything is type-consistent. No ill-typed anything.
sewardj35439212004-07-14 22:36:10 +00002170 The target address at the end of the BB is a 32- or 64-
2171 bit expression, depending on the guest's word size.
sewardje539a402004-07-14 18:24:17 +00002172
2173 Each temp is assigned only once, before its uses.
sewardjc13e2ed2004-10-31 21:44:54 +00002174*/
2175
2176static inline Int countArgs ( IRExpr** args )
2177{
2178 Int i;
2179 for (i = 0; args[i]; i++)
2180 ;
2181 return i;
2182}
sewardje539a402004-07-14 18:24:17 +00002183
sewardj35439212004-07-14 22:36:10 +00002184static
2185__attribute((noreturn))
sewardjdd40fdf2006-12-24 02:20:24 +00002186void sanityCheckFail ( IRSB* bb, IRStmt* stmt, HChar* what )
sewardje539a402004-07-14 18:24:17 +00002187{
sewardj35439212004-07-14 22:36:10 +00002188 vex_printf("\nIR SANITY CHECK FAILURE\n\n");
sewardjdd40fdf2006-12-24 02:20:24 +00002189 ppIRSB(bb);
sewardj35439212004-07-14 22:36:10 +00002190 if (stmt) {
2191 vex_printf("\nIN STATEMENT:\n\n");
2192 ppIRStmt(stmt);
2193 }
2194 vex_printf("\n\nERROR = %s\n\n", what );
2195 vpanic("sanityCheckFail: exiting due to bad IR");
2196}
2197
sewardjdd40fdf2006-12-24 02:20:24 +00002198static Bool saneIRRegArray ( IRRegArray* arr )
sewardj2d3f77c2004-09-22 23:49:09 +00002199{
2200 if (arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */)
2201 return False;
sewardjba999312004-11-15 15:21:17 +00002202 if (arr->elemTy == Ity_I1)
sewardj2d3f77c2004-09-22 23:49:09 +00002203 return False;
2204 if (arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */)
2205 return False;
2206 return True;
2207}
2208
sewardj8ea867b2004-10-30 19:03:02 +00002209static Bool saneIRCallee ( IRCallee* cee )
2210{
2211 if (cee->name == NULL)
2212 return False;
2213 if (cee->addr == 0)
2214 return False;
sewardj77352542004-10-30 20:39:01 +00002215 if (cee->regparms < 0 || cee->regparms > 3)
sewardj8ea867b2004-10-30 19:03:02 +00002216 return False;
2217 return True;
2218}
2219
sewardj49bfe672004-11-15 15:46:26 +00002220static Bool saneIRConst ( IRConst* con )
2221{
2222 switch (con->tag) {
2223 case Ico_U1:
sewardja98bf492005-02-07 01:39:17 +00002224 return toBool( con->Ico.U1 == True || con->Ico.U1 == False );
sewardj49bfe672004-11-15 15:46:26 +00002225 default:
2226 /* Is there anything we can meaningfully check? I don't
2227 think so. */
2228 return True;
2229 }
2230}
sewardj35439212004-07-14 22:36:10 +00002231
2232/* Traverse a Stmt/Expr, inspecting IRTemp uses. Report any out of
2233 range ones. Report any which are read and for which the current
2234 def_count is zero. */
2235
2236static
sewardjdd40fdf2006-12-24 02:20:24 +00002237void useBeforeDef_Temp ( IRSB* bb, IRStmt* stmt, IRTemp tmp, Int* def_counts )
sewardj17442fe2004-09-20 14:54:28 +00002238{
2239 if (tmp < 0 || tmp >= bb->tyenv->types_used)
2240 sanityCheckFail(bb,stmt, "out of range Temp in IRExpr");
2241 if (def_counts[tmp] < 1)
2242 sanityCheckFail(bb,stmt, "IRTemp use before def in IRExpr");
2243}
2244
2245static
sewardjdd40fdf2006-12-24 02:20:24 +00002246void useBeforeDef_Expr ( IRSB* bb, IRStmt* stmt, IRExpr* expr, Int* def_counts )
sewardj35439212004-07-14 22:36:10 +00002247{
2248 Int i;
2249 switch (expr->tag) {
2250 case Iex_Get:
2251 break;
sewardjbb53f8c2004-08-14 11:50:01 +00002252 case Iex_GetI:
sewardjeeac8412004-11-02 00:26:55 +00002253 useBeforeDef_Expr(bb,stmt,expr->Iex.GetI.ix,def_counts);
sewardjbb53f8c2004-08-14 11:50:01 +00002254 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002255 case Iex_RdTmp:
2256 useBeforeDef_Temp(bb,stmt,expr->Iex.RdTmp.tmp,def_counts);
sewardj35439212004-07-14 22:36:10 +00002257 break;
sewardj40c80262006-02-08 19:30:46 +00002258 case Iex_Qop:
2259 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg1,def_counts);
2260 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg2,def_counts);
2261 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg3,def_counts);
2262 useBeforeDef_Expr(bb,stmt,expr->Iex.Qop.arg4,def_counts);
2263 break;
sewardjb183b852006-02-03 16:08:03 +00002264 case Iex_Triop:
2265 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg1,def_counts);
2266 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg2,def_counts);
2267 useBeforeDef_Expr(bb,stmt,expr->Iex.Triop.arg3,def_counts);
2268 break;
sewardj35439212004-07-14 22:36:10 +00002269 case Iex_Binop:
2270 useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg1,def_counts);
2271 useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg2,def_counts);
2272 break;
2273 case Iex_Unop:
2274 useBeforeDef_Expr(bb,stmt,expr->Iex.Unop.arg,def_counts);
2275 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002276 case Iex_Load:
2277 useBeforeDef_Expr(bb,stmt,expr->Iex.Load.addr,def_counts);
sewardj35439212004-07-14 22:36:10 +00002278 break;
2279 case Iex_Const:
2280 break;
2281 case Iex_CCall:
2282 for (i = 0; expr->Iex.CCall.args[i]; i++)
2283 useBeforeDef_Expr(bb,stmt,expr->Iex.CCall.args[i],def_counts);
2284 break;
sewardj4042c7e2004-07-18 01:28:30 +00002285 case Iex_Mux0X:
2286 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.cond,def_counts);
2287 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.expr0,def_counts);
2288 useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.exprX,def_counts);
sewardjeeb9ef82004-07-15 12:39:03 +00002289 break;
2290 default:
2291 vpanic("useBeforeDef_Expr");
sewardj35439212004-07-14 22:36:10 +00002292 }
2293}
2294
2295static
sewardjdd40fdf2006-12-24 02:20:24 +00002296void useBeforeDef_Stmt ( IRSB* bb, IRStmt* stmt, Int* def_counts )
sewardj35439212004-07-14 22:36:10 +00002297{
sewardj17442fe2004-09-20 14:54:28 +00002298 Int i;
2299 IRDirty* d;
sewardje9d8a262009-07-01 08:06:34 +00002300 IRCAS* cas;
sewardj35439212004-07-14 22:36:10 +00002301 switch (stmt->tag) {
sewardjf1689312005-03-16 18:19:10 +00002302 case Ist_IMark:
2303 break;
sewardj5a9ffab2005-05-12 17:55:01 +00002304 case Ist_AbiHint:
2305 useBeforeDef_Expr(bb,stmt,stmt->Ist.AbiHint.base,def_counts);
sewardj478646f2008-05-01 20:13:04 +00002306 useBeforeDef_Expr(bb,stmt,stmt->Ist.AbiHint.nia,def_counts);
sewardj5a9ffab2005-05-12 17:55:01 +00002307 break;
sewardj35439212004-07-14 22:36:10 +00002308 case Ist_Put:
sewardj6d076362004-09-23 11:06:17 +00002309 useBeforeDef_Expr(bb,stmt,stmt->Ist.Put.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002310 break;
sewardjd1725d12004-08-12 20:46:53 +00002311 case Ist_PutI:
sewardjeeac8412004-11-02 00:26:55 +00002312 useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.ix,def_counts);
sewardj2d3f77c2004-09-22 23:49:09 +00002313 useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.data,def_counts);
sewardjd1725d12004-08-12 20:46:53 +00002314 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002315 case Ist_WrTmp:
2316 useBeforeDef_Expr(bb,stmt,stmt->Ist.WrTmp.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002317 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002318 case Ist_Store:
2319 useBeforeDef_Expr(bb,stmt,stmt->Ist.Store.addr,def_counts);
2320 useBeforeDef_Expr(bb,stmt,stmt->Ist.Store.data,def_counts);
sewardj35439212004-07-14 22:36:10 +00002321 break;
sewardje9d8a262009-07-01 08:06:34 +00002322 case Ist_CAS:
2323 cas = stmt->Ist.CAS.details;
2324 useBeforeDef_Expr(bb,stmt,cas->addr,def_counts);
2325 if (cas->expdHi)
2326 useBeforeDef_Expr(bb,stmt,cas->expdHi,def_counts);
2327 useBeforeDef_Expr(bb,stmt,cas->expdLo,def_counts);
2328 if (cas->dataHi)
2329 useBeforeDef_Expr(bb,stmt,cas->dataHi,def_counts);
2330 useBeforeDef_Expr(bb,stmt,cas->dataLo,def_counts);
2331 break;
sewardj17442fe2004-09-20 14:54:28 +00002332 case Ist_Dirty:
2333 d = stmt->Ist.Dirty.details;
2334 for (i = 0; d->args[i] != NULL; i++)
2335 useBeforeDef_Expr(bb,stmt,d->args[i],def_counts);
2336 if (d->mFx != Ifx_None)
2337 useBeforeDef_Expr(bb,stmt,d->mAddr,def_counts);
2338 break;
sewardjd2445f62005-03-21 00:15:53 +00002339 case Ist_NoOp:
sewardjc4356f02007-11-09 21:15:04 +00002340 case Ist_MBE:
sewardj3e838932005-01-07 12:09:15 +00002341 break;
sewardj35439212004-07-14 22:36:10 +00002342 case Ist_Exit:
sewardj0276d4b2004-11-15 15:30:21 +00002343 useBeforeDef_Expr(bb,stmt,stmt->Ist.Exit.guard,def_counts);
sewardj35439212004-07-14 22:36:10 +00002344 break;
2345 default:
2346 vpanic("useBeforeDef_Stmt");
2347 }
2348}
2349
sewardj6efd4a12004-07-15 03:54:23 +00002350static
sewardjdd40fdf2006-12-24 02:20:24 +00002351void tcExpr ( IRSB* bb, IRStmt* stmt, IRExpr* expr, IRType gWordTy )
sewardj6efd4a12004-07-15 03:54:23 +00002352{
2353 Int i;
sewardj40c80262006-02-08 19:30:46 +00002354 IRType t_dst, t_arg1, t_arg2, t_arg3, t_arg4;
sewardj6efd4a12004-07-15 03:54:23 +00002355 IRTypeEnv* tyenv = bb->tyenv;
2356 switch (expr->tag) {
2357 case Iex_Get:
sewardjdd40fdf2006-12-24 02:20:24 +00002358 case Iex_RdTmp:
sewardj6efd4a12004-07-15 03:54:23 +00002359 break;
sewardjbb53f8c2004-08-14 11:50:01 +00002360 case Iex_GetI:
sewardjeeac8412004-11-02 00:26:55 +00002361 tcExpr(bb,stmt, expr->Iex.GetI.ix, gWordTy );
2362 if (typeOfIRExpr(tyenv,expr->Iex.GetI.ix) != Ity_I32)
2363 sanityCheckFail(bb,stmt,"IRExpr.GetI.ix: not :: Ity_I32");
sewardjdd40fdf2006-12-24 02:20:24 +00002364 if (!saneIRRegArray(expr->Iex.GetI.descr))
sewardj2d3f77c2004-09-22 23:49:09 +00002365 sanityCheckFail(bb,stmt,"IRExpr.GetI.descr: invalid descr");
sewardjbb53f8c2004-08-14 11:50:01 +00002366 break;
sewardj40c80262006-02-08 19:30:46 +00002367 case Iex_Qop: {
2368 IRType ttarg1, ttarg2, ttarg3, ttarg4;
2369 tcExpr(bb,stmt, expr->Iex.Qop.arg1, gWordTy );
2370 tcExpr(bb,stmt, expr->Iex.Qop.arg2, gWordTy );
2371 tcExpr(bb,stmt, expr->Iex.Qop.arg3, gWordTy );
2372 tcExpr(bb,stmt, expr->Iex.Qop.arg4, gWordTy );
2373 typeOfPrimop(expr->Iex.Qop.op,
2374 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
2375 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
2376 || t_arg3 == Ity_INVALID || t_arg4 == Ity_INVALID) {
2377 vex_printf(" op name: " );
2378 ppIROp(expr->Iex.Qop.op);
2379 vex_printf("\n");
2380 sanityCheckFail(bb,stmt,
2381 "Iex.Qop: wrong arity op\n"
2382 "... name of op precedes BB printout\n");
2383 }
2384 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg1);
2385 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg2);
2386 ttarg3 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg3);
2387 ttarg4 = typeOfIRExpr(tyenv, expr->Iex.Qop.arg4);
2388 if (t_arg1 != ttarg1 || t_arg2 != ttarg2
2389 || t_arg3 != ttarg3 || t_arg4 != ttarg4) {
2390 vex_printf(" op name: ");
2391 ppIROp(expr->Iex.Qop.op);
2392 vex_printf("\n");
2393 vex_printf(" op type is (");
2394 ppIRType(t_arg1);
2395 vex_printf(",");
2396 ppIRType(t_arg2);
2397 vex_printf(",");
2398 ppIRType(t_arg3);
2399 vex_printf(",");
2400 ppIRType(t_arg4);
2401 vex_printf(") -> ");
2402 ppIRType (t_dst);
2403 vex_printf("\narg tys are (");
2404 ppIRType(ttarg1);
2405 vex_printf(",");
2406 ppIRType(ttarg2);
2407 vex_printf(",");
2408 ppIRType(ttarg3);
2409 vex_printf(",");
2410 ppIRType(ttarg4);
2411 vex_printf(")\n");
2412 sanityCheckFail(bb,stmt,
2413 "Iex.Qop: arg tys don't match op tys\n"
2414 "... additional details precede BB printout\n");
2415 }
2416 break;
2417 }
sewardjb183b852006-02-03 16:08:03 +00002418 case Iex_Triop: {
2419 IRType ttarg1, ttarg2, ttarg3;
2420 tcExpr(bb,stmt, expr->Iex.Triop.arg1, gWordTy );
2421 tcExpr(bb,stmt, expr->Iex.Triop.arg2, gWordTy );
2422 tcExpr(bb,stmt, expr->Iex.Triop.arg3, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002423 typeOfPrimop(expr->Iex.Triop.op,
2424 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002425 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002426 || t_arg3 == Ity_INVALID || t_arg4 != Ity_INVALID) {
sewardjb183b852006-02-03 16:08:03 +00002427 vex_printf(" op name: " );
2428 ppIROp(expr->Iex.Triop.op);
2429 vex_printf("\n");
2430 sanityCheckFail(bb,stmt,
2431 "Iex.Triop: wrong arity op\n"
2432 "... name of op precedes BB printout\n");
2433 }
2434 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg1);
2435 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg2);
2436 ttarg3 = typeOfIRExpr(tyenv, expr->Iex.Triop.arg3);
2437 if (t_arg1 != ttarg1 || t_arg2 != ttarg2 || t_arg3 != ttarg3) {
2438 vex_printf(" op name: ");
2439 ppIROp(expr->Iex.Triop.op);
2440 vex_printf("\n");
2441 vex_printf(" op type is (");
2442 ppIRType(t_arg1);
2443 vex_printf(",");
2444 ppIRType(t_arg2);
2445 vex_printf(",");
2446 ppIRType(t_arg3);
2447 vex_printf(") -> ");
2448 ppIRType (t_dst);
2449 vex_printf("\narg tys are (");
2450 ppIRType(ttarg1);
2451 vex_printf(",");
2452 ppIRType(ttarg2);
2453 vex_printf(",");
2454 ppIRType(ttarg3);
2455 vex_printf(")\n");
2456 sanityCheckFail(bb,stmt,
2457 "Iex.Triop: arg tys don't match op tys\n"
2458 "... additional details precede BB printout\n");
2459 }
2460 break;
2461 }
sewardj6d2638e2004-07-15 09:38:27 +00002462 case Iex_Binop: {
2463 IRType ttarg1, ttarg2;
sewardj6efd4a12004-07-15 03:54:23 +00002464 tcExpr(bb,stmt, expr->Iex.Binop.arg1, gWordTy );
2465 tcExpr(bb,stmt, expr->Iex.Binop.arg2, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002466 typeOfPrimop(expr->Iex.Binop.op,
2467 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002468 if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002469 || t_arg3 != Ity_INVALID || t_arg4 != Ity_INVALID) {
sewardj8f3debf2004-09-08 23:42:23 +00002470 vex_printf(" op name: " );
2471 ppIROp(expr->Iex.Binop.op);
2472 vex_printf("\n");
2473 sanityCheckFail(bb,stmt,
2474 "Iex.Binop: wrong arity op\n"
2475 "... name of op precedes BB printout\n");
2476 }
sewardj6d2638e2004-07-15 09:38:27 +00002477 ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg1);
2478 ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg2);
2479 if (t_arg1 != ttarg1 || t_arg2 != ttarg2) {
2480 vex_printf(" op name: ");
2481 ppIROp(expr->Iex.Binop.op);
2482 vex_printf("\n");
2483 vex_printf(" op type is (");
2484 ppIRType(t_arg1);
2485 vex_printf(",");
2486 ppIRType(t_arg2);
2487 vex_printf(") -> ");
2488 ppIRType (t_dst);
2489 vex_printf("\narg tys are (");
2490 ppIRType(ttarg1);
2491 vex_printf(",");
2492 ppIRType(ttarg2);
2493 vex_printf(")\n");
2494 sanityCheckFail(bb,stmt,
2495 "Iex.Binop: arg tys don't match op tys\n"
2496 "... additional details precede BB printout\n");
sewardj695cff92004-10-13 14:50:14 +00002497 }
sewardj6efd4a12004-07-15 03:54:23 +00002498 break;
sewardj6d2638e2004-07-15 09:38:27 +00002499 }
sewardj6efd4a12004-07-15 03:54:23 +00002500 case Iex_Unop:
2501 tcExpr(bb,stmt, expr->Iex.Unop.arg, gWordTy );
sewardj40c80262006-02-08 19:30:46 +00002502 typeOfPrimop(expr->Iex.Binop.op,
2503 &t_dst, &t_arg1, &t_arg2, &t_arg3, &t_arg4);
sewardjb183b852006-02-03 16:08:03 +00002504 if (t_arg1 == Ity_INVALID || t_arg2 != Ity_INVALID
sewardj40c80262006-02-08 19:30:46 +00002505 || t_arg3 != Ity_INVALID || t_arg4 != Ity_INVALID)
sewardj6efd4a12004-07-15 03:54:23 +00002506 sanityCheckFail(bb,stmt,"Iex.Unop: wrong arity op");
2507 if (t_arg1 != typeOfIRExpr(tyenv, expr->Iex.Unop.arg))
2508 sanityCheckFail(bb,stmt,"Iex.Unop: arg ty doesn't match op ty");
2509 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002510 case Iex_Load:
2511 tcExpr(bb,stmt, expr->Iex.Load.addr, gWordTy);
2512 if (typeOfIRExpr(tyenv, expr->Iex.Load.addr) != gWordTy)
2513 sanityCheckFail(bb,stmt,"Iex.Load.addr: not :: guest word type");
2514 if (expr->Iex.Load.end != Iend_LE && expr->Iex.Load.end != Iend_BE)
2515 sanityCheckFail(bb,stmt,"Iex.Load.end: bogus endianness");
sewardj6efd4a12004-07-15 03:54:23 +00002516 break;
2517 case Iex_CCall:
sewardjc13e2ed2004-10-31 21:44:54 +00002518 if (!saneIRCallee(expr->Iex.CCall.cee))
2519 sanityCheckFail(bb,stmt,"Iex.CCall.cee: bad IRCallee");
sewardjcf787902004-11-03 09:08:33 +00002520 if (expr->Iex.CCall.cee->regparms > countArgs(expr->Iex.CCall.args))
sewardjc13e2ed2004-10-31 21:44:54 +00002521 sanityCheckFail(bb,stmt,"Iex.CCall.cee: #regparms > #args");
sewardj43c56462004-11-06 12:17:57 +00002522 for (i = 0; expr->Iex.CCall.args[i]; i++) {
2523 if (i >= 32)
2524 sanityCheckFail(bb,stmt,"Iex.CCall: > 32 args");
sewardj6efd4a12004-07-15 03:54:23 +00002525 tcExpr(bb,stmt, expr->Iex.CCall.args[i], gWordTy);
sewardj43c56462004-11-06 12:17:57 +00002526 }
sewardjba999312004-11-15 15:21:17 +00002527 if (expr->Iex.CCall.retty == Ity_I1)
2528 sanityCheckFail(bb,stmt,"Iex.CCall.retty: cannot return :: Ity_I1");
sewardj6efd4a12004-07-15 03:54:23 +00002529 for (i = 0; expr->Iex.CCall.args[i]; i++)
sewardjba999312004-11-15 15:21:17 +00002530 if (typeOfIRExpr(tyenv, expr->Iex.CCall.args[i]) == Ity_I1)
2531 sanityCheckFail(bb,stmt,"Iex.CCall.arg: arg :: Ity_I1");
sewardj6efd4a12004-07-15 03:54:23 +00002532 break;
2533 case Iex_Const:
sewardj49bfe672004-11-15 15:46:26 +00002534 if (!saneIRConst(expr->Iex.Const.con))
2535 sanityCheckFail(bb,stmt,"Iex.Const.con: invalid const");
sewardj6efd4a12004-07-15 03:54:23 +00002536 break;
sewardj4042c7e2004-07-18 01:28:30 +00002537 case Iex_Mux0X:
2538 tcExpr(bb,stmt, expr->Iex.Mux0X.cond, gWordTy);
2539 tcExpr(bb,stmt, expr->Iex.Mux0X.expr0, gWordTy);
2540 tcExpr(bb,stmt, expr->Iex.Mux0X.exprX, gWordTy);
2541 if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.cond) != Ity_I8)
2542 sanityCheckFail(bb,stmt,"Iex.Mux0X.cond: cond :: Ity_I8");
2543 if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.expr0)
2544 != typeOfIRExpr(tyenv, expr->Iex.Mux0X.exprX))
2545 sanityCheckFail(bb,stmt,"Iex.Mux0X: expr0/exprX mismatch");
sewardjeeb9ef82004-07-15 12:39:03 +00002546 break;
2547 default:
sewardj6efd4a12004-07-15 03:54:23 +00002548 vpanic("tcExpr");
2549 }
2550}
2551
2552
2553static
sewardjdd40fdf2006-12-24 02:20:24 +00002554void tcStmt ( IRSB* bb, IRStmt* stmt, IRType gWordTy )
sewardj6efd4a12004-07-15 03:54:23 +00002555{
sewardj17442fe2004-09-20 14:54:28 +00002556 Int i;
2557 IRDirty* d;
sewardje9d8a262009-07-01 08:06:34 +00002558 IRCAS* cas;
2559 IRType tyExpd, tyData;
sewardj6efd4a12004-07-15 03:54:23 +00002560 IRTypeEnv* tyenv = bb->tyenv;
2561 switch (stmt->tag) {
sewardjf1689312005-03-16 18:19:10 +00002562 case Ist_IMark:
2563 /* Somewhat heuristic, but rule out totally implausible
2564 instruction sizes. */
2565 if (stmt->Ist.IMark.len < 0 || stmt->Ist.IMark.len > 20)
2566 sanityCheckFail(bb,stmt,"IRStmt.IMark.len: implausible");
2567 break;
sewardj5a9ffab2005-05-12 17:55:01 +00002568 case Ist_AbiHint:
2569 if (typeOfIRExpr(tyenv, stmt->Ist.AbiHint.base) != gWordTy)
2570 sanityCheckFail(bb,stmt,"IRStmt.AbiHint.base: "
2571 "not :: guest word type");
sewardj478646f2008-05-01 20:13:04 +00002572 if (typeOfIRExpr(tyenv, stmt->Ist.AbiHint.nia) != gWordTy)
2573 sanityCheckFail(bb,stmt,"IRStmt.AbiHint.nia: "
2574 "not :: guest word type");
sewardj5a9ffab2005-05-12 17:55:01 +00002575 break;
sewardj6efd4a12004-07-15 03:54:23 +00002576 case Ist_Put:
sewardj6d076362004-09-23 11:06:17 +00002577 tcExpr( bb, stmt, stmt->Ist.Put.data, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002578 if (typeOfIRExpr(tyenv,stmt->Ist.Put.data) == Ity_I1)
2579 sanityCheckFail(bb,stmt,"IRStmt.Put.data: cannot Put :: Ity_I1");
sewardj2d3f77c2004-09-22 23:49:09 +00002580 break;
sewardjd1725d12004-08-12 20:46:53 +00002581 case Ist_PutI:
sewardj2d3f77c2004-09-22 23:49:09 +00002582 tcExpr( bb, stmt, stmt->Ist.PutI.data, gWordTy );
sewardjeeac8412004-11-02 00:26:55 +00002583 tcExpr( bb, stmt, stmt->Ist.PutI.ix, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002584 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data) == Ity_I1)
2585 sanityCheckFail(bb,stmt,"IRStmt.PutI.data: cannot PutI :: Ity_I1");
sewardj6d076362004-09-23 11:06:17 +00002586 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data)
2587 != stmt->Ist.PutI.descr->elemTy)
2588 sanityCheckFail(bb,stmt,"IRStmt.PutI.data: data ty != elem ty");
sewardjeeac8412004-11-02 00:26:55 +00002589 if (typeOfIRExpr(tyenv,stmt->Ist.PutI.ix) != Ity_I32)
2590 sanityCheckFail(bb,stmt,"IRStmt.PutI.ix: not :: Ity_I32");
sewardjdd40fdf2006-12-24 02:20:24 +00002591 if (!saneIRRegArray(stmt->Ist.PutI.descr))
sewardj2d3f77c2004-09-22 23:49:09 +00002592 sanityCheckFail(bb,stmt,"IRStmt.PutI.descr: invalid descr");
2593 break;
sewardjdd40fdf2006-12-24 02:20:24 +00002594 case Ist_WrTmp:
2595 tcExpr( bb, stmt, stmt->Ist.WrTmp.data, gWordTy );
2596 if (typeOfIRTemp(tyenv, stmt->Ist.WrTmp.tmp)
2597 != typeOfIRExpr(tyenv, stmt->Ist.WrTmp.data))
sewardj6d2638e2004-07-15 09:38:27 +00002598 sanityCheckFail(bb,stmt,"IRStmt.Put.Tmp: tmp and expr do not match");
sewardj6efd4a12004-07-15 03:54:23 +00002599 break;
sewardjaf1ceca2005-06-30 23:31:27 +00002600 case Ist_Store:
2601 tcExpr( bb, stmt, stmt->Ist.Store.addr, gWordTy );
2602 tcExpr( bb, stmt, stmt->Ist.Store.data, gWordTy );
2603 if (typeOfIRExpr(tyenv, stmt->Ist.Store.addr) != gWordTy)
2604 sanityCheckFail(bb,stmt,"IRStmt.Store.addr: not :: guest word type");
2605 if (typeOfIRExpr(tyenv, stmt->Ist.Store.data) == Ity_I1)
2606 sanityCheckFail(bb,stmt,"IRStmt.Store.data: cannot Store :: Ity_I1");
2607 if (stmt->Ist.Store.end != Iend_LE && stmt->Ist.Store.end != Iend_BE)
2608 sanityCheckFail(bb,stmt,"Ist.Store.end: bogus endianness");
sewardje9d8a262009-07-01 08:06:34 +00002609 if (stmt->Ist.Store.resSC != IRTemp_INVALID
2610 && typeOfIRTemp(tyenv, stmt->Ist.Store.resSC) != Ity_I1)
2611 sanityCheckFail(bb,stmt,"Ist.Store.resSC: not :: Ity_I1");
2612 break;
2613 case Ist_CAS:
2614 cas = stmt->Ist.CAS.details;
2615 /* make sure it's definitely either a CAS or a DCAS */
2616 if (cas->oldHi == IRTemp_INVALID
2617 && cas->expdHi == NULL && cas->dataHi == NULL) {
2618 /* fine; it's a single cas */
2619 }
2620 else
2621 if (cas->oldHi != IRTemp_INVALID
2622 && cas->expdHi != NULL && cas->dataHi != NULL) {
2623 /* fine; it's a double cas */
2624 }
2625 else {
2626 /* it's some el-mutanto hybrid */
2627 goto bad_cas;
2628 }
2629 /* check the address type */
2630 tcExpr( bb, stmt, cas->addr, gWordTy );
2631 if (typeOfIRExpr(tyenv, cas->addr) != gWordTy) goto bad_cas;
2632 /* check types on the {old,expd,data}Lo components agree */
2633 tyExpd = typeOfIRExpr(tyenv, cas->expdLo);
2634 tyData = typeOfIRExpr(tyenv, cas->dataLo);
2635 if (tyExpd != tyData) goto bad_cas;
2636 if (tyExpd != typeOfIRTemp(tyenv, cas->oldLo))
2637 goto bad_cas;
2638 /* check the base element type is sane */
2639 if (tyExpd == Ity_I8 || tyExpd == Ity_I16 || tyExpd == Ity_I32
2640 || (gWordTy == Ity_I64 && tyExpd == Ity_I64)) {
2641 /* fine */
2642 } else {
2643 goto bad_cas;
2644 }
2645 /* If it's a DCAS, check types on the {old,expd,data}Hi
2646 components too */
2647 if (cas->oldHi != IRTemp_INVALID) {
2648 tyExpd = typeOfIRExpr(tyenv, cas->expdHi);
2649 tyData = typeOfIRExpr(tyenv, cas->dataHi);
2650 if (tyExpd != tyData) goto bad_cas;
2651 if (tyExpd != typeOfIRTemp(tyenv, cas->oldHi))
2652 goto bad_cas;
2653 /* and finally check that oldLo and oldHi have the same
2654 type. This forces equivalence amongst all 6 types. */
2655 if (typeOfIRTemp(tyenv, cas->oldHi)
2656 != typeOfIRTemp(tyenv, cas->oldLo))
2657 goto bad_cas;
2658 }
2659 break;
2660 bad_cas:
2661 sanityCheckFail(bb,stmt,"IRStmt.CAS: ill-formed");
sewardj6efd4a12004-07-15 03:54:23 +00002662 break;
sewardj17442fe2004-09-20 14:54:28 +00002663 case Ist_Dirty:
2664 /* Mostly check for various kinds of ill-formed dirty calls. */
2665 d = stmt->Ist.Dirty.details;
sewardj8ea867b2004-10-30 19:03:02 +00002666 if (d->cee == NULL) goto bad_dirty;
2667 if (!saneIRCallee(d->cee)) goto bad_dirty;
sewardjcf787902004-11-03 09:08:33 +00002668 if (d->cee->regparms > countArgs(d->args)) goto bad_dirty;
sewardj17442fe2004-09-20 14:54:28 +00002669 if (d->mFx == Ifx_None) {
2670 if (d->mAddr != NULL || d->mSize != 0)
2671 goto bad_dirty;
2672 } else {
2673 if (d->mAddr == NULL || d->mSize == 0)
2674 goto bad_dirty;
2675 }
2676 if (d->nFxState < 0 || d->nFxState > VEX_N_FXSTATE)
2677 goto bad_dirty;
sewardjc5fc7aa2004-10-27 23:00:55 +00002678 if (d->nFxState == 0 && d->needsBBP)
2679 goto bad_dirty;
sewardj17442fe2004-09-20 14:54:28 +00002680 for (i = 0; i < d->nFxState; i++) {
2681 if (d->fxState[i].fx == Ifx_None) goto bad_dirty;
2682 if (d->fxState[i].size <= 0) goto bad_dirty;
2683 }
2684 /* check types, minimally */
sewardjb8385d82004-11-02 01:34:15 +00002685 if (d->guard == NULL) goto bad_dirty;
sewardj49bfe672004-11-15 15:46:26 +00002686 tcExpr( bb, stmt, d->guard, gWordTy );
sewardjba999312004-11-15 15:21:17 +00002687 if (typeOfIRExpr(tyenv, d->guard) != Ity_I1)
2688 sanityCheckFail(bb,stmt,"IRStmt.Dirty.guard not :: Ity_I1");
sewardj92d168d2004-11-15 14:22:12 +00002689 if (d->tmp != IRTemp_INVALID
sewardjba999312004-11-15 15:21:17 +00002690 && typeOfIRTemp(tyenv, d->tmp) == Ity_I1)
2691 sanityCheckFail(bb,stmt,"IRStmt.Dirty.dst :: Ity_I1");
sewardj17442fe2004-09-20 14:54:28 +00002692 for (i = 0; d->args[i] != NULL; i++) {
sewardj43c56462004-11-06 12:17:57 +00002693 if (i >= 32)
2694 sanityCheckFail(bb,stmt,"IRStmt.Dirty: > 32 args");
sewardjba999312004-11-15 15:21:17 +00002695 if (typeOfIRExpr(tyenv, d->args[i]) == Ity_I1)
2696 sanityCheckFail(bb,stmt,"IRStmt.Dirty.arg[i] :: Ity_I1");
sewardj17442fe2004-09-20 14:54:28 +00002697 }
2698 break;
2699 bad_dirty:
2700 sanityCheckFail(bb,stmt,"IRStmt.Dirty: ill-formed");
sewardje9d8a262009-07-01 08:06:34 +00002701 break;
sewardjd2445f62005-03-21 00:15:53 +00002702 case Ist_NoOp:
sewardjc4356f02007-11-09 21:15:04 +00002703 break;
2704 case Ist_MBE:
2705 switch (stmt->Ist.MBE.event) {
sewardje9d8a262009-07-01 08:06:34 +00002706 case Imbe_Fence:
sewardjc4356f02007-11-09 21:15:04 +00002707 break;
2708 default: sanityCheckFail(bb,stmt,"IRStmt.MBE.event: unknown");
2709 break;
2710 }
sewardj3e838932005-01-07 12:09:15 +00002711 break;
sewardj6efd4a12004-07-15 03:54:23 +00002712 case Ist_Exit:
sewardj0276d4b2004-11-15 15:30:21 +00002713 tcExpr( bb, stmt, stmt->Ist.Exit.guard, gWordTy );
2714 if (typeOfIRExpr(tyenv,stmt->Ist.Exit.guard) != Ity_I1)
2715 sanityCheckFail(bb,stmt,"IRStmt.Exit.guard: not :: Ity_I1");
sewardj49bfe672004-11-15 15:46:26 +00002716 if (!saneIRConst(stmt->Ist.Exit.dst))
2717 sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: bad dst");
sewardj6efd4a12004-07-15 03:54:23 +00002718 if (typeOfIRConst(stmt->Ist.Exit.dst) != gWordTy)
2719 sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: not :: guest word type");
2720 break;
2721 default:
2722 vpanic("tcStmt");
2723 }
2724}
2725
sewardjdd40fdf2006-12-24 02:20:24 +00002726void sanityCheckIRSB ( IRSB* bb, HChar* caller,
sewardjb9230752004-12-29 19:25:06 +00002727 Bool require_flat, IRType guest_word_size )
sewardj35439212004-07-14 22:36:10 +00002728{
2729 Int i;
2730 IRStmt* stmt;
2731 Int n_temps = bb->tyenv->types_used;
2732 Int* def_counts = LibVEX_Alloc(n_temps * sizeof(Int));
2733
sewardjb9230752004-12-29 19:25:06 +00002734 if (0)
2735 vex_printf("sanityCheck: %s\n", caller);
2736
sewardj35439212004-07-14 22:36:10 +00002737 vassert(guest_word_size == Ity_I32
sewardj695cff92004-10-13 14:50:14 +00002738 || guest_word_size == Ity_I64);
sewardj35439212004-07-14 22:36:10 +00002739
sewardjd7cb8532004-08-17 23:59:23 +00002740 if (bb->stmts_used < 0 || bb->stmts_size < 8
2741 || bb->stmts_used > bb->stmts_size)
2742 /* this BB is so strange we can't even print it */
sewardjdd40fdf2006-12-24 02:20:24 +00002743 vpanic("sanityCheckIRSB: stmts array limits wierd");
sewardjd7cb8532004-08-17 23:59:23 +00002744
sewardj6d2638e2004-07-15 09:38:27 +00002745 /* Ensure each temp has a plausible type. */
2746 for (i = 0; i < n_temps; i++) {
sewardj17442fe2004-09-20 14:54:28 +00002747 IRType ty = typeOfIRTemp(bb->tyenv,(IRTemp)i);
sewardj496a58d2005-03-20 18:44:44 +00002748 if (!isPlausibleIRType(ty)) {
sewardj6d2638e2004-07-15 09:38:27 +00002749 vex_printf("Temp t%d declared with implausible type 0x%x\n",
2750 i, (UInt)ty);
2751 sanityCheckFail(bb,NULL,"Temp declared with implausible type");
2752 }
2753 }
sewardj35439212004-07-14 22:36:10 +00002754
sewardjb9230752004-12-29 19:25:06 +00002755 /* Check for flatness, if required. */
2756 if (require_flat) {
2757 for (i = 0; i < bb->stmts_used; i++) {
2758 stmt = bb->stmts[i];
2759 if (!stmt)
sewardjd2445f62005-03-21 00:15:53 +00002760 sanityCheckFail(bb, stmt, "IRStmt: is NULL");
sewardjb9230752004-12-29 19:25:06 +00002761 if (!isFlatIRStmt(stmt))
2762 sanityCheckFail(bb, stmt, "IRStmt: is not flat");
2763 }
sewardj496a58d2005-03-20 18:44:44 +00002764 if (!isIRAtom(bb->next))
sewardjb9230752004-12-29 19:25:06 +00002765 sanityCheckFail(bb, NULL, "bb->next is not an atom");
2766 }
2767
sewardj35439212004-07-14 22:36:10 +00002768 /* Count the defs of each temp. Only one def is allowed.
2769 Also, check that each used temp has already been defd. */
sewardj6d2638e2004-07-15 09:38:27 +00002770
2771 for (i = 0; i < n_temps; i++)
2772 def_counts[i] = 0;
2773
sewardjd7cb8532004-08-17 23:59:23 +00002774 for (i = 0; i < bb->stmts_used; i++) {
sewardje9d8a262009-07-01 08:06:34 +00002775 IRDirty* d;
2776 IRCAS* cas;
sewardjd7cb8532004-08-17 23:59:23 +00002777 stmt = bb->stmts[i];
sewardje9d8a262009-07-01 08:06:34 +00002778 /* Check any temps used by this statement. */
sewardj35439212004-07-14 22:36:10 +00002779 useBeforeDef_Stmt(bb,stmt,def_counts);
sewardj17442fe2004-09-20 14:54:28 +00002780
sewardje9d8a262009-07-01 08:06:34 +00002781 /* Now make note of any temps defd by this statement. */
2782 switch (stmt->tag) {
2783 case Ist_WrTmp:
sewardjdd40fdf2006-12-24 02:20:24 +00002784 if (stmt->Ist.WrTmp.tmp < 0 || stmt->Ist.WrTmp.tmp >= n_temps)
sewardj17442fe2004-09-20 14:54:28 +00002785 sanityCheckFail(bb, stmt,
2786 "IRStmt.Tmp: destination tmp is out of range");
sewardjdd40fdf2006-12-24 02:20:24 +00002787 def_counts[stmt->Ist.WrTmp.tmp]++;
2788 if (def_counts[stmt->Ist.WrTmp.tmp] > 1)
sewardj17442fe2004-09-20 14:54:28 +00002789 sanityCheckFail(bb, stmt,
sewardjcf787902004-11-03 09:08:33 +00002790 "IRStmt.Tmp: destination tmp is assigned more than once");
sewardje9d8a262009-07-01 08:06:34 +00002791 break;
2792 case Ist_Store:
2793 if (stmt->Ist.Store.resSC != IRTemp_INVALID) {
2794 IRTemp resSC = stmt->Ist.Store.resSC;
2795 if (resSC < 0 || resSC >= n_temps)
2796 sanityCheckFail(bb, stmt,
2797 "IRStmt.Store.resSC: destination tmp is out of range");
2798 def_counts[resSC]++;
2799 if (def_counts[resSC] > 1)
2800 sanityCheckFail(bb, stmt,
2801 "IRStmt.Store.resSC: destination tmp "
2802 "is assigned more than once");
2803 }
2804 break;
2805 case Ist_Dirty:
2806 if (stmt->Ist.Dirty.details->tmp != IRTemp_INVALID) {
2807 d = stmt->Ist.Dirty.details;
2808 if (d->tmp < 0 || d->tmp >= n_temps)
2809 sanityCheckFail(bb, stmt,
2810 "IRStmt.Dirty: destination tmp is out of range");
2811 def_counts[d->tmp]++;
2812 if (def_counts[d->tmp] > 1)
2813 sanityCheckFail(bb, stmt,
2814 "IRStmt.Dirty: destination tmp is assigned more than once");
2815 }
2816 break;
2817 case Ist_CAS:
2818 cas = stmt->Ist.CAS.details;
2819
2820 if (cas->oldHi != IRTemp_INVALID) {
2821 if (cas->oldHi < 0 || cas->oldHi >= n_temps)
2822 sanityCheckFail(bb, stmt,
2823 "IRStmt.CAS: destination tmpHi is out of range");
2824 def_counts[cas->oldHi]++;
2825 if (def_counts[cas->oldHi] > 1)
2826 sanityCheckFail(bb, stmt,
2827 "IRStmt.CAS: destination tmpHi is assigned more than once");
2828 }
2829 if (cas->oldLo < 0 || cas->oldLo >= n_temps)
2830 sanityCheckFail(bb, stmt,
2831 "IRStmt.CAS: destination tmpLo is out of range");
2832 def_counts[cas->oldLo]++;
2833 if (def_counts[cas->oldLo] > 1)
2834 sanityCheckFail(bb, stmt,
2835 "IRStmt.CAS: destination tmpLo is assigned more than once");
2836 break;
2837 default:
2838 /* explicitly handle the rest, so as to keep gcc quiet */
2839 break;
sewardj35439212004-07-14 22:36:10 +00002840 }
2841 }
2842
sewardj6efd4a12004-07-15 03:54:23 +00002843 /* Typecheck everything. */
sewardjd7cb8532004-08-17 23:59:23 +00002844 for (i = 0; i < bb->stmts_used; i++)
sewardj39e3f242004-08-18 16:54:52 +00002845 if (bb->stmts[i])
2846 tcStmt( bb, bb->stmts[i], guest_word_size );
sewardj6efd4a12004-07-15 03:54:23 +00002847 if (typeOfIRExpr(bb->tyenv,bb->next) != guest_word_size)
2848 sanityCheckFail(bb, NULL, "bb->next field has wrong type");
sewardje539a402004-07-14 18:24:17 +00002849}
2850
sewardj4345f7a2004-09-22 19:49:27 +00002851/*---------------------------------------------------------------*/
2852/*--- Misc helper functions ---*/
2853/*---------------------------------------------------------------*/
2854
2855Bool eqIRConst ( IRConst* c1, IRConst* c2 )
2856{
2857 if (c1->tag != c2->tag)
2858 return False;
2859
2860 switch (c1->tag) {
sewardja98bf492005-02-07 01:39:17 +00002861 case Ico_U1: return toBool( (1 & c1->Ico.U1) == (1 & c2->Ico.U1) );
2862 case Ico_U8: return toBool( c1->Ico.U8 == c2->Ico.U8 );
2863 case Ico_U16: return toBool( c1->Ico.U16 == c2->Ico.U16 );
2864 case Ico_U32: return toBool( c1->Ico.U32 == c2->Ico.U32 );
2865 case Ico_U64: return toBool( c1->Ico.U64 == c2->Ico.U64 );
2866 case Ico_F64: return toBool( c1->Ico.F64 == c2->Ico.F64 );
sewardj0da5eb82007-01-27 00:46:28 +00002867 case Ico_F64i: return toBool( c1->Ico.F64i == c2->Ico.F64i );
2868 case Ico_V128: return toBool( c1->Ico.V128 == c2->Ico.V128 );
sewardj4345f7a2004-09-22 19:49:27 +00002869 default: vpanic("eqIRConst");
2870 }
2871}
2872
sewardjdd40fdf2006-12-24 02:20:24 +00002873Bool eqIRRegArray ( IRRegArray* descr1, IRRegArray* descr2 )
sewardje98dcf22004-10-04 09:15:11 +00002874{
sewardja98bf492005-02-07 01:39:17 +00002875 return toBool( descr1->base == descr2->base
2876 && descr1->elemTy == descr2->elemTy
2877 && descr1->nElems == descr2->nElems );
sewardje98dcf22004-10-04 09:15:11 +00002878}
2879
sewardj2d3f77c2004-09-22 23:49:09 +00002880Int sizeofIRType ( IRType ty )
2881{
2882 switch (ty) {
sewardjc9a43662004-11-30 18:51:59 +00002883 case Ity_I8: return 1;
2884 case Ity_I16: return 2;
2885 case Ity_I32: return 4;
2886 case Ity_I64: return 8;
2887 case Ity_F32: return 4;
2888 case Ity_F64: return 8;
2889 case Ity_V128: return 16;
sewardj2d3f77c2004-09-22 23:49:09 +00002890 default: vex_printf("\n"); ppIRType(ty); vex_printf("\n");
2891 vpanic("sizeofIRType");
2892 }
2893}
2894
sewardj49651f42004-10-28 22:11:04 +00002895IRExpr* mkIRExpr_HWord ( HWord hw )
2896{
sewardjf9655262004-10-31 20:02:16 +00002897 vassert(sizeof(void*) == sizeof(HWord));
sewardj49651f42004-10-28 22:11:04 +00002898 if (sizeof(HWord) == 4)
2899 return IRExpr_Const(IRConst_U32((UInt)hw));
2900 if (sizeof(HWord) == 8)
sewardjf9655262004-10-31 20:02:16 +00002901 return IRExpr_Const(IRConst_U64((ULong)hw));
sewardj49651f42004-10-28 22:11:04 +00002902 vpanic("mkIRExpr_HWord");
2903}
sewardj6efd4a12004-07-15 03:54:23 +00002904
sewardj2d49b432005-02-01 00:37:06 +00002905IRDirty* unsafeIRDirty_0_N ( Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002906 IRExpr** args )
2907{
2908 IRDirty* d = emptyIRDirty();
sewardjb8385d82004-11-02 01:34:15 +00002909 d->cee = mkIRCallee ( regparms, name, addr );
sewardjba999312004-11-15 15:21:17 +00002910 d->guard = IRExpr_Const(IRConst_U1(True));
sewardjb8385d82004-11-02 01:34:15 +00002911 d->args = args;
sewardjf9655262004-10-31 20:02:16 +00002912 return d;
2913}
2914
2915IRDirty* unsafeIRDirty_1_N ( IRTemp dst,
sewardj2d49b432005-02-01 00:37:06 +00002916 Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002917 IRExpr** args )
2918{
2919 IRDirty* d = emptyIRDirty();
sewardjb8385d82004-11-02 01:34:15 +00002920 d->cee = mkIRCallee ( regparms, name, addr );
sewardjba999312004-11-15 15:21:17 +00002921 d->guard = IRExpr_Const(IRConst_U1(True));
sewardjb8385d82004-11-02 01:34:15 +00002922 d->args = args;
2923 d->tmp = dst;
sewardjf9655262004-10-31 20:02:16 +00002924 return d;
2925}
2926
2927IRExpr* mkIRExprCCall ( IRType retty,
sewardj2d49b432005-02-01 00:37:06 +00002928 Int regparms, HChar* name, void* addr,
sewardjf9655262004-10-31 20:02:16 +00002929 IRExpr** args )
2930{
2931 return IRExpr_CCall ( mkIRCallee ( regparms, name, addr ),
2932 retty, args );
2933}
2934
sewardj496a58d2005-03-20 18:44:44 +00002935Bool eqIRAtom ( IRExpr* a1, IRExpr* a2 )
2936{
2937 vassert(isIRAtom(a1));
2938 vassert(isIRAtom(a2));
sewardjdd40fdf2006-12-24 02:20:24 +00002939 if (a1->tag == Iex_RdTmp && a2->tag == Iex_RdTmp)
2940 return toBool(a1->Iex.RdTmp.tmp == a2->Iex.RdTmp.tmp);
sewardj496a58d2005-03-20 18:44:44 +00002941 if (a1->tag == Iex_Const && a2->tag == Iex_Const)
2942 return eqIRConst(a1->Iex.Const.con, a2->Iex.Const.con);
2943 return False;
2944}
2945
sewardje539a402004-07-14 18:24:17 +00002946/*---------------------------------------------------------------*/
sewardjcef7d3e2009-07-02 12:21:59 +00002947/*--- end ir_defs.c ---*/
sewardj887a11a2004-07-05 17:26:47 +00002948/*---------------------------------------------------------------*/