Skip to content

Commit 1cae3dc

Browse files
Petr BauchPetr Bauch
authored andcommitted
Add malloc and size_t symbols
1 parent eb87bd0 commit 1cae3dc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

gnat2goto/driver/driver.adb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,42 @@ package body Driver is
5555
procedure Follow_Type_Declarations (Old_Table : Symbol_Table;
5656
New_Table : in out Symbol_Table);
5757

58+
procedure Add_Malloc_Symbol;
59+
60+
procedure Add_Malloc_Symbol is
61+
Malloc_Name : constant String := "malloc";
62+
Malloc_Params : constant Irep := New_Irep (I_Parameter_List);
63+
Size_Param : constant Irep :=
64+
Create_Fun_Parameter (Fun_Name => Malloc_Name,
65+
Param_Name => "size",
66+
Param_Type =>
67+
Make_Symbol_Type (Identifier => "__CPROVER_size_t"),
68+
Param_List => Malloc_Params,
69+
A_Symbol_Table => Global_Symbol_Table);
70+
Malloc_Type : constant Irep :=
71+
Make_Code_Type (Parameters => Malloc_Params,
72+
Ellipsis => False,
73+
Return_Type => Make_Pointer_Type (Make_Void_Type),
74+
Inlined => False,
75+
Knr => False);
76+
Malloc_Symbol : Symbol;
77+
begin
78+
if Kind (Size_Param) = I_Code_Parameter then
79+
Malloc_Symbol :=
80+
New_Function_Symbol_Entry (Name => Malloc_Name,
81+
Symbol_Type => Malloc_Type,
82+
Value => Ireps.Empty,
83+
A_Symbol_Table => Global_Symbol_Table);
84+
pragma Assert (Kind (Malloc_Symbol.SymType) = I_Code_Type);
85+
end if;
86+
end Add_Malloc_Symbol;
87+
5888
procedure GNAT_To_Goto (GNAT_Root : Node_Id)
5989
is
6090
begin
6191
Translate_Standard_Types;
6292
Add_CProver_Internal_Symbols;
93+
Add_Malloc_Symbol;
6394
Translate_Compilation_Unit (GNAT_Root);
6495
end GNAT_To_Goto;
6596

@@ -350,6 +381,20 @@ package body Driver is
350381
Global_Symbol_Table.Insert (Builtin.Name, Builtin);
351382
end Add_Universal_Integer;
352383

384+
procedure Add_CProver_Size_T;
385+
procedure Add_CProver_Size_T is
386+
Builtin : Symbol;
387+
Type_Irep : constant Irep := New_Irep (I_Unsignedbv_Type);
388+
begin
389+
Set_Width (Type_Irep, 64);
390+
Builtin.Name := Intern ("__CPROVER_size_t");
391+
Builtin.PrettyName := Builtin.Name;
392+
Builtin.BaseName := Builtin.Name;
393+
Builtin.SymType := Type_Irep;
394+
Builtin.IsType := True;
395+
396+
Global_Symbol_Table.Insert (Builtin.Name, Builtin);
397+
end Add_CProver_Size_T;
353398
begin
354399
-- Add primitive types to the symtab
355400
for Standard_Type in S_Types'Range loop
@@ -410,6 +455,7 @@ package body Driver is
410455
end loop;
411456
Add_Universal_Integer;
412457
Add_Standard_String;
458+
Add_CProver_Size_T;
413459
end Translate_Standard_Types;
414460

415461
procedure Add_CProver_Internal_Symbols is

0 commit comments

Comments
 (0)