Skip to content

Commit bd18b02

Browse files
authored
Merge pull request #212 from xbauch/feature/function-bodies
Support for function bodies
2 parents 3ba6acd + c9b7583 commit bd18b02

File tree

45 files changed

+168
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+168
-81
lines changed

gnat2goto/driver/driver.adb

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,14 @@ package body Driver is
366366
Initial_Call : constant Irep := New_Irep (I_Code_Function_Call);
367367
Initial_Call_Args : constant Irep := New_Irep (I_Argument_List);
368368

369-
Add_Start : Boolean;
370-
Program_Symbol : constant Symbol := Do_Compilation_Unit (GNAT_Root,
371-
Add_Start);
369+
Unit_Is_Subprogram : Boolean;
370+
Program_Symbol : constant Symbol :=
371+
Do_Compilation_Unit (GNAT_Root, Unit_Is_Subprogram);
372+
373+
-- Only add CPROVER_Start if the unit is subprogram and the user did not
374+
-- suppress it (by cmdl option).
375+
Add_Start : constant Boolean :=
376+
Unit_Is_Subprogram and not Suppress_Cprover_Start;
372377

373378
Sym_Tab_File : File_Type;
374379
Base_Name : constant String :=
@@ -404,20 +409,6 @@ package body Driver is
404409
end;
405410

