mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
var-return support for const eval methods
This commit is contained in:
parent
585e2575e8
commit
706fe9e04b
15 changed files with 292 additions and 60 deletions
|
@ -379,9 +379,11 @@ BeType* BeIRCodeGen::GetBeType(BfTypeCode typeCode, bool& isSigned)
|
|||
else
|
||||
return llvm::Type::getInt64Ty(*mLLVMContext);*/
|
||||
case BfTypeCode_Float:
|
||||
isSigned = true;
|
||||
beTypeCode = BeTypeCode_Float;
|
||||
break;
|
||||
case BfTypeCode_Double:
|
||||
isSigned = true;
|
||||
beTypeCode = BeTypeCode_Double;
|
||||
break;
|
||||
}
|
||||
|
@ -2330,6 +2332,13 @@ void BeIRCodeGen::HandleNextCmd()
|
|||
SetResult(curId, mBeModule->CreateRet(val));
|
||||
}
|
||||
break;
|
||||
case BfIRCmd_CreateSetRet:
|
||||
{
|
||||
CMD_PARAM(BeValue*, val);
|
||||
CMD_PARAM(int, returnTypeId);
|
||||
SetResult(curId, mBeModule->CreateSetRet(val, returnTypeId));
|
||||
}
|
||||
break;
|
||||
case BfIRCmd_CreateRetVoid:
|
||||
{
|
||||
mBeModule->CreateRetVoid();
|
||||
|
@ -2433,7 +2442,9 @@ void BeIRCodeGen::HandleNextCmd()
|
|||
}
|
||||
else
|
||||
{
|
||||
if (attribute == BFIRAttribute_AlwaysInline)
|
||||
if (attribute == BfIRAttribute_VarRet)
|
||||
func->mIsVarReturn = true;
|
||||
else if (attribute == BFIRAttribute_AlwaysInline)
|
||||
func->mAlwaysInline = true;
|
||||
else if (attribute == BFIRAttribute_NoUnwind)
|
||||
func->mNoUnwind = true;
|
||||
|
@ -3483,3 +3494,33 @@ BeType* BeIRCodeGen::GetBeTypeById(int id)
|
|||
{
|
||||
return GetTypeEntry(id).mBeType;
|
||||
}
|
||||
|
||||
BeState BeIRCodeGen::GetState()
|
||||
{
|
||||
BeState state;
|
||||
state.mActiveFunction = mActiveFunction;
|
||||
state.mSavedDebugLocs = mSavedDebugLocs;
|
||||
state.mHasDebugLoc = mHasDebugLoc;
|
||||
|
||||
state.mActiveBlock = mBeModule->mActiveBlock;
|
||||
state.mInsertPos = mBeModule->mInsertPos;
|
||||
state.mCurDbgLoc = mBeModule->mCurDbgLoc;
|
||||
state.mPrevDbgLocInline = mBeModule->mPrevDbgLocInline;
|
||||
state.mLastDbgLoc = mBeModule->mLastDbgLoc;
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void BeIRCodeGen::SetState(const BeState& state)
|
||||
{
|
||||
mActiveFunction = state.mActiveFunction;
|
||||
mBeModule->mActiveFunction = mActiveFunction;
|
||||
mSavedDebugLocs = state.mSavedDebugLocs;
|
||||
mHasDebugLoc = state.mHasDebugLoc;
|
||||
|
||||
mBeModule->mActiveBlock = state.mActiveBlock;
|
||||
mBeModule->mInsertPos = state.mInsertPos;
|
||||
mBeModule->mCurDbgLoc = state.mCurDbgLoc;
|
||||
mBeModule->mPrevDbgLocInline = state.mPrevDbgLocInline;
|
||||
mBeModule->mLastDbgLoc = state.mLastDbgLoc;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,19 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class BeState
|
||||
{
|
||||
public:
|
||||
BeFunction* mActiveFunction;
|
||||
Array<BeDbgLoc*> mSavedDebugLocs;
|
||||
bool mHasDebugLoc;
|
||||
|
||||
BeBlock* mActiveBlock;
|
||||
int mInsertPos;
|
||||
BeDbgLoc* mCurDbgLoc;
|
||||
BeDbgLoc* mPrevDbgLocInline;
|
||||
BeDbgLoc* mLastDbgLoc;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class CmdParamVec : public SizedArray<T, 8>
|
||||
|
@ -139,6 +152,9 @@ public:
|
|||
BeMDNode* GetBeMetadata(int streamId);
|
||||
|
||||
BeType* GetBeTypeById(int id);
|
||||
|
||||
BeState GetState();
|
||||
void SetState(const BeState& state);
|
||||
};
|
||||
|
||||
NS_BF_END
|
|
@ -2349,6 +2349,7 @@ String BeModule::ToString(BeFunction* wantFunc)
|
|||
str += " void";
|
||||
}
|
||||
break;
|
||||
DISPLAY_INST2(BeSetRetInst, "setret", mRetValue, mReturnTypeId);
|
||||
case BeCallInst::TypeId:
|
||||
{
|
||||
auto castedInst = (BeCallInst*)inst;
|
||||
|
@ -3383,6 +3384,15 @@ BeRetInst* BeModule::CreateRet(BeValue* value)
|
|||
return inst;
|
||||
}
|
||||
|
||||
BeSetRetInst* BeModule::CreateSetRet(BeValue* value, int returnTypeId)
|
||||
{
|
||||
auto inst = mAlloc.Alloc<BeSetRetInst>();
|
||||
inst->mRetValue = value;
|
||||
inst->mReturnTypeId = returnTypeId;
|
||||
AddInst(inst);
|
||||
return inst;
|
||||
}
|
||||
|
||||
BeCallInst* BeModule::CreateCall(BeValue* func, const SizedArrayImpl<BeValue*>& args)
|
||||
{
|
||||
auto inst = mOwnedValues.Alloc<BeCallInst>();
|
||||
|
|
|
@ -518,6 +518,7 @@ public:
|
|||
String mName;
|
||||
#endif
|
||||
BfIRLinkageType mLinkageType;
|
||||
bool mIsVarReturn;
|
||||
bool mAlwaysInline;
|
||||
bool mNoUnwind;
|
||||
bool mUWTable;
|
||||
|
@ -539,6 +540,7 @@ public:
|
|||
mLinkageType = BfIRLinkageType_External;
|
||||
mModule = NULL;
|
||||
mDbgFunction = NULL;
|
||||
mIsVarReturn = false;
|
||||
mAlwaysInline = false;
|
||||
mDidInlinePass = false;
|
||||
mNoUnwind = false;
|
||||
|
@ -1265,6 +1267,15 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class BeSetRetInst : public BeRetInst
|
||||
{
|
||||
public:
|
||||
BE_VALUE_TYPE(BeSetRetInst, BeRetInst);
|
||||
|
||||
public:
|
||||
int32 mReturnTypeId;
|
||||
};
|
||||
|
||||
class BeCallInst : public BeInst
|
||||
{
|
||||
public:
|
||||
|
@ -2311,6 +2322,7 @@ public:
|
|||
BeCondBrInst* CreateCondBr(BeValue* cond, BeBlock* trueBlock, BeBlock* falseBlock);
|
||||
BeRetInst* CreateRetVoid();
|
||||
BeRetInst* CreateRet(BeValue* value);
|
||||
BeSetRetInst* CreateSetRet(BeValue* value, int returnTypeId);
|
||||
BeCallInst* CreateCall(BeValue* func, const SizedArrayImpl<BeValue*>& args);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue