aboutsummaryrefslogtreecommitdiffstats
path: root/powerpc/Asmexpand.ml
diff options
context:
space:
mode:
Diffstat (limited to 'powerpc/Asmexpand.ml')
-rw-r--r--powerpc/Asmexpand.ml55
1 files changed, 44 insertions, 11 deletions
diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml
index ec5a767f..699c841f 100644
--- a/powerpc/Asmexpand.ml
+++ b/powerpc/Asmexpand.ml
@@ -19,10 +19,48 @@ open Integers
open AST
open Memdata
open Asm
-open Asmexpandaux
+(* Buffering the expanded code *)
-(* Useful constants and helper functions *)
+let current_code = ref ([]: instruction list)
+
+let emit i = current_code := i :: !current_code
+
+let emit_loadimm r n =
+ List.iter emit (Asmgen.loadimm r n [])
+
+let emit_addimm rd rs n =
+ List.iter emit (Asmgen.addimm rd rs n [])
+
+let get_code () =
+ let c = List.rev !current_code in current_code := []; c
+
+(* Generation of fresh labels *)
+
+let dummy_function = { fn_code = []; fn_sig = signature_main }
+let current_function = ref dummy_function
+let next_label = ref (None : label option)
+
+let new_label () =
+ let lbl =
+ match !next_label with
+ | Some l -> l
+ | None ->
+ (* on-demand computation of the next available label *)
+ List.fold_left
+ (fun next instr ->
+ match instr with
+ | Plabel l -> if P.lt l next then next else P.succ l
+ | _ -> next)
+ P.one (!current_function).fn_code
+ in
+ next_label := Some (P.succ lbl);
+ lbl
+
+let set_current_function f =
+ current_function := f; next_label := None
+
+(* Useful constants *)
let _0 = Integers.Int.zero
let _1 = Integers.Int.one
@@ -33,14 +71,6 @@ let _8 = coqint_of_camlint 8l
let _m4 = coqint_of_camlint (-4l)
let _m8 = coqint_of_camlint (-8l)
-let emit_loadimm r n =
- List.iter emit (Asmgen.loadimm r n [])
-
-let emit_addimm rd rs n =
- List.iter emit (Asmgen.addimm rd rs n [])
-
-
-
(* Handling of annotations *)
let expand_annot_val txt targ args res =
@@ -503,8 +533,11 @@ let expand_instruction instr =
let expand_function fn =
set_current_function fn;
+ current_code := [];
List.iter expand_instruction fn.fn_code;
- get_current_function ()
+ let c = get_code() in
+ set_current_function dummy_function;
+ { fn with fn_code = c }
let expand_fundef = function
| Internal f -> Internal (expand_function f)