From 761799c17ae1b2a2002d7e8163bdfcb00d441200 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Fri, 8 Apr 2022 20:54:40 +0200 Subject: [PATCH] Parser: fixes #13 - implicit start of text section when parsing assembly When an assembly file starts with instructions without explicitly declaring any section beforehand, a .text section will be created implicitly. --- riscemu/parser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riscemu/parser.py b/riscemu/parser.py index eb06dc5..551ddd2 100644 --- a/riscemu/parser.py +++ b/riscemu/parser.py @@ -15,7 +15,9 @@ from .types.exceptions import ParseException def parse_instruction(token: Token, args: Tuple[str], context: ParseContext): - if context.section is None or context.section.type != MemorySectionType.Instructions: + if context.section is None: + context.new_section('.text', MemorySectionType.Instructions) + if context.section.type != MemorySectionType.Instructions: raise ParseException("{} {} encountered in invalid context: {}".format(token, args, context)) ins = SimpleInstruction(token.value, args, context.context, context.section.current_address()) context.section.data.append(ins)