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