char *luaU_dumpchunk_buffer(const Proto* Main, size_t *len) { char *buf; /* First calculate the total size*/ __lua_dumper_size = 0; DumpByte = DumpByte_calc_size; DumpSig = DumpSig_calc_size; DumpBlock = DumpBlock_calc_size; DumpVector = DumpVector_calc_size; DumpHeader(NULL); DumpFunction(Main, NULL); /* Allocate the buffer */ *len = __lua_dumper_size; C_MAKE(buf, __lua_dumper_size, char); /* Now dump it for real */ __lua_dumper_size = 0; DumpByte = DumpByte_buffer; DumpSig = DumpSig_buffer; DumpBlock = DumpBlock_buffer; DumpVector = DumpVector_buffer; DumpHeader(buf); DumpFunction(Main, buf); return buf; }
static void DumpConstants(const ktap_proto *f, DumpState *D) { int i, n = f->sizek; DumpInt(n, D); for (i = 0; i < n; i++) { const ktap_value* o=&f->k[i]; DumpChar(ttypenv(o), D); switch (ttypenv(o)) { case KTAP_TNIL: break; case KTAP_TBOOLEAN: DumpChar(bvalue(o), D); break; case KTAP_TNUMBER: DumpNumber(nvalue(o), D); break; case KTAP_TSTRING: DumpString(rawtsvalue(o), D); break; default: printf("ktap: DumpConstants with unknown vaule type %d\n", ttypenv(o)); ktap_assert(0); } } n = f->sizep; DumpInt(n, D); for (i = 0; i < n; i++) DumpFunction(f->p[i], D); }
static void DumpConstants(const killa_Proto* f, DumpState* D) { int i,n=f->sizek; DumpInt(n,D); for (i=0; i<n; i++) { const killa_TValue* o=&f->k[i]; DumpChar(killa_ttype(o),D); switch (killa_ttype(o)) { case KILLA_TNULL: break; case KILLA_TBOOLEAN: DumpChar(killa_bvalue(o),D); break; case KILLA_TNUMBER: DumpNumber(killa_nvalue(o),D); break; case KILLA_TSTRING: DumpString(killa_rawtsvalue(o),D); break; } } n=f->sizep; DumpInt(n,D); for (i=0; i<n; i++) DumpFunction(f->p[i],D); }
static void DumpConstants(const Proto* f, DumpState* D) { int i,n; DumpInt(n=f->sizek,D); for (i=0; i<n; i++) { const TObject* o=&f->k[i]; DumpByte(ttype(o),D); switch (ttype(o)) { case LUA_TNUMBER: DumpNumber(nvalue(o),D); break; case LUA_TSTRING: DumpString(tsvalue(o),D); break; case LUA_TNIL: break; default: lua_assert(0); /* cannot happen */ break; } } DumpInt(n=f->sizep,D); for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D); }
static void DumpConstants(const Proto* f, DumpState* D) { int i,n=f->sizek; DumpInt(n,D); for (i=0; i<n; i++) { const TValue* o=&f->k[i]; DumpChar(ttype(o),D); switch (ttype(o)) { case LUA_TNIL: break; case LUA_TBOOLEAN: DumpChar(bvalue(o),D); break; case LUA_TNUMBER: DumpNumber(nvalue(o),D); break; case LUA_TSTRING: DumpString(rawtsvalue(o),D); break; default: lua_assert(0); /* cannot happen */ break; } } n=f->sizep; DumpInt(n,D); for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D); }
static void DumpProtos (const Proto *f, DumpState *D) { int i; int n = f->sizep; DumpInt(n, D); for (i = 0; i < n; i++) DumpFunction(f->p[i], f->source, D); }
/* ** dump function as precompiled chunk */ void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data) { DumpState D; D.L=L; D.write=w; D.data=data; DumpHeader(&D); DumpFunction(Main,NULL,&D); }
static void DumpConstants(const Proto* tf, void* D) { int i,n; DumpInt(n=tf->nkstr,D); for (i=0; i<n; i++) DumpString(tf->kstr[i],D); DumpInt(tf->nknum,D); DumpVector(tf->knum,tf->nknum,sizeof(*tf->knum),D); DumpInt(n=tf->nkproto,D); for (i=0; i<n; i++) DumpFunction(tf->kproto[i],D); }
/* ** dump Lua function as precompiled chunk */ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; DumpHeader(&D); DumpFunction(f,NULL,&D); return D.status; }
/* * dump ktap function as precompiled chunk */ int ktapc_dump(const ktap_proto *f, ktap_writer w, void *data, int strip) { DumpState D; D.writer = w; D.data = data; D.strip = strip; D.status = 0; DumpHeader(&D); DumpFunction(f, &D); return D.status; }
/* ** dump Lua function as precompiled chunk */ int luaU_dump (LuaThread* L, const LuaProto* f, lua_Writer w, void* data, int strip) { THREAD_CHECK(L); DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; DumpHeader(&D); DumpFunction(f,&D); return D.status; }
/* ** dump Lua function as precompiled chunk with specified target */ int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target) { DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; D.target=target; DumpHeader(&D); DumpFunction(f,NULL,&D); return D.status; }
static void DumpSubFunctions(TProtoFunc* tf, FILE* D) { int i,n; n = tf->nconsts; for (i=0; i<n; i++) { TObject* o=tf->consts+i; if (ttype(o) == LUA_T_PROTO) { fputc('#',D); DumpWord(i,D); DumpFunction(tfvalue(o),D); } } fputc('$',D); }
/* ** dump Lua function as precompiled chunk */ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, char endian) { DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; D.swap=doendian(endian); D.endian=endian; luaZ_initbuffer(L, &D.b); DumpHeader(&D); DumpFunction(f,NULL,&D); luaZ_freebuffer(L, &D.b); return D.status; }
void DumpTranslationUnit(AstTranslationUnit transUnit) { AstNode p; ASTFile = CreateOutput(Input.filename, ".ast"); p = transUnit->extDecls; while (p) { if (p->kind == NK_Function) { DumpFunction((AstFunction)p); } p = p->next; } fclose(ASTFile); }
void luaU_dumpchunk_file(const Proto* Main, PHYSFS_file* D) { cptr err; DumpByte = DumpByte_file; DumpSig = DumpSig_file; DumpBlock = DumpBlock_file; DumpVector = DumpVector_file; DumpHeader(D); DumpFunction(Main,D); if ((err = PHYSFS_getLastError()) != NULL) { quit(format("luac: write error: %s", err)); } }
/* ** dump Lua function as precompiled chunk */ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { LuaDumpConfig config; DumpState D; D.L=L; D.writer=w; D.data=data; D.strip=strip; D.status=0; // Dump functions are expecting this config config.endianness = (luaU_getHostOrder() == WWS_LUA_LITTLE_ENDIAN) ? 1 : 0; config.sizeof_int = sizeof(int); config.sizeof_size_t = sizeof(size_t); config.sizeof_lua_Number = sizeof(lua_Number); D.config = &config; DumpHeader(&D); DumpFunction(f,NULL,&D); return D.status; }
static void DumpConstants(const LuaProto* f, DumpState* D) { int n = (int)f->constants.size(); DumpInt(n,D); for(int i=0; i < n; i++) { LuaValue v = f->constants[i]; DumpChar(v.type(),D); if(v.isBool()) { DumpChar(v.getBool() ? 1 : 0,D); } else if(v.isNumber()) { DumpNumber(v.getNumber(),D); } else if(v.isString()) { DumpString(v.getString(),D); } } n = (int)f->subprotos_.size(); DumpInt(n,D); for (int i=0; i < n; i++) { DumpFunction(f->subprotos_[i],D); } }
void luaU_dumpchunk(const Proto* Main, FILE* D) { DumpHeader(D); DumpFunction(Main,D); }
static void FinishThingdef() { int errorcount = 0; unsigned i; int codesize = 0; FILE *dump = NULL; if (Args->CheckParm("-dumpdisasm")) dump = fopen("disasm.txt", "w"); for (i = 0; i < StateTempCalls.Size(); ++i) { FStateTempCall *tcall = StateTempCalls[i]; VMFunction *func; assert(tcall->Code != NULL); // Can we call this function directly without wrapping it in an // anonymous function? e.g. Are we passing any parameters to it? func = tcall->Code->GetDirectFunction(); if (func == NULL) { FCompileContext ctx(tcall->ActorClass); tcall->Code = tcall->Code->Resolve(ctx); // Make sure resolving it didn't obliterate it. if (tcall->Code != NULL) { VMFunctionBuilder buildit; // Allocate registers used to pass parameters in. // self, stateowner, state (all are pointers) buildit.Registers[REGT_POINTER].Get(3); // Emit code tcall->Code->Emit(&buildit); VMScriptFunction *sfunc = buildit.MakeFunction(); sfunc->NumArgs = NAP; // Generate prototype for this anonymous function TArray<PType *> args(3); SetImplicitArgs(&args, NULL, tcall->ActorClass, VARF_Method | VARF_Action); if (tcall->Proto != NULL) { sfunc->Proto = NewPrototype(tcall->Proto->ReturnTypes, args); } else { TArray<PType *> norets(0); sfunc->Proto = NewPrototype(norets, args); } func = sfunc; if (dump != NULL) { char label[64]; int labellen = mysnprintf(label, countof(label), "Function %s.States[%d] (*%d)", tcall->ActorClass->TypeName.GetChars(), tcall->FirstState, tcall->NumStates); DumpFunction(dump, sfunc, label, labellen); codesize += sfunc->CodeSize; } } } if (tcall->Code != NULL) { delete tcall->Code; tcall->Code = NULL; for (int k = 0; k < tcall->NumStates; ++k) { tcall->ActorClass->OwnedStates[tcall->FirstState + k].SetAction(func); } } } for (i = 0; i < PClassActor::AllActorClasses.Size(); i++) { PClassActor *ti = PClassActor::AllActorClasses[i]; if (ti->Size == TentativeClass) { Printf(TEXTCOLOR_RED "Class %s referenced but not defined\n", ti->TypeName.GetChars()); errorcount++; continue; } AActor *def = GetDefaultByType(ti); if (!def) { Printf("No ActorInfo defined for class '%s'\n", ti->TypeName.GetChars()); errorcount++; continue; } if (def->Damage != NULL) { FxDamageValue *dmg = (FxDamageValue *)ActorDamageFuncs[(uintptr_t)def->Damage - 1]; VMScriptFunction *sfunc; sfunc = dmg->GetFunction(); if (sfunc == NULL) { FCompileContext ctx(ti); dmg->Resolve(ctx); VMFunctionBuilder buildit; buildit.Registers[REGT_POINTER].Get(1); // The self pointer dmg->Emit(&buildit); sfunc = buildit.MakeFunction(); sfunc->NumArgs = 1; sfunc->Proto = NULL; ///FIXME: Need a proper prototype here // Save this function in case this damage value was reused // (which happens quite easily with inheritance). dmg->SetFunction(sfunc); } def->Damage = sfunc; if (dump != NULL && sfunc != NULL) { char label[64]; int labellen = mysnprintf(label, countof(label), "Function %s.Damage", ti->TypeName.GetChars()); DumpFunction(dump, sfunc, label, labellen); codesize += sfunc->CodeSize; } } } if (dump != NULL) { fprintf(dump, "\n*************************************************************************\n%i code bytes\n", codesize * 4); fclose(dump); } if (errorcount > 0) { I_Error("%d errors during actor postprocessing", errorcount); } ActorDamageFuncs.DeleteAndClear(); StateTempCalls.DeleteAndClear(); // Since these are defined in DECORATE now the table has to be initialized here. for(int i = 0; i < 31; i++) { char fmt[20]; mysnprintf(fmt, countof(fmt), "QuestItem%d", i+1); QuestItemClasses[i] = PClass::FindActor(fmt); } }
void DumpChunk(TProtoFunc* Main, FILE* D) { DumpHeader(Main,D); DumpFunction(Main,D); }