move dump to debug
This commit is contained in:
parent
5107ac5df8
commit
dc89a24701
|
@ -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 "vm.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
|
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
|
||||||
#define MEMORY_SIZE 1024
|
#define MEMORY_SIZE 1024
|
||||||
|
|
18
src/vm.c
18
src/vm.c
|
@ -2,24 +2,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.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.
|
* 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_JGZ, /* jump to address dest if src1 > 0 */
|
||||||
OP_INT_TO_STRING, /* dest = src1 as str */
|
OP_INT_TO_STRING, /* dest = src1 as str */
|
||||||
OP_F32_TO_STRING, /* dest = src2 as str */
|
OP_F32_TO_STRING, /* dest = src2 as str */
|
||||||
OP_READ_STRING,
|
OP_READ_STRING, /* dest = src1 */
|
||||||
OP_PRINT_STRING,
|
OP_PRINT_STRING, /* dest = src1 */
|
||||||
OP_CMP_STRING,
|
OP_CMP_STRING, /* dest = src1 */
|
||||||
} Opcode;
|
} Opcode;
|
||||||
|
|
||||||
void run_vm(Data *memory, uint32_t memory_size);
|
void run_vm(Data *memory, uint32_t memory_size);
|
||||||
int core_dump(Data *memory, uint32_t memory_size);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue