move dump to debug

This commit is contained in:
zongor 2025-06-13 21:50:43 -04:00
parent 5107ac5df8
commit dc89a24701
6 changed files with 32 additions and 23 deletions

View File

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

19
src/debug.c Normal file
View File

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

8
src/debug.h Normal file
View File

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

View File

@ -1,4 +1,5 @@
#include "vm.h"
#include "debug.h"
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
#define MEMORY_SIZE 1024

View File

@ -2,24 +2,6 @@
#include <string.h>
#include <unistd.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;
}
/**
* String copy in data memory.
*/

View File

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