Inline inner DSL module.

git-svn-id: http://caml.inria.fr/svn/ocaml/branches/abstract_intel_emit@15401 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2014-09-30 15:07:29 +00:00
parent 0fd13b09d7
commit cf495ee713
4 changed files with 84 additions and 93 deletions

View File

@ -27,7 +27,6 @@ open Emitaux
open Intel_ast
open Intel_proc
open Intel_dsl
open Intel_dsl.DSL
let _label s = D.label ~typ:QWORD s
@ -432,7 +431,7 @@ let emit_instr fallthrough i =
| _ -> I.mov (int 0, res i 0)
end
else
I.mov (emit_nat n, res i 0)
I.mov (nat n, res i 0)
| Lop(Iconst_float f) ->
begin match Int64.bits_of_float f with
| 0x0000_0000_0000_0000L -> (* +0.0 *)
@ -606,7 +605,7 @@ let emit_instr fallthrough i =
| Lop(Ispecific(Ilea addr)) ->
I.lea (addressing addr NONE i 0, res i 0)
| Lop(Ispecific(Istore_int(n, addr, _))) ->
I.mov (emit_nat n, addressing addr QWORD i 0)
I.mov (nat n, addressing addr QWORD i 0)
| Lop(Ispecific(Istore_symbol(s, addr, _))) ->
assert (not !pic_code && not !Clflags.dlcode);
add_used_symbol s;

View File

@ -27,7 +27,6 @@ open Emitaux
open Intel_ast
open Intel_proc
open Intel_dsl
open Intel_dsl.DSL
let _label s = D.label ~typ:DWORD s
@ -501,7 +500,7 @@ let emit_instr fallthrough i =
| Reg _ -> I.xor (reg i.res.(0), reg i.res.(0))
| _ -> I.mov (int 0, reg i.res.(0))
end else
I.mov (emit_nat n, reg i.res.(0))
I.mov (nat n, reg i.res.(0))
| Lop(Iconst_float f) ->
begin match Int64.bits_of_float f with
| 0x0000_0000_0000_0000L -> (* +0.0 *)
@ -727,7 +726,7 @@ let emit_instr fallthrough i =
| Lop(Ispecific(Ilea addr)) ->
I.lea (addressing addr DWORD i 0, reg i.res.(0))
| Lop(Ispecific(Istore_int(n, addr, _))) ->
I.mov (emit_nat n, addressing addr DWORD i 0)
I.mov (nat n, addressing addr DWORD i 0)
| Lop(Ispecific(Istore_symbol(s, addr, _))) ->
add_used_symbol s;
I.mov (immsym s, addressing addr DWORD i 0)
@ -755,7 +754,7 @@ let emit_instr fallthrough i =
stack_offset := !stack_offset + 4
done
| Lop(Ispecific(Ipush_int n)) ->
I.push (emit_nat n);
I.push (nat n);
cfi_adjust_cfa_offset 4;
stack_offset := !stack_offset + 4
| Lop(Ispecific(Ipush_symbol s)) ->

View File

@ -30,53 +30,19 @@
open Intel_ast
open Intel_proc
module D = struct
let section segment flags args = directive (Section (segment, flags, args))
let align n = directive (Align (false, n))
let byte n = directive (Byte n)
let bytes s = directive (Bytes s)
let cfi_adjust_cfa_offset n = directive (Cfi_adjust_cfa_offset n)
let cfi_endproc () = directive Cfi_endproc
let cfi_startproc () = directive Cfi_startproc
let comment s = directive (Comment s)
let data () = section [ ".data" ] None []
let extrn s ptr = directive (External (s, ptr))
let file num filename = directive (File (num, filename))
let global s = directive (Global s)
let indirect_symbol s = directive (Indirect_symbol s)
let label ?(typ = NONE) s = directive (NewLabel (s, typ))
let loc num loc = directive (Loc (num, loc))
let long cst = directive (Long cst)
let mode386 () = directive Mode386
let model name = directive (Model name)
let private_extern s = directive (Private_extern s)
let qword cst = directive (Quad cst)
let setvar (arg1, arg2) = directive (Set (arg1, arg2))
let size name cst = directive (Size (name, cst))
let space n = directive (Space n)
let text () = section [ ".text" ] None []
let type_ name typ = directive (Type (name, typ))
let word cst = directive (Word cst)
end
module DSL = struct
let sym s = Sym s
let emit_nat n = Imm (Int64.of_nativeint n)
let nat n = Imm (Int64.of_nativeint n)
let int n = Imm (Int64.of_int n)
let const_64 n = Const n
let const_32 n = Const (Int64.of_int32 n)
let const_nat n = Const (Int64.of_nativeint n)
let const n = Const (Int64.of_int n)
let al = Reg8L RAX
let ah = Reg8H AH
let cl = Reg8L RCX
let ax = Reg16 RAX
let rax = Reg64 RAX
let r10 = Reg64 R10
let r11 = Reg64 R11
@ -104,6 +70,34 @@ module DSL = struct
let mem64_rip typ ?(ofs = 0) s =
Mem64_RIP (typ, s, ofs)
module D = struct
let section segment flags args = directive (Section (segment, flags, args))
let align n = directive (Align (false, n))
let byte n = directive (Byte n)
let bytes s = directive (Bytes s)
let cfi_adjust_cfa_offset n = directive (Cfi_adjust_cfa_offset n)
let cfi_endproc () = directive Cfi_endproc
let cfi_startproc () = directive Cfi_startproc
let comment s = directive (Comment s)
let data () = section [ ".data" ] None []
let extrn s ptr = directive (External (s, ptr))
let file num filename = directive (File (num, filename))
let global s = directive (Global s)
let indirect_symbol s = directive (Indirect_symbol s)
let label ?(typ = NONE) s = directive (NewLabel (s, typ))
let loc num loc = directive (Loc (num, loc))
let long cst = directive (Long cst)
let mode386 () = directive Mode386
let model name = directive (Model name)
let private_extern s = directive (Private_extern s)
let qword cst = directive (Quad cst)
let setvar (arg1, arg2) = directive (Set (arg1, arg2))
let size name cst = directive (Size (name, cst))
let space n = directive (Space n)
let text () = section [ ".text" ] None []
let type_ name typ = directive (Type (name, typ))
let word cst = directive (Word cst)
end
module I = struct

View File

@ -29,42 +29,9 @@
open Intel_ast
module D : sig
(** Directives *)
val align: int -> unit
val byte: constant -> unit
val bytes: string -> unit
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
val label: ?typ:data_type -> string -> unit
val loc: int -> int -> unit
val long: constant -> unit
val mode386: unit -> unit
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
module DSL : sig
val sym: string -> arg
val emit_nat: nativeint -> arg
val nat: nativeint -> arg
val int: int -> arg
val const_64: int64 -> constant
val const_32: int32 -> constant
val const_nat: nativeint -> constant
val const: int -> constant
@ -98,7 +65,39 @@ module DSL : sig
int -> reg64 -> arg
val mem64_rip: data_type -> ?ofs:int -> string -> arg
module D : sig
(** Directives *)
val align: int -> unit
val byte: constant -> unit
val bytes: string -> unit
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
val label: ?typ:data_type -> string -> unit
val loc: int -> int -> unit
val long: constant -> unit
val mode386: unit -> unit
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
module I : sig
val add: arg * arg -> unit
val addsd: arg * arg -> unit