comparison python/x86.py @ 160:10330be89bc2

Started from scratch with code edit
author Windel Bouwman
date Sat, 09 Mar 2013 11:56:48 +0100
parents 9683a4cd848f
children 3eb9b9e2958d
comparison
equal deleted inserted replaced
159:5e1dd04cb61c 160:10330be89bc2
16 return '{0} {1}, {2}'.format(self.op, self.a, self.b) 16 return '{0} {1}, {2}'.format(self.op, self.a, self.b)
17 17
18 class X86CodeGen: 18 class X86CodeGen:
19 def __init__(self, diag): 19 def __init__(self, diag):
20 self.diag = diag 20 self.diag = diag
21 self.regs = ['rax', 'rbx', 'rcx', 'rdx']
21 22
22 def emit(self, i): 23 def emit(self, i):
23 self.asm.append(i) 24 self.asm.append(i)
25 def allocateReg(self, typ):
26 return 'ax'
27 def deallocateReg(self, r):
28 pass
24 29
25 def genBin(self, i): 30 def genBin(self, i):
26 self.asm = [] 31 self.asm = []
27 self.genModule(i) 32 self.genModule(i)
28 33
44 def genIns(self, i): 49 def genIns(self, i):
45 if type(i) is ir.BinaryOperator: 50 if type(i) is ir.BinaryOperator:
46 if i.operation == 'fadd': 51 if i.operation == 'fadd':
47 r = 'rax' 52 r = 'rax'
48 self.emit(Op('add', r, '11')) 53 self.emit(Op('add', r, '11'))
54 elif type(i) is ir.LoadInstruction:
55 r = 'rbx'
56 self.emit(Op('mov', r, '{0}'.format(i.value)))
49 elif type(i) is ir.RetInstruction: 57 elif type(i) is ir.RetInstruction:
50 self.emit('ret') 58 self.emit('ret')
59 elif type(i) is ir.CallInstruction:
60 self.emit('call')
51 else: 61 else:
52 print('Unknown ins', i) 62 print('Unknown ins', i)
53 63