diff options
author | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2015-04-22 14:27:12 +0200 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2015-04-22 14:27:12 +0200 |
commit | 0bf99217426a44046ef0aaa7f84a9b2a3646ed89 (patch) | |
tree | e4f983980a5001792b90ed8f3dbd8fa241e43eb1 /cparser/Cprint.ml | |
parent | 08b2b46f15e70b11c044e4e9a7c8438a96d57ed7 (diff) | |
parent | ca4aa822693f4d98de99fd3f13c1523d733e1cb0 (diff) | |
download | compcert-0bf99217426a44046ef0aaa7f84a9b2a3646ed89.tar.gz compcert-0bf99217426a44046ef0aaa7f84a9b2a3646ed89.zip |
Merge pull request #40 from AbsInt/inline-asm
GCC-style extended inline asm.
The subset implemented is:
- zero or one output
- output constraints "=r" (to register) or "=m" (to memory)
- zero, one or several inputs
- input constraints "r" (in register), "m" (in memory), "i" and "n" (compile-time integer constant)
- clobbered registers (the 3rd argument)
- both anonymous (%3) and named (%[name]) operands
- modifiers %R and %Q to refer to the most significant / least significant part of a register pair holding a 64-bit integer. (Undocumented GCC ARM feature.)
All asm statements are treated as "volatile", possibly modifying memory and condition codes.
Diffstat (limited to 'cparser/Cprint.ml')
-rw-r--r-- | cparser/Cprint.ml | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/cparser/Cprint.ml b/cparser/Cprint.ml index ee8002d4..4ceaa016 100644 --- a/cparser/Cprint.ml +++ b/cparser/Cprint.ml @@ -364,6 +364,27 @@ let full_decl pp (sto, id, ty, int) = end; fprintf pp ";@]" +let asm_operand pp (label, constr, e) = + begin match label with + | None -> () + | Some l -> fprintf pp "[%s] " l + end; + fprintf pp "%a (%a)" const (CStr constr) exp (0, e) + +let asm_operands pp = function + | [] -> () + | op1 :: ops -> + fprintf pp "@[<hov 0>%a" asm_operand op1; + List.iter (fun op -> fprintf pp ",@ %a" asm_operand op) ops; + fprintf pp "@]" + +let asm_flags pp = function + | [] -> () + | fl1 :: fls -> + fprintf pp "@[<hov 0>%a" const (CStr fl1); + List.iter (fun fl -> fprintf pp ",@ %a" const (CStr fl)) fls; + fprintf pp "@]" + exception Not_expr let rec exp_of_stmt s = @@ -429,8 +450,21 @@ let rec stmt pp s = fprintf pp "@[<v 2>{@ %a@;<0 -2>}@]" stmt_block s | Sdecl d -> full_decl pp d - | Sasm txt -> - fprintf pp "asm(%a);" const (CStr txt) + | Sasm(attrs, txt, [], [], []) -> + fprintf pp "asm%a(%a);" attributes attrs const (CStr txt) + | Sasm(attrs, txt, outputs, inputs, []) -> + fprintf pp "asm%a(@[<hov 0>%a@ :%a@ :%a@]);" + attributes attrs + const (CStr txt) + asm_operands outputs + asm_operands inputs + | Sasm(attrs, txt, outputs, inputs, flags) -> + fprintf pp "asm%a(@[<hov 0>%a@ :%a@ :%a@ : %a@]);" + attributes attrs + const (CStr txt) + asm_operands outputs + asm_operands inputs + asm_flags flags and slabel pp = function | Slabel s -> |