Mercurial > lcfOS
changeset 240:6259856841a0
Remove project
author | Windel Bouwman |
---|---|
date | Mon, 22 Jul 2013 22:37:33 +0200 |
parents | 63bb40758066 |
children | ce6d390043a7 |
files | python/codegenarm.py python/hexfile.py python/ide.py python/project.py python/pyyacc.py python/st-util.py python/testcg.py python/transform.py |
diffstat | 8 files changed, 107 insertions(+), 118 deletions(-) [+] |
line wrap: on
line diff
--- a/python/codegenarm.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/codegenarm.py Mon Jul 22 22:37:33 2013 +0200 @@ -34,6 +34,7 @@ self.emit(Label('reset')) for f in ircode.Functions: + self.localVars = [] # Add global variable addresses to immediate list: for gvar in ircode.Variables: pass #self.imms.append(( @@ -87,18 +88,27 @@ self.imms.append((lname, ins.value)) self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.target)))) elif type(ins) is ir.Store: + print('STORE', ins, self.localVars) # Load value in r0: self.loadStack(arm.r0, ins.value) # store in memory: # TODO: split globals and locals?? #self.getGlobal(arm.r1, ins.location) - self.loadStack(arm.r1, ins.location) - self.emit(arm.storeimm5_ins(arm.r0, arm.MemR8Rel(arm.r1, 0))) + # Horrible hack with localVars + if ins.location in self.localVars: + print('local', ins.location) + self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.getStack(ins.location)))) + else: + self.loadStack(arm.r1, ins.location) + self.emit(arm.storeimm5_ins(arm.r0, arm.MemR8Rel(arm.r1, 0))) elif type(ins) is ir.Load: # TODO: differ global and local?? #self.getGlobal(arm.r0, ins.location) - self.loadStack(arm.r0, ins.location) - self.emit(arm.loadimm5_ins(arm.r0, arm.MemR8Rel(arm.r0, 0))) + if ins.location in self.localVars: + self.emit(arm.ldr_sprel(arm.r0, arm.MemSpRel(self.getStack(ins.location)))) + else: + self.loadStack(arm.r0, ins.location) + self.emit(arm.loadimm5_ins(arm.r0, arm.MemR8Rel(arm.r0, 0))) # Store value on stack: self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.value)))) elif type(ins) is ir.BinaryOperator: @@ -132,6 +142,8 @@ elif type(ins) is ir.Alloc: # Local variables are added to stack self.addStack(ins.value) + self.localVars.append(ins.value) + # load address into variable: else: raise NotImplementedError('IR "{}" not covered'.format(ins))
--- a/python/hexfile.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/hexfile.py Mon Jul 22 22:37:33 2013 +0200 @@ -21,9 +21,9 @@ class HexFile: """ Represents an intel hexfile """ - def __init__(self, filename=None): - self.regions = [] - self.startAddress = 0 + def __init__(self): + self.regions = [] + self.startAddress = 0 def load(self, f): endOfFile = False
--- a/python/ide.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/ide.py Mon Jul 22 22:37:33 2013 +0200 @@ -7,7 +7,6 @@ from PyQt4.QtGui import * # Compiler imports: -from project import Project import ppci from astviewer import AstViewer #from codeeditor import CodeEdit @@ -158,6 +157,7 @@ self.addToolBar(self.ctrlToolbar) self.ctrlToolbar.setObjectName('debugToolbar') self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice) + self.ctrlToolbar.statusChange.connect(self.memview.refresh) self.devxplr.deviceSelected.connect(self.memview.setDevice) self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice) self.ctrlToolbar.statusChange.connect(self.regview.refresh) @@ -173,12 +173,6 @@ if shortcut: a.setShortcut(shortcut) - addMenuEntry("New", self.projectMenu, self.newProject) - addMenuEntry("Open", self.projectMenu, self.openProject) - addMenuEntry("Save", self.projectMenu, self.saveProject) - addMenuEntry("Close", self.projectMenu, self.closeProject) - addMenuEntry("Build", self.projectMenu, self.buildProject, shortcut=QKeySequence('F7')) - addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) @@ -205,14 +199,6 @@ self.c3front = c3.Builder(self.diag) # File handling: - def newProject(self): - filename = QFileDialog.getSaveFileName(self, \ - "Select new projectfile", "", "lcfos Project files (*.lcp2)") - if filename: - self.project = Project() - self.project.filename = filename - self.project.save() - def newFile(self): ce = CodeEdit() ce.textChanged.connect(self.buildProject) @@ -363,8 +349,8 @@ self.buildOutput.append("Done!") if __name__ == '__main__': - app = QApplication(sys.argv) - ide = Ide() - ide.show() - app.exec_() + app = QApplication(sys.argv) + ide = Ide() + ide.show() + app.exec_()
--- a/python/project.py Mon Jul 22 17:57:25 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -""" - source project - contains: - - modules - - primitives like functions, types and variables - - other modules -""" - -import json - -class Project: - def __init__(self, filename=None): - self.name = "" - self.modules = [] - self.elements = [] - self.settings = {} - if filename: - self.load(filename) - - def load(self, filename): - """ Load the project from file """ - self.filename = filename - - with open(self.filename, 'r') as f: - d = json.load(f) - self.elements = d['elements'] - - def save(self): - if self.filename: - d = {'elements': self.elements} - print(d) - with open(self.filename, 'w') as f: - json.dump(d, f) -
--- a/python/pyyacc.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/pyyacc.py Mon Jul 22 22:37:33 2013 +0200 @@ -2,7 +2,6 @@ Parser generator script """ -import shelve import hashlib from ppci import Token @@ -170,17 +169,7 @@ def genParser(self): """ Generates a parser from the grammar (using a caching algorithm) """ signature = self.getSignature() - cache = shelve.open('__grammar_cache__.shelve') - # TODO: fix caching. - if ('signature1' in cache) and cache['signature'] == signature: - goto_table = cache['goto_table'] - action_table = cache['action_table'] - else: - action_table, goto_table = self.doGenerate() - cache['goto_table'] = goto_table - cache['action_table'] = action_table - cache['signature'] = signature - cache.close() + action_table, goto_table = self.doGenerate() p = LRParser(action_table, goto_table, self.start_symbol) p.grammar = self return p
--- a/python/st-util.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/st-util.py Mon Jul 22 22:37:33 2013 +0200 @@ -79,8 +79,8 @@ self.mdl.refresh() class MemoryView(QWidget): - BlockSize = 0x100 - def __init__(self): + BlockSize = 0x100 + def __init__(self): super().__init__() l = QVBoxLayout(self) l2 = QHBoxLayout() @@ -99,27 +99,32 @@ self.hexEdit = HexEdit() self.Address = 0x8000000 l.addWidget(self.hexEdit) - self.addressLine.returnPressed.connect(self.doLoad) - def doLoad(self): - txt = self.addressLine.text() - self.loadAddress(int(txt, 16)) - def getAddress(self): - txt = self.addressLine.text() - return int(txt, 16) - def doUp(self): - self.Address -= self.BlockSize - def doDown(self): - self.Address += self.BlockSize - def setAddress(self, address): - if self.device: - data = self.device.iface.read_mem32(address, self.BlockSize) - else: - data = bytearray(self.BlockSize) - self.hexEdit.bv.Data = data - self.hexEdit.bv.Offset = address - self.addressLine.setText('{0:08X}'.format(address)) - Address = property(getAddress, setAddress) - def setDevice(self, dev): + self.addressLine.returnPressed.connect(self.refresh) + + def refresh(self): + address = self.Address + if self.device: + data = self.device.iface.read_mem32(address, self.BlockSize) + else: + data = bytearray(self.BlockSize) + self.hexEdit.bv.Data = data + self.hexEdit.bv.Offset = address + + def getAddress(self): + txt = self.addressLine.text() + return int(txt, 16) + + def doUp(self): + self.Address -= self.BlockSize + + def doDown(self): + self.Address += self.BlockSize + + def setAddress(self, address): + self.addressLine.setText('{0:08X}'.format(address)) + self.refresh() + Address = property(getAddress, setAddress) + def setDevice(self, dev): self.device = dev self.Address = 0x8000000
--- a/python/testcg.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/testcg.py Mon Jul 22 22:37:33 2013 +0200 @@ -1,22 +1,43 @@ import unittest import ppci, codegen, ir import cortexm3 as arm +import codegenarm +import outstream + +def genTestFunction(): + m = ir.Module('tst') + f = ir.Function('tst') + m.addFunction(f) + bb = ir.BasicBlock('entry') + f.addBasicBlock(bb) + return m, bb + class testCodeGeneration(unittest.TestCase): def setUp(self): self.cg = codegen.CodeGenerator(arm.armtarget) def testFunction(self): - m = ir.Module('tst') - f = ir.Function('tst') - m.addFunction(f) - bb = ir.BasicBlock('entry') - f.addBasicBlock(bb) + m, bb = genTestFunction() v = ir.Value('tst') bb.addInstruction(ir.ImmLoad(v, 123)) m.check() obj = self.cg.generate(m) self.assertTrue(obj) +class testArmCodeGeneration(unittest.TestCase): + def testStack(self): + s = outstream.OutputStream() + cg = codegenarm.ArmCodeGenerator(s) + m, bb = genTestFunction() + v = ir.Value('tst') + bb.addInstruction(ir.Alloc(v)) + v2 = ir.Value('tst2') + bb.addInstruction(ir.ImmLoad(v2, 22)) + bb.addInstruction(ir.Store(v, v2)) + m.check() + cg.generate(m) + s.dump() + if __name__ == '__main__': - unittest.main() + unittest.main()
--- a/python/transform.py Mon Jul 22 17:57:25 2013 +0200 +++ b/python/transform.py Mon Jul 22 22:37:33 2013 +0200 @@ -1,4 +1,8 @@ -from ir import * +""" + Transformation to optimize IR-code +""" + +from ir import * # Standard passes: class FunctionPass: @@ -13,21 +17,25 @@ def prepare(self): pass + class BasicBlockPass(FunctionPass): - def onFunction(self, f): - for bb in f.BasicBlocks: - self.onBasicBlock(bb) - def onBasicBlock(self, bb): - """ Override this virtual method """ - raise NotImplementedError() - + def onFunction(self, f): + for bb in f.BasicBlocks: + self.onBasicBlock(bb) + + def onBasicBlock(self, bb): + """ Override this virtual method """ + raise NotImplementedError() + + class InstructionPass(BasicBlockPass): - def onBasicBlock(self, bb): - for ins in iter(bb.Instructions): - self.onInstruction(ins) - def onInstruction(self, ins): - """ Override this virtual method """ - raise NotImplementedError() + def onBasicBlock(self, bb): + for ins in iter(bb.Instructions): + self.onInstruction(ins) + + def onInstruction(self, ins): + """ Override this virtual method """ + raise NotImplementedError() # Usefull transforms: class ConstantFolder(InstructionPass): @@ -90,7 +98,8 @@ def onBasicBlock(self, bb): def instructionUsed(ins): if len(ins.defs) == 0: - # In case this instruction does not define any variables, assume it is usefull. + # In case this instruction does not define any + # variables, assume it is usefull. return True for d in ins.defs: if d.IsUsed: @@ -111,13 +120,12 @@ continue # update all references: t_new = constMap[ins.value] - print('Replace {} with {}'.format(t_old, t_new)) for use in t_old.used_by: use.replaceValue(t_old, t_new) bb.removeInstruction(ins) else: constMap[ins.value] = ins.target - + def isAllocPromotable(allocinst): # Check if alloc value is only used by load and store operations. @@ -129,6 +137,7 @@ otherUse = True return True + class CleanPass(FunctionPass): def onFunction(self, f): bbs = list(f.BasicBlocks) @@ -149,6 +158,7 @@ pred.LastInstruction.changeTarget(bb, ins.target) f.removeBasicBlock(bb) + class Mem2RegPromotor(FunctionPass): def onFunction(self, f): # TODO