|
|
@ -69,6 +69,7 @@ class ParseContext:
|
|
|
|
def _finalize_section(self):
|
|
|
|
def _finalize_section(self):
|
|
|
|
if self.section is None:
|
|
|
|
if self.section is None:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if self.section.type == MemorySectionType.Data:
|
|
|
|
if self.section.type == MemorySectionType.Data:
|
|
|
|
section = BinaryDataMemorySection(
|
|
|
|
section = BinaryDataMemorySection(
|
|
|
|
self.section.data, self.section.name, self.context, self.program.name, self.section.base
|
|
|
|
self.section.data, self.section.name, self.context, self.program.name, self.section.base
|
|
|
@ -79,12 +80,12 @@ class ParseContext:
|
|
|
|
self.section.data, self.section.name, self.context, self.program.name, self.section.base
|
|
|
|
self.section.data, self.section.name, self.context, self.program.name, self.section.base
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.program.add_section(section)
|
|
|
|
self.program.add_section(section)
|
|
|
|
|
|
|
|
|
|
|
|
self.section = None
|
|
|
|
self.section = None
|
|
|
|
|
|
|
|
|
|
|
|
def new_section(self, name: str, type: MemorySectionType, alignment: int = 4):
|
|
|
|
def new_section(self, name: str, type: MemorySectionType, alignment: int = 4):
|
|
|
|
base = 0
|
|
|
|
base = align_addr(self.current_address(), alignment)
|
|
|
|
if self.section is not None:
|
|
|
|
|
|
|
|
base = align_addr(self.section.current_address(), alignment)
|
|
|
|
|
|
|
|
self._finalize_section()
|
|
|
|
self._finalize_section()
|
|
|
|
self.section = CurrentSection(name, type, base)
|
|
|
|
self.section = CurrentSection(name, type, base)
|
|
|
|
|
|
|
|
|
|
|
@ -95,6 +96,11 @@ class ParseContext:
|
|
|
|
if is_relative:
|
|
|
|
if is_relative:
|
|
|
|
self.program.relative_labels.add(name)
|
|
|
|
self.program.relative_labels.add(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def current_address(self):
|
|
|
|
|
|
|
|
if self.section:
|
|
|
|
|
|
|
|
return self.section.current_address()
|
|
|
|
|
|
|
|
return self.program.base if self.program.base is not None else 0
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
def __repr__(self):
|
|
|
|
return "{}(\n\tsetion={},\n\tprogram={}\n)".format(
|
|
|
|
return "{}(\n\tsetion={},\n\tprogram={}\n)".format(
|
|
|
|
self.__class__.__name__, self.section, self.program
|
|
|
|
self.__class__.__name__, self.section, self.program
|
|
|
@ -123,7 +129,7 @@ class AssemblerDirectives:
|
|
|
|
ASSERT_LEN(args, 1)
|
|
|
|
ASSERT_LEN(args, 1)
|
|
|
|
ASSERT_IN_SECTION_TYPE(context, MemorySectionType.Data)
|
|
|
|
ASSERT_IN_SECTION_TYPE(context, MemorySectionType.Data)
|
|
|
|
align_to = parse_numeric_argument(args[0])
|
|
|
|
align_to = parse_numeric_argument(args[0])
|
|
|
|
current_mod = context.section.current_address() % align_to
|
|
|
|
current_mod = context.current_address() % align_to
|
|
|
|
if current_mod == 0:
|
|
|
|
if current_mod == 0:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
context.section.data += bytearray(align_to - current_mod)
|
|
|
|
context.section.data += bytearray(align_to - current_mod)
|
|
|
|