summaryrefslogtreecommitdiff
path: root/cfrontend
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-05-26 11:59:09 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-05-26 11:59:09 +0000
commitf0db487d8c8798b9899be03bf65bcb12524b9186 (patch)
treeaa9c57edf987fed973dfebd0de067be7bcdb089c /cfrontend
parentee8556f646ac19726f012fff78fffdee39f5be63 (diff)
Updated Caml parts to match new representation for global variables.
*/PrintAsm.ml: watch out for large stack frames in Pallocframe. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1349 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cfrontend')
-rw-r--r--cfrontend/C2Clight.ml16
-rw-r--r--cfrontend/PrintCsyntax.ml23
2 files changed, 27 insertions, 12 deletions
diff --git a/cfrontend/C2Clight.ml b/cfrontend/C2Clight.ml
index 5bdd727..2f61d53 100644
--- a/cfrontend/C2Clight.ml
+++ b/cfrontend/C2Clight.ml
@@ -69,7 +69,9 @@ let global_for_string s id =
:: !init in
add_char '\000';
for i = String.length s - 1 downto 0 do add_char s.[i] done;
- Datatypes.Coq_pair(Datatypes.Coq_pair(id, !init), typeStringLiteral s)
+ Datatypes.Coq_pair(id,
+ {gvar_info = typeStringLiteral s; gvar_init = !init;
+ gvar_readonly = true; gvar_volatile = false})
let globals_for_strings globs =
Hashtbl.fold
@@ -654,6 +656,13 @@ let rec type_is_readonly env t =
| C.TArray(t', _, _) -> type_is_readonly env t'
| _ -> false
+let rec type_is_volatile env t =
+ let a = Cutil.attributes_of_type env t in
+ if List.mem C.AConst a then true else
+ match Cutil.unroll env t with
+ | C.TArray(t', _, _) -> type_is_volatile env t'
+ | _ -> false
+
let convertGlobvar env (sto, id, ty, optinit as decl) =
let id' = intern_string id.name in
let ty' = convertTyp env ty in
@@ -667,7 +676,10 @@ let convertGlobvar env (sto, id, ty, optinit as decl) =
Sections.define_variable id'
(match Cutil.sizeof env ty with Some sz -> sz | None -> max_int)
(type_is_readonly env ty);
- Datatypes.Coq_pair(Datatypes.Coq_pair(id', init'), ty')
+ Datatypes.Coq_pair(id',
+ {gvar_info = ty'; gvar_init = init';
+ gvar_readonly = type_is_readonly env ty;
+ gvar_volatile = type_is_volatile env ty})
(** Convert a list of global declarations.
Result is a pair [(funs, vars)] where [funs] are
diff --git a/cfrontend/PrintCsyntax.ml b/cfrontend/PrintCsyntax.ml
index d678831..3b5dbc5 100644
--- a/cfrontend/PrintCsyntax.ml
+++ b/cfrontend/PrintCsyntax.ml
@@ -376,24 +376,27 @@ let print_init p = function
let re_string_literal = Str.regexp "__stringlit_[0-9]+"
-let print_globvar p (Coq_pair(Coq_pair(id, init), ty)) =
- match init with
+let print_globvar p (Coq_pair(id, v)) =
+ let name1 = extern_atom id in
+ let name2 = if v.gvar_readonly then "const " ^ name1 else name1 in
+ let name3 = if v.gvar_volatile then "volatile " ^ name2 else name2 in
+ match v.gvar_init with
| [] ->
fprintf p "extern %s;@ @ "
- (name_cdecl (extern_atom id) ty)
+ (name_cdecl name3 v.gvar_info)
| [Init_space _] ->
fprintf p "%s;@ @ "
- (name_cdecl (extern_atom id) ty)
+ (name_cdecl name3 v.gvar_info)
| _ ->
fprintf p "@[<hov 2>%s = "
- (name_cdecl (extern_atom id) ty);
+ (name_cdecl name3 v.gvar_info);
if Str.string_match re_string_literal (extern_atom id) 0
- && List.for_all (function Init_int8 _ -> true | _ -> false) init
+ && List.for_all (function Init_int8 _ -> true | _ -> false) v.gvar_init
then
- fprintf p "\"%s\"" (string_of_init (chop_last_nul init))
+ fprintf p "\"%s\"" (string_of_init (chop_last_nul v.gvar_init))
else begin
fprintf p "{@ ";
- List.iter (print_init p) init;
+ List.iter (print_init p) v.gvar_init;
fprintf p "}"
end;
fprintf p ";@]@ @ "
@@ -474,8 +477,8 @@ let collect_fundef (Coq_pair(id, fd)) =
| External(_, args, res) -> collect_type_list args; collect_type res
| Internal f -> collect_function f
-let collect_globvar (Coq_pair(Coq_pair(id, init), ty)) =
- collect_type ty
+let collect_globvar (Coq_pair(id, v)) =
+ collect_type v.gvar_info
let collect_program p =
List.iter collect_globvar p.prog_vars;