1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Support for "returnaddress" intrinsic

This commit is contained in:
Brian Fiete 2022-01-06 06:26:56 -05:00
parent eb7e78174c
commit 0826b6d49f
4 changed files with 13 additions and 0 deletions

View file

@ -92,6 +92,8 @@ namespace System
public static extern void* StdMalloc(int size); public static extern void* StdMalloc(int size);
[LinkName("free")] [LinkName("free")]
public static extern void StdFree(void* ptr); public static extern void StdFree(void* ptr);
[Intrinsic("returnaddress")]
public static extern void* GetReturnAddress(int32 level = 0);
[CallingConvention(.Cdecl)] [CallingConvention(.Cdecl)]
public static extern void* VirtualAlloc(int size, bool canExecute, bool canWrite); public static extern void* VirtualAlloc(int size, bool canExecute, bool canWrite);
[CallingConvention(.Cdecl)] [CallingConvention(.Cdecl)]

View file

@ -17697,6 +17697,14 @@ void BeMCContext::Generate(BeFunction* function)
useAltArgs = true; useAltArgs = true;
} }
break; break;
case BfIRIntrinsic_ReturnAddress:
{
result = AllocVirtualReg(intrin->mReturnType);
CreateDefineVReg(result);
auto vregInfo = GetVRegInfo(result);
vregInfo->mFrameOffset = 0;
}
break;
case BfIRIntrinsic_VAArg: case BfIRIntrinsic_VAArg:
{ {
auto mcListPtr = GetOperand(castedInst->mArgs[0].mValue); auto mcListPtr = GetOperand(castedInst->mArgs[0].mValue);

View file

@ -451,6 +451,7 @@ enum BfIRIntrinsic : uint8
BfIRIntrinsic_Or, BfIRIntrinsic_Or,
BfIRIntrinsic_Pow, BfIRIntrinsic_Pow,
BfIRIntrinsic_PowI, BfIRIntrinsic_PowI,
BfIRIntrinsic_ReturnAddress,
BfIRIntrinsic_Round, BfIRIntrinsic_Round,
BfIRIntrinsic_SAR, BfIRIntrinsic_SAR,
BfIRIntrinsic_SHL, BfIRIntrinsic_SHL,

View file

@ -181,6 +181,7 @@ static const BuiltinEntry gIntrinEntries[] =
{"or"}, {"or"},
{"pow"}, {"pow"},
{"powi"}, {"powi"},
{"returnaddress"},
{"round"}, {"round"},
{"sar"}, {"sar"},
{"shl"}, {"shl"},
@ -2684,6 +2685,7 @@ void BfIRCodeGen::HandleNextCmd()
{ (llvm::Intrinsic::ID)-2, -1}, // or { (llvm::Intrinsic::ID)-2, -1}, // or
{ llvm::Intrinsic::pow, 0, -1}, { llvm::Intrinsic::pow, 0, -1},
{ llvm::Intrinsic::powi, 0, -1}, { llvm::Intrinsic::powi, 0, -1},
{ llvm::Intrinsic::returnaddress, -1},
{ llvm::Intrinsic::round, 0, -1}, { llvm::Intrinsic::round, 0, -1},
{ (llvm::Intrinsic::ID)-2, -1}, // sar { (llvm::Intrinsic::ID)-2, -1}, // sar
{ (llvm::Intrinsic::ID)-2, -1}, // shl { (llvm::Intrinsic::ID)-2, -1}, // shl