-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvasm.cpp
55 lines (51 loc) · 1.35 KB
/
vasm.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
#include "lexer.h"
#include "parser.h"
#include "vasm.h"
#include <iostream>
#include <string>
using namespace std;
string infile_name;
string outfile_name;
void parse_args(int argc, char *argv[]){
if(argc <= 1){
cout << "Usage: vasm.exe INPUT_FILE (OUTPUT_FILE_NAME) \n";
exit(1);
}
infile_name = argv[1];
if(argc >= 3)
outfile_name = argv[2];
else{
size_t found = infile_name.find_last_of("/\\");
string file_name = infile_name.substr(found + 1);
found = file_name.find_last_of(".");
file_name = infile_name.substr(0, found);
outfile_name = file_name + ".mem";
}
}
int main(int argc, char *argv[]) {
parse_args(argc, argv);
cout << "Input file name: " << infile_name << endl;
cout << "Output file name: " << outfile_name << endl;
if(file_init(infile_name))
cout << "---Read file success---\n";
else {
cout << "Open input file failed\n";
exit(1);
}
if(lex())
cout << "---Lex success---\n";
print_token();
//parse
cout << "\n---Start parsing---\n";
parse();
cout << "Parser returned" <<endl;
print_prog();
cout << "\n---Start translating---\n";
asm_to_machine();
print_machine_code();
if(!init_outfile(outfile_name)){
cout << "Output file error\n";
}
write_out();
return 0;
}