Add more values to the ast to facilitate encoding
- Add a instruction value that contains the encoding, the address and a flag to indicate if this instruction contains label references - Add label value that contains an address - Add reference value that contains offset, an absolute address and an operand size
This commit is contained in:
parent
9c6b69e187
commit
9a1570e3e5
14
src/ast.h
14
src/ast.h
@ -75,7 +75,7 @@ typedef struct register_ {
|
||||
} register_t;
|
||||
|
||||
typedef struct opcode_encoding {
|
||||
uint8_t encoding[32];
|
||||
uint8_t buffer[32];
|
||||
size_t len;
|
||||
} opcode_encoding_t;
|
||||
|
||||
@ -89,7 +89,19 @@ struct ast_node {
|
||||
union {
|
||||
register_t reg;
|
||||
number_t number;
|
||||
struct {
|
||||
bool has_reference;
|
||||
opcode_encoding_t encoding;
|
||||
int64_t address;
|
||||
} instruction;
|
||||
struct {
|
||||
int64_t offset;
|
||||
int64_t address;
|
||||
operand_size_t size;
|
||||
} reference;
|
||||
struct {
|
||||
int64_t address;
|
||||
} label;
|
||||
} value;
|
||||
};
|
||||
|
||||
|
@ -481,7 +481,7 @@ error_t *encoder_encode_instruction(encoder_t *encoder,
|
||||
return err;
|
||||
|
||||
// produce the actual encoding output in the NODE_INSTRUCTION value
|
||||
uint8_t *output = instruction->value.encoding.encoding;
|
||||
uint8_t *output = instruction->value.instruction.encoding.buffer;
|
||||
size_t output_len = 0;
|
||||
|
||||
// Handle prefixes
|
||||
@ -500,7 +500,7 @@ error_t *encoder_encode_instruction(encoder_t *encoder,
|
||||
memcpy(output + output_len, encoding->buffer, encoding->len);
|
||||
output_len += encoding->len;
|
||||
|
||||
instruction->value.encoding.len = output_len;
|
||||
instruction->value.instruction.encoding.len = output_len;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ error_t *print_encoding(tokenlist_t *list) {
|
||||
if (node->id != NODE_INSTRUCTION)
|
||||
continue;
|
||||
|
||||
print_hex(node->value.encoding.len, node->value.encoding.encoding);
|
||||
print_hex(node->value.instruction.encoding.len,
|
||||
node->value.instruction.encoding.buffer);
|
||||
}
|
||||
|
||||
encoder_free(encoder);
|
||||
|
Loading…
x
Reference in New Issue
Block a user