sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 4 | /*--- This file (libvex_ir.h) 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 | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 9 | #ifndef __LIBVEX_IR_H |
| 10 | #define __LIBVEX_IR_H |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 11 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 12 | #include "libvex_basictypes.h" |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 13 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 14 | |
| 15 | /*---------------------------------------------------------------*/ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 16 | /*--- Type definitions for the IR ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 17 | /*---------------------------------------------------------------*/ |
| 18 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 19 | /* ------------------ Types ------------------ */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 20 | |
| 21 | typedef |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 22 | enum { Ity_INVALID=0x10FFF, |
| 23 | Ity_Bit=0x11000, |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 24 | Ity_I8, Ity_I16, Ity_I32, Ity_I64, |
| 25 | Ity_F32, Ity_F64 |
| 26 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 27 | IRType; |
| 28 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 29 | extern void ppIRType ( IRType ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 30 | extern Int sizeofIRType ( IRType ); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 31 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 32 | |
| 33 | /* ------------------ Constants ------------------ */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 34 | |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 35 | typedef |
sewardj | 51cba89 | 2004-08-20 00:09:03 +0000 | [diff] [blame] | 36 | enum { Ico_Bit=0x12000, |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 37 | Ico_U8, Ico_U16, Ico_U32, Ico_U64, |
| 38 | Ico_F64, /* 64-bit IEEE754 floating */ |
| 39 | Ico_F64i /* 64-bit unsigned int to be interpreted literally |
| 40 | as a IEEE754 double value. */ |
sewardj | 207557a | 2004-08-27 12:00:18 +0000 | [diff] [blame] | 41 | } |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 42 | IRConstTag; |
| 43 | |
| 44 | typedef |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 45 | struct _IRConst { |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 46 | IRConstTag tag; |
| 47 | union { |
sewardj | 51cba89 | 2004-08-20 00:09:03 +0000 | [diff] [blame] | 48 | Bool Bit; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 49 | UChar U8; |
| 50 | UShort U16; |
| 51 | UInt U32; |
| 52 | ULong U64; |
sewardj | a58ea66 | 2004-08-15 03:12:41 +0000 | [diff] [blame] | 53 | Double F64; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 54 | ULong F64i; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 55 | } Ico; |
| 56 | } |
| 57 | IRConst; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 58 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 59 | extern IRConst* IRConst_Bit ( Bool ); |
| 60 | extern IRConst* IRConst_U8 ( UChar ); |
| 61 | extern IRConst* IRConst_U16 ( UShort ); |
| 62 | extern IRConst* IRConst_U32 ( UInt ); |
| 63 | extern IRConst* IRConst_U64 ( ULong ); |
| 64 | extern IRConst* IRConst_F64 ( Double ); |
| 65 | extern IRConst* IRConst_F64i ( ULong ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 66 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 67 | extern IRConst* dopyIRConst ( IRConst* ); |
| 68 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 69 | extern void ppIRConst ( IRConst* ); |
sewardj | 4345f7a | 2004-09-22 19:49:27 +0000 | [diff] [blame] | 70 | extern Bool eqIRConst ( IRConst*, IRConst* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 71 | |
| 72 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 73 | /* ------------------ Call targets ------------------ */ |
| 74 | |
| 75 | /* Describes a helper function to call. The name part is purely for |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 76 | pretty printing and not actually used. regparms=n tells the back |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 77 | end that the callee has been declared |
| 78 | "__attribute__((regparm(n)))". On some targets (x86) the back end |
| 79 | will need to construct a non-standard sequence to call a function |
| 80 | declared like this. */ |
| 81 | |
| 82 | typedef |
| 83 | struct { |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 84 | Int regparms; |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 85 | Char* name; |
| 86 | HWord addr; |
| 87 | } |
| 88 | IRCallee; |
| 89 | |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 90 | extern IRCallee* mkIRCallee ( Int regparms, Char* name, HWord addr ); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 91 | |
| 92 | extern IRCallee* dopyIRCallee ( IRCallee* ); |
| 93 | |
| 94 | extern void ppIRCallee ( IRCallee* ); |
| 95 | |
| 96 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 97 | /* ------------------ Guest state arrays ------------------ */ |
| 98 | |
| 99 | typedef |
| 100 | struct { |
| 101 | Int base; |
| 102 | IRType elemTy; |
| 103 | Int nElems; |
| 104 | } |
| 105 | IRArray; |
| 106 | |
| 107 | extern IRArray* mkIRArray ( Int, IRType, Int ); |
| 108 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 109 | extern IRArray* dopyIRArray ( IRArray* ); |
| 110 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 111 | extern void ppIRArray ( IRArray* ); |
sewardj | e98dcf2 | 2004-10-04 09:15:11 +0000 | [diff] [blame] | 112 | extern Bool eqIRArray ( IRArray*, IRArray* ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 113 | |
| 114 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 115 | /* ------------------ Temporaries ------------------ */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 116 | |
sewardj | 1c19276 | 2004-10-14 00:28:15 +0000 | [diff] [blame] | 117 | /* The IR optimiser relies on the fact that IRTemps are 32-bit |
| 118 | ints. Do not change them to be ints of any other size. */ |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 119 | typedef UInt IRTemp; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 120 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 121 | extern void ppIRTemp ( IRTemp ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 122 | |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 123 | #define INVALID_IRTEMP ((IRTemp)0xFFFFFFFF) |
| 124 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 125 | |
| 126 | /* ------------------ Binary and unary ops ------------------ */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 127 | |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 128 | typedef |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 129 | enum { |
| 130 | /* Do not change this ordering. The IR generators |
| 131 | rely on (eg) Iop_Add64 == IopAdd8 + 3. */ |
sewardj | 66de227 | 2004-07-16 21:19:05 +0000 | [diff] [blame] | 132 | Iop_INVALID=0x13000, |
| 133 | Iop_Add8, Iop_Add16, Iop_Add32, Iop_Add64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 134 | Iop_Sub8, Iop_Sub16, Iop_Sub32, Iop_Sub64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 135 | /* Signless mul. MullS/MullU is elsewhere. */ |
| 136 | Iop_Mul8, Iop_Mul16, Iop_Mul32, Iop_Mul64, |
| 137 | Iop_Or8, Iop_Or16, Iop_Or32, Iop_Or64, |
| 138 | Iop_And8, Iop_And16, Iop_And32, Iop_And64, |
| 139 | Iop_Xor8, Iop_Xor16, Iop_Xor32, Iop_Xor64, |
| 140 | Iop_Shl8, Iop_Shl16, Iop_Shl32, Iop_Shl64, |
| 141 | Iop_Shr8, Iop_Shr16, Iop_Shr32, Iop_Shr64, |
| 142 | Iop_Sar8, Iop_Sar16, Iop_Sar32, Iop_Sar64, |
sewardj | e90ad6a | 2004-07-10 19:02:10 +0000 | [diff] [blame] | 143 | /* Integer comparisons. */ |
| 144 | Iop_CmpEQ8, Iop_CmpEQ16, Iop_CmpEQ32, Iop_CmpEQ64, |
| 145 | Iop_CmpNE8, Iop_CmpNE16, Iop_CmpNE32, Iop_CmpNE64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 146 | /* Tags for unary ops */ |
| 147 | Iop_Not8, Iop_Not16, Iop_Not32, Iop_Not64, |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 148 | Iop_Neg8, Iop_Neg16, Iop_Neg32, Iop_Neg64, |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 149 | /* Widening multiplies */ |
| 150 | Iop_MullS8, Iop_MullS16, Iop_MullS32, |
| 151 | Iop_MullU8, Iop_MullU16, Iop_MullU32, |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 152 | |
sewardj | ce646f2 | 2004-08-31 23:55:54 +0000 | [diff] [blame] | 153 | /* Wierdo integer stuff */ |
| 154 | Iop_Clz32, /* count leading zeroes */ |
| 155 | Iop_Ctz32, /* count trailing zeros */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 156 | /* Ctz32/Clz32 are UNDEFINED when given arguments of zero. |
| 157 | You must ensure they are never given a zero argument. |
| 158 | */ |
| 159 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 160 | /* Ordering not important after here. */ |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 161 | Iop_CmpLT32S, |
| 162 | Iop_CmpLE32S, |
| 163 | Iop_CmpLT32U, |
| 164 | Iop_CmpLE32U, |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 165 | /* Division */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 166 | /* TODO: clarify semantics wrt rounding, negative values, whatever */ |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 167 | Iop_DivModU64to32, // :: I64,I32 -> I64 |
| 168 | // of which lo half is div and hi half is mod |
| 169 | Iop_DivModS64to32, // ditto, signed |
sewardj | 89d4e98 | 2004-09-12 19:14:46 +0000 | [diff] [blame] | 170 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 171 | /* Widening conversions */ |
sewardj | e5427e8 | 2004-09-11 19:43:51 +0000 | [diff] [blame] | 172 | Iop_8Uto16, Iop_8Uto32, Iop_16Uto32, Iop_32Uto64, |
sewardj | bb53f8c | 2004-08-14 11:50:01 +0000 | [diff] [blame] | 173 | Iop_8Sto16, Iop_8Sto32, Iop_16Sto32, Iop_32Sto64, |
sewardj | a238471 | 2004-07-29 14:36:40 +0000 | [diff] [blame] | 174 | /* Narrowing conversions */ |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 175 | Iop_32to8, |
sewardj | b81f8b3 | 2004-07-30 10:17:50 +0000 | [diff] [blame] | 176 | /* 8 <-> 16 bit conversions */ |
| 177 | Iop_16to8, // :: I16 -> I8, low half |
| 178 | Iop_16HIto8, // :: I16 -> I8, high half |
| 179 | Iop_8HLto16, // :: (I8,I8) -> I16 |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 180 | /* 16 <-> 32 bit conversions */ |
| 181 | Iop_32to16, // :: I32 -> I16, low half |
| 182 | Iop_32HIto16, // :: I32 -> I16, high half |
| 183 | Iop_16HLto32, // :: (I16,I16) -> I32 |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 184 | /* 32 <-> 64 bit conversions */ |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 185 | Iop_64to32, // :: I64 -> I32, low half |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 186 | Iop_64HIto32, // :: I64 -> I32, high half |
| 187 | Iop_32HLto64, // :: (I32,I32) -> I64 |
sewardj | cf780b4 | 2004-07-13 18:42:17 +0000 | [diff] [blame] | 188 | /* 1-bit stuff */ |
sewardj | 6e797c5 | 2004-10-13 15:20:17 +0000 | [diff] [blame] | 189 | Iop_Not1, /* :: Ity_Bit -> Ity_Bit */ |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 190 | Iop_32to1, /* :: Ity_I32 -> Ity_Bit, just select bit[0] */ |
| 191 | Iop_1Uto8, /* :: Ity_Bit -> Ity_I8, unsigned widen */ |
| 192 | Iop_1Uto32, /* :: Ity_Bit -> Ity_I32, unsigned widen */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 193 | |
| 194 | /* ------ Floating point. We try and be IEEE754 compliant. ------ */ |
| 195 | |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 196 | /* Binary operations mandated by IEEE754. */ |
sewardj | 46de407 | 2004-09-11 19:23:24 +0000 | [diff] [blame] | 197 | Iop_AddF64, Iop_SubF64, Iop_MulF64, Iop_DivF64, /* Iop_RemF64, */ |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 198 | |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 199 | /* Binary ops supported by IA32 but not mandated by 754. */ |
sewardj | 442d0be | 2004-10-15 22:57:13 +0000 | [diff] [blame] | 200 | Iop_AtanF64, /* FPATAN, arctan(arg1/arg2) */ |
| 201 | Iop_Yl2xF64, /* FYL2X, arg1 * log2(arg2) */ |
| 202 | Iop_Yl2xp1F64, /* FYL2XP1, arg1 * log2(arg2+1.0) */ |
| 203 | Iop_PRemF64, /* FPREM, non-IEEE remainder(arg1/arg2) */ |
| 204 | Iop_PRemC3210F64, /* C3210 flags resulting from FPREM, :: I32 */ |
| 205 | Iop_PRem1F64, /* FPREM1, IEEE remainder(arg1/arg2) */ |
| 206 | Iop_PRem1C3210F64, /* C3210 flags resulting from FPREM1, :: I32 */ |
| 207 | Iop_ScaleF64, /* FSCALE, arg1 * (2^RoundTowardsZero(arg2)) */ |
| 208 | /* Note that on x86 guest, PRem1{C3210} has the same behaviour |
| 209 | as the IEEE mandated RemF64, except it is limited in the |
| 210 | range of its operand. Hence the partialness. */ |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 211 | |
| 212 | /* Unary operations mandated by IEEE754. */ |
| 213 | Iop_NegF64, Iop_SqrtF64, |
| 214 | |
| 215 | /* Unary ops supported by IA32 but not mandated by 754. */ |
| 216 | Iop_AbsF64, /* FABS */ |
| 217 | Iop_SinF64, /* FSIN */ |
| 218 | Iop_CosF64, /* FCOS */ |
sewardj | 99016a7 | 2004-10-15 22:09:17 +0000 | [diff] [blame] | 219 | Iop_TanF64, /* FTAN */ |
sewardj | 06c32a0 | 2004-09-12 12:07:34 +0000 | [diff] [blame] | 220 | Iop_2xm1F64, /* (2^arg - 1.0) */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 221 | |
| 222 | /* Comparison, yielding GT/LT/EQ/UN(ordered), as per the following: |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 223 | 0x45 Unordered |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 224 | 0x01 LT |
| 225 | 0x00 GT |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 226 | 0x40 EQ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 227 | This just happens to be the Intel encoding. The values |
| 228 | are recorded in the type IRCmpF64Result. |
| 229 | */ |
| 230 | Iop_CmpF64, |
| 231 | |
| 232 | /* int -> double */ |
| 233 | Iop_I32toF64, Iop_I64toF64, |
| 234 | |
| 235 | /* double -> int. These take a first argument :: Ity_I32 |
| 236 | (an IRRoundingMode) which is an indication of the rounding mode, |
| 237 | as per the following encoding: |
| 238 | 00b to nearest (the default) |
| 239 | 01b to -infinity |
| 240 | 10b to +infinity |
| 241 | 11b to zero |
| 242 | This just happens to be the Intel encoding. For reference only, |
| 243 | the PPC encoding is: |
| 244 | 00b to nearest (the default) |
| 245 | 01b to zero |
| 246 | 10b to +infinity |
| 247 | 11b to -infinity |
| 248 | Any PPC -> IR front end will have to translate these PPC |
| 249 | encodings to the standard encodings. |
| 250 | |
| 251 | If one of these conversions gets an out-of-range condition, |
| 252 | or a NaN, as an argument, the result is host-defined. On x86 |
| 253 | the "integer indefinite" value 0x80..00 is produced. |
| 254 | On PPC it is either 0x80..00 or 0x7F..FF depending on the sign |
| 255 | of the argument. |
| 256 | */ |
| 257 | Iop_F64toI64, Iop_F64toI32, Iop_F64toI16, |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 258 | |
sewardj | e670911 | 2004-09-10 18:37:18 +0000 | [diff] [blame] | 259 | /* F64 -> F64, also takes an I32 first argument encoding the |
| 260 | rounding mode. */ |
| 261 | Iop_RoundF64, |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 262 | |
| 263 | /* double <-> float. What does this mean -- does it round? */ |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 264 | Iop_F32toF64, Iop_F64toF32, |
| 265 | |
| 266 | /* Reinterpretation. Take an F64 and produce an I64 with |
| 267 | the same bit pattern, or vice versa. */ |
| 268 | Iop_ReinterpF64asI64, Iop_ReinterpI64asF64 |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 269 | } |
| 270 | IROp; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 271 | |
sewardj | ce646f2 | 2004-08-31 23:55:54 +0000 | [diff] [blame] | 272 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 273 | extern void ppIROp ( IROp ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 274 | |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 275 | |
sewardj | c9868d7 | 2004-09-12 19:19:17 +0000 | [diff] [blame] | 276 | |
| 277 | /* Encoding of IEEE754-specified rounding modes in Float -> Int |
| 278 | conversions. This is the same as the encoding used by Intel IA32 |
| 279 | to indicate x87 rounding mode. */ |
| 280 | typedef |
| 281 | enum { Irrm_NEAREST=0, Irrm_NegINF=1, Irrm_PosINF=2, Irrm_ZERO=3 } |
| 282 | IRRoundingMode; |
| 283 | |
| 284 | /* Floating point comparison result values, as created by Iop_CmpF64. |
| 285 | This is also derived from what IA32 does. */ |
| 286 | typedef |
| 287 | enum { |
| 288 | Ircr_UN = 0x45, |
| 289 | Ircr_LT = 0x01, |
| 290 | Ircr_GT = 0x00, |
| 291 | Ircr_EQ = 0x40 |
| 292 | } |
| 293 | IRCmpF64Result; |
| 294 | |
| 295 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 296 | /* ------------------ Expressions ------------------ */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 297 | /* |
| 298 | Some details of expression semantics: |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 299 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 300 | IRExpr_GetI (also IRStmt_PutI) |
| 301 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 302 | This carries two ints, which give the lowest and highest possible |
| 303 | byte offsets that the GetI can possibly reference. For example, if |
| 304 | the type is Ity_I32, and the Expr may have a value of M, M+4 or |
| 305 | M+8, where M is a translation-time known constant, then the low and |
| 306 | high limits are M and M+11 respectively. |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 307 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 308 | PutI's limit values are interpreted identically. |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 309 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 310 | The limit values are used by IR optimisers to establish |
| 311 | aliasing/non-aliasing between seperate GetI and PutI events, which |
| 312 | could be used to do reordering of them, or suchlike things. |
| 313 | Clearly it's critical to give the correct limit values -- this is |
| 314 | something that can't be automatically checked (in general), and so |
| 315 | the front-end writers must be very careful to tell the truth, since |
| 316 | not doing so could lead to obscure IR optimisation bugs. |
| 317 | |
| 318 | IRExpr_CCall |
| 319 | ~~~~~~~~~~~~ |
| 320 | The name is the C helper function; the backends will call back to |
| 321 | the front ends to get the address of a host-code helper function to |
| 322 | be called. |
| 323 | |
| 324 | The args are a NULL-terminated array of arguments. The stated |
| 325 | return IRType, and the implied argument types, must match that of |
| 326 | the function being called well enough so that the back end can |
| 327 | actually generate correct code for the call. |
| 328 | |
| 329 | The called function **must** satisfy the following: |
| 330 | |
| 331 | * no side effects -- must be a pure function, the result of which |
| 332 | depends only on the passed parameters. |
| 333 | |
| 334 | * it may not look at, nor modify, any of the guest state since that |
| 335 | would hide guest state transitions from instrumenters |
| 336 | |
| 337 | * it may not access guest memory, since that would hide guest |
| 338 | memory transactions from the instrumenters |
| 339 | |
| 340 | This is restrictive, but makes the semantics clean, and does |
| 341 | not interfere with IR optimisation. |
| 342 | |
| 343 | If you want to call a helper which can mess with guest state and/or |
| 344 | memory, instead use IRStmt_Dirty. This is a lot more flexible, but |
| 345 | you pay for that flexibility in that you have to give a bunch of |
| 346 | details about what the helper does (and you better be telling the |
| 347 | truth, otherwise any derived instrumentation will be wrong). Also |
| 348 | IRStmt_Dirty inhibits various IR optimisations and so can cause |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 349 | quite poor code to be generated. Try to avoid it. |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 350 | */ |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 351 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 352 | /* The possible kinds of expressions are as follows: */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 353 | typedef |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 354 | enum { |
| 355 | Iex_Binder, /* Used only in pattern matching. |
| 356 | Not an expression. */ |
| 357 | Iex_Get, /* read guest state, fixed offset */ |
| 358 | Iex_GetI, /* read guest state, run-time offset */ |
| 359 | Iex_Tmp, /* value of temporary */ |
| 360 | Iex_Binop, /* binary operation */ |
| 361 | Iex_Unop, /* unary operation */ |
| 362 | Iex_LDle, /* little-endian read from memory */ |
| 363 | Iex_Const, /* constant-valued expression */ |
| 364 | Iex_Mux0X, /* ternary if-then-else operator (STRICT) */ |
| 365 | Iex_CCall /* call to pure (side-effect-free) helper fn */ |
| 366 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 367 | IRExprTag; |
| 368 | |
| 369 | typedef |
| 370 | struct _IRExpr { |
| 371 | IRExprTag tag; |
| 372 | union { |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 373 | struct { |
| 374 | Int binder; |
| 375 | } Binder; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 376 | struct { |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 377 | Int offset; |
| 378 | IRType ty; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 379 | } Get; |
| 380 | struct { |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 381 | IRArray* descr; |
| 382 | struct _IRExpr* off; |
| 383 | Int bias; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 384 | } GetI; |
| 385 | struct { |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 386 | IRTemp tmp; |
| 387 | } Tmp; |
| 388 | struct { |
| 389 | IROp op; |
| 390 | struct _IRExpr* arg1; |
| 391 | struct _IRExpr* arg2; |
| 392 | } Binop; |
| 393 | struct { |
| 394 | IROp op; |
| 395 | struct _IRExpr* arg; |
| 396 | } Unop; |
| 397 | struct { |
| 398 | IRType ty; |
| 399 | struct _IRExpr* addr; |
| 400 | } LDle; |
| 401 | struct { |
sewardj | 66f2f79 | 2004-06-30 16:37:16 +0000 | [diff] [blame] | 402 | IRConst* con; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 403 | } Const; |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 404 | struct { |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 405 | IRCallee* cee; |
| 406 | IRType retty; |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 407 | struct _IRExpr** args; |
| 408 | } CCall; |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 409 | struct { |
| 410 | struct _IRExpr* cond; |
sewardj | eeb9ef8 | 2004-07-15 12:39:03 +0000 | [diff] [blame] | 411 | struct _IRExpr* expr0; |
sewardj | 4042c7e | 2004-07-18 01:28:30 +0000 | [diff] [blame] | 412 | struct _IRExpr* exprX; |
| 413 | } Mux0X; |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 414 | } Iex; |
| 415 | } |
| 416 | IRExpr; |
| 417 | |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 418 | extern IRExpr* IRExpr_Binder ( Int binder ); |
| 419 | extern IRExpr* IRExpr_Get ( Int off, IRType ty ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 420 | extern IRExpr* IRExpr_GetI ( IRArray* descr, IRExpr* off, Int bias ); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 421 | extern IRExpr* IRExpr_Tmp ( IRTemp tmp ); |
| 422 | extern IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 ); |
| 423 | extern IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg ); |
| 424 | extern IRExpr* IRExpr_LDle ( IRType ty, IRExpr* addr ); |
| 425 | extern IRExpr* IRExpr_Const ( IRConst* con ); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 426 | extern IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args ); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 427 | extern IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX ); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 428 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 429 | extern IRExpr* dopyIRExpr ( IRExpr* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 430 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 431 | extern void ppIRExpr ( IRExpr* ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 432 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 433 | /* NULL-terminated IRExpr expression vectors, suitable for use as arg |
| 434 | lists in clean/dirty helper calls. */ |
| 435 | |
| 436 | extern IRExpr** mkIRExprVec_0 ( void ); |
| 437 | extern IRExpr** mkIRExprVec_1 ( IRExpr* arg1 ); |
| 438 | extern IRExpr** mkIRExprVec_2 ( IRExpr* arg1, IRExpr* arg2 ); |
| 439 | |
| 440 | extern IRExpr** sopyIRExprVec ( IRExpr** ); |
| 441 | extern IRExpr** dopyIRExprVec ( IRExpr** ); |
| 442 | |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 443 | /* Make a constant expression from the given host word, |
| 444 | taking into account of course the host word size. */ |
| 445 | extern IRExpr* mkIRExpr_HWord ( HWord ); |
| 446 | |
| 447 | |
| 448 | inline static Bool isAtom ( IRExpr* e ) { |
| 449 | return e->tag == Iex_Tmp || e->tag == Iex_Const; |
| 450 | } |
| 451 | |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 452 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 453 | /* ------------------ Dirty helper calls ------------------ */ |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 454 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 455 | /* A dirty call is a flexible mechanism for calling a helper function |
| 456 | or procedure. The helper function may read, write or modify client |
| 457 | memory, and may read, write or modify client state. It can take |
| 458 | arguments and optionally return a value. It may return different |
| 459 | results and/or do different things when called repeated with the |
| 460 | same arguments, by means of storing private state. |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 461 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 462 | If a value is returned, it is assigned to the nominated return |
| 463 | temporary. |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 464 | |
| 465 | Dirty calls are statements rather than expressions for obvious |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 466 | reasons. If a dirty call is stated as writing guest state, any |
| 467 | values derived from the written parts of the guest state are |
| 468 | invalid. Similarly, if the dirty call is stated as writing |
| 469 | memory, any loaded values are invalidated by it. |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 470 | |
| 471 | In order that instrumentation is possible, the call must state, and |
| 472 | state correctly |
| 473 | |
| 474 | * whether it reads, writes or modifies memory, and if so where |
| 475 | (only one chunk can be stated) |
| 476 | |
| 477 | * whether it reads, writes or modifies guest state, and if so which |
| 478 | pieces (several pieces may be stated, and currently their extents |
| 479 | must be known at translation-time). |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 480 | |
| 481 | Normally, code is generated to pass just the args to the helper. |
| 482 | However, if .needsBBP is set, then an extra first argument is |
| 483 | passed, which is the baseblock pointer, so that the callee can |
| 484 | access the guest state. It is invalid for .nFxState to be zero |
| 485 | but .needsBBP to be True, since .nFxState==0 is a claim that the |
| 486 | call does not access guest state. |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 487 | */ |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 488 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 489 | #define VEX_N_FXSTATE 4 /* enough for CPUID on x86 */ |
| 490 | |
| 491 | typedef |
| 492 | enum { |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 493 | Ifx_None = 0x15000, /* no effect */ |
| 494 | Ifx_Read, /* reads the resource */ |
| 495 | Ifx_Write, /* writes the resource */ |
| 496 | Ifx_Modify, /* modifies the resource */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 497 | } |
| 498 | IREffect; |
| 499 | |
| 500 | extern void ppIREffect ( IREffect ); |
| 501 | |
| 502 | |
| 503 | typedef |
| 504 | struct { |
| 505 | /* What to call, and details of args/results */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 506 | IRCallee* cee; /* where to call */ |
| 507 | IRExpr** args; /* arg list, ends in NULL */ |
| 508 | IRTemp tmp; /* to assign result to, or INVALID_IRTEMP if none */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 509 | |
| 510 | /* Mem effects; we allow only one R/W/M region to be stated */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 511 | IREffect mFx; /* indicates memory effects, if any */ |
| 512 | IRExpr* mAddr; /* of access, or NULL if mFx==Ifx_None */ |
| 513 | Int mSize; /* of access, or zero if mFx==Ifx_None */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 514 | |
| 515 | /* Guest state effects; up to N allowed */ |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 516 | Bool needsBBP; /* True => also pass guest state ptr to callee */ |
| 517 | Int nFxState; /* must be 0 .. VEX_N_FXSTATE */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 518 | struct { |
| 519 | IREffect fx; /* read, write or modify? */ |
| 520 | Int offset; |
| 521 | Int size; |
| 522 | } fxState[VEX_N_FXSTATE]; |
| 523 | } |
| 524 | IRDirty; |
| 525 | |
| 526 | extern void ppIRDirty ( IRDirty* ); |
| 527 | extern IRDirty* emptyIRDirty ( void ); |
| 528 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 529 | extern IRDirty* dopyIRDirty ( IRDirty* ); |
| 530 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 531 | /* A handy function which takes some of the tedium out of constructing |
| 532 | dirty helper calls. The called function impliedly does not return |
| 533 | any value. The call is marked as accessing neither guest state nor |
| 534 | memory (hence the "unsafe" designation) -- you can mess with this |
| 535 | later if need be.*/ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 536 | extern IRDirty* unsafeIRDirty_0_N ( IRCallee* cee, IRExpr** args ); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 537 | |
| 538 | /* Similarly, make a zero-annotation dirty call which returns a value, |
| 539 | and assign that to the given temp. */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 540 | extern IRDirty* unsafeIRDirty_1_N ( IRTemp dst, IRCallee* cee, IRExpr** args ); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 541 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 542 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 543 | /* ------------------ Statements ------------------ */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 544 | |
| 545 | /* The possible kinds of statements are as follows: */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 546 | typedef |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 547 | enum { |
| 548 | Ist_Put, /* write guest state, fixed offset */ |
| 549 | Ist_PutI, /* write guest state, run-time offset */ |
| 550 | Ist_Tmp, /* assign value to temporary */ |
| 551 | Ist_STle, /* little-endian write to memory */ |
| 552 | Ist_Dirty, /* call complex ("dirty") helper function */ |
| 553 | Ist_Exit /* conditional exit from BB */ |
| 554 | } |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 555 | IRStmtTag; |
| 556 | |
| 557 | typedef |
| 558 | struct _IRStmt { |
| 559 | IRStmtTag tag; |
| 560 | union { |
| 561 | struct { |
| 562 | Int offset; |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 563 | IRExpr* data; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 564 | } Put; |
| 565 | struct { |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 566 | IRArray* descr; |
| 567 | IRExpr* off; |
| 568 | Int bias; |
| 569 | IRExpr* data; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 570 | } PutI; |
| 571 | struct { |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 572 | IRTemp tmp; |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 573 | IRExpr* data; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 574 | } Tmp; |
| 575 | struct { |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 576 | IRExpr* addr; |
| 577 | IRExpr* data; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 578 | } STle; |
sewardj | 64e1d65 | 2004-07-12 14:00:46 +0000 | [diff] [blame] | 579 | struct { |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 580 | IRDirty* details; |
| 581 | } Dirty; |
| 582 | struct { |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 583 | IRExpr* cond; |
sewardj | 64e1d65 | 2004-07-12 14:00:46 +0000 | [diff] [blame] | 584 | IRConst* dst; |
| 585 | } Exit; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 586 | } Ist; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 587 | } |
| 588 | IRStmt; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 589 | |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 590 | extern IRStmt* IRStmt_Put ( Int off, IRExpr* data ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 591 | extern IRStmt* IRStmt_PutI ( IRArray* descr, IRExpr* off, Int bias, |
| 592 | IRExpr* data ); |
sewardj | 6d07636 | 2004-09-23 11:06:17 +0000 | [diff] [blame] | 593 | extern IRStmt* IRStmt_Tmp ( IRTemp tmp, IRExpr* data ); |
| 594 | extern IRStmt* IRStmt_STle ( IRExpr* addr, IRExpr* data ); |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 595 | extern IRStmt* IRStmt_Dirty ( IRDirty* details ); |
| 596 | extern IRStmt* IRStmt_Exit ( IRExpr* cond, IRConst* dst ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 597 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 598 | extern IRStmt* dopyIRStmt ( IRStmt* ); |
| 599 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 600 | extern void ppIRStmt ( IRStmt* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 601 | |
| 602 | |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 603 | /* ------------------ Basic Blocks ------------------ */ |
sewardj | 78c19df | 2004-07-12 22:49:27 +0000 | [diff] [blame] | 604 | |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 605 | /* This describes the unconditional jumps which implicitly happen at |
| 606 | the end of each basic block. Conditional jumps -- which can only |
| 607 | be done with the IRStmt_Exit statement -- are implicitly of the |
| 608 | Ijk_Boring kind. */ |
| 609 | |
sewardj | 78c19df | 2004-07-12 22:49:27 +0000 | [diff] [blame] | 610 | typedef |
| 611 | enum { |
sewardj | e8e9d73 | 2004-07-16 21:03:45 +0000 | [diff] [blame] | 612 | Ijk_Boring=0x14000, /* not interesting; just goto next */ |
sewardj | 78c19df | 2004-07-12 22:49:27 +0000 | [diff] [blame] | 613 | Ijk_Call, /* guest is doing a call */ |
| 614 | Ijk_Ret, /* guest is doing a return */ |
| 615 | Ijk_ClientReq, /* do guest client req before continuing */ |
| 616 | Ijk_Syscall, /* do guest syscall before continuing */ |
| 617 | Ijk_Yield /* client is yielding to thread scheduler */ |
| 618 | } |
| 619 | IRJumpKind; |
| 620 | |
| 621 | extern void ppIRJumpKind ( IRJumpKind ); |
| 622 | |
| 623 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 624 | /* A bunch of statements, expressions, etc, are incomplete without an |
| 625 | environment indicating the type of each IRTemp. So this provides |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 626 | one. IR temporaries are really just unsigned ints and so this |
| 627 | provides an array, 0 .. n_types_used-1 of them. |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 628 | */ |
| 629 | typedef |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 630 | struct { |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 631 | IRType* types; |
| 632 | Int types_size; |
| 633 | Int types_used; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 634 | } |
| 635 | IRTypeEnv; |
| 636 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 637 | extern IRTemp newIRTemp ( IRTypeEnv*, IRType ); |
| 638 | extern IRTypeEnv* dopyIRTypeEnv ( IRTypeEnv* ); |
| 639 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 640 | extern void ppIRTypeEnv ( IRTypeEnv* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 641 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 642 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 643 | /* Basic blocks contain: |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 644 | - A table giving a type for each temp |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 645 | - An expandable array of statements |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 646 | - An expression of type 32 or 64 bits, depending on the |
| 647 | guest's word size, indicating the next destination. |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 648 | - An indication of any special actions (JumpKind) needed |
| 649 | for this final jump. |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 650 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 651 | typedef |
| 652 | struct _IRBB { |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 653 | IRTypeEnv* tyenv; |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 654 | IRStmt** stmts; |
| 655 | Int stmts_size; |
| 656 | Int stmts_used; |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 657 | IRExpr* next; |
| 658 | IRJumpKind jumpkind; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 659 | } |
| 660 | IRBB; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 661 | |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 662 | extern IRBB* emptyIRBB ( void ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 663 | |
| 664 | extern IRBB* dopyIRBB ( IRBB* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 665 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 666 | extern void ppIRBB ( IRBB* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 667 | |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 668 | extern void addStmtToIRBB ( IRBB*, IRStmt* ); |
| 669 | |
| 670 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 671 | |
| 672 | /*---------------------------------------------------------------*/ |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 673 | /*--- Helper functions for the IR ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 674 | /*---------------------------------------------------------------*/ |
| 675 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 676 | /* For messing with IR type environments */ |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 677 | extern IRTypeEnv* emptyIRTypeEnv ( void ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 678 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 679 | /* What is the type of this expression? */ |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 680 | extern IRType typeOfIRConst ( IRConst* ); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 681 | extern IRType typeOfIRTemp ( IRTypeEnv*, IRTemp ); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 682 | extern IRType typeOfIRExpr ( IRTypeEnv*, IRExpr* ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 683 | |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 684 | /* Sanity check a BB of IR */ |
| 685 | extern void sanityCheckIRBB ( IRBB* bb, IRType guest_word_size ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 686 | |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 687 | /* Is this any value actually in the enumeration 'IRType' ? */ |
| 688 | extern Bool isPlausibleType ( IRType ty ); |
| 689 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 690 | #endif /* ndef __LIBVEX_IR_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 691 | |
| 692 | |
| 693 | /*---------------------------------------------------------------*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 694 | /*--- libvex_ir.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 695 | /*---------------------------------------------------------------*/ |