diff --git a/src/Makefile b/src/Makefile index 8bd320e..3624ea0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -31,7 +31,7 @@ OBJ_WASM = $(addprefix $(OBJ_DIR_WASM)/,$(notdir $(SRC:.c=.o))) .PHONY: all clean install wasm # Default target builds both versions -all: native +all: native # Native build rules # ------------------ diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..0a0c2cf --- /dev/null +++ b/src/debug.c @@ -0,0 +1,19 @@ +#include "debug.h" + +int core_dump(Data *memory, uint32_t memory_size) { + FILE *file = fopen("memory_dump.bin", "wb"); + if (!file) { + perror("Failed to open file"); + return EXIT_FAILURE; + } + size_t written = fwrite(memory, 1, memory_size, file); + if (written != memory_size) { + fprintf(stderr, "Incomplete write: %zu bytes written out of %u\n", written, + memory_size); + fclose(file); + return EXIT_FAILURE; + } + + fclose(file); + return EXIT_SUCCESS; +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..9cfc993 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,8 @@ +#ifndef ZRE_DEBUG_H +#define ZRE_DEBUG_H + +#include "vm.h" + +int core_dump(Data *memory, uint32_t memory_size); + +#endif diff --git a/src/main.c b/src/main.c index 20d6066..3c1416e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include "vm.h" +#include "debug.h" /* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */ #define MEMORY_SIZE 1024 diff --git a/src/vm.c b/src/vm.c index 09eba7f..1e60beb 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2,24 +2,6 @@ #include #include -int core_dump(Data *memory, uint32_t memory_size) { - FILE *file = fopen("memory_dump.bin", "wb"); - if (!file) { - perror("Failed to open file"); - return EXIT_FAILURE; - } - size_t written = fwrite(memory, 1, memory_size, file); - if (written != memory_size) { - fprintf(stderr, "Incomplete write: %zu bytes written out of %u\n", written, - memory_size); - fclose(file); - return EXIT_FAILURE; - } - - fclose(file); - return EXIT_SUCCESS; -} - /** * String copy in data memory. */ diff --git a/src/vm.h b/src/vm.h index 60b5ae2..5aaf1e5 100644 --- a/src/vm.h +++ b/src/vm.h @@ -26,12 +26,11 @@ typedef enum { OP_JGZ, /* jump to address dest if src1 > 0 */ OP_INT_TO_STRING, /* dest = src1 as str */ OP_F32_TO_STRING, /* dest = src2 as str */ - OP_READ_STRING, - OP_PRINT_STRING, - OP_CMP_STRING, + OP_READ_STRING, /* dest = src1 */ + OP_PRINT_STRING, /* dest = src1 */ + OP_CMP_STRING, /* dest = src1 */ } Opcode; void run_vm(Data *memory, uint32_t memory_size); -int core_dump(Data *memory, uint32_t memory_size); #endif