浏览代码

Make ASMInstruction's bytes an array.

master
Ben Kurtovic 9 年前
父节点
当前提交
bfba6cd709
共有 4 个文件被更改,包括 9 次插入13 次删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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;


正在加载...
取消
保存