Pārlūkot izejas kodu

Make ASMInstruction's bytes an array.

master
Ben Kurtovic pirms 9 gadiem
vecāks
revīzija
bfba6cd709
4 mainītis faili ar 9 papildinājumiem un 13 dzēšanām
  1. +2
    -8
      src/assembler.c
  2. +2
    -1
      src/assembler/state.c
  3. +2
    -2
      src/assembler/state.h
  4. +3
    -2
      src/assembler/tokenizer.c

+ 2
- 8
src/assembler.c Parādīt failu

@@ -90,14 +90,8 @@ static ErrorInfo* resolve_symbols(AssemblerState *state)
return ei;
}

if (inst->loc.length == 3) {
inst->b2 = symbol->offset & 0xFF;
inst->b3 = symbol->offset >> 8;
} else {
inst->b3 = symbol->offset & 0xFF;
inst->b4 = symbol->offset >> 8;
}

inst->bytes[inst->loc.length - 2] = symbol->offset & 0xFF;
inst->bytes[inst->loc.length - 1] = symbol->offset >> 8;
free(inst->symbol);
inst->symbol = NULL;
}


+ 2
- 1
src/assembler/state.c Parādīt failu

@@ -88,6 +88,7 @@ void asm_instructions_free(ASMInstruction *inst)
{
while (inst) {
ASMInstruction *temp = inst->next;
free(inst->bytes);
if (inst->symbol)
free(inst->symbol);
free(inst);
@@ -102,7 +103,7 @@ void asm_data_free(ASMData *data)
{
while (data) {
ASMData *temp = data->next;
free(data->data);
free(data->bytes);
free(data);
data = temp;
}


+ 2
- 2
src/assembler/state.h Parādīt failu

@@ -40,7 +40,7 @@ typedef struct {

struct ASMInstruction {
ASMLocation loc;
uint8_t b1, b2, b3, b4;
uint8_t *bytes;
char *symbol;
const ASMLine *line;
struct ASMInstruction *next;
@@ -49,7 +49,7 @@ typedef struct ASMInstruction ASMInstruction;

struct ASMData {
ASMLocation loc;
uint8_t *data;
uint8_t *bytes;
struct ASMData *next;
};
typedef struct ASMData ASMData;


+ 3
- 2
src/assembler/tokenizer.c Parādīt failu

@@ -155,7 +155,7 @@ static ErrorInfo* parse_data(

data->loc.offset = offset;
data->loc.length = 6;
data->data = (uint8_t*) strdup("foobar");
data->bytes = (uint8_t*) strdup("foobar");
data->next = NULL;

*data_ptr = data;
@@ -182,7 +182,8 @@ static ErrorInfo* parse_instruction(

inst->loc.offset = offset;
inst->loc.length = 1;
inst->b1 = 0x3C;
uint8_t tmp = 0x3C;
inst->bytes = memcpy(malloc(1), &tmp, 1);
inst->symbol = NULL;
inst->line = line;
inst->next = NULL;


Notiek ielāde…
Atcelt
Saglabāt