Пример #1
0
CodeGen hex(AST &ast){
	CodeGen cg;
	cg.generate(ast.get_root());
	cg.back_patch();
	cg.fill();
	// cg.print_hex();
	// cg.print_tables();

	return cg;
}
Пример #2
0
int main (int argc, char * argv[]) {
    if (argc != 3) {
        cout << "argument too few" << endl;
        exit(1);
    }

    ifstream file(argv[1]);
    if (file.fail ()) {
        cout << "open file to read failed." << endl;
        exit(1);
    }

    BufferReader reader(file);
    Source source(reader);
    MutCTokenizer * tokenizer = new MutCTokenizer(source);
    MutCParser * parser = new MutCParser(tokenizer);

    parser->parse ();
    parser->ast ().printAST ();
    cout << "start decorating..." << endl;
    parser->decorateAST ();
    cout << "decorating done..." << endl;

    // shared_ptr<CodeGen> codegen = make_shared <CodeGen> (parser.get ());
    CodeGen * codegen = new CodeGen(parser);
    cout << "start generating..." << endl;
    Code & code = codegen->generate ();
    cout << "generating done..." << endl;

    ofstream output(argv[2]);
    if (output.fail ()) {
        cout << "open file to write failed." << endl;
        exit(1);
    }
    cout << "start outputing..." << endl;
    output << code.toString ();
    cout << "outputing done..." << endl;

    delete codegen;
    delete tokenizer;


    return 0;
}