Mercurial > lcfOS
comparison python/ir/module.py @ 205:d77cb5962cc5
Added some handcoded arm code generation
author | Windel Bouwman |
---|---|
date | Sun, 23 Jun 2013 18:23:18 +0200 |
parents | 460db5669efa |
children | 88a1e0baef65 |
comparison
equal
deleted
inserted
replaced
204:de3a68f677a5 | 205:d77cb5962cc5 |
---|---|
5 class Module: | 5 class Module: |
6 """ Main container for a piece of code. """ | 6 """ Main container for a piece of code. """ |
7 def __init__(self, name): | 7 def __init__(self, name): |
8 self.name = name | 8 self.name = name |
9 self.funcs = [] | 9 self.funcs = [] |
10 self.variables = [] | |
11 | |
10 def __repr__(self): | 12 def __repr__(self): |
11 return 'IR-module [{0}]'.format(self.name) | 13 return 'IR-module [{0}]'.format(self.name) |
14 | |
12 def getInstructions(self): | 15 def getInstructions(self): |
13 ins = [] | 16 ins = [] |
14 for bb in self.BasicBlocks: | 17 for bb in self.BasicBlocks: |
15 ins += bb.Instructions | 18 ins += bb.Instructions |
16 return ins | 19 return ins |
17 Instructions = property(getInstructions) | 20 Instructions = property(getInstructions) |
21 | |
18 def getBBs(self): | 22 def getBBs(self): |
19 bbs = [] | 23 bbs = [] |
20 for f in self.Functions: | 24 for f in self.Functions: |
21 bbs += f.BasicBlocks | 25 bbs += f.BasicBlocks |
22 return bbs | 26 return bbs |
27 | |
23 BasicBlocks = property(getBBs) | 28 BasicBlocks = property(getBBs) |
24 def addFunc(self, f): | 29 def addFunc(self, f): |
25 self.funcs.append(f) | 30 self.funcs.append(f) |
26 def getFuncs(self): | 31 addFunction = addFunc |
32 | |
33 def addVariable(self, v): | |
34 self.variables.append(v) | |
35 | |
36 def getVariables(self): | |
37 return self.variables | |
38 Variables = property(getVariables) | |
39 | |
40 def getFunctions(self): | |
27 return self.funcs | 41 return self.funcs |
28 Functions = property(getFuncs) | 42 Functions = property(getFunctions) |
43 | |
29 def dump(self): | 44 def dump(self): |
30 print(self) | 45 print(self) |
46 for v in self.Variables: | |
47 print(' ', v) | |
31 for fn in self.Functions: | 48 for fn in self.Functions: |
32 print(fn) | 49 print(fn) |
33 for bb in fn.BasicBlocks: | 50 for bb in fn.BasicBlocks: |
34 print(' ', bb) | 51 print(' ', bb) |
35 for ins in bb.Instructions: | 52 for ins in bb.Instructions: |
36 print(' ', ins) | 53 print(' ', ins) |
37 print('END') | 54 |
38 def dumpgv(self, outf): | 55 def dumpgv(self, outf): |
39 outf.write('digraph G \n{\n') | 56 outf.write('digraph G \n{\n') |
40 for f in self.Functions: | 57 for f in self.Functions: |
41 outf.write('{0} [label="{1}" shape=box3d]\n'.format(id(f), f)) | 58 outf.write('{0} [label="{1}" shape=box3d]\n'.format(id(f), f)) |
42 for bb in f.BasicBlocks: | 59 for bb in f.BasicBlocks: |