mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Wasm calling convention fixes. IDEHelper/Tests runs on wasm now.
This commit is contained in:
parent
c0ebcc8fda
commit
31746c1f19
12 changed files with 99 additions and 13 deletions
|
@ -90,11 +90,12 @@ namespace System
|
||||||
|
|
||||||
static function void(StringView str) OutString = => OutString_Simple;
|
static function void(StringView str) OutString = => OutString_Simple;
|
||||||
|
|
||||||
#if !BF_RUNTIME_DISABLE
|
#if !BF_RUNTIME_DISABLE && !BF_PLATFORM_WASM
|
||||||
private static extern void PutChars(char8* c, int32 len);
|
private static extern void PutChars(char8* c, int32 len);
|
||||||
#else
|
#else
|
||||||
[CLink]
|
[CLink]
|
||||||
private static extern void putchar(char8 c);
|
private static extern int32 putchar(char8 c);
|
||||||
|
[LinkName("Console_PutChars")]
|
||||||
private static void PutChars(char8* c, int32 len)
|
private static void PutChars(char8* c, int32 len)
|
||||||
{
|
{
|
||||||
for (int i < len)
|
for (int i < len)
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace System
|
||||||
[CRepr]
|
[CRepr]
|
||||||
struct VarArgs
|
struct VarArgs
|
||||||
{
|
{
|
||||||
#if BF_PLATFORM_WINDOWS
|
#if BF_PLATFORM_WINDOWS || BF_PLATFORM_WASM
|
||||||
void* mVAList;
|
void* mVAList;
|
||||||
#else
|
#else
|
||||||
int[5] mVAList; // Conservative size for va_list
|
int[5] mVAList; // Conservative size for va_list
|
||||||
|
@ -67,7 +67,7 @@ namespace System
|
||||||
|
|
||||||
public void* ToVAList() mut
|
public void* ToVAList() mut
|
||||||
{
|
{
|
||||||
#if BF_PLATFORM_WINDOWS
|
#if BF_PLATFORM_WINDOWS || BF_PLATFORM_WASM
|
||||||
return mVAList;
|
return mVAList;
|
||||||
#else
|
#else
|
||||||
return &mVAList;
|
return &mVAList;
|
||||||
|
@ -101,6 +101,8 @@ namespace System
|
||||||
|
|
||||||
#if BF_PLATFORM_WASM
|
#if BF_PLATFORM_WASM
|
||||||
static int32 sTestIdx;
|
static int32 sTestIdx;
|
||||||
|
static int32 sRanTestCount;
|
||||||
|
static int32 sErrorCount;
|
||||||
class TestEntry
|
class TestEntry
|
||||||
{
|
{
|
||||||
public String mName ~ delete _;
|
public String mName ~ delete _;
|
||||||
|
@ -155,6 +157,7 @@ namespace System
|
||||||
[CallingConvention(.Cdecl), LinkName("Test_Error_Wasm")]
|
[CallingConvention(.Cdecl), LinkName("Test_Error_Wasm")]
|
||||||
static void Test_Error(char8* error)
|
static void Test_Error(char8* error)
|
||||||
{
|
{
|
||||||
|
sErrorCount++;
|
||||||
Debug.WriteLine(scope $"TEST ERROR: {StringView(error)}");
|
Debug.WriteLine(scope $"TEST ERROR: {StringView(error)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +183,22 @@ namespace System
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sRanTestCount++;
|
||||||
return sTestIdx++;
|
return sTestIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
[CallingConvention(.Cdecl), LinkName("Test_Finish_Wasm")]
|
[CallingConvention(.Cdecl), LinkName("Test_Finish_Wasm")]
|
||||||
static void Test_Finish()
|
static void Test_Finish()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Tests done.");
|
sRanTestCount--;
|
||||||
|
|
||||||
|
String completeStr = scope $"Completed {sRanTestCount} of {sTestEntries.Count} tests.'";
|
||||||
|
Debug.WriteLine(completeStr);
|
||||||
|
if (sErrorCount > 0)
|
||||||
|
{
|
||||||
|
String failStr = scope $"ERROR: Failed {sErrorCount} test{((sErrorCount != 1) ? "s" : "")}";
|
||||||
|
Debug.WriteLine(failStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
[CallingConvention(.Cdecl)]
|
[CallingConvention(.Cdecl)]
|
||||||
|
|
|
@ -10881,6 +10881,9 @@ namespace IDE
|
||||||
case "VSToolPath_x64":
|
case "VSToolPath_x64":
|
||||||
newString = gApp.mSettings.mVSSettings.mBin64Path;
|
newString = gApp.mSettings.mVSSettings.mBin64Path;
|
||||||
IDEUtils.FixFilePath(newString);
|
IDEUtils.FixFilePath(newString);
|
||||||
|
case "EmccPath":
|
||||||
|
newString = scope:ReplaceBlock String();
|
||||||
|
newString.AppendF($"{gApp.mSettings.mEmscriptenPath}/upstream/emscripten/emcc.bat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma warning disable 168
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -1601,6 +1603,14 @@ namespace IDE.ui
|
||||||
floatVal.ToString(valStr);
|
floatVal.ToString(valStr);
|
||||||
valueItem.Label = valStr;
|
valueItem.Label = valStr;
|
||||||
}
|
}
|
||||||
|
else if (curVariantType == typeof(Workspace.ConfigSelection))
|
||||||
|
{
|
||||||
|
var platformItem = (DarkListViewItem)propEntry.mListViewItem.GetSubItem(2);
|
||||||
|
|
||||||
|
var configSelection = propEntry.mCurValue.Get<Workspace.ConfigSelection>();
|
||||||
|
valueItem.Label = configSelection.mConfig;
|
||||||
|
platformItem.Label = configSelection.mPlatform;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ThrowUnimplemented();
|
ThrowUnimplemented();
|
||||||
//valueItem.Label = ToStackString!(propEntry.mCurValue);
|
//valueItem.Label = ToStackString!(propEntry.mCurValue);
|
||||||
|
|
|
@ -14018,7 +14018,14 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
|
||||||
else if ((closureTypeInst != NULL) && (captureThisByValue))
|
else if ((closureTypeInst != NULL) && (captureThisByValue))
|
||||||
{
|
{
|
||||||
// When we need to aggregrate a splat for a target, we just point out delegate's mTarget to inside ourselves where we aggregated the value
|
// When we need to aggregrate a splat for a target, we just point out delegate's mTarget to inside ourselves where we aggregated the value
|
||||||
auto fieldPtr = mModule->mBfIRBuilder->CreateInBoundsGEP(mResult.mValue, 0, 1);
|
int dataIdx = 1;
|
||||||
|
if (!closureTypeInst->mFieldInstances.IsEmpty())
|
||||||
|
{
|
||||||
|
auto& fieldInst = closureTypeInst->mFieldInstances[0];
|
||||||
|
BF_ASSERT(fieldInst.GetFieldDef()->mName == "__this");
|
||||||
|
dataIdx = fieldInst.mDataIdx;
|
||||||
|
}
|
||||||
|
auto fieldPtr = mModule->mBfIRBuilder->CreateInBoundsGEP(mResult.mValue, 0, dataIdx);
|
||||||
target = mModule->LoadValue(target);
|
target = mModule->LoadValue(target);
|
||||||
mModule->mBfIRBuilder->CreateStore(target.mValue, fieldPtr);
|
mModule->mBfIRBuilder->CreateStore(target.mValue, fieldPtr);
|
||||||
target = BfTypedValue(fieldPtr, target.mType, true);
|
target = BfTypedValue(fieldPtr, target.mType, true);
|
||||||
|
|
|
@ -1259,7 +1259,7 @@ void BfModule::SetupIRBuilder(bool dbgVerifyCodeGen)
|
||||||
//mBfIRBuilder->mDbgVerifyCodeGen = true;
|
//mBfIRBuilder->mDbgVerifyCodeGen = true;
|
||||||
if (
|
if (
|
||||||
(mModuleName == "-")
|
(mModuleName == "-")
|
||||||
|| (mModuleName == "")
|
//|| (mModuleName == "")
|
||||||
//|| (mModuleName == "Tests_FuncRefs")
|
//|| (mModuleName == "Tests_FuncRefs")
|
||||||
)
|
)
|
||||||
mBfIRBuilder->mDbgVerifyCodeGen = true;
|
mBfIRBuilder->mDbgVerifyCodeGen = true;
|
||||||
|
|
|
@ -1801,11 +1801,11 @@ void BfTypeInstance::Dispose()
|
||||||
mTypeDef = NULL;
|
mTypeDef = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BfTypeInstance::GetSplatCount()
|
int BfTypeInstance::GetSplatCount(bool force)
|
||||||
{
|
{
|
||||||
if (IsValuelessType())
|
if (IsValuelessType())
|
||||||
return 0;
|
return 0;
|
||||||
if (!mIsSplattable)
|
if ((!mIsSplattable) && (!force))
|
||||||
return 1;
|
return 1;
|
||||||
int splatCount = 0;
|
int splatCount = 0;
|
||||||
BfTypeUtils::SplatIterate([&](BfType* checkType) { splatCount++; }, this);
|
BfTypeUtils::SplatIterate([&](BfType* checkType) { splatCount++; }, this);
|
||||||
|
@ -2048,6 +2048,30 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo
|
||||||
|
|
||||||
bool deepCheck = false;
|
bool deepCheck = false;
|
||||||
|
|
||||||
|
if (mModule->mCompiler->mOptions.mMachineType == BfMachineType_Wasm32)
|
||||||
|
{
|
||||||
|
if (IsComposite())
|
||||||
|
{
|
||||||
|
if (GetSplatCount(true) == 1)
|
||||||
|
{
|
||||||
|
BfType* componentType = NULL;
|
||||||
|
BfTypeUtils::SplatIterate([&](BfType* checkType) { componentType = checkType; }, this);
|
||||||
|
if (componentType != NULL)
|
||||||
|
{
|
||||||
|
if (componentType->IsPrimitiveType())
|
||||||
|
{
|
||||||
|
auto primType = (BfPrimitiveType*)componentType;
|
||||||
|
if (outTypeCode != NULL)
|
||||||
|
*outTypeCode = primType->mTypeDef->mTypeCode;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mModule->mCompiler->mOptions.mPlatformType == BfPlatformType_Windows)
|
if (mModule->mCompiler->mOptions.mPlatformType == BfPlatformType_Windows)
|
||||||
{
|
{
|
||||||
// Odd Windows rule: composite returns for non-static methods are always sret
|
// Odd Windows rule: composite returns for non-static methods are always sret
|
||||||
|
|
|
@ -553,7 +553,7 @@ public:
|
||||||
virtual bool IsSpecializedByAutoCompleteMethod() { return false; }
|
virtual bool IsSpecializedByAutoCompleteMethod() { return false; }
|
||||||
virtual bool IsUnspecializedTypeVariation() { return false; }
|
virtual bool IsUnspecializedTypeVariation() { return false; }
|
||||||
virtual bool IsSplattable() { return false; }
|
virtual bool IsSplattable() { return false; }
|
||||||
virtual int GetSplatCount() { return 1; }
|
virtual int GetSplatCount(bool force = false) { return 1; }
|
||||||
virtual bool IsVoid() { return false; }
|
virtual bool IsVoid() { return false; }
|
||||||
virtual bool IsVoidPtr() { return false; }
|
virtual bool IsVoidPtr() { return false; }
|
||||||
virtual bool CanBeValuelessType() { return false; }
|
virtual bool CanBeValuelessType() { return false; }
|
||||||
|
@ -2134,7 +2134,7 @@ public:
|
||||||
virtual bool IsFinishingType() override { return mIsFinishingType; }
|
virtual bool IsFinishingType() override { return mIsFinishingType; }
|
||||||
virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); }
|
virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); }
|
||||||
virtual bool IsSplattable() override { BF_ASSERT((mInstSize >= 0) || (!IsComposite())); return mIsSplattable; }
|
virtual bool IsSplattable() override { BF_ASSERT((mInstSize >= 0) || (!IsComposite())); return mIsSplattable; }
|
||||||
virtual int GetSplatCount() override;
|
virtual int GetSplatCount(bool force = false) override;
|
||||||
virtual bool IsTypeInstance() override { return true; }
|
virtual bool IsTypeInstance() override { return true; }
|
||||||
virtual BfTypeCode GetTypeCode() override { return mTypeDef->mTypeCode; }
|
virtual BfTypeCode GetTypeCode() override { return mTypeDef->mTypeCode; }
|
||||||
virtual bool IsInterface() override { return mTypeDef->mTypeCode == BfTypeCode_Interface; }
|
virtual bool IsInterface() override { return mTypeDef->mTypeCode == BfTypeCode_Interface; }
|
||||||
|
@ -2465,7 +2465,7 @@ public:
|
||||||
virtual bool IsComposite() override { return true; }
|
virtual bool IsComposite() override { return true; }
|
||||||
virtual bool IsMethodRef() override { return true; }
|
virtual bool IsMethodRef() override { return true; }
|
||||||
virtual bool IsSplattable() override { return true; }
|
virtual bool IsSplattable() override { return true; }
|
||||||
virtual int GetSplatCount() override { return (int)mDataToParamIdx.mSize; }
|
virtual int GetSplatCount(bool force) override { return (int)mDataToParamIdx.mSize; }
|
||||||
|
|
||||||
virtual bool IsOnDemand() override { return true; }
|
virtual bool IsOnDemand() override { return true; }
|
||||||
virtual bool IsTemporary() override { return true; }
|
virtual bool IsTemporary() override { return true; }
|
||||||
|
|
|
@ -19,3 +19,7 @@ PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)
|
||||||
[Configs.Test.macOS]
|
[Configs.Test.macOS]
|
||||||
OtherLinkFlags = "$(LinkFlags) $(ProjectDir)/CLib/main.o"
|
OtherLinkFlags = "$(LinkFlags) $(ProjectDir)/CLib/main.o"
|
||||||
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)/CLib/main.o"]
|
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)/CLib/main.o"]
|
||||||
|
|
||||||
|
[Configs.Test.wasm32]
|
||||||
|
OtherLinkFlags = "$(LinkFlags) $(ProjectDir)/CLib/main_wasm.o -sSTACK_SIZE=1048576"
|
||||||
|
PreBuildCmds = ["$(EmccPath) $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)/CLib/main_wasm.o"]
|
||||||
|
|
|
@ -11,6 +11,11 @@ IntermediateType = "ObjectAndIRCode"
|
||||||
[Configs.Debug.Win32]
|
[Configs.Debug.Win32]
|
||||||
IntermediateType = "ObjectAndIRCode"
|
IntermediateType = "ObjectAndIRCode"
|
||||||
|
|
||||||
|
[Configs.Debug.wasm32]
|
||||||
|
AllocType = "CRT"
|
||||||
|
EnableObjectDebugFlags = false
|
||||||
|
EmitObjectAccessCheck = false
|
||||||
|
|
||||||
[Configs.Test.Win64]
|
[Configs.Test.Win64]
|
||||||
IntermediateType = "ObjectAndIRCode"
|
IntermediateType = "ObjectAndIRCode"
|
||||||
COptimizationLevel = "O2"
|
COptimizationLevel = "O2"
|
||||||
|
@ -26,6 +31,12 @@ COptimizationLevel = "O2"
|
||||||
ConfigSelections = {TestsB = {Config = "Test"}}
|
ConfigSelections = {TestsB = {Config = "Test"}}
|
||||||
|
|
||||||
[Configs.Test.Win32]
|
[Configs.Test.Win32]
|
||||||
|
ConfigSelections = {TestsB = {Config = "Test"}}
|
||||||
|
|
||||||
|
[Configs.Test.wasm32]
|
||||||
|
AllocType = "CRT"
|
||||||
|
EnableObjectDebugFlags = false
|
||||||
|
EmitObjectAccessCheck = false
|
||||||
IntermediateType = "ObjectAndIRCode"
|
IntermediateType = "ObjectAndIRCode"
|
||||||
ConfigSelections = {TestsB = {Config = "Test"}}
|
ConfigSelections = {TestsB = {Config = "Test"}}
|
||||||
|
|
||||||
|
@ -50,3 +61,13 @@ EmitObjectAccessCheck = false
|
||||||
EnableRealtimeLeakCheck = false
|
EnableRealtimeLeakCheck = false
|
||||||
AllocStackTraceDepth = 0
|
AllocStackTraceDepth = 0
|
||||||
COptimizationLevel = "O2"
|
COptimizationLevel = "O2"
|
||||||
|
|
||||||
|
[Configs.TestFail.wasm32]
|
||||||
|
AllocType = "CRT"
|
||||||
|
EnableObjectDebugFlags = false
|
||||||
|
EmitObjectAccessCheck = false
|
||||||
|
|
||||||
|
[Configs.Paranoid.wasm32]
|
||||||
|
AllocType = "CRT"
|
||||||
|
EnableObjectDebugFlags = false
|
||||||
|
EmitObjectAccessCheck = false
|
||||||
|
|
|
@ -92,6 +92,7 @@ namespace Tests
|
||||||
Test.Assert(ptr[i] == data[i]);
|
Test.Assert(ptr[i] == data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||||
[Test]
|
[Test]
|
||||||
public static void Test()
|
public static void Test()
|
||||||
{
|
{
|
||||||
|
@ -129,5 +130,6 @@ namespace Tests
|
||||||
Test.Assert(cf.mC == 234);
|
Test.Assert(cf.mC == 234);
|
||||||
cf.mB.Append('!', 2048);
|
cf.mB.Append('!', 2048);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,7 @@ namespace Tests
|
||||||
Test.Assert(t.InstanceSize == 8);
|
Test.Assert(t.InstanceSize == 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !BF_PLATFORM_WASM
|
||||||
[Test]
|
[Test]
|
||||||
static void TestA()
|
static void TestA()
|
||||||
{
|
{
|
||||||
|
@ -683,5 +684,6 @@ namespace Tests
|
||||||
fieldIdx++;
|
fieldIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue