summaryrefslogtreecommitdiff
path: root/pokemontools/preprocessor.py
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2013-09-11 03:00:00 -0400
committeryenatch <yenatch@gmail.com>2013-09-11 16:30:38 -0400
commit7bf5fcab90a2861b4a8f5b5c193838ff3470a69f (patch)
tree46b2b4a583431d8dfef336b9229897556b51424f /pokemontools/preprocessor.py
parent4e0f27d789318d32e54e1c2b3e80307757e4f8a1 (diff)
spit GLOBAL defs for labels into globals.asm instead of inline
Diffstat (limited to 'pokemontools/preprocessor.py')
-rw-r--r--pokemontools/preprocessor.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py
index 026da41..0cb7f48 100644
--- a/pokemontools/preprocessor.py
+++ b/pokemontools/preprocessor.py
@@ -3,6 +3,7 @@
Basic preprocessor for both pokecrystal and pokered.
"""
+import os
import sys
import exceptions
@@ -466,6 +467,8 @@ class Preprocessor(object):
self.macros = macros
self.macro_table = make_macro_table(self.macros)
+ self.globes = []
+
def preprocess(self, lines=None):
"""
Run the preprocessor against stdin.
@@ -480,6 +483,19 @@ class Preprocessor(object):
for l in lines:
self.read_line(l)
+ self.update_globals()
+
+ def update_globals(self):
+ """
+ Add any labels not already in globals.asm.
+ """
+ globes = open(os.path.join(self.config.path, 'globals.asm'), 'r+')
+ lines = globes.readlines()
+ for globe in self.globes:
+ line = 'GLOBAL ' + globe + '\n'
+ if line not in lines:
+ globes.write(line)
+
def read_line(self, l):
"""
Preprocesses a given line of asm.
@@ -493,8 +509,8 @@ class Preprocessor(object):
asm, comment = separate_comment(l)
# export all labels
- if ':' in asm[:asm.find('"')] and "macro" not in asm.lower():
- sys.stdout.write('GLOBAL ' + asm.split(':')[0] + '\n')
+ if ':' in asm.split('"')[0] and "macro" not in asm.lower():
+ self.globes += [asm.split(':')[0]]
# expect preprocessed .asm files
if "INCLUDE" in asm: