1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 | -------------------------------------------------------------------------------------
--
-- HAC - HAC Ada Compiler
--
-- A compiler in Ada for an Ada subset
--
-- Copyright, license, etc. : see top package.
--
-------------------------------------------------------------------------------------
--
-- Builder: *the* entry point for building an executable (possibly for the p-code
-- virtual machine) from Ada sources (a main procedure and possible depending units).
with HAC_Sys.Co_Defs,
HAC_Sys.Defs,
HAC_Sys.Librarian,
HAC_Sys.Targets;
with HAT;
with Ada.Containers.Hashed_Maps,
Ada.Finalization,
Ada.Streams,
Ada.Strings.Unbounded.Hash,
Ada.Text_IO;
package HAC_Sys.Builder is
package String_Maps is new Ada.Containers.Hashed_Maps
(Key_Type => HAT.VString,
Element_Type => HAT.VString,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => HAT."=",
"=" => HAT."=");
type Build_Data is new Ada.Finalization.Limited_Controlled with record
CD : Co_Defs.Compiler_Data_Access := new Co_Defs.Compiler_Data;
LD : Librarian.Library_Data;
global_VM_variables : String_Maps.Map;
global_remarks : Defs.Remark_Set := Defs.default_remarks;
main_name_hint : HAT.VString; -- This is used for circular unit dependency detection
asm_dump : Boolean := False; -- Assembler output of compiled object code
cmp_dump_file_name : HAT.VString; -- Compiler dump
listing_file_name : HAT.VString; -- Listing of source code with details
var_map_file_name : HAT.VString; -- Output of variables (map)
target : Targets.Abstract_Machine_Reference := null; -- Always heap-allocated!
end record;
overriding procedure Finalize (BD : in out Build_Data);
-- Build the main procedure.
-- The main procedure's source code stream is already
-- available via Set_Main_Source_Stream.
-- If the stream stems from a file, the file must be already open and won't be closed.
-- Build_Main takes care of all other needed compilations around main as well.
--
procedure Build_Main (BD : in out Build_Data);
procedure Build_Main_from_File (BD : in out Build_Data; File_Name : String);
procedure Set_Diagnostic_Parameters
(BD : in out Build_Data;
asm_dump : Boolean := False; -- Assembler output of compiled object code
cmp_dump_file_name : String := ""; -- Compiler dump
listing_file_name : String := ""; -- Listing of source code with details
var_map_file_name : String := ""); -- Output of variables (map)
procedure Set_Remark_Set
(BD : in out Build_Data;
set : in Defs.Remark_Set);
-- Set current main source stream (file, editor data, zipped file,...)
procedure Set_Main_Source_Stream (
BD : in out Build_Data;
s : access Ada.Streams.Root_Stream_Type'Class;
file_name : in String; -- Can be a virtual name (editor title, zip entry)
start_line : in Natural := 0 -- We could have a shebang or other Ada sources before
);
procedure Set_Message_Feedbacks (
BD : in out Build_Data;
trace_params : in Co_Defs.Compilation_Trace_Parameters
);
procedure Set_Target
(BD : in out Build_Data;
new_target : Targets.Abstract_Machine_Reference);
function Build_Successful (BD : Build_Data) return Boolean;
function Total_Compiled_Lines (BD : Build_Data) return Natural;
function Object_Code_Size (BD : Build_Data) return Natural;
function Folded_Instructions (BD : Build_Data) return Natural;
function Specialized_Instructions (BD : Build_Data) return Natural;
function Maximum_Object_Code_Size return Natural;
-------------------------
-- Various utilities --
-------------------------
-- Skip an possible "shebang", e.g.: #!/usr/bin/env hac, in a text file.
-- The Ada source begins from next line.
--
procedure Skip_Shebang (f : in out Ada.Text_IO.File_Type; shebang_offset : out Natural);
end HAC_Sys.Builder;
|