From 6a8f9945403c4856ad94b115f6bcc229e79bc492 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sun, 12 Jan 2014 14:11:30 +0000 Subject: Better printing of integer literals: add U and LL suffixes when needed. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2405 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cfrontend/PrintClight.ml | 4 ++++ cfrontend/PrintCsyntax.ml | 31 ++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'cfrontend') diff --git a/cfrontend/PrintClight.ml b/cfrontend/PrintClight.ml index 376707a..49705c4 100644 --- a/cfrontend/PrintClight.ml +++ b/cfrontend/PrintClight.ml @@ -76,10 +76,14 @@ let rec expr p (prec, e) = fprintf p "*%a" expr (prec', a1) | Efield(a1, f, _) -> fprintf p "%a.%s" expr (prec', a1) (extern_atom f) + | Econst_int(n, Tint(I32, Unsigned, _)) -> + fprintf p "%luU" (camlint_of_coqint n) | Econst_int(n, _) -> fprintf p "%ld" (camlint_of_coqint n) | Econst_float(f, _) -> fprintf p "%F" (camlfloat_of_coqfloat f) + | Econst_long(n, Tlong(Unsigned, _)) -> + fprintf p "%LuLLU" (camlint64_of_coqint n) | Econst_long(n, _) -> fprintf p "%LdLL" (camlint64_of_coqint n) | Eunop(Oabsfloat, a1, _) -> diff --git a/cfrontend/PrintCsyntax.ml b/cfrontend/PrintCsyntax.ml index 758323e..a233c1f 100644 --- a/cfrontend/PrintCsyntax.ml +++ b/cfrontend/PrintCsyntax.ml @@ -179,13 +179,24 @@ let print_pointer_hook : (formatter -> Values.block * Integers.Int.int -> unit) ref = ref (fun p (b, ofs) -> ()) -let print_value p v = - match v with - | Vint n -> fprintf p "%ld" (camlint_of_coqint n) - | Vfloat f -> fprintf p "%F" (camlfloat_of_coqfloat f) - | Vlong n -> fprintf p "%Ld" (camlint64_of_coqint n) - | Vptr(b, ofs) -> fprintf p "" !print_pointer_hook (b, ofs) - | Vundef -> fprintf p "" +let print_typed_value p v ty = + match v, ty with + | Vint n, Tint(I32, Unsigned, _) -> + fprintf p "%luU" (camlint_of_coqint n) + | Vint n, _ -> + fprintf p "%ld" (camlint_of_coqint n) + | Vfloat f, _ -> + fprintf p "%F" (camlfloat_of_coqfloat f) + | Vlong n, Tlong(Unsigned, _) -> + fprintf p "%LuLLU" (camlint64_of_coqint n) + | Vlong n, _ -> + fprintf p "%LdLL" (camlint64_of_coqint n) + | Vptr(b, ofs), _ -> + fprintf p "" !print_pointer_hook (b, ofs) + | Vundef, _ -> + fprintf p "" + +let print_value p v = print_typed_value p v Tvoid let rec expr p (prec, e) = let (prec', assoc) = precedence e in @@ -207,8 +218,8 @@ let rec expr p (prec, e) = fprintf p "%a.%s" expr (prec', a1) (extern_atom f) | Evalof(l, _) -> expr p (prec, l) - | Eval(v, _) -> - print_value p (v) + | Eval(v, ty) -> + print_typed_value p v ty | Esizeof(ty, _) -> fprintf p "sizeof(%s)" (name_type ty) | Ealignof(ty, _) -> @@ -251,6 +262,8 @@ let rec expr p (prec, e) = | Ebuiltin(EF_annot_val(txt, _), _, args, _) -> fprintf p "__builtin_annot_val@[(%S%a)@]" (extern_atom txt) exprlist (false, args) + | Ebuiltin(EF_external(id, sg), _, args, _) -> + fprintf p "%s@[(%a)@]" (extern_atom id) exprlist (true, args) | Ebuiltin(_, _, args, _) -> fprintf p "@[(%a)@]" exprlist (true, args) | Eparen(a1, ty) -> -- cgit v1.2.3