aboutsummaryrefslogtreecommitdiff
path: root/tools/assemble.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assemble.c')
-rw-r--r--tools/assemble.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/tools/assemble.c b/tools/assemble.c
index b8bd75e..bb8c8d4 100644
--- a/tools/assemble.c
+++ b/tools/assemble.c
@@ -20,7 +20,7 @@ void free_expr(struct instruction *expr)
/* instructions are stored in a circular list */
int add_instruction(struct instruction **expr, uint16_t encoding,
- struct instruction_data data)
+ struct instruction_data data, const char *name)
{
struct instruction *new;
@@ -34,6 +34,7 @@ int add_instruction(struct instruction **expr, uint16_t encoding,
new->address_assigned = false;
new->encoding = encoding;
new->data = data;
+ new->name = name;
if (!*expr) {
new->next = new;
@@ -113,11 +114,13 @@ static uint16_t im_instruction(uint16_t payload)
}
static void encode_instruction(struct instruction *instruction,
- uint16_t *memory)
+ struct translated_word *memory)
{
uint32_t im = 0;
uint16_t encoding = instruction->encoding;
- uint16_t *dest = memory + instruction->address / 2;
+ struct translated_word *dest = memory + instruction->address / 2;
+
+ dest->instr = instruction;
if (instruction->data.info == DATA_INSTR_ADDR) {
im = (*instruction->data.data.ptr)->address;
@@ -132,17 +135,18 @@ static void encode_instruction(struct instruction *instruction,
case DATA_INSTR_ADDR :
case DATA_ADDR_AFTER :
case DATA_KNOWN :
- *(dest++) = im_instruction(im >> 22);
+ (dest++)->contents = im_instruction(im >> 22);
case DATA_KNOWN_21_BITS :
- *(dest++) = im_instruction(im >> 7);
+ (dest++)->contents = im_instruction(im >> 7);
case DATA_KNOWN_6_BITS :
encoding |= im & 0x7F;
}
- *dest = encoding;
+ dest->contents = encoding;
}
-static void encode_expr(struct instruction *expr, uint16_t *memory)
+static void encode_expr(struct instruction *expr,
+ struct translated_word *memory)
{
struct instruction *tmp = expr;
@@ -152,14 +156,14 @@ static void encode_expr(struct instruction *expr, uint16_t *memory)
} while (tmp != expr);
}
-int assemble(uint32_t memory_size, uint16_t memory[memory_size],
+int assemble(uint32_t memory_size, struct translated_word memory[memory_size],
struct module *module)
{
uint32_t i;
struct function *main_function = NULL;
uint32_t current_address;
uint64_t function_size;
- struct instruction *startup = NULL;
+ struct instruction **startup = &module->startup;
unsigned short startup_size;
int retval = -1;
@@ -181,13 +185,13 @@ int assemble(uint32_t memory_size, uint16_t memory[memory_size],
* We're first writing some value at STACK_FRAME_BACKUP_ADDR to be able
* to check, if the functions we call restore frame address properly
*/
- if (i_const(im(0x23), &startup) ||
- i_store(im(STACK_FRAME_BACKUP_ADDR), &startup) ||
- i_call (ptr(&main_function->translated_body), &startup) ||
- i_halt ( &startup))
+ if (i_const(im(0x23), startup) ||
+ i_store(im(STACK_FRAME_BACKUP_ADDR), startup) ||
+ i_call (ptr(&main_function->translated_body), startup) ||
+ i_halt ( startup))
goto fail;
- startup_size = estimate_expr_size(startup);
+ startup_size = estimate_expr_size(*startup);
i = module->functions_count;
current_address = CODE_TOP_ADDR;
@@ -209,13 +213,13 @@ int assemble(uint32_t memory_size, uint16_t memory[memory_size],
assign_addresses_and_sizes(module->functions[i].translated_body,
module->functions[i].start_addr);
- assign_addresses_and_sizes(startup, 0x0);
+ assign_addresses_and_sizes(*startup, 0x0);
i = module->functions_count;
while (i--)
encode_expr(module->functions[i].translated_body, memory);
- encode_expr(startup, memory);
+ encode_expr(*startup, memory);
retval = 0;
@@ -223,7 +227,5 @@ fail:
if (retval)
PRERR("Couldn't assemble code for stack machine\n");
- free_expr(startup);
-
return retval;
}