8 redef class AnalysisManager
9 var model
: nullable Model = null
10 fun build_model
(ast
: AListing): Model
12 var model
= new Model(ast
)
19 # lines to appear on the resulting program
20 var lines
= new Array[ANonEmptyLine]
22 # labet to declaation line
23 var labels_to_line
= new HashMap[String,ALine]
24 var labels_to_address
= new HashMap[String,Int]
27 var address_to_line
= new HashMap[Int,ANonEmptyLine]
32 for line
in ast
.n_lines
do
33 # TODO if directive = equate
34 var label_decl
= line
.n_label_decl
35 if label_decl
!= null then
36 var lbl
= label_decl
.n_id
37 var label_name
= lbl
.text
39 if line
isa ADirectiveLine and line
.n_directive
isa AEquateDirective then
41 labels_to_address
[label_name
] = line
.n_directive
.as(AEquateDirective).n_value
.to_i
42 lbl
.labels_to_address
[label_name
] = line
.n_directive
.as(AEquateDirective).n_value
.to_i
44 labels_to_address
[label_name
] = offset
45 lbl
.labels_to_address
[label_name
] = offset
51 if line
isa ANonEmptyLine and line
.size
> 0 then
53 address_to_line
[offset
] = line
58 for lbl
,address
in labels_to_address
do
59 if address_to_line
.has_key
(address
) then
60 var line
= address_to_line
[address
]
61 labels_to_line
[lbl
] = line
70 fun size
: Int is abstract
72 redef fun to_s
do return "L{address}"
79 return "L{location.to_line_s} (m{address}..{address+size}): {text}"
81 return "L{location.to_line_s}: {text}"
85 fun lbl
: nullable String
87 var lbl_decl
= n_label_decl
88 if lbl_decl
!= null then
89 var lbl
= lbl_decl
.n_id
.text
94 redef class AInstructionLine
95 redef fun size
do return 4
97 redef class ADirectiveLine
98 redef fun size
do return n_directive
.size
100 redef class AEmptyLine
101 redef fun size
do return 0
106 var ltl
= manager
.model
.address_to_line
107 if ltl
.has_key
(index
) then
108 var line
= ltl
[index
]
111 return "{lbl}@m{index}"