diff python/outstream.py @ 219:1fa3e0050b49

Expanded ad hoc code generator
author Windel Bouwman
date Sat, 06 Jul 2013 12:38:09 +0200
parents 4cb47d80fd1f
children 1c7364bd74c7
line wrap: on
line diff
--- a/python/outstream.py	Fri Jul 05 15:30:22 2013 +0200
+++ b/python/outstream.py	Sat Jul 06 12:38:09 2013 +0200
@@ -5,12 +5,20 @@
  to a file or binary or hexfile.
 """
 
+class Alignment:
+    def __init__(self, a):
+        self.align = a
+
 class OutputStream:
     def __init__(self):
         self.sections = {}
         self.currentSection = None
     def emit(self, item):
         self.sections[self.currentSection].append(item)
+
+    def align(self, alignment):
+        self.emit(Alignment(alignment))
+        
     def selectSection(self, s):
         self.currentSection = s
         if not s in self.sections:
@@ -30,6 +38,10 @@
                 i.address = address
                 if type(i) is ALabel:
                     continue
+                if type(i) is Alignment:
+                    while (address % i.align) != 0:
+                        address += 1
+                    continue
                 bts = i.encode()
                 address += len(bts)
 
@@ -43,6 +55,8 @@
         for i in self.sections[s]:
             if type(i) is ALabel:
                 print(i)
+            elif type(i) is Alignment:
+                pass
             else:
                 addr = i.address
                 insword = i.encode()