Module(GC*gc,std::string path){
         vm = new VirtualMachine(gc);
         Parser * par;
         if(path.length()<3 || std::string(path.end()-4,path.end()) != ".nls"){
                 vm->LoadAssembly(path.c_str());
                 BINDALL(vm,setSysFunction);
                 vm->run();
         }else{
                 try{
                         std::ifstream in (path);
                         std::string res( (  std::istreambuf_iterator<char>( in ) ),
                                   std::istreambuf_iterator<char>());
                         in.close();
                         par = new Parser(new Lexer(res,path),path);
                         par->Parse();
                         RefHolder rh;
                         BasicBlock bb (&rh);
                         par->getRoot()->emit(&bb);
                         bb.ReplaceLabels();
                         bb.emit(IL::hlt);
                         vm->SetBasicBlock(&bb);
                         vm->run();
                 }catch(...){
                         NLogger::log("Cannot load module:"+path);
                 }
                 delete par;
         }
 }
Exemple #2
0
int main(int argc, char** argv) {
    bool opTree = false;
    string filename = "";

    for (int i = 1; i < argc; i++) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 't': // Print the tree
                opTree = true;
                break;
            }
        } else
            filename = string(argv[i]);
    }

    try {
        SyntaxTree tree;
        vector<char> bytecode;
        ifstream ifs(filename.c_str());

        VirtualMachine vm;

        vm.compile(ifs, bytecode, tree);

        if (opTree)
            tree.dump(std::cout);

        vm.run(&bytecode[0]);

    } catch (std::exception &e) {
        std::cerr << e.what() << "\n";
    }
}
Exemple #3
0
int main( int argc, char * argv[] )
{
    Assembler ass;
    VirtualMachine vm;
    ass.assemble( argv[1] );
    vm.run( argv[1] );
} // end main function
Exemple #4
0
/**
 * Executes the given SVM class
 * @param argc the number of arguments passed
 * @param argv the given file arguments
 */
int Main::executeBinary( int argc, char* argv[] ) {
	// cache the class name
	const char* classname = argv[1];

	// startup the virtual machine
	VirtualMachine *vm = new VirtualMachine();

	// execute the class
	return vm->run( classname, argc, argv );
}
Exemple #5
0
int main(int argc, char *argv[] )
{
    Assembler assembler(argv[1]);
    unsigned short startAddr(0);
    try {
        startAddr = assembler.start();
    } catch (std::exception &ex) {
        std::cout << "Assembler error: " << ex.what() << std::endl;
        return 1;
    }

    boost::shared_array<unsigned int> data(assembler.getBlock());
    VirtualMachine vm;
    try {
        vm.setDebugInfo(assembler.byteToLineMap);
        vm.load(data);
        vm.run(startAddr);
    } catch (std::exception &ex) {
        std::cout << "VM error: " << ex.what() << std::endl;
        return 1;
    }

    return 0;
}