X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/8aeae09e74b46ca52866f22b48f55fecdf27b849..66a27d2fc7c1ad4e97de76d4982168a0fed9920a:/src/main.cpp?ds=inline diff --git a/src/main.cpp b/src/main.cpp index 199f04d..bd9a2b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,42 +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"); +int main(int argc, const char * argv[]) +{ + std::ifstream ifs("test/test.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; - if (parser.getNumberOfSyntaxErrors() > 0) { + // 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); - - tocProgram(std::cout, prg); + // generate IR from tree and instantiate generics + Program prg = getProgram(prog, nullptr); + instantiateGenerics(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