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

Added changes to support CompilerExplorer

This commit is contained in:
Brian Fiete 2019-10-11 05:58:08 -07:00
parent c97b074fee
commit c9e0ab6089
20 changed files with 389 additions and 156 deletions

View file

@ -47,36 +47,58 @@ int main(int argc, char* argv[])
gApp = new BootApp();
/*for (int i = 0; i < argc; i++)
{
if (i != 0)
std::cout << " ";
std::cout << argv[i];
}
std::cout << std::endl;*/
String cmd;
bool success = true;
for (int i = 1; i < argc; i++)
{
std::string arg = argv[i];
String arg = argv[i];
if (arg.StartsWith("--"))
arg.Remove(0, 1);
if (!cmd.IsEmpty())
{
cmd.Append('=');
arg.Insert(0, cmd);
cmd.Clear();
}
if (arg[0] == '"')
{
arg.erase(0, 1);
arg.Remove(0, 1);
if ((arg.length() > 1) && (arg[arg.length() - 1] == '"'))
arg.erase(arg.length() - 1);
arg.RemoveToEnd(arg.length() - 1);
success &= gApp->HandleCmdLine(arg, "");
continue;
}
int eqPos = (int)arg.find('=');
int eqPos = (int)arg.IndexOf('=');
if (eqPos == -1)
{
success &= gApp->HandleCmdLine(arg, "");
continue;
}
std::string cmd = arg.substr(0, eqPos);
std::string param = arg.substr(eqPos + 1);
cmd = arg.Substring(0, eqPos);
if (eqPos == arg.length() - 1)
continue;
String param = arg.Substring(eqPos + 1);
if ((param.length() > 1) && (param[0] == '"'))
{
param.erase(0, 1);
param.Remove(0, 1);
if ((param.length() > 1) && (param[param.length() - 1] == '"'))
param.erase(param.length() - 1);
param.Remove(param.length() - 1);
}
success &= gApp->HandleCmdLine(cmd, param);
cmd.Clear();
}
if (!gApp->mShowedHelp)

View file

@ -76,7 +76,7 @@ BF_IMPORT void BF_CALLTYPE BfSystem_AddTypeOptions(void* bfSystem, const char* f
BF_IMPORT void BF_CALLTYPE BfProject_SetDisabled(void* bfProject, bool disabled);
BF_IMPORT void BF_CALLTYPE BfProject_SetOptions(void* bfProject, int targetType, const char* startupObject, const char* preprocessorMacros,
int optLevel, int ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP);
int optLevel, int ltoType, int32 flags);
BF_IMPORT void BF_CALLTYPE BfProject_ClearDependencies(void* bfProject);
BF_IMPORT void BF_CALLTYPE BfProject_AddDependency(void* bfProject, void* depProject);
@ -169,6 +169,10 @@ BootApp::BootApp()
mSystem = NULL;
mCompiler = NULL;
mProject = NULL;
mCELibProject = NULL;
mIsCERun = false;
mAsmKind = BfAsmKind_None;
mStartupObject = "Program";
#ifdef BF_PLATFORM_WINDOWS
mOptLevel = BfOptLevel_OgPlus;
@ -246,19 +250,25 @@ bool BootApp::HandleCmdLine(const String &cmd, const String& param)
bool wantedParam = false;
if ((cmd == "--help") || (cmd == "-h") || (cmd == "/?"))
if ((!cmd.StartsWith("-")) && (mIsCERun) && (mCESrc.IsEmpty()))
{
mCESrc = cmd;
return true;
}
if ((cmd == "-help") || (cmd == "-h") || (cmd == "/?"))
{
mShowedHelp = true;
std::cout << "BeefBoot - Beef bootstrapping tool" << std::endl;
return false;
}
else if (cmd == "--src")
else if (cmd == "-src")
{
mRequestedSrc.Add(param);
wantedParam = true;
}
else if (cmd == "--verbosity")
else if (cmd == "-verbosity")
{
if (param == "quiet")
mVerbosity = Verbosity_Quiet;
@ -277,24 +287,34 @@ bool BootApp::HandleCmdLine(const String &cmd, const String& param)
}
wantedParam = true;
}
else if (cmd == "--define")
else if (cmd == "-version")
{
BfpSystemResult sysResult;
String exePath;
BFP_GETSTR_HELPER(exePath, sysResult, BfpSystem_GetExecutablePath(__STR, __STRLEN, &sysResult));
std::cout << "0.0.0" << std::endl;
mShowedHelp = true;
return true;
}
else if (cmd == "-define")
{
if (!mDefines.IsEmpty())
mDefines += "\n";
mDefines += param;
wantedParam = true;
}
else if (cmd == "--startup")
else if (cmd == "-startup")
{
mStartupObject = param;
wantedParam = true;
}
else if (cmd == "--out")
else if (cmd == "-out")
{
mTargetPath = param;
wantedParam = true;
}
else if (cmd == "--linkparams")
else if (cmd == "-linkparams")
{
mLinkParams = param;
wantedParam = true;
@ -327,6 +347,31 @@ bool BootApp::HandleCmdLine(const String &cmd, const String& param)
{
mEmitIR = true;
}
else if (cmd == "-cedest")
{
mIsCERun = true;
mCEDest = param;
wantedParam = true;
}
else if (cmd == "-cesrc")
{
mIsCERun = true;
}
else if (cmd == "-emitasm")
{
if (param.IsEmpty())
{
mAsmKind = BfAsmKind_Intel;
}
else
{
if (param == "att")
mAsmKind = BfAsmKind_ATT;
else
mAsmKind = BfAsmKind_Intel;
wantedParam = true;
}
}
else
{
Fail("Unknown option: " + cmd);
@ -353,7 +398,7 @@ bool BootApp::Init()
mWorkingDir = cwdPtr;
free(cwdPtr);
if (mTargetPath.IsEmpty())
if ((mTargetPath.IsEmpty()) && (mCESrc.IsEmpty()))
{
Fail("'Out' path not specified");
}
@ -366,7 +411,7 @@ bool BootApp::Init()
return !mHadErrors;
}
void BootApp::QueueFile(const StringImpl& path)
void BootApp::QueueFile(const StringImpl& path, void* project)
{
String ext;
ext = GetFileExtension(path);
@ -382,7 +427,7 @@ void BootApp::QueueFile(const StringImpl& path)
}
bool worked = true;
void* bfParser = BfSystem_CreateParser(mSystem, mProject);
void* bfParser = BfSystem_CreateParser(mSystem, project);
BfParser_SetSource(bfParser, data, len, path.c_str());
//bfParser.SetCharIdData(charIdData);
worked &= BfParser_Parse(bfParser, mPassInstance, false);
@ -404,7 +449,7 @@ void BootApp::QueuePath(const StringImpl& path)
String fileName;
fileName = GetFileName(filePath);
QueueFile(filePath);
QueueFile(filePath, (mCELibProject != NULL) ? mCELibProject : mProject);
}
for (auto& fileEntry : FileEnumerator(path, FileEnumerator::Flags_Directories))
@ -421,7 +466,7 @@ void BootApp::QueuePath(const StringImpl& path)
}
else
{
QueueFile(path);
QueueFile(path, mProject);
}
}
@ -678,7 +723,6 @@ void BootApp::DoLinkMS()
BfpSpawnFlags flags = BfpSpawnFlag_None;
if (true)
{
//if (linkLine.HasMultibyteChars())
if (true)
flags = (BfpSpawnFlags)(BfpSpawnFlag_UseArgsFile | BfpSpawnFlag_UseArgsFile_Native | BfpSpawnFlag_UseArgsFile_BOM);
else
@ -739,9 +783,19 @@ bool BootApp::Compile()
int dotPos = (int)projectName.IndexOf('.');
if (dotPos != -1)
projectName.RemoveToEnd(dotPos);
if (projectName.IsEmpty())
projectName.Append("BeefProject");
mProject = BfSystem_CreateProject(mSystem, projectName.c_str());
if (mIsCERun)
{
mCELibProject = BfSystem_CreateProject(mSystem, "BeefLib");
BfProjectFlags flags = BfProjectFlags_None;
BfProject_SetOptions(mCELibProject, BfTargetType_BeefLib, "", mDefines.c_str(), mOptLevel, 0, flags);
}
if (!mDefines.IsEmpty())
mDefines.Append("\n");
mDefines.Append("BF_64_BIT");
@ -750,7 +804,19 @@ bool BootApp::Compile()
mDefines.Append(BF_PLATFORM_NAME);
int ltoType = 0;
BfProject_SetOptions(mProject, mTargetType, mStartupObject.c_str(), mDefines.c_str(), mOptLevel, ltoType, false, false, false, false);
BfProjectFlags flags = BfProjectFlags_None;
if (mIsCERun)
{
flags = (BfProjectFlags)(flags | BfProjectFlags_SingleModule | BfProjectFlags_AlwaysIncludeAll);
if (mAsmKind == BfAsmKind_ATT)
flags = (BfProjectFlags)(flags | BfProjectFlags_AsmOutput | BfProjectFlags_AsmOutput_ATT);
else if (mAsmKind == BfAsmKind_Intel)
flags = (BfProjectFlags)(flags | BfProjectFlags_AsmOutput);
}
BfProject_SetOptions(mProject, mTargetType, mStartupObject.c_str(), mDefines.c_str(), mOptLevel, ltoType, flags);
if (mCELibProject != NULL)
BfProject_AddDependency(mProject, mCELibProject);
mPassInstance = BfSystem_CreatePassInstance(mSystem);
@ -762,18 +828,23 @@ bool BootApp::Compile()
mBuildDir = GetFileDir(exePath) + "/build";
RecursiveCreateDirectory(mBuildDir + "/" + projectName);
if (mIsCERun)
RecursiveCreateDirectory(mBuildDir + "/BeefLib");
BfCompilerOptionFlags optionFlags = (BfCompilerOptionFlags)(BfCompilerOptionFlag_EmitDebugInfo | BfCompilerOptionFlag_EmitLineInfo | BfCompilerOptionFlag_GenerateOBJ);
if (mEmitIR)
optionFlags = (BfCompilerOptionFlags)(optionFlags | BfCompilerOptionFlag_WriteIR);
int maxWorkerThreads = BfpSystem_GetNumLogicalCPUs(NULL);
if (maxWorkerThreads <= 1)
maxWorkerThreads = 6;
BfCompiler_SetOptions(mCompiler, NULL, 0, BfMachineType_x64, mToolset, BfSIMDSetting_SSE2, 1, maxWorkerThreads, optionFlags, "malloc", "free");
if (mIsCERun)
{
QueueFile(mCESrc, mProject);
}
for (auto& srcName : mRequestedSrc)
{
String absPath = GetAbsPath(srcName, mWorkingDir);
@ -784,6 +855,51 @@ bool BootApp::Compile()
{
DoCompile();
OutputLine(StrFormat("TIMING: Beef compiling: %0.1fs", (BFTickCount() - startTick) / 1000.0), OutputPri_Normal);
if (!mCEDest.IsEmpty())
{
String ext;
String srcResult = mBuildDir + "/BeefProject/BeefProject";
if (mAsmKind == BfAsmKind_None)
srcResult += BF_OBJ_EXT;
else
srcResult += ".s";
BfpFileResult result = BfpFileResult_Ok;
BfpFile_Copy(srcResult.c_str(), mCEDest.c_str(), BfpFileCopyKind_Always, &result);
if (result != BfpFileResult_Ok)
{
Fail(StrFormat("Failed to copy '%s' to '%s'", srcResult.c_str(), mCEDest.c_str()));
}
}
if ((mIsCERun) && (mEmitIR))
{
String ext;
String srcResult = mBuildDir + "/BeefProject/BeefProject";
String irDestPath = mCEDest;
int dotPos = (int)irDestPath.LastIndexOf('.');
if (dotPos != -1)
irDestPath.RemoveToEnd(dotPos);
if (mOptLevel == BfOptLevel_OgPlus)
{
srcResult += ".beir";
irDestPath += ".ll";
}
else
{
srcResult += ".ll";
irDestPath += ".ll";
}
BfpFileResult result = BfpFileResult_Ok;
BfpFile_Copy(srcResult.c_str(), irDestPath.c_str(), BfpFileCopyKind_Always, &result);
if (result != BfpFileResult_Ok)
{
Fail(StrFormat("Failed to copy '%s' to '%s'", srcResult.c_str(), mCEDest.c_str()));
}
}
}
while (true)
@ -820,7 +936,7 @@ bool BootApp::Compile()
OutputLine(msg);
}
if (!mHadErrors)
if ((!mHadErrors) && (!mTargetPath.IsEmpty()))
{
if (mVerbosity == Verbosity_Normal)
{

View file

@ -48,18 +48,24 @@ public:
String mStartupObject;
String mTargetPath;
String mLinkParams;
BfAsmKind mAsmKind;
void* mSystem;
void* mCompiler;
void* mProject;
void* mPassInstance;
bool mIsCERun;
void* mCELibProject;
String mCESrc;
String mCEDest;
public:
void Fail(const String & error);
void OutputLine(const String& text, OutputPri outputPri = OutputPri_Normal);
bool QueueRun(const String& fileName, const String& args, const String& workingDir, BfpSpawnFlags extraFlags);
void QueueFile(const StringImpl& path);
void QueueFile(const StringImpl& path, void* project);
void QueuePath(const StringImpl& path);
void DoCompile();
void DoLinkMS();

View file

@ -5,6 +5,10 @@ Dependencies = {Beefy2D = "*", corlib = "*"}
Name = "BeefBuild"
StartupObject = "BeefBuild.Program"
[Platform.Windows]
Description = "BeefBuild"
FileVersion = "0.42.1"
[Configs.Debug.Win32]
TargetName = ""
OtherLinkFlags = ""
@ -16,8 +20,8 @@ TargetName = "$(ProjectName)_d"
OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib Rpcrt4.lib Ole32.lib"
CLibType = "Dynamic"
BeefLibType = "DynamicDebug"
DebugCommandArguments = "-run"
DebugWorkingDirectory = "c:\\temp\\Hello2"
DebugCommandArguments = "--version"
DebugWorkingDirectory = "c:\\beef\\ide\\mintest"
EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
PreprocessorMacros = ["DEBUG", "CLI"]

View file

@ -160,30 +160,6 @@ namespace System.Reflection
dataPtr = *(void**)dataPtr;
handled = true;
}
else
{
if (!underlyingType.IsSubtypeOf(paramType))
{
if (underlyingType.IsGenericType)
{
var ptrTypedPrimitive = (SpecializedGenericType)underlyingType;
if ((ptrTypedPrimitive.mTypeFlags.HasFlag(.Sys_PointerT)))
{
let elementType = Type.GetType(ptrTypedPrimitive.mResolvedTypeRefs[0]);
if (elementType == paramType)
{
dataPtr = *(void**)dataPtr;
handled = true;
}
}
}
/*if (underlyingType.IsSpecialType(TypeInstance.[Friend]sPointerTType, "System", "Pointer", 2))
{
}*/
}
}
if (!handled)
{

View file

@ -826,7 +826,7 @@ namespace System.Reflection
SizedArray = 0x0800,
Splattable = 0x1000,
Union = 0x2000,
Sys_PointerT = 0x4000, // System.Pointer<T>
//
WantsMark = 0x8000,
Delegate = 0x10000,
HasDestructor = 0x20000,

View file

@ -1816,7 +1816,64 @@ BFP_EXPORT void BFP_CALLTYPE BfpFile_SetAttributes(const char* path, BfpFileAttr
BFP_EXPORT void BFP_CALLTYPE BfpFile_Copy(const char* oldPath, const char* newPath, BfpFileCopyKind copyKind, BfpFileResult* outResult)
{
NOT_IMPL;
int fd_to, fd_from;
char buf[4096];
ssize_t nread;
fd_from = open(oldPath, O_RDONLY);
if (fd_from < 0)
{
OUTRESULT(BfpFileResult_NotFound);
return;
}
fd_to = open(newPath, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd_to < 0)
{
OUTRESULT(BfpFileResult_AlreadyExists);
goto out_error;
}
while (nread = read(fd_from, buf, sizeof buf), nread > 0)
{
char *out_ptr = buf;
ssize_t nwritten;
do {
nwritten = write(fd_to, out_ptr, nread);
if (nwritten >= 0)
{
nread -= nwritten;
out_ptr += nwritten;
}
else if (errno != EINTR)
{
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
} while (nread > 0);
}
if (nread == 0)
{
if (close(fd_to) < 0)
{
fd_to = -1;
OUTRESULT(BfpFileResult_UnknownError);
goto out_error;
}
close(fd_from);
/* Success! */
OUTRESULT(BfpFileResult_Ok);
return;
}
out_error:
close(fd_from);
if (fd_to >= 0)
close(fd_to);
}
BFP_EXPORT void BFP_CALLTYPE BfpFile_Rename(const char* oldPath, const char* newPath, BfpFileResult* outResult)

View file

@ -8,6 +8,18 @@ namespace IDE.Compiler
{
public class BfProject
{
enum Flags : int32
{
None = 0,
MergeFunctions = 1,
CombineLoads = 2,
VectorizeLoops = 4,
VectorizeSLP = 8,
SingleModule = 0x10,
AsmOutput = 0x20,
AsmOutput_ATT = 0x40,
}
[StdCall, CLink]
extern static void BfProject_Delete(void* nativeBfProject);
@ -22,7 +34,7 @@ namespace IDE.Compiler
[StdCall, CLink]
extern static void BfProject_SetOptions(void* nativeBfProject, int32 targetType, char8* startupObject, char8* preprocessorMacros,
int32 optLevel, int32 ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP);
int32 optLevel, int32 ltoType, Flags flags);
public void* mNativeBfProject;
public bool mDisabled;
@ -51,10 +63,21 @@ namespace IDE.Compiler
public void SetOptions(Project.TargetType targetType, String startupObject, List<String> preprocessorMacros,
BuildOptions.BfOptimizationLevel optLevel, BuildOptions.LTOType ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP)
{
Flags flags = default;
void SetFlags(bool val, Flags flag)
{
if (val)
flags |= flag;
}
SetFlags(mergeFunctions, .MergeFunctions);
SetFlags(combineLoads, .CombineLoads);
SetFlags(vectorizeLoops, .VectorizeLoops);
SetFlags(vectorizeSLP, .VectorizeSLP);
String macrosStr = scope String();
macrosStr.Join("\n", preprocessorMacros.GetEnumerator());
BfProject_SetOptions(mNativeBfProject, (int32)targetType, startupObject, macrosStr,
(int32)optLevel, (int32)ltoType, mergeFunctions, combineLoads, vectorizeLoops, vectorizeSLP);
(int32)optLevel, (int32)ltoType, flags);
}
}

View file

@ -1179,48 +1179,6 @@ namespace IDE.ui
}
}
public void RemoveInvalidContinuationItems()
{
/*var lastValidListViewItem = this;
for (int32 idx = 1; idx < mWatchSeriesInfo.mCount; idx++)
{
int32 parentIdx = idx + mWatchSeriesInfo.mStartMemberIdx;
if (parentIdx >= mParentItem.mChildItems.Count)
break;
WatchListViewItem watchListViewItem = (WatchListViewItem)mParentItem.mChildItems[parentIdx];
if (watchListViewItem.mWatchSeriesInfo != mWatchSeriesInfo)
break;
if (watchListViewItem.mSeriesMemberIdx == 0)
break;
int addrSize = IDEApp.sApp.mDebugger.GetAddrSize() * 2;
int addrsCount = (mWatchSeriesInfo.mAddrs.Length / addrSize) / mWatchSeriesInfo.mAddrsEntrySize;
if (watchListViewItem.mSeriesMemberIdx >= addrsCount)
{
lastValidListViewItem.mBottomPadding += watchListViewItem.mSelfHeight + watchListViewItem.mBottomPadding;
mListView.mListSizeDirty = true;
mParentItem.RemoveChildItem(watchListViewItem);
idx--;
}
else
lastValidListViewItem = watchListViewItem;
}*/
// This caused 'closing' opened items with Dictionary elements when stepping
/*if (mWatchSeriesInfo.mAddrs != null)
{
int32 checkIdx = mWatchSeriesInfo.mStartMemberIdx + 1;
while (checkIdx < mParentItem.mChildItems.Count)
{
WatchListViewItem watchListViewItem = (WatchListViewItem)mParentItem.mChildItems[checkIdx];
if (watchListViewItem.mWatchSeriesInfo != mWatchSeriesInfo)
break;
//mParentItem.RemoveChildItem(watchListViewItem);
}
}*/
}
public override void Update()
{
if ((mWatchEntry != null) && (mWatchEntry.mIsPending))
@ -2508,13 +2466,6 @@ namespace IDE.ui
while (listViewItem.GetChildCount() > memberCount)
listViewItem.RemoveChildItem(listViewItem.GetChildAtIndex(memberCount));
if ((watchSeriesInfo != null) && (watchSeriesInfo.mAddrs != null))
{
var headItem = (WatchListViewItem)listViewItem.GetChildAtIndex(watchSeriesInfo.mStartMemberIdx);
headItem.RemoveInvalidContinuationItems();
mListView.UpdateAll();
}
if ((listViewItem.GetChildCount() == 0) && (listViewItem.mOpenButton != null))
{
Widget.RemoveAndDelete(listViewItem.mOpenButton);

View file

@ -497,6 +497,9 @@ void BfCodeGenThread::RunLoop()
BP_ZONE("BfCodeGen::RunLoop.LLVM.OBJ");
String outFileName;
if (request->mOptions.mAsmKind != BfAsmKind_None)
outFileName = request->mOutFileName + ".s";
else
outFileName = request->mOutFileName + BF_OBJ_EXT;
if (!llvmIRCodeGen->WriteObjectFile(outFileName, request->mOptions))
{

View file

@ -5529,7 +5529,7 @@ void BfCompiler::CompileReified()
if (typeDef->mIsPartial)
continue;
bool isAlwaysInclude = typeDef->mIsAlwaysInclude;
bool isAlwaysInclude = (typeDef->mIsAlwaysInclude) || (typeDef->mProject->mAlwaysIncludeAll);
if (typeDef->mProject->IsTestProject())
{

View file

@ -149,7 +149,8 @@ void BfContext::AssignModule(BfType* type)
BF_ASSERT(!typeInst->mModule->mIsReified);
}
BfModule* module;
BfModule* module = NULL;
bool needsModuleInit = false;
// We used to have this "IsReified" check, but we DO want to create modules for unreified types even if they remain unused.
// What was that IsReified check catching?
@ -173,13 +174,39 @@ void BfContext::AssignModule(BfType* type)
auto typeInst = type->ToTypeInstance();
BF_ASSERT(typeInst != NULL);
String moduleName = GenerateModuleName(typeInst);
auto project = typeInst->mTypeDef->mProject;
if ((project->mSingleModule) && (typeInst->mIsReified))
{
BfModule** modulePtr = NULL;
if (mProjectModule.TryAdd(project, NULL, &modulePtr))
{
String moduleName = project->mName;
module = new BfModule(this, moduleName);
module->mIsReified = typeInst->mIsReified;
module->mProject = typeInst->mTypeDef->mProject;
module->mIsReified = true;
module->mProject = project;
typeInst->mModule = module;
BF_ASSERT(!mLockModules);
mModules.push_back(module);
*modulePtr = module;
needsModuleInit = true;
}
else
{
module = *modulePtr;
typeInst->mModule = module;
}
}
else
{
String moduleName = GenerateModuleName(typeInst);
module = new BfModule(this, moduleName);
module->mIsReified = typeInst->mIsReified;
module->mProject = project;
typeInst->mModule = module;
BF_ASSERT(!mLockModules);
mModules.push_back(module);
needsModuleInit = true;
}
}
auto localTypeInst = type->ToTypeInstance();
@ -191,7 +218,7 @@ void BfContext::AssignModule(BfType* type)
module->mOwnedTypeInstances.push_back(localTypeInst);
}
if (!module->mIsScratchModule)
if (needsModuleInit)
module->Init();
}

View file

@ -289,6 +289,7 @@ public:
BfModule* mScratchModule;
BfModule* mUnreifiedModule;
HashSet<String> mUsedModuleNames;
Dictionary<BfProject*, BfModule*> mProjectModule;
Array<BfModule*> mModules;
Array<BfModule*> mDeletingModules;
HashSet<BfTypeInstance*> mFailTypes; // All types handled after a failure need to be rebuild on subsequent compile

View file

@ -3415,7 +3415,8 @@ static void AddFunctionSimplificationPasses(llvm::legacy::PassManagerBase &MPM,
//if (EnableGVNHoist)
if (options.mEnableGVNHoist)
MPM.add(llvm::createGVNHoistPass());
if (options.mEnableGVNSink) {
if (options.mEnableGVNSink)
{
MPM.add(llvm::createGVNSinkPass());
MPM.add(llvm::createCFGSimplificationPass());
}
@ -4047,7 +4048,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen
{
// Ask the target to add backend passes as necessary.
if (target->addPassesToEmitFile(PM, out, NULL,
llvm::TargetMachine::CGFT_ObjectFile,
(codeGenOptions.mAsmKind != BfAsmKind_None) ? llvm::TargetMachine::CGFT_AssemblyFile : llvm::TargetMachine::CGFT_ObjectFile,
//TargetMachine::CGFT_AssemblyFile,
noVerify /*, StartAfterID, StopAfterID*/))
{
@ -4110,6 +4111,12 @@ const char* BfIRCodeGen::GetIntrinsicName(int intrinId)
return gIntrinEntries[intrinId].mName;
}
void BfIRCodeGen::SetAsmKind(BfAsmKind asmKind)
{
const char* args[] = {"", (asmKind == BfAsmKind_ATT) ? "-x86-asm-syntax=att" : "-x86-asm-syntax=intel" };
llvm::cl::ParseCommandLineOptions(2, args);
}
#ifdef BF_PLATFORM_LINUX
//HACK: I don't know why this is needed, but we get link errors if we don't have it.
int BF_LinuxFixLinkage()

View file

@ -141,6 +141,7 @@ public:
static int GetIntrinsicId(const StringImpl& name);
static const char* GetIntrinsicName(int intrinId);
static void SetAsmKind(BfAsmKind asmKind);
};
NS_BF_END

View file

@ -4407,11 +4407,6 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
typeFlags |= BfTypeFlags_Union;
if (type->IsDelegate())
typeFlags |= BfTypeFlags_Delegate;
if (typeInstance != NULL)
{
if (typeInstance->mTypeDef == mCompiler->mPointerTTypeDef)
typeFlags |= BfTypeFlags_Sys_PointerT;
}
if (type->WantsGCMarking())
typeFlags |= BfTypeFlags_WantsMarking;
@ -20413,7 +20408,7 @@ void BfModule::DbgFinish()
needForceLinking = true;
}
if (needForceLinking)
if ((needForceLinking) && (mProject->mCodeGenOptions.mAsmKind == BfAsmKind_None))
{
BfMethodState methodState;
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, &methodState);
@ -20510,13 +20505,6 @@ bool BfModule::Finish()
BF_ASSERT((int)mOutFileNames.size() >= mExtensionCount);
bool writeModule = mBfIRBuilder->HasExports();
// if ((!writeModule) && (!IsOptimized()))
// {
// CreateForceLinkMarker(this);
// mHasForceLinkMarker = true;
// writeModule = true;
// }
String outputPath;
BfCodeGenOptions codeGenOptions = mProject->mCodeGenOptions;

View file

@ -3468,6 +3468,11 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
attributes = attributes->mNextAttribute;
}
if ((mProject != NULL) && (mProject->mAlwaysIncludeAll) && (methodDef->mBody != NULL))
{
implRequired = true;
declRequired = true;
}
if (typeInstance->IsInterface())
declRequired = true;
@ -8671,7 +8676,9 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
// * <-> Var
if ((typedVal.mType->IsVar()) || (toType->IsVar()))
{
BF_ASSERT((mCurMethodInstance->mIsUnspecialized) || (mCurMethodState->mClosureState != NULL) || (mHadVarUsage));
BF_ASSERT(((mCurMethodInstance != NULL) && (mCurMethodInstance->mIsUnspecialized)) ||
((mCurMethodState != NULL) && (mCurMethodState->mClosureState != NULL)) ||
(mHadVarUsage));
return GetDefaultValue(toType);
}

View file

@ -9,6 +9,7 @@
#include "BfAutoComplete.h"
#include "BfResolvePass.h"
#include "MemReporter.h"
#include "BfIRCodeGen.h"
#include "BeefySysLib/util/AllocDebug.h"
@ -840,8 +841,11 @@ bool BfTypeDef::HasSource(BfSource* source)
BfProject::BfProject()
{
mDisabled = false;
mSingleModule = false;
mTargetType = BfTargetType_BeefConsoleApplication;
mBuildConfigChanged = false;
mSingleModule = false;
mAlwaysIncludeAll = false;
mSystem = NULL;
mIdx = -1;
}
@ -3588,7 +3592,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetDisabled(BfProject* bfProject, bool disa
}
BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int targetType, const char* startupObject, const char* preprocessorMacros,
int optLevel, int ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP)
int optLevel, int ltoType, BfProjectFlags flags)
{
bfProject->mTargetType = (BfTargetType)targetType;
bfProject->mStartupObject = startupObject;
@ -3596,11 +3600,27 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target
BfCodeGenOptions codeGenOptions;
codeGenOptions.mOptLevel = (BfOptLevel)optLevel;
codeGenOptions.mLTOType = (BfLTOType)ltoType;
codeGenOptions.mMergeFunctions = mergeFunctions;
codeGenOptions.mLoadCombine = combineLoads;
codeGenOptions.mLoopVectorize = vectorizeLoops;
codeGenOptions.mSLPVectorize = vectorizeSLP;
codeGenOptions.mMergeFunctions = (flags & BfProjectFlags_MergeFunctions) != 0;
codeGenOptions.mLoadCombine = (flags & BfProjectFlags_CombineLoads) != 0;
codeGenOptions.mLoopVectorize = (flags & BfProjectFlags_VectorizeLoops) != 0;
codeGenOptions.mSLPVectorize = (flags & BfProjectFlags_VectorizeSLP) != 0;
if ((flags & BfProjectFlags_AsmOutput) != 0)
{
static bool setLLVMAsmKind = false;
if ((flags & BfProjectFlags_AsmOutput_ATT) != 0)
codeGenOptions.mAsmKind = BfAsmKind_ATT;
else
codeGenOptions.mAsmKind = BfAsmKind_Intel;
if (!setLLVMAsmKind)
{
setLLVMAsmKind = true;
BfIRCodeGen::SetAsmKind(codeGenOptions.mAsmKind);
}
}
bfProject->mCodeGenOptions = codeGenOptions;
bfProject->mSingleModule = (flags & BfProjectFlags_SingleModule) != 0;
bfProject->mAlwaysIncludeAll = (flags & BfProjectFlags_AlwaysIncludeAll) != 0;
bfProject->mPreprocessorMacros.Clear();

View file

@ -154,7 +154,7 @@ enum BfTypeFlags
BfTypeFlags_SizedArray = 0x0800,
BfTypeFlags_Splattable = 0x1000,
BfTypeFlags_Union = 0x2000,
BfTypeFlags_Sys_PointerT = 0x4000,
//
BfTypeFlags_WantsMarking = 0x8000,
BfTypeFlags_Delegate = 0x10000,
BfTypeFlags_HasDestructor = 0x20000,
@ -209,6 +209,13 @@ enum BfSIMDSetting
BfSIMDSetting_AVX2,
};
enum BfAsmKind
{
BfAsmKind_None,
BfAsmKind_ATT,
BfAsmKind_Intel,
};
enum BfOptLevel
{
BfOptLevel_NotSet = -1,
@ -240,6 +247,7 @@ struct BfCodeGenOptions
bool mIsHotCompile;
bool mWriteObj;
BfAsmKind mAsmKind;
bool mWriteToLib;
bool mWriteLLVMIR;
@ -291,6 +299,7 @@ struct BfCodeGenOptions
{
mIsHotCompile = false;
mWriteObj = true;
mAsmKind = BfAsmKind_None;
mWriteToLib = false;
mWriteLLVMIR = false;
mVirtualMethodOfs = 0;
@ -921,6 +930,19 @@ enum BfTargetType
BfTargetType_BeefTest
};
enum BfProjectFlags
{
BfProjectFlags_None = 0,
BfProjectFlags_MergeFunctions = 1,
BfProjectFlags_CombineLoads = 2,
BfProjectFlags_VectorizeLoops = 4,
BfProjectFlags_VectorizeSLP = 8,
BfProjectFlags_SingleModule = 0x10,
BfProjectFlags_AsmOutput = 0x20,
BfProjectFlags_AsmOutput_ATT = 0x40,
BfProjectFlags_AlwaysIncludeAll = 0x80,
};
class BfProject
{
public:
@ -930,6 +952,8 @@ public:
BfTargetType mTargetType;
BfCodeGenOptions mCodeGenOptions;
bool mDisabled;
bool mSingleModule;
bool mAlwaysIncludeAll;
int mIdx;
String mStartupObject;

View file

@ -52,7 +52,7 @@ fi
### DEBUG ###
echo Building BeefBuild_bootd
../../jbuild_d/Debug/bin/BeefBoot --out="BeefBuild_bootd" --src=../src --src=../../BeefBuild/src --src=../../BeefLibs/corlib/src --src=../../BeefLibs/Beefy2D/src --define=CLI --define=DEBUG --startup=BeefBuild.Program --linkparams="./libBeefRT_d.so ./libIDEHelper_d.so ./libBeefySysLib_d.so ../../extern/llvm_linux_8_0_0/lib/libLLVMCore.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMC.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMCParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMCodeGen.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Disassembler.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMCDisassembler.a ../../extern/llvm_linux_8_0_0/lib/libLLVMSupport.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Info.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Utils.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86AsmPrinter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Desc.a ../../extern/llvm_linux_8_0_0/lib/libLLVMObject.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBitReader.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAsmParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMTarget.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86CodeGen.a ../../extern/llvm_linux_8_0_0/lib/libLLVMScalarOpts.a ../../extern/llvm_linux_8_0_0/lib/libLLVMInstCombine.a ../../extern/llvm_linux_8_0_0/lib/libLLVMSelectionDAG.a ../../extern/llvm_linux_8_0_0/lib/libLLVMProfileData.a ../../extern/llvm_linux_8_0_0/lib/libLLVMTransformUtils.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAnalysis.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86AsmParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAsmPrinter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBitWriter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMVectorize.a ../../extern/llvm_linux_8_0_0/lib/libLLVMipo.a ../../extern/llvm_linux_8_0_0/lib/libLLVMInstrumentation.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoDWARF.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoPDB.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoCodeView.a ../../extern/llvm_linux_8_0_0/lib/libLLVMGlobalISel.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBinaryFormat.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDemangle.a -ltinfo -Wl,-rpath -Wl,."
../../jbuild_d/Debug/bin/BeefBoot --out="BeefBuild_bootd" --src=../src --src=../../BeefBuild/src --src=../../BeefLibs/corlib/src --src=../../BeefLibs/Beefy2D/src --define=CLI --define=DEBUG --startup=BeefBuild.Program --linkparams="./libBeefRT_d.so ./libIDEHelper_d.so ./libBeefySysLib_d.so ../../extern/llvm_linux_8_0_0/lib/libLLVMCore.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMC.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMCParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMCodeGen.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Disassembler.a ../../extern/llvm_linux_8_0_0/lib/libLLVMMCDisassembler.a ../../extern/llvm_linux_8_0_0/lib/libLLVMSupport.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Info.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Utils.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86AsmPrinter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86Desc.a ../../extern/llvm_linux_8_0_0/lib/libLLVMObject.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBitReader.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAsmParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMTarget.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86CodeGen.a ../../extern/llvm_linux_8_0_0/lib/libLLVMScalarOpts.a ../../extern/llvm_linux_8_0_0/lib/libLLVMInstCombine.a ../../extern/llvm_linux_8_0_0/lib/libLLVMSelectionDAG.a ../../extern/llvm_linux_8_0_0/lib/libLLVMProfileData.a ../../extern/llvm_linux_8_0_0/lib/libLLVMTransformUtils.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAnalysis.a ../../extern/llvm_linux_8_0_0/lib/libLLVMX86AsmParser.a ../../extern/llvm_linux_8_0_0/lib/libLLVMAsmPrinter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBitWriter.a ../../extern/llvm_linux_8_0_0/lib/libLLVMVectorize.a ../../extern/llvm_linux_8_0_0/lib/libLLVMipo.a ../../extern/llvm_linux_8_0_0/lib/libLLVMInstrumentation.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoDWARF.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoPDB.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDebugInfoCodeView.a ../../extern/llvm_linux_8_0_0/lib/libLLVMGlobalISel.a ../../extern/llvm_linux_8_0_0/lib/libLLVMBinaryFormat.a ../../extern/llvm_linux_8_0_0/lib/libLLVMDemangle.a -ltinfo -Wl,-rpath -Wl,\$ORIGIN"
echo Building BeefBuild_d
./BeefBuild_bootd -clean -proddir=../../BeefBuild -config=Debug -platform=Linux64
#./BeefBuild_d -proddir=../../TestApp
@ -63,7 +63,7 @@ echo Testing IDEHelper/Tests in BeefBuild_d
### RELEASE ###
echo Building BeefBuild_boot
../../jbuild/Release/bin/BeefBoot --out="BeefBuild_boot" --src=../src --src=../../BeefBuild/src --src=../../BeefLibs/corlib/src --src=../../BeefLibs/Beefy2D/src --define=CLI --define=DEBUG --startup=BeefBuild.Program --linkparams="./libBeefRT.so ./libIDEHelper.so ./libBeefySysLib.so ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMCore.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMC.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMCParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMCodeGen.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Disassembler.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMCDisassembler.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMSupport.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Info.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Utils.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86AsmPrinter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Desc.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMObject.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBitReader.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAsmParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMTarget.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86CodeGen.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMScalarOpts.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMInstCombine.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMSelectionDAG.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMProfileData.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMTransformUtils.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAnalysis.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86AsmParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAsmPrinter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBitWriter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMVectorize.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMipo.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMInstrumentation.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoDWARF.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoPDB.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoCodeView.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMGlobalISel.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBinaryFormat.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDemangle.a -ltinfo -Wl,-rpath -Wl,."
../../jbuild/Release/bin/BeefBoot --out="BeefBuild_boot" --src=../src --src=../../BeefBuild/src --src=../../BeefLibs/corlib/src --src=../../BeefLibs/Beefy2D/src --define=CLI --define=DEBUG --startup=BeefBuild.Program --linkparams="./libBeefRT.so ./libIDEHelper.so ./libBeefySysLib.so ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMCore.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMC.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMCParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMCodeGen.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Disassembler.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMMCDisassembler.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMSupport.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Info.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Utils.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86AsmPrinter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86Desc.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMObject.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBitReader.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAsmParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMTarget.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86CodeGen.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMScalarOpts.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMInstCombine.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMSelectionDAG.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMProfileData.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMTransformUtils.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAnalysis.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMX86AsmParser.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMAsmPrinter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBitWriter.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMVectorize.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMipo.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMInstrumentation.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoDWARF.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoPDB.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDebugInfoCodeView.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMGlobalISel.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMBinaryFormat.a ../../extern/llvm_linux_rel_8_0_0/lib/libLLVMDemangle.a -ltinfo -Wl,-rpath -Wl,\$ORIGIN"
echo Building BeedBuild
./BeefBuild_boot -clean -proddir=../../BeefBuild -config=Release -platform=Linux64
#./BeefBuild_d -proddir=../../TestApp