99import stat
1010import collections
1111
12- from BE .Base import cfg
1312from BE .Base import ir
1413from IR import opcode_tab as o
15- from BE .Base import sanity
1614from BE .Base import serialize
1715
1816from BE .CpuA32 import opcode_tab as a32
2725from BE .Elf import elf_unit
2826
2927
30- def LegalizeAll (unit : ir .Unit , opt_stats , verbose = False ):
31- seeds = [f for f in [unit .fun_syms .get ("_start" ),
32- unit .fun_syms .get ("main" )] if f ]
33- if seeds :
34- cfg .UnitRemoveUnreachableCode (unit , seeds )
35- for fun in unit .funs :
36- sanity .FunCheck (fun , unit , check_cfg = False ,
37- check_push_pop = True , check_fallthroughs = False )
38-
39- if fun .kind is o .FUN_KIND .NORMAL :
40- legalize .PhaseOptimize (fun , unit , opt_stats )
41-
42- for fun in unit .funs :
43- legalize .PhaseLegalization (fun , unit , opt_stats )
44-
4528
46- def RegAllocGlobal (unit : ir .Unit , opt_stats , fout , verbose = False ):
47- for fun in unit .funs :
48- sanity .FunCheck (fun , unit , check_cfg = False ,
49- check_push_pop = False , check_fallthroughs = False )
50- legalize .PhaseGlobalRegAlloc (fun , opt_stats , fout )
51- if verbose :
52- legalize .DumpFun ("after global_reg_alloc" , fun )
53-
54-
55- def RegAllocLocal (unit : ir .Unit , opt_stats , verbose = False ):
56- for fun in unit .funs :
57- legalize .PhaseFinalizeStackAndLocalRegAlloc (fun , opt_stats )
58- if verbose :
59- legalize .DumpFun ("after stack finalization" , fun )
6029
6130
6231############################################################
@@ -272,9 +241,9 @@ def main():
272241 if args .mode == "binary" :
273242 # we need to legalize all functions first as this may change the signature
274243 # and fills in cpu reg usage which is used by subsequent interprocedural opts.
275- LegalizeAll (unit , opt_stats , None )
276- RegAllocGlobal (unit , opt_stats , None )
277- RegAllocLocal (unit , opt_stats , None )
244+ legalize . LegalizeAll (unit , opt_stats , None )
245+ legalize . RegAllocGlobal (unit , opt_stats , None )
246+ legalize . RegAllocLocal (unit , opt_stats , None )
278247 armunit = EmitUnitAsBinary (unit )
279248 exe = assembler .Assemble (armunit , True )
280249 exe .save (open (args .output , "wb" ))
@@ -285,17 +254,17 @@ def main():
285254
286255 # we need to legalize all functions first as this may change the signature
287256 # and fills in cpu reg usage which is used by subsequent interprocedural opts.
288- LegalizeAll (unit , opt_stats )
257+ legalize . LegalizeAll (unit , opt_stats )
289258 if args .mode == "legalize" :
290259 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
291260 return
292261
293- RegAllocGlobal (unit , opt_stats , fout )
262+ legalize . RegAllocGlobal (unit , opt_stats , fout )
294263 if args .mode == "reg_alloc_global" :
295264 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
296265 return
297266
298- RegAllocLocal (unit , opt_stats )
267+ legalize . RegAllocLocal (unit , opt_stats )
299268 if args .mode == "reg_alloc_local" :
300269 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
301270 return
0 commit comments