Skip to content

Commit

Permalink
Merge pull request #54 from cdm-processors/fix-templates
Browse files Browse the repository at this point in the history
Fix templates
  • Loading branch information
Intelix8996 authored Jan 28, 2024
2 parents e0a465c + 986d3b3 commit 67241ee
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cocas/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, sn: TemplateSectionNode, code_segments: Type[CodeSegmentsInte

elif isinstance(line, InstructionNode):
if line.mnemonic not in target_instructions.assembly_directives():
raise Exception('Only "dc" and "ds" allowed in templates')
raise Exception('Only these directives allowed in templates: ' +
', '.join(target_instructions.assembly_directives()))
for seg in target_instructions.assemble_instruction(line, temp_storage):
size += seg.size

Expand Down
4 changes: 2 additions & 2 deletions cocas/targets/cdm16/target_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,5 @@ class Handler:
]

@staticmethod
def assembly_directives() -> set[str]:
return super().assembly_directives()
def assembly_directives():
return {'ds', 'dc', 'db', 'dw'}
4 changes: 4 additions & 0 deletions cocas/targets/cdm8/target_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,7 @@ class Handler:
'ldi': 0xD0
})
]

@staticmethod
def assembly_directives():
return {'ds', 'dc'}
44 changes: 44 additions & 0 deletions tests/resources/cdm16/input/template.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
asect 0
main: ext # Declare labels
default_handler: ext # as external

# Interrupt vector table (IVT)
# Place a vector to program start and
# map all internal exceptions to default_handler
dc main, 0 # Startup/Reset vector
dc default_handler, 0 # Unaligned SP
dc default_handler, 0 # Unaligned PC
dc default_handler, 0 # Invalid instruction
dc default_handler, 0 # Double fault
align 0x80 # Reserve space for the rest
# of IVT

# Exception handlers section
rsect exc_handlers

# This handler halts processor
default_handler>
halt

# Templates
tplate foo
a: ds 7
b: dc "abcd"
c: db 10
d: dw 20
e: ds 984
f: dc 30


# Main program section
rsect main
main>
ldi r0, foo.a
ldi r1, foo.b
ldi r2, foo.c
ldi r3, foo.d
ldi r4, foo.e
ldi r5, foo.f
ldi r6, foo._

end
8 changes: 8 additions & 0 deletions tests/resources/cdm16/output/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
registers:
r0: 0
r1: 7
r2: 11
r3: 12
r4: 14
r5: 998
r6: 1000

0 comments on commit 67241ee

Please sign in to comment.