From: rs <> Date: Fri, 10 Oct 2025 02:05:17 +0000 (-0500) Subject: Add local labels and error on label redefinition X-Git-Url: https://git.the-white-hart.net/?a=commitdiff_plain;h=7e8f7cc262b6bb8d39af92b3dd9fa6d931e9c65e;p=vhdl Add local labels and error on label redefinition --- diff --git a/projects/cpu_0/asm/as.py b/projects/cpu_0/asm/as.py index 88c4a1e..c4d2892 100755 --- a/projects/cpu_0/asm/as.py +++ b/projects/cpu_0/asm/as.py @@ -41,6 +41,7 @@ class Assembler(object): def chomp(self, filename: str, source: str) -> bool: error = False comment = False + scope_label = '' for token, line_no in self.tokenize(source): if comment: if token == ')': @@ -56,14 +57,25 @@ class Assembler(object): elif token.lower() in self.INSTRS: self.flash_section += self.INSTRS[token.lower()] elif '=' in token: - sym, value = token.split('=', maxsplit=1) + label, value = token.split('=', maxsplit=1) value = int(value, 0) - self.syms[sym] = value + if label in self.syms: + print(f'{filename}:{line_no} - "{label}" redefined') + error = True + self.syms[label] = value elif token.endswith(':'): - if token[0] not in '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ': - print(f'{filename}:{line_no} - Invalid label name "{token}"') + label = token[:-1] + if label[0] not in '._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ': + print(f'{filename}:{line_no} - Invalid label name "{label}"') + error = True + if label[0] != '.': + scope_label = label + else: + label = scope_label + label + if label in self.syms: + print(f'{filename}:{line_no} - "{label}" redefined') error = True - self.syms[token[:-1]] = len(self.flash_section) + self.syms[label] = len(self.flash_section) elif token[0] in '-0123456789': if token.endswith('i8'): val = int(token[:-2], 0) @@ -83,7 +95,9 @@ class Assembler(object): else: print(f'{filename}:{line_no} - Number "{token}" must end with "i8" or "i32"') error = True - elif token[0] in '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ': + elif token[0] in '._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ': + if token[0] == '.': + token = scope_label + token if token in self.syms: self.flash_section += struct.pack('