X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/71a20a4f3d4e5f5278f7d004af710af89dfd7ebc..refs/heads/main:/src/main.cpp diff --git a/src/main.cpp b/src/main.cpp index 4c78f5b..a075a80 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,44 +7,58 @@ #include "toc.h" #include "repr.h" #include "repr_get.h" -#include "check.h" +#include "generic.h" +//#include "check.h" using namespace antlr4; int main(int argc, const char * argv[]) { - std::ifstream ifs("test.toc"); + std::ifstream ifs("test/test2.toc"); + // create ANTLR input from filestream ANTLRInputStream input(ifs); + // lex input TocLexer lexer(&input); CommonTokenStream tokens(&lexer); + // parse TocParser parser(&tokens); + + // get Prog (root node) TocParser::ProgContext * prog = parser.prog(); - tree::ParseTree * tree = prog; + // dont continue on parse error if (parser.getNumberOfSyntaxErrors() > 0) { std::cerr << "Parsing error" << std::endl; return 1; } - std::string s = tree->toStringTree(&parser) + "\n"; - + // print raw parse tree + //tree::ParseTree * tree = prog; + //std::string s = tree->toStringTree(&parser) + "\n"; //std::cout << "Parse Tree: " << s << std::endl; - Program prg = getProgram(prog); + // generate IR from tree and instantiate generics + Program prg = getProgram(prog, nullptr); + instantiateGenerics(prg); - tocProgram(std::cout, prg); - - if (!checkProgram(prg)) - std::cerr << "Error" << std::endl; + // print to cout and file + try + { + tocProgram(std::cout, prg); - //std::ofstream ofs("output.c"); - //tocProg(ofs, prg); - //ofs.close(); + std::ofstream ofs("output.c"); + tocProgram(ofs, prg); + ofs.close(); + } + catch (const char * e) + { + std::cerr << "Error: " << e << std::endl; + } return 0; } \ No newline at end of file