6 private var cfg_sanity_verified
= false
9 private fun verify_cfg_sanity_code
(v
: Noter, data_in_code
: Array[ALine])
11 for line
in lines
do if line
isa ADirectiveLine then
12 data_in_code
.add
(line
)
15 cfg_sanity_verified
= true
18 # reports code in data
19 private fun verify_cfg_sanity_data
(v
: Noter, dead_lines
: Array[ALine])
21 for line
in lines
do if line
isa AInstructionLine then
25 cfg_sanity_verified
= true
29 redef class AnalysisManager
30 fun verify_cfg_sanity
(cfg
: CFG)
32 # verify executable code
33 var executed_data
= new Array[ALine]
34 verify_cfg_sanity_recursively_code
( cfg
.start
, executed_data
)
36 # verify data or dead code
37 var dead_code
= new Array[ALine]
38 for b
in cfg
.blocks
do if not b
.cfg_sanity_verified
then
39 b
.verify_cfg_sanity_data
(self, dead_code
)
42 group
( dead_code
, "unreachable instructions (dead code?)", false )
43 group
( executed_data
, "data in program flow (missing BR?)", true )
46 fun verify_cfg_sanity_recursively_code
(b
: BasicBlock, executed_data
: Array[ALine])
48 if b
.cfg_sanity_verified
then return # is code
50 b
.verify_cfg_sanity_code
(self,executed_data
)
51 for s
in b
.successors
do verify_cfg_sanity_recursively_code
( s
, executed_data
)
54 private fun group
(lines
: Array[ALine], msg
: String, error
: Bool)
56 lines
= lines
.iterator
.sort
.to_a
57 var len
= lines
.length
58 var first
: nullable ALine = null
64 if i
== len-1
or line
.address
+ line
.size
!= lines
[i
+1].address
then
67 manager
.notes
.add
(new Error(first
.location
, msg
))
69 manager
.notes
.add
(new Error.range
(first
.location
, line
.location
, msg
))
73 manager
.notes
.add
(new Error(first
.location
, msg
))
75 manager
.notes
.add
(new Warn.range
(first
.location
, line
.location
, msg
))
86 redef type OTHER: ALine
87 redef fun <=>(o
) do return address
<=> o
.address