2 | 2 |
from sixtypical.ast import Program, Routine, Block, Instr
|
3 | 3 |
from sixtypical.model import (
|
4 | 4 |
ConstantRef, LocationRef, IndexedRef, IndirectRef, AddressRef,
|
5 | |
TYPE_BIT, TYPE_BYTE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType,
|
|
5 |
TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType,
|
6 | 6 |
REG_A, REG_X, REG_Y, FLAG_C
|
7 | 7 |
)
|
8 | 8 |
from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
|
|
34 | 34 |
assert isinstance(program, Program)
|
35 | 35 |
|
36 | 36 |
for defn in program.defns:
|
37 | |
label = Label(defn.name)
|
38 | |
if defn.addr is not None:
|
39 | |
label.set_addr(defn.addr)
|
40 | |
self.labels[defn.name] = label
|
|
37 |
# compute length of memory pointed to. this is awful.
|
|
38 |
length = None
|
|
39 |
type_ = defn.location.type
|
|
40 |
if type_ == TYPE_BYTE:
|
|
41 |
length = 1
|
|
42 |
elif type_ == TYPE_WORD or isinstance(type_, (PointerType, VectorType)):
|
|
43 |
length = 2
|
|
44 |
elif type_ == TYPE_BYTE_TABLE:
|
|
45 |
length = 256
|
|
46 |
elif type_ == TYPE_WORD_TABLE:
|
|
47 |
length = 512
|
|
48 |
elif isinstance(type_, BufferType):
|
|
49 |
length = type_.size
|
|
50 |
if length is None:
|
|
51 |
raise NotImplementedError("Need size for type {}".format(type_))
|
|
52 |
self.labels[defn.name] = Label(defn.name, addr=defn.addr, length=length)
|
41 | 53 |
|
42 | 54 |
for routine in program.routines:
|
43 | 55 |
self.routines[routine.name] = routine
|
|
59 | 71 |
for defn in program.defns:
|
60 | 72 |
if defn.initial is not None:
|
61 | 73 |
label = self.labels[defn.name]
|
|
74 |
initial_data = Byte(defn.initial) # TODO: support other types than Byte
|
|
75 |
label.set_length(initial_data.size())
|
62 | 76 |
self.emitter.resolve_label(label)
|
63 | |
self.emitter.emit(Byte(defn.initial))
|
|
77 |
self.emitter.emit(initial_data)
|
64 | 78 |
|
65 | 79 |
# uninitialized, "BSS" data
|
66 | 80 |
for defn in program.defns:
|