assembler functional
[dcpu16] / as-dcpu16.h
1 #ifndef AS_DCPU16_H_PTFNJB09
2 #define AS_DCPU16_H_PTFNJB09
3
4 #include "dcpu16.h"
5
6 struct instruction_ {
7 char *label; /* set if a label points here */
8 char *opcode; /* tokenized instruction text */
9 struct operand_ *operands; /* list of operands */
10 unsigned int length; /* words */
11 unsigned int ready : 1; /* bytecode computed? */
12 DCPU16_WORD instr_words[];
13 };
14
15
16 enum operand_types_{
17 OT_DIRECT, /* these operands simply render their contents into bytecode */
18 OT_NEXT, /* these operands increase instruction length */
19 OT_LABEL /* labels need to be computed then converted to other types */
20 };
21
22 struct operand_ {
23 struct operand_ *next;
24 char *operand; /* tokenized operand text */
25 enum operand_types_ type;
26 union {
27 DCPU16_WORD word_value;
28 struct instruction_ *label_destination;
29 } value;
30 };
31
32
33 #define IL_SIZE(entries) (((entries) * sizeof(struct instruction_ *)) + sizeof(struct instruction_list_))
34
35 struct instruction_list_ {
36 size_t allocated;
37 size_t entries;
38 struct instruction_ *instr[];
39 };
40
41
42 /* note label table holds its own structs, not pointers */
43 struct label_ {
44 char *label; /* name of label */
45 struct instruction_ *instr;
46 };
47
48 #define LL_SIZE(entries) (((entries) * sizeof(struct label_ *)) + sizeof(struct label_list_))
49
50 struct label_list_ {
51 size_t allocated;
52 size_t entries;
53 struct label_ label[];
54 };
55
56 #endif /* AS_DCPU16_H_PTFNJB09 */