406411
if not Add_Start then
407-
-- If the compilation unit is not a subprogram body then there is
408-
-- no function/procedure to call
409-
-- CBMC does not like that so we add cprover_start with empty body
410-
Start_Symbol.Name := Start_Name;
411-
Start_Symbol.PrettyName := Start_Name;
412-
Start_Symbol.BaseName := Start_Name;
413-
414-
Set_Return_Type (Start_Type, Void_Type);
415-
416-
Start_Symbol.SymType := Start_Type;
417-
Start_Symbol.Value := Start_Body;
418-
Start_Symbol.Mode := Intern ("C");
419-
420-
Global_Symbol_Table.Insert (Start_Name, Start_Symbol);
421412
Sanitise_Type_Declarations (Global_Symbol_Table,
422413
Sanitised_Symbol_Table);
423414
Put_Line (Sym_Tab_File,
@@ -553,6 +544,9 @@ package body Driver is
553544
then
554545
Dump_Statement_AST_On_Error := True;
555546
return True;
547+
elsif Switch (First .. Last) = "-no-cprover-start" then
548+
Suppress_Cprover_Start := True;
549+
return True;
556550
end if;
557551
end if;
558552
return False;

gnat2goto/driver/driver.ads

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
with Types; use Types;
2525

2626
package Driver is
27+
Suppress_Cprover_Start : Boolean := False;
2728

2829
procedure GNAT_To_Goto (GNAT_Root : Node_Id);
2930
procedure Translate_Compilation_Unit (GNAT_Root : Node_Id);

gnat2goto/driver/tree_walk.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ package body Tree_Walk is
991991
-- Do_Compilation_Unit --
992992
-------------------------
993993

994-
function Do_Compilation_Unit (N : Node_Id; Add_Start : out Boolean)
994+
function Do_Compilation_Unit (N : Node_Id; Unit_Is_Subprogram : out Boolean)
995995
return Symbol
996996
is
997997
U : constant Node_Id := Unit (N);
@@ -1018,15 +1018,15 @@ package body Tree_Walk is
10181018

10191019
-- and update the symbol table entry for this subprogram.
10201020
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1021-
Add_Start := True;
1021+
Unit_Is_Subprogram := True;
10221022
end;
10231023

10241024
when N_Package_Body =>
10251025
declare
10261026
Dummy : constant Irep := Do_Subprogram_Or_Block (U);
10271027
pragma Unreferenced (Dummy);
10281028
begin
1029-
Add_Start := False;
1029+
Unit_Is_Subprogram := False;
10301030
end;
10311031

10321032
when others =>

gnat2goto/driver/tree_walk.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ package Tree_Walk is
7575

7676
Check_Function_Symbol : Irep := Ireps.Empty;
7777

78-
function Do_Compilation_Unit (N : Node_Id; Add_Start : out Boolean)
78+
function Do_Compilation_Unit (N : Node_Id; Unit_Is_Subprogram : out Boolean)
7979
return Symbol
8080
with Pre => Nkind (N) = N_Compilation_Unit;
8181

testsuite/gnat2goto/lib/python/test_support.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,18 @@ def filter_timing(results):
2929

3030
return re.sub(skip, r'', results)
3131

32-
33-
def process(debug, file, cbmcargs):
32+
def process_gnat2goto(debug, file, is_main):
3433
"""Process Ada file with gnat2goto and cbmc"""
3534
unit = os.path.splitext(file)[0]
3635
jsout = unit + ".json_symtab"
37-
symtab = unit + ".symtab"
38-
gotoprog = unit + ".goto_functions"
39-
out = unit + ".out"
4036
errout = unit + ".error"
4137
stdoutp = unit + "stdoutp"
42-
cbmcerr = unit + "cbmc_error"
38+
gnat2gotoargs = []
39+
if not is_main: gnat2gotoargs.append("--no-cprover-start")
4340

44-
cmd = ["gnat2goto", file]
41+
cmd = ["gnat2goto", file] + gnat2gotoargs
4542

46-
g2go_results = Run(["gnat2goto", file], output=stdoutp, error=errout)
43+
g2go_results = Run(cmd, output=stdoutp, error=errout)
4744

4845
stdout_file = open (stdoutp)
4946
errout_file = open (errout)
@@ -60,12 +57,22 @@ def process(debug, file, cbmcargs):
6057
if g2go_results.status != 0:
6158
print "ERROR code ", g2go_results.status, " returned by gnat2goto when translating " + unit
6259
print "CBMC not run"
63-
return ""
60+
return False
61+
62+
return True
63+
64+
# only run the following if gnat2goto succeeded
65+
def process_cbmc(debug, files, cbmcargs):
66+
"""Process Ada file with gnat2goto and cbmc"""
67+
jsout = []
68+
for file in files:
69+
unit = os.path.splitext(file)[0]
70+
file_jsout = unit + ".json_symtab"
71+
jsout.append(file_jsout)
72+
73+
cbmcerr = TEST_NAME + "cbmc_error"
6474

65-
# only run the following if gnat2goto succeeded
66-
# Run(["cbmc", jsout, "--show-symbol-table"], output=symtab)
67-
# Run(["cbmc", jsout, "--show-goto-functions"], output=gotoprog)
68-
cmdline = ["cbmc", jsout]
75+
cmdline = ["cbmc"] + jsout
6976
if cbmcargs: cmdline += cbmcargs.split(" ")
7077
results = Run(cmdline, error=cbmcerr)
7178

@@ -80,7 +87,6 @@ def process(debug, file, cbmcargs):
8087

8188
return filter_timing(results.out)
8289

83-
8490
def cbmc_match(line):
8591
return ('FAILURE' in line or
8692
'SUCCESS' in line or
@@ -91,16 +97,21 @@ def filter_cbmc_output(cbmc_output):
9197
lines = cbmc_output.split("\n")
9298
return "\n".join(filter(cbmc_match, lines))
9399

94-
def prove(cbmcargs="", debug=False):
100+
def prove(cbmcargs="", main="", debug=False):
95101
"""Call gnat2goto (and cbmc) on all *.adb files from the current directory
96102
97103
PARAMETERS
98-
none: yet
104+
cbmcargs: arguments to be passed to CBMC
105+
main: name of the file containing the entry point
106+
debug: flag indicating if debug output should be printed out
99107
"""
100108
for file in ada_body_files():
101-
out = process(debug, file, cbmcargs)
102-
if debug:
103-
print('<<< DEBUG ' + file + ' >>>')
104-
print(out)
105-
print('<<< END DEBUG ' + file + ' >>>')
106-
print(filter_cbmc_output(out))
109+
gnat2goto_success = process_gnat2goto(debug, file, main == "" or file == main)
110+
if not gnat2goto_success:
111+
return ""
112+
out = process_cbmc(debug, ada_body_files(), cbmcargs)
113+
if debug:
114+
print('<<< DEBUG ' + file + ' >>>')
115+
print(out)
116+
print('<<< END DEBUG ' + file + ' >>>')
117+
print(filter_cbmc_output(out))
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[1] file absolute.adb line 7 assertion: SUCCESS
2+
[2] file absolute.adb line 8 assertion: SUCCESS
3+
[3] file absolute.adb line 10 assertion: FAILURE
4+
VERIFICATION FAILED
File renamed without changes.

testsuite/gnat2goto/tests/abs/absolute_float.adb renamed to testsuite/gnat2goto/tests/absolute_float/absolute_float.adb

File renamed without changes.

testsuite/gnat2goto/tests/abs/test.out renamed to testsuite/gnat2goto/tests/absolute_float/test.out

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[1] file absolute.adb line 7 assertion: SUCCESS
2-
[2] file absolute.adb line 8 assertion: SUCCESS
3-
[3] file absolute.adb line 10 assertion: FAILURE
4-
VERIFICATION FAILED
51
[1] file absolute_float.adb line 7 assertion: SUCCESS
62
[2] file absolute_float.adb line 8 assertion: SUCCESS
73
[3] file absolute_float.adb line 10 assertion: FAILURE

0 commit comments

Comments
 (0)