4 EAX | EBX | ECX | EDX | ESI | EDI | EBP | RSP | R8D | R9D | R10D | R11D | R12D | R13D | R14D | R15D
5 datatype oper = REG of reg | TEMP of Temp.temp | CONST of Word32.word | REL of (reg * int)
12 IMUL3 of oper * oper * Word32.word |
14 LEAL of oper * oper * oper |
20 val cmpoper : oper * oper -> order
21 val opereq : oper * oper -> bool
22 val regname : reg -> string
23 val regtonum : reg -> int
24 val numtoreg : int -> reg
25 val prettyprint_oper : oper -> string
26 val prettyprint : insn -> string
29 structure x86 :> X86 =
32 EAX | EBX | ECX | EDX | ESI | EDI | EBP | RSP | R8D | R9D | R10D | R11D | R12D | R13D | R14D | R15D
33 datatype oper = REG of reg | TEMP of Temp.temp | CONST of Word32.word | REL of (reg * int)
40 IMUL3 of oper * oper * Word32.word |
42 LEAL of oper * oper * oper |
48 fun regname EAX = "eax"
58 | regname R10D = "r10d"
59 | regname R11D = "r11d"
60 | regname R12D = "r12d"
61 | regname R13D = "r13d"
62 | regname R14D = "r14d"
63 | regname R15D = "r15d"
79 | regtonum EBP = 14 (* Dummy numbers -- not permitted for allocation, but there so that we can compare *)
96 | numtoreg n = raise ErrorMsg.InternalError ("numtoreg: Unknown register "^(Int.toString n))
98 fun regcmp (r1, r2) = Int.compare (regtonum r1, regtonum r2)
100 fun cmpoper (REG(reg1), REG(reg2)) = regcmp (reg1, reg2)
101 | cmpoper (TEMP(temp1), TEMP(temp2)) = Temp.compare (temp1,temp2)
102 | cmpoper (CONST(const1), CONST(const2)) = Word32.compare (const1, const2)
103 | cmpoper (REL (r1, i1), REL (r2, i2)) =
105 val regorder = regcmp (r1, r2)
106 val intorder = Int.compare (i1, i2)
108 if (regorder = EQUAL) then intorder
111 | cmpoper (CONST _, _) = LESS
112 | cmpoper (REG _, _) = LESS
113 | cmpoper (REL _, _) = LESS
114 | cmpoper (_, _) = GREATER
116 fun opereq (a, b) = cmpoper (a, b) = EQUAL
118 fun moreDifferentToString (i) =
119 if (i >= 0) then Int.toString i
120 else "-" ^ (Int.toString (~i))
122 fun prettyprint_oper (REG r) = "%" ^ (regname r)
123 | prettyprint_oper (TEMP t) = Temp.name t
124 | prettyprint_oper (CONST c) = "$0x" ^ (Word32.toString c)
125 | prettyprint_oper (REL (r, i)) = (moreDifferentToString i) ^ "(%" ^ (regname r) ^ ")"
127 fun prettyprint (DIRECTIVE(str)) = str ^ "\n"
128 | prettyprint (COMMENT(str)) = "// " ^ str ^ "\n"
129 | prettyprint (MOVL(src, dst)) = "\tMOVL\t" ^ (prettyprint_oper src) ^ ", " ^ (prettyprint_oper dst) ^ "\n"
130 | prettyprint (SUBL(src, dst)) = "\tSUBL\t" ^ (prettyprint_oper src) ^ ", " ^ (prettyprint_oper dst) ^ "\n"
131 | prettyprint (IMUL(src, dst)) = "\tIMUL\t" ^ (prettyprint_oper src) ^ ", " ^ (prettyprint_oper dst) ^ "\n"
132 | prettyprint (IMUL3(dst, tmp, const)) = "\tIMUL\t" ^ (prettyprint_oper (CONST const)) ^ ", " ^ (prettyprint_oper tmp) ^ ", " ^ (prettyprint_oper dst) ^ "\n"
133 | prettyprint (ADDL(src, dst)) = "\tADDL\t" ^ (prettyprint_oper src) ^ ", " ^ (prettyprint_oper dst) ^ "\n"
134 | prettyprint (LEAL(src1, src2, dst)) = "\tLEAL\t(" ^ (prettyprint_oper src1) ^ "," ^ (prettyprint_oper src2) ^ ")," ^ (prettyprint_oper dst) ^ "\n"
135 | prettyprint (IDIVL(src)) = "\tIDIVL\t" ^ (prettyprint_oper src) ^ "\n"
136 | prettyprint (NEG (src)) = "\tNEG\t" ^ (prettyprint_oper src) ^ "\n"
137 | prettyprint (CLTD) = "\tCLTD\n"
138 | prettyprint (RET) = "\tRET\n"
139 (* | prettyprint _ = raise ErrorMsg.InternalError ("prettyprint: unknown instruction")*)