fix prog1.bin not working
add debug parameter add nja-mac
This commit is contained in:
parent
fb8497fbee
commit
88271c91ca
@ -12,7 +12,7 @@ unsigned int fromFile(char *path, struct program program) {
|
||||
FILE *fptr;
|
||||
fptr = fopen(path, "r+b");
|
||||
if (fptr == NULL) {
|
||||
printf("Error: cannot open code file %s", path);
|
||||
printf("Error: cannot open code file %s\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
unsigned int buffer[4];
|
||||
|
||||
70
njvm.c
70
njvm.c
@ -7,10 +7,6 @@
|
||||
#include "codeReader.c"
|
||||
#include "SDA.c"
|
||||
|
||||
//Comment to disable debug
|
||||
|
||||
#define DEBUG
|
||||
|
||||
// Stack
|
||||
struct stack stack;
|
||||
#define SIZE 1000
|
||||
@ -92,7 +88,7 @@ void execute(struct program program) {
|
||||
stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack);
|
||||
break;
|
||||
case POPL:
|
||||
push(stack, stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))]);
|
||||
push(&stack, stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -100,20 +96,18 @@ void execute(struct program program) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void tests(void) {
|
||||
printf("Runnig debug mode\n");
|
||||
int temp = fromFile("./prog1.bin", program);
|
||||
int temp = fromFile("./prog2.bin", program);
|
||||
int sizeSDA = temp;
|
||||
unsigned int s[sizeSDA];
|
||||
sda.size = &temp;
|
||||
sda.sda = s;
|
||||
printProgram(program);
|
||||
execute(program);
|
||||
printSDA(sda);
|
||||
}
|
||||
|
||||
#endif /* ifdef DEBUG */
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Initialize the Stack
|
||||
int size = SIZE;
|
||||
@ -131,41 +125,49 @@ int main(int argc, char *argv[]) {
|
||||
program.program = p;
|
||||
program.saveProgram = &saveProgram;
|
||||
|
||||
// Initialize runtime variables
|
||||
int debug = 0;
|
||||
int run = 0;
|
||||
int sizeSDA;
|
||||
|
||||
#ifdef DEBUG
|
||||
tests();
|
||||
#endif /* ifdef DEBUG */
|
||||
if (argc > 1) {
|
||||
if (strcmp(argv[1], "--version") == 0) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "--debug") == 0) {
|
||||
debug = 1;
|
||||
} else if (strcmp(argv[i], "--version") == 0) {
|
||||
version();
|
||||
} else if (strcmp(argv[1], "--help") == 0) {
|
||||
return 0;
|
||||
} else if (strcmp(argv[i], "--help") == 0) {
|
||||
help();
|
||||
} else if (strcmp(argv[1], "--prog1") == 0) {
|
||||
copyToProgram(code1, sizeof(code1) / sizeof(code1[0]), program);
|
||||
goto run;
|
||||
} else if (strcmp(argv[1], "--prog2") == 0) {
|
||||
copyToProgram(code2, sizeof(code2) / sizeof(code2[0]), program);
|
||||
goto run;
|
||||
} else if (strcmp(argv[1], "--prog3") == 0) {
|
||||
copyToProgram(code3, sizeof(code3) / sizeof(code3[0]), program);
|
||||
goto run;
|
||||
return 0;
|
||||
} else {
|
||||
printf("unknown command line argument '%s', try './njvm --help'", argv[1]);
|
||||
sizeSDA = fromFile(argv[i], program);
|
||||
run = 1;
|
||||
}
|
||||
} else {
|
||||
run:
|
||||
// Started
|
||||
if (*program.saveProgram == 1) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Debug mode
|
||||
*/
|
||||
if (debug) {
|
||||
tests();
|
||||
}
|
||||
|
||||
/*
|
||||
* Run program
|
||||
*/
|
||||
if (run) {
|
||||
printf("Ninja Virtual Machine started\n");
|
||||
unsigned int s[sizeSDA];
|
||||
sda.size = &sizeSDA;
|
||||
sda.sda = s;
|
||||
printProgram(program);
|
||||
execute(program);
|
||||
printSDA(sda);
|
||||
if (debug == 1) printSDA(sda);
|
||||
printf("Ninja Virtual Machine stopped\n");
|
||||
} else {
|
||||
printf("Error: no code file specified\n");
|
||||
return 1;
|
||||
}
|
||||
// Stopped
|
||||
printf("Ninja Virtual Machine stopped\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user