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; } }
int main(int argc, char *argv[]) { if(argc < 2) { std::cout << "Invalid number of arguments passed. Expected script path." << std::endl; return -1; } std::vector<unsigned int> bytes; BytecodeIO::readBytecode(argv[1], bytes); VirtualMachine VM; try { VM.interpret(&bytes[0], bytes.size()); } catch(const std::string &e) { std::cout << "\nException: " << e; } catch(const std::exception &e) { std::cout << "\nException: " << e.what(); } return 0; }
void StartInstance::Launch() { isInit = true; VirtualMachine *vm = new VirtualMachine(); if (isInit) { Power *p = new Power(); std::cout << "V1" << std::endl; map->seeMap(); std::cout << "-----------" << std::endl; map = p->findPowerOnMap(map); std::cout << "V2" << std::endl; map->seeMap(); std::cout << "-----------" << std::endl; vm->setMap(map->getMap()); vm->Launch(*map->getMap()); } else { std::string error = "Error Initialisation"; throw myException(error); } }
int main(int argc, char** argv) { (void)argc; (void)argv; VirtualMachine vm; vm.LoadFile("script.as"); vm.Call("void main()"); JavaVM *jvm; /* denotes a Java VM */ JNIEnv *env; /* pointer to native method interface */ JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */ JavaVMOption* options = new JavaVMOption[1]; options[0].optionString = "-Djava.class.path=/usr/lib/java"; vm_args.version = JNI_VERSION_1_6; vm_args.nOptions = 1; vm_args.options = options; vm_args.ignoreUnrecognized = false; /* load and initialize a Java VM, return a JNI interface * pointer in env */ JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); delete options; /* invoke the Main.test method using the JNI */ jclass cls = env->FindClass("Main"); jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V"); env->CallStaticVoidMethod(cls, mid, 100); /* We are done. */ jvm->DestroyJavaVM(); std::cout << "Hello World! (C++)" << std::endl; }
int main( int argc, char * argv[] ) { Assembler ass; VirtualMachine vm; ass.assemble( argv[1] ); vm.run( argv[1] ); } // end main function
void MinusCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { double number1 = atof(variable1.getValue().c_str()); double number2 = atof(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 - number2)); vm.setReturnToken(variable1.getTokenType()); } else { // Exception minus requires 2 numbers throwCustomError("cannot subtract " + variable1.getValue() + " by " + variable2.getValue(), vm, supergeheimeToken); return; } }
void AddLengthToArrayCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { vector<string>& parameters = node.getContentArrayNonConstant(); if (parameters.size() > 3) { string retVal = ""; for (size_t i = 1; i < parameters.size()-1; i++) { if (i != parameters.size() - 2) { retVal += vm.getVariable(parameters.at(i))->getValue() + ";"; } else { retVal += vm.getVariable(parameters.at(i))->getValue(); } } vm.setReturnValue(retVal); } else { vm.setReturnValue(vm.getVariable(parameters[1])->getValue()); } }
int main(int argc, char* argv[]) { VirtualMachine vm; vm.readProgram("test.vm"); vm.start(); return 0; }
void ModuloCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { auto supergeheimeToken = node.getToken(); vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { int number1 = atoi(variable1.getValue().c_str()); int number2 = atoi(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 % number2)); vm.setReturnToken(variable1.getTokenType()); } else { throwCustomError("cannot get remainder (modulo) " + variable1.getValue() + " from " + variable2.getValue(), vm,supergeheimeToken); return; } }
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"; } }
int main(int argc, char** args) { std::unique_ptr<BytecodeGenerator> g; try { g = std::unique_ptr<BytecodeGenerator>(new BytecodeGenerator()); } catch(SourceException e) { std::cout << e.Get() << std::endl; return 1; } VirtualMachine vm; vm.LoadProgram(g->GetBytecode(), g->GetBytecodeSize(), g->GetConstants()); char* result = vm.TrackByte(2000); vm.Run(); std::cout << "The value of tracked variable is: " << (int)*result << std::endl; return 0; }
explicit VMCodeBufferManage(VirtualMachineManage *vmmanage) :var_combos(&var_pcode) { if ( !vmmanage ) throw; VirtualMachine *vm = vmmanage->rand_virtual_machine(); var_pcode.init_handle_table(vm->get_vm_handle_table()); var_pcode.init_sign( vm->get_vm_handle().sign ); }
void IdentifierToReturnValueCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { vector<string>& parameters = node.getContentArrayNonConstant(); vm.setReturnValue(parameters.at(1)); vm.setReturnToken(node.getToken()->getSubType()); vm.addIdentifer(parameters.at(1)); vm.addArrayTypeToArrayTypes(node.getToken()->getText(), node.getToken()->getSubType()); }
void VirtualObject::finalize(VirtualMachine& vm) { if ( mpNativeObject != NULL ) { vm.unregisterNative(*this); } vm.release(*this); }
VirtualMachine::Debugger::Debugger(VirtualMachine &vm) : VM_(vm) { setFctHook(); if (vm.isFonctionnal()) { vm.addDebugger(this); lua_sethook(vm.getLua(), HookEvents, 0, 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 ); }
explicit VMCodeBufferManage(VirtualMachineManage *vmmanage) :var_combos(&var_pcode) { if ( !vmmanage ) throw; VirtualMachine *vm = vmmanage->rand_virtual_machine(); var_pcode.init_handle_table(vm->get_vm_handle_table()); var_pcode.init_sign( vm->get_vm_handle().fuc_select.addorsub ); //var_combos.link_pcode( &var_pcode ); }
int VirtualMachine::Debugger::setHook(lua_State *lua) { VirtualMachine *VM; VM = VirtualMachine::getVm(); if (VM->isFonctionnal()) if (lua_gettop(lua) == 2 && lua_isnumber(lua, 1) && lua_isnumber(lua, 2)) lua_sethook(VM->getLua(), HookEvents, lua_tonumber(lua, 1), lua_tonumber(lua, 2)); return 0; }
int main(int argc, char** argv) { (void)argc; (void)argv; VirtualMachine vm; vm.LoadFile("script.as"); vm.Call("void main()"); std::cout << "Hello World! (C++)" << std::endl; }
static size_t checkIndex(void* state, List* list, Object& obj){ VirtualMachine *vm = (VirtualMachine*)state; if (obj.type != NUMOBJ){ vm->throwError("list index type isn't num",TYPEERROR); } float index = obj.value.numval; if (index != (int)index){ vm->throwError("index isn't int",ARGUMENTERROR); } if (index < 0 || (size_t)index >= list->vec.size()){ vm->throwError("index out of range",ARGUMENTERROR); } return (size_t)index; }
void CommandLine::executeInstr() { if (!strcmp(argv[0], "load")) { #if defined(__APPLE__) char* buf = (char*)alloca(sizeof(argv[1]) + 7); sprintf(buf, "%s.dylib", argv[1]); #else char* buf = (char*)alloca(sizeof(argv[1]) + 4); sprintf(buf, "%s.so", argv[1]); #endif void* handle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); if (handle == 0) { fprintf(stderr, "\t Unable to load %s\n", argv[1]); printf("\t error = %s\n", dlerror()); return; } boot_t func = (boot_t)(intptr_t)dlsym(handle, "initialiseVirtualMachine"); if (func == 0) { fprintf(stderr, "\t Unable to find %s boot method\n", argv[1]); dlclose(handle); return; } func(); create_vm_t vmlet = (create_vm_t)(intptr_t)dlsym(handle, "createVirtualMachine"); vmlets[argv[1]] = vmlet; } else { create_vm_t func = vmlets[argv[0]]; mvm::Object* CU = compilers[argv[0]]; if (!func) { fprintf(stderr, "\t Unknown vm %s\n", argv[0]); } else { #if 0 thread_arg_t* thread_arg = (thread_arg_t*)malloc(sizeof (thread_arg_t)); thread_arg->argc = argc; thread_arg->argv = argv; thread_arg->func = func; int tid = 0; Thread::start(&tid, (int (*)(void *))startApp, thread_arg); #else VirtualMachine* VM = func(CU); VM->runApplication(argc, argv); #endif } } }
static std::string arguments(const VirtualMachine &vm, size_t nArgs) { std::ostringstream ss; ss <<"("; for (size_t i=0; i<nArgs; ++i) { BaseSemantics::SValuePtr arg = vm.argument(i); ss <<(i?", ":"") <<"arg_" <<i <<" = " <<*arg; if (vm.map()->at(arg->get_number()).exists()) { if (uint64_t deref = vm.readMemory(arg->get_number())) ss <<" [deref=" <<StringUtility::toHex2(deref, vm.wordSize()) <<"]"; } } ss <<")"; return ss.str(); }
DWORD WINAPI StartVMThread( void* clientPtr ) { VirtualMachine* vm = (VirtualMachine*) clientPtr; vm->m_ProcessorState->ps_Halt = false; vm->DispatchLoop(); // Reset all VM state data. vm->m_Registers->ClearAllRegisters(); vm->m_Registers->ClearAllFlags(); vm->m_OpcodeCounter = 0; vm->m_Registers->r_InstructionPointer = 0; return 1; }
VMCodeBufferManage(VirtualMachineManage *vmmanage, #ifdef PROTECT_X64 unsigned long key #else unsigned int key #endif ) :var_combos(&var_pcode) { if ( !vmmanage ) throw; VirtualMachine *vm = vmmanage->rand_virtual_machine(); var_pcode.init_handle_table(vm->get_vm_handle_table()); var_pcode.init_sign( vm->get_vm_handle().fuc_select.addorsub ); //var_combos.link_pcode( &var_pcode ); }
Video::Video(VirtualMachine& vm, VideoFairy& videoFairy) :vm_(vm) ,debugger_(vm.debugger()) ,cartridge(NULL) ,videoFairy(videoFairy) ,isEven(false) ,nowY(0) ,nowX(0) ,spriteHitCnt(0) ,executeNMIonVBlank(false) ,spriteHeight(8) ,patternTableAddressBackground(0) ,patternTableAddress8x8Sprites(0) ,vramIncrementSize(1) ,colorEmphasis(0) ,spriteVisibility(false) ,backgroundVisibility(false) ,spriteClipping(false) ,backgroundClipping(false) ,paletteMask(0) ,nowOnVBnank(false) ,sprite0Hit(false) ,lostSprites(false) ,vramBuffer(0) ,spriteAddr(0) ,vramAddrRegister(0x0) ,vramAddrReloadRegister(0) ,horizontalScrollBits(0) ,scrollRegisterWritten(false) ,vramAddrRegisterWritten(false) { //ctor memset(this->screenBuffer, 0x0, screenWidth * screenHeight * sizeof(uint8_t)); }
void PlusCommand::execute(VirtualMachine& vm, AbstractFunctionCall& node) { vector<string>& parameters = node.getContentArrayNonConstant(); Variable variable1 = *vm.getVariable(parameters.at(1)); Variable variable2 = *vm.getVariable(parameters.at(2)); if (isUndefined(variable1, variable2, vm)) { return; } if (variable1.getTokenType() == IToken::TYPE_NUMBER && variable2.getTokenType() == IToken::TYPE_NUMBER) { double number1 = atof(variable1.getValue().c_str()); double number2 = atof(variable2.getValue().c_str()); vm.setReturnValue(to_string(number1 + number2)); vm.setReturnToken(variable1.getTokenType()); } else if (variable1.getTokenType() == IToken::TYPE_FACT && variable2.getTokenType() == IToken::TYPE_FACT) { bool bool1 = (variable1.getValue() == "true") ? true : false; bool bool2 = (variable2.getValue() == "true") ? true : false; bool outcome = bool1 + bool2; if (outcome) { vm.setReturnValue("true"); } else { vm.setReturnValue("false"); } vm.setReturnToken(variable1.getTokenType()); } else { string var1 = variable1.getValue(); string var2 = variable2.getValue(); if (variable1.getTokenType() == IToken::TYPE_NUMBER) { var1 = removeUnnecessaryDotsAndZeros(var1); } if (variable1.getTokenType() == IToken::TYPE_NUMBER) { var2 = removeUnnecessaryDotsAndZeros(var2); } vm.setReturnValue(var1 + var2); vm.setReturnToken(IToken::TYPE_TEXT); } }
int main (int argc, char *argv[]) { if (argc < 2) { std::cout << "Incorrect program call: Processor.exe <program names>" << std::endl; return 0; } VirtualMachine processor; for (int i = 1; i < argc; i++) { std::ifstream file; file.open (argv[i], std::ios::in|std::ios::binary|std::ios::ate); if (!file.is_open ()) { std::cout << "Error: can't open " << argv[i] << std::endl; return 0; } std::streampos size = file.tellg (); unsigned char *data = (unsigned char*)malloc ((size_t)size); assert (data && "Allocation error in Main function"); file.seekg (0, std::ios::beg); file.read ((char *)data, size); file.close (); if (!processor.load (data, (size_t)size)) { std::cout << "Error: can not get data from " << argv[i] << std::endl; return 0; } clock_t t1 = clock (); if (!processor.execute ()) { std::cout << "Program " << argv[i] << " finished unsuccessfully" << std::endl; return 0; } std::cout << "Execution time: " << (clock () - t1) * 1000 / CLOCKS_PER_SEC << " ms" << std::endl; free (data); file.close (); } return 0; }
void ProgramMonitor::UpdateContent(const VirtualMachine &vm) { _addrToRowMap.clear(); _rowToAddrMap.clear(); DeleteAllItems(); int iRow = 0; for (unsigned char addr = 0x00; vm.IsValidMem(addr) && addr < VirtualMachine::ADDR_REGISTER; ) { const Operator *pOperator = vm.GetOperatorMap().Find(vm.GetMem(addr)); if (pOperator == NULL) break; _addrToRowMap[addr] = iRow; _rowToAddrMap[iRow] = addr; InsertItem(iRow, wxT("")); SetItem(iRow, COL_Address, wxString::Format(wxT("%02X"), addr)); SetItem(iRow, COL_Symbol, pOperator->GetSymbol(_upperCaseFlag)); SetItem(iRow, COL_Code, wxString::Format(wxT("%X"), pOperator->GetCode())); iRow++; if (pOperator->GetType() == Operator::TYPE_NoOperand) { // nothing to do } else if (pOperator->GetType() == Operator::TYPE_NibbleOperand) { unsigned char value = pOperator->FetchOperand(vm, addr); _addrToRowMap[addr + 1] = iRow; _rowToAddrMap[iRow] = addr + 1; InsertItem(iRow, wxT("")); SetItem(iRow, COL_Address, wxString::Format(wxT("%02X"), addr + 1)); SetItem(iRow, COL_Symbol, wxString::Format(wxT("<%X>"), value)); SetItem(iRow, COL_Code, wxString::Format(wxT("%X"), value)); iRow++; } else if (pOperator->GetType() == Operator::TYPE_JUMP) { unsigned char addrDest = pOperator->FetchOperand(vm, addr); _addrToRowMap[addr + 1] = iRow; _rowToAddrMap[iRow] = addr + 1; InsertItem(iRow, wxT("")); SetItem(iRow, COL_Address, wxString::Format(wxT("%02X"), addr + 1)); SetItem(iRow, COL_Symbol, wxString::Format(wxT("<%X>"), addrDest >> 4)); SetItem(iRow, COL_Code, wxString::Format(wxT("%X"), addrDest >> 4)); iRow++; _addrToRowMap[addr + 2] = iRow; _rowToAddrMap[iRow] = addr + 2; InsertItem(iRow, wxT("")); SetItem(iRow, COL_Address, wxString::Format(wxT("%02X"), addr + 2)); SetItem(iRow, COL_Symbol, wxString::Format(wxT("<%X>"), addrDest & 0xf)); SetItem(iRow, COL_Code, wxString::Format(wxT("%X"), addrDest & 0xf)); iRow++; } else if (pOperator->GetType() == Operator::TYPE_CAL) {
llvm::GlobalVariable *Property::GetMemberInfo() { if(!propertyInfo) { // Only create the property info variable when reflection is enabled. Module *module = GetModule(); if(!module->HasReflection()) return NULL; // Get the property info class. VirtualMachine *vm = module->GetVirtualMachine(); Class *propInfoClass = vm->GetPropertyInfoClass(); llvm::Module *targetModule = module->GetTargetModule(); propertyInfo = new llvm::GlobalVariable(*targetModule, propInfoClass->GetTargetType(), false, ComputeMetadataLinkage(), NULL, GetMangledName() + "_propinfo_"); } return propertyInfo; }
Object listStr(void* state){ VirtualMachine *vm = (VirtualMachine*)state; int len = 1; Object obj; getArgs(state, &len, &obj); List* l =(List*)obj.value.userData->data; std::ostringstream oss; oss << "["; for (size_t i = 0; i < l->vec.size(); ++i){ oss << toPrintableStr(state, l->vec[i],true); if (i != l->vec.size()-1) oss << ","; } oss << "]"; Object ret; ret.type = STROBJ; ret.value.strObj = vm->addStrObj(oss.str()); return ret; }