diff options
Diffstat (limited to 'pokemontools/preprocessor.py')
-rw-r--r-- | pokemontools/preprocessor.py | 20 |
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: |