forked from lyh552506/miniC-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (35 loc) · 1.05 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
#include "./include/lib/CFG.hpp"
#include "./include/ir/opt/New_passManager.hpp"
#include "./include/backend/RISCVLowering.hpp"
#include "./include/yacc/parser.hpp"
#include <fstream>
#include <getopt.h>
#include <iostream>
#include <memory>
extern FILE *yyin;
extern int optind, opterr, optopt;
extern char *optargi;
std::string asmoutput_path;
void copyFile(const std::string &sourcePath,
const std::string &destinationPath) {
std::ifstream source(sourcePath, std::ios::binary);
std::ofstream destination(destinationPath, std::ios::binary);
destination << source.rdbuf();
}
int main(int argc, char **argv) {
// compiler -S -o testcase.s testcase.sy
asmoutput_path = argv[3];
yyin = fopen(argv[4], "r");
yy::parser parse;
parse();
Singleton<CompUnit *>()->codegen();
auto PM = std::make_unique<_PassManager>();
// PM->DecodeArgs(argc-4,argv+4);
PM->RunOnLevel();
freopen(asmoutput_path.c_str(), "w", stdout);
RISCVModuleLowering RISCVAsm;
RISCVAsm.run(&Singleton<Module>());
fflush(stdout);
fclose(stdout);
return 0;
}