- removed atag parameter from GetConstantAddress.

This commit is contained in:
Christoph Oelckers 2017-04-10 15:39:04 +02:00
parent ef77cbd295
commit e551ef52f8
6 changed files with 35 additions and 63 deletions

View file

@ -671,7 +671,7 @@ static int CreateSpawnFunc(VMFunctionBuilder &buildit, int value1, int value2)
I_Error("No class found for dehackednum %d!\n", value1+1);
return 0;
}
int typereg = buildit.GetConstantAddress(InfoNames[value1-1], ATAG_OBJECT);
int typereg = buildit.GetConstantAddress(InfoNames[value1-1]);
int heightreg = buildit.GetConstantFloat(value2);
buildit.Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, typereg); // itemtype
@ -813,7 +813,7 @@ void SetDehParams(FState *state, int codepointer)
}
// Emit code for action parameters.
int argcount = MBFCodePointerFactories[codepointer](buildit, value1, value2);
buildit.Emit(OP_TAIL_K, buildit.GetConstantAddress(sym->Variants[0].Implementation, ATAG_OBJECT), numargs + argcount, 0);
buildit.Emit(OP_TAIL_K, buildit.GetConstantAddress(sym->Variants[0].Implementation), numargs + argcount, 0);
// Attach it to the state.
VMScriptFunction *sfunc = new VMScriptFunction;
buildit.MakeFunction(sfunc);

View file

@ -587,12 +587,7 @@ ExpEmit FxConstant::Emit(VMFunctionBuilder *build)
}
else if (regtype == REGT_POINTER)
{
VM_ATAG tag = ATAG_GENERIC;
if (value.Type->GetLoadOp() != OP_LP)
{
tag = ATAG_OBJECT;
}
out.RegNum = build->GetConstantAddress(value.pointer, tag);
out.RegNum = build->GetConstantAddress(value.pointer);
}
else if (regtype == REGT_STRING)
{
@ -4634,7 +4629,7 @@ void FxTypeCheck::EmitCompare(VMFunctionBuilder *build, bool invert, TArray<size
{
ExpEmit ares = EmitCommon(build);
ares.Free(build);
build->Emit(OP_EQA_K, !invert, ares.RegNum, build->GetConstantAddress(nullptr, ATAG_OBJECT));
build->Emit(OP_EQA_K, !invert, ares.RegNum, build->GetConstantAddress(nullptr));
patchspots_no.Push(build->Emit(OP_JMP, 0));
}
@ -4702,7 +4697,7 @@ ExpEmit FxDynamicCast::Emit(VMFunctionBuilder *build)
ExpEmit castee = expr->Emit(build);
castee.Free(build);
ExpEmit ares(build, REGT_POINTER);
build->Emit(OP_DYNCAST_K, ares.RegNum, castee.RegNum, build->GetConstantAddress(CastType, ATAG_OBJECT));
build->Emit(OP_DYNCAST_K, ares.RegNum, castee.RegNum, build->GetConstantAddress(CastType));
return ares;
}
@ -5537,11 +5532,11 @@ ExpEmit FxRandom::Emit(VMFunctionBuilder *build)
{
EmitParameter(build, min, ScriptPosition);
EmitParameter(build, max, ScriptPosition);
build->Emit(opcode, build->GetConstantAddress(callfunc, ATAG_OBJECT), 3, 1);
build->Emit(opcode, build->GetConstantAddress(callfunc), 3, 1);
}
else
{
build->Emit(opcode, build->GetConstantAddress(callfunc, ATAG_OBJECT), 1, 1);
build->Emit(opcode, build->GetConstantAddress(callfunc), 1, 1);
}
if (EmitTail)
@ -5656,7 +5651,7 @@ ExpEmit FxRandomPick::Emit(VMFunctionBuilder *build)
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(rng));
build->EmitParamInt(0);
build->EmitParamInt(choices.Size() - 1);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 3, 1);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), 3, 1);
ExpEmit resultreg(build, REGT_INT);
build->Emit(OP_RESULT, 0, REGT_INT, resultreg.RegNum);
@ -5788,11 +5783,11 @@ ExpEmit FxFRandom::Emit(VMFunctionBuilder *build)
{
EmitParameter(build, min, ScriptPosition);
EmitParameter(build, max, ScriptPosition);
build->Emit(opcode, build->GetConstantAddress(callfunc, ATAG_OBJECT), 3, 1);
build->Emit(opcode, build->GetConstantAddress(callfunc), 3, 1);
}
else
{
build->Emit(opcode, build->GetConstantAddress(callfunc, ATAG_OBJECT), 1, 1);
build->Emit(opcode, build->GetConstantAddress(callfunc), 1, 1);
}
if (EmitTail)
@ -5880,7 +5875,7 @@ ExpEmit FxRandom2::Emit(VMFunctionBuilder *build)
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(rng));
EmitParameter(build, mask, ScriptPosition);
build->Emit(opcode, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2, 1);
build->Emit(opcode, build->GetConstantAddress(callfunc), 2, 1);
if (EmitTail)
{
@ -8540,14 +8535,14 @@ ExpEmit FxActionSpecialCall::Emit(VMFunctionBuilder *build)
if (build->FramePointer.Fixed) EmitTail = false; // do not tail call if the stack is in use
if (EmitTail)
{
build->Emit(OP_TAIL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2 + i, 0);
build->Emit(OP_TAIL_K, build->GetConstantAddress(callfunc), 2 + i, 0);
ExpEmit call;
call.Final = true;
return call;
}
ExpEmit dest(build, REGT_INT);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2 + i, 1);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), 2 + i, 1);
build->Emit(OP_RESULT, 0, REGT_INT, dest.RegNum);
return dest;
}
@ -8937,7 +8932,7 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
if (selfside == FScopeBarrier::Side_PlainData)
{
// Check the self object against the calling function's flags at run time
build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc, ATAG_OBJECT));
build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc));
}
}
@ -8981,7 +8976,7 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
// Get a constant register for this function
if (staticcall)
{
int funcaddr = build->GetConstantAddress(vmfunc, ATAG_OBJECT);
int funcaddr = build->GetConstantAddress(vmfunc);
// Emit the call
if (EmitTail)
{ // Tail call
@ -10499,7 +10494,7 @@ ExpEmit FxReturnStatement::Emit(VMFunctionBuilder *build)
ExpEmit reg(build, REGT_POINTER);
build->Emit(OP_ADDA_RK, reg.RegNum, build->FramePointer.RegNum, build->GetConstantInt(build->ConstructedStructs[i]->StackOffset));
build->Emit(OP_PARAM, 0, reg.RegType, reg.RegNum);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mDestructor, ATAG_OBJECT), 1, 0);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mDestructor), 1, 0);
reg.Free(build);
}
@ -10696,13 +10691,13 @@ ExpEmit FxClassTypeCast::Emit(VMFunctionBuilder *build)
{
if (basex->ValueType != TypeName)
{
return ExpEmit(build->GetConstantAddress(nullptr, ATAG_OBJECT), REGT_POINTER, true);
return ExpEmit(build->GetConstantAddress(nullptr), REGT_POINTER, true);
}
ExpEmit clsname = basex->Emit(build);
assert(!clsname.Konst);
ExpEmit dest(build, REGT_POINTER);
build->Emit(OP_PARAM, 0, clsname.RegType, clsname.RegNum);
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(const_cast<PClass *>(desttype), ATAG_OBJECT));
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(const_cast<PClass *>(desttype)));
// Call the BuiltinNameToClass function to convert from 'name' to class.
VMFunction *callfunc;
@ -10712,7 +10707,7 @@ ExpEmit FxClassTypeCast::Emit(VMFunctionBuilder *build)
assert(((PSymbolVMFunction *)sym)->Function != nullptr);
callfunc = ((PSymbolVMFunction *)sym)->Function;
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2, 1);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), 2, 1);
build->Emit(OP_RESULT, 0, REGT_POINTER, dest.RegNum);
clsname.Free(build);
return dest;
@ -10811,7 +10806,7 @@ ExpEmit FxClassPtrCast::Emit(VMFunctionBuilder *build)
ExpEmit clsname = basex->Emit(build);
build->Emit(OP_PARAM, 0, clsname.RegType, clsname.RegNum);
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(desttype, ATAG_OBJECT));
build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(desttype));
VMFunction *callfunc;
PSymbol *sym = FindBuiltinFunction(NAME_BuiltinClassCast, BuiltinClassCast);
@ -10821,7 +10816,7 @@ ExpEmit FxClassPtrCast::Emit(VMFunctionBuilder *build)
callfunc = ((PSymbolVMFunction *)sym)->Function;
clsname.Free(build);
ExpEmit dest(build, REGT_POINTER);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2, 1);
build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc), 2, 1);
build->Emit(OP_RESULT, 0, REGT_POINTER, dest.RegNum);
return dest;
}
@ -11160,7 +11155,7 @@ ExpEmit FxLocalVariableDeclaration::Emit(VMFunctionBuilder *build)
case REGT_POINTER:
{
build->Emit(OP_LKP, RegNum, build->GetConstantAddress(constval->GetValue().GetPointer(), ValueType->GetLoadOp() != OP_LP ? ATAG_OBJECT : ATAG_GENERIC));
build->Emit(OP_LKP, RegNum, build->GetConstantAddress(constval->GetValue().GetPointer()));
break;
}
case REGT_STRING:
@ -11192,7 +11187,7 @@ ExpEmit FxLocalVariableDeclaration::Emit(VMFunctionBuilder *build)
ExpEmit reg(build, REGT_POINTER);
build->Emit(OP_ADDA_RK, reg.RegNum, build->FramePointer.RegNum, build->GetConstantInt(StackOffset));
build->Emit(OP_PARAM, 0, reg.RegType, reg.RegNum);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mConstructor, ATAG_OBJECT), 1, 0);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mConstructor), 1, 0);
reg.Free(build);
}
if (pstr->mDestructor != nullptr) build->ConstructedStructs.Push(this);
@ -11218,7 +11213,7 @@ void FxLocalVariableDeclaration::Release(VMFunctionBuilder *build)
ExpEmit reg(build, REGT_POINTER);
build->Emit(OP_ADDA_RK, reg.RegNum, build->FramePointer.RegNum, build->GetConstantInt(StackOffset));
build->Emit(OP_PARAM, 0, reg.RegType, reg.RegNum);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mDestructor, ATAG_OBJECT), 1, 0);
build->Emit(OP_CALL_K, build->GetConstantAddress(pstr->mDestructor), 1, 0);
reg.Free(build);
}
build->ConstructedStructs.Delete(build->ConstructedStructs.Find(this));
@ -11300,7 +11295,7 @@ ExpEmit FxStaticArray::Emit(VMFunctionBuilder *build)
{
TArray<void*> cvalues;
for (auto v : values) cvalues.Push(static_cast<FxConstant *>(v)->GetValue().GetPointer());
StackOffset = build->AllocConstantsAddress(cvalues.Size(), &cvalues[0], ElementType->GetLoadOp() != OP_LP ? ATAG_OBJECT : ATAG_GENERIC);
StackOffset = build->AllocConstantsAddress(cvalues.Size(), &cvalues[0]);
break;
}
}

View file

@ -273,25 +273,20 @@ unsigned VMFunctionBuilder::GetConstantString(FString val)
//
//==========================================================================
unsigned VMFunctionBuilder::GetConstantAddress(void *ptr, VM_ATAG tag)
unsigned VMFunctionBuilder::GetConstantAddress(void *ptr)
{
if (ptr == NULL)
{ // Make all NULL pointers generic. (Or should we allow typed NULLs?)
tag = ATAG_GENERIC;
}
AddrKonst *locp = AddressConstantMap.CheckKey(ptr);
if (locp != NULL)
{
// There should only be one tag associated with a memory location. Exceptions are made for null pointers that got allocated through constant arrays.
assert(ptr == nullptr || locp->Tag == tag);
return locp->KonstNum;
}
else
{
unsigned locc = AddressConstantList.Push(ptr);
AtagConstantList.Push(tag);
AtagConstantList.Push(0);
AddrKonst loc = { locc, tag };
AddrKonst loc = { locc, 0 };
AddressConstantMap.Insert(ptr, loc);
return loc.KonstNum;
}
@ -327,15 +322,15 @@ unsigned VMFunctionBuilder::AllocConstantsFloat(unsigned count, double *values)
return addr;
}
unsigned VMFunctionBuilder::AllocConstantsAddress(unsigned count, void **ptrs, VM_ATAG tag)
unsigned VMFunctionBuilder::AllocConstantsAddress(unsigned count, void **ptrs)
{
unsigned addr = AddressConstantList.Reserve(count);
AtagConstantList.Reserve(count);
memcpy(&AddressConstantList[addr], ptrs, count * sizeof(void *));
for (unsigned i = 0; i < count; i++)
{
AtagConstantList[addr + i] = tag;
AddrKonst loc = { addr+i, tag };
AtagConstantList[addr + i] = 0;
AddrKonst loc = { addr+i, 0 };
AddressConstantMap.Insert(ptrs[i], loc);
}
return addr;

View file

@ -51,12 +51,12 @@ public:
// Returns the constant register holding the value.
unsigned GetConstantInt(int val);
unsigned GetConstantFloat(double val);
unsigned GetConstantAddress(void *ptr, VM_ATAG tag = ATAG_GENERIC);
unsigned GetConstantAddress(void *ptr);
unsigned GetConstantString(FString str);
unsigned AllocConstantsInt(unsigned int count, int *values);
unsigned AllocConstantsFloat(unsigned int count, double *values);
unsigned AllocConstantsAddress(unsigned int count, void **ptrs, VM_ATAG tag);
unsigned AllocConstantsAddress(unsigned int count, void **ptrs);
unsigned AllocConstantsString(unsigned int count, FString *ptrs);

View file

@ -353,34 +353,16 @@ struct VMReturn
*(FString *)Location = val;
}
void SetPointer(void *val, int tag)
{
assert(RegType == REGT_POINTER);
*(void **)Location = val;
if (TagOfs != 0)
{
*((VM_ATAG *)Location + TagOfs) = tag;
}
}
void SetPointer(void *val)
{
assert(RegType == REGT_POINTER);
*(void **)Location = val;
if (TagOfs != 0)
{
*((VM_ATAG *)Location + TagOfs) = ATAG_GENERIC;
}
}
void SetObject(DObject *val)
{
assert(RegType == REGT_POINTER);
*(void **)Location = val;
if (TagOfs != 0)
{
*((VM_ATAG *)Location + TagOfs) = ATAG_OBJECT;
}
}
void IntAt(int *loc)

View file

@ -2021,12 +2021,12 @@ static void SetReturn(const VMRegisters &reg, VMFrame *frame, VMReturn *ret, VM_
if (regtype & REGT_KONST)
{
assert(regnum < func->NumKonstA);
ret->SetPointer(func->KonstA[regnum].v, func->KonstATags()[regnum]);
ret->SetPointer(func->KonstA[regnum].v);
}
else
{
assert(regnum < frame->NumRegA);
ret->SetPointer(reg.a[regnum], reg.atag[regnum]);
ret->SetPointer(reg.a[regnum]);
}
break;
}