move dump to debug
This commit is contained in:
parent
5107ac5df8
commit
dc89a24701
|
@ -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
|
||||
# ------------------
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -1,4 +1,5 @@
|
|||
#include "vm.h"
|
||||
#include "debug.h"
|
||||
|
||||
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
|
||||
#define MEMORY_SIZE 1024
|
||||
|
|
18
src/vm.c
18
src/vm.c
|
@ -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.
|
||||
*/
|
||||
|
|
7
src/vm.h
7
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
|
||||
|
|
Loading…
Reference in New Issue