This commit is contained in:
2026-07-16 19:04:36 +10:00
parent c0da7748d2
commit 3bf340d9f2
3 changed files with 12 additions and 20 deletions

View File

@@ -9,6 +9,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "../instruction.h" #include "../instruction.h"
#include "../util.h"
// Table of strings to instructions // Table of strings to instructions
struct _stringToInstructionOpcodeTable {char* str; InstructionOpcode opcode;} stringToInstructionOpcodeTable[] = { struct _stringToInstructionOpcodeTable {char* str; InstructionOpcode opcode;} stringToInstructionOpcodeTable[] = {
@@ -212,27 +213,15 @@ void serializeProgramToFile(Program* program, const char* outputFileName) {
} }
// Write magic header // Write magic header
size_t written = fwrite("mlc\0", 4, 1, fp); ROMFileHeader header = {
if (written != 1) { .magic = "mlc\0",
fprintf(stderr, "failed to write magic header into file %s\n", outputFileName); .version = 1,
fclose(fp); .numInstructions = program->len
exit(1); };
}
// Write program version size_t written = fwrite(&header, sizeof(ROMFileHeader), 1, fp);
uint8_t version = 1;
written = fwrite(&version, sizeof(uint8_t), 1, fp);
if (written != 1) { if (written != 1) {
fprintf(stderr, "failed to write version header into file %s\n", outputFileName); fprintf(stderr, "failed to write file header into file %s\n", outputFileName);
fclose(fp);
exit(1);
}
// Write instruction count
uint32_t instCount = program->len;
written = fwrite(&instCount, sizeof(uint32_t), 1, fp);
if (written != 1) {
fprintf(stderr, "failed to write instruction count header into file %s\n", outputFileName);
fclose(fp); fclose(fp);
exit(1); exit(1);
} }

View File

@@ -37,6 +37,8 @@ int main(int argc, char** argv) {
memcpy(emu->mem + MEM_PROGRAM_START, rom->instructions, sizeof(SerializedInst) * rom->header.numInstructions); memcpy(emu->mem + MEM_PROGRAM_START, rom->instructions, sizeof(SerializedInst) * rom->header.numInstructions);
printf("hi i exist\n");
startEmulator(emu); startEmulator(emu);
freeEmulator(emu); freeEmulator(emu);

View File

@@ -2,4 +2,5 @@ mvi a 2
mvi b 2 mvi b 2
add a b add a b
hlt hlt
hlt