changeset 243:ef683881c64e

Remove various files
author Windel Bouwman
date Tue, 23 Jul 2013 16:50:02 +0200
parents c94965418684
children 58155c7c4a8e
files python/bouncing_cube.py python/codegenarm.py python/elffile.py python/ir/basicblock.py python/ir/builder.py python/readelf.py python/runtests.py python/testc3.py python/testcg.py python/testir.py
diffstat 10 files changed, 19 insertions(+), 305 deletions(-) [+]
line wrap: on
line diff
--- a/python/bouncing_cube.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/bouncing_cube.py	Tue Jul 23 16:50:02 2013 +0200
@@ -298,7 +298,7 @@
       state = newstate
 
       t += dt
-      print state[6,0], t, ' ', (t/endtime)*100.0, '%'
+      print(state[6,0], t, ' ', (t/endtime)*100.0, '%')
     return states
   
 
@@ -394,11 +394,11 @@
 
 et = 20.0
 dt = 0.04
-print 'starting integration... endtime =', et, ' stepsize =', dt
+print('starting integration... endtime =', et, ' stepsize =', dt)
 t0 = time.time()
 states = simulate(et, dt)
 t1 = time.time()
-print 'That was heavy, it took me ', t1-t0, ' seconds!'
+print('That was heavy, it took me ', t1-t0, ' seconds!')
 app = QApplication(sys.argv)
 w = W(states, dt)
 w.show()
--- a/python/codegenarm.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/codegenarm.py	Tue Jul 23 16:50:02 2013 +0200
@@ -88,7 +88,6 @@
             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:
@@ -96,7 +95,7 @@
             #self.getGlobal(arm.r1, ins.location)
             # Horrible hack with localVars
             if ins.location in self.localVars:
-                print('local', ins.location)
+                # The value was alloc'ed
                 self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.getStack(ins.location))))
             else:
                 self.loadStack(arm.r1, ins.location)
--- a/python/elffile.py	Mon Jul 22 22:56:51 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-import struct
-import collections
-
-class ElfFile:
-   def __init__(self, f):
-      self.f = f
-      self.parse()
-   def parse(self):
-      self.parseHeader()
-   @property
-   def ElfClass(self):
-      return classes[self.ei_class]
-   def parseHeader(self):
-      # Parse identifier
-      e_ident = self.f.read(16)
-      ELFMAGIC = bytes([0x7f]) + b'ELF'
-      assert e_ident[0:4] == ELFMAGIC
-      self.ei_class = e_ident[4]
-      # Change the class of this object in some strange way:
-      self.__class__ = classes[self.ei_class] 
-      print('ELF class: ', self.ElfClass)
-      assert self.ei_class in classes.keys()
-      self.ei_data = e_ident[5]
-      print('ei_data:', self.ei_data)
-      ei_version = e_ident[6]
-      assert ei_version == 1
-
-      # rest of the ELF header:
-      e_type = self.readHalf()
-      e_machine = self.readHalf()
-      e_version = self.readWord()
-      e_entry = self.readAddr()
-      self.e_phoff = self.readOff()
-      self.e_shoff = self.readOff()
-      self.e_flags = self.readWord()
-      e_ehsize = self.readHalf()
-      self.e_phentsize = self.readHalf()
-      self.e_phnum = self.readHalf()
-      self.e_shentsize = self.readHalf()
-      self.e_shnum = self.readHalf()
-      self.e_shstrndx = self.readHalf()
-      
-      assert e_ehsize == self.HEADERSIZE
-      print('program header size', self.e_phentsize, self.e_phnum)
-      print('section header size', self.e_shentsize, self.e_shnum)
-      print('string index:', self.e_shstrndx)
-   def readFmt(self, fmt):
-      size = struct.calcsize(fmt)
-      return struct.unpack(fmt, self.f.read(size))
-   def readHalf(self):
-      return self.readFmt('<H')[0]
-   def readWord(self):
-      return self.readFmt('<I')[0]
-   def parsePrograms(self):
-      # Skip to start of program headers:
-      self.f.seek(self.e_phoff)
-      pheaders = []
-      for i in range(self.e_phnum):
-         pheaders.append(self.parseProgramHeader())
-      return pheaders
-
-ProgramHeader = collections.namedtuple('ProgramHeader', ['p_type', 
-   'p_flags', 'p_offset', 'p_vaddr', 'p_paddr', 'p_filesz', 'p_memsz'])
-      
-class Elf32File(ElfFile):
-   HEADERSIZE=52
-   def readAddr(self):
-      return self.readFmt('<I')[0]
-   readOff = readAddr
-   def parseProgramHeader(self):
-      p_type = self.readWord()
-      p_offset = self.readOff()
-      p_vaddr = self.readAddr()
-      p_paddr = self.readAddr()
-      p_filesz = self.readWord()
-      p_memsz = self.readWord()
-      p_flags = self.readWord()
-      p_align = self.readWord()
-      return ProgramHeader(p_type, p_flags, p_offset, p_vaddr, p_paddr, p_filesz, p_memsz)
-      
-class Elf64File(ElfFile):
-   HEADERSIZE=64
-   def readAddr(self):
-      return self.readFmt('<Q')[0]
-   readOff = readAddr
-   readXword = readAddr
-   def parseProgramHeader(self):
-      p_type = self.readWord()
-      p_flags = self.readWord()
-      p_offset = self.readOff()
-      p_vaddr = self.readAddr()
-      p_paddr = self.readAddr()
-      p_filesz = self.readXword()
-      p_memsz = self.readXword()
-      p_align = self.readXword()
-      return ProgramHeader(p_type, p_flags, p_offset, p_vaddr, p_paddr)
-
-classes = {1:Elf32File, 2:Elf64File}
-
--- a/python/ir/basicblock.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/ir/basicblock.py	Tue Jul 23 16:50:02 2013 +0200
@@ -11,7 +11,6 @@
     def addInstruction(self, i):
         i.parent = self
         self.instructions.append(i)
-    addIns = addInstruction
 
     def replaceInstruction(self, i1, i2):
         idx = self.instructions.index(i1)
@@ -26,14 +25,7 @@
 
     def getInstructions(self):
         return self.instructions
-
-    def setInstructions(self, ins):
-      for i in self.instructions:
-         i.parent = None
-      self.instructions = ins
-      for i in self.instructions:
-         i.parent = self
-    Instructions = property(getInstructions, setInstructions)
+    Instructions = property(getInstructions)
 
     def getLastIns(self):
         return self.instructions[-1]
@@ -46,13 +38,12 @@
     @property
     def FirstInstruction(self):
         return self.instructions[0]
-    FirstIns = FirstInstruction
 
     def getSuccessors(self):
-      if not self.Empty:
-         i = self.LastInstruction
-         return i.Targets
-      return []
+        if not self.Empty:
+            i = self.LastInstruction
+            return i.Targets
+        return []
     Successors = property(getSuccessors)
 
     def getPredecessors(self):
--- a/python/ir/builder.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/ir/builder.py	Tue Jul 23 16:50:02 2013 +0200
@@ -64,5 +64,5 @@
    def addIns(self, i):
       if not self.bb:
             raise Exception('No basic block')
-      self.bb.addIns(i)
+      self.bb.addInstruction(i)
 
--- a/python/readelf.py	Mon Jul 22 22:56:51 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-
-import elffile, argparse
-
-parser = argparse.ArgumentParser()
-parser.add_argument('file', type=argparse.FileType('rb'))
-parser.add_argument('-l', action='store_const', const=True, default=False, dest='list_program_headers')
-
-args = parser.parse_args()
-print(args)
-ef = elffile.ElfFile(args.file)
-print(ef)
-
-if args.list_program_headers:
-   print('program headers')
-   phs = ef.parsePrograms()
-   print(phs)
-   for ph in phs:
-      print('type=0x{0:X} vaddr=0x{1:X} filesz=0x{2:X}'.format(ph.p_type, ph.p_vaddr, ph.p_filesz))
-
--- a/python/runtests.py	Mon Jul 22 22:56:51 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-#!/usr/bin/python
-
-import unittest
-import os
-
-from compiler.compiler import Compiler
-from compiler.errors import CompilerException, printError
-from compiler import lexer
-from compiler.parser import Parser
-from compiler import assembler
-from compiler.codegenerator import CodeGenerator
-from project import Project
-
-class CompilerTestCase(unittest.TestCase):
-   """ test methods start with 'test*' """
-   def testSource1(self):
-      source = """
-      module lcfos;
-      var  
-        a : integer;
-
-      procedure putchar(num : integer);
-      begin
-      end putchar;
-
-      procedure WriteNum( num: integer);
-        var 
-          d, base :  integer;
-          dgt : integer;
-        begin
-          d := 1;
-          base := 10;
-          while num div d >= base do
-            d := d * base
-          end;
-          while d <> 0 do
-             dgt := num div d;
-             num := num mod d;
-             d   := d div base;
-             putchar(48 + dgt)
-           end
-        end WriteNum;
-
-      begin
-        a := 1;
-        while a < 26
-         do
-           putchar(65+a);
-           a := a * 2
-         end;
-      end lcfos.
-      """
-      pc = Compiler()
-      pc.compilesource(source)
-   def testSource2(self):
-      source = """
-      module lcfos;
-      var  
-        a, b : integer;
-        arr: array 30 of integer;
-        arr2: array 10, 12 of integer;
-        procedure t2*() : integer;
-        begin
-        a := 2;
-        while a < 5 do
-           b := arr[a-1] + arr[a-2];
-           arr2[a,2] := b;
-           arr2[a,3] := arr2[a,2] + arr2[a,2]*3 + b;
-           arr[a] := b;
-           a := a  + 1;
-         end;
-         return b
-        end t2;
-        begin
-         b := 12;
-         arr[0] := 1;
-         arr[1] := 1;
-      end lcfos.
-      """
-      pc = Compiler()
-      mod = pc.compilesource(source)
-   def testSource5(self):
-      source = """
-      module lcfos;
-      procedure WriteLn() : integer;
-        const zzz = 13;
-        var
-          a, b, c: integer;
-        begin
-         a := 2;
-         b := 7;
-         c := 10 * a + b*10*a;
-         return c
-        end WriteLn;
-      begin  end lcfos.
-      """
-      pc = Compiler()
-      pc.compilesource(source)
-   def tstForStatement(self):
-      source = """
-      module fortest;
-      var  
-        a,b,c : integer;
-      begin
-         c := 0;
-         for a := 1 to 10 by 1 do
-            b := a + 15;
-            c := c + b * a;
-         end;
-      end fortest.
-      """
-      pc = Compiler()
-      pc.compilesource(source)
-   def testSourceIfAndWhilePattern(self):
-      source = """
-      module lcfos;
-      procedure WriteLn() : integer;
-        const zzz = 13;
-        var
-          a, b, c: integer;
-        begin
-         a := 1;
-         b := 2;
-         if a * 3 > b then
-            c := 10*a + b*10*a*a*a*b;
-         else
-            c := 13;
-         end;
-         while a < 101 do
-            a := a + 1;
-            c := c + 2;
-         end;
-         return c
-        end WriteLn;
-      begin end lcfos.
-      """
-      pc = Compiler()
-      pc.compilesource(source)
-
-   def testPattern1(self):
-      """ Test if expression can be compiled into byte code """
-      src = "12*13+33-12*2*3"
-      tokens = lexer.tokenize(src)
-      ast = Parser(tokens).parseExpression()
-      code = CodeGenerator().genexprcode(ast)
-
-   def testProject(self):
-      p = Project('test.xml', isnew=True)
-      p.name = "Test project"
-      p.files.append('main.mod')
-      p.files.append('test.mod')
-      p.save('test.xml')
-
-      q = Project('test.xml')
-
-      assert(p.name == q.name)
-      assert(p.files == q.files)
-      # TODO: remove test.xml test file
-      os.remove('test.xml')
-
-if __name__ == '__main__':
-   unittest.main()
-
--- a/python/testc3.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/testc3.py	Tue Jul 23 16:50:02 2013 +0200
@@ -487,6 +487,6 @@
         self.assertEqual(1, len(ircode.Functions))
 
 if __name__ == '__main__':
-   unittest.main()
+    unittest.main()
 
 
--- a/python/testcg.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/testcg.py	Tue Jul 23 16:50:02 2013 +0200
@@ -25,6 +25,7 @@
         obj = self.cg.generate(m)
         self.assertTrue(obj)
 
+
 class testArmCodeGeneration(unittest.TestCase):
     def testStack(self):
         s = outstream.OutputStream()
@@ -37,7 +38,8 @@
         bb.addInstruction(ir.Store(v, v2))
         m.check()
         cg.generate(m)
-        s.dump()
+        #s.dump()
 
 if __name__ == '__main__':
     unittest.main()
+
--- a/python/testir.py	Mon Jul 22 22:56:51 2013 +0200
+++ b/python/testir.py	Tue Jul 23 16:50:02 2013 +0200
@@ -93,10 +93,14 @@
    cgenx86 = x86.X86CodeGenSimple(diag)
    ir = builder.build(testsrc)
    diag.printErrors(testsrc)
-   #ir.dump()
+   ir.dump()
+   ir.check()
    cf = transform.ConstantFolder()
+   ir.check()
    dcd = transform.DeadCodeDeleter()
+   ir.check()
    m2r = transform.Mem2RegPromotor()
+   ir.check()
    clr = transform.CleanPass()
    ir.check()
    cf.run(ir)