-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnjvm.c
72 lines (59 loc) · 1.7 KB
/
njvm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "njvm.h"
#include "stack.h"
#include "check_input.h"
// TODOS
unsigned int version = 8;
unsigned int versionBin;
unsigned int numberOfInstructions;
unsigned int stackS_G;
char format[4];
ObjRef *stack_G;
int *memory;
unsigned int feld[10];
unsigned int ir;
unsigned int pc;
FILE *f = NULL;
char *fileName;
bool debug = false;
int main(int argc, char *argv[]) {
/*
for(int i = 0; i < argc; ++i) {
printf("argv[%d]: %s\n", i, argv[i]);
}
printf("\n");
*/
for(int i = 0; i < argc; i++) {
if(!strcmp(argv[i], "--help")) {
printf("Usage: ./njvm [options] <code file>\n");
printf("Options:\n");
printf("\t--debug start virtual machine in debug mode\n");
printf("\t--version show version and exit\n");
printf("\t--help show this help and exit\n");
return 0;
} else if(!strcmp(argv[i], "--version")) {
printf("Ninja Virtual Machine version %d (%s %s)\n", version, __DATE__, __TIME__);
return 0;
} else if(!strcmp(argv[i], "--debug")) {
debug = true;
} else {
f = fopen(argv[i], "r");
fileName = (char*) malloc(strlen(argv[i]));
fileName = argv[i];
}
}
checkInput();
if(debug) {
printf("DEBUG: file '%s' loaded (code size = %d, data size = %d)\n", fileName, numberOfInstructions, stackS_G);
}
printf("Ninja Virtual Machine started\n");
pc = 0;
do {
ir = memory[pc];
pc++;
} while(execute(ir));
printf("Ninja Virtual Machine stopped\n");
}