Include imm16's in the word count (fix the infinite loop bug yay!)
This commit is contained in:
@@ -248,11 +248,16 @@ void serializeProgramToFile(Program* program, const char* outputFileName) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t totalWords = 0;
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
totalWords += program->at[i].hasImm16 ? 2 : 1;
|
||||
}
|
||||
|
||||
// Write magic header
|
||||
ROMFileHeader header = {
|
||||
.magic = "mlc\0",
|
||||
.version = 1,
|
||||
.numInstructions = program->len
|
||||
.numInstructions = totalWords
|
||||
};
|
||||
|
||||
size_t written = fwrite(&header, sizeof(ROMFileHeader), 1, fp);
|
||||
|
||||
@@ -30,7 +30,7 @@ void addInstructionToProgram(Program* program, Instruction inst) {
|
||||
}
|
||||
|
||||
if (program->len + 1 >= program->capacity) {
|
||||
Instruction* tmp = malloc(sizeof(Instruction) * program->capacity * 2);
|
||||
Instruction* tmp = realloc(program->at, sizeof(Instruction) * program->capacity * 2);
|
||||
if (tmp == NULL) {
|
||||
fprintf(stderr, "malloc failed while expanding program\n");
|
||||
exit(1);
|
||||
@@ -50,7 +50,7 @@ void addLabelToProgram(Program* program, const char* name, uint8_t position) {
|
||||
}
|
||||
|
||||
if (program->labels.len + 1 >= program->labels.capacity) {
|
||||
Label* tmp = malloc(sizeof(Label) * program->labels.capacity * 2);
|
||||
Label* tmp = realloc(program->labels.at, sizeof(Label) * program->labels.capacity * 2);
|
||||
if (tmp == NULL) {
|
||||
fprintf(stderr, "malloc failed while expanding program labels\n");
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user