Skip to content

Commit a55025d

Browse files
authored
clightgen: add info on configuration and platform to generated .v files (AbsInt#238)
Information about the run of clightgen is added to the generated .v file as definitions within a sub-module named Info. Closes: AbsInt#226.
1 parent b193660 commit a55025d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

exportclight/Clightgen.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ let compile_c_ast sourcename csyntax ofile =
5353
end;
5454
(* Print Clight in Coq syntax *)
5555
let oc = open_out ofile in
56-
ExportClight.print_program (Format.formatter_of_out_channel oc) clight;
56+
ExportClight.print_program (Format.formatter_of_out_channel oc)
57+
clight sourcename !option_normalize;
5758
close_out oc
5859

5960
(* From C source to Clight *)

exportclight/ExportClight.ml

+19-3
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ let print_assertions p =
487487
let prologue = "\
488488
From Coq Require Import String List ZArith.\n\
489489
From compcert Require Import Coqlib Integers Floats AST Ctypes Cop Clight Clightdefs.\n\
490-
Local Open Scope Z_scope.\n\
491-
\n"
490+
Local Open Scope Z_scope.\n"
492491

493492
(* Naming the compiler-generated temporaries occurring in the program *)
494493

@@ -543,13 +542,30 @@ let name_globdef (id, g) =
543542
let name_program p =
544543
List.iter name_globdef p.Ctypes.prog_defs
545544

545+
(* Information about this run of clightgen *)
546+
547+
let print_clightgen_info p sourcefile normalized =
548+
fprintf p "@[<v 2>Module Info.";
549+
fprintf p "@ Definition version := %S%%string." Version.version;
550+
fprintf p "@ Definition build_number := %S%%string." Version.buildnr;
551+
fprintf p "@ Definition build_tag := %S%%string." Version.tag;
552+
fprintf p "@ Definition arch := %S%%string." Configuration.arch;
553+
fprintf p "@ Definition model := %S%%string." Configuration.model;
554+
fprintf p "@ Definition abi := %S%%string." Configuration.abi;
555+
fprintf p "@ Definition bitsize := %d." (if Archi.ptr64 then 64 else 32);
556+
fprintf p "@ Definition big_endian := %B." Archi.big_endian;
557+
fprintf p "@ Definition source_file := %S%%string." sourcefile;
558+
fprintf p "@ Definition normalized := %B." normalized;
559+
fprintf p "@]@ End Info.@ @ "
560+
546561
(* All together *)
547562

548-
let print_program p prog =
563+
let print_program p prog sourcefile normalized =
549564
Hashtbl.clear temp_names;
550565
name_program prog;
551566
fprintf p "@[<v 0>";
552567
fprintf p "%s" prologue;
568+
print_clightgen_info p sourcefile normalized;
553569
define_idents p;
554570
List.iter (print_globdef p) prog.Ctypes.prog_defs;
555571
fprintf p "Definition composites : list composite_definition :=@ ";

0 commit comments

Comments
 (0)