50 lines
1,000 B
C++
50 lines
1,000 B
C++
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#include <emit.hh>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <xlangLexer.h>
|
|
#include <xlangParser.h>
|
|
|
|
static void usage() {
|
|
std::cerr << getprogname() << " [-o output.ssa] input.x" << std::endl;
|
|
exit(1);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int opt;
|
|
std::string inputfile;
|
|
std::string outputfile;
|
|
|
|
while ((opt = getopt(argc, argv, "o:")) != -1) {
|
|
switch (opt) {
|
|
case 'o':
|
|
outputfile = optarg;
|
|
break;
|
|
default:
|
|
usage();
|
|
}
|
|
}
|
|
argc -= optind;
|
|
argv += optind;
|
|
if (argc != 1) {
|
|
usage();
|
|
}
|
|
inputfile = argv[0];
|
|
if (!outputfile.length()) {
|
|
outputfile = "/dev/stdout";
|
|
}
|
|
|
|
std::ifstream inputstream{inputfile};
|
|
antlr4::ANTLRInputStream input{inputstream};
|
|
xlang::xlangLexer lexer{&input};
|
|
antlr4::CommonTokenStream tokens{&lexer};
|
|
xlang::xlangParser parser{&tokens};
|
|
auto *tree = parser.file();
|
|
|
|
xlang::EmitVisitor emit{outputfile};
|
|
emit.visitFile(tree);
|
|
return 0;
|
|
}
|