From 1b5db339bb05f773a6a132be4c0b8cea54d50461 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 17 Apr 2015 16:30:43 +0200 Subject: Experiment: support a subset of GCC's extended asm statements. --- powerpc/Asmexpand.ml | 2 +- powerpc/CBuiltins.ml | 4 ++++ powerpc/TargetPrinter.ml | 17 +++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'powerpc') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 47895cb1..fbe5f782 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -523,7 +523,7 @@ let expand_instruction instr = expand_builtin_memcpy (Z.to_int sz) (Z.to_int al) args | EF_annot_val(txt, targ) -> expand_annot_val txt targ args res - | EF_inline_asm txt -> + | EF_inline_asm(txt, sg) -> emit instr | _ -> assert false diff --git a/powerpc/CBuiltins.ml b/powerpc/CBuiltins.ml index 8840d2c3..222a4d94 100644 --- a/powerpc/CBuiltins.ml +++ b/powerpc/CBuiltins.ml @@ -90,3 +90,7 @@ let builtins = { let size_va_list = 12 let va_list_scalar = false + +(* Expand memory references inside extended asm statements. Used in C2C. *) + +let asm_mem_argument arg = Printf.sprintf "0(%s)" arg diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml index b3d228b3..49954998 100644 --- a/powerpc/TargetPrinter.ml +++ b/powerpc/TargetPrinter.ml @@ -284,10 +284,14 @@ module Target (System : SYSTEM):TARGET = let ireg_or_zero oc r = if r = GPR0 then output_string oc "0" else ireg oc r - (* [preg] is only used for printing annotations. - Use the full register names [rN] and [fN] to avoid - ambiguity with constants. *) let preg oc = function + | IR r -> ireg oc r + | FR r -> freg oc r + | _ -> assert false + + (* For printing annotations, use the full register names [rN] and [fN] + to avoid ambiguity with constants. *) + let preg_annot oc = function | IR r -> fprintf oc "r%s" (int_reg_name r) | FR r -> fprintf oc "f%s" (float_reg_name r) | _ -> assert false @@ -327,7 +331,7 @@ module Target (System : SYSTEM):TARGET = (int_of_string (Str.matched_group 2 txt)) end else begin fprintf oc "%s annotation: " comment; - PrintAnnot.print_annot_stmt preg "R1" oc txt targs args + PrintAnnot.print_annot_stmt preg_annot "R1" oc txt targs args end (* Determine if the displacement of a conditional branch fits the short form *) @@ -646,9 +650,10 @@ module Target (System : SYSTEM):TARGET = fprintf oc "%a:\n" label (transl_label lbl) | Pbuiltin(ef, args, res) -> begin match ef with - | EF_inline_asm txt -> + | EF_inline_asm(txt, sg) -> fprintf oc "%s begin inline assembly\n" comment; - fprintf oc " %s\n" (extern_atom txt); + fprintf oc "\t"; + PrintAnnot.print_inline_asm preg oc (extern_atom txt) sg args res; fprintf oc "%s end inline assembly\n" comment | _ -> assert false -- cgit From 426881cde464691b61c5c49cf5038d21aace75fe Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 21 Apr 2015 10:21:06 +0200 Subject: Support for GCC-style extended asm, continued: - support "r", "m" and "i" constraints - support "%Q" and "%R" modifiers for register pairs - support register clobbers - split off analysis and transformation of asm statements in cparser/ExtendedAsm.ml --- powerpc/Asmexpand.ml | 2 +- powerpc/TargetPrinter.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'powerpc') diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index fbe5f782..aec8f66e 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -523,7 +523,7 @@ let expand_instruction instr = expand_builtin_memcpy (Z.to_int sz) (Z.to_int al) args | EF_annot_val(txt, targ) -> expand_annot_val txt targ args res - | EF_inline_asm(txt, sg) -> + | EF_inline_asm(txt, sg, clob) -> emit instr | _ -> assert false diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml index 49954998..99e2479d 100644 --- a/powerpc/TargetPrinter.ml +++ b/powerpc/TargetPrinter.ml @@ -650,7 +650,7 @@ module Target (System : SYSTEM):TARGET = fprintf oc "%a:\n" label (transl_label lbl) | Pbuiltin(ef, args, res) -> begin match ef with - | EF_inline_asm(txt, sg) -> + | EF_inline_asm(txt, sg, clob) -> fprintf oc "%s begin inline assembly\n" comment; fprintf oc "\t"; PrintAnnot.print_inline_asm preg oc (extern_atom txt) sg args res; -- cgit From 832685e5dc7c17c434146d353b60c2158e3edd11 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 21 Apr 2015 11:36:56 +0200 Subject: Cleanups and updates for extended asm. --- powerpc/TargetPrinter.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'powerpc') diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml index 99e2479d..b05b29c0 100644 --- a/powerpc/TargetPrinter.ml +++ b/powerpc/TargetPrinter.ml @@ -651,8 +651,7 @@ module Target (System : SYSTEM):TARGET = | Pbuiltin(ef, args, res) -> begin match ef with | EF_inline_asm(txt, sg, clob) -> - fprintf oc "%s begin inline assembly\n" comment; - fprintf oc "\t"; + fprintf oc "%s begin inline assembly\n\t" comment; PrintAnnot.print_inline_asm preg oc (extern_atom txt) sg args res; fprintf oc "%s end inline assembly\n" comment | _ -> -- cgit