1 (* Copyright (C) 2009 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 signature AMD64_PSEUDO =
12 structure CFunction: C_FUNCTION
13 structure CType: C_TYPE
15 structure RepType: REP_TYPE
16 structure Runtime: RUNTIME
17 structure WordSize: WORD_SIZE
18 structure WordX: WORD_X
19 sharing CFunction = RepType.CFunction
20 sharing CType = RepType.CType
21 sharing WordSize = CType.WordSize = WordX.WordSize
23 val tracer : string -> ('a -> 'b) ->
24 (('a -> 'b) * (unit -> unit))
25 val tracerTop : string -> ('a -> 'b) ->
26 (('a -> 'b) * (unit -> unit))
30 datatype class = INT | FLT
32 = BYTE | WORD | LONG | QUAD
34 val fromBytes : int -> t
35 val toBytes : t -> int
36 val fromCType : CType.t -> t vector
37 val class : t -> class
38 val eq : t * t -> bool
39 val lt : t * t -> bool
40 val toString : t -> string
47 val word : WordX.t -> t
48 val int' : int * WordSize.t -> t
51 val label : Label.t -> t
52 val labelPlusWord : Label.t * WordX.t -> t
53 val labelPlusInt : Label.t * int -> t
58 datatype t = One | Two | Four | Eight
59 val fromBytes : int -> t
60 val fromCType : CType.t -> t
68 val new : {name: string} -> t
75 val eq : t * t -> bool
79 val layout : t -> Layout.t
81 val imm : {base: Immediate.t,
86 val basic : {base: Immediate.t,
91 val simple : {base: t,
96 val complex : {base: t,
101 val shift : {origin: t,
106 val class : t -> Class.t
107 val compare : t * t -> order
109 * Static memory locations
111 val makeContents : {base: Immediate.t,
116 structure ClassSet : SET
117 sharing type ClassSet.Element.t = MemLoc.Class.t
118 structure MemLocSet : SET
119 sharing type MemLocSet.Element.t = MemLoc.t
125 val layout : t -> Layout.t
126 val toString : t -> string
128 val immediate : Immediate.t -> t
129 val immediate_word : WordX.t -> t
130 val immediate_int' : int * WordSize.t -> t
131 val immediate_int : int -> t
132 val immediate_zero : t
133 val immediate_label : Label.t -> t
134 val deImmediate : t -> Immediate.t option
135 val label : Label.t -> t
136 val deLabel : t -> Label.t option
137 val memloc : MemLoc.t -> t
138 val memloc_label: Label.t -> t
139 val deMemloc : t -> MemLoc.t option
141 val size : t -> Size.t option
142 val eq : t * t -> bool
143 val mayAlias : t * t -> bool
146 structure Instruction :
148 (* Integer binary arithmetic(w/o mult & div)/logic instructions. *)
150 = ADD (* signed/unsigned addition; p. 58 *)
151 | ADC (* signed/unsigned addition with carry; p. 56 *)
152 | SUB (* signed/unsigned subtraction; p. 234 *)
153 | SBB (* signed/unsigned subtraction with borrow; p. 216 *)
154 | AND (* logical and; p. 60 *)
155 | OR (* logical or; p. 176 *)
156 | XOR (* logical xor; p. 243 *)
157 (* Integer multiplication and division. *)
159 = IMUL (* signed multiplication (one operand form); p. 114 *)
160 | MUL (* unsigned multiplication; p. 170 *)
161 | IDIV (* signed division; p. 112 *)
162 | DIV (* unsigned division; p. 108 *)
163 | IMOD (* signed modulus; *)
164 | MOD (* unsigned modulus; *)
165 (* Integer unary arithmetic/logic instructions. *)
167 = INC (* increment by 1; p. 117 *)
168 | DEC (* decrement by 1; p. 106 *)
169 | NEG (* two's complement negation; p. 172 *)
170 | NOT (* one's complement negation; p. 175 *)
171 (* Integer shift/rotate arithmetic/logic instructions. *)
173 = SAL (* shift arithmetic left; p. 211 *)
174 | SHL (* shift logical left; p. 211 *)
175 | SAR (* shift arithmetic right; p. 214 *)
176 | SHR (* shift logical right; p. 214 *)
177 | ROL (* rotate left; p. 206 *)
178 | RCL (* rotate through carry left; p. 197 *)
179 | ROR (* rotate right; p. 208 *)
180 | RCR (* rotate through carry right; p. 199 *)
181 (* Move with extention instructions. *)
183 = MOVSX (* move with sign extention; p. 167 *)
184 | MOVZX (* move with zero extention; p. 169 *)
185 (* Condition test field; p. 340 *)
187 = O (* overflow *) | NO (* not overflow *)
188 | B (* below *) | NB (* not below *)
189 | AE (* above or equal *) | NAE (* not above or equal *)
190 | C (* carry *) | NC (* not carry *)
191 | E (* equal *) | NE (* not equal *)
192 | Z (* zero *) | NZ (* not zero *)
193 | BE (* below or equal *) | NBE (* not below or equal *)
194 | A (* above *) | NA (* not above *)
195 | S (* sign *) | NS (* not sign *)
196 | P (* parity *) | NP (* not parity *)
197 | PE (* parity even *) | PO (* parity odd *)
199 | NL (* not less than *)
200 | LE (* less than or equal *)
201 | NLE (* not less than or equal *)
202 | G (* greater than *)
203 | NG (* not greater than *)
204 | GE (* greater than or equal *)
205 | NGE (* not greater than or equal *)
206 val condition_negate : condition -> condition
207 val condition_reverse : condition -> condition
209 (* Scalar SSE binary arithmetic instructions. *)
211 = SSE_ADDS (* addition; p. 7,10 *)
212 | SSE_SUBS (* subtraction; p. 371,374 *)
213 | SSE_MULS (* multiplication; p. 201,204 *)
214 | SSE_DIVS (* division; p. 97,100 *)
215 | SSE_MAXS (* maximum; p. 128, 130 *)
216 | SSE_MINS (* minimum; p. 132, 134 *)
217 (* Scalar SSE unary arithmetic instructions. *)
219 = SSE_SQRTS (* square root; p. 360,362 *)
220 (* Packed SSE binary logical instructions (used as scalar). *)
222 = SSE_ANDNP (* and-not; p. 17,19 *)
223 | SSE_ANDP (* and; p. 21,23 *)
224 | SSE_ORP (* or; p. 206,208 *)
225 | SSE_XORP (* xor; p. 391,393 *)
234 val toString : t -> string
238 val p2align : Immediate.t * Immediate.t option * Immediate.t option -> t
239 val byte : Immediate.t list -> t
240 val word : Immediate.t list -> t
241 val long : Immediate.t list -> t
242 val quad : Immediate.t list -> t
249 val toString : t -> string
251 val comment : string -> t
252 val isComment : t -> bool
253 val pseudoop : PseudoOp.t -> t
254 val pseudoop_data : unit -> t
255 val pseudoop_text : unit -> t
256 val pseudoop_p2align : Immediate.t * Immediate.t option * Immediate.t option -> t
257 val pseudoop_byte : Immediate.t list -> t
258 val pseudoop_global: Label.t -> t
259 val pseudoop_word : Immediate.t list -> t
260 val pseudoop_long : Immediate.t list -> t
261 val pseudoop_quad : Immediate.t list -> t
262 val label : Label.t -> t
263 val instruction : Instruction.t -> t
264 val instruction_nop : unit -> t
265 val instruction_binal : {oper: Instruction.binal,
269 val instruction_pmd : {oper: Instruction.md,
273 val instruction_imul2 : {src: Operand.t,
276 val instruction_unal : {oper: Instruction.unal,
279 val instruction_sral : {oper: Instruction.sral,
283 val instruction_cmp : {src1: Operand.t,
286 val instruction_test : {src1: Operand.t,
289 val instruction_setcc : {condition: Instruction.condition,
292 val instruction_jmp : {target: Operand.t,
294 val instruction_jcc : {condition: Instruction.condition,
295 target: Operand.t} -> t
296 val instruction_call : {target: Operand.t,
298 val instruction_ret : {src: Operand.t option} -> t
299 val instruction_mov : {src: Operand.t,
302 val instruction_cmovcc : {condition: Instruction.condition,
306 val instruction_xchg : {src: Operand.t,
309 val instruction_ppush : {src: Operand.t,
312 val instruction_ppop : {dst: Operand.t,
315 val instruction_movx : {oper: Instruction.movx,
319 dstsize: Size.t} -> t
320 val instruction_xvom : {src: Operand.t,
323 dstsize: Size.t} -> t
324 val instruction_lea : {src: Operand.t,
327 val instruction_sse_binas : {oper: Instruction.sse_binas,
331 val instruction_sse_unas : {oper: Instruction.sse_unas,
335 val instruction_sse_binlp : {oper: Instruction.sse_binlp,
339 val instruction_sse_movs : {src: Operand.t,
342 val instruction_sse_comis : {src1: Operand.t,
345 val instruction_sse_ucomis : {src1: Operand.t,
348 val instruction_sse_cvtsfp2sfp : {src: Operand.t,
351 dstsize: Size.t} -> t
352 val instruction_sse_cvtsfp2si : {src: Operand.t,
355 dstsize: Size.t} -> t
356 val instruction_sse_cvtsi2sfp : {src: Operand.t,
359 dstsize: Size.t} -> t
360 val instruction_sse_movd : {src: Operand.t,
363 dstsize: Size.t} -> t
368 datatype t = T of {size: int,
369 frameLayoutsIndex: int}
376 val cont: {label: Label.t,
378 frameInfo: FrameInfo.t} -> t
379 val creturn: {dsts: (Operand.t * Size.t) vector,
380 frameInfo: FrameInfo.t option,
381 func: RepType.t CFunction.t,
383 val func: {label: Label.t,
384 live: MemLocSet.t} -> t
385 val handler: {frameInfo: FrameInfo.t,
387 live: MemLocSet.t} -> t
388 val jump: {label: Label.t} -> t
389 val label: t -> Label.t
398 val word : (WordX.t * 'a) list -> 'a t
403 val goto : {target: Label.t} -> t
404 val iff : {condition: Instruction.condition,
406 falsee: Label.t} -> t
407 val switch : {test: Operand.t,
408 cases: Label.t Cases.t,
409 default: Label.t} -> t
410 val tail : {target: Label.t,
411 live: MemLocSet.t} -> t
412 val nontail : {target: Label.t,
415 handler: Label.t option,
417 val return : {live: MemLocSet.t} -> t
418 val raisee : {live: MemLocSet.t} -> t
419 val ccall : {args: (Operand.t * Size.t) list,
420 frameInfo: FrameInfo.t option,
421 func: RepType.t CFunction.t,
422 return: Label.t option} -> t
425 structure ProfileLabel :
433 val mkBlock': {entry: Entry.t option,
434 statements: Assembly.t list,
435 transfer: Transfer.t option} -> t'
436 val mkProfileBlock': {profileLabel: ProfileLabel.t} -> t'
437 val printBlock' : t' -> unit
440 val printBlock : t -> unit
442 val compress: t' list -> t list
447 datatype t = T of {data: Assembly.t list, blocks: Block.t list}
452 functor amd64PseudoCheck(structure S : AMD64) : AMD64_PSEUDO = S