aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.extr6
-rw-r--r--arm/AsmToJSON.mli13
-rw-r--r--arm/Asmexpand.ml9
-rw-r--r--arm/TargetPrinter.ml61
-rw-r--r--backend/Asmexpandaux.ml9
-rw-r--r--backend/Asmexpandaux.mli36
-rw-r--r--backend/CMlexer.mll2
-rw-r--r--backend/CMparser.mly2
-rw-r--r--backend/CMtypecheck.ml17
-rw-r--r--backend/IRC.ml31
-rw-r--r--backend/IRC.mli1
-rw-r--r--backend/Inliningaux.ml2
-rw-r--r--backend/Linearizeaux.ml3
-rw-r--r--backend/PrintAsm.ml5
-rw-r--r--backend/PrintAsm.mli2
-rw-r--r--backend/PrintAsmaux.ml1
-rw-r--r--backend/PrintCminor.ml3
-rw-r--r--backend/PrintLTL.ml3
-rw-r--r--backend/PrintMach.ml4
-rw-r--r--backend/PrintRTL.ml2
-rw-r--r--backend/PrintXTL.ml4
-rw-r--r--backend/RTLgenaux.ml2
-rw-r--r--backend/Regalloc.ml40
-rw-r--r--backend/Splitting.ml2
-rw-r--r--cfrontend/C2C.ml100
-rw-r--r--cfrontend/PrintClight.ml14
-rw-r--r--cfrontend/PrintCsyntax.ml15
-rw-r--r--common/Sections.ml2
-rw-r--r--common/Switchaux.ml1
-rwxr-xr-xconfigure10
-rw-r--r--cparser/Bitfields.ml10
-rw-r--r--cparser/Ceval.ml41
-rw-r--r--cparser/Cutil.ml7
-rw-r--r--cparser/Cutil.mli4
-rw-r--r--cparser/Elab.ml34
-rw-r--r--cparser/Env.ml11
-rw-r--r--cparser/ExtendedAsm.ml1
-rw-r--r--cparser/Lexer.mll5
-rw-r--r--cparser/PackedStructs.ml12
-rw-r--r--cparser/StructReturn.ml2
-rw-r--r--cparser/Transform.ml4
-rw-r--r--cparser/Transform.mli2
-rw-r--r--cparser/Unblock.ml19
-rw-r--r--debug/Debug.ml5
-rw-r--r--debug/Debug.mli2
-rw-r--r--debug/DebugInformation.ml66
-rw-r--r--debug/DebugInformation.mli106
-rw-r--r--debug/DebugInit.ml8
-rw-r--r--debug/DebugTypes.mli20
-rw-r--r--debug/DwarfPrinter.ml11
-rw-r--r--debug/DwarfTypes.mli3
-rw-r--r--debug/Dwarfgen.ml52
-rw-r--r--driver/Configuration.mli11
-rw-r--r--driver/Driver.ml18
-rw-r--r--driver/Interp.ml21
-rw-r--r--exportclight/Clightgen.ml1
-rw-r--r--exportclight/ExportClight.ml33
-rw-r--r--ia32/AsmToJSON.mli13
-rw-r--r--ia32/Asmexpand.ml5
-rw-r--r--ia32/TargetPrinter.ml49
-rw-r--r--lib/Camlcoq.ml6
-rw-r--r--lib/Json.ml12
-rw-r--r--lib/Printlines.ml6
-rw-r--r--lib/Printlines.mli2
-rw-r--r--powerpc/AsmToJSON.ml219
-rw-r--r--powerpc/AsmToJSON.mli13
-rw-r--r--powerpc/Asmexpand.ml10
-rw-r--r--powerpc/TargetPrinter.ml25
68 files changed, 624 insertions, 647 deletions
diff --git a/Makefile.extr b/Makefile.extr
index 87d5107d..503c6a6a 100644
--- a/Makefile.extr
+++ b/Makefile.extr
@@ -38,9 +38,9 @@ INCLUDES=$(patsubst %,-I %, $(DIRS))
# warning 3 = deprecated feature. Turned off for OCaml 4.02 (bytes vs strings)
# warning 20 = unused function argument. There are some in extracted code
-WARNINGS=-w -3 -strict-sequence
-extraction/%.cmx: WARNINGS +=-w -20
-extraction/%.cmo: WARNINGS +=-w -20
+WARNINGS=-w +a-4-9-27-29 -strict-sequence -safe-string -warn-error +a
+extraction/%.cmx: WARNINGS +=-w -20-27-32..34-39-41-44..45
+extraction/%.cmo: WARNINGS +=-w -20-27-32..34-39-41-44..45
COMPFLAGS+=-g $(INCLUDES) $(MENHIR_INCLUDES) $(WARNINGS)
diff --git a/arm/AsmToJSON.mli b/arm/AsmToJSON.mli
new file mode 100644
index 00000000..20bcba5e
--- /dev/null
+++ b/arm/AsmToJSON.mli
@@ -0,0 +1,13 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
+(* *)
+(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
+(* is distributed under the terms of the INRIA Non-Commercial *)
+(* License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+val p_program: out_channel -> (Asm.coq_function AST.fundef, 'a) AST.program -> unit
diff --git a/arm/Asmexpand.ml b/arm/Asmexpand.ml
index 47269f8f..79f06991 100644
--- a/arm/Asmexpand.ml
+++ b/arm/Asmexpand.ml
@@ -16,7 +16,6 @@
open Asm
open Asmexpandaux
-open Asmgen
open AST
open Camlcoq
open Integers
@@ -268,11 +267,11 @@ let rec next_arg_location ir ofs = function
else next_arg_location 4 (align ofs 8 + 8) l
let expand_builtin_va_start r =
- if not !current_function.fn_sig.sig_cc.cc_vararg then
+ if not (is_current_function_variadic ()) then
invalid_arg "Fatal error: va_start used in non-vararg function";
let ofs =
Int32.add
- (next_arg_location 0 0 !current_function.fn_sig.sig_args)
+ (next_arg_location 0 0 (get_current_function_args ()))
!PrintAsmaux.current_function_stacksize in
expand_addimm IR14 IR13 (coqint_of_camlint ofs);
emit (Pstr (IR14,r,SOimm _0))
@@ -364,7 +363,7 @@ let expand_instruction instr =
match instr with
| Pallocframe (sz, ofs) ->
emit (Pmov (IR12,SOreg IR13));
- if (!current_function).fn_sig.sig_cc.cc_vararg then begin
+ if (is_current_function_variadic ()) then begin
emit (Ppush [IR0;IR1;IR2;IR3]);
emit (Pcfi_adjust _16);
end;
@@ -374,7 +373,7 @@ let expand_instruction instr =
PrintAsmaux.current_function_stacksize := camlint_of_coqint sz
| Pfreeframe (sz, ofs) ->
let sz =
- if (!current_function).fn_sig.sig_cc.cc_vararg
+ if (is_current_function_variadic ())
then coqint_of_camlint (Int32.add 16l (camlint_of_coqint sz))
else sz in
if Asmgen.is_immed_arith sz
diff --git a/arm/TargetPrinter.ml b/arm/TargetPrinter.ml
index 3ca90ce9..bfe11555 100644
--- a/arm/TargetPrinter.ml
+++ b/arm/TargetPrinter.ml
@@ -13,11 +13,10 @@
(* Printing ARM assembly code in asm syntax *)
open Printf
-open Datatypes
+open !Datatypes
open Camlcoq
open Sections
open AST
-open Memdata
open Asm
open PrintAsmaux
open Fileinfo
@@ -68,12 +67,6 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET =
| FR8 -> "d8" | FR9 -> "d9" | FR10 -> "d10" | FR11 -> "d11"
| FR12 -> "d12" | FR13 -> "d13" | FR14 -> "d14" | FR15 -> "d15"
- let single_float_reg_index = function
- | FR0 -> 0 | FR1 -> 2 | FR2 -> 4 | FR3 -> 6
- | FR4 -> 8 | FR5 -> 10 | FR6 -> 12 | FR7 -> 14
- | FR8 -> 16 | FR9 -> 18 | FR10 -> 20 | FR11 -> 22
- | FR12 -> 24 | FR13 -> 26 | FR14 -> 28 | FR15 -> 30
-
let single_float_reg_name = function
| FR0 -> "s0" | FR1 -> "s2" | FR2 -> "s4" | FR3 -> "s6"
| FR4 -> "s8" | FR5 -> "s10" | FR6 -> "s12" | FR7 -> "s14"
@@ -130,7 +123,7 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET =
orr
rsb
sub (but not sp - imm)
- On the other hand, "mov rd, rs" and "mov rd, #imm" have shorter
+ On the other hand, "mov rd, rs" and "mov rd, #imm" have shorter
encodings if they do not have the "S" flag. Moreover, the "S"
flag is not supported if rd or rs is sp.
@@ -257,39 +250,6 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET =
ireg r lbl symbol_offset (id, ofs); 1
end
-(* Emit instruction sequences that set or offset a register by a constant. *)
-(* No S suffix because they are applied to SP most of the time. *)
-
- let movimm oc dst n =
- match Asmgen.decompose_int n with
- | [] -> assert false
- | hd::tl as l ->
- fprintf oc " mov %s, #%a\n" dst coqint hd;
- List.iter
- (fun n -> fprintf oc " orr %s, %s, #%a\n" dst dst coqint n)
- tl;
- List.length l
-
- let addimm oc dst src n =
- match Asmgen.decompose_int n with
- | [] -> assert false
- | hd::tl as l ->
- fprintf oc " add %s, %s, #%a\n" dst src coqint hd;
- List.iter
- (fun n -> fprintf oc " add %s, %s, #%a\n" dst dst coqint n)
- tl;
- List.length l
-
- let subimm oc dst src n =
- match Asmgen.decompose_int n with
- | [] -> assert false
- | hd::tl as l ->
- fprintf oc " sub %s, %s, #%a\n" dst src coqint hd;
- List.iter
- (fun n -> fprintf oc " sub %s, %s, #%a\n" dst dst coqint n)
- tl;
- List.length l
-
(* Recognition of float constants appropriate for VMOV.
a normalized binary floating point encoding with 1 sign bit, 4
bits of fraction and a 3-bit exponent *)
@@ -310,23 +270,6 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET =
let print_file_line oc file line =
print_file_line oc comment file line
- let print_location oc loc =
- if loc <> Cutil.no_loc then print_file_line oc (fst loc) (snd loc)
-
-(* Auxiliary for 64-bit integer arithmetic built-ins. They expand to
- two instructions, one computing the low 32 bits of the result,
- followed by another computing the high 32 bits. In cases where
- the first instruction would overwrite arguments to the second
- instruction, we must go through IR14 to hold the low 32 bits of the result.
- *)
-
- let print_int64_arith oc conflict rl fn =
- if conflict then begin
- let n = fn IR14 in
- fprintf oc " mov %a, %a\n" ireg rl ireg IR14;
- n + 1
- end else
- fn rl
(* Fixing up calling conventions *)
diff --git a/backend/Asmexpandaux.ml b/backend/Asmexpandaux.ml
index 3d1dd754..13aa71d2 100644
--- a/backend/Asmexpandaux.ml
+++ b/backend/Asmexpandaux.ml
@@ -50,6 +50,15 @@ let new_label () =
let set_current_function f =
current_function := f; next_label := None; current_code := []
+let get_current_function_args () =
+ (!current_function).fn_sig.sig_args
+
+let is_current_function_variadic () =
+ (!current_function).fn_sig.sig_cc.cc_vararg
+
+let get_current_function_sig () =
+ (!current_function).fn_sig
+
let get_current_function () =
let c = List.rev !current_code in
let fn = !current_function in
diff --git a/backend/Asmexpandaux.mli b/backend/Asmexpandaux.mli
new file mode 100644
index 00000000..797eb10c
--- /dev/null
+++ b/backend/Asmexpandaux.mli
@@ -0,0 +1,36 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Xavier Leroy, INRIA Paris-Rocquencourt *)
+(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
+(* *)
+(* Copyright Institut National de Recherche en Informatique et en *)
+(* Automatique. All rights reserved. This file is distributed *)
+(* under the terms of the INRIA Non-Commercial License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+open Asm
+open AST
+open BinNums
+
+(** Auxiliary functions for builtin expansion *)
+
+val emit: instruction -> unit
+ (* Emit an instruction *)
+val new_label: unit -> label
+ (* Compute a fresh label *)
+val is_current_function_variadic: unit -> bool
+ (* Test wether the current function is a variadic function *)
+val get_current_function_args: unit -> typ list
+ (* Get the types of the current function arguments *)
+val get_current_function_sig: unit -> signature
+ (* Get the signature of the current function *)
+val set_current_function: coq_function -> unit
+ (* Set the current function *)
+val get_current_function: unit -> coq_function
+ (* Get the current function *)
+val expand_debug: positive -> int -> (preg -> int) -> (instruction -> unit) -> instruction list -> unit
+ (* Expand builtin debug function. Takes the function id, the register number of the stackpointer, a
+ function to get the dwarf mapping of varibale names and for the expansion of simple instructions *)
diff --git a/backend/CMlexer.mll b/backend/CMlexer.mll
index a595311a..c82f5401 100644
--- a/backend/CMlexer.mll
+++ b/backend/CMlexer.mll
@@ -14,8 +14,6 @@
(* *********************************************************************)
{
-open BinNums
-open Camlcoq
open CMparser
exception Error of string
}
diff --git a/backend/CMparser.mly b/backend/CMparser.mly
index e712057c..7fa6500a 100644
--- a/backend/CMparser.mly
+++ b/backend/CMparser.mly
@@ -17,7 +17,7 @@
including function calls in expressions, matches, while statements, etc. */
%{
-open Datatypes
+open !Datatypes
open Camlcoq
open BinNums
open Integers
diff --git a/backend/CMtypecheck.ml b/backend/CMtypecheck.ml
index 72bf9cb4..cd0d25dc 100644
--- a/backend/CMtypecheck.ml
+++ b/backend/CMtypecheck.ml
@@ -18,11 +18,9 @@
(* FIXME: proper support for type Tsingle *)
open Printf
-open Datatypes
open Camlcoq
open AST
open PrintAST
-open Integers
open Cminor
exception Error of string
@@ -74,21 +72,6 @@ let type_var env id =
with Not_found ->
raise (Error (sprintf "Unbound variable %s\n" (extern_atom id)))
-let type_letvar env n =
- let n = Nat.to_int n in
- try
- List.nth env n
- with Not_found ->
- raise (Error (sprintf "Unbound let variable #%d\n" n))
-
-let name_of_comparison = function
- | Ceq -> "eq"
- | Cne -> "ne"
- | Clt -> "lt"
- | Cle -> "le"
- | Cgt -> "gt"
- | Cge -> "ge"
-
let type_constant = function
| Ointconst _ -> tint
| Ofloatconst _ -> tfloat
diff --git a/backend/IRC.ml b/backend/IRC.ml
index eb677069..d542f85e 100644
--- a/backend/IRC.ml
+++ b/backend/IRC.ml
@@ -12,13 +12,11 @@
open Printf
open Camlcoq
-open Datatypes
open AST
open Registers
open Machregs
open Locations
open Conventions1
-open Conventions
open XTL
(* Iterated Register Coalescing: George and Appel's graph coloring algorithm *)
@@ -138,7 +136,6 @@ module DLinkNode = struct
nstate = state; nprev = empty; nnext = empty }
in empty
let dummy = make Colored
- let clear dl = dl.nnext <- dl; dl.nprev <- dl
let notempty dl = dl.nnext != dl
let insert n dl =
n.nstate <- dl.nstate;
@@ -167,7 +164,6 @@ module DLinkMove = struct
mstate = state; mprev = empty; mnext = empty }
in empty
let dummy = make CoalescedMoves
- let clear dl = dl.mnext <- dl; dl.mprev <- dl
let notempty dl = dl.mnext != dl
let insert m dl =
m.mstate <- dl.mstate;
@@ -180,12 +176,6 @@ module DLinkMove = struct
remove m dl1; insert m dl2
let pick dl =
let m = dl.mnext in remove m dl; m
- let iter f dl =
- let rec iter m = if m != dl then (f m; iter m.mnext)
- in iter dl.mnext
- let fold f dl accu =
- let rec fold m accu = if m == dl then accu else fold m.mnext (f m accu)
- in fold dl.mnext accu
end
(* Auxiliary data structures *)
@@ -447,7 +437,7 @@ let moveRelated n =
(* Initial partition of nodes into spill / freeze / simplify *)
let initialNodePartition g =
- let part_node v n =
+ let part_node n =
match n.nstate with
| Initial ->
let k = g.num_available_registers.(n.regclass) in
@@ -459,43 +449,42 @@ let initialNodePartition g =
DLinkNode.insert n g.simplifyWorklist
| Colored -> ()
| _ -> assert false in
- Hashtbl.iter part_node g.varTable
-
+ Hashtbl.iter (fun _ a -> part_node a) g.varTable
(* Check invariants *)
-let degreeInvariant g n =
+let _degreeInvariant _ n =
let c = ref 0 in
iterAdjacent (fun n -> incr c) n;
if !c <> n.degree then
failwith("degree invariant violated by " ^ name_of_node n)
-let simplifyWorklistInvariant g n =
+let _simplifyWorklistInvariant g n =
if n.degree < g.num_available_registers.(n.regclass)
&& not (moveRelated n)
then ()
else failwith("simplify worklist invariant violated by " ^ name_of_node n)
-let freezeWorklistInvariant g n =
+let _freezeWorklistInvariant g n =
if n.degree < g.num_available_registers.(n.regclass)
&& moveRelated n
then ()
else failwith("freeze worklist invariant violated by " ^ name_of_node n)
-let spillWorklistInvariant g n =
+let _spillWorklistInvariant g n =
if n.degree >= g.num_available_registers.(n.regclass)
then ()
else failwith("spill worklist invariant violated by " ^ name_of_node n)
-let checkInvariants g =
+let _checkInvariants g =
DLinkNode.iter
- (fun n -> degreeInvariant g n; simplifyWorklistInvariant g n)
+ (fun n -> _degreeInvariant g n; _simplifyWorklistInvariant g n)
g.simplifyWorklist;
DLinkNode.iter
- (fun n -> degreeInvariant g n; freezeWorklistInvariant g n)
+ (fun n -> _degreeInvariant g n; _freezeWorklistInvariant g n)
g.freezeWorklist;
DLinkNode.iter
- (fun n -> degreeInvariant g n; spillWorklistInvariant g n)
+ (fun n -> _degreeInvariant g n; _spillWorklistInvariant g n)
g.spillWorklist
(* Enable moves that have become low-degree related *)
diff --git a/backend/IRC.mli b/backend/IRC.mli
index e81b6dc5..d27dedaa 100644
--- a/backend/IRC.mli
+++ b/backend/IRC.mli
@@ -12,7 +12,6 @@
(* Iterated Register Coalescing: George and Appel's graph coloring algorithm *)
-open AST
open Registers
open Machregs
open Locations
diff --git a/backend/Inliningaux.ml b/backend/Inliningaux.ml
index 42129166..265831a5 100644
--- a/backend/Inliningaux.ml
+++ b/backend/Inliningaux.ml
@@ -10,8 +10,6 @@
(* *)
(* *********************************************************************)
-open Camlcoq
-
(* To be considered: heuristics based on size of function? *)
let should_inline (id: AST.ident) (f: RTL.coq_function) =
diff --git a/backend/Linearizeaux.ml b/backend/Linearizeaux.ml
index 71ee2e56..46d5c3f1 100644
--- a/backend/Linearizeaux.ml
+++ b/backend/Linearizeaux.ml
@@ -10,10 +10,7 @@
(* *)
(* *********************************************************************)
-open Coqlib
-open Datatypes
open LTL
-open Lattice
open Maps
open Camlcoq
diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml
index 6c1eda57..96aa080e 100644
--- a/backend/PrintAsm.ml
+++ b/backend/PrintAsm.ml
@@ -12,9 +12,8 @@
(* *********************************************************************)
open AST
-open Asm
open Camlcoq
-open Datatypes
+open !Datatypes
open DwarfPrinter
open PrintAsmaux
open Printf
@@ -119,7 +118,7 @@ module Printer(Target:TARGET) =
module DebugPrinter = DwarfPrinter (DwarfTarget)
end
-let print_program oc p db =
+let print_program oc p =
let module Target = (val (sel_target ()):TARGET) in
let module Printer = Printer(Target) in
Fileinfo.reset_filenames ();
diff --git a/backend/PrintAsm.mli b/backend/PrintAsm.mli
index 0b2869b0..29e91540 100644
--- a/backend/PrintAsm.mli
+++ b/backend/PrintAsm.mli
@@ -11,4 +11,4 @@
(* *)
(* *********************************************************************)
-val print_program: out_channel -> Asm.program -> DwarfTypes.dw_entry option -> unit
+val print_program: out_channel -> Asm.program -> unit
diff --git a/backend/PrintAsmaux.ml b/backend/PrintAsmaux.ml
index 0ca5b8e0..148c5300 100644
--- a/backend/PrintAsmaux.ml
+++ b/backend/PrintAsmaux.ml
@@ -14,7 +14,6 @@
open AST
open Asm
open Camlcoq
-open Datatypes
open Memdata
open Printf
open Sections
diff --git a/backend/PrintCminor.ml b/backend/PrintCminor.ml
index 45c18e9a..d50e07a3 100644
--- a/backend/PrintCminor.ml
+++ b/backend/PrintCminor.ml
@@ -17,7 +17,6 @@
open Format
open Camlcoq
-open Datatypes
open Integers
open AST
open PrintAST
@@ -27,7 +26,7 @@ open Cminor
type associativity = LtoR | RtoL | NA
-let rec precedence = function
+let precedence = function
| Evar _ -> (16, NA)
| Econst _ -> (16, NA)
| Eunop _ -> (15, RtoL)
diff --git a/backend/PrintLTL.ml b/backend/PrintLTL.ml
index 0f78bc58..a0a08218 100644
--- a/backend/PrintLTL.ml
+++ b/backend/PrintLTL.ml
@@ -17,8 +17,7 @@ open Camlcoq
open Datatypes
open Maps
open AST
-open Integers
-open Locations
+open !Locations
open LTL
open PrintAST
open PrintOp
diff --git a/backend/PrintMach.ml b/backend/PrintMach.ml
index 0ce2e87b..517f3037 100644
--- a/backend/PrintMach.ml
+++ b/backend/PrintMach.ml
@@ -15,14 +15,10 @@
open Printf
open Camlcoq
open Datatypes
-open Maps
open AST
-open Integers
-open Locations
open Machregsaux
open Mach
open PrintAST
-open PrintOp
let reg pp r =
match name_of_register r with
diff --git a/backend/PrintRTL.ml b/backend/PrintRTL.ml
index f2242c13..ba336b0a 100644
--- a/backend/PrintRTL.ml
+++ b/backend/PrintRTL.ml
@@ -17,10 +17,8 @@ open Camlcoq
open Datatypes
open Maps
open AST
-open Integers
open RTL
open PrintAST
-open PrintOp
(* Printing of RTL code *)
diff --git a/backend/PrintXTL.ml b/backend/PrintXTL.ml
index dd8434da..31273f97 100644
--- a/backend/PrintXTL.ml
+++ b/backend/PrintXTL.ml
@@ -17,9 +17,7 @@ open Camlcoq
open Datatypes
open Maps
open AST
-open Registers
-open Op
-open Locations
+open !Locations
open PrintAST
open PrintOp
open XTL
diff --git a/backend/RTLgenaux.ml b/backend/RTLgenaux.ml
index 045299d4..e39d3b56 100644
--- a/backend/RTLgenaux.ml
+++ b/backend/RTLgenaux.ml
@@ -11,9 +11,7 @@
(* *********************************************************************)
open Datatypes
-open Camlcoq
open AST
-open Switch
open CminorSel
(* Heuristic to orient if-then-else statements.
diff --git a/backend/Regalloc.ml b/backend/Regalloc.ml
index a5fa8cd7..e531a34a 100644
--- a/backend/Regalloc.ml
+++ b/backend/Regalloc.ml
@@ -33,9 +33,7 @@ open Datatypes
open Coqlib
open Maps
open AST
-open Memdata
open Kildall
-open Registers
open Op
open Machregs
open Locations
@@ -94,9 +92,9 @@ let rec constrain_regs vl cl =
let move v1 v2 k =
if v1 = v2 then
k
- else if is_stack_reg v1 then begin
+ else if XTL.is_stack_reg v1 then begin
let t = new_temp (typeof v2) in Xmove(v1, t) :: Xmove(t, v2) :: k
- end else if is_stack_reg v2 then begin
+ end else if XTL.is_stack_reg v2 then begin
let t = new_temp (typeof v1) in Xmove(v1, t) :: Xmove(t, v2) :: k
end else
Xmove(v1, v2) :: k
@@ -308,7 +306,7 @@ let rec vset_removeres r after =
let live_before instr after =
match instr with
| Xmove(src, dst) | Xspill(src, dst) | Xreload(src, dst) ->
- if VSet.mem dst after || is_stack_reg src
+ if VSet.mem dst after || XTL.is_stack_reg src
then VSet.add src (VSet.remove dst after)
else after
| Xparmove(srcs, dsts, itmp, ftmp) ->
@@ -385,7 +383,7 @@ let rec dce_parmove srcs dsts after =
| [], [] -> [], []
| src1 :: srcs, dst1 :: dsts ->
let (srcs', dsts') = dce_parmove srcs dsts after in
- if VSet.mem dst1 after || is_stack_reg src1
+ if VSet.mem dst1 after || XTL.is_stack_reg src1
then (src1 :: srcs', dst1 :: dsts')
else (srcs', dsts')
| _, _ -> assert false
@@ -399,7 +397,7 @@ let rec keep_builtin_arg after = function
let dce_instr instr after k =
match instr with
| Xmove(src, dst) ->
- if VSet.mem dst after || is_stack_reg src
+ if VSet.mem dst after || XTL.is_stack_reg src
then instr :: k
else k
| Xparmove(srcs, dsts, itmp, ftmp) ->
@@ -431,7 +429,7 @@ let rec dce_block blk after =
let dead_code_elimination f liveness =
{ f with fn_code =
- PTree.map (fun pc blk -> snd(dce_block blk (PMap.get pc liveness)))
+ PTree.map (fun pc blk -> Datatypes.snd(dce_block blk (PMap.get pc liveness)))
f.fn_code }
@@ -484,9 +482,9 @@ let spill_costs f =
let charge_instr = function
| Xmove(src, dst) ->
- if is_stack_reg src then
+ if XTL.is_stack_reg src then
force_stack_allocation dst
- else if is_stack_reg dst then
+ else if XTL.is_stack_reg dst then
force_stack_allocation src
else begin
charge 1 1 src; charge 1 1 dst
@@ -595,12 +593,12 @@ let add_interfs_instr g instr live =
add_interfs_list g itmp srcs; add_interfs_list g itmp dsts;
add_interfs_list g ftmp srcs; add_interfs_list g ftmp dsts;
(* Take into account destroyed reg when accessing Incoming param *)
- if List.exists (function (L(S(Incoming, _, _))) -> true | _ -> false) srcs
+ if List.exists (function (L(Locations.S(Incoming, _, _))) -> true | _ -> false) srcs
then add_interfs_list g (vmreg temp_for_parent_frame) dsts;
(* Take into account destroyed reg when initializing Outgoing
arguments of type Tsingle *)
if List.exists
- (function (L(S(Outgoing, _, Tsingle))) -> true | _ -> false) dsts
+ (function (L(Locations.S(Outgoing, _, Tsingle))) -> true | _ -> false) dsts
then
List.iter
(fun mr ->
@@ -690,10 +688,10 @@ let find_coloring f liveness =
(*********** Determination of variables that need spill code insertion *****)
let is_reg alloc v =
- match alloc v with R _ -> true | S _ -> false
+ match alloc v with R _ -> true | Locations.S _ -> false
let add_tospill alloc v ts =
- match alloc v with R _ -> ts | S _ -> VSet.add v ts
+ match alloc v with R _ -> ts | Locations.S _ -> VSet.add v ts
let addlist_tospill alloc vl ts =
List.fold_right (add_tospill alloc) vl ts
@@ -963,7 +961,7 @@ let spill_function f tospill round =
exception Bad_LTL
-let mreg_of alloc v = match alloc v with R mr -> mr | S _ -> raise Bad_LTL
+let mreg_of alloc v = match alloc v with R mr -> mr | Locations.S _ -> raise Bad_LTL
let mregs_of alloc vl = List.map (mreg_of alloc) vl
@@ -973,11 +971,11 @@ let make_move src dst k =
match src, dst with
| R rsrc, R rdst ->
if rsrc = rdst then k else LTL.Lop(Omove, [rsrc], rdst) :: k
- | R rsrc, S(sl, ofs, ty) ->
+ | R rsrc, Locations.S(sl, ofs, ty) ->
LTL.Lsetstack(rsrc, sl, ofs, ty) :: k
- | S(sl, ofs, ty), R rdst ->
+ | Locations.S(sl, ofs, ty), R rdst ->
LTL.Lgetstack(sl, ofs, ty, rdst) :: k
- | S _, S _ ->
+ | Locations.S _, Locations.S _ ->
if src = dst then k else raise Bad_LTL
type parmove_status = To_move | Being_moved | Moved
@@ -997,11 +995,11 @@ let make_parmove srcs dsts itmp ftmp k =
match s, d with
| R rs, R rd ->
code := LTL.Lop(Omove, [rs], rd) :: !code
- | R rs, S(sl, ofs, ty) ->
+ | R rs, Locations.S(sl, ofs, ty) ->
code := LTL.Lsetstack(rs, sl, ofs, ty) :: !code
- | S(sl, ofs, ty), R rd ->
+ | Locations.S(sl, ofs, ty), R rd ->
code := LTL.Lgetstack(sl, ofs, ty, rd) :: !code
- | S(sls, ofss, tys), S(sld, ofsd, tyd) ->
+ | Locations.S(sls, ofss, tys), Locations.S(sld, ofsd, tyd) ->
let tmp = temp_for tys in
(* code will be reversed at the end *)
code := LTL.Lsetstack(tmp, sld, ofsd, tyd) ::
diff --git a/backend/Splitting.ml b/backend/Splitting.ml
index 17b8098d..40f09c3d 100644
--- a/backend/Splitting.ml
+++ b/backend/Splitting.ml
@@ -13,10 +13,8 @@
(* Live range splitting over RTL *)
open Camlcoq
-open Datatypes
open Coqlib
open Maps
-open AST
open Kildall
open Registers
open RTL
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml
index 418fa702..16e8a80d 100644
--- a/cfrontend/C2C.ml
+++ b/cfrontend/C2C.ml
@@ -22,10 +22,10 @@ open Builtins
open Camlcoq
open AST
open Values
-open Ctypes
-open Cop
-open Csyntax
-open Initializers
+open !Ctypes
+open !Cop
+open !Csyntax
+open !Initializers
open Floats
(** ** Extracting information about global variables from their atom *)
@@ -106,7 +106,7 @@ let comp_env : composite_env ref = ref Maps.PTree.empty
(** Hooks -- overriden in machine-dependent CPragmas module *)
-let process_pragma_hook = ref (fun (s: string) -> false)
+let process_pragma_hook = ref (fun (_: string) -> false)
(** ** Error handling *)
@@ -267,7 +267,7 @@ let stringNum = ref 0 (* number of next global for string literals *)
let stringTable : (string, AST.ident) Hashtbl.t = Hashtbl.create 47
let wstringTable : (int64 list, AST.ident) Hashtbl.t = Hashtbl.create 47
-let name_for_string_literal env s =
+let name_for_string_literal s =
try
Hashtbl.find stringTable s
with Not_found ->
@@ -297,7 +297,7 @@ let global_for_string s id =
(id, Gvar {gvar_info = typeStringLiteral s; gvar_init = !init;
gvar_readonly = true; gvar_volatile = false})
-let name_for_wide_string_literal env s =
+let name_for_wide_string_literal s =
try
Hashtbl.find wstringTable s
with Not_found ->
@@ -357,13 +357,11 @@ let make_builtin_memcpy args =
let sz1 =
match Initializers.constval !comp_env sz with
| Errors.OK(Vint n) -> n
- | _ -> error "ill-formed __builtin_memcpy_aligned (3rd argument must be
-a constant)"; Integers.Int.zero in
+ | _ -> error "ill-formed __builtin_memcpy_aligned (3rd argument must be a constant)"; Integers.Int.zero in
let al1 =
match Initializers.constval !comp_env al with
| Errors.OK(Vint n) -> n
- | _ -> error "ill-formed __builtin_memcpy_aligned (4th argument must be
-a constant)"; Integers.Int.one in
+ | _ -> error "ill-formed __builtin_memcpy_aligned (4th argument must be a constant)"; Integers.Int.one in
(* to check: sz1 > 0, al1 divides sz1, al1 = 1|2|4|8 *)
(* Issue #28: must decay array types to pointer types *)
Ebuiltin(EF_memcpy(sz1, al1),
@@ -405,7 +403,7 @@ let make_builtin_va_arg_by_ref helper ty arg =
let make_builtin_va_arg env ty e =
match ty with
- | Tint _ | Tpointer _ ->
+ | Ctypes.Tint _ | Tpointer _ ->
make_builtin_va_arg_by_val
"__compcert_va_int32" ty (Tint(I32, Unsigned, noattr)) e
| Tlong _ ->
@@ -445,7 +443,7 @@ let convertCallconv va unproto attr =
(** Types *)
let convertIkind = function
- | C.IBool -> (Unsigned, IBool)
+ | C.IBool -> (Unsigned, Ctypes.IBool)
| C.IChar -> ((if (!Machine.config).Machine.char_signed
then Signed else Unsigned), I8)
| C.ISChar -> (Signed, I8)
@@ -480,7 +478,7 @@ let checkFunctionType env tres targs =
l
end
end
-
+
let rec convertTyp env t =
match t with
| C.TVoid a -> Tvoid
@@ -661,10 +659,10 @@ let rec convertExpr env e =
convertFloat f k
| C.EConst(C.CStr s) ->
let ty = typeStringLiteral s in
- Evalof(Evar(name_for_string_literal env s, ty), ty)
+ Evalof(Evar(name_for_string_literal s, ty), ty)
| C.EConst(C.CWStr s) ->
let ty = typeWideStringLiteral s in
- Evalof(Evar(name_for_wide_string_literal env s, ty), ty)
+ Evalof(Evar(name_for_wide_string_literal s, ty), ty)
| C.EConst(C.CEnum(id, i)) ->
Ctyping.econst_int (convertInt i) Signed
| C.ESizeof ty1 ->
@@ -696,22 +694,22 @@ let rec convertExpr env e =
e1, e2, tyres) ->
let op' =
match op with
- | C.Oadd -> Oadd
- | C.Osub -> Osub
- | C.Omul -> Omul
- | C.Odiv -> Odiv
- | C.Omod -> Omod
- | C.Oand -> Oand
- | C.Oor -> Oor
- | C.Oxor -> Oxor
- | C.Oshl -> Oshl
- | C.Oshr -> Oshr
- | C.Oeq -> Oeq
- | C.One -> One
- | C.Olt -> Olt
- | C.Ogt -> Ogt
- | C.Ole -> Ole
- | C.Oge -> Oge
+ | C.Oadd -> Cop.Oadd
+ | C.Osub -> Cop.Osub
+ | C.Omul -> Cop.Omul
+ | C.Odiv -> Cop.Odiv
+ | C.Omod -> Cop.Omod
+ | C.Oand -> Cop.Oand
+ | C.Oor -> Cop.Oor
+ | C.Oxor -> Cop.Oxor
+ | C.Oshl -> Cop.Oshl
+ | C.Oshr -> Cop.Oshr
+ | C.Oeq -> Cop.Oeq
+ | C.One -> Cop.One
+ | C.Olt -> Cop.Olt
+ | C.Ogt -> Cop.Ogt
+ | C.Ole -> Cop.Ole
+ | C.Oge -> Cop.Oge
| _ -> assert false in
ewrap (Ctyping.ebinop op' (convertExpr env e1) (convertExpr env e2))
| C.EBinop(C.Oassign, e1, e2, _) ->
@@ -728,16 +726,16 @@ let rec convertExpr env e =
e1, e2, tyres) ->
let op' =
match op with
- | C.Oadd_assign -> Oadd
- | C.Osub_assign -> Osub
- | C.Omul_assign -> Omul
- | C.Odiv_assign -> Odiv
- | C.Omod_assign -> Omod
- | C.Oand_assign -> Oand
- | C.Oor_assign -> Oor
- | C.Oxor_assign -> Oxor
- | C.Oshl_assign -> Oshl
- | C.Oshr_assign -> Oshr
+ | C.Oadd_assign -> Cop.Oadd
+ | C.Osub_assign -> Cop.Osub
+ | C.Omul_assign -> Cop.Omul
+ | C.Odiv_assign -> Cop.Odiv
+ | C.Omod_assign -> Cop.Omod
+ | C.Oand_assign -> Cop.Oand
+ | C.Oor_assign -> Cop.Oor
+ | C.Oxor_assign -> Cop.Oxor
+ | C.Oshl_assign -> Cop.Oshl
+ | C.Oshr_assign -> Cop.Oshr
| _ -> assert false in
let e1' = convertLvalue env e1 in
let e2' = convertExpr env e2 in
@@ -958,13 +956,13 @@ let rec contains_case s =
let swrap = function
| Errors.OK s -> s
| Errors.Error msg ->
- error ("retyping error: " ^ string_of_errmsg msg); Sskip
+ error ("retyping error: " ^ string_of_errmsg msg); Csyntax.Sskip
let rec convertStmt env s =
updateLoc s.sloc;
match s.sdesc with
| C.Sskip ->
- Sskip
+ Csyntax.Sskip
| C.Sdo e ->
swrap (Ctyping.sdo (convertExpr env e))
| C.Sseq(s1, s2) ->
@@ -1080,7 +1078,7 @@ let convertFundef loc env fd =
a_access = Sections.Access_default;
a_inline = fd.fd_inline && not fd.fd_vararg; (* PR#15 *)
a_loc = loc };
- (id', Gfun(Internal
+ (id', Gfun(Ctypes.Internal
{fn_return = ret;
fn_callconv = convertCallconv fd.fd_vararg false fd.fd_attrib;
fn_params = params;
@@ -1108,20 +1106,20 @@ let convertFundecl env (sto, id, ty, optinit) =
&& List.mem_assoc id.name builtins.functions
then EF_builtin(id'', sg)
else EF_external(id'', sg) in
- (id', Gfun(External(ef, args, res, cconv)))
+ (id', Gfun(Ctypes.External(ef, args, res, cconv)))
(** Initializers *)
let rec convertInit env init =
match init with
| C.Init_single e ->
- Init_single (convertExpr env e)
+ Initializers.Init_single (convertExpr env e)
| C.Init_array il ->
- Init_array (convertInitList env (List.rev il) Init_nil)
+ Initializers.Init_array (convertInitList env (List.rev il) Init_nil)
| C.Init_struct(_, flds) ->
- Init_struct (convertInitList env (List.rev_map snd flds) Init_nil)
+ Initializers.Init_struct (convertInitList env (List.rev_map snd flds) Init_nil)
| C.Init_union(_, fld, i) ->
- Init_union (intern_string fld.fld_name, convertInit env i)
+ Initializers.Init_union (intern_string fld.fld_name, convertInit env i)
and convertInitList env il accu =
match il with
@@ -1227,7 +1225,7 @@ let rec translEnv env = function
let env' =
match g.gdesc with
| C.Gcompositedecl(su, id, attr) ->
- Env.add_composite env id (Cutil.composite_info_decl env su attr)
+ Env.add_composite env id (Cutil.composite_info_decl su attr)
| C.Gcompositedef(su, id, attr, fld) ->
Env.add_composite env id (Cutil.composite_info_def env su attr fld)
| C.Gtypedef(id, ty) ->
diff --git a/cfrontend/PrintClight.ml b/cfrontend/PrintClight.ml
index 8a321757..e08411a5 100644
--- a/cfrontend/PrintClight.ml
+++ b/cfrontend/PrintClight.ml
@@ -17,14 +17,12 @@
open Format
open Camlcoq
-open Datatypes
-open Values
open AST
open PrintAST
-open Ctypes
+open !Ctypes
open Cop
open PrintCsyntax
-open Clight
+open !Clight
(* Naming temporaries *)
@@ -34,9 +32,7 @@ let temp_name (id: ident) = "$" ^ Z.to_string (Z.Zpos id)
(* Precedences and associativity (H&S section 7.2) *)
-type associativity = LtoR | RtoL | NA
-
-let rec precedence = function
+let precedence = function
| Evar _ -> (16, NA)
| Etempvar _ -> (16, NA)
| Ederef _ -> (15, RtoL)
@@ -258,10 +254,10 @@ let print_function p id f =
let print_fundef p id fd =
match fd with
- | External((EF_external _ | EF_runtime _), args, res, cconv) ->
+ | Ctypes.External((EF_external _ | EF_runtime _), args, res, cconv) ->
fprintf p "extern %s;@ @ "
(name_cdecl (extern_atom id) (Tfunction(args, res, cconv)))
- | External(_, _, _, _) ->
+ | Ctypes.External(_, _, _, _) ->
()
| Internal f ->
print_function p id f
diff --git a/cfrontend/PrintCsyntax.ml b/cfrontend/PrintCsyntax.ml
index d884100b..4287f7f9 100644
--- a/cfrontend/PrintCsyntax.ml
+++ b/cfrontend/PrintCsyntax.ml
@@ -15,16 +15,13 @@
(** Pretty-printer for Csyntax *)
-open Printf
open Format
open Camlcoq
-open Datatypes
open Values
open AST
-open Globalenvs
-open Ctypes
+open !Ctypes
open Cop
-open Csyntax
+open !Csyntax
let name_unop = function
| Onotbool -> "!"
@@ -177,7 +174,7 @@ let print_pointer_hook
let print_typed_value p v ty =
match v, ty with
- | Vint n, Tint(I32, Unsigned, _) ->
+ | Vint n, Ctypes.Tint(I32, Unsigned, _) ->
fprintf p "%luU" (camlint_of_coqint n)
| Vint n, _ ->
fprintf p "%ld" (camlint_of_coqint n)
@@ -429,12 +426,12 @@ let print_function p id f =
let print_fundef p id fd =
match fd with
- | External((EF_external _ | EF_runtime _), args, res, cconv) ->
+ | Ctypes.External((EF_external _ | EF_runtime _), args, res, cconv) ->
fprintf p "extern %s;@ @ "
(name_cdecl (extern_atom id) (Tfunction(args, res, cconv)))
- | External(_, _, _, _) ->
+ | Ctypes.External(_, _, _, _) ->
()
- | Internal f ->
+ | Ctypes.Internal f ->
print_function p id f
let string_of_init id =
diff --git a/common/Sections.ml b/common/Sections.ml
index ec5b6412..b792581f 100644
--- a/common/Sections.ml
+++ b/common/Sections.ml
@@ -13,8 +13,6 @@
(* *)
(* *********************************************************************)
-open Camlcoq
-
(* Handling of linker sections *)
type section_name =
diff --git a/common/Switchaux.ml b/common/Switchaux.ml
index 0d4901bf..35f58aa7 100644
--- a/common/Switchaux.ml
+++ b/common/Switchaux.ml
@@ -10,7 +10,6 @@
(* *)
(* *********************************************************************)
-open Datatypes
open Camlcoq
open Switch
diff --git a/configure b/configure
index a377f072..9e315065 100755
--- a/configure
+++ b/configure
@@ -284,15 +284,19 @@ esac
echo "Testing OCaml... " | tr -d '\n'
ocaml_ver=`ocamlopt -version 2>/dev/null`
case "$ocaml_ver" in
- 4.*)
+ 4.00.*|4.01.*)
+ echo "version $ocaml_ver -- UNSUPPORTED"
+ echo "Error: CompCert requires OCaml version 4.02 or later."
+ missingtools=true;;
+ 4.0*)
echo "version $ocaml_ver -- good!";;
?.*)
echo "version $ocaml_ver -- UNSUPPORTED"
- echo "Error: CompCert requires OCaml version 4.00 or later."
+ echo "Error: CompCert requires OCaml version 4.02 or later."
missingtools=true;;
*)
echo "NOT FOUND"
- echo "Error: make sure OCaml version 4.00 or later is installed."
+ echo "Error: make sure OCaml version 4.02 or later is installed."
missingtools=true;;
esac
diff --git a/cparser/Bitfields.ml b/cparser/Bitfields.ml
index bbc39456..d55a6d36 100644
--- a/cparser/Bitfields.ml
+++ b/cparser/Bitfields.ml
@@ -19,7 +19,7 @@
open Printf
open Machine
-open C
+open !C
open Cutil
open Transform
@@ -60,12 +60,6 @@ let unsigned_ikind_for_carrier nbits =
if nbits <= 8 * !config.sizeof_longlong then IULongLong else
assert false
-let fits_unsigned v n =
- v >= 0L && v < Int64.shift_left 1L n
-
-let fits_signed v n =
- let p = Int64.shift_left 1L (n-1) in v >= Int64.neg p && v < p
-
let is_signed_enum_bitfield env sid fld eid n =
let info = Env.find_enum env eid in
if List.for_all (fun (_, v, _) -> int_representable v n false) info.Env.ei_members
@@ -73,7 +67,7 @@ let is_signed_enum_bitfield env sid fld eid n =
else if List.for_all (fun (_, v, _) -> int_representable v n true) info.Env.ei_members
then true
else begin
- Cerrors.warning "Warning: not all values of type 'enum %s' can be represented in bit-field '%s' of struct '%s' (%d bits are not enough)" eid.name fld sid.name n;
+ Cerrors.warning "Warning: not all values of type 'enum %s' can be represented in bit-field '%s' of struct '%s' (%d bits are not enough)" eid.name fld sid.C.name n;
false
end
diff --git a/cparser/Ceval.ml b/cparser/Ceval.ml
index 74b535d4..c3d7eeeb 100644
--- a/cparser/Ceval.ml
+++ b/cparser/Ceval.ml
@@ -91,7 +91,7 @@ let is_signed env ty =
| TEnum(_, _) -> is_signed_ikind enum_ikind
| _ -> false
-let cast env ty_to ty_from v =
+let cast env ty_to v =
match unroll env ty_to, v with
| TInt(IBool, _), _ ->
if boolean_value v then I 1L else I 0L
@@ -118,12 +118,12 @@ let unop env op tyres ty v =
| Olognot, _, _ -> if boolean_value v then I 0L else I 1L
| Onot, _, I n -> I (Int64.lognot n)
| _ -> raise Notconst
- in cast env ty tyres res
+ in cast env ty res
-let comparison env direction ptraction tyop ty1 v1 ty2 v2 =
+let comparison env direction ptraction tyop v1 v2 =
(* tyop = type at which the comparison is done *)
let b =
- match cast env tyop ty1 v1, cast env tyop ty2 v2 with
+ match cast env tyop v1, cast env tyop v2 with
| I n1, I n2 ->
if is_signed env tyop
then direction (compare n1 n2) 0
@@ -143,25 +143,25 @@ let binop env op tyop tyres ty1 v1 ty2 v2 =
match op with
| Oadd ->
if is_arith_type env ty1 && is_arith_type env ty2 then begin
- match cast env tyop ty1 v1, cast env tyop ty2 v2 with
+ match cast env tyop v1, cast env tyop v2 with
| I n1, I n2 -> I (Int64.add n1 n2)
| _, _ -> raise Notconst
end else
raise Notconst
| Osub ->
if is_arith_type env ty1 && is_arith_type env ty2 then begin
- match cast env tyop ty1 v1, cast env tyop ty2 v2 with
+ match cast env tyop v1, cast env tyop v2 with
| I n1, I n2 -> I (Int64.sub n1 n2)
| _, _ -> raise Notconst
end else
raise Notconst
| Omul ->
- begin match cast env tyop ty1 v1, cast env tyop ty2 v2 with
+ begin match cast env tyop v1, cast env tyop v2 with
| I n1, I n2 -> I (Int64.mul n1 n2)
| _, _ -> raise Notconst
end
| Odiv ->
- begin match cast env tyop ty1 v1, cast env tyop ty2 v2 with
+ begin match cast env tyop v1, cast env tyop v2 with
| I n1, I n2 ->
if n2 = 0L then raise Notconst else
if is_signed env tyop then I (Int64.div n1 n2)
@@ -206,17 +206,17 @@ let binop env op tyop tyres ty1 v1 ty2 v2 =
| _, _ -> raise Notconst
end
| Oeq ->
- comparison env (=) (Some false) tyop ty1 v1 ty2 v2
+ comparison env (=) (Some false) tyop v1 v2
| One ->
- comparison env (<>) (Some true) tyop ty1 v1 ty2 v2
+ comparison env (<>) (Some true) tyop v1 v2
| Olt ->
- comparison env (<) None tyop ty1 v1 ty2 v2
+ comparison env (<) None tyop v1 v2
| Ogt ->
- comparison env (>) None tyop ty1 v1 ty2 v2
+ comparison env (>) None tyop v1 v2
| Ole ->
- comparison env (<=) None tyop ty1 v1 ty2 v2
+ comparison env (<=) None tyop v1 v2
| Oge ->
- comparison env (>=) None tyop ty1 v1 ty2 v2
+ comparison env (>=) None tyop v1 v2
| Ocomma ->
v2
| Ologand ->
@@ -229,7 +229,7 @@ let binop env op tyop tyres ty1 v1 ty2 v2 =
else if boolean_value v2 then I 1L else I 0L
| _ -> raise Notconst
(* force normalization of result, e.g. of double to float *)
- in cast env tyres tyres res
+ in cast env tyres res
let rec expr env e =
match e.edesc with
@@ -253,11 +253,10 @@ let rec expr env e =
binop env op ty e.etyp e1.etyp (expr env e1) e2.etyp (expr env e2)
| EConditional(e1, e2, e3) ->
if boolean_value (expr env e1)
- then cast env e.etyp e2.etyp (expr env e2)
- else cast env e.etyp e3.etyp (expr env e3)
- (* | ECast(TInt (_, _), EConst (CFloat (_, _))) -> TODO *)
+ then cast env e.etyp (expr env e2)
+ else cast env e.etyp (expr env e3)
| ECast(ty, e1) ->
- cast env ty e1.etyp (expr env e1)
+ cast env ty (expr env e1)
| ECompound _ ->
raise Notconst
| ECall _ ->
@@ -265,14 +264,14 @@ let rec expr env e =
let integer_expr env e =
try
- match cast env (TInt(ILongLong, [])) e.etyp (expr env e) with
+ match cast env (TInt(ILongLong, [])) (expr env e) with
| I n -> Some n
| _ -> None
with Notconst -> None
let constant_expr env ty e =
try
- match unroll env ty, cast env ty e.etyp (expr env e) with
+ match unroll env ty, cast env ty (expr env e) with
| TInt(ik, _), I n -> Some(CInt(n, ik, ""))
| TPtr(_, _), I n -> Some(CInt(n, IInt, ""))
| TPtr(_, _), S s -> Some(CStr s)
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml
index c15a7adf..1bbb8e98 100644
--- a/cparser/Cutil.ml
+++ b/cparser/Cutil.ml
@@ -15,7 +15,6 @@
(* Operations on C types and abstract syntax *)
-open Printf
open Cerrors
open C
open Env
@@ -194,7 +193,7 @@ let strip_attributes_type t attr =
(* Remove the last attribute from the toplevel and return the changed type *)
let strip_last_attribute typ =
- let rec hd_opt l = match l with
+ let hd_opt l = match l with
[] -> None,[]
| a::rest -> Some a,rest in
match typ with
@@ -561,7 +560,7 @@ let incomplete_type env t =
(* Computing composite_info records *)
-let composite_info_decl env su attr =
+let composite_info_decl su attr =
{ ci_kind = su; ci_members = [];
ci_alignof = None; ci_sizeof = None;
ci_attr = attr }
@@ -892,7 +891,7 @@ let is_literal_0 e =
let is_debug_stmt s =
let is_debug_call = function
- | (ECall ({edesc = EVar id; _},_)) -> id.name = "__builtin_debug"
+ | (ECall ({edesc = EVar id; _},_)) -> id.C.name = "__builtin_debug"
| _ -> false in
match s.sdesc with
| Sdo {edesc = e;_} ->
diff --git a/cparser/Cutil.mli b/cparser/Cutil.mli
index b353cba3..3dcfe4aa 100644
--- a/cparser/Cutil.mli
+++ b/cparser/Cutil.mli
@@ -102,13 +102,11 @@ val sizeof_ikind: ikind -> int
(* Return the size of the given integer kind. *)
val sizeof_fkind: fkind -> int
(* Return the size of the given float kind. *)
-val is_signed_ikind: ikind -> bool
- (* Return true if the given integer kind is signed, false if unsigned. *)
(* Computing composite_info records *)
val composite_info_decl:
- Env.t -> struct_or_union -> attributes -> Env.composite_info
+ struct_or_union -> attributes -> Env.composite_info
val composite_info_def:
Env.t -> struct_or_union -> attributes -> field list -> Env.composite_info
val struct_layout:
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index d7a1212a..130f37cd 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -19,9 +19,9 @@
open Format
open Machine
-open Cabs
+open !Cabs
open Cabshelper
-open C
+open !C
open Cutil
open Env
@@ -203,7 +203,7 @@ let elab_int_constant loc s0 =
in
(v, ty)
-let elab_float_constant loc f =
+let elab_float_constant f =
let ty = match f.suffix_FI with
| Some ("l"|"L") -> FLongDouble
| Some ("f"|"F") -> FFloat
@@ -253,11 +253,11 @@ let elab_string_literal loc wide chars =
if wide then
CWStr chars
else begin
- let res = String.create (List.length chars) in
+ let res = Bytes.create (List.length chars) in
List.iteri
- (fun i c -> res.[i] <- Char.unsafe_chr (Int64.to_int c))
+ (fun i c -> Bytes.set res i (Char.unsafe_chr (Int64.to_int c)))
chars;
- CStr res
+ CStr (Bytes.to_string res)
end
let elab_constant loc = function
@@ -265,7 +265,7 @@ let elab_constant loc = function
let (v, ik) = elab_int_constant loc s in
CInt(v, ik, s)
| CONST_FLOAT f ->
- let (v, fk) = elab_float_constant loc f in
+ let (v, fk) = elab_float_constant f in
CFloat(v, fk)
| CONST_CHAR(wide, s) ->
CInt(elab_char_constant loc wide s, IInt, "")
@@ -319,7 +319,7 @@ let elab_gcc_attr loc env = function
warning loc "cannot parse '%s' attribute, ignored" v; []
end
-let is_power_of_two n = n > 0L && Int64.(logand n (pred n)) = 0L
+let is_power_of_two n = n > 0L && Int64.logand n (Int64.pred n) = 0L
let extract_alignas loc a =
match a with
@@ -569,7 +569,7 @@ and elab_parameters env params =
let (vars, _) = mmap elab_parameter (Env.new_scope env) params in
(* Catch special case f(t) where t is void or a typedef to void *)
match vars with
- | [ ( {name=""}, t) ] when is_void_type env t -> []
+ | [ ( {C.name=""}, t) ] when is_void_type env t -> []
| _ -> vars
(* Elaboration of a function parameter *)
@@ -578,7 +578,7 @@ and elab_parameter env (PARAM (spec, id, decl, attr, loc)) =
let (sto, inl, tydef, bty, env1) = elab_specifier loc env spec in
if tydef then
error loc "'typedef' used in function parameter";
- let ((ty, _), env2) = elab_type_declarator loc env1 bty false decl in
+ let ((ty, _), _) = elab_type_declarator loc env1 bty false decl in
let ty = add_attributes_type (elab_attributes env attr) ty in
if sto <> Storage_default && sto <> Storage_register then
error loc
@@ -753,7 +753,7 @@ and elab_struct_or_union only kind loc tag optmembers attrs env =
(* declaration of an incomplete struct or union *)
if tag = "" then
error loc "anonymous, incomplete struct or union";
- let ci = composite_info_decl env kind attrs in
+ let ci = composite_info_decl kind attrs in
(* enter it with a new name *)
let (tag', env') = Env.enter_composite env tag ci in
(* emit it *)
@@ -761,7 +761,7 @@ and elab_struct_or_union only kind loc tag optmembers attrs env =
(tag', env')
| _, Some members ->
(* definition of a complete struct or union *)
- let ci1 = composite_info_decl env kind attrs in
+ let ci1 = composite_info_decl kind attrs in
(* enter it, incomplete, with a new name *)
let (tag', env') = Env.enter_composite env tag ci1 in
(* emit a declaration so that inner structs and unions can refer to it *)
@@ -900,8 +900,6 @@ module I = struct
* ident (* union type *)
* field (* current member *)
- type state = zipinit * init (* current point & init for this point *)
-
(* The initial state: default initialization, current point at top *)
let top env name ty = (Ztop(name, ty), default_init env ty)
@@ -1727,7 +1725,7 @@ let elab_expr loc env a =
| (TInt _ | TEnum _), TPtr _ ->
warning "comparison between integer and pointer";
EBinop(op, b1, b2, TPtr(TVoid [], []))
- | ty1, ty2 ->
+ | _, _ ->
error "illegal comparison between types@ %a@ and %a"
Cprint.typ b1.etyp Cprint.typ b2.etyp in
{ edesc = resdesc; etyp = TInt(IInt, []) }
@@ -1860,7 +1858,7 @@ let enter_decdefs local loc env sto dl =
fatal_error loc "'register' on global declaration";
if sto <> Storage_default && dl = [] then
warning loc "Storage class specifier on empty declaration";
- let rec enter_decdef (decls, env) (s, ty, init) =
+ let enter_decdef (decls, env) (s, ty, init) =
let isfun = is_function_type env ty in
if sto = Storage_extern && init <> NO_INIT then
error loc "'extern' declaration cannot have an initializer";
@@ -1936,7 +1934,7 @@ let elab_fundef env spec name defs body loc =
"Illegal declaration of function parameter" in
let (kr_params_defs, env1) = mmap elab_kr_param_def env1 defs in
let kr_params_defs = List.concat kr_params_defs in
- let rec search_param_type param =
+ let search_param_type param =
match List.filter (fun (p, _) -> p = param) kr_params_defs with
| [] ->
(* Parameter is not declared, defaults to "int" in ISO C90,
@@ -1960,7 +1958,7 @@ let elab_fundef env spec name defs body loc =
(ty_ret, params, vararg, attr)
| _ -> fatal_error loc "wrong type for function definition" in
(* Enter function in the environment, for recursive references *)
- let (fun_id, sto1, env1,ty) = enter_or_refine_ident false loc env1 s sto ty in
+ let (fun_id, sto1, env1, _) = enter_or_refine_ident false loc env1 s sto ty in
(* Enter parameters in the environment *)
let env2 =
List.fold_left (fun e (id, ty) -> Env.add_ident e id Storage_default ty)
diff --git a/cparser/Env.ml b/cparser/Env.ml
index 65df6cb9..dae79ef2 100644
--- a/cparser/Env.ml
+++ b/cparser/Env.ml
@@ -118,12 +118,6 @@ let lookup_ident env s =
with Not_found ->
raise(Error(Unbound_identifier s))
-let lookup_tag env s =
- try
- IdentMap.lookup s env.env_tag
- with Not_found ->
- raise(Error(Unbound_tag(s, "tag")))
-
let lookup_struct env s =
try
let (id, ci as res) = IdentMap.lookup s env.env_tag in
@@ -169,11 +163,6 @@ let find_ident env id =
with Not_found ->
raise(Error(Unbound_identifier(id.name)))
-let find_tag env id =
- try IdentMap.find id env.env_tag
- with Not_found ->
- raise(Error(Unbound_tag(id.name, "tag")))
-
let find_struct env id =
try
let ci = IdentMap.find id env.env_tag in
diff --git a/cparser/ExtendedAsm.ml b/cparser/ExtendedAsm.ml
index 94fcda31..c3d80272 100644
--- a/cparser/ExtendedAsm.ml
+++ b/cparser/ExtendedAsm.ml
@@ -33,7 +33,6 @@ open Printf
open Machine
open C
open Cutil
-open Env
open Cerrors
(* Renaming of labeled and numbered operands *)
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll
index bcf2ada0..871f2bf9 100644
--- a/cparser/Lexer.mll
+++ b/cparser/Lexer.mll
@@ -17,8 +17,7 @@
open Lexing
open Pre_parser
open Pre_parser_aux
-open Cabshelper
-open Camlcoq
+open !Cabshelper
module SSet = Set.Make(String)
@@ -430,7 +429,7 @@ and singleline_comment = parse
open Streams
open Specif
open Parser
- open Aut.GramDefs
+ open !Aut.GramDefs
(* This is the main entry point to the lexer. *)
diff --git a/cparser/PackedStructs.ml b/cparser/PackedStructs.ml
index 6ea5d121..aafa1caa 100644
--- a/cparser/PackedStructs.ml
+++ b/cparser/PackedStructs.ml
@@ -127,7 +127,7 @@ let transf_composite loc env su id attrs ml =
(* Accessor functions *)
-let lookup_function loc env name =
+let lookup_function env name =
match Env.lookup_ident env name with
| (id, II_ident(sto, ty)) -> (id, ty)
| (id, II_enum _) -> raise (Env.Error(Env.Unbound_identifier name))
@@ -161,14 +161,14 @@ let bswap_read loc env lval =
try
if !use_reversed then begin
let (id, fty) =
- lookup_function loc env (sprintf "__builtin_read%d_reversed" bsize) in
+ lookup_function env (sprintf "__builtin_read%d_reversed" bsize) in
let fn = {edesc = EVar id; etyp = fty} in
let args = [ecast_opt env (TPtr(aty,[])) (eaddrof lval)] in
let call = {edesc = ECall(fn, args); etyp = aty} in
ecast_opt env ty call
end else begin
let (id, fty) =
- lookup_function loc env (sprintf "__builtin_bswap%d" bsize) in
+ lookup_function env (sprintf "__builtin_bswap%d" bsize) in
let fn = {edesc = EVar id; etyp = fty} in
let args = [ecast_opt env aty lval] in
let call = {edesc = ECall(fn, args); etyp = aty} in
@@ -188,14 +188,14 @@ let bswap_write loc env lhs rhs =
try
if !use_reversed then begin
let (id, fty) =
- lookup_function loc env (sprintf "__builtin_write%d_reversed" bsize) in
+ lookup_function env (sprintf "__builtin_write%d_reversed" bsize) in
let fn = {edesc = EVar id; etyp = fty} in
let args = [ecast_opt env (TPtr(aty,[])) (eaddrof lhs);
ecast_opt env aty rhs] in
{edesc = ECall(fn, args); etyp = TVoid[]}
end else begin
let (id, fty) =
- lookup_function loc env (sprintf "__builtin_bswap%d" bsize) in
+ lookup_function env (sprintf "__builtin_bswap%d" bsize) in
let fn = {edesc = EVar id; etyp = fty} in
let args = [ecast_opt env aty rhs] in
let call = {edesc = ECall(fn, args); etyp = aty} in
@@ -403,7 +403,7 @@ let rec transf_globdecls env accu = function
| Union -> attr
| Struct -> remove_custom_attributes ["packed";"__packed__"] attr in
transf_globdecls
- (Env.add_composite env id (composite_info_decl env su attr'))
+ (Env.add_composite env id (composite_info_decl su attr'))
({g with gdesc = Gcompositedecl(su, id, attr')} :: accu)
gl
| Gcompositedef(su, id, attr, fl) ->
diff --git a/cparser/StructReturn.ml b/cparser/StructReturn.ml
index 4e019380..04f0021a 100644
--- a/cparser/StructReturn.ml
+++ b/cparser/StructReturn.ml
@@ -19,7 +19,7 @@
open Machine
open Configuration
-open C
+open !C
open Cutil
open Transform
diff --git a/cparser/Transform.ml b/cparser/Transform.ml
index 840234b8..0a2ce3bb 100644
--- a/cparser/Transform.ml
+++ b/cparser/Transform.ml
@@ -45,7 +45,7 @@ let new_temp ?(name = "t") ty =
let attributes_to_remove_from_temp = add_attributes [AConst] [AVolatile]
-let mk_temp env ?(name = "t") ty =
+let mk_temp env ty =
new_temp (remove_attributes_type env attributes_to_remove_from_temp ty)
(* Bind a l-value to a temporary variable if it is not invariant. *)
@@ -211,7 +211,7 @@ let program
Env.add_ident env f.fd_name f.fd_storage (fundef_typ f))
| Gcompositedecl(su, id, attr) ->
(Gcompositedecl(su, id, attr),
- Env.add_composite env id (composite_info_decl env su attr))
+ Env.add_composite env id (composite_info_decl su attr))
| Gcompositedef(su, id, attr, fl) ->
let (attr', fl') = composite env su id attr fl in
(Gcompositedef(su, id, attr', fl'),
diff --git a/cparser/Transform.mli b/cparser/Transform.mli
index a04896a9..dbd8e575 100644
--- a/cparser/Transform.mli
+++ b/cparser/Transform.mli
@@ -18,7 +18,7 @@ val reset_temps : unit -> unit
val get_temps : unit -> C.decl list
val new_temp_var : ?name:string -> C.typ -> C.ident
val new_temp : ?name:string -> C.typ -> C.exp
-val mk_temp : Env.t -> ?name:string -> C.typ -> C.exp
+val mk_temp : Env.t -> C.typ -> C.exp
(** Avoiding repeated evaluation of a l-value *)
diff --git a/cparser/Unblock.ml b/cparser/Unblock.ml
index ef8bc91c..0669be6e 100644
--- a/cparser/Unblock.ml
+++ b/cparser/Unblock.ml
@@ -64,17 +64,6 @@ let add_inits_stmt loc inits s =
(fun e s -> sseq loc {sdesc = Sdo e; sloc = loc} s)
inits s
-(* Prepend assignments to the given expression. *)
-(* Associate to the left so that it prints more nicely *)
-
-let add_inits_expr inits e =
- match inits with
- | [] -> e
- | i1 :: il ->
- let comma a b =
- { edesc = EBinop(Ocomma, a, b, b.etyp); etyp = b.etyp } in
- comma (List.fold_left comma i1 il) e
-
(* Record new variables to be locally or globally defined *)
let local_variables = ref ([]: decl list)
@@ -357,7 +346,7 @@ let unblock_fundef env f =
(* Simplification of compound literals within a top-level declaration *)
-let unblock_decl loc env ((sto, id, ty, optinit) as d) =
+let unblock_decl env ((sto, id, ty, optinit) as d) =
match optinit with
| None -> [d]
| Some init ->
@@ -375,8 +364,8 @@ let rec unblock_glob env accu = function
| [] -> List.rev accu
| g :: gl ->
match g.gdesc with
- | Gdecl((sto, id, ty, init) as d) ->
- let dl = unblock_decl g.gloc env d in
+ | Gdecl d ->
+ let dl = unblock_decl env d in
unblock_glob env
(List.rev_append
(List.map (fun d' -> {g with gdesc = Gdecl d'}) dl)
@@ -387,7 +376,7 @@ let rec unblock_glob env accu = function
unblock_glob env ({g with gdesc = Gfundef f'} :: accu) gl
| Gcompositedecl(su, id, attr) ->
unblock_glob
- (Env.add_composite env id (composite_info_decl env su attr))
+ (Env.add_composite env id (composite_info_decl su attr))
(g :: accu) gl
| Gcompositedef(su, id, attr, fl) ->
unblock_glob
diff --git a/debug/Debug.ml b/debug/Debug.ml
index 775a0903..7403d7c2 100644
--- a/debug/Debug.ml
+++ b/debug/Debug.ml
@@ -12,9 +12,8 @@
open AST
open BinNums
-open C
+open !C
open Camlcoq
-open Dwarfgen
open DwarfTypes
open Sections
@@ -32,7 +31,7 @@ type implem =
add_fun_addr: atom -> section_name -> (int * int) -> unit;
generate_debug_info: (atom -> string) -> string -> debug_entries option;
all_files_iter: (string -> unit) -> unit;
- insert_local_declaration: storage -> ident -> typ -> location -> unit;
+ insert_local_declaration: storage -> ident -> C.typ -> location -> unit;
atom_local_variable: ident -> atom -> unit;
enter_scope: int -> int -> int -> unit;
enter_function_scope: int -> int -> unit;
diff --git a/debug/Debug.mli b/debug/Debug.mli
index 387491c2..f044b1ad 100644
--- a/debug/Debug.mli
+++ b/debug/Debug.mli
@@ -11,7 +11,7 @@
(* *********************************************************************)
open AST
-open C
+open !C
open Camlcoq
open DwarfTypes
open BinNums
diff --git a/debug/DebugInformation.ml b/debug/DebugInformation.ml
index 105b6aad..471318af 100644
--- a/debug/DebugInformation.ml
+++ b/debug/DebugInformation.ml
@@ -10,7 +10,6 @@
(* *)
(* *********************************************************************)
-open AST
open BinNums
open C
open Camlcoq
@@ -28,8 +27,6 @@ let next_id () =
let nid = !id in
incr id; nid
-let reset_id () =
- id := 0
(* Auximilary functions *)
let list_replace c f l =
@@ -47,11 +44,15 @@ let add_file file =
(* All types encountered *)
let types: (int,debug_types) Hashtbl.t = Hashtbl.create 7
+let get_type = Hashtbl.find types
+
+let fold_types f a = Hashtbl.fold f types a
+
(* Lookup table for types *)
let lookup_types: (string, int) Hashtbl.t = Hashtbl.create 7
(* Translate a C.typ to a string needed for hashing *)
-let typ_to_string (ty: typ) =
+let typ_to_string ty =
let buf = Buffer.create 7 in
let chan = Format.formatter_of_buffer buf in
Cprint.print_debug_idents := true;
@@ -64,13 +65,13 @@ let typ_to_string (ty: typ) =
let strip_attributes typ = strip_attributes_type typ [AConst; AVolatile]
(* Find the type id to an type *)
-let find_type (ty: typ) =
+let find_type ty =
(* We are only interested in Const and Volatile *)
let ty = strip_attributes ty in
Hashtbl.find lookup_types (typ_to_string ty)
(* Add type and information *)
-let insert_type (ty: typ) =
+let insert_type ty =
let insert d_ty ty =
let id = next_id ()
and name = typ_to_string ty in
@@ -104,7 +105,7 @@ let insert_type (ty: typ) =
arr_size= s;
} in
ArrayType arr
- | TFun (t,param,va,_) ->
+ | TFun (t,param,_,_) ->
let param,prot = (match param with
| None -> [],false
| Some p -> List.map (fun (i,t) -> let t = attr_aux t in
@@ -213,6 +214,8 @@ let replace_typedef id f =
(* All global definitions encountered *)
let definitions: (int,definition_type) Hashtbl.t = Hashtbl.create 7
+let fold_definitions f a = Hashtbl.fold f definitions a
+
(* Mapping from stamp to debug id *)
let stamp_to_definition: (int,int) Hashtbl.t = Hashtbl.create 7
@@ -255,6 +258,8 @@ let replace_fun id f =
(* All local variables *)
let local_variables: (int, local_information) Hashtbl.t = Hashtbl.create 7
+let get_local_variable id = Hashtbl.find local_variables id
+
(* Mapping from stamp to the debug id of the local variable *)
let stamp_to_local: (int,int) Hashtbl.t = Hashtbl.create 7
@@ -516,29 +521,18 @@ let enter_scope f_id p_id id =
with Not_found -> ()
-type scope_range =
- {
- start_addr: positive option;
- end_addr: positive option;
- }
-
-type var_range =
- {
- range_start: positive option;
- range_end: positive option;
- var_loc: int * int builtin_arg;
- }
-
-type var_location =
- | RangeLoc of var_range list
- | FunctionLoc of int * int builtin_arg (* Stack allocated variables *)
-
let var_locations: (atom * atom,var_location) Hashtbl.t = Hashtbl.create 7
+let variable_location var f = Hashtbl.find var_locations (var,f)
+
let scope_ranges: (int,scope_range list) Hashtbl.t = Hashtbl.create 7
+let get_scope_ranges = Hashtbl.find scope_ranges
+
let label_translation: (atom * positive, int) Hashtbl.t = Hashtbl.create 7
+let translate_label f l = Hashtbl.find label_translation (f,l)
+
let add_label atom p i =
Hashtbl.add label_translation (atom,p) i
@@ -589,20 +583,22 @@ let stack_variable (f,v) (sp,loc) =
let compilation_section_start: (string,int) Hashtbl.t = Hashtbl.create 7
let compilation_section_end: (string,int) Hashtbl.t = Hashtbl.create 7
+let section_start n = Hashtbl.find compilation_section_start n
+
+let fold_section_start f a = Hashtbl.fold f compilation_section_start a
+
+let section_end n = Hashtbl.find compilation_section_end n
+
let diab_additional: (string,int * int * section_name) Hashtbl.t = Hashtbl.create 7
+let diab_additional_section s =
+ let line_start,debug_start,_ = Hashtbl.find diab_additional s in
+ line_start,debug_start
+
let section_to_string = function
| Section_user (n,_,_) -> n
| _ -> ".text"
-let add_compilation_section_start sec addr =
- let sec = section_to_string sec in
- Hashtbl.add compilation_section_start sec addr
-
-let add_compilation_section_end sec addr =
- let sec = section_to_string sec in
- Hashtbl.add compilation_section_end sec addr
-
let add_diab_info sec addr1 add2 addr3 =
let sec' = section_to_string sec in
Hashtbl.add compilation_section_start sec' addr3;
@@ -622,6 +618,8 @@ let exists_section sec =
let filenum: (string * string,int) Hashtbl.t = Hashtbl.create 7
+let diab_file_loc f l = Hashtbl.find filenum (f,l)
+
let compute_diab_file_enum end_label entry_label line_end =
Hashtbl.iter (fun sec (_,_,secname) ->
Hashtbl.add compilation_section_end sec (end_label secname);
@@ -633,8 +631,12 @@ let compute_diab_file_enum end_label entry_label line_end =
let compute_gnu_file_enum f =
StringSet.iter f !all_files
+let all_files_iter f = StringSet.iter f !all_files
+
let printed_vars: StringSet.t ref = ref StringSet.empty
+let is_variable_printed id = StringSet.mem id !printed_vars
+
let variable_printed id =
printed_vars := StringSet.add id !printed_vars
diff --git a/debug/DebugInformation.mli b/debug/DebugInformation.mli
new file mode 100644
index 00000000..66c4cd11
--- /dev/null
+++ b/debug/DebugInformation.mli
@@ -0,0 +1,106 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
+(* *)
+(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
+(* is distributed under the terms of the INRIA Non-Commercial *)
+(* License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+open AST
+open BinNums
+open !C
+open Camlcoq
+open DebugTypes
+open Sections
+
+val typ_to_string: C.typ -> string
+
+val next_id: unit -> int
+
+val get_type: int -> debug_types
+
+val fold_types: (int -> debug_types -> 'a -> 'a) -> 'a -> 'a
+
+val is_variable_printed: string -> bool
+
+val variable_location: atom -> atom -> var_location
+
+val translate_label: atom -> positive -> int
+
+val get_scope_ranges: int -> scope_range list
+
+val get_local_variable: int -> local_information
+
+val diab_file_loc: string -> string -> int
+
+val section_start: string -> int
+
+val fold_section_start: (string -> int -> 'a -> 'a) -> 'a -> 'a
+
+val section_end: string -> int
+
+val diab_additional_section: string -> int * int
+
+val file_name: string ref
+
+val fold_definitions: (int -> definition_type -> 'a -> 'a) -> 'a -> 'a
+
+val atom_global: ident -> atom -> unit
+
+val set_composite_size: ident -> struct_or_union -> int option -> unit
+
+val set_member_offset: ident -> string -> int -> unit
+
+val set_bitfield_offset: ident -> string -> int -> string -> int -> unit
+
+val insert_global_declaration: Env.t -> globdecl -> unit
+
+val diab_add_fun_addr: atom -> section_name -> (int * int) -> unit
+
+val gnu_add_fun_addr: atom -> section_name -> (int * int) -> unit
+
+val all_files_iter: (string -> unit) -> unit
+
+val insert_local_declaration: storage -> ident -> typ -> location -> unit
+
+val atom_local_variable: ident -> atom -> unit
+
+val enter_scope: int -> int -> int -> unit
+
+val enter_function_scope: int -> int -> unit
+
+val add_lvar_scope: int -> ident -> int -> unit
+
+val open_scope: atom -> int -> positive -> unit
+
+val close_scope: atom -> int -> positive -> unit
+
+val start_live_range: (atom * atom) -> positive -> (int * int builtin_arg) -> unit
+
+val end_live_range: (atom * atom) -> positive -> unit
+
+val stack_variable: (atom * atom) -> int * int builtin_arg -> unit
+
+val add_label: atom -> positive -> int -> unit
+
+val atom_parameter: ident -> ident -> atom -> unit
+
+val compute_diab_file_enum: (section_name -> int) -> (string-> int) -> (unit -> unit) -> unit
+
+val compute_gnu_file_enum: (string -> unit) -> unit
+
+val exists_section: section_name -> bool
+
+val remove_unused: ident -> unit
+
+val remove_unused_function: ident -> unit
+
+val variable_printed: string -> unit
+
+val add_diab_info: section_name -> int -> int -> int -> unit
+
+val init: string -> unit
diff --git a/debug/DebugInit.ml b/debug/DebugInit.ml
index 17a90536..462ca2d3 100644
--- a/debug/DebugInit.ml
+++ b/debug/DebugInit.ml
@@ -10,12 +10,6 @@
(* *)
(* *********************************************************************)
-open AST
-open BinNums
-open C
-open Camlcoq
-open Dwarfgen
-open DwarfTypes
open Debug
let default_debug =
@@ -28,7 +22,7 @@ let default_debug =
insert_global_declaration = DebugInformation.insert_global_declaration;
add_fun_addr = (fun _ _ _ -> ());
generate_debug_info = (fun _ _ -> None);
- all_files_iter = (fun f -> DebugInformation.StringSet.iter f !DebugInformation.all_files);
+ all_files_iter = DebugInformation.all_files_iter;
insert_local_declaration = DebugInformation.insert_local_declaration;
atom_local_variable = DebugInformation.atom_local_variable;
enter_scope = DebugInformation.enter_scope;
diff --git a/debug/DebugTypes.mli b/debug/DebugTypes.mli
index 53a39665..25c7390f 100644
--- a/debug/DebugTypes.mli
+++ b/debug/DebugTypes.mli
@@ -10,6 +10,8 @@
(* *)
(* *********************************************************************)
+open AST
+open BinNums
open C
open Camlcoq
@@ -158,3 +160,21 @@ type scope_information =
type local_information =
| LocalVariable of local_variable_information
| Scope of scope_information
+
+
+type scope_range =
+ {
+ start_addr: positive option;
+ end_addr: positive option;
+ }
+
+type var_range =
+ {
+ range_start: positive option;
+ range_end: positive option;
+ var_loc: int * int builtin_arg;
+ }
+
+type var_location =
+ | RangeLoc of var_range list
+ | FunctionLoc of int * int builtin_arg (* Stack allocated variables *)
diff --git a/debug/DwarfPrinter.ml b/debug/DwarfPrinter.ml
index ef44a2d5..9313b6c5 100644
--- a/debug/DwarfPrinter.ml
+++ b/debug/DwarfPrinter.ml
@@ -33,9 +33,6 @@ module DwarfPrinter(Target: DWARF_TARGET):
let string_of_comment s = sprintf " %s %s" comment s
- let add_comment buf s =
- Buffer.add_string buf (sprintf " %s %s" comment s)
-
(* Byte value to string *)
let string_of_byte value ct =
sprintf " .byte %s%s\n" (if value then "0x1" else "0x0") (string_of_comment ct)
@@ -67,8 +64,6 @@ module DwarfPrinter(Target: DWARF_TARGET):
let add_member_size = add_abbr_entry (0x0b,"DW_AT_byte_size",DW_FORM_udata)
- let add_high_pc = add_abbr_entry (0x12,"DW_AT_high_pc",DW_FORM_addr)
-
let add_low_pc = add_abbr_entry (0x11,"DW_AT_low_pc",DW_FORM_addr)
let add_declaration = add_abbr_entry (0x3c,"DW_AT_declaration",DW_FORM_flag)
@@ -115,7 +110,7 @@ module DwarfPrinter(Target: DWARF_TARGET):
if has_sibling then add_abbr_entry (0x1,"DW_AT_sibling",DW_FORM_ref4) buf;
in
(match entity.tag with
- | DW_TAG_array_type e ->
+ | DW_TAG_array_type _ ->
prologue 0x1 "DW_TAG_array_type";
add_type buf
| DW_TAG_base_type b ->
@@ -623,9 +618,9 @@ module DwarfPrinter(Target: DWARF_TARGET):
let name = if e.section_name <> ".text" then Some e.section_name else None in
section oc (Section_debug_info name);
print_debug_info oc e.start_label e.line_label e.entry) entries;
- if List.exists (fun e -> match e.locs with _,[] -> false | _,_ -> true) entries then begin
+ if List.exists (fun e -> match e.dlocs with _,[] -> false | _,_ -> true) entries then begin
section oc Section_debug_loc;
- List.iter (fun e -> print_location_list oc e.locs) entries
+ List.iter (fun e -> print_location_list oc e.dlocs) entries
end
let print_ranges oc r =
diff --git a/debug/DwarfTypes.mli b/debug/DwarfTypes.mli
index 2af64c0b..f6074cf3 100644
--- a/debug/DwarfTypes.mli
+++ b/debug/DwarfTypes.mli
@@ -12,7 +12,6 @@
(* Types used for writing dwarf debug information *)
-open BinNums
open Camlcoq
open Sections
@@ -285,7 +284,7 @@ type diab_entry =
start_label: int;
line_label: int;
entry: dw_entry;
- locs: dw_locations;
+ dlocs: dw_locations;
}
type diab_entries = diab_entry list
diff --git a/debug/Dwarfgen.ml b/debug/Dwarfgen.ml
index d070e3a9..f1a8ce3e 100644
--- a/debug/Dwarfgen.ml
+++ b/debug/Dwarfgen.ml
@@ -21,6 +21,8 @@ open DwarfUtil
(* Generate the dwarf DIE's from the information collected in DebugInformation *)
+module StringSet = Set.Make(String)
+
(* Helper function to get values that must be set. *)
let get_opt_val = function
| Some a -> a
@@ -270,7 +272,7 @@ module Dwarfgenaux (Target: TARGET) =
IntSet.add id d,true
else
d,false in
- let t = Hashtbl.find types id in
+ let t = get_type id in
match t with
| IntegerType _
| FloatType _
@@ -308,15 +310,15 @@ module Dwarfgenaux (Target: TARGET) =
else
d in
let typs = aux needed in
- List.rev (Hashtbl.fold (fun id t acc ->
+ List.rev (fold_types (fun id t acc ->
if IntSet.mem id typs then
(infotype_to_entry id t)::acc
else
- acc) types [])
+ acc) [])
let global_variable_to_entry acc id v =
let loc = match v.gvar_atom with
- | Some a when StringSet.mem (extern_atom a) !printed_vars ->
+ | Some a when is_variable_printed (extern_atom a) ->
Some (LocSymbol a)
| _ -> None in
let var = {
@@ -369,15 +371,15 @@ module Dwarfgenaux (Target: TARGET) =
if !Clflags.option_gdepth > 2 then
try
begin
- match (Hashtbl.find var_locations (f_id,atom)) with
+ match variable_location f_id atom with
| FunctionLoc (a,r) ->
translate_function_loc a r
| RangeLoc l ->
let l = List.rev_map (fun i ->
let hi = get_opt_val i.range_start
and lo = get_opt_val i.range_end in
- let hi = Hashtbl.find label_translation (f_id,hi)
- and lo = Hashtbl.find label_translation (f_id,lo) in
+ let hi = translate_label f_id hi
+ and lo = translate_label f_id lo in
hi,lo,range_entry_loc i.var_loc) l in
let id = next_id () in
Some (LocRef id),[{loc = l;loc_id = id;}]
@@ -402,11 +404,11 @@ module Dwarfgenaux (Target: TARGET) =
let scope_range f_id id (o,dwr) =
try
- let r = Hashtbl.find scope_ranges id in
+ let r = get_scope_ranges id in
let lbl l h = match l,h with
| Some l,Some h->
- let l = (Hashtbl.find label_translation (f_id,l))
- and h = (Hashtbl.find label_translation (f_id,h)) in
+ let l = translate_label f_id l
+ and h = translate_label f_id h in
l,h
| _ -> raise Not_found in
begin
@@ -451,7 +453,7 @@ module Dwarfgenaux (Target: TARGET) =
add_children entry vars,(acc >>= dwr)
and local_to_entry f_id acc id =
- match Hashtbl.find local_variables id with
+ match get_local_variable id with
| LocalVariable v -> local_variable_to_entry f_id acc v id
| Scope v -> let s,acc = (scope_to_entry f_id acc v id) in
Some s,acc
@@ -460,7 +462,7 @@ module Dwarfgenaux (Target: TARGET) =
match id with
| None -> [],acc
| Some id ->
- let sc = Hashtbl.find local_variables id in
+ let sc = get_local_variable id in
(match sc with
| Scope sc -> mmap_opt (local_to_entry f_id) acc sc.scope_variables
| _ -> assert false)
@@ -499,7 +501,7 @@ module Dwarfgenaux (Target: TARGET) =
module StringMap = Map.Make(String)
let diab_file_loc sec (f,l) =
- Diab_file_loc (Hashtbl.find filenum (sec,f),l)
+ Diab_file_loc ((diab_file_loc sec f),l)
let prod_name =
let version_string =
@@ -518,9 +520,9 @@ let diab_gen_compilation_section s defs acc =
let defs,accu = List.fold_left (fun (acc,bcc) (id,t) ->
let t,bcc = Gen.definition_to_entry bcc id t in
t::acc,bcc) ([],empty_accu) defs in
- let low_pc = Hashtbl.find compilation_section_start s
- and line_start,debug_start,_ = Hashtbl.find diab_additional s
- and high_pc = Hashtbl.find compilation_section_end s in
+ let low_pc = section_start s
+ and line_start,debug_start = diab_additional_section s
+ and high_pc = section_end s in
let cp = {
compile_unit_name = Simple_string !file_name;
compile_unit_range = Pc_pair (low_pc,high_pc);
@@ -534,16 +536,16 @@ let diab_gen_compilation_section s defs acc =
start_label = debug_start;
line_label = line_start;
entry = cp;
- locs = Some low_pc,accu.locs;
+ dlocs = Some low_pc,accu.locs;
}::acc
let gen_diab_debug_info sec_name var_section : debug_entries =
- let defs = Hashtbl.fold (fun id t acc ->
+ let defs = fold_definitions (fun id t acc ->
let s = match t with
| GlobalVariable _ -> var_section
| Function f -> sec_name (get_opt_val f.fun_atom) in
let old = try StringMap.find s acc with Not_found -> [] in
- StringMap.add s ((id,t)::old) acc) definitions StringMap.empty in
+ StringMap.add s ((id,t)::old) acc) StringMap.empty in
let entries = StringMap.fold diab_gen_compilation_section defs [] in
Diab entries
@@ -567,15 +569,15 @@ let gnu_string_entry s =
let gen_gnu_debug_info sec_name var_section : debug_entries =
let r,dwr,low_pc =
try if !Clflags.option_gdwarf > 3 then
- let pcs = Hashtbl.fold (fun s low acc ->
- (low,Hashtbl.find compilation_section_end s)::acc) compilation_section_start [] in
+ let pcs = fold_section_start (fun s low acc ->
+ (low,section_end s)::acc) [] in
match pcs with
| [] -> Empty,(0,[]),None
| [(l,h)] -> Pc_pair (l,h),(0,[]),Some l
| _ -> Offset 0,(2 + 4 * (List.length pcs),[pcs]),None
else
- let l = Hashtbl.find compilation_section_start ".text"
- and h = Hashtbl.find compilation_section_end ".text" in
+ let l = section_start ".text"
+ and h = section_end ".text" in
Pc_pair(l,h),(0,[]),Some l
with Not_found -> Empty,(0,[]),None in
let accu = empty_accu >>= dwr in
@@ -583,12 +585,12 @@ let gen_gnu_debug_info sec_name var_section : debug_entries =
let file_loc = gnu_file_loc
let string_entry = gnu_string_entry
end) in
- let defs,accu,sec = Hashtbl.fold (fun id t (acc,bcc,sec) ->
+ let defs,accu,sec = fold_definitions (fun id t (acc,bcc,sec) ->
let s = match t with
| GlobalVariable _ -> var_section
| Function f -> sec_name (get_opt_val f.fun_atom) in
let t,bcc = Gen.definition_to_entry bcc id t in
- t::acc,bcc,StringSet.add s sec) definitions ([],accu,StringSet.empty) in
+ t::acc,bcc,StringSet.add s sec) ([],accu,StringSet.empty) in
let types = Gen.gen_types accu.typs in
let cp = {
compile_unit_name = gnu_string_entry !file_name;
diff --git a/driver/Configuration.mli b/driver/Configuration.mli
index 1d048ac4..abfd3ab4 100644
--- a/driver/Configuration.mli
+++ b/driver/Configuration.mli
@@ -12,27 +12,37 @@
val arch: string
(** Target architecture *)
+
val model: string
(** Sub-model for this architecture *)
+
val abi: string
(** ABI to use *)
+
val system: string
(** Flavor of operating system that runs CompCert *)
val prepro: string list
(** How to invoke the external preprocessor *)
+
val asm: string list
(** How to invoke the external assembler *)
+
val linker: string list
(** How to invoke the external linker *)
+
val asm_supports_cfi: bool
(** True if the assembler supports Call Frame Information *)
+
val stdlib_path: string
(** Path to CompCert's library *)
+
val has_runtime_lib: bool
(** True if CompCert's library is available. *)
+
val has_standard_headers: bool
(** True if CompCert's standard header files is available. *)
+
val advanced_debug: bool
(** True if advanced debug is implement for the Target *)
@@ -52,6 +62,7 @@ type struct_return_style =
val struct_passing_style: struct_passing_style
(** Calling conventions to use for passing structs and unions as
first-class values *)
+
val struct_return_style: struct_return_style
(** Calling conventions to use for returning structs and unions as
first-class values *)
diff --git a/driver/Driver.ml b/driver/Driver.ml
index bbd949e0..16267128 100644
--- a/driver/Driver.ml
+++ b/driver/Driver.ml
@@ -159,7 +159,7 @@ let parse_c_file sourcename ifile =
PrintCsyntax.print_program (Format.formatter_of_out_channel oc) csyntax;
close_out oc
end;
- csyntax,None
+ csyntax
(* Dump Asm code in asm format for the validator *)
@@ -174,7 +174,7 @@ let dump_jasm asm sourcename destfile =
(* From CompCert C AST to asm *)
-let compile_c_ast sourcename csyntax ofile debug =
+let compile_c_ast sourcename csyntax ofile =
(* Prepare to dump Clight, RTL, etc, if requested *)
let set_dest dst opt ext =
dst := if !opt then Some (output_filename sourcename ".c" ext)
@@ -200,14 +200,14 @@ let compile_c_ast sourcename csyntax ofile debug =
dump_jasm asm sourcename (output_filename sourcename ".c" !sdump_suffix);
(* Print Asm in text form *)
let oc = open_out ofile in
- PrintAsm.print_program oc asm debug;
+ PrintAsm.print_program oc asm;
close_out oc
(* From C source to asm *)
let compile_c_file sourcename ifile ofile =
- let ast,debug = parse_c_file sourcename ifile in
- compile_c_ast sourcename ast ofile debug
+ let ast = parse_c_file sourcename ifile in
+ compile_c_ast sourcename ast ofile
(* From Cminor to asm *)
@@ -232,7 +232,7 @@ let compile_cminor_file ifile ofile =
exit 2
| Errors.OK p ->
let oc = open_out ofile in
- PrintAsm.print_program oc p None;
+ PrintAsm.print_program oc p;
close_out oc
with Parsing.Parse_error ->
eprintf "File %s, character %d: Syntax error\n"
@@ -304,7 +304,7 @@ let process_c_file sourcename =
let name =
if !option_interp then begin
Machine.config := Machine.compcert_interpreter !Machine.config;
- let csyntax,_ = parse_c_file sourcename preproname in
+ let csyntax = parse_c_file sourcename preproname in
if not !option_dprepro then
safe_remove preproname;
Interp.execute csyntax;
@@ -338,7 +338,7 @@ let process_c_file sourcename =
let process_i_file sourcename =
ensure_inputfile_exists sourcename;
if !option_interp then begin
- let csyntax,_ = parse_c_file sourcename sourcename in
+ let csyntax = parse_c_file sourcename sourcename in
Interp.execute csyntax;
""
end else if !option_S then begin
@@ -438,7 +438,7 @@ let perform_actions () =
let explode_comma_option s =
match Str.split (Str.regexp ",") s with
| [] -> assert false
- | hd :: tl -> tl
+ | _ :: tl -> tl
let version_string =
if Version.buildnr <> "" && Version.tag <> "" then
diff --git a/driver/Interp.ml b/driver/Interp.ml
index 4b6d0a44..5c2158ae 100644
--- a/driver/Interp.ml
+++ b/driver/Interp.ml
@@ -12,20 +12,17 @@
(* Interpreting CompCert C sources *)
-open Format
+open !Format
open Camlcoq
-open Datatypes
open AST
open Integers
open Values
open Memory
open Globalenvs
open Events
-open Ctypes
-open Cop
-open Csyntax
+open !Ctypes
+open !Csyntax
open Csem
-open Clflags
(* Configuration *)
@@ -86,16 +83,16 @@ let name_of_fundef prog fd =
if fd == fd' then extern_atom id else find_name rem
| (id, Gvar v) :: rem ->
find_name rem
- in find_name prog.prog_defs
+ in find_name prog.Ctypes.prog_defs
let name_of_function prog fn =
let rec find_name = function
| [] -> "<unknown function>"
- | (id, Gfun(Internal fn')) :: rem ->
+ | (id, Gfun(Ctypes.Internal fn')) :: rem ->
if fn == fn' then extern_atom id else find_name rem
| (id, _) :: rem ->
find_name rem
- in find_name prog.prog_defs
+ in find_name prog.Ctypes.prog_defs
let invert_local_variable e b =
Maps.PTree.fold
@@ -584,7 +581,7 @@ let world_program prog =
(id, Gvar gv')
| Gfun fd ->
(id, gd) in
- {prog with prog_defs = List.map change_def prog.prog_defs}
+ {prog with Ctypes.prog_defs = List.map change_def prog.Ctypes.prog_defs}
(* Massaging the program to get a suitable "main" function *)
@@ -599,7 +596,7 @@ let change_main_function p old_main old_main_ty =
fn_params = []; fn_vars = []; fn_body = body } in
let new_main_id = intern_string "___main" in
{ prog_main = new_main_id;
- prog_defs = (new_main_id, Gfun(Internal new_main_fn)) :: p.prog_defs;
+ Ctypes.prog_defs = (new_main_id, Gfun(Internal new_main_fn)) :: p.Ctypes.prog_defs;
prog_public = p.prog_public;
prog_types = p.prog_types;
prog_comp_env = p.prog_comp_env }
@@ -610,7 +607,7 @@ let rec find_main_function name = function
| (id, Gvar v) :: gdl -> find_main_function name gdl
let fixup_main p =
- match find_main_function p.prog_main p.prog_defs with
+ match find_main_function p.Ctypes.prog_main p.prog_defs with
| None ->
fprintf err_formatter "ERROR: no main() function@.";
None
diff --git a/exportclight/Clightgen.ml b/exportclight/Clightgen.ml
index a5d48a3f..d917032e 100644
--- a/exportclight/Clightgen.ml
+++ b/exportclight/Clightgen.ml
@@ -293,4 +293,3 @@ let _ =
Builtins.set C2C.builtins;
CPragmas.initialize();
parse_cmdline cmdline_actions
-
diff --git a/exportclight/ExportClight.ml b/exportclight/ExportClight.ml
index b5877f8b..0e4f1fa3 100644
--- a/exportclight/ExportClight.ml
+++ b/exportclight/ExportClight.ml
@@ -17,12 +17,10 @@
open Format
open Camlcoq
-open Datatypes
-open Values
open AST
-open Ctypes
+open !Ctypes
open Cop
-open Clight
+open !Clight
(* Options, lists, pairs *)
@@ -50,15 +48,15 @@ let print_list fn p l =
exception Not_an_identifier
let sanitize s =
- let s' = String.create (String.length s) in
+ let s' = Bytes.create (String.length s) in
for i = 0 to String.length s - 1 do
- s'.[i] <-
- match s.[i] with
+ Bytes.set s' i
+ (match String.get s i with
| 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' as c -> c
| ' ' | '$' -> '_'
- | _ -> raise Not_an_identifier
+ | _ -> raise Not_an_identifier)
done;
- s'
+ Bytes.to_string s'
let temp_names : (ident, string) Hashtbl.t = Hashtbl.create 17
@@ -79,7 +77,7 @@ let iter_hashtbl_sorted (h: ('a, string) Hashtbl.t) (f: 'a * string -> unit) =
(Hashtbl.fold (fun k d accu -> (k, d) :: accu) h []))
let define_idents p =
- iter_hashtbl_sorted
+ iter_hashtbl_sorted
string_of_atom
(fun (id, name) ->
try
@@ -402,14 +400,14 @@ let print_variable p (id, v) =
let print_globdef p (id, gd) =
match gd with
- | Gfun(Internal f) -> print_function p (id, f)
- | Gfun(External _) -> ()
+ | Gfun(Clight.Internal f) -> print_function p (id, f)
+ | Gfun(Clight.External _) -> ()
| Gvar v -> print_variable p (id, v)
let print_ident_globdef p = function
- | (id, Gfun(Internal f)) ->
+ | (id, Gfun(Clight.Internal f)) ->
fprintf p "(%a, Gfun(Internal f_%s))" ident id (extern_atom id)
- | (id, Gfun(External(ef, targs, tres, cc))) ->
+ | (id, Gfun(Clight.External(ef, targs, tres, cc))) ->
fprintf p "@[<hov 2>(%a,@ @[<hov 2>Gfun(External %a@ %a@ %a@ %a))@]@]"
ident id external_function ef typlist targs typ tres callconv cc
| (id, Gvar v) ->
@@ -529,12 +527,12 @@ let name_function f =
let name_globdef (id, g) =
match g with
- | Gfun(Internal f) -> name_function f
+ | Gfun(Clight.Internal f) -> name_function f
| _ -> ()
let name_program p =
- List.iter name_globdef p.prog_defs
-
+ List.iter name_globdef p.Clight.prog_defs
+
(* All together *)
let print_program p prog =
@@ -557,4 +555,3 @@ let print_program p prog =
fprintf p "|}.@ ";
print_assertions p;
fprintf p "@]@."
-
diff --git a/ia32/AsmToJSON.mli b/ia32/AsmToJSON.mli
new file mode 100644
index 00000000..20bcba5e
--- /dev/null
+++ b/ia32/AsmToJSON.mli
@@ -0,0 +1,13 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
+(* *)
+(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
+(* is distributed under the terms of the INRIA Non-Commercial *)
+(* License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+val p_program: out_channel -> (Asm.coq_function AST.fundef, 'a) AST.program -> unit
diff --git a/ia32/Asmexpand.ml b/ia32/Asmexpand.ml
index 61beeb00..5e5bbb3e 100644
--- a/ia32/Asmexpand.ml
+++ b/ia32/Asmexpand.ml
@@ -16,7 +16,6 @@
open Asm
open Asmexpandaux
-open Asmgen
open AST
open Camlcoq
open Datatypes
@@ -201,12 +200,12 @@ let expand_builtin_vstore chunk args =
(* Handling of varargs *)
let expand_builtin_va_start r =
- if not !current_function.fn_sig.sig_cc.cc_vararg then
+ if not (is_current_function_variadic ()) then
invalid_arg "Fatal error: va_start used in non-vararg function";
let ofs = coqint_of_camlint
Int32.(add (add !PrintAsmaux.current_function_stacksize 4l)
(mul 4l (Z.to_int32 (Conventions1.size_arguments
- !current_function.fn_sig)))) in
+ (get_current_function_sig ()))))) in
emit (Pmov_mr (linear_addr r _0, ESP));
emit (Padd_mi (linear_addr r _0, ofs))
diff --git a/ia32/TargetPrinter.ml b/ia32/TargetPrinter.ml
index f12843d2..f2358487 100644
--- a/ia32/TargetPrinter.ml
+++ b/ia32/TargetPrinter.ml
@@ -13,11 +13,10 @@
(* Printing IA32 assembly code in asm syntax *)
open Printf
-open Datatypes
+open !Datatypes
open Camlcoq
open Sections
open AST
-open Memdata
open Asm
open PrintAsmaux
open Fileinfo
@@ -309,27 +308,6 @@ module Target(System: SYSTEM):TARGET =
let section oc sec =
fprintf oc " %s\n" (name_of_section sec)
-(* SP adjustment to allocate or free a stack frame *)
-
- let int32_align n a =
- if n >= 0l
- then Int32.logand (Int32.add n (Int32.of_int (a-1))) (Int32.of_int (-a))
- else Int32.logand n (Int32.of_int (-a))
-
- let sp_adjustment sz =
- let sz = camlint_of_coqint sz in
- (* Preserve proper alignment of the stack *)
- let sz = int32_align sz stack_alignment in
- (* The top 4 bytes have already been allocated by the "call" instruction. *)
- let sz = Int32.sub sz 4l in
- sz
-
-(* Base-2 log of a Caml integer *)
-
- let rec log2 n =
- assert (n > 0);
- if n = 1 then 0 else 1 + log2 (n lsr 1)
-
(* Emit a align directive *)
let need_masks = ref false
@@ -339,8 +317,6 @@ module Target(System: SYSTEM):TARGET =
let print_file_line oc file line =
print_file_line oc comment file line
- let print_location oc loc =
- if loc <> Cutil.no_loc then print_file_line oc (fst loc) (snd loc)
(* Built-in functions *)
@@ -351,19 +327,6 @@ module Target(System: SYSTEM):TARGET =
- inlined by the compiler: take their arguments in arbitrary
registers; preserve all registers except ECX, EDX, XMM6 and XMM7. *)
- (* Handling of varargs *)
-
- let print_builtin_va_start oc r =
- if not (!current_function_sig).sig_cc.cc_vararg then
- invalid_arg "Fatal error: va_start used in non-vararg function";
- let ofs =
- Int32.(add (add !current_function_stacksize 4l)
- (mul 4l (Z.to_int32 (Conventions1.size_arguments
- !current_function_sig)))) in
- fprintf oc " movl %%esp, 0(%a)\n" ireg r;
- fprintf oc " addl $%ld, 0(%a)\n" ofs ireg r
-
-
(* Printing of instructions *)
(* Reminder on AT&T syntax: op source, dest *)
@@ -410,7 +373,7 @@ module Target(System: SYSTEM):TARGET =
fprintf oc " fstps %a\n" addressing a
| Pxchg_rr(r1, r2) ->
fprintf oc " xchgl %a, %a\n" ireg r1 ireg r2
- (** Moves with conversion *)
+ (* Moves with conversion *)
| Pmovb_mr(a, r1) ->
fprintf oc " movb %a, %a\n" ireg8 r1 addressing a
| Pmovw_mr(a, r1) ->
@@ -443,7 +406,7 @@ module Target(System: SYSTEM):TARGET =
fprintf oc " cvttss2si %a, %a\n" freg r1 ireg rd
| Pcvtsi2ss_fr(rd, r1) ->
fprintf oc " cvtsi2ss %a, %a\n" ireg r1 freg rd
- (** Arithmetic and logical operations over integers *)
+ (* Arithmetic and logical operations over integers *)
| Plea(rd, a) ->
fprintf oc " leal %a, %a\n" addressing a ireg rd
| Pneg(rd) ->
@@ -509,7 +472,7 @@ module Target(System: SYSTEM):TARGET =
| Psetcc(c, rd) ->
fprintf oc " set%s %a\n" (name_of_condition c) ireg8 rd;
fprintf oc " movzbl %a, %a\n" ireg8 rd ireg rd
- (** Arithmetic operations over floats *)
+ (* Arithmetic operations over floats *)
| Paddd_ff(rd, r1) ->
fprintf oc " addsd %a, %a\n" freg r1 freg rd
| Psubd_ff(rd, r1) ->
@@ -546,7 +509,7 @@ module Target(System: SYSTEM):TARGET =
fprintf oc " comiss %a, %a\n" freg r2 freg r1
| Pxorps_f (rd) ->
fprintf oc " xorpd %a, %a\n" freg rd freg rd
- (** Branches and calls *)
+ (* Branches and calls *)
| Pjmp_l(l) ->
fprintf oc " jmp %a\n" label (transl_label l)
| Pjmp_s(f, sg) ->
@@ -652,7 +615,7 @@ module Target(System: SYSTEM):TARGET =
fprintf oc " sqrtsd %a, %a\n" freg a1 freg res
| Psub_ri (res,n) ->
fprintf oc " subl $%ld, %a\n" (camlint_of_coqint n) ireg res;
- (** Pseudo-instructions *)
+ (* Pseudo-instructions *)
| Plabel(l) ->
fprintf oc "%a:\n" label (transl_label l)
| Pallocframe(sz, ofs_ra, ofs_link)
diff --git a/lib/Camlcoq.ml b/lib/Camlcoq.ml
index c5fb2e55..90c3ab3f 100644
--- a/lib/Camlcoq.ml
+++ b/lib/Camlcoq.ml
@@ -307,11 +307,11 @@ let first_unused_ident () = !next_atom
(* Strings *)
let camlstring_of_coqstring (s: char list) =
- let r = String.create (List.length s) in
+ let r = Bytes.create (List.length s) in
let rec fill pos = function
| [] -> r
- | c :: s -> r.[pos] <- c; fill (pos + 1) s
- in fill 0 s
+ | c :: s -> Bytes.set r pos c; fill (pos + 1) s
+ in Bytes.to_string (fill 0 s)
let coqstring_of_camlstring s =
let rec cstring accu pos =
diff --git a/lib/Json.ml b/lib/Json.ml
index 4aa91e95..22b50a9e 100644
--- a/lib/Json.ml
+++ b/lib/Json.ml
@@ -15,7 +15,8 @@ open Printf
(* Simple functions for JSON printing *)
(* Print a string as json string *)
-let p_jstring oc s = fprintf oc "\"%s\"" s
+let p_jstring oc s =
+ fprintf oc "\"%s\"" s
(* Print a list as json array *)
let p_jarray elem oc l =
@@ -29,13 +30,20 @@ let p_jarray elem oc l =
(* Print a bool as json bool *)
let p_jbool oc = fprintf oc "%B"
-(* Print a int as json int *)
+(* Print an int as json int *)
let p_jint oc = fprintf oc "%d"
+(* Print an int32 as json int *)
+let p_jint32 oc = fprintf oc "%ld"
+
(* Print a member *)
let p_jmember oc name p_mem mem =
fprintf oc "\n%a:%a" p_jstring name p_mem mem
+(* Print singleton object *)
+let p_jsingle_object oc name p_mem mem =
+ fprintf oc "{%a:%a}" p_jstring name p_mem mem
+
(* Print optional value *)
let p_jopt p_elem oc = function
| None -> output_string oc "null"
diff --git a/lib/Printlines.ml b/lib/Printlines.ml
index e0805f15..453096bc 100644
--- a/lib/Printlines.ml
+++ b/lib/Printlines.ml
@@ -48,7 +48,7 @@ let forward b dest =
(* Position [b] to the beginning of line [dest], which must be less than
the current line. *)
-let backward_buf = lazy (String.create 65536)
+let backward_buf = lazy (Bytes.create 65536)
(* 65536 to match [IO_BUFFER_SIZE] in the OCaml runtime.
lazy to allocate on demand. *)
@@ -65,13 +65,13 @@ let backward b dest =
seek_in b.chan 0;
b.lineno <- 1
end else begin
- let pos' = max 0 (pos - String.length buf) in
+ let pos' = max 0 (pos - Bytes.length buf) in
let len = pos - pos' in
seek_in b.chan pos';
really_input b.chan buf 0 len;
backward pos' (pos - pos')
end
- end else if buf.[idx-1] = '\n' then begin
+ end else if Bytes.get buf (idx-1) = '\n' then begin
(* Reached beginning of current line *)
if b.lineno = dest then begin
(* Found line number dest *)
diff --git a/lib/Printlines.mli b/lib/Printlines.mli
index 79201f86..545eb033 100644
--- a/lib/Printlines.mli
+++ b/lib/Printlines.mli
@@ -20,8 +20,10 @@ type filebuf
val openfile: string -> filebuf
(** Open the file with the given name. *)
+
val close: filebuf -> unit
(** Close the file underlying the given buffer. *)
+
val copy: out_channel -> string -> filebuf -> int -> int -> unit
(** [copy oc pref buf first last] copies lines number [first]
to [last], included, to the channel [oc]. Each line is
diff --git a/powerpc/AsmToJSON.ml b/powerpc/AsmToJSON.ml
index 75a629c5..7862aad8 100644
--- a/powerpc/AsmToJSON.ml
+++ b/powerpc/AsmToJSON.ml
@@ -21,91 +21,20 @@ open Json
open Printf
open Sections
-let p_ireg oc reg =
- let num = match reg with
- | GPR0 -> 0
- | GPR1 -> 1
- | GPR2 -> 2
- | GPR3 -> 3
- | GPR4 -> 4
- | GPR5 -> 5
- | GPR6 -> 6
- | GPR7 -> 7
- | GPR8 -> 8
- | GPR9 -> 9
- | GPR10 -> 10
- | GPR11 -> 11
- | GPR12 -> 12
- | GPR13 -> 13
- | GPR14 -> 14
- | GPR15 -> 15
- | GPR16 -> 16
- | GPR17 -> 17
- | GPR18 -> 18
- | GPR19 -> 19
- | GPR20 -> 20
- | GPR21 -> 21
- | GPR22 -> 22
- | GPR23 -> 23
- | GPR24 -> 24
- | GPR25 -> 25
- | GPR26 -> 26
- | GPR27 -> 27
- | GPR28 -> 28
- | GPR29 -> 29
- | GPR30 -> 30
- | GPR31 -> 31
- in output_string oc "{";
- p_jmember oc "Register" (fun oc d -> p_jstring oc ("r"^(string_of_int d))) num;
- output_string oc "}"
+let p_reg oc t n =
+ let s = sprintf "%s%s" t n in
+ p_jsingle_object oc "Register" p_jstring s
-let p_freg oc reg =
- let num = match reg with
- | FPR0 -> 0
- | FPR1 -> 1
- | FPR2 -> 2
- | FPR3 -> 3
- | FPR4 -> 4
- | FPR5 -> 5
- | FPR6 -> 6
- | FPR7 -> 7
- | FPR8 -> 8
- | FPR9 -> 9
- | FPR10 -> 10
- | FPR11 -> 11
- | FPR12 -> 12
- | FPR13 -> 13
- | FPR14 -> 14
- | FPR15 -> 15
- | FPR16 -> 16
- | FPR17 -> 17
- | FPR18 -> 18
- | FPR19 -> 19
- | FPR20 -> 20
- | FPR21 -> 21
- | FPR22 -> 22
- | FPR23 -> 23
- | FPR24 -> 24
- | FPR25 -> 25
- | FPR26 -> 26
- | FPR27 -> 27
- | FPR28 -> 28
- | FPR29 -> 29
- | FPR30 -> 30
- | FPR31 -> 31
- in output_string oc "{";
- p_jmember oc "Register" (fun oc d -> p_jstring oc ("f"^(string_of_int d))) num;
- output_string oc "}"
+let p_ireg oc reg =
+ p_reg oc "r" (TargetPrinter.int_reg_name reg)
-let p_preg oc = function
- | IR ir -> p_ireg oc ir
- | FR fr -> p_freg oc fr
- | _ -> assert false (* This register should not be used. *)
+let p_freg oc reg =
+ p_reg oc "f" (TargetPrinter.float_reg_name reg)
let p_atom oc a = p_jstring oc (extern_atom a)
-let p_atom_constant oc a = fprintf oc "{\"Atom\":%a}" p_atom a
+let p_atom_constant oc a = p_jsingle_object oc "Atom" p_atom a
let p_int oc i = fprintf oc "%ld" (camlint_of_coqint i)
let p_int64 oc i = fprintf oc "%Ld" (camlint64_of_coqint i)
@@ -113,36 +42,44 @@ let p_float32 oc f = fprintf oc "%ld" (camlint_of_coqint (Floats.Float32.to_bits
let p_float64 oc f = fprintf oc "%Ld" (camlint64_of_coqint (Floats.Float.to_bits f))
let p_z oc z = fprintf oc "%s" (Z.to_string z)
-let p_int_constant oc i = fprintf oc "{\"Integer\":%a}" p_int i
-let p_float64_constant oc f = fprintf oc "{\"Float\":%a}" p_float64 f
-let p_float32_constant oc f = fprintf oc "{\"Float\":%a}" p_float32 f
-let p_z_constant oc z = fprintf oc "{\"Integer\":%s}" (Z.to_string z)
+let p_int_constant oc i = p_jsingle_object oc "Integer" p_int i
+let p_float64_constant oc f = p_jsingle_object oc "Float" p_float64 f
+let p_float32_constant oc f = p_jsingle_object oc "Float" p_float32 f
+
+let p_sep oc = fprintf oc ","
-let p_constant oc = function
+let p_constant oc c =
+ let p_symbol oc (i,c) =
+ output_string oc "{";
+ p_jmember oc "Name" p_atom i;
+ p_sep oc;
+ p_jmember oc "Offset" p_int c;
+ output_string oc "}" in
+ match c with
| Cint i -> p_int_constant oc i
- | Csymbol_low (i,c) -> fprintf oc "{\"Symbol_low\":{\"Name\":%a,\"Offset\":%a}}" p_atom i p_int c
- | Csymbol_high (i,c) -> fprintf oc "{\"Symbol_high\":{\"Name\":%a,\"Offset\":%a}}" p_atom i p_int c
- | Csymbol_sda (i,c) -> fprintf oc "{\"Symbol_sda\":{\"Name\":%a,\"Offset\":%a}}" p_atom i p_int c
- | Csymbol_rel_low (i,c) -> fprintf oc "{\"Symbol_rel_low\":{\"Name\":%a,\"Offset\":%a}}" p_atom i p_int c
- | Csymbol_rel_high (i,c) -> fprintf oc "{\"Symbol_rel_high\":{\"Name\":%a,\"Offset\":%a}}" p_atom i p_int c
+ | Csymbol_low (i,c) ->
+ p_jsingle_object oc "Symbol_low" p_symbol (i,c)
+ | Csymbol_high (i,c) ->
+ p_jsingle_object oc "Symbol_high" p_symbol (i,c)
+ | Csymbol_sda (i,c) ->
+ p_jsingle_object oc "Symbol_sda" p_symbol (i,c)
+ | Csymbol_rel_low (i,c) ->
+ p_jsingle_object oc "Symbol_rel_low" p_symbol (i,c)
+ | Csymbol_rel_high (i,c) ->
+ p_jsingle_object oc "Symbol_rel_high" p_symbol (i,c)
let p_crbit oc c =
- let number = match c with
- | CRbit_0 -> 0
- | CRbit_1 -> 1
- | CRbit_2 -> 2
- | CRbit_3 -> 3
- | CRbit_6 -> 6 in
- fprintf oc "{\"CRbit\":%d}" number
+ p_jsingle_object oc "CRbit" p_jint (TargetPrinter.num_crbit c)
-let p_label oc l = fprintf oc "{\"Label\":%ld}" (P.to_int32 l)
+let p_label oc l =
+ p_jsingle_object oc "Label" p_jint32 (P.to_int32 l)
type instruction_arg =
| Ireg of ireg
| Freg of freg
| Constant of constant
| Crbit of crbit
- | Label of positive
+ | ALabel of positive
| Float32 of Floats.float32
| Float64 of Floats.float
| Atom of positive
@@ -152,14 +89,14 @@ let p_arg oc = function
| Freg fr -> p_freg oc fr
| Constant c -> p_constant oc c
| Crbit cr -> p_crbit oc cr
- | Label lbl -> p_label oc lbl
+ | ALabel lbl -> p_label oc lbl
| Float32 f -> p_float32_constant oc f
| Float64 f -> p_float64_constant oc f
| Atom a -> p_atom_constant oc a
let p_instruction oc ic =
let p_args oc l= fprintf oc "%a:%a" p_jstring "Args" (p_jarray p_arg) l
- and inst_name oc s = fprintf oc"%a:%a" p_jstring "Instruction Name" p_jstring s in
+ and inst_name oc s = p_jmember oc "Instruction Name" p_jstring s in
let first = ref true in
let sep oc = if !first then first := false else output_string oc ", " in
let instruction n args = fprintf oc "\n%t{%a,%a}" sep inst_name n p_args args in
@@ -176,16 +113,16 @@ let p_instruction oc ic =
| Pandc (ir1,ir2,ir3) -> instruction "Pandc" [Ireg ir1; Ireg ir2; Ireg ir3]
| Pandi_ (ir1,ir2,c) -> instruction "Pandi_" [Ireg ir1; Ireg ir2; Constant c]
| Pandis_ (ir1,ir2,c) -> instruction "Pandis_" [Ireg ir1; Ireg ir2; Constant c]
- | Pb l -> instruction "Pb" [Label l]
+ | Pb l -> instruction "Pb" [ALabel l]
| Pbctr s -> instruction "Pbctr" []
| Pbctrl s -> instruction "Pbctrl" []
- | Pbdnz l -> instruction "Pbdnz" [Label l]
- | Pbf (cr,l) -> instruction "Pbf" [Crbit cr; Label l]
+ | Pbdnz l -> instruction "Pbdnz" [ALabel l]
+ | Pbf (cr,l) -> instruction "Pbf" [Crbit cr; ALabel l]
| Pbl (i,s) -> instruction "Pbl" [Atom i]
| Pbs (i,s) -> instruction "Pbs" [Atom i]
| Pblr -> instruction "Pblr" []
- | Pbt (cr,l) -> instruction "Pbt" [Crbit cr; Label l]
- | Pbtbl (i,lb) -> instruction "Pbtbl" ((Ireg i)::(List.map (fun a -> Label a) lb))
+ | Pbt (cr,l) -> instruction "Pbt" [Crbit cr; ALabel l]
+ | Pbtbl (i,lb) -> instruction "Pbtbl" ((Ireg i)::(List.map (fun a -> ALabel a) lb))
| Pcmpb (ir1,ir2,ir3) -> instruction "Pcmpb" [Ireg ir1; Ireg ir2; Ireg ir3]
| Pcmplw (ir1,ir2) -> instruction "Pcmplw" [Ireg ir1; Ireg ir2]
| Pcmplwi (ir,c) -> instruction "Pcmplwi" [Ireg ir; Constant c]
@@ -326,17 +263,14 @@ let p_instruction oc ic =
| Pxor (ir1,ir2,ir3) -> instruction "Pxor" [Ireg ir1; Ireg ir2; Ireg ir3]
| Pxori (ir1,ir2,c) ->instruction "Pxori" [Ireg ir1; Ireg ir2; Constant c]
| Pxoris (ir1,ir2,c) -> instruction "Pxoris" [Ireg ir1; Ireg ir2; Constant c]
- | Plabel l -> instruction "Plabel" [Label l]
+ | Plabel l -> instruction "Plabel" [ALabel l]
| Pbuiltin _ -> ()
| Pcfi_adjust _ (* Only debug relevant *)
| Pcfi_rel_offset _ -> () (* Only debug relevant *) in
List.iter instruction ic
let p_storage oc static =
- if static then
- fprintf oc "\"Static\""
- else
- fprintf oc "\"Extern\""
+ p_jstring oc (if static then "Static" else "Extern")
let p_section oc = function
| Section_text -> fprintf oc "{\"Section Name\":\"Text\"}"
@@ -365,29 +299,60 @@ let p_fundef oc (name,f) =
and inline = atom_is_inline name
and static = atom_is_static name
and c_section,l_section,j_section = match (atom_sections name) with [a;b;c] -> a,b,c | _ -> assert false in
- fprintf oc "{\"Fun Name\":%a,\n\"Fun Storage Class\":%a,\n\"Fun Alignment\":%a,\n\"Fun Section Code\":%a,\"Fun Section Literals\":%a,\"Fun Section Jumptable\":%a,\n\"Fun Inline\":%B,\n\"Fun Code\":[%a]}\n"
- p_atom name p_storage static p_int_opt alignment
- p_section c_section p_section l_section p_section j_section inline
- p_instruction f.fn_code
+ output_string oc "{";
+ p_jmember oc "Fun Name" p_atom name;
+ p_sep oc;
+ p_jmember oc "Fun Storage Class" p_storage static;
+ p_sep oc;
+ p_jmember oc "Fun Alignment" p_int_opt alignment;
+ p_sep oc;
+ p_jmember oc "Fun Section Code" p_section c_section;
+ p_sep oc;
+ p_jmember oc "Fun Section Literal" p_section l_section;
+ p_sep oc;
+ p_jmember oc "Fun Section Jumptable" p_section j_section;
+ p_sep oc;
+ p_jmember oc "Fun Inline" p_jbool inline;
+ p_sep oc;
+ p_jmember oc "Fun Code" (fun oc a -> fprintf oc "[%a]" p_instruction a) f.fn_code;
+ output_string oc "}\n"
let p_init_data oc = function
- | Init_int8 ic -> fprintf oc "{\"Init_int8\":%a}" p_int ic
- | Init_int16 ic -> fprintf oc "{\"Init_int16\":%a}" p_int ic
- | Init_int32 ic -> fprintf oc "{\"Init_int32\":%a}" p_int ic
- | Init_int64 lc -> fprintf oc "{\"Init_int64\":%a}" p_int64 lc
- | Init_float32 f -> fprintf oc "{\"Init_float32\":%a}" p_float32 f
- | Init_float64 f -> fprintf oc "{\"Init_float64\":%a}" p_float64 f
- | Init_space z -> fprintf oc "{\"Init_space\":%a}" p_z z
- | Init_addrof (p,i) -> fprintf oc "{\"Init_addrof\":{\"Addr\":%a,\"Offset\":%a}}" p_atom p p_int i
+ | Init_int8 ic -> p_jsingle_object oc "Init_int8" p_int ic
+ | Init_int16 ic -> p_jsingle_object oc "Init_int16" p_int ic
+ | Init_int32 ic -> p_jsingle_object oc "Init_int32" p_int ic
+ | Init_int64 lc -> p_jsingle_object oc "Init_int64" p_int64 lc
+ | Init_float32 f -> p_jsingle_object oc "Init_float32" p_float32 f
+ | Init_float64 f -> p_jsingle_object oc "Init_float64" p_float64 f
+ | Init_space z -> p_jsingle_object oc "Init_space" p_z z
+ | Init_addrof (p,i) ->
+ let p_addr_of oc (p,i) =
+ output_string oc "{";
+ p_jmember oc "Addr" p_atom p;
+ p_sep oc;
+ p_jmember oc "Offset" p_int i;
+ output_string oc "}" in
+ p_jsingle_object oc "Init_addrof" p_addr_of (p,i)
let p_vardef oc (name,v) =
let alignment = atom_alignof name
and static = atom_is_static name
- and section = match (atom_sections name) with [s] -> s | _ -> assert false (* Should only have one section *) in
- fprintf oc "{\"Var Name\":%a,\"Var Readonly\":%B,\"Var Volatile\":%B,\n\"Var Storage Class\":%a,\n\"Var Alignment\":%a,\n\"Var Section\":%a,\n\"Var Init\":%a}\n"
- p_atom name v.gvar_readonly v.gvar_volatile
- p_storage static p_int_opt alignment p_section section
- (p_jarray p_init_data) v.gvar_init
+ and section = match (atom_sections name) with [s] -> s | _ -> assert false in(* Should only have one section *)
+ output_string oc "{";
+ p_jmember oc "Var Name" p_atom name;
+ p_sep oc;
+ p_jmember oc "Var Readonly" p_jbool v.gvar_readonly;
+ p_sep oc;
+ p_jmember oc "Var Volatile" p_jbool v.gvar_volatile;
+ p_sep oc;
+ p_jmember oc "Var Storage Class" p_storage static;
+ p_sep oc;
+ p_jmember oc "Var Alignment" p_int_opt alignment;
+ p_sep oc;
+ p_jmember oc "Var Section" p_section section;
+ p_sep oc;
+ p_jmember oc "Var Init" (p_jarray p_init_data) v.gvar_init;
+ output_string oc "}\n"
let p_program oc prog =
let prog_vars,prog_funs = List.fold_left (fun (vars,funs) (ident,def) ->
diff --git a/powerpc/AsmToJSON.mli b/powerpc/AsmToJSON.mli
new file mode 100644
index 00000000..20bcba5e
--- /dev/null
+++ b/powerpc/AsmToJSON.mli
@@ -0,0 +1,13 @@
+(* *********************************************************************)
+(* *)
+(* The Compcert verified compiler *)
+(* *)
+(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
+(* *)
+(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
+(* is distributed under the terms of the INRIA Non-Commercial *)
+(* License Agreement. *)
+(* *)
+(* *********************************************************************)
+
+val p_program: out_channel -> (Asm.coq_function AST.fundef, 'a) AST.program -> unit
diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml
index dad19a6d..bfec9254 100644
--- a/powerpc/Asmexpand.ml
+++ b/powerpc/Asmexpand.ml
@@ -13,11 +13,9 @@
(* Expanding built-ins and some pseudo-instructions by rewriting
of the PPC assembly code. *)
-open Datatypes
open Camlcoq
open Integers
open AST
-open Memdata
open Asm
open Asmexpandaux
@@ -310,10 +308,10 @@ let rec next_arg_locations ir fr ofs = function
else next_arg_locations ir fr (align ofs 8 + 8) l
let expand_builtin_va_start r =
- if not (!current_function).fn_sig.sig_cc.cc_vararg then
+ if not (is_current_function_variadic ()) then
invalid_arg "Fatal error: va_start used in non-vararg function";
let (ir, fr, ofs) =
- next_arg_locations 0 0 0 (!current_function).fn_sig.sig_args in
+ next_arg_locations 0 0 0 (get_current_function_args ()) in
emit_loadimm GPR0 (Z.of_uint ir);
emit (Pstb(GPR0, Cint _0, r));
emit_loadimm GPR0 (Z.of_uint fr);
@@ -644,7 +642,7 @@ let num_crbit = function
let expand_instruction instr =
match instr with
| Pallocframe(sz, ofs,retofs) ->
- let variadic = (!current_function).fn_sig.sig_cc.cc_vararg in
+ let variadic = is_current_function_variadic () in
let sz = camlint_of_coqint sz in
assert (ofs = _0);
let sz = if variadic then Int32.add sz 96l else sz in
@@ -669,7 +667,7 @@ let expand_instruction instr =
set_cr6 sg;
emit instr
| Pfreeframe(sz, ofs) ->
- let variadic = (!current_function).fn_sig.sig_cc.cc_vararg in
+ let variadic = is_current_function_variadic () in
let sz = camlint_of_coqint sz in
let sz = if variadic then Int32.add sz 96l else sz in
if sz < 0x8000l && sz >= 0l then
diff --git a/powerpc/TargetPrinter.ml b/powerpc/TargetPrinter.ml
index 3d183972..ae9d4191 100644
--- a/powerpc/TargetPrinter.ml
+++ b/powerpc/TargetPrinter.ml
@@ -14,12 +14,11 @@
open Printf
open Fileinfo
-open Datatypes
+open !Datatypes
open Maps
open Camlcoq
open Sections
open AST
-open Memdata
open Asm
open PrintAsmaux
@@ -72,6 +71,14 @@ let float_reg_name = function
| FPR24 -> "24" | FPR25 -> "25" | FPR26 -> "26" | FPR27 -> "27"
| FPR28 -> "28" | FPR29 -> "29" | FPR30 -> "30" | FPR31 -> "31"
+let num_crbit = function
+ | CRbit_0 -> 0
+ | CRbit_1 -> 1
+ | CRbit_2 -> 2
+ | CRbit_3 -> 3
+ | CRbit_6 -> 6
+
+
let label = elf_label
module Linux_System : SYSTEM =
@@ -303,9 +310,6 @@ module Target (System : SYSTEM):TARGET =
(* Basic printing functions *)
let symbol = symbol
- let raw_symbol oc s =
- fprintf oc "%s" s
-
let label = label
let label_low oc lbl =
@@ -314,14 +318,6 @@ module Target (System : SYSTEM):TARGET =
let label_high oc lbl =
fprintf oc ".L%d@ha" lbl
-
- let num_crbit = function
- | CRbit_0 -> 0
- | CRbit_1 -> 1
- | CRbit_2 -> 2
- | CRbit_3 -> 3
- | CRbit_6 -> 6
-
let crbit oc bit =
fprintf oc "%d" (num_crbit bit)
@@ -340,9 +336,6 @@ module Target (System : SYSTEM):TARGET =
| FR r -> fprintf oc "f%s" (float_reg_name r)
| _ -> assert false
- let print_location oc loc =
- if loc <> Cutil.no_loc then print_file_line oc (fst loc) (snd loc)
-
(* Encoding masks for rlwinm instructions *)
let rolm_mask n =