-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
57 lines (46 loc) · 1.12 KB
/
main.cpp
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
#include <main.h>
//Parsed commands
cmd_list cmds;
//Variables and their characteristics
variable_map var_map;
//Labels
label_list labels;
//Function calling stuff
param_stack par_stack;
formal_params_stack formal_stack;
return_stack ret_stack;
call_addr_stack call_stack;
std::ifstream inFile;
bool parser_dbg=false;
void wrong_usage_msg(int arg_num){
fatal("[USAGE] vvm <input file>, "+to_string(arg_num)+" args supplied\n");
}
void invalid_arg_msg(const char* arg){
fatal("[INVALID ARGUMENT] "+std::string(arg)+"\n");
}
int main(int argc, const char* argv[]){
//Check and parse the command line arguments
if(argc<MIN_ARGC || argc>MAX_ARGC){
wrong_usage_msg(argc-1);
}
//Leaving room for more future command line options
std::string filename;
bool inFileSupplied=false;
for(int i=1;i<argc;i++){
if(file_exists(argv[i])){
filename=argv[i];
inFileSupplied=true;
}
else{
invalid_arg_msg(argv[i]);
}
}
if(!inFileSupplied)
fatal("[ERROR] Input file not defined: "+filename+"\n");
inFile.open(filename);
//Parse the input file into a list of commands
parse();
//Execute it!
execute();
return 0;
}