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