12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include <iostream>
- #include <string>
- #include <fstream>
- #include "Parser.h"
- #include "Optimizer.h"
- #include "AssemblyGenerator.h"
- using namespace std;
- using zp::Parser;
- using zp::Optimizer;
- using zp::AssemblyGenerator;
- int main(int argc, char** argv)
- {
- string filename = "";
- for (int i = 1; i < argc; i++) {
- string arg = argv[i];
- if (arg == "") {
- }
- else if (arg[0] == '-') {
- }
- else {
- filename = arg;
- }
- }
- istream* in = &cin;
- ostream* out = &cout;
- if (filename != "") {
- in = new ifstream{filename.c_str(), fstream::in};
- out = new ofstream{(filename + ".s").c_str(), fstream::out};
- }
- Parser parser{ *in };
- unique_ptr<zp::Block> ast;
- try {
- ast = parser.parse();
- }
- catch(zp::ParserException& pe) {
- cerr << "Error: " << pe.what() << endl;
- return 1;
- }
- Optimizer optimizer;
- auto ir = ast->accept(optimizer);
- AssemblyGenerator ag{ *out };
- ir->accept(ag);
- ag.finish();
- if (filename != "") {
- dynamic_cast<ifstream*> (in)->close();
- dynamic_cast<ofstream*> (out)->close();
- delete in;
- delete out;
- in = &cin;
- out = &cout;
- }
- }
|