sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
sewardj | c0ee2ed | 2004-07-27 10:29:41 +0000 | [diff] [blame] | 4 | /*--- This file (ir/irdefs.c) is ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 5 | /*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/ |
| 6 | /*--- ---*/ |
| 7 | /*---------------------------------------------------------------*/ |
| 8 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
| 13 | Copyright (C) 2004 OpenWorks, LLP. |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or modify |
| 16 | it under the terms of the GNU General Public License as published by |
| 17 | the Free Software Foundation; Version 2 dated June 1991 of the |
| 18 | license. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or liability |
| 23 | for damages. See the GNU General Public License for more details. |
| 24 | |
| 25 | Neither the names of the U.S. Department of Energy nor the |
| 26 | University of California nor the names of its contributors may be |
| 27 | used to endorse or promote products derived from this software |
| 28 | without prior written permission. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | along with this program; if not, write to the Free Software |
| 32 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 33 | USA. |
| 34 | */ |
| 35 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 36 | #include "libvex_basictypes.h" |
| 37 | #include "libvex_ir.h" |
| 38 | #include "libvex.h" |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 39 | |
sewardj | c0ee2ed | 2004-07-27 10:29:41 +0000 | [diff] [blame] | 40 | #include "main/vex_util.h" |
| 41 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 42 | |
| 43 | /*---------------------------------------------------------------*/ |
| 44 | /*--- Printing the IR ---*/ |
| 45 | /*---------------------------------------------------------------*/ |
| 46 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 47 | void ppIRType ( IRType ty ) |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 48 | { |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 49 | switch (ty) { |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 50 | case Ity_INVALID: vex_printf("Ity_INVALID"); break; |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 51 | case Ity_I1: vex_printf( "I1"); break; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 52 | case Ity_I8: vex_printf( "I8"); break; |
| 53 | case Ity_I16: vex_printf( "I16"); break; |
| 54 | case Ity_I32: vex_printf( "I32"); break; |
| 55 | case Ity_I64: vex_printf( "I64"); break; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 56 | case Ity_F32: vex_printf( "F32"); break; |
| 57 | case Ity_F64: vex_printf( "F64"); break; |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 58 | case Ity_V128: vex_printf( "V128"); break; |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 59 | default: vex_printf("ty = 0x%x\n", (Int)ty); |
| 60 | vpanic("ppIRType"); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 64 | void ppIRConst ( IRConst* con ) |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 65 | { |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 66 | switch (con->tag) { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 67 | case Ico_U1: vex_printf( "%d:I1", con->Ico.U1 ? 1 : 0); break; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 68 | case Ico_U8: vex_printf( "0x%x:I8", (UInt)(con->Ico.U8)); break; |
| 69 | case Ico_U16: vex_printf( "0x%x:I16", (UInt)(con->Ico.U16)); break; |
| 70 | case Ico_U32: vex_printf( "0x%x:I32", (UInt)(con->Ico.U32)); break; |
| 71 | case Ico_U64: vex_printf( "0x%llx:I64", (ULong)(con->Ico.U64)); break; |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 72 | case Ico_F64: vex_printf( "F64{0x%llx}", *(ULong*)(&con->Ico.F64)); |
| 73 | break; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 74 | case Ico_F64i: vex_printf( "F64i{0x%llx}", con->Ico.F64i); break; |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 75 | case Ico_V128: vex_printf( "V128{0x%04x}", (UInt)(con->Ico.V128)); break; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 76 | default: vpanic("ppIRConst"); |
| 77 | } |
| 78 | } |
| 79 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 80 | void ppIRCallee ( IRCallee* ce ) |
| 81 | { |
| 82 | vex_printf("%s", ce->name); |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 83 | if (ce->regparms > 0) |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 84 | vex_printf("[rp=%d]", ce->regparms); |
| 85 | if (ce->mcx_mask > 0) |
| 86 | vex_printf("[mcx=0x%x]", ce->mcx_mask); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 87 | vex_printf("{%p}", (void*)ce->addr); |
| 88 | } |
| 89 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 90 | void ppIRArray ( IRArray* arr ) |
| 91 | { |
sewardj | 0bfea7f | 2004-10-04 07:15:48 +0000 | [diff] [blame] | 92 | vex_printf("(%d:%dx", arr->base, arr->nElems); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 93 | ppIRType(arr->elemTy); |
sewardj | 0bfea7f | 2004-10-04 07:15:48 +0000 | [diff] [blame] | 94 | vex_printf(")"); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 95 | } |
| 96 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 97 | void ppIRTemp ( IRTemp tmp ) |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 98 | { |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 99 | if (tmp == IRTemp_INVALID) |
| 100 | vex_printf("IRTemp_INVALID"); |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 101 | else |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 102 | vex_printf( "t%d", (Int)tmp); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 103 | } |
| 104 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 105 | void ppIROp ( IROp op ) |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 106 | { |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 107 | Char* str; |
| 108 | IROp base; |
| 109 | switch (op) { |
| 110 | case Iop_Add8 ... Iop_Add64: |
| 111 | str = "Add"; base = Iop_Add8; break; |
| 112 | case Iop_Sub8 ... Iop_Sub64: |
| 113 | str = "Sub"; base = Iop_Sub8; break; |
| 114 | case Iop_Mul8 ... Iop_Mul64: |
| 115 | str = "Mul"; base = Iop_Mul8; break; |
| 116 | case Iop_Or8 ... Iop_Or64: |
| 117 | str = "Or"; base = Iop_Or8; break; |
| 118 | case Iop_And8 ... Iop_And64: |
| 119 | str = "And"; base = Iop_And8; break; |
| 120 | case Iop_Xor8 ... Iop_Xor64: |
| 121 | str = "Xor"; base = Iop_Xor8; break; |
| 122 | case Iop_Shl8 ... Iop_Shl64: |
| 123 | str = "Shl"; base = Iop_Shl8; break; |
| 124 | case Iop_Shr8 ... Iop_Shr64: |
| 125 | str = "Shr"; base = Iop_Shr8; break; |
| 126 | case Iop_Sar8 ... Iop_Sar64: |
| 127 | str = "Sar"; base = Iop_Sar8; break; |
sewardj | e90ad6a | 2004-07-10 19:02:10 +0000 | [diff] [blame] | 128 | case Iop_CmpEQ8 ... Iop_CmpEQ64: |
| 129 | str = "CmpEQ"; base = Iop_CmpEQ8; break; |
| 130 | case Iop_CmpNE8 ... Iop_CmpNE64: |
| 131 | str = "CmpNE"; base = Iop_CmpNE8; break; |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 132 | case Iop_Not8 ... Iop_Not64: |
| 133 | str = "Not"; base = Iop_Not8; break; |
| 134 | /* other cases must explicitly "return;" */ |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 135 | case Iop_8Uto16: vex_printf("8Uto16"); return; |
| 136 | case Iop_8Uto32: vex_printf("8Uto32"); return; |
| 137 | case Iop_16Uto32: vex_printf("16Uto32"); return; |
| 138 | case Iop_8Sto16: vex_printf("8Sto16"); return; |
| 139 | case Iop_8Sto32: vex_printf("8Sto32"); return; |
| 140 | case Iop_16Sto32: vex_printf("16Sto32"); return; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 141 | case Iop_32Sto64: vex_printf("32Sto64"); return; |
sewardj | e5427e8 | 2004-09-11 19:43:51 +0000 | [diff] [blame] | 142 | case Iop_32Uto64: vex_printf("32Uto64"); return; |
sewardj | a238471 | 2004-07-29 14:36:40 +0000 | [diff] [blame] | 143 | case Iop_32to8: vex_printf("32to8"); return; |
sewardj | 6e797c5 | 2004-10-13 15:20:17 +0000 | [diff] [blame] | 144 | |
| 145 | case Iop_Not1: vex_printf("Not1"); return; |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 146 | case Iop_32to1: vex_printf("32to1"); return; |
| 147 | case Iop_1Uto8: vex_printf("1Uto8"); return; |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 148 | case Iop_1Uto32: vex_printf("1Uto32"); return; |
sewardj | fd33277 | 2004-11-09 16:01:40 +0000 | [diff] [blame] | 149 | case Iop_1Sto8: vex_printf("1Sto8"); return; |
sewardj | 8eda630 | 2004-11-05 01:55:46 +0000 | [diff] [blame] | 150 | case Iop_1Sto16: vex_printf("1Sto16"); return; |
sewardj | 415d935 | 2004-11-04 15:20:15 +0000 | [diff] [blame] | 151 | case Iop_1Sto32: vex_printf("1Sto32"); return; |
sewardj | b5874aa | 2004-11-04 16:57:50 +0000 | [diff] [blame] | 152 | case Iop_1Sto64: vex_printf("1Sto64"); return; |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 153 | |
| 154 | case Iop_MullS8: vex_printf("MullS8"); return; |
| 155 | case Iop_MullS16: vex_printf("MullS16"); return; |
| 156 | case Iop_MullS32: vex_printf("MullS32"); return; |
| 157 | case Iop_MullU8: vex_printf("MullU8"); return; |
| 158 | case Iop_MullU16: vex_printf("MullU16"); return; |
| 159 | case Iop_MullU32: vex_printf("MullU32"); return; |
| 160 | |
sewardj | ce646f2 | 2004-08-31 23:55:54 +0000 | [diff] [blame] | 161 | case Iop_Clz32: vex_printf("Clz32"); return; |
| 162 | case Iop_Ctz32: vex_printf("Ctz32"); return; |
| 163 | |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 164 | case Iop_CmpLT32S: vex_printf("CmpLT32S"); return; |
| 165 | case Iop_CmpLE32S: vex_printf("CmpLE32S"); return; |
| 166 | case Iop_CmpLT32U: vex_printf("CmpLT32U"); return; |
| 167 | case Iop_CmpLE32U: vex_printf("CmpLE32U"); return; |
| 168 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 169 | case Iop_DivModU64to32: vex_printf("DivModU64to32"); return; |
| 170 | case Iop_DivModS64to32: vex_printf("DivModS64to32"); return; |
| 171 | |
sewardj | b81f8b3 | 2004-07-30 10:17:50 +0000 | [diff] [blame] | 172 | case Iop_16HIto8: vex_printf("16HIto8"); return; |
| 173 | case Iop_16to8: vex_printf("16to8"); return; |
| 174 | case Iop_8HLto16: vex_printf("8HLto16"); return; |
| 175 | |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 176 | case Iop_32HIto16: vex_printf("32HIto16"); return; |
| 177 | case Iop_32to16: vex_printf("32to16"); return; |
| 178 | case Iop_16HLto32: vex_printf("16HLto32"); return; |
| 179 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 180 | case Iop_64HIto32: vex_printf("64HIto32"); return; |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 181 | case Iop_64to32: vex_printf("64to32"); return; |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 182 | case Iop_32HLto64: vex_printf("32HLto64"); return; |
| 183 | |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 184 | case Iop_AddF64: vex_printf("AddF64"); return; |
| 185 | case Iop_SubF64: vex_printf("SubF64"); return; |
| 186 | case Iop_MulF64: vex_printf("MulF64"); return; |
| 187 | case Iop_DivF64: vex_printf("DivF64"); return; |
sewardj | 46de407 | 2004-09-11 19:23:24 +0000 | [diff] [blame] | 188 | |
sewardj | 442d0be | 2004-10-15 22:57:13 +0000 | [diff] [blame] | 189 | case Iop_ScaleF64: vex_printf("ScaleF64"); return; |
| 190 | case Iop_AtanF64: vex_printf("AtanF64"); return; |
| 191 | case Iop_Yl2xF64: vex_printf("Yl2xF64"); return; |
| 192 | case Iop_Yl2xp1F64: vex_printf("Yl2xp1F64"); return; |
| 193 | case Iop_PRemF64: vex_printf("PRemF64"); return; |
| 194 | case Iop_PRemC3210F64: vex_printf("PRemC3210F64"); return; |
| 195 | case Iop_PRem1F64: vex_printf("PRem1F64"); return; |
| 196 | case Iop_PRem1C3210F64: vex_printf("PRem1C3210F64"); return; |
| 197 | case Iop_NegF64: vex_printf("NegF64"); return; |
| 198 | case Iop_SqrtF64: vex_printf("SqrtF64"); return; |
sewardj | 46de407 | 2004-09-11 19:23:24 +0000 | [diff] [blame] | 199 | |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 200 | case Iop_AbsF64: vex_printf("AbsF64"); return; |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 201 | case Iop_SinF64: vex_printf("SinF64"); return; |
| 202 | case Iop_CosF64: vex_printf("CosF64"); return; |
sewardj | 99016a7 | 2004-10-15 22:09:17 +0000 | [diff] [blame] | 203 | case Iop_TanF64: vex_printf("TanF64"); return; |
sewardj | 06c32a0 | 2004-09-12 12:07:34 +0000 | [diff] [blame] | 204 | case Iop_2xm1F64: vex_printf("2xm1F64"); return; |
sewardj | bdc7d21 | 2004-09-09 02:46:40 +0000 | [diff] [blame] | 205 | |
sewardj | 46de407 | 2004-09-11 19:23:24 +0000 | [diff] [blame] | 206 | case Iop_CmpF64: vex_printf("CmpF64"); return; |
| 207 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 208 | case Iop_F64toI16: vex_printf("F64toI16"); return; |
| 209 | case Iop_F64toI32: vex_printf("F64toI32"); return; |
| 210 | case Iop_F64toI64: vex_printf("F64toI64"); return; |
| 211 | |
| 212 | case Iop_I16toF64: vex_printf("I16toF64"); return; |
sewardj | 89cd093 | 2004-09-08 18:23:25 +0000 | [diff] [blame] | 213 | case Iop_I32toF64: vex_printf("I32toF64"); return; |
sewardj | bdc7d21 | 2004-09-09 02:46:40 +0000 | [diff] [blame] | 214 | case Iop_I64toF64: vex_printf("I64toF64"); return; |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 215 | |
sewardj | 89cd093 | 2004-09-08 18:23:25 +0000 | [diff] [blame] | 216 | case Iop_F32toF64: vex_printf("F32toF64"); return; |
| 217 | case Iop_F64toF32: vex_printf("F64toF32"); return; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 218 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 219 | case Iop_RoundF64: vex_printf("RoundF64"); return; |
| 220 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 221 | case Iop_ReinterpF64asI64: vex_printf("ReinterpF64asI64"); return; |
| 222 | case Iop_ReinterpI64asF64: vex_printf("ReinterpI64asF64"); return; |
sewardj | fd22645 | 2004-12-07 19:02:18 +0000 | [diff] [blame] | 223 | case Iop_ReinterpF32asI32: vex_printf("ReinterpF32asI32"); return; |
| 224 | case Iop_ReinterpI32asF32: vex_printf("ReinterpI32asF32"); return; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 225 | |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 226 | case Iop_Add32Fx4: vex_printf("Add32Fx4"); return; |
| 227 | case Iop_Add32F0x4: vex_printf("Add32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 228 | case Iop_Add64Fx2: vex_printf("Add64Fx2"); return; |
| 229 | case Iop_Add64F0x2: vex_printf("Add64F0x2"); return; |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 230 | |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 231 | case Iop_Div32Fx4: vex_printf("Div32Fx4"); return; |
| 232 | case Iop_Div32F0x4: vex_printf("Div32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 233 | case Iop_Div64Fx2: vex_printf("Div64Fx2"); return; |
| 234 | case Iop_Div64F0x2: vex_printf("Div64F0x2"); return; |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 235 | |
| 236 | case Iop_Max32Fx4: vex_printf("Max32Fx4"); return; |
| 237 | case Iop_Max32F0x4: vex_printf("Max32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 238 | case Iop_Max64Fx2: vex_printf("Max64Fx2"); return; |
| 239 | case Iop_Max64F0x2: vex_printf("Max64F0x2"); return; |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 240 | |
| 241 | case Iop_Min32Fx4: vex_printf("Min32Fx4"); return; |
| 242 | case Iop_Min32F0x4: vex_printf("Min32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 243 | case Iop_Min64Fx2: vex_printf("Min64Fx2"); return; |
| 244 | case Iop_Min64F0x2: vex_printf("Min64F0x2"); return; |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 245 | |
sewardj | 9636b44 | 2004-12-04 01:38:37 +0000 | [diff] [blame] | 246 | case Iop_Mul32Fx4: vex_printf("Mul32Fx4"); return; |
| 247 | case Iop_Mul32F0x4: vex_printf("Mul32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 248 | case Iop_Mul64Fx2: vex_printf("Mul64Fx2"); return; |
| 249 | case Iop_Mul64F0x2: vex_printf("Mul64F0x2"); return; |
sewardj | 9636b44 | 2004-12-04 01:38:37 +0000 | [diff] [blame] | 250 | |
sewardj | 0bd7ce6 | 2004-12-05 02:47:40 +0000 | [diff] [blame] | 251 | case Iop_Recip32Fx4: vex_printf("Recip32Fx4"); return; |
| 252 | case Iop_Recip32F0x4: vex_printf("Recip32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 253 | case Iop_Recip64Fx2: vex_printf("Recip64Fx2"); return; |
| 254 | case Iop_Recip64F0x2: vex_printf("Recip64F0x2"); return; |
sewardj | 0bd7ce6 | 2004-12-05 02:47:40 +0000 | [diff] [blame] | 255 | |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 256 | case Iop_RSqrt32Fx4: vex_printf("RSqrt32Fx4"); return; |
| 257 | case Iop_RSqrt32F0x4: vex_printf("RSqrt32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 258 | case Iop_RSqrt64Fx2: vex_printf("RSqrt64Fx2"); return; |
| 259 | case Iop_RSqrt64F0x2: vex_printf("RSqrt64F0x2"); return; |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 260 | |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 261 | case Iop_Sqrt32Fx4: vex_printf("Sqrt32Fx4"); return; |
| 262 | case Iop_Sqrt32F0x4: vex_printf("Sqrt32F0x4"); return; |
| 263 | case Iop_Sqrt64Fx2: vex_printf("Sqrt64Fx2"); return; |
| 264 | case Iop_Sqrt64F0x2: vex_printf("Sqrt64F0x2"); return; |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 265 | |
| 266 | case Iop_Sub32Fx4: vex_printf("Sub32Fx4"); return; |
| 267 | case Iop_Sub32F0x4: vex_printf("Sub32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 268 | case Iop_Sub64Fx2: vex_printf("Sub64Fx2"); return; |
| 269 | case Iop_Sub64F0x2: vex_printf("Sub64F0x2"); return; |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 270 | |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 271 | case Iop_CmpEQ32Fx4: vex_printf("CmpEQ32Fx4"); return; |
| 272 | case Iop_CmpLT32Fx4: vex_printf("CmpLT32Fx4"); return; |
| 273 | case Iop_CmpLE32Fx4: vex_printf("CmpLE32Fx4"); return; |
| 274 | case Iop_CmpUN32Fx4: vex_printf("CmpUN32Fx4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 275 | case Iop_CmpEQ64Fx2: vex_printf("CmpEQ64Fx2"); return; |
| 276 | case Iop_CmpLT64Fx2: vex_printf("CmpLT64Fx2"); return; |
| 277 | case Iop_CmpLE64Fx2: vex_printf("CmpLE64Fx2"); return; |
| 278 | case Iop_CmpUN64Fx2: vex_printf("CmpUN64Fx2"); return; |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 279 | |
| 280 | case Iop_CmpEQ32F0x4: vex_printf("CmpEQ32F0x4"); return; |
| 281 | case Iop_CmpLT32F0x4: vex_printf("CmpLT32F0x4"); return; |
| 282 | case Iop_CmpLE32F0x4: vex_printf("CmpLE32F0x4"); return; |
| 283 | case Iop_CmpUN32F0x4: vex_printf("CmpUN32F0x4"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 284 | case Iop_CmpEQ64F0x2: vex_printf("CmpEQ64F0x2"); return; |
| 285 | case Iop_CmpLT64F0x2: vex_printf("CmpLT64F0x2"); return; |
| 286 | case Iop_CmpLE64F0x2: vex_printf("CmpLE64F0x2"); return; |
| 287 | case Iop_CmpUN64F0x2: vex_printf("CmpUN64F0x2"); return; |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 288 | |
| 289 | case Iop_64HLto128: vex_printf("64HLto128"); return; |
| 290 | case Iop_128to64: vex_printf("128to64"); return; |
| 291 | case Iop_128HIto64: vex_printf("128HIto64"); return; |
| 292 | |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 293 | case Iop_32Uto128: vex_printf("32Uto128"); return; |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 294 | case Iop_64Uto128: vex_printf("64Uto128"); return; |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 295 | case Iop_Set128lo32: vex_printf("Set128lo32"); return; |
sewardj | 008754b | 2004-12-08 14:37:10 +0000 | [diff] [blame] | 296 | case Iop_Set128lo64: vex_printf("Set128lo64"); return; |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 297 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame^] | 298 | case Iop_And128: vex_printf("And128"); return; |
| 299 | case Iop_Or128: vex_printf("Or128"); return; |
| 300 | case Iop_Xor128: vex_printf("Xor128"); return; |
| 301 | |
| 302 | case Iop_Add8x16: vex_printf("Add8x16"); return; |
| 303 | case Iop_Add16x8: vex_printf("Add16x8"); return; |
| 304 | case Iop_Add32x4: vex_printf("Add32x4"); return; |
| 305 | case Iop_Add64x2: vex_printf("Add64x2"); return; |
| 306 | case Iop_QAdd8Ux16: vex_printf("QAdd8Ux16"); return; |
| 307 | case Iop_QAdd16Ux8: vex_printf("QAdd16Ux8"); return; |
| 308 | case Iop_QAdd8Sx16: vex_printf("QAdd8Sx16"); return; |
| 309 | case Iop_QAdd16Sx8: vex_printf("QAdd16Sx8"); return; |
| 310 | |
| 311 | case Iop_Sub8x16: vex_printf("Sub8x16"); return; |
| 312 | case Iop_Sub16x8: vex_printf("Sub16x8"); return; |
| 313 | case Iop_Sub32x4: vex_printf("Sub32x4"); return; |
| 314 | case Iop_Sub64x2: vex_printf("Sub64x2"); return; |
| 315 | case Iop_QSub8Ux16: vex_printf("QSub8Ux16"); return; |
| 316 | case Iop_QSub16Ux8: vex_printf("QSub16Ux8"); return; |
| 317 | case Iop_QSub8Sx16: vex_printf("QSub8Sx16"); return; |
| 318 | case Iop_QSub16Sx8: vex_printf("QSub16Sx8"); return; |
| 319 | |
| 320 | case Iop_Mul16x8: vex_printf("Mul16x8"); return; |
| 321 | case Iop_MulHi16Ux8: vex_printf("MulHi16Ux8"); return; |
| 322 | case Iop_MulHi16Sx8: vex_printf("MulHi16Sx8"); return; |
| 323 | |
| 324 | case Iop_Avg8Ux16: vex_printf("Avg8Ux16"); return; |
| 325 | case Iop_Avg16Ux8: vex_printf("Avg16Ux8"); return; |
| 326 | |
| 327 | case Iop_Max16Sx8: vex_printf("Max16Sx8"); return; |
| 328 | case Iop_Max8Ux16: vex_printf("Max8Ux16"); return; |
| 329 | case Iop_Min16Sx8: vex_printf("Min16Sx8"); return; |
| 330 | case Iop_Min8Ux16: vex_printf("Min8Ux16"); return; |
| 331 | |
| 332 | case Iop_CmpEQ8x16: vex_printf("CmpEQ8x16"); return; |
| 333 | case Iop_CmpEQ16x8: vex_printf("CmpEQ16x8"); return; |
| 334 | case Iop_CmpEQ32x4: vex_printf("CmpEQ32x4"); return; |
| 335 | case Iop_CmpGT8Sx16: vex_printf("CmpGT8Sx16"); return; |
| 336 | case Iop_CmpGT16Sx8: vex_printf("CmpGT16Sx8"); return; |
| 337 | case Iop_CmpGT32Sx4: vex_printf("CmpGT32Sx4"); return; |
| 338 | |
| 339 | case Iop_ShlN16x8: vex_printf("ShlN16x8"); return; |
| 340 | case Iop_ShlN32x4: vex_printf("ShlN32x4"); return; |
| 341 | case Iop_ShlN64x2: vex_printf("ShlN64x2"); return; |
| 342 | case Iop_ShrN16x8: vex_printf("ShrN16x8"); return; |
| 343 | case Iop_ShrN32x4: vex_printf("ShrN32x4"); return; |
| 344 | case Iop_ShrN64x2: vex_printf("ShrN64x2"); return; |
| 345 | case Iop_SarN16x8: vex_printf("SarN16x8"); return; |
| 346 | case Iop_SarN32x4: vex_printf("SarN32x4"); return; |
| 347 | |
| 348 | case Iop_QNarrow16Ux8: vex_printf("QNarrow16Ux8"); return; |
| 349 | case Iop_QNarrow16Sx8: vex_printf("QNarrow16Sx8"); return; |
| 350 | case Iop_QNarrow32Sx4: vex_printf("QNarrow32Sx4"); return; |
| 351 | |
| 352 | case Iop_InterleaveHI8x16: vex_printf("InterleaveHI8x16"); return; |
| 353 | case Iop_InterleaveHI16x8: vex_printf("InterleaveHI16x8"); return; |
| 354 | case Iop_InterleaveHI32x4: vex_printf("InterleaveHI32x4"); return; |
| 355 | case Iop_InterleaveHI64x2: vex_printf("InterleaveHI64x2"); return; |
| 356 | case Iop_InterleaveLO8x16: vex_printf("InterleaveLO8x16"); return; |
| 357 | case Iop_InterleaveLO16x8: vex_printf("InterleaveLO16x8"); return; |
| 358 | case Iop_InterleaveLO32x4: vex_printf("InterleaveLO32x4"); return; |
| 359 | case Iop_InterleaveLO64x2: vex_printf("InterleaveLO64x2"); return; |
| 360 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 361 | default: vpanic("ppIROp(1)"); |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | switch (op - base) { |
| 365 | case 0: vex_printf(str); vex_printf("8"); break; |
| 366 | case 1: vex_printf(str); vex_printf("16"); break; |
| 367 | case 2: vex_printf(str); vex_printf("32"); break; |
| 368 | case 3: vex_printf(str); vex_printf("64"); break; |
| 369 | default: vpanic("ppIROp(2)"); |
| 370 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 371 | } |
| 372 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 373 | void ppIRExpr ( IRExpr* e ) |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 374 | { |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 375 | Int i; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 376 | switch (e->tag) { |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 377 | case Iex_Binder: |
| 378 | vex_printf("BIND-%d", e->Iex.Binder.binder); |
| 379 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 380 | case Iex_Get: |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 381 | vex_printf( "GET:" ); |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 382 | ppIRType(e->Iex.Get.ty); |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 383 | vex_printf("(%d)", e->Iex.Get.offset); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 384 | break; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 385 | case Iex_GetI: |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 386 | vex_printf( "GETI" ); |
| 387 | ppIRArray(e->Iex.GetI.descr); |
| 388 | vex_printf("["); |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 389 | ppIRExpr(e->Iex.GetI.ix); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 390 | vex_printf(",%d]", e->Iex.GetI.bias); |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 391 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 392 | case Iex_Tmp: |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 393 | ppIRTemp(e->Iex.Tmp.tmp); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 394 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 395 | case Iex_Binop: |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 396 | ppIROp(e->Iex.Binop.op); |
| 397 | vex_printf( "(" ); |
| 398 | ppIRExpr(e->Iex.Binop.arg1); |
| 399 | vex_printf( "," ); |
| 400 | ppIRExpr(e->Iex.Binop.arg2); |
| 401 | vex_printf( ")" ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 402 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 403 | case Iex_Unop: |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 404 | ppIROp(e->Iex.Unop.op); |
| 405 | vex_printf( "(" ); |
| 406 | ppIRExpr(e->Iex.Unop.arg); |
| 407 | vex_printf( ")" ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 408 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 409 | case Iex_LDle: |
sewardj | e05c42c | 2004-07-08 20:25:10 +0000 | [diff] [blame] | 410 | vex_printf( "LDle:" ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 411 | ppIRType(e->Iex.LDle.ty); |
sewardj | e05c42c | 2004-07-08 20:25:10 +0000 | [diff] [blame] | 412 | vex_printf( "(" ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 413 | ppIRExpr(e->Iex.LDle.addr); |
| 414 | vex_printf( ")" ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 415 | break; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 416 | case Iex_Const: |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 417 | ppIRConst(e->Iex.Const.con); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 418 | break; |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 419 | case Iex_CCall: |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 420 | ppIRCallee(e->Iex.CCall.cee); |
| 421 | vex_printf("("); |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 422 | for (i = 0; e->Iex.CCall.args[i] != NULL; i++) { |
| 423 | ppIRExpr(e->Iex.CCall.args[i]); |
| 424 | if (e->Iex.CCall.args[i+1] != NULL) |
| 425 | vex_printf(","); |
| 426 | } |
| 427 | vex_printf("):"); |
| 428 | ppIRType(e->Iex.CCall.retty); |
| 429 | break; |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 430 | case Iex_Mux0X: |
| 431 | vex_printf("Mux0X("); |
| 432 | ppIRExpr(e->Iex.Mux0X.cond); |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 433 | vex_printf(","); |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 434 | ppIRExpr(e->Iex.Mux0X.expr0); |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 435 | vex_printf(","); |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 436 | ppIRExpr(e->Iex.Mux0X.exprX); |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 437 | vex_printf(")"); |
| 438 | break; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 439 | default: |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 440 | vpanic("ppIExpr"); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 444 | void ppIREffect ( IREffect fx ) |
| 445 | { |
| 446 | switch (fx) { |
| 447 | case Ifx_None: vex_printf("noFX"); return; |
| 448 | case Ifx_Read: vex_printf("RdFX"); return; |
| 449 | case Ifx_Write: vex_printf("WrFX"); return; |
| 450 | case Ifx_Modify: vex_printf("MoFX"); return; |
| 451 | default: vpanic("ppIREffect"); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void ppIRDirty ( IRDirty* d ) |
| 456 | { |
| 457 | Int i; |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 458 | if (d->tmp != IRTemp_INVALID) { |
sewardj | 4b861de | 2004-11-03 15:24:42 +0000 | [diff] [blame] | 459 | ppIRTemp(d->tmp); |
| 460 | vex_printf(" = "); |
| 461 | } |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 462 | vex_printf("DIRTY "); |
| 463 | ppIRExpr(d->guard); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 464 | if (d->needsBBP) |
| 465 | vex_printf(" NeedsBBP"); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 466 | if (d->mFx != Ifx_None) { |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 467 | vex_printf(" "); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 468 | ppIREffect(d->mFx); |
| 469 | vex_printf("-mem("); |
| 470 | ppIRExpr(d->mAddr); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 471 | vex_printf(",%d)", d->mSize); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 472 | } |
| 473 | for (i = 0; i < d->nFxState; i++) { |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 474 | vex_printf(" "); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 475 | ppIREffect(d->fxState[i].fx); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 476 | vex_printf("-gst(%d,%d)", d->fxState[i].offset, d->fxState[i].size); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 477 | } |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 478 | vex_printf(" ::: "); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 479 | ppIRCallee(d->cee); |
| 480 | vex_printf("("); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 481 | for (i = 0; d->args[i] != NULL; i++) { |
| 482 | ppIRExpr(d->args[i]); |
| 483 | if (d->args[i+1] != NULL) { |
| 484 | vex_printf(","); |
| 485 | } |
| 486 | } |
| 487 | vex_printf(")"); |
| 488 | } |
| 489 | |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 490 | void ppIRJumpKind ( IRJumpKind kind ) |
| 491 | { |
| 492 | switch (kind) { |
| 493 | case Ijk_Boring: vex_printf("Boring"); break; |
| 494 | case Ijk_Call: vex_printf("Call"); break; |
| 495 | case Ijk_Ret: vex_printf("Return"); break; |
| 496 | case Ijk_ClientReq: vex_printf("ClientReq"); break; |
| 497 | case Ijk_Syscall: vex_printf("Syscall"); break; |
| 498 | case Ijk_Yield: vex_printf("Yield"); break; |
| 499 | case Ijk_EmWarn: vex_printf("EmWarn"); break; |
| 500 | default: vpanic("ppIRJumpKind"); |
| 501 | } |
| 502 | } |
| 503 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 504 | void ppIRStmt ( IRStmt* s ) |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 505 | { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 506 | switch (s->tag) { |
| 507 | case Ist_Put: |
| 508 | vex_printf( "PUT(%d) = ", s->Ist.Put.offset); |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 509 | ppIRExpr(s->Ist.Put.data); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 510 | break; |
| 511 | case Ist_PutI: |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 512 | vex_printf( "PUTI" ); |
| 513 | ppIRArray(s->Ist.PutI.descr); |
| 514 | vex_printf("["); |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 515 | ppIRExpr(s->Ist.PutI.ix); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 516 | vex_printf(",%d] = ", s->Ist.PutI.bias); |
| 517 | ppIRExpr(s->Ist.PutI.data); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 518 | break; |
| 519 | case Ist_Tmp: |
| 520 | ppIRTemp(s->Ist.Tmp.tmp); |
| 521 | vex_printf( " = " ); |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 522 | ppIRExpr(s->Ist.Tmp.data); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 523 | break; |
| 524 | case Ist_STle: |
| 525 | vex_printf( "STle("); |
| 526 | ppIRExpr(s->Ist.STle.addr); |
| 527 | vex_printf( ") = "); |
| 528 | ppIRExpr(s->Ist.STle.data); |
| 529 | break; |
| 530 | case Ist_Dirty: |
| 531 | ppIRDirty(s->Ist.Dirty.details); |
| 532 | break; |
| 533 | case Ist_Exit: |
| 534 | vex_printf( "if (" ); |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 535 | ppIRExpr(s->Ist.Exit.guard); |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 536 | vex_printf( ") goto {"); |
| 537 | ppIRJumpKind(s->Ist.Exit.jk); |
| 538 | vex_printf("} "); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 539 | ppIRConst(s->Ist.Exit.dst); |
| 540 | break; |
| 541 | default: |
| 542 | vpanic("ppIRStmt"); |
| 543 | } |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 544 | } |
| 545 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 546 | void ppIRTypeEnv ( IRTypeEnv* env ) { |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 547 | UInt i; |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 548 | for (i = 0; i < env->types_used; i++) { |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 549 | if (i % 8 == 0) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 550 | vex_printf( " "); |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 551 | ppIRTemp(i); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 552 | vex_printf( ":"); |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 553 | ppIRType(env->types[i]); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 554 | if (i % 8 == 7) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 555 | vex_printf( "\n"); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 556 | else |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 557 | vex_printf( " "); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 558 | } |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 559 | if (env->types_used > 0 && env->types_used % 8 != 7) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 560 | vex_printf( "\n"); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 561 | } |
| 562 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 563 | void ppIRBB ( IRBB* bb ) |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 564 | { |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 565 | Int i; |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 566 | vex_printf("IRBB {\n"); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 567 | ppIRTypeEnv(bb->tyenv); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 568 | vex_printf("\n"); |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 569 | for (i = 0; i < bb->stmts_used; i++) { |
sewardj | 39e3f24 | 2004-08-18 16:54:52 +0000 | [diff] [blame] | 570 | if (bb->stmts[i]) { |
| 571 | vex_printf( " "); |
| 572 | ppIRStmt(bb->stmts[i]); |
| 573 | } |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 574 | vex_printf( "\n"); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 575 | } |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 576 | vex_printf( " goto {"); |
| 577 | ppIRJumpKind(bb->jumpkind); |
| 578 | vex_printf( "} "); |
| 579 | ppIRExpr( bb->next ); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 580 | vex_printf( "\n}\n"); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | |
| 584 | /*---------------------------------------------------------------*/ |
| 585 | /*--- Constructors ---*/ |
| 586 | /*---------------------------------------------------------------*/ |
| 587 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 588 | |
| 589 | /* Constructors -- IRConst */ |
| 590 | |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 591 | IRConst* IRConst_U1 ( Bool bit ) |
sewardj | b8e7586 | 2004-08-19 17:58:45 +0000 | [diff] [blame] | 592 | { |
| 593 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 594 | c->tag = Ico_U1; |
| 595 | c->Ico.U1 = bit; |
sewardj | 4b861de | 2004-11-03 15:24:42 +0000 | [diff] [blame] | 596 | /* call me paranoid; I don't care :-) */ |
| 597 | vassert(bit == False || bit == True); |
sewardj | b8e7586 | 2004-08-19 17:58:45 +0000 | [diff] [blame] | 598 | return c; |
| 599 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 600 | IRConst* IRConst_U8 ( UChar u8 ) |
| 601 | { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 602 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 603 | c->tag = Ico_U8; |
| 604 | c->Ico.U8 = u8; |
| 605 | return c; |
| 606 | } |
| 607 | IRConst* IRConst_U16 ( UShort u16 ) |
| 608 | { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 609 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 610 | c->tag = Ico_U16; |
| 611 | c->Ico.U16 = u16; |
| 612 | return c; |
| 613 | } |
| 614 | IRConst* IRConst_U32 ( UInt u32 ) |
| 615 | { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 616 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 617 | c->tag = Ico_U32; |
| 618 | c->Ico.U32 = u32; |
| 619 | return c; |
| 620 | } |
| 621 | IRConst* IRConst_U64 ( ULong u64 ) |
| 622 | { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 623 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 624 | c->tag = Ico_U64; |
| 625 | c->Ico.U64 = u64; |
| 626 | return c; |
| 627 | } |
sewardj | a58ea66 | 2004-08-15 03:12:41 +0000 | [diff] [blame] | 628 | IRConst* IRConst_F64 ( Double f64 ) |
| 629 | { |
| 630 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
| 631 | c->tag = Ico_F64; |
| 632 | c->Ico.F64 = f64; |
| 633 | return c; |
| 634 | } |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 635 | IRConst* IRConst_F64i ( ULong f64i ) |
sewardj | 207557a | 2004-08-27 12:00:18 +0000 | [diff] [blame] | 636 | { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 637 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
| 638 | c->tag = Ico_F64i; |
| 639 | c->Ico.F64i = f64i; |
sewardj | 207557a | 2004-08-27 12:00:18 +0000 | [diff] [blame] | 640 | return c; |
| 641 | } |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 642 | IRConst* IRConst_V128 ( UShort con ) |
| 643 | { |
| 644 | IRConst* c = LibVEX_Alloc(sizeof(IRConst)); |
| 645 | c->tag = Ico_V128; |
| 646 | c->Ico.V128 = con; |
| 647 | return c; |
| 648 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 649 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 650 | /* Constructors -- IRCallee */ |
| 651 | |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 652 | IRCallee* mkIRCallee ( Int regparms, Char* name, void* addr ) |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 653 | { |
| 654 | IRCallee* ce = LibVEX_Alloc(sizeof(IRCallee)); |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 655 | ce->regparms = regparms; |
| 656 | ce->name = name; |
| 657 | ce->addr = addr; |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 658 | ce->mcx_mask = 0; |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 659 | vassert(regparms >= 0 && regparms <= 3); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 660 | vassert(name != NULL); |
| 661 | vassert(addr != 0); |
| 662 | return ce; |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /* Constructors -- IRArray */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 667 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 668 | IRArray* mkIRArray ( Int base, IRType elemTy, Int nElems ) |
| 669 | { |
| 670 | IRArray* arr = LibVEX_Alloc(sizeof(IRArray)); |
| 671 | arr->base = base; |
| 672 | arr->elemTy = elemTy; |
| 673 | arr->nElems = nElems; |
| 674 | vassert(!(arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */)); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 675 | vassert(!(arr->elemTy == Ity_I1)); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 676 | vassert(!(arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */)); |
| 677 | return arr; |
| 678 | } |
| 679 | |
| 680 | |
| 681 | /* Constructors -- IRExpr */ |
| 682 | |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 683 | IRExpr* IRExpr_Binder ( Int binder ) { |
| 684 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
| 685 | e->tag = Iex_Binder; |
| 686 | e->Iex.Binder.binder = binder; |
| 687 | return e; |
| 688 | } |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 689 | IRExpr* IRExpr_Get ( Int off, IRType ty ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 690 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 691 | e->tag = Iex_Get; |
| 692 | e->Iex.Get.offset = off; |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 693 | e->Iex.Get.ty = ty; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 694 | return e; |
| 695 | } |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 696 | IRExpr* IRExpr_GetI ( IRArray* descr, IRExpr* ix, Int bias ) { |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 697 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
| 698 | e->tag = Iex_GetI; |
| 699 | e->Iex.GetI.descr = descr; |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 700 | e->Iex.GetI.ix = ix; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 701 | e->Iex.GetI.bias = bias; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 702 | return e; |
| 703 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 704 | IRExpr* IRExpr_Tmp ( IRTemp tmp ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 705 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 706 | e->tag = Iex_Tmp; |
| 707 | e->Iex.Tmp.tmp = tmp; |
| 708 | return e; |
| 709 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 710 | IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 711 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 712 | e->tag = Iex_Binop; |
| 713 | e->Iex.Binop.op = op; |
| 714 | e->Iex.Binop.arg1 = arg1; |
| 715 | e->Iex.Binop.arg2 = arg2; |
| 716 | return e; |
| 717 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 718 | IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 719 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 720 | e->tag = Iex_Unop; |
| 721 | e->Iex.Unop.op = op; |
| 722 | e->Iex.Unop.arg = arg; |
| 723 | return e; |
| 724 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 725 | IRExpr* IRExpr_LDle ( IRType ty, IRExpr* addr ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 726 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 727 | e->tag = Iex_LDle; |
| 728 | e->Iex.LDle.ty = ty; |
| 729 | e->Iex.LDle.addr = addr; |
| 730 | return e; |
| 731 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 732 | IRExpr* IRExpr_Const ( IRConst* con ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 733 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 734 | e->tag = Iex_Const; |
| 735 | e->Iex.Const.con = con; |
| 736 | return e; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 737 | } |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 738 | IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args ) { |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 739 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
| 740 | e->tag = Iex_CCall; |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 741 | e->Iex.CCall.cee = cee; |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 742 | e->Iex.CCall.retty = retty; |
| 743 | e->Iex.CCall.args = args; |
| 744 | return e; |
| 745 | } |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 746 | IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX ) { |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 747 | IRExpr* e = LibVEX_Alloc(sizeof(IRExpr)); |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 748 | e->tag = Iex_Mux0X; |
| 749 | e->Iex.Mux0X.cond = cond; |
| 750 | e->Iex.Mux0X.expr0 = expr0; |
| 751 | e->Iex.Mux0X.exprX = exprX; |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 752 | return e; |
| 753 | } |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 754 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 755 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 756 | /* Constructors for NULL-terminated IRExpr expression vectors, |
| 757 | suitable for use as arg lists in clean/dirty helper calls. */ |
| 758 | |
| 759 | IRExpr** mkIRExprVec_0 ( void ) { |
| 760 | IRExpr** vec = LibVEX_Alloc(1 * sizeof(IRExpr*)); |
| 761 | vec[0] = NULL; |
| 762 | return vec; |
| 763 | } |
| 764 | IRExpr** mkIRExprVec_1 ( IRExpr* arg1 ) { |
| 765 | IRExpr** vec = LibVEX_Alloc(2 * sizeof(IRExpr*)); |
| 766 | vec[0] = arg1; |
| 767 | vec[1] = NULL; |
| 768 | return vec; |
| 769 | } |
| 770 | IRExpr** mkIRExprVec_2 ( IRExpr* arg1, IRExpr* arg2 ) { |
| 771 | IRExpr** vec = LibVEX_Alloc(3 * sizeof(IRExpr*)); |
| 772 | vec[0] = arg1; |
| 773 | vec[1] = arg2; |
| 774 | vec[2] = NULL; |
| 775 | return vec; |
| 776 | } |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 777 | IRExpr** mkIRExprVec_3 ( IRExpr* arg1, IRExpr* arg2, IRExpr* arg3 ) { |
| 778 | IRExpr** vec = LibVEX_Alloc(4 * sizeof(IRExpr*)); |
| 779 | vec[0] = arg1; |
| 780 | vec[1] = arg2; |
| 781 | vec[2] = arg3; |
| 782 | vec[3] = NULL; |
| 783 | return vec; |
| 784 | } |
| 785 | IRExpr** mkIRExprVec_4 ( IRExpr* arg1, IRExpr* arg2, |
| 786 | IRExpr* arg3, IRExpr* arg4 ) { |
| 787 | IRExpr** vec = LibVEX_Alloc(5 * sizeof(IRExpr*)); |
| 788 | vec[0] = arg1; |
| 789 | vec[1] = arg2; |
| 790 | vec[2] = arg3; |
| 791 | vec[3] = arg4; |
| 792 | vec[4] = NULL; |
| 793 | return vec; |
| 794 | } |
sewardj | f32c67d | 2004-11-08 13:10:44 +0000 | [diff] [blame] | 795 | IRExpr** mkIRExprVec_5 ( IRExpr* arg1, IRExpr* arg2, |
| 796 | IRExpr* arg3, IRExpr* arg4, IRExpr* arg5 ) { |
| 797 | IRExpr** vec = LibVEX_Alloc(6 * sizeof(IRExpr*)); |
| 798 | vec[0] = arg1; |
| 799 | vec[1] = arg2; |
| 800 | vec[2] = arg3; |
| 801 | vec[3] = arg4; |
| 802 | vec[4] = arg5; |
| 803 | vec[5] = NULL; |
| 804 | return vec; |
| 805 | } |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 806 | |
| 807 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 808 | /* Constructors -- IRDirty */ |
| 809 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 810 | IRDirty* emptyIRDirty ( void ) { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 811 | IRDirty* d = LibVEX_Alloc(sizeof(IRDirty)); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 812 | d->cee = NULL; |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 813 | d->guard = NULL; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 814 | d->args = NULL; |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 815 | d->tmp = IRTemp_INVALID; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 816 | d->mFx = Ifx_None; |
| 817 | d->mAddr = NULL; |
| 818 | d->mSize = 0; |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 819 | d->needsBBP = False; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 820 | d->nFxState = 0; |
| 821 | return d; |
| 822 | } |
| 823 | |
| 824 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 825 | /* Constructors -- IRStmt */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 826 | |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 827 | IRStmt* IRStmt_Put ( Int off, IRExpr* data ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 828 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 829 | s->tag = Ist_Put; |
| 830 | s->Ist.Put.offset = off; |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 831 | s->Ist.Put.data = data; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 832 | return s; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 833 | } |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 834 | IRStmt* IRStmt_PutI ( IRArray* descr, IRExpr* ix, |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 835 | Int bias, IRExpr* data ) { |
| 836 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
| 837 | s->tag = Ist_PutI; |
| 838 | s->Ist.PutI.descr = descr; |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 839 | s->Ist.PutI.ix = ix; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 840 | s->Ist.PutI.bias = bias; |
| 841 | s->Ist.PutI.data = data; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 842 | return s; |
| 843 | } |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 844 | IRStmt* IRStmt_Tmp ( IRTemp tmp, IRExpr* data ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 845 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 846 | s->tag = Ist_Tmp; |
| 847 | s->Ist.Tmp.tmp = tmp; |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 848 | s->Ist.Tmp.data = data; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 849 | return s; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 850 | } |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 851 | IRStmt* IRStmt_STle ( IRExpr* addr, IRExpr* data ) { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 852 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 853 | s->tag = Ist_STle; |
| 854 | s->Ist.STle.addr = addr; |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 855 | s->Ist.STle.data = data; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 856 | return s; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 857 | } |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 858 | IRStmt* IRStmt_Dirty ( IRDirty* d ) |
| 859 | { |
| 860 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
| 861 | s->tag = Ist_Dirty; |
| 862 | s->Ist.Dirty.details = d; |
| 863 | return s; |
| 864 | } |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 865 | IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst ) { |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 866 | IRStmt* s = LibVEX_Alloc(sizeof(IRStmt)); |
| 867 | s->tag = Ist_Exit; |
| 868 | s->Ist.Exit.guard = guard; |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 869 | s->Ist.Exit.jk = jk; |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 870 | s->Ist.Exit.dst = dst; |
sewardj | 64e1d65 | 2004-07-12 14:00:46 +0000 | [diff] [blame] | 871 | return s; |
| 872 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 873 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 874 | |
| 875 | /* Constructors -- IRTypeEnv */ |
| 876 | |
| 877 | IRTypeEnv* emptyIRTypeEnv ( void ) |
| 878 | { |
| 879 | IRTypeEnv* env = LibVEX_Alloc(sizeof(IRTypeEnv)); |
| 880 | env->types = LibVEX_Alloc(8 * sizeof(IRType)); |
| 881 | env->types_size = 8; |
| 882 | env->types_used = 0; |
| 883 | return env; |
| 884 | } |
| 885 | |
| 886 | |
| 887 | /* Constructors -- IRBB */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 888 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 889 | IRBB* emptyIRBB ( void ) |
| 890 | { |
| 891 | IRBB* bb = LibVEX_Alloc(sizeof(IRBB)); |
| 892 | bb->tyenv = emptyIRTypeEnv(); |
| 893 | bb->stmts_used = 0; |
| 894 | bb->stmts_size = 8; |
| 895 | bb->stmts = LibVEX_Alloc(bb->stmts_size * sizeof(IRStmt*)); |
| 896 | bb->next = NULL; |
| 897 | bb->jumpkind = Ijk_Boring; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 898 | return bb; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 899 | } |
| 900 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 901 | |
| 902 | /*---------------------------------------------------------------*/ |
| 903 | /*--- (Deep) copy constructors. These make complete copies ---*/ |
| 904 | /*--- the original, which can be modified without affecting ---*/ |
| 905 | /*--- the original. ---*/ |
| 906 | /*---------------------------------------------------------------*/ |
| 907 | |
| 908 | /* Copying IR Expr vectors (for call args). */ |
| 909 | |
| 910 | /* Shallow copy of an IRExpr vector */ |
| 911 | |
| 912 | IRExpr** sopyIRExprVec ( IRExpr** vec ) |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 913 | { |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 914 | Int i; |
| 915 | IRExpr** newvec; |
| 916 | for (i = 0; vec[i]; i++) |
| 917 | ; |
| 918 | newvec = LibVEX_Alloc((i+1)*sizeof(IRExpr*)); |
| 919 | for (i = 0; vec[i]; i++) |
| 920 | newvec[i] = vec[i]; |
| 921 | newvec[i] = NULL; |
| 922 | return newvec; |
| 923 | } |
| 924 | |
| 925 | /* Deep copy of an IRExpr vector */ |
| 926 | |
| 927 | IRExpr** dopyIRExprVec ( IRExpr** vec ) |
| 928 | { |
| 929 | Int i; |
| 930 | IRExpr** newvec = sopyIRExprVec( vec ); |
| 931 | for (i = 0; newvec[i]; i++) |
| 932 | newvec[i] = dopyIRExpr(newvec[i]); |
| 933 | return newvec; |
| 934 | } |
| 935 | |
| 936 | /* Deep copy constructors for all heap-allocated IR types follow. */ |
| 937 | |
| 938 | IRConst* dopyIRConst ( IRConst* c ) |
| 939 | { |
| 940 | switch (c->tag) { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 941 | case Ico_U1: return IRConst_U1(c->Ico.U1); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 942 | case Ico_U8: return IRConst_U8(c->Ico.U8); |
| 943 | case Ico_U16: return IRConst_U16(c->Ico.U16); |
| 944 | case Ico_U32: return IRConst_U32(c->Ico.U32); |
| 945 | case Ico_U64: return IRConst_U64(c->Ico.U64); |
| 946 | case Ico_F64: return IRConst_F64(c->Ico.F64); |
| 947 | case Ico_F64i: return IRConst_F64i(c->Ico.F64i); |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 948 | case Ico_V128: return IRConst_V128(c->Ico.V128); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 949 | default: vpanic("dopyIRConst"); |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 950 | } |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 951 | } |
| 952 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 953 | IRCallee* dopyIRCallee ( IRCallee* ce ) |
| 954 | { |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 955 | IRCallee* ce2 = mkIRCallee(ce->regparms, ce->name, ce->addr); |
| 956 | ce2->mcx_mask = ce->mcx_mask; |
| 957 | return ce2; |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 958 | } |
| 959 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 960 | IRArray* dopyIRArray ( IRArray* d ) |
| 961 | { |
| 962 | return mkIRArray(d->base, d->elemTy, d->nElems); |
| 963 | } |
| 964 | |
| 965 | IRExpr* dopyIRExpr ( IRExpr* e ) |
| 966 | { |
| 967 | switch (e->tag) { |
| 968 | case Iex_Get: |
| 969 | return IRExpr_Get(e->Iex.Get.offset, e->Iex.Get.ty); |
| 970 | case Iex_GetI: |
| 971 | return IRExpr_GetI(dopyIRArray(e->Iex.GetI.descr), |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 972 | dopyIRExpr(e->Iex.GetI.ix), |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 973 | e->Iex.GetI.bias); |
| 974 | case Iex_Tmp: |
| 975 | return IRExpr_Tmp(e->Iex.Tmp.tmp); |
| 976 | case Iex_Binop: |
| 977 | return IRExpr_Binop(e->Iex.Binop.op, |
| 978 | dopyIRExpr(e->Iex.Binop.arg1), |
| 979 | dopyIRExpr(e->Iex.Binop.arg2)); |
| 980 | case Iex_Unop: |
| 981 | return IRExpr_Unop(e->Iex.Unop.op, |
| 982 | dopyIRExpr(e->Iex.Unop.arg)); |
| 983 | case Iex_LDle: |
| 984 | return IRExpr_LDle(e->Iex.LDle.ty, |
| 985 | dopyIRExpr(e->Iex.LDle.addr)); |
| 986 | case Iex_Const: |
| 987 | return IRExpr_Const(dopyIRConst(e->Iex.Const.con)); |
| 988 | case Iex_CCall: |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 989 | return IRExpr_CCall(dopyIRCallee(e->Iex.CCall.cee), |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 990 | e->Iex.CCall.retty, |
| 991 | dopyIRExprVec(e->Iex.CCall.args)); |
| 992 | |
| 993 | case Iex_Mux0X: |
| 994 | return IRExpr_Mux0X(dopyIRExpr(e->Iex.Mux0X.cond), |
| 995 | dopyIRExpr(e->Iex.Mux0X.expr0), |
| 996 | dopyIRExpr(e->Iex.Mux0X.exprX)); |
| 997 | default: |
| 998 | vpanic("dopyIRExpr"); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | IRDirty* dopyIRDirty ( IRDirty* d ) |
| 1003 | { |
| 1004 | Int i; |
| 1005 | IRDirty* d2 = emptyIRDirty(); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1006 | d2->cee = dopyIRCallee(d->cee); |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1007 | d2->guard = dopyIRExpr(d->guard); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1008 | d2->args = dopyIRExprVec(d->args); |
| 1009 | d2->tmp = d->tmp; |
| 1010 | d2->mFx = d->mFx; |
| 1011 | d2->mAddr = d->mAddr==NULL ? NULL : dopyIRExpr(d->mAddr); |
| 1012 | d2->mSize = d->mSize; |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1013 | d2->needsBBP = d->needsBBP; |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1014 | d2->nFxState = d->nFxState; |
| 1015 | for (i = 0; i < d2->nFxState; i++) |
| 1016 | d2->fxState[i] = d->fxState[i]; |
| 1017 | return d2; |
| 1018 | } |
| 1019 | |
| 1020 | IRStmt* dopyIRStmt ( IRStmt* s ) |
| 1021 | { |
| 1022 | switch (s->tag) { |
| 1023 | case Ist_Put: |
| 1024 | return IRStmt_Put(s->Ist.Put.offset, |
| 1025 | dopyIRExpr(s->Ist.Put.data)); |
| 1026 | case Ist_PutI: |
| 1027 | return IRStmt_PutI(dopyIRArray(s->Ist.PutI.descr), |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1028 | dopyIRExpr(s->Ist.PutI.ix), |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1029 | s->Ist.PutI.bias, |
| 1030 | dopyIRExpr(s->Ist.PutI.data)); |
| 1031 | case Ist_Tmp: |
| 1032 | return IRStmt_Tmp(s->Ist.Tmp.tmp, |
| 1033 | dopyIRExpr(s->Ist.Tmp.data)); |
| 1034 | case Ist_STle: |
| 1035 | return IRStmt_STle(dopyIRExpr(s->Ist.STle.addr), |
| 1036 | dopyIRExpr(s->Ist.STle.data)); |
| 1037 | case Ist_Dirty: |
| 1038 | return IRStmt_Dirty(dopyIRDirty(s->Ist.Dirty.details)); |
| 1039 | case Ist_Exit: |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1040 | return IRStmt_Exit(dopyIRExpr(s->Ist.Exit.guard), |
| 1041 | s->Ist.Exit.jk, |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1042 | dopyIRConst(s->Ist.Exit.dst)); |
| 1043 | default: |
| 1044 | vpanic("dopyIRStmt"); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | IRTypeEnv* dopyIRTypeEnv ( IRTypeEnv* src ) |
| 1049 | { |
| 1050 | Int i; |
| 1051 | IRTypeEnv* dst = LibVEX_Alloc(sizeof(IRTypeEnv)); |
| 1052 | dst->types_size = src->types_size; |
| 1053 | dst->types_used = src->types_used; |
| 1054 | dst->types = LibVEX_Alloc(dst->types_size * sizeof(IRType)); |
| 1055 | for (i = 0; i < src->types_used; i++) |
| 1056 | dst->types[i] = src->types[i]; |
| 1057 | return dst; |
| 1058 | } |
| 1059 | |
| 1060 | IRBB* dopyIRBB ( IRBB* bb ) |
| 1061 | { |
| 1062 | Int i; |
| 1063 | IRStmt** sts2; |
| 1064 | IRBB* bb2 = emptyIRBB(); |
| 1065 | bb2->tyenv = dopyIRTypeEnv(bb->tyenv); |
| 1066 | bb2->stmts_used = bb2->stmts_size = bb->stmts_used; |
| 1067 | sts2 = LibVEX_Alloc(bb2->stmts_used * sizeof(IRStmt*)); |
| 1068 | for (i = 0; i < bb2->stmts_used; i++) |
| 1069 | sts2[i] = bb->stmts[i]==NULL ? NULL : dopyIRStmt(bb->stmts[i]); |
| 1070 | bb2->stmts = sts2; |
| 1071 | bb2->next = dopyIRExpr(bb->next); |
| 1072 | bb2->jumpkind = bb->jumpkind; |
| 1073 | return bb2; |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1076 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1077 | /*---------------------------------------------------------------*/ |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1078 | /*--- Primop types ---*/ |
| 1079 | /*---------------------------------------------------------------*/ |
| 1080 | |
| 1081 | static |
| 1082 | void typeOfPrimop ( IROp op, IRType* t_dst, IRType* t_arg1, IRType* t_arg2 ) |
| 1083 | { |
| 1084 | # define UNARY(_td,_ta1) \ |
| 1085 | *t_dst = (_td); *t_arg1 = (_ta1); break |
| 1086 | # define BINARY(_td,_ta1,_ta2) \ |
| 1087 | *t_dst = (_td); *t_arg1 = (_ta1); *t_arg2 = (_ta2); break |
| 1088 | # define COMPARISON(_ta) \ |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1089 | *t_dst = Ity_I1; *t_arg1 = *t_arg2 = (_ta); break; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1090 | |
| 1091 | *t_dst = Ity_INVALID; |
| 1092 | *t_arg1 = Ity_INVALID; |
| 1093 | *t_arg2 = Ity_INVALID; |
| 1094 | switch (op) { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1095 | case Iop_Add8: case Iop_Sub8: case Iop_Mul8: |
| 1096 | case Iop_Or8: case Iop_And8: case Iop_Xor8: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1097 | BINARY(Ity_I8,Ity_I8,Ity_I8); |
| 1098 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1099 | case Iop_Add16: case Iop_Sub16: case Iop_Mul16: |
| 1100 | case Iop_Or16: case Iop_And16: case Iop_Xor16: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1101 | BINARY(Ity_I16,Ity_I16,Ity_I16); |
| 1102 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1103 | case Iop_Add32: case Iop_Sub32: case Iop_Mul32: |
| 1104 | case Iop_Or32: case Iop_And32: case Iop_Xor32: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1105 | BINARY(Ity_I32,Ity_I32,Ity_I32); |
| 1106 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1107 | case Iop_Add64: case Iop_Sub64: case Iop_Mul64: |
| 1108 | case Iop_Or64: case Iop_And64: case Iop_Xor64: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1109 | BINARY(Ity_I64,Ity_I64,Ity_I64); |
| 1110 | |
| 1111 | case Iop_Shl8: case Iop_Shr8: case Iop_Sar8: |
| 1112 | BINARY(Ity_I8,Ity_I8,Ity_I8); |
| 1113 | case Iop_Shl16: case Iop_Shr16: case Iop_Sar16: |
| 1114 | BINARY(Ity_I16,Ity_I16,Ity_I8); |
| 1115 | case Iop_Shl32: case Iop_Shr32: case Iop_Sar32: |
| 1116 | BINARY(Ity_I32,Ity_I32,Ity_I8); |
| 1117 | case Iop_Shl64: case Iop_Shr64: case Iop_Sar64: |
| 1118 | BINARY(Ity_I64,Ity_I64,Ity_I8); |
| 1119 | |
sewardj | 86b133b | 2004-11-15 13:54:26 +0000 | [diff] [blame] | 1120 | case Iop_Not8: UNARY(Ity_I8,Ity_I8); |
| 1121 | case Iop_Not16: UNARY(Ity_I16,Ity_I16); |
| 1122 | case Iop_Not32: UNARY(Ity_I32,Ity_I32); |
| 1123 | case Iop_Not64: UNARY(Ity_I64,Ity_I64); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1124 | |
| 1125 | case Iop_CmpEQ8: case Iop_CmpNE8: |
| 1126 | COMPARISON(Ity_I8); |
| 1127 | case Iop_CmpEQ16: case Iop_CmpNE16: |
| 1128 | COMPARISON(Ity_I16); |
| 1129 | case Iop_CmpEQ32: case Iop_CmpNE32: |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1130 | case Iop_CmpLT32S: case Iop_CmpLE32S: |
| 1131 | case Iop_CmpLT32U: case Iop_CmpLE32U: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1132 | COMPARISON(Ity_I32); |
| 1133 | case Iop_CmpEQ64: case Iop_CmpNE64: |
| 1134 | COMPARISON(Ity_I64); |
| 1135 | |
sewardj | b81f8b3 | 2004-07-30 10:17:50 +0000 | [diff] [blame] | 1136 | case Iop_MullU8: case Iop_MullS8: |
| 1137 | BINARY(Ity_I16,Ity_I8,Ity_I8); |
| 1138 | case Iop_MullU16: case Iop_MullS16: |
| 1139 | BINARY(Ity_I32,Ity_I16,Ity_I16); |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1140 | case Iop_MullU32: case Iop_MullS32: |
| 1141 | BINARY(Ity_I64,Ity_I32,Ity_I32); |
| 1142 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1143 | case Iop_Clz32: case Iop_Ctz32: |
sewardj | ce646f2 | 2004-08-31 23:55:54 +0000 | [diff] [blame] | 1144 | UNARY(Ity_I32,Ity_I32); |
| 1145 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1146 | case Iop_DivModU64to32: case Iop_DivModS64to32: |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1147 | BINARY(Ity_I64,Ity_I64,Ity_I32); |
| 1148 | |
sewardj | b81f8b3 | 2004-07-30 10:17:50 +0000 | [diff] [blame] | 1149 | case Iop_16HIto8: case Iop_16to8: |
| 1150 | UNARY(Ity_I8,Ity_I16); |
| 1151 | case Iop_8HLto16: |
| 1152 | BINARY(Ity_I16,Ity_I8,Ity_I8); |
| 1153 | |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 1154 | case Iop_32HIto16: case Iop_32to16: |
| 1155 | UNARY(Ity_I16,Ity_I32); |
| 1156 | case Iop_16HLto32: |
| 1157 | BINARY(Ity_I32,Ity_I16,Ity_I16); |
| 1158 | |
| 1159 | case Iop_64HIto32: case Iop_64to32: |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1160 | UNARY(Ity_I32, Ity_I64); |
| 1161 | case Iop_32HLto64: |
| 1162 | BINARY(Ity_I64,Ity_I32,Ity_I32); |
| 1163 | |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1164 | case Iop_Not1: UNARY(Ity_I1,Ity_I1); |
| 1165 | case Iop_1Uto8: UNARY(Ity_I8,Ity_I1); |
| 1166 | case Iop_1Sto8: UNARY(Ity_I8,Ity_I1); |
| 1167 | case Iop_1Sto16: UNARY(Ity_I16,Ity_I1); |
| 1168 | case Iop_1Uto32: case Iop_1Sto32: UNARY(Ity_I32,Ity_I1); |
| 1169 | case Iop_1Sto64: UNARY(Ity_I64,Ity_I1); |
| 1170 | case Iop_32to1: UNARY(Ity_I1,Ity_I32); |
sewardj | 4734104 | 2004-09-19 11:55:46 +0000 | [diff] [blame] | 1171 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1172 | case Iop_8Uto32: case Iop_8Sto32: |
| 1173 | UNARY(Ity_I32,Ity_I8); |
sewardj | 4734104 | 2004-09-19 11:55:46 +0000 | [diff] [blame] | 1174 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1175 | case Iop_8Uto16: case Iop_8Sto16: |
| 1176 | UNARY(Ity_I16,Ity_I8); |
sewardj | 4734104 | 2004-09-19 11:55:46 +0000 | [diff] [blame] | 1177 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1178 | case Iop_16Uto32: case Iop_16Sto32: |
| 1179 | UNARY(Ity_I32,Ity_I16); |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1180 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1181 | case Iop_32Sto64: case Iop_32Uto64: |
| 1182 | UNARY(Ity_I64,Ity_I32); |
| 1183 | |
| 1184 | case Iop_32to8: UNARY(Ity_I8,Ity_I32); |
| 1185 | |
sewardj | 442d0be | 2004-10-15 22:57:13 +0000 | [diff] [blame] | 1186 | case Iop_ScaleF64: case Iop_PRemF64: case Iop_PRem1F64: |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1187 | case Iop_AtanF64: case Iop_Yl2xF64: case Iop_Yl2xp1F64: |
| 1188 | case Iop_AddF64: case Iop_SubF64: case Iop_MulF64: case Iop_DivF64: |
sewardj | a58ea66 | 2004-08-15 03:12:41 +0000 | [diff] [blame] | 1189 | BINARY(Ity_F64,Ity_F64,Ity_F64); |
sewardj | 442d0be | 2004-10-15 22:57:13 +0000 | [diff] [blame] | 1190 | case Iop_PRemC3210F64: case Iop_PRem1C3210F64: |
sewardj | bdc7d21 | 2004-09-09 02:46:40 +0000 | [diff] [blame] | 1191 | case Iop_CmpF64: |
| 1192 | BINARY(Ity_I32,Ity_F64,Ity_F64); |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 1193 | case Iop_NegF64: case Iop_AbsF64: case Iop_SqrtF64: |
sewardj | 99016a7 | 2004-10-15 22:09:17 +0000 | [diff] [blame] | 1194 | case Iop_SinF64: case Iop_CosF64: case Iop_TanF64: case Iop_2xm1F64: |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 1195 | UNARY(Ity_F64,Ity_F64); |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 1196 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 1197 | case Iop_ReinterpI64asF64: UNARY(Ity_F64, Ity_I64); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1198 | case Iop_ReinterpF64asI64: UNARY(Ity_I64, Ity_F64); |
sewardj | fd22645 | 2004-12-07 19:02:18 +0000 | [diff] [blame] | 1199 | case Iop_ReinterpI32asF32: UNARY(Ity_F32, Ity_I32); |
| 1200 | case Iop_ReinterpF32asI32: UNARY(Ity_I32, Ity_F32); |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 1201 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 1202 | case Iop_F64toI16: BINARY(Ity_I16, Ity_I32,Ity_F64); |
| 1203 | case Iop_F64toI32: BINARY(Ity_I32, Ity_I32,Ity_F64); |
| 1204 | case Iop_F64toI64: BINARY(Ity_I64, Ity_I32,Ity_F64); |
| 1205 | |
| 1206 | case Iop_I16toF64: UNARY(Ity_F64, Ity_I16); |
| 1207 | case Iop_I32toF64: UNARY(Ity_F64, Ity_I32); |
sewardj | 4cb918d | 2004-12-03 19:43:31 +0000 | [diff] [blame] | 1208 | case Iop_I64toF64: BINARY(Ity_F64, Ity_I32,Ity_I64); |
| 1209 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 1210 | case Iop_F32toF64: UNARY(Ity_F64, Ity_F32); |
| 1211 | case Iop_F64toF32: BINARY(Ity_F32, Ity_I32,Ity_F64); |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 1212 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 1213 | case Iop_RoundF64: BINARY(Ity_F64, Ity_I32,Ity_F64); |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1214 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1215 | case Iop_64HLto128: BINARY(Ity_V128, Ity_I64,Ity_I64); |
| 1216 | case Iop_128to64: case Iop_128HIto64: |
| 1217 | UNARY(Ity_I64, Ity_V128); |
| 1218 | |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 1219 | case Iop_32Uto128: UNARY(Ity_V128, Ity_I32); |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1220 | case Iop_64Uto128: UNARY(Ity_V128, Ity_I64); |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 1221 | case Iop_Set128lo32: BINARY(Ity_V128, Ity_V128,Ity_I32); |
sewardj | 008754b | 2004-12-08 14:37:10 +0000 | [diff] [blame] | 1222 | case Iop_Set128lo64: BINARY(Ity_V128, Ity_V128,Ity_I64); |
sewardj | 129b3d9 | 2004-12-05 15:42:05 +0000 | [diff] [blame] | 1223 | |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1224 | case Iop_CmpEQ32Fx4: case Iop_CmpLT32Fx4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1225 | case Iop_CmpEQ64Fx2: case Iop_CmpLT64Fx2: |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1226 | case Iop_CmpLE32Fx4: case Iop_CmpUN32Fx4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1227 | case Iop_CmpLE64Fx2: case Iop_CmpUN64Fx2: |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1228 | case Iop_CmpEQ32F0x4: case Iop_CmpLT32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1229 | case Iop_CmpEQ64F0x2: case Iop_CmpLT64F0x2: |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1230 | case Iop_CmpLE32F0x4: case Iop_CmpUN32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1231 | case Iop_CmpLE64F0x2: case Iop_CmpUN64F0x2: |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1232 | case Iop_Add32Fx4: case Iop_Add32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1233 | case Iop_Add64Fx2: case Iop_Add64F0x2: |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 1234 | case Iop_Div32Fx4: case Iop_Div32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1235 | case Iop_Div64Fx2: case Iop_Div64F0x2: |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 1236 | case Iop_Max32Fx4: case Iop_Max32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1237 | case Iop_Max64Fx2: case Iop_Max64F0x2: |
sewardj | 176a59c | 2004-12-03 20:08:31 +0000 | [diff] [blame] | 1238 | case Iop_Min32Fx4: case Iop_Min32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1239 | case Iop_Min64Fx2: case Iop_Min64F0x2: |
sewardj | 9636b44 | 2004-12-04 01:38:37 +0000 | [diff] [blame] | 1240 | case Iop_Mul32Fx4: case Iop_Mul32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1241 | case Iop_Mul64Fx2: case Iop_Mul64F0x2: |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 1242 | case Iop_Sub32Fx4: case Iop_Sub32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1243 | case Iop_Sub64Fx2: case Iop_Sub64F0x2: |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1244 | case Iop_And128: case Iop_Or128: case Iop_Xor128: |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame^] | 1245 | case Iop_Add8x16: case Iop_Add16x8: |
| 1246 | case Iop_Add32x4: case Iop_Add64x2: |
| 1247 | case Iop_QAdd8Ux16: case Iop_QAdd16Ux8: |
| 1248 | case Iop_QAdd8Sx16: case Iop_QAdd16Sx8: |
| 1249 | case Iop_Sub8x16: case Iop_Sub16x8: |
| 1250 | case Iop_Sub32x4: case Iop_Sub64x2: |
| 1251 | case Iop_QSub8Ux16: case Iop_QSub16Ux8: |
| 1252 | case Iop_QSub8Sx16: case Iop_QSub16Sx8: |
| 1253 | case Iop_Mul16x8: |
| 1254 | case Iop_MulHi16Ux8: |
| 1255 | case Iop_MulHi16Sx8: |
| 1256 | case Iop_Avg8Ux16: |
| 1257 | case Iop_Avg16Ux8: |
| 1258 | case Iop_Max16Sx8: |
| 1259 | case Iop_Max8Ux16: |
| 1260 | case Iop_Min16Sx8: |
| 1261 | case Iop_Min8Ux16: |
| 1262 | case Iop_CmpEQ8x16: case Iop_CmpEQ16x8: case Iop_CmpEQ32x4: |
| 1263 | case Iop_CmpGT8Sx16: case Iop_CmpGT16Sx8: case Iop_CmpGT32Sx4: |
| 1264 | case Iop_QNarrow16Ux8: |
| 1265 | case Iop_QNarrow16Sx8: case Iop_QNarrow32Sx4: |
| 1266 | case Iop_InterleaveHI8x16: case Iop_InterleaveHI16x8: |
| 1267 | case Iop_InterleaveHI32x4: case Iop_InterleaveHI64x2: |
| 1268 | case Iop_InterleaveLO8x16: case Iop_InterleaveLO16x8: |
| 1269 | case Iop_InterleaveLO32x4: case Iop_InterleaveLO64x2: |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1270 | BINARY(Ity_V128, Ity_V128,Ity_V128); |
| 1271 | |
sewardj | 0bd7ce6 | 2004-12-05 02:47:40 +0000 | [diff] [blame] | 1272 | case Iop_Recip32Fx4: case Iop_Recip32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1273 | case Iop_Recip64Fx2: case Iop_Recip64F0x2: |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 1274 | case Iop_RSqrt32Fx4: case Iop_RSqrt32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1275 | case Iop_RSqrt64Fx2: case Iop_RSqrt64F0x2: |
sewardj | c1e7dfc | 2004-12-05 19:29:45 +0000 | [diff] [blame] | 1276 | case Iop_Sqrt32Fx4: case Iop_Sqrt32F0x4: |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1277 | case Iop_Sqrt64Fx2: case Iop_Sqrt64F0x2: |
sewardj | 0bd7ce6 | 2004-12-05 02:47:40 +0000 | [diff] [blame] | 1278 | UNARY(Ity_V128, Ity_V128); |
| 1279 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame^] | 1280 | case Iop_ShlN16x8: case Iop_ShlN32x4: case Iop_ShlN64x2: |
| 1281 | case Iop_ShrN16x8: case Iop_ShrN32x4: case Iop_ShrN64x2: |
| 1282 | case Iop_SarN16x8: case Iop_SarN32x4: |
| 1283 | BINARY(Ity_V128, Ity_V128, Ity_I8); |
| 1284 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1285 | default: |
| 1286 | ppIROp(op); |
| 1287 | vpanic("typeOfPrimop"); |
| 1288 | } |
| 1289 | # undef UNARY |
| 1290 | # undef BINARY |
| 1291 | # undef COMPARISON |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | /*---------------------------------------------------------------*/ |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1296 | /*--- Helper functions for the IR -- IR Basic Blocks ---*/ |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1297 | /*---------------------------------------------------------------*/ |
| 1298 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1299 | void addStmtToIRBB ( IRBB* bb, IRStmt* st ) |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1300 | { |
| 1301 | Int i; |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1302 | if (bb->stmts_used == bb->stmts_size) { |
| 1303 | IRStmt** stmts2 = LibVEX_Alloc(2 * bb->stmts_size * sizeof(IRStmt*)); |
| 1304 | for (i = 0; i < bb->stmts_size; i++) |
| 1305 | stmts2[i] = bb->stmts[i]; |
| 1306 | bb->stmts = stmts2; |
| 1307 | bb->stmts_size *= 2; |
| 1308 | } |
| 1309 | vassert(bb->stmts_used < bb->stmts_size); |
| 1310 | bb->stmts[bb->stmts_used] = st; |
| 1311 | bb->stmts_used++; |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1314 | |
| 1315 | /*---------------------------------------------------------------*/ |
| 1316 | /*--- Helper functions for the IR -- IR Type Environments ---*/ |
| 1317 | /*---------------------------------------------------------------*/ |
| 1318 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1319 | /* Allocate a new IRTemp, given its type. */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1320 | |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1321 | IRTemp newIRTemp ( IRTypeEnv* env, IRType ty ) |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1322 | { |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1323 | vassert(env); |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1324 | vassert(env->types_used >= 0); |
| 1325 | vassert(env->types_size >= 0); |
| 1326 | vassert(env->types_used <= env->types_size); |
| 1327 | if (env->types_used < env->types_size) { |
| 1328 | env->types[env->types_used] = ty; |
| 1329 | return env->types_used++; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1330 | } else { |
| 1331 | Int i; |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1332 | Int new_size = env->types_size==0 ? 8 : 2*env->types_size; |
| 1333 | IRType* new_types |
| 1334 | = LibVEX_Alloc(new_size * sizeof(IRType)); |
| 1335 | for (i = 0; i < env->types_used; i++) |
| 1336 | new_types[i] = env->types[i]; |
| 1337 | env->types = new_types; |
| 1338 | env->types_size = new_size; |
| 1339 | return newIRTemp(env, ty); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1344 | /*---------------------------------------------------------------*/ |
| 1345 | /*--- Helper functions for the IR -- finding types of exprs ---*/ |
| 1346 | /*---------------------------------------------------------------*/ |
| 1347 | |
sewardj | edeb4c4 | 2004-09-21 23:39:25 +0000 | [diff] [blame] | 1348 | inline |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1349 | IRType typeOfIRTemp ( IRTypeEnv* env, IRTemp tmp ) |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1350 | { |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1351 | vassert(tmp >= 0); |
| 1352 | vassert(tmp < env->types_used); |
| 1353 | return env->types[tmp]; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1357 | IRType typeOfIRConst ( IRConst* con ) |
| 1358 | { |
| 1359 | switch (con->tag) { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1360 | case Ico_U1: return Ity_I1; |
sewardj | 207557a | 2004-08-27 12:00:18 +0000 | [diff] [blame] | 1361 | case Ico_U8: return Ity_I8; |
| 1362 | case Ico_U16: return Ity_I16; |
| 1363 | case Ico_U32: return Ity_I32; |
| 1364 | case Ico_U64: return Ity_I64; |
| 1365 | case Ico_F64: return Ity_F64; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1366 | case Ico_F64i: return Ity_F64; |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 1367 | case Ico_V128: return Ity_V128; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1368 | default: vpanic("typeOfIRConst"); |
| 1369 | } |
| 1370 | } |
| 1371 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1372 | IRType typeOfIRExpr ( IRTypeEnv* tyenv, IRExpr* e ) |
| 1373 | { |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1374 | IRType t_dst, t_arg1, t_arg2; |
sewardj | edeb4c4 | 2004-09-21 23:39:25 +0000 | [diff] [blame] | 1375 | start: |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1376 | switch (e->tag) { |
sewardj | e05c42c | 2004-07-08 20:25:10 +0000 | [diff] [blame] | 1377 | case Iex_LDle: |
| 1378 | return e->Iex.LDle.ty; |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 1379 | case Iex_Get: |
| 1380 | return e->Iex.Get.ty; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1381 | case Iex_GetI: |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1382 | return e->Iex.GetI.descr->elemTy; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1383 | case Iex_Tmp: |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1384 | return typeOfIRTemp(tyenv, e->Iex.Tmp.tmp); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1385 | case Iex_Const: |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1386 | return typeOfIRConst(e->Iex.Const.con); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1387 | case Iex_Binop: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1388 | typeOfPrimop(e->Iex.Binop.op, &t_dst, &t_arg1, &t_arg2); |
| 1389 | return t_dst; |
| 1390 | case Iex_Unop: |
| 1391 | typeOfPrimop(e->Iex.Unop.op, &t_dst, &t_arg1, &t_arg2); |
| 1392 | return t_dst; |
| 1393 | case Iex_CCall: |
| 1394 | return e->Iex.CCall.retty; |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 1395 | case Iex_Mux0X: |
sewardj | edeb4c4 | 2004-09-21 23:39:25 +0000 | [diff] [blame] | 1396 | e = e->Iex.Mux0X.expr0; |
| 1397 | goto start; |
| 1398 | /* return typeOfIRExpr(tyenv, e->Iex.Mux0X.expr0); */ |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 1399 | case Iex_Binder: |
| 1400 | vpanic("typeOfIRExpr: Binder is not a valid expression"); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1401 | default: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1402 | ppIRExpr(e); |
| 1403 | vpanic("typeOfIRExpr"); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1404 | } |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1405 | } |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 1406 | |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1407 | /* Is this any value actually in the enumeration 'IRType' ? */ |
| 1408 | Bool isPlausibleType ( IRType ty ) |
| 1409 | { |
| 1410 | switch (ty) { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1411 | case Ity_INVALID: case Ity_I1: |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1412 | case Ity_I8: case Ity_I16: case Ity_I32: case Ity_I64: |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1413 | case Ity_F32: case Ity_F64: |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1414 | case Ity_V128: |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1415 | return True; |
| 1416 | default: |
| 1417 | return False; |
| 1418 | } |
| 1419 | } |
| 1420 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1421 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 1422 | /*---------------------------------------------------------------*/ |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 1423 | /*--- Sanity checking -- FLATNESS ---*/ |
| 1424 | /*---------------------------------------------------------------*/ |
| 1425 | |
| 1426 | /* Check that the canonical flatness constraints hold on an |
| 1427 | IRStmt. The only place where any expression is allowed to be |
| 1428 | non-atomic is the RHS of IRStmt_Tmp. */ |
| 1429 | |
| 1430 | /* Relies on: |
| 1431 | inline static Bool isAtom ( IRExpr* e ) { |
| 1432 | return e->tag == Iex_Tmp || e->tag == Iex_Const; |
| 1433 | } |
| 1434 | */ |
| 1435 | |
| 1436 | Bool isFlatIRStmt ( IRStmt* st ) |
| 1437 | { |
| 1438 | Int i; |
| 1439 | IRExpr* e; |
| 1440 | IRDirty* di; |
| 1441 | |
| 1442 | switch (st->tag) { |
| 1443 | case Ist_Put: |
| 1444 | return isAtom(st->Ist.Put.data); |
| 1445 | case Ist_PutI: |
| 1446 | return isAtom(st->Ist.PutI.ix) && isAtom(st->Ist.PutI.data); |
| 1447 | case Ist_Tmp: |
| 1448 | /* This is the only interesting case. The RHS can be any |
| 1449 | expression, *but* all its subexpressions *must* be |
| 1450 | atoms. */ |
| 1451 | e = st->Ist.Tmp.data; |
| 1452 | switch (e->tag) { |
| 1453 | case Iex_Binder: return True; |
| 1454 | case Iex_Get: return True; |
| 1455 | case Iex_GetI: return isAtom(e->Iex.GetI.ix); |
| 1456 | case Iex_Tmp: return True; |
| 1457 | case Iex_Binop: return isAtom(e->Iex.Binop.arg1) |
| 1458 | && isAtom(e->Iex.Binop.arg2); |
| 1459 | case Iex_Unop: return isAtom(e->Iex.Unop.arg); |
| 1460 | case Iex_LDle: return isAtom(e->Iex.LDle.addr); |
| 1461 | case Iex_Const: return True; |
| 1462 | case Iex_CCall: for (i = 0; e->Iex.CCall.args[i]; i++) |
| 1463 | if (!isAtom(e->Iex.CCall.args[i])) |
| 1464 | return False; |
| 1465 | return True; |
| 1466 | case Iex_Mux0X: return isAtom(e->Iex.Mux0X.cond) |
| 1467 | && isAtom(e->Iex.Mux0X.expr0) |
| 1468 | && isAtom(e->Iex.Mux0X.exprX); |
| 1469 | default: vpanic("isFlatIRStmt(e)"); |
| 1470 | } |
| 1471 | /*notreached*/ |
| 1472 | vassert(0); |
| 1473 | case Ist_STle: |
| 1474 | return isAtom(st->Ist.STle.addr) && isAtom(st->Ist.STle.data); |
| 1475 | case Ist_Dirty: |
| 1476 | di = st->Ist.Dirty.details; |
| 1477 | if (!isAtom(di->guard)) |
| 1478 | return False; |
| 1479 | for (i = 0; di->args[i]; i++) |
| 1480 | if (!isAtom(di->args[i])) |
| 1481 | return False; |
| 1482 | if (di->mAddr && !isAtom(di->mAddr)) |
| 1483 | return False; |
| 1484 | return True; |
| 1485 | case Ist_Exit: |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 1486 | return isAtom(st->Ist.Exit.guard); |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 1487 | default: |
| 1488 | vpanic("isFlatIRStmt(st)"); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | /*---------------------------------------------------------------*/ |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1494 | /*--- Sanity checking ---*/ |
| 1495 | /*---------------------------------------------------------------*/ |
| 1496 | |
| 1497 | /* Checks: |
| 1498 | |
| 1499 | Everything is type-consistent. No ill-typed anything. |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1500 | The target address at the end of the BB is a 32- or 64- |
| 1501 | bit expression, depending on the guest's word size. |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1502 | |
| 1503 | Each temp is assigned only once, before its uses. |
sewardj | c13e2ed | 2004-10-31 21:44:54 +0000 | [diff] [blame] | 1504 | */ |
| 1505 | |
| 1506 | static inline Int countArgs ( IRExpr** args ) |
| 1507 | { |
| 1508 | Int i; |
| 1509 | for (i = 0; args[i]; i++) |
| 1510 | ; |
| 1511 | return i; |
| 1512 | } |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1513 | |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1514 | static |
| 1515 | __attribute((noreturn)) |
| 1516 | void sanityCheckFail ( IRBB* bb, IRStmt* stmt, Char* what ) |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1517 | { |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1518 | vex_printf("\nIR SANITY CHECK FAILURE\n\n"); |
| 1519 | ppIRBB(bb); |
| 1520 | if (stmt) { |
| 1521 | vex_printf("\nIN STATEMENT:\n\n"); |
| 1522 | ppIRStmt(stmt); |
| 1523 | } |
| 1524 | vex_printf("\n\nERROR = %s\n\n", what ); |
| 1525 | vpanic("sanityCheckFail: exiting due to bad IR"); |
| 1526 | } |
| 1527 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1528 | static Bool saneIRArray ( IRArray* arr ) |
| 1529 | { |
| 1530 | if (arr->base < 0 || arr->base > 10000 /* somewhat arbitrary */) |
| 1531 | return False; |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1532 | if (arr->elemTy == Ity_I1) |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1533 | return False; |
| 1534 | if (arr->nElems <= 0 || arr->nElems > 500 /* somewhat arbitrary */) |
| 1535 | return False; |
| 1536 | return True; |
| 1537 | } |
| 1538 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1539 | static Bool saneIRCallee ( IRCallee* cee ) |
| 1540 | { |
| 1541 | if (cee->name == NULL) |
| 1542 | return False; |
| 1543 | if (cee->addr == 0) |
| 1544 | return False; |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 1545 | if (cee->regparms < 0 || cee->regparms > 3) |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1546 | return False; |
| 1547 | return True; |
| 1548 | } |
| 1549 | |
sewardj | 49bfe67 | 2004-11-15 15:46:26 +0000 | [diff] [blame] | 1550 | static Bool saneIRConst ( IRConst* con ) |
| 1551 | { |
| 1552 | switch (con->tag) { |
| 1553 | case Ico_U1: |
| 1554 | return con->Ico.U1 == True || con->Ico.U1 == False; |
| 1555 | default: |
| 1556 | /* Is there anything we can meaningfully check? I don't |
| 1557 | think so. */ |
| 1558 | return True; |
| 1559 | } |
| 1560 | } |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1561 | |
| 1562 | /* Traverse a Stmt/Expr, inspecting IRTemp uses. Report any out of |
| 1563 | range ones. Report any which are read and for which the current |
| 1564 | def_count is zero. */ |
| 1565 | |
| 1566 | static |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1567 | void useBeforeDef_Temp ( IRBB* bb, IRStmt* stmt, IRTemp tmp, Int* def_counts ) |
| 1568 | { |
| 1569 | if (tmp < 0 || tmp >= bb->tyenv->types_used) |
| 1570 | sanityCheckFail(bb,stmt, "out of range Temp in IRExpr"); |
| 1571 | if (def_counts[tmp] < 1) |
| 1572 | sanityCheckFail(bb,stmt, "IRTemp use before def in IRExpr"); |
| 1573 | } |
| 1574 | |
| 1575 | static |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1576 | void useBeforeDef_Expr ( IRBB* bb, IRStmt* stmt, IRExpr* expr, Int* def_counts ) |
| 1577 | { |
| 1578 | Int i; |
| 1579 | switch (expr->tag) { |
| 1580 | case Iex_Get: |
| 1581 | break; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1582 | case Iex_GetI: |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1583 | useBeforeDef_Expr(bb,stmt,expr->Iex.GetI.ix,def_counts); |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1584 | break; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1585 | case Iex_Tmp: |
| 1586 | useBeforeDef_Temp(bb,stmt,expr->Iex.Tmp.tmp,def_counts); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | case Iex_Binop: |
| 1589 | useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg1,def_counts); |
| 1590 | useBeforeDef_Expr(bb,stmt,expr->Iex.Binop.arg2,def_counts); |
| 1591 | break; |
| 1592 | case Iex_Unop: |
| 1593 | useBeforeDef_Expr(bb,stmt,expr->Iex.Unop.arg,def_counts); |
| 1594 | break; |
| 1595 | case Iex_LDle: |
| 1596 | useBeforeDef_Expr(bb,stmt,expr->Iex.LDle.addr,def_counts); |
| 1597 | break; |
| 1598 | case Iex_Const: |
| 1599 | break; |
| 1600 | case Iex_CCall: |
| 1601 | for (i = 0; expr->Iex.CCall.args[i]; i++) |
| 1602 | useBeforeDef_Expr(bb,stmt,expr->Iex.CCall.args[i],def_counts); |
| 1603 | break; |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 1604 | case Iex_Mux0X: |
| 1605 | useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.cond,def_counts); |
| 1606 | useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.expr0,def_counts); |
| 1607 | useBeforeDef_Expr(bb,stmt,expr->Iex.Mux0X.exprX,def_counts); |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | default: |
| 1610 | vpanic("useBeforeDef_Expr"); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | static |
| 1615 | void useBeforeDef_Stmt ( IRBB* bb, IRStmt* stmt, Int* def_counts ) |
| 1616 | { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1617 | Int i; |
| 1618 | IRDirty* d; |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1619 | switch (stmt->tag) { |
| 1620 | case Ist_Put: |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1621 | useBeforeDef_Expr(bb,stmt,stmt->Ist.Put.data,def_counts); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1622 | break; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 1623 | case Ist_PutI: |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1624 | useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.ix,def_counts); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1625 | useBeforeDef_Expr(bb,stmt,stmt->Ist.PutI.data,def_counts); |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 1626 | break; |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1627 | case Ist_Tmp: |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1628 | useBeforeDef_Expr(bb,stmt,stmt->Ist.Tmp.data,def_counts); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | case Ist_STle: |
| 1631 | useBeforeDef_Expr(bb,stmt,stmt->Ist.STle.addr,def_counts); |
| 1632 | useBeforeDef_Expr(bb,stmt,stmt->Ist.STle.data,def_counts); |
| 1633 | break; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1634 | case Ist_Dirty: |
| 1635 | d = stmt->Ist.Dirty.details; |
| 1636 | for (i = 0; d->args[i] != NULL; i++) |
| 1637 | useBeforeDef_Expr(bb,stmt,d->args[i],def_counts); |
| 1638 | if (d->mFx != Ifx_None) |
| 1639 | useBeforeDef_Expr(bb,stmt,d->mAddr,def_counts); |
| 1640 | break; |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1641 | case Ist_Exit: |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 1642 | useBeforeDef_Expr(bb,stmt,stmt->Ist.Exit.guard,def_counts); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1643 | break; |
| 1644 | default: |
| 1645 | vpanic("useBeforeDef_Stmt"); |
| 1646 | } |
| 1647 | } |
| 1648 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1649 | static |
| 1650 | void tcExpr ( IRBB* bb, IRStmt* stmt, IRExpr* expr, IRType gWordTy ) |
| 1651 | { |
| 1652 | Int i; |
| 1653 | IRType t_dst, t_arg1, t_arg2; |
| 1654 | IRTypeEnv* tyenv = bb->tyenv; |
| 1655 | switch (expr->tag) { |
| 1656 | case Iex_Get: |
| 1657 | case Iex_Tmp: |
| 1658 | break; |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1659 | case Iex_GetI: |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1660 | tcExpr(bb,stmt, expr->Iex.GetI.ix, gWordTy ); |
| 1661 | if (typeOfIRExpr(tyenv,expr->Iex.GetI.ix) != Ity_I32) |
| 1662 | sanityCheckFail(bb,stmt,"IRExpr.GetI.ix: not :: Ity_I32"); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1663 | if (!saneIRArray(expr->Iex.GetI.descr)) |
| 1664 | sanityCheckFail(bb,stmt,"IRExpr.GetI.descr: invalid descr"); |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 1665 | break; |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1666 | case Iex_Binop: { |
| 1667 | IRType ttarg1, ttarg2; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1668 | tcExpr(bb,stmt, expr->Iex.Binop.arg1, gWordTy ); |
| 1669 | tcExpr(bb,stmt, expr->Iex.Binop.arg2, gWordTy ); |
| 1670 | typeOfPrimop(expr->Iex.Binop.op, &t_dst, &t_arg1, &t_arg2); |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 1671 | if (t_arg1 == Ity_INVALID || t_arg2 == Ity_INVALID) { |
| 1672 | vex_printf(" op name: " ); |
| 1673 | ppIROp(expr->Iex.Binop.op); |
| 1674 | vex_printf("\n"); |
| 1675 | sanityCheckFail(bb,stmt, |
| 1676 | "Iex.Binop: wrong arity op\n" |
| 1677 | "... name of op precedes BB printout\n"); |
| 1678 | } |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1679 | ttarg1 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg1); |
| 1680 | ttarg2 = typeOfIRExpr(tyenv, expr->Iex.Binop.arg2); |
| 1681 | if (t_arg1 != ttarg1 || t_arg2 != ttarg2) { |
| 1682 | vex_printf(" op name: "); |
| 1683 | ppIROp(expr->Iex.Binop.op); |
| 1684 | vex_printf("\n"); |
| 1685 | vex_printf(" op type is ("); |
| 1686 | ppIRType(t_arg1); |
| 1687 | vex_printf(","); |
| 1688 | ppIRType(t_arg2); |
| 1689 | vex_printf(") -> "); |
| 1690 | ppIRType (t_dst); |
| 1691 | vex_printf("\narg tys are ("); |
| 1692 | ppIRType(ttarg1); |
| 1693 | vex_printf(","); |
| 1694 | ppIRType(ttarg2); |
| 1695 | vex_printf(")\n"); |
| 1696 | sanityCheckFail(bb,stmt, |
| 1697 | "Iex.Binop: arg tys don't match op tys\n" |
| 1698 | "... additional details precede BB printout\n"); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1699 | } |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1700 | break; |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1701 | } |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1702 | case Iex_Unop: |
| 1703 | tcExpr(bb,stmt, expr->Iex.Unop.arg, gWordTy ); |
| 1704 | typeOfPrimop(expr->Iex.Binop.op, &t_dst, &t_arg1, &t_arg2); |
| 1705 | if (t_arg1 == Ity_INVALID || t_arg2 != Ity_INVALID) |
| 1706 | sanityCheckFail(bb,stmt,"Iex.Unop: wrong arity op"); |
| 1707 | if (t_arg1 != typeOfIRExpr(tyenv, expr->Iex.Unop.arg)) |
| 1708 | sanityCheckFail(bb,stmt,"Iex.Unop: arg ty doesn't match op ty"); |
| 1709 | break; |
| 1710 | case Iex_LDle: |
| 1711 | tcExpr(bb,stmt, expr->Iex.LDle.addr, gWordTy); |
| 1712 | if (typeOfIRExpr(tyenv, expr->Iex.LDle.addr) != gWordTy) |
| 1713 | sanityCheckFail(bb,stmt,"Iex.LDle.addr: not :: guest word type"); |
| 1714 | break; |
| 1715 | case Iex_CCall: |
sewardj | c13e2ed | 2004-10-31 21:44:54 +0000 | [diff] [blame] | 1716 | if (!saneIRCallee(expr->Iex.CCall.cee)) |
| 1717 | sanityCheckFail(bb,stmt,"Iex.CCall.cee: bad IRCallee"); |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 1718 | if (expr->Iex.CCall.cee->regparms > countArgs(expr->Iex.CCall.args)) |
sewardj | c13e2ed | 2004-10-31 21:44:54 +0000 | [diff] [blame] | 1719 | sanityCheckFail(bb,stmt,"Iex.CCall.cee: #regparms > #args"); |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 1720 | for (i = 0; expr->Iex.CCall.args[i]; i++) { |
| 1721 | if (i >= 32) |
| 1722 | sanityCheckFail(bb,stmt,"Iex.CCall: > 32 args"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1723 | tcExpr(bb,stmt, expr->Iex.CCall.args[i], gWordTy); |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 1724 | } |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1725 | if (expr->Iex.CCall.retty == Ity_I1) |
| 1726 | sanityCheckFail(bb,stmt,"Iex.CCall.retty: cannot return :: Ity_I1"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1727 | for (i = 0; expr->Iex.CCall.args[i]; i++) |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1728 | if (typeOfIRExpr(tyenv, expr->Iex.CCall.args[i]) == Ity_I1) |
| 1729 | sanityCheckFail(bb,stmt,"Iex.CCall.arg: arg :: Ity_I1"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1730 | break; |
| 1731 | case Iex_Const: |
sewardj | 49bfe67 | 2004-11-15 15:46:26 +0000 | [diff] [blame] | 1732 | if (!saneIRConst(expr->Iex.Const.con)) |
| 1733 | sanityCheckFail(bb,stmt,"Iex.Const.con: invalid const"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1734 | break; |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 1735 | case Iex_Mux0X: |
| 1736 | tcExpr(bb,stmt, expr->Iex.Mux0X.cond, gWordTy); |
| 1737 | tcExpr(bb,stmt, expr->Iex.Mux0X.expr0, gWordTy); |
| 1738 | tcExpr(bb,stmt, expr->Iex.Mux0X.exprX, gWordTy); |
| 1739 | if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.cond) != Ity_I8) |
| 1740 | sanityCheckFail(bb,stmt,"Iex.Mux0X.cond: cond :: Ity_I8"); |
| 1741 | if (typeOfIRExpr(tyenv, expr->Iex.Mux0X.expr0) |
| 1742 | != typeOfIRExpr(tyenv, expr->Iex.Mux0X.exprX)) |
| 1743 | sanityCheckFail(bb,stmt,"Iex.Mux0X: expr0/exprX mismatch"); |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 1744 | break; |
| 1745 | default: |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1746 | vpanic("tcExpr"); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | static |
| 1752 | void tcStmt ( IRBB* bb, IRStmt* stmt, IRType gWordTy ) |
| 1753 | { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1754 | Int i; |
| 1755 | IRDirty* d; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1756 | IRTypeEnv* tyenv = bb->tyenv; |
| 1757 | switch (stmt->tag) { |
| 1758 | case Ist_Put: |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1759 | tcExpr( bb, stmt, stmt->Ist.Put.data, gWordTy ); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1760 | if (typeOfIRExpr(tyenv,stmt->Ist.Put.data) == Ity_I1) |
| 1761 | sanityCheckFail(bb,stmt,"IRStmt.Put.data: cannot Put :: Ity_I1"); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1762 | break; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 1763 | case Ist_PutI: |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1764 | tcExpr( bb, stmt, stmt->Ist.PutI.data, gWordTy ); |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1765 | tcExpr( bb, stmt, stmt->Ist.PutI.ix, gWordTy ); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1766 | if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data) == Ity_I1) |
| 1767 | sanityCheckFail(bb,stmt,"IRStmt.PutI.data: cannot PutI :: Ity_I1"); |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1768 | if (typeOfIRExpr(tyenv,stmt->Ist.PutI.data) |
| 1769 | != stmt->Ist.PutI.descr->elemTy) |
| 1770 | sanityCheckFail(bb,stmt,"IRStmt.PutI.data: data ty != elem ty"); |
sewardj | eeac841 | 2004-11-02 00:26:55 +0000 | [diff] [blame] | 1771 | if (typeOfIRExpr(tyenv,stmt->Ist.PutI.ix) != Ity_I32) |
| 1772 | sanityCheckFail(bb,stmt,"IRStmt.PutI.ix: not :: Ity_I32"); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1773 | if (!saneIRArray(stmt->Ist.PutI.descr)) |
| 1774 | sanityCheckFail(bb,stmt,"IRStmt.PutI.descr: invalid descr"); |
| 1775 | break; |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1776 | case Ist_Tmp: |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1777 | tcExpr( bb, stmt, stmt->Ist.Tmp.data, gWordTy ); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1778 | if (typeOfIRTemp(tyenv, stmt->Ist.Tmp.tmp) |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 1779 | != typeOfIRExpr(tyenv, stmt->Ist.Tmp.data)) |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1780 | sanityCheckFail(bb,stmt,"IRStmt.Put.Tmp: tmp and expr do not match"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1781 | break; |
| 1782 | case Ist_STle: |
| 1783 | tcExpr( bb, stmt, stmt->Ist.STle.addr, gWordTy ); |
| 1784 | tcExpr( bb, stmt, stmt->Ist.STle.data, gWordTy ); |
| 1785 | if (typeOfIRExpr(tyenv, stmt->Ist.STle.addr) != gWordTy) |
| 1786 | sanityCheckFail(bb,stmt,"IRStmt.STle.addr: not :: guest word type"); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1787 | if (typeOfIRExpr(tyenv, stmt->Ist.STle.data) == Ity_I1) |
| 1788 | sanityCheckFail(bb,stmt,"IRStmt.STle.data: cannot STle :: Ity_I1"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1789 | break; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1790 | case Ist_Dirty: |
| 1791 | /* Mostly check for various kinds of ill-formed dirty calls. */ |
| 1792 | d = stmt->Ist.Dirty.details; |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1793 | if (d->cee == NULL) goto bad_dirty; |
| 1794 | if (!saneIRCallee(d->cee)) goto bad_dirty; |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 1795 | if (d->cee->regparms > countArgs(d->args)) goto bad_dirty; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1796 | if (d->mFx == Ifx_None) { |
| 1797 | if (d->mAddr != NULL || d->mSize != 0) |
| 1798 | goto bad_dirty; |
| 1799 | } else { |
| 1800 | if (d->mAddr == NULL || d->mSize == 0) |
| 1801 | goto bad_dirty; |
| 1802 | } |
| 1803 | if (d->nFxState < 0 || d->nFxState > VEX_N_FXSTATE) |
| 1804 | goto bad_dirty; |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1805 | if (d->nFxState == 0 && d->needsBBP) |
| 1806 | goto bad_dirty; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1807 | for (i = 0; i < d->nFxState; i++) { |
| 1808 | if (d->fxState[i].fx == Ifx_None) goto bad_dirty; |
| 1809 | if (d->fxState[i].size <= 0) goto bad_dirty; |
| 1810 | } |
| 1811 | /* check types, minimally */ |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1812 | if (d->guard == NULL) goto bad_dirty; |
sewardj | 49bfe67 | 2004-11-15 15:46:26 +0000 | [diff] [blame] | 1813 | tcExpr( bb, stmt, d->guard, gWordTy ); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1814 | if (typeOfIRExpr(tyenv, d->guard) != Ity_I1) |
| 1815 | sanityCheckFail(bb,stmt,"IRStmt.Dirty.guard not :: Ity_I1"); |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 1816 | if (d->tmp != IRTemp_INVALID |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1817 | && typeOfIRTemp(tyenv, d->tmp) == Ity_I1) |
| 1818 | sanityCheckFail(bb,stmt,"IRStmt.Dirty.dst :: Ity_I1"); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1819 | for (i = 0; d->args[i] != NULL; i++) { |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 1820 | if (i >= 32) |
| 1821 | sanityCheckFail(bb,stmt,"IRStmt.Dirty: > 32 args"); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1822 | if (typeOfIRExpr(tyenv, d->args[i]) == Ity_I1) |
| 1823 | sanityCheckFail(bb,stmt,"IRStmt.Dirty.arg[i] :: Ity_I1"); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1824 | } |
| 1825 | break; |
| 1826 | bad_dirty: |
| 1827 | sanityCheckFail(bb,stmt,"IRStmt.Dirty: ill-formed"); |
| 1828 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1829 | case Ist_Exit: |
sewardj | 0276d4b | 2004-11-15 15:30:21 +0000 | [diff] [blame] | 1830 | tcExpr( bb, stmt, stmt->Ist.Exit.guard, gWordTy ); |
| 1831 | if (typeOfIRExpr(tyenv,stmt->Ist.Exit.guard) != Ity_I1) |
| 1832 | sanityCheckFail(bb,stmt,"IRStmt.Exit.guard: not :: Ity_I1"); |
sewardj | 49bfe67 | 2004-11-15 15:46:26 +0000 | [diff] [blame] | 1833 | if (!saneIRConst(stmt->Ist.Exit.dst)) |
| 1834 | sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: bad dst"); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1835 | if (typeOfIRConst(stmt->Ist.Exit.dst) != gWordTy) |
| 1836 | sanityCheckFail(bb,stmt,"IRStmt.Exit.dst: not :: guest word type"); |
| 1837 | break; |
| 1838 | default: |
| 1839 | vpanic("tcStmt"); |
| 1840 | } |
| 1841 | } |
| 1842 | |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1843 | void sanityCheckIRBB ( IRBB* bb, IRType guest_word_size ) |
| 1844 | { |
| 1845 | Int i; |
| 1846 | IRStmt* stmt; |
| 1847 | Int n_temps = bb->tyenv->types_used; |
| 1848 | Int* def_counts = LibVEX_Alloc(n_temps * sizeof(Int)); |
| 1849 | |
| 1850 | vassert(guest_word_size == Ity_I32 |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1851 | || guest_word_size == Ity_I64); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1852 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1853 | if (bb->stmts_used < 0 || bb->stmts_size < 8 |
| 1854 | || bb->stmts_used > bb->stmts_size) |
| 1855 | /* this BB is so strange we can't even print it */ |
| 1856 | vpanic("sanityCheckIRBB: stmts array limits wierd"); |
| 1857 | |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1858 | /* Ensure each temp has a plausible type. */ |
| 1859 | for (i = 0; i < n_temps; i++) { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1860 | IRType ty = typeOfIRTemp(bb->tyenv,(IRTemp)i); |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1861 | if (!isPlausibleType(ty)) { |
| 1862 | vex_printf("Temp t%d declared with implausible type 0x%x\n", |
| 1863 | i, (UInt)ty); |
| 1864 | sanityCheckFail(bb,NULL,"Temp declared with implausible type"); |
| 1865 | } |
| 1866 | } |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1867 | |
| 1868 | /* Count the defs of each temp. Only one def is allowed. |
| 1869 | Also, check that each used temp has already been defd. */ |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 1870 | |
| 1871 | for (i = 0; i < n_temps; i++) |
| 1872 | def_counts[i] = 0; |
| 1873 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1874 | for (i = 0; i < bb->stmts_used; i++) { |
| 1875 | stmt = bb->stmts[i]; |
sewardj | 39e3f24 | 2004-08-18 16:54:52 +0000 | [diff] [blame] | 1876 | if (!stmt) |
| 1877 | continue; |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1878 | useBeforeDef_Stmt(bb,stmt,def_counts); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1879 | |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1880 | if (stmt->tag == Ist_Tmp) { |
| 1881 | if (stmt->Ist.Tmp.tmp < 0 || stmt->Ist.Tmp.tmp >= n_temps) |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1882 | sanityCheckFail(bb, stmt, |
| 1883 | "IRStmt.Tmp: destination tmp is out of range"); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1884 | def_counts[stmt->Ist.Tmp.tmp]++; |
| 1885 | if (def_counts[stmt->Ist.Tmp.tmp] > 1) |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1886 | sanityCheckFail(bb, stmt, |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 1887 | "IRStmt.Tmp: destination tmp is assigned more than once"); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1888 | } |
| 1889 | else |
| 1890 | if (stmt->tag == Ist_Dirty |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 1891 | && stmt->Ist.Dirty.details->tmp != IRTemp_INVALID) { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1892 | IRDirty* d = stmt->Ist.Dirty.details; |
| 1893 | if (d->tmp < 0 || d->tmp >= n_temps) |
| 1894 | sanityCheckFail(bb, stmt, |
| 1895 | "IRStmt.Dirty: destination tmp is out of range"); |
| 1896 | def_counts[d->tmp]++; |
| 1897 | if (def_counts[d->tmp] > 1) |
| 1898 | sanityCheckFail(bb, stmt, |
| 1899 | "IRStmt.Dirty: destination tmp is assigned more than once"); |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1903 | /* Typecheck everything. */ |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 1904 | for (i = 0; i < bb->stmts_used; i++) |
sewardj | 39e3f24 | 2004-08-18 16:54:52 +0000 | [diff] [blame] | 1905 | if (bb->stmts[i]) |
| 1906 | tcStmt( bb, bb->stmts[i], guest_word_size ); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1907 | if (typeOfIRExpr(bb->tyenv,bb->next) != guest_word_size) |
| 1908 | sanityCheckFail(bb, NULL, "bb->next field has wrong type"); |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
sewardj | 4345f7a | 2004-09-22 19:49:27 +0000 | [diff] [blame] | 1911 | /*---------------------------------------------------------------*/ |
| 1912 | /*--- Misc helper functions ---*/ |
| 1913 | /*---------------------------------------------------------------*/ |
| 1914 | |
| 1915 | Bool eqIRConst ( IRConst* c1, IRConst* c2 ) |
| 1916 | { |
| 1917 | if (c1->tag != c2->tag) |
| 1918 | return False; |
| 1919 | |
| 1920 | switch (c1->tag) { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1921 | case Ico_U1: return (1 & c1->Ico.U1) == (1 & c2->Ico.U1); |
sewardj | 4345f7a | 2004-09-22 19:49:27 +0000 | [diff] [blame] | 1922 | case Ico_U8: return c1->Ico.U8 == c2->Ico.U8; |
| 1923 | case Ico_U16: return c1->Ico.U16 == c2->Ico.U16; |
| 1924 | case Ico_U32: return c1->Ico.U32 == c2->Ico.U32; |
| 1925 | case Ico_U64: return c1->Ico.U64 == c2->Ico.U64; |
| 1926 | case Ico_F64: return c1->Ico.F64 == c2->Ico.F64; |
| 1927 | default: vpanic("eqIRConst"); |
| 1928 | } |
| 1929 | } |
| 1930 | |
sewardj | e98dcf2 | 2004-10-04 09:15:11 +0000 | [diff] [blame] | 1931 | Bool eqIRArray ( IRArray* descr1, IRArray* descr2 ) |
| 1932 | { |
| 1933 | return descr1->base == descr2->base |
| 1934 | && descr1->elemTy == descr2->elemTy |
| 1935 | && descr1->nElems == descr2->nElems; |
| 1936 | } |
| 1937 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1938 | Int sizeofIRType ( IRType ty ) |
| 1939 | { |
| 1940 | switch (ty) { |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1941 | case Ity_I8: return 1; |
| 1942 | case Ity_I16: return 2; |
| 1943 | case Ity_I32: return 4; |
| 1944 | case Ity_I64: return 8; |
| 1945 | case Ity_F32: return 4; |
| 1946 | case Ity_F64: return 8; |
| 1947 | case Ity_V128: return 16; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 1948 | default: vex_printf("\n"); ppIRType(ty); vex_printf("\n"); |
| 1949 | vpanic("sizeofIRType"); |
| 1950 | } |
| 1951 | } |
| 1952 | |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1953 | IRExpr* mkIRExpr_HWord ( HWord hw ) |
| 1954 | { |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1955 | vassert(sizeof(void*) == sizeof(HWord)); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1956 | if (sizeof(HWord) == 4) |
| 1957 | return IRExpr_Const(IRConst_U32((UInt)hw)); |
| 1958 | if (sizeof(HWord) == 8) |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1959 | return IRExpr_Const(IRConst_U64((ULong)hw)); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1960 | vpanic("mkIRExpr_HWord"); |
| 1961 | } |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 1962 | |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1963 | IRDirty* unsafeIRDirty_0_N ( Int regparms, Char* name, void* addr, |
| 1964 | IRExpr** args ) |
| 1965 | { |
| 1966 | IRDirty* d = emptyIRDirty(); |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1967 | d->cee = mkIRCallee ( regparms, name, addr ); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1968 | d->guard = IRExpr_Const(IRConst_U1(True)); |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1969 | d->args = args; |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1970 | return d; |
| 1971 | } |
| 1972 | |
| 1973 | IRDirty* unsafeIRDirty_1_N ( IRTemp dst, |
| 1974 | Int regparms, Char* name, void* addr, |
| 1975 | IRExpr** args ) |
| 1976 | { |
| 1977 | IRDirty* d = emptyIRDirty(); |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1978 | d->cee = mkIRCallee ( regparms, name, addr ); |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 1979 | d->guard = IRExpr_Const(IRConst_U1(True)); |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1980 | d->args = args; |
| 1981 | d->tmp = dst; |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1982 | return d; |
| 1983 | } |
| 1984 | |
| 1985 | IRExpr* mkIRExprCCall ( IRType retty, |
| 1986 | Int regparms, Char* name, void* addr, |
| 1987 | IRExpr** args ) |
| 1988 | { |
| 1989 | return IRExpr_CCall ( mkIRCallee ( regparms, name, addr ), |
| 1990 | retty, args ); |
| 1991 | } |
| 1992 | |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 1993 | /*---------------------------------------------------------------*/ |
sewardj | c0ee2ed | 2004-07-27 10:29:41 +0000 | [diff] [blame] | 1994 | /*--- end ir/irdefs.c ---*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 1995 | /*---------------------------------------------------------------*/ |