view python/ppci/core/asmwriter.py @ 107:1544e7a4aa98

Improvements
author Windel Bouwman
date Tue, 01 Jan 2013 17:16:05 +0100
parents
children 9e552d34bd60
line wrap: on
line source


from . import llvmtype
#typeNames[VoidType] = 'void'

class AsmWriter:
   def __init__(self):
      self.typeNames = {}
      self.typeNames[llvmtype.typeID.Void] = 'void'
   def printModule(self, module):
      if module.Identifier:
         print('; ModuleID = {0}'.format(module.Identifier))
      # 
      # Print functions:
      for f in module.Functions:
         self.printFunction(f)
   def printFunction(self, f):
      # TODO: if definition:

      t = self.strType(f.ReturnType.tid)
      args = '()'
      print('define {0} {1}{2}'.format(t, f.name, args))
      print('{')

      for bb in f.BasicBlocks:
         print(bb)

      print('}')

   def strType(self, t):
      return self.typeNames[t]
      
   def printBasicBlock(self, bb):
      if bb.Name:
         # print label
         print('{0}:'.format(bb.Name))
      for instr in bb.Instructions:
         self.printInstruction(instr)
   def printInstruction(self, i):
      pass