88import stat
99import collections
1010
11- from BE .Base import cfg
1211from BE .Base import ir
1312from IR import opcode_tab as o
14- from BE .Base import sanity
1513from BE .Base import serialize
1614
1715from BE .CpuA64 import opcode_tab as a64
2624from BE .Elf import elf_unit
2725
2826
29- def LegalizeAll (unit , opt_stats , fout , verbose = False ):
30- seeds = [f for f in [unit .fun_syms .get ("_start" ),
31- unit .fun_syms .get ("main" )] if f ]
32- if seeds :
33- cfg .UnitRemoveUnreachableCode (unit , seeds )
34- for fun in unit .funs :
35- sanity .FunCheck (fun , unit , check_cfg = False ,
36- check_push_pop = True , check_fallthroughs = False )
37-
38- if fun .kind is o .FUN_KIND .NORMAL :
39- legalize .PhaseOptimize (fun , unit , opt_stats , fout )
40-
41- for fun in unit .funs :
42- legalize .PhaseLegalizationStep1 (fun , unit , opt_stats , fout )
43-
44- for fun in unit .funs :
45- legalize .PhaseLegalizationStep2 (fun , unit , opt_stats , fout )
46-
47-
48- def RegAllocGlobal (unit , opt_stats , fout , verbose = False ):
49- for fun in unit .funs :
50- sanity .FunCheck (fun , unit , check_cfg = False ,
51- check_push_pop = False , check_fallthroughs = False )
52- legalize .PhaseGlobalRegAlloc (fun , opt_stats , fout )
53- if verbose :
54- legalize .DumpFun ("after global_reg_alloc" , fun )
55-
56-
57- def RegAllocLocal (unit , opt_stats , fout , verbose = False ):
58- for fun in unit .funs :
59- legalize .PhaseFinalizeStackAndLocalRegAlloc (fun , opt_stats , fout )
60- if verbose :
61- legalize .DumpFun ("after stack finalization" , fun )
62-
63-
6427############################################################
6528# textual emitter
6629############################################################
@@ -294,9 +257,9 @@ def main():
294257 if args .mode == "binary" :
295258 # we need to legalize all functions first as this may change the signature
296259 # and fills in cpu reg usage which is used by subsequent interprocedural opts.
297- LegalizeAll (unit , opt_stats , None )
298- RegAllocGlobal (unit , opt_stats , None )
299- RegAllocLocal (unit , opt_stats , None )
260+ legalize . LegalizeAll (unit , opt_stats , None )
261+ legalize . RegAllocGlobal (unit , opt_stats , None )
262+ legalize . RegAllocLocal (unit , opt_stats , None )
300263 armunit = EmitUnitAsBinary (unit )
301264 exe = assembler .Assemble (armunit , True )
302265 exe .save (open (args .output , "wb" ))
@@ -307,17 +270,17 @@ def main():
307270
308271 # we need to legalize all functions first as this may change the signature
309272 # and fills in cpu reg usage which is used by subsequent interprocedural opts.
310- LegalizeAll (unit , opt_stats , fout )
273+ legalize . LegalizeAll (unit , opt_stats , fout )
311274 if args .mode == "legalize" :
312275 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
313276 return
314277
315- RegAllocGlobal (unit , opt_stats , fout )
278+ legalize . RegAllocGlobal (unit , opt_stats , fout )
316279 if args .mode == "reg_alloc_global" :
317280 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
318281 return
319282
320- RegAllocLocal (unit , opt_stats , fout )
283+ legalize . RegAllocLocal (unit , opt_stats , fout )
321284 if args .mode == "reg_alloc_local" :
322285 print ("\n " .join (serialize .UnitRenderToASM (unit )), file = fout )
323286 return
0 commit comments