Merge pull request #27 from yenatch/master

spit GLOBAL defs for labels into globals.asm instead of inline
This commit is contained in:
Bryan Bishop 2013-09-11 17:38:53 -07:00
commit 0ce2555a19

View File

@ -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: