2014-09-26 01:32:32 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Fabrice Le Fessant, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
2014-11-25 09:46:21 -08:00
|
|
|
(* Copyright 2014 Institut National de Recherche en Informatique et *)
|
2014-09-26 01:32:32 -07:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(** Helpers for Intel code generators *)
|
|
|
|
|
|
|
|
(* The DSL* modules expose functions to emit x86/x86_64 instructions
|
2014-09-30 08:20:02 -07:00
|
|
|
using a syntax close to the official Intel syntax, except that
|
2014-11-27 08:48:23 -08:00
|
|
|
source and destination operands are reversed as in the AT&T
|
|
|
|
syntax:
|
|
|
|
|
2014-12-01 02:27:23 -08:00
|
|
|
mov src dst
|
2014-09-26 01:32:32 -07:00
|
|
|
*)
|
|
|
|
|
|
|
|
|
2014-11-27 09:12:21 -08:00
|
|
|
open X86_ast
|
2014-09-26 01:32:32 -07:00
|
|
|
|
2014-09-30 08:07:29 -07:00
|
|
|
val sym: string -> arg
|
|
|
|
val nat: nativeint -> arg
|
|
|
|
val int: int -> arg
|
|
|
|
val const_32: int32 -> constant
|
|
|
|
val const_nat: nativeint -> constant
|
|
|
|
val const: int -> constant
|
|
|
|
val al: arg
|
|
|
|
val ah: arg
|
|
|
|
val cl: arg
|
|
|
|
val ax: arg
|
|
|
|
val rax: arg
|
|
|
|
val r10: arg
|
|
|
|
val r11: arg
|
|
|
|
val r14: arg
|
|
|
|
val r15: arg
|
|
|
|
val rsp: arg
|
|
|
|
val rbp: arg
|
|
|
|
val xmm15: arg
|
|
|
|
val eax: arg
|
|
|
|
val ebx: arg
|
|
|
|
val ecx: arg
|
|
|
|
val edx: arg
|
|
|
|
val ebp: arg
|
|
|
|
val esp: arg
|
|
|
|
val st0: arg
|
|
|
|
val st1: arg
|
|
|
|
|
|
|
|
val mem32:
|
|
|
|
data_type -> ?scale:int -> ?base:reg64 -> ?sym:string ->
|
|
|
|
int -> reg64 -> arg
|
|
|
|
|
|
|
|
val mem64:
|
|
|
|
data_type -> ?scale:int -> ?base:reg64 -> ?sym:string ->
|
|
|
|
int -> reg64 -> arg
|
|
|
|
|
|
|
|
val mem64_rip: data_type -> ?ofs:int -> string -> arg
|
|
|
|
|
|
|
|
|
2014-09-30 07:54:15 -07:00
|
|
|
module D : sig
|
|
|
|
(** Directives *)
|
|
|
|
|
|
|
|
val align: int -> unit
|
|
|
|
val byte: constant -> unit
|
2014-09-30 08:00:52 -07:00
|
|
|
val bytes: string -> unit
|
2014-09-30 07:54:15 -07:00
|
|
|
val cfi_adjust_cfa_offset: int -> unit
|
|
|
|
val cfi_endproc: unit -> unit
|
|
|
|
val cfi_startproc: unit -> unit
|
|
|
|
val comment: string -> unit
|
|
|
|
val data: unit -> unit
|
|
|
|
val extrn: string -> data_type -> unit
|
|
|
|
val file: int -> string -> unit
|
|
|
|
val global: string -> unit
|
|
|
|
val indirect_symbol: string -> unit
|
2014-09-30 07:59:56 -07:00
|
|
|
val label: ?typ:data_type -> string -> unit
|
2014-09-30 07:54:15 -07:00
|
|
|
val loc: int -> int -> unit
|
|
|
|
val long: constant -> unit
|
2014-09-30 08:00:52 -07:00
|
|
|
val mode386: unit -> unit
|
2014-09-30 07:54:15 -07:00
|
|
|
val model: string -> unit
|
|
|
|
val private_extern: string -> unit
|
|
|
|
val qword: constant -> unit
|
|
|
|
val section: string list -> string option -> string list -> unit
|
|
|
|
val setvar: string * constant -> unit
|
|
|
|
val size: string -> constant -> unit
|
|
|
|
val space: int -> unit
|
|
|
|
val text: unit -> unit
|
|
|
|
val type_: string -> string -> unit
|
|
|
|
val word: constant -> unit
|
|
|
|
end
|
|
|
|
|
2014-09-30 07:37:09 -07:00
|
|
|
module I : sig
|
2014-09-30 08:20:02 -07:00
|
|
|
(* Instructions *)
|
|
|
|
|
2014-11-27 09:20:22 -08:00
|
|
|
val add: arg -> arg -> unit
|
|
|
|
val addsd: arg -> arg -> unit
|
|
|
|
val and_: arg -> arg -> unit
|
|
|
|
val andpd: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val bswap: arg -> unit
|
|
|
|
val call: arg -> unit
|
|
|
|
val cdq: unit -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val cmp: arg -> arg -> unit
|
|
|
|
val comisd: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val cqo: unit -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val cvtsd2ss: arg -> arg -> unit
|
|
|
|
val cvtsi2sd: arg -> arg -> unit
|
|
|
|
val cvtss2sd: arg -> arg -> unit
|
|
|
|
val cvttsd2si: arg -> arg -> unit
|
2014-09-30 07:27:23 -07:00
|
|
|
val dec: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val divsd: arg -> arg -> unit
|
2014-09-26 01:32:32 -07:00
|
|
|
val fabs: unit -> unit
|
|
|
|
val fadd: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val faddp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fchs: unit -> unit
|
2014-09-26 01:32:32 -07:00
|
|
|
val fcomp: arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fcompp: unit -> unit
|
|
|
|
val fcos: unit -> unit
|
|
|
|
val fdiv: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val fdivp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fdivr: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val fdivrp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fild: arg -> unit
|
|
|
|
val fistp: arg -> unit
|
|
|
|
val fld1: unit -> unit
|
2014-09-26 01:32:32 -07:00
|
|
|
val fld: arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fldcw: arg -> unit
|
|
|
|
val fldlg2: unit -> unit
|
|
|
|
val fldln2: unit -> unit
|
|
|
|
val fldz: unit -> unit
|
|
|
|
val fmul: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val fmulp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fnstcw: arg -> unit
|
2014-09-26 01:32:32 -07:00
|
|
|
val fnstsw: arg -> unit
|
|
|
|
val fpatan: unit -> unit
|
|
|
|
val fptan: unit -> unit
|
|
|
|
val fsin: unit -> unit
|
|
|
|
val fsqrt: unit -> unit
|
|
|
|
val fstp: arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fsub: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val fsubp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fsubr: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val fsubrp: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val fxch: arg -> unit
|
|
|
|
val fyl2x: unit -> unit
|
|
|
|
val hlt: unit -> unit
|
2014-09-30 07:18:25 -07:00
|
|
|
val idiv: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val imul: arg -> arg option -> unit
|
2014-09-30 07:19:15 -07:00
|
|
|
val inc: arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val j: condition -> arg -> unit
|
|
|
|
val ja: arg -> unit
|
|
|
|
val jae: arg -> unit
|
|
|
|
val jb: arg -> unit
|
|
|
|
val jbe: arg -> unit
|
|
|
|
val je: arg -> unit
|
|
|
|
val jg: arg -> unit
|
|
|
|
val jmp: arg -> unit
|
|
|
|
val jne: arg -> unit
|
|
|
|
val jp: arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val lea: arg -> arg -> unit
|
|
|
|
val mov: arg -> arg -> unit
|
|
|
|
val movapd: arg -> arg -> unit
|
|
|
|
val movsd: arg -> arg -> unit
|
|
|
|
val movss: arg -> arg -> unit
|
|
|
|
val movsx: arg -> arg -> unit
|
|
|
|
val movsxd: arg -> arg -> unit
|
|
|
|
val movzx: arg -> arg -> unit
|
|
|
|
val mulsd: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val nop: unit -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val or_: arg -> arg -> unit
|
2014-09-30 07:19:15 -07:00
|
|
|
val pop: arg -> unit
|
|
|
|
val push: arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val ret: unit -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val sal: arg -> arg -> unit
|
|
|
|
val sar: arg -> arg -> unit
|
2014-09-30 07:37:09 -07:00
|
|
|
val set: condition -> arg -> unit
|
2014-11-27 09:20:22 -08:00
|
|
|
val shr: arg -> arg -> unit
|
|
|
|
val sqrtsd: arg -> arg -> unit
|
|
|
|
val sub: arg -> arg -> unit
|
|
|
|
val subsd: arg -> arg -> unit
|
|
|
|
val test: arg -> arg -> unit
|
|
|
|
val ucomisd: arg -> arg -> unit
|
|
|
|
val xchg: arg -> arg -> unit
|
|
|
|
val xor: arg -> arg -> unit
|
|
|
|
val xorpd: arg -> arg -> unit
|
2014-09-26 01:32:32 -07:00
|
|
|
end
|