MCPcopy Create free account
hub / github.com/beefytech/Beef / LoadValue

Method LoadValue

IDEHelper/Compiler/BfModule.cpp:13498–13590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13496}
13497
13498BfTypedValue BfModule::LoadValue(BfTypedValue typedValue, BfAstNode* refNode, bool isVolatile)
13499{
13500 if (!typedValue.IsAddr())
13501 return typedValue;
13502
13503 PopulateType(typedValue.mType);
13504 if ((typedValue.mType->IsValuelessType()) || (typedValue.mType->IsVar()))
13505 return BfTypedValue(mBfIRBuilder->GetFakeVal(), typedValue.mType, false);
13506
13507 if (typedValue.mValue.IsConst())
13508 {
13509 auto constantValue = mBfIRBuilder->GetConstant(typedValue.mValue);
13510 if (constantValue != NULL)
13511 {
13512 if (constantValue->mConstType == BfConstType_GlobalVar)
13513 {
13514 auto globalVar = (BfGlobalVar*)constantValue;
13515 if (globalVar->mName[0] == '#')
13516 {
13517 BfTypedValue result = GetCompilerFieldValue(globalVar->mName);
13518 if (result)
13519 {
13520 // We want to avoid 'unreachable code' issues from values that
13521 // are technically constant but change depending on compilation context
13522 if (mCurMethodState != NULL)
13523 {
13524 auto checkScope = mCurMethodState->mCurScope;
13525 while (checkScope != NULL)
13526 {
13527 checkScope->mSupressNextUnreachable = true;
13528 checkScope = checkScope->mPrevScope;
13529 }
13530 }
13531 return result;
13532 }
13533
13534 if (!mIsComptimeModule)
13535 return GetDefaultTypedValue(typedValue.mType);
13536 }
13537 }
13538
13539 if ((mIsComptimeModule) && (mCompiler->mCeMachine->mDebugger != NULL) && (mCompiler->mCeMachine->mDebugger->mCurDbgState != NULL))
13540 {
13541 auto ceDebugger = mCompiler->mCeMachine->mDebugger;
13542 auto ceContext = ceDebugger->mCurDbgState->mCeContext;
13543 auto activeFrame = ceDebugger->mCurDbgState->mActiveFrame;
13544
13545 auto ceTypedValue = ceDebugger->GetAddr(constantValue);
13546 if (ceTypedValue)
13547 {
13548 if ((typedValue.mType->IsObjectOrInterface()) || (typedValue.mType->IsPointer()) || (typedValue.mType->IsRef()))
13549 {
13550 void* data = ceContext->GetMemoryPtr((addr_ce)ceTypedValue.mAddr, sizeof(addr_ce));
13551 if (data == NULL)
13552 {
13553 Fail("Invalid address", refNode);
13554 return GetDefaultTypedValue(typedValue.mType);
13555 }

Callers 15

TryDevirtualizeCallMethod · 0.80
DoCaseExpressionMethod · 0.80
VisitMethod · 0.80
LoadLocalMethod · 0.80
LookupIdentifierMethod · 0.80
LoadPropertyMethod · 0.80
LoadFieldMethod · 0.80
LookupFieldMethod · 0.80
ResolveArgValuesMethod · 0.80
SplatArgsMethod · 0.80
PushArgMethod · 0.80

Calls 15

BfTypedValueClass · 0.85
FailFunction · 0.85
IsAddrMethod · 0.80
GetFakeValMethod · 0.80
GetMemoryPtrMethod · 0.80
CreateIntToPtrMethod · 0.80
MapTypeMethod · 0.80
CreateConstantMethod · 0.80
IsVolatileMethod · 0.80
IsValuelessTypeMethod · 0.45
IsVarMethod · 0.45
IsConstMethod · 0.45

Tested by

no test coverage detected