- added ability to filter VM disassembly dump
Use '-dumpdisasm something' to output functions with 'something' in their printable names Open and close output file only once when processing code generated by Dehacked, and calculate its sizes as well
This commit is contained in:
parent
09016b7c05
commit
5a19010699
3 changed files with 79 additions and 32 deletions
|
|
@ -809,11 +809,7 @@ VMFunction *FFunctionBuildList::AddFunction(PNamespace *gnspc, const VersionInfo
|
|||
|
||||
void FFunctionBuildList::Build()
|
||||
{
|
||||
int codesize = 0;
|
||||
int datasize = 0;
|
||||
FILE *dump = nullptr;
|
||||
|
||||
if (Args->CheckParm("-dumpdisasm")) dump = fopen("disasm.txt", "w");
|
||||
VMDisassemblyDumper disasmdump(VMDisassemblyDumper::Overwrite);
|
||||
|
||||
for (auto &item : mItems)
|
||||
{
|
||||
|
|
@ -900,13 +896,8 @@ void FFunctionBuildList::Build()
|
|||
}
|
||||
}
|
||||
|
||||
if (dump != nullptr)
|
||||
{
|
||||
DumpFunction(dump, sfunc, item.PrintableName.GetChars(), (int)item.PrintableName.Len());
|
||||
codesize += sfunc->CodeSize;
|
||||
datasize += sfunc->LineInfoCount * sizeof(FStatementInfo) + sfunc->ExtraSpace + sfunc->NumKonstD * sizeof(int) +
|
||||
sfunc->NumKonstA * sizeof(void*) + sfunc->NumKonstF * sizeof(double) + sfunc->NumKonstS * sizeof(FString);
|
||||
}
|
||||
disasmdump.Write(sfunc, item.PrintableName);
|
||||
|
||||
sfunc->Unsafe = ctx.Unsafe;
|
||||
}
|
||||
catch (CRecoverableError &err)
|
||||
|
|
@ -916,15 +907,7 @@ void FFunctionBuildList::Build()
|
|||
}
|
||||
}
|
||||
delete item.Code;
|
||||
if (dump != nullptr)
|
||||
{
|
||||
fflush(dump);
|
||||
}
|
||||
}
|
||||
if (dump != nullptr)
|
||||
{
|
||||
fprintf(dump, "\n*************************************************************************\n%i code bytes\n%i data bytes", codesize * 4, datasize);
|
||||
fclose(dump);
|
||||
disasmdump.Flush();
|
||||
}
|
||||
VMFunction::CreateRegUseInfo();
|
||||
FScriptPosition::StrictErrors = false;
|
||||
|
|
@ -1122,3 +1105,50 @@ ExpEmit FunctionCallEmitter::EmitCall(VMFunctionBuilder *build, TArray<ExpEmit>
|
|||
return retreg;
|
||||
}
|
||||
|
||||
|
||||
VMDisassemblyDumper::VMDisassemblyDumper(const FileOperationType operation)
|
||||
{
|
||||
static const char *const DUMP_ARG_NAME = "-dumpdisasm";
|
||||
|
||||
if (Args->CheckParm(DUMP_ARG_NAME))
|
||||
{
|
||||
dump = fopen("disasm.txt", operation == Overwrite ? "w" : "a");
|
||||
namefilter = Args->CheckValue(DUMP_ARG_NAME);
|
||||
namefilter.ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
VMDisassemblyDumper::~VMDisassemblyDumper()
|
||||
{
|
||||
if (dump != nullptr)
|
||||
{
|
||||
fprintf(dump, "\n*************************************************************************\n%i code bytes\n%i data bytes\n", codesize * 4, datasize);
|
||||
fclose(dump);
|
||||
}
|
||||
}
|
||||
|
||||
void VMDisassemblyDumper::Write(VMScriptFunction *sfunc, const FString &fname)
|
||||
{
|
||||
if (dump != nullptr)
|
||||
{
|
||||
if (namefilter.Len() > 0 && fname.MakeLower().IndexOf(namefilter) == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(sfunc != nullptr);
|
||||
|
||||
DumpFunction(dump, sfunc, fname, (int)fname.Len());
|
||||
codesize += sfunc->CodeSize;
|
||||
datasize += sfunc->LineInfoCount * sizeof(FStatementInfo) + sfunc->ExtraSpace + sfunc->NumKonstD * sizeof(int) +
|
||||
sfunc->NumKonstA * sizeof(void*) + sfunc->NumKonstF * sizeof(double) + sfunc->NumKonstS * sizeof(FString);
|
||||
}
|
||||
}
|
||||
|
||||
void VMDisassemblyDumper::Flush()
|
||||
{
|
||||
if (dump != nullptr)
|
||||
{
|
||||
fflush(dump);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue