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

Added Android support, and generalized target triple support

Added PICLevel, RelocKind
DarwinCommon/LinuxCommon/AndroidCommon merged into PosixCommon
Mangling changed to avoid '@'
This commit is contained in:
Brian Fiete 2019-10-23 07:12:36 -07:00
parent 7a27ab75bf
commit 3883a3674d
39 changed files with 3457 additions and 5636 deletions

View file

@ -57,7 +57,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, int32 flags);
int optLevel, int ltoType, int relocType, int picLevel, int32 flags);
BF_IMPORT void BF_CALLTYPE BfProject_ClearDependencies(void* bfProject);
BF_IMPORT void BF_CALLTYPE BfProject_AddDependency(void* bfProject, void* depProject);
@ -795,7 +795,7 @@ bool BootApp::Compile()
mCELibProject = BfSystem_CreateProject(mSystem, "BeefLib");
BfProjectFlags flags = BfProjectFlags_None;
BfProject_SetOptions(mCELibProject, BfTargetType_BeefLib, "", mDefines.c_str(), mOptLevel, 0, flags);
BfProject_SetOptions(mCELibProject, BfTargetType_BeefLib, "", mDefines.c_str(), mOptLevel, 0, 0, 0, flags);
}
if (!mDefines.IsEmpty())
@ -815,7 +815,7 @@ bool BootApp::Compile()
else if (mAsmKind == BfAsmKind_Intel)
flags = (BfProjectFlags)(flags | BfProjectFlags_AsmOutput);
}
BfProject_SetOptions(mProject, mTargetType, mStartupObject.c_str(), mDefines.c_str(), mOptLevel, ltoType, flags);
BfProject_SetOptions(mProject, mTargetType, mStartupObject.c_str(), mDefines.c_str(), mOptLevel, ltoType, 0, 0, flags);
if (mCELibProject != NULL)
BfProject_AddDependency(mProject, mCELibProject);

View file

@ -20,7 +20,7 @@ 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 = "--version"
DebugCommandArguments = "-platform=x86_64-none-linux-android21 -workspace=C:/proj/Android/BeefTest/app/src/main/cpp/../beef/\""
DebugWorkingDirectory = "c:\\beef\\ide\\mintest"
EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
PreprocessorMacros = ["DEBUG", "CLI"]
@ -34,15 +34,6 @@ DebugCommandArguments = "-proddir=..\\ -config=Debug -platform=Win64"
DebugWorkingDirectory = "$(WorkspaceDir)/../IDE/dist"
PreprocessorMacros = ["DEBUG", "CLI"]
[Configs.Release.macOS]
TargetDirectory = "$(WorkspaceDir)/../IDE/dist"
OtherLinkFlags = "./libBeefRT.dylib ./libIDEHelper.dylib ./libBeefySysLib.dylib ../../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 -Wl,-rpath -Wl,."
CLibType = "Dynamic"
DebugCommandArguments = "-proddir=..\\ -config=Debug -platform=Win64"
DebugWorkingDirectory = "$(WorkspaceDir)/../IDE/dist"
PreprocessorMacros = ["CLI"]
[Configs.Debug.Linux64]
TargetDirectory = "$(WorkspaceDir)/../IDE/dist"
TargetName = "$(ProjectName)_d"
@ -52,6 +43,14 @@ DebugCommandArguments = "-proddir=..\\ -config=Debug -platform=Win64"
DebugWorkingDirectory = "$(WorkspaceDir)/../IDE/dist"
PreprocessorMacros = ["DEBUG", "CLI"]
[Configs.Release.macOS]
TargetDirectory = "$(WorkspaceDir)/../IDE/dist"
OtherLinkFlags = "./libBeefRT.dylib ./libIDEHelper.dylib ./libBeefySysLib.dylib ../../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 -Wl,-rpath -Wl,."
CLibType = "Dynamic"
DebugCommandArguments = "-proddir=..\\ -config=Debug -platform=Win64"
DebugWorkingDirectory = "$(WorkspaceDir)/../IDE/dist"
PreprocessorMacros = ["CLI"]
[Configs.Release.Linux64]
TargetDirectory = "$(WorkspaceDir)/../IDE/dist"
OtherLinkFlags = "./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"

View file

@ -50,6 +50,68 @@ if (${APPLE})
../BeefySysLib/platform/osx
)
elseif (${ANDROID})
if (ANDROID_ABI STREQUAL "x86")
include_directories(
.
../BeefySysLib/
../BeefySysLib/third_party
../BeefySysLib/third_party/freetype/include
../BeefySysLib/third_party/libffi/i686-pc-linux-gnu/include
../
../extern
../extern/llvm/include
../extern/llvm_linux/include
../extern/llvm/lib/Target
../BeefySysLib/platform/android
)
elseif (ANDROID_ABI STREQUAL "x86_64")
include_directories(
.
../BeefySysLib/
../BeefySysLib/third_party
../BeefySysLib/third_party/freetype/include
../BeefySysLib/third_party/libffi/x86_64-pc-linux-gnu/include
../
../extern
../extern/llvm/include
../extern/llvm_linux/include
../extern/llvm/lib/Target
../BeefySysLib/platform/android
)
elseif (ANDROID_ABI STREQUAL "armeabi-v7a")
include_directories(
.
../BeefySysLib/
../BeefySysLib/third_party
../BeefySysLib/third_party/freetype/include
../BeefySysLib/third_party/libffi/arm-unknown-linux-gnu/include
../
../extern
../extern/llvm/include
../extern/llvm_linux/include
../extern/llvm/lib/Target
../BeefySysLib/platform/android
)
else()
include_directories(
.
../BeefySysLib/
../BeefySysLib/third_party
../BeefySysLib/third_party/freetype/include
../BeefySysLib/third_party/libffi/aarch64-unknown-linux-gnu/include
../
../extern
../extern/llvm/include
../extern/llvm_linux/include
../extern/llvm/lib/Target
../BeefySysLib/platform/android
)
endif()
else()
include_directories(
.
@ -135,6 +197,7 @@ file(GLOB SRC_FILES
../BeefySysLib/util/BeefPerf.cpp
../BeefySysLib/util/String.cpp
../BeefySysLib/util/UTF8.cpp
../BeefySysLib/util/Hash.cpp
../BeefySysLib/third_party/utf8proc/utf8proc.c
)
@ -143,6 +206,11 @@ if (${APPLE})
../BeefySysLib/platform/darwin/BFPlatform.cpp
../BeefySysLib/platform/darwin/DarwinCommon.cpp
)
elseif (${ANDROID})
file(GLOB SRC_FILES_OS
../BeefySysLib/platform/android/BFPlatform.cpp
../BeefySysLib/platform/android/AndroidCommon.cpp
)
else()
file(GLOB SRC_FILES_OS
../BeefySysLib/platform/linux/BFPlatform.cpp
@ -151,15 +219,19 @@ else()
endif()
# Add library to build.
add_library(${PROJECT_NAME} SHARED
add_library(${PROJECT_NAME} STATIC
${SRC_FILES}
${SRC_FILES_OS}
)
if (${APPLE})
target_link_libraries(${PROJECT_NAME} pthread ffi)
elseif (${ANDROID})
set(TARGET_LIBS_OS "")
#target_link_libraries(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../BeefySysLib/third_party/libffi/aarch64-unknown-linux-gnu/.libs/libffi.a)
#target_link_libraries(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../BeefySysLib/third_party/libffi/i686-pc-linux-gnu/.libs/libffi.a)
else()
set(TARGET_LIBS_OS "backtrace")
target_link_libraries(${PROJECT_NAME} pthread ffi backtrace)
endif()
# Link with other dependencies.
@ -167,6 +239,8 @@ if(MSVC)
target_link_libraries(${PROJECT_NAME} BeefySysLib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib LLVMX86Disassembler.lib LLVMMCDisassembler.lib LLVMSupport.lib LLVMX86Info.lib LLVMX86Utils.lib LLVMX86AsmPrinter.lib LLVMX86Desc.lib %(AdditionalDependencies) LLVMMC.lib LLVMObject.lib LLVMCore.lib LLVMBitReader.lib LLVMAsmParser.lib LLVMMCParser.lib LLVMCodeGen.lib LLVMTarget.lib LLVMX86CodeGen.lib LLVMScalarOpts.lib LLVMInstCombine.lib LLVMSelectionDAG.lib LLVMProfileData.lib LLVMTransformUtils.lib LLVMAnalysis.lib LLVMX86AsmParser.lib LLVMAsmPrinter.lib LLVMBitWriter.lib LLVMVectorize.lib LLVMipo.lib LLVMInstrumentation.lib LLVMDebugInfoDWARF.lib LLVMDebugInfoPDB.lib LLVMDebugInfoCodeView.lib LLVMGlobalISel.lib LLVMBinaryFormat.lib libcurl_a.lib)
else()
set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux/lib")
target_link_libraries(${PROJECT_NAME} BeefySysLib pthread dl ffi ${TARGET_LIBS_OS}
target_link_libraries(${PROJECT_NAME} dl
)
endif()
#pthread ffi

View file

@ -230,7 +230,7 @@ void SetErrorString(const char* str)
while (true)
{
const char* prevStr = gErrorString;
auto result = ::InterlockedCompareExchangePointer((void* volatile*)&gErrorString, (void*)newStr, (void*)prevStr);
auto result = (void*)BfpSystem_InterlockedCompareExchangePtr((uintptr*)&gErrorString, (uintptr)prevStr, (uintptr)newStr);
if (result != prevStr)
continue;
if (prevStr != NULL)

View file

@ -0,0 +1,8 @@
#include <android/log.h>
#define BFP_PRINTF(...) __android_log_print(ANDROID_LOG_INFO, "Beef", __VA_ARGS__)
#define BFP_ERRPRINTF(...) __android_log_print(ANDROID_LOG_ERROR, "Beef", __VA_ARGS__)
#define BFP_HAS_PTHREAD_GETATTR_NP
#include "../posix/PosixCommon.cpp"

View file

@ -0,0 +1,159 @@
#pragma once
#ifdef __LP64__
#define BF64
#else
#define BF32
#endif
#define BOOST_DETAIL_NO_CONTAINER_FWD
#include <string>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <assert.h>
#include <sys/time.h>
//#include <libkern/OSAtomic.h>
#include <cstdlib>
#include <unistd.h>
#include <wchar.h>
#include <math.h>
#include <stdarg.h>
#include <string.h>
#include <pthread.h>
#include <wctype.h>
#include <stddef.h>
//#define offsetof(type, member) __builtin_offsetof (type, member)
extern "C"
{
//#define FFI_BUILDING
//#include "third_party/libffi/x86_64-apple-darwin12.5.0/include/ffi.h"
}
#define BF_ENDIAN_LITTLE
#define _NOEXCEPT noexcept
#define NTAPI
//#define FFI_STDCALL FFI_DEFAULT_ABI
//#define FFI_THISCALL FFI_DEFAULT_ABI
//#define FFI_FASTCALL FFI_DEFAULT_ABI
#define INVALID_SOCKET -1
typedef uint64_t uint64;
typedef uint32_t uint32;
typedef uint16_t uint16;
typedef uint8_t uint8;
typedef int64_t int64;
typedef int32_t int32;
typedef int16_t int16;
typedef int8_t int8;
typedef unsigned int uint;
//#define BF_PLATFORM_SDL
#define NOP
//#define BF_NOTHROW throw ()
//#define BF_NOTHROW noexcept
#define BF_NOTHROW
#ifdef BF64
typedef int64 intptr;
typedef uint64 uintptr;
#else
typedef int32 intptr;
typedef uint32 uintptr;
#endif
typedef wchar_t* BSTR;
typedef int HRESULT;
typedef uint8 BYTE;
typedef uint16 WORD;
typedef uint32 DWORD;
typedef int32 LONG;
typedef pthread_key_t BFTlsKey;
typedef pthread_t BF_THREADID;
typedef pthread_t BF_THREADHANDLE;
#define BF_HAS_TLS_DECLSPEC
#define BF_TLS_DECLSPEC thread_local
//:int64 abs(int64 val);
#define _stricmp stricmp
#define strnicmp strncasecmp
struct IID
{
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
};
typedef void* HANDLE;
typedef void* HMODULE;
// We only need the stdcall attribute for x32?
//#define BFSTDCALL __attribute__((stdcall))
//#include "../notwin/NotWin.h"
#ifdef DEBUG
#define _DEBUG
#endif
#define NOT_IMPL throw "Unimplemented";
//ARM
#if defined(__x86_64__) || defined(__i386__)
#define BF_FULL_MEMORY_FENCE() __asm__ __volatile__("mfence": : :"memory")
#define BF_SPINWAIT_NOP() __asm__ volatile ("pause\n" : : : "memory" );
#else
#define BF_FULL_MEMORY_FENCE() __sync_synchronize()
#define BF_SPINWAIT_NOP() ((void) 0)
#endif
#define BF_COMPILER_FENCE() __asm__ __volatile__("": : :"memory")
#define BF_THREAD_YIELD() sched_yield()
#if defined _DEBUG || defined BF_DEBUG_ASSERTS
#define BF_ASSERT(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
#else
#define BF_ASSERT(_Expression) (void)(0)
#endif
#define BF_ASSERT_REL(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
#define BF_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
#if defined _DEBUG || defined BF_DEBUG_ASSERTS
#define BF_DBG_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
#else
#define BF_DBG_FATAL(msg)
#endif
#define BF_NOINLINE __attribute__ ((noinline))
#define BF_NAKED
#define stricmp strcasecmp
#define _alloca alloca
#define DIR_SEP_CHAR '/'
#define DIR_SEP_CHAR_ALT '\\'
static char* itoa(int value, char* str, int base)
{
if (base == 16)
sprintf(str, "%X", value);
else
sprintf(str, "%d", value);
return str;
}

View file

@ -0,0 +1,13 @@
#include "Common.h"
#include "BFPlatform.h"
//#include <CoreFoundation/CFByteOrder.h>
//#include <mach/mach_time.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <wchar.h>
#include <fcntl.h>
//#include <mach/clock.h>
//#include <mach/mach.h>
#include <time.h>
#include <dirent.h>

View file

@ -0,0 +1,24 @@
#pragma once
#define BFSTDCALL
#include "AndroidCommon.h"
#define BF_PLATFORM_ANDROID
#define BF_PLATFORM_POSIX
#define BF_PLATFORM_NAME "BF_PLATFORM_ANDROID"
#define BF_IMPORT extern "C"
#ifdef BFSYSLIB_DYNAMIC
#define BF_EXPORT extern "C"
#define BF_CALLTYPE
#else
#define BF_EXPORT extern "C"
#define BF_CALLTYPE
#define BF_RESOURCES_REL_DIR "../Resources"
#endif
#define BF_DEBUG_BREAK()
#include "../PlatformInterface.h"

View file

@ -0,0 +1,9 @@
#pragma once
#include "../../HeadlessApp.h"
NS_BF_BEGIN;
typedef HeadlessApp PlatformBFApp;
NS_BF_END;

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@
#endif
#define BF_PLATFORM_IOS
#define BF_PLATFORM_POSIX
#define BF_PLATFORM_OPENGL_ES2
#define BF_PLATFORM_FULLSCREEN

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,8 @@
#include <string>
#define BF_PLATFORM_MACOS
#define BF_PLATFORM_POSIX
#define BF_PLATFORM_DARWIN
#define BF_PLATFORM_NAME "BF_PLATFORM_MACOS"
#define BF_IMPORT extern "C"

File diff suppressed because it is too large Load diff

View file

@ -21,16 +21,14 @@ typedef fd_set FD_SET;
#include <sys/socket.h>
#include <mach/error.h>
#include <mach/mach.h>
#include <cerrno>
//#define errno (*__error())
#endif
//#include <rpcdce.h>
#ifdef BF_PLATFORM_POSIX
#include <cerrno>
#endif
#pragma comment(lib,"wsock32.lib")
//#include "Hash.h"
#pragma warning(disable:4996)
USING_NS_BF;

View file

@ -1356,7 +1356,9 @@ static int gDbgVizIdx = 0;
HashContext::~HashContext()
{
#ifdef BF_PLATFORM_WINDOWS
delete mDbgVizStream;
#endif
}
void HashContext::Reset()
@ -1378,6 +1380,7 @@ void HashContext::Mixin(const void* data, int size)
{
int addBytes = std::min(size, 1024 - mBufSize);
#ifdef BF_PLATFORM_WINDOWS
if (mDbgViz)
{
int findIdx = 0x2cc159;
@ -1386,6 +1389,7 @@ void HashContext::Mixin(const void* data, int size)
NOP;
}
}
#endif
memcpy(&mBuf[mBufSize], data, addBytes);
mBufSize += addBytes;
@ -1417,6 +1421,7 @@ void HashContext::MixinStr(const StringImpl& str)
Val128 HashContext::Finish128()
{
#ifdef BF_PLATFORM_WINDOWS
if (mDbgViz)
{
// String dbg = "HashContext Dbg";
@ -1441,6 +1446,7 @@ Val128 HashContext::Finish128()
if ((mDbgVizStream != NULL) && (mDbgVizStream->IsOpen()))
mDbgVizStream->Write(mBuf, mBufSize);
}
#endif
if (mBufSize <= 16)
{
@ -1459,6 +1465,7 @@ Val128 HashContext::Finish128()
uint64 HashContext::Finish64()
{
#ifdef BF_PLATFORM_WINDOWS
if (mDbgViz)
{
// String dbg = "HashContext Dbg";
@ -1476,6 +1483,7 @@ uint64 HashContext::Finish64()
}
mDbgVizStream->Write(mBuf, mBufSize);
}
#endif
if (mBufSize <= 8)
{

View file

@ -109,16 +109,20 @@ public:
uint8 mBuf[1024];
int mBufSize;
int mBufOffset;
#ifdef BF_PLATFORM_WINDOWS
bool mDbgViz;
FileStream* mDbgVizStream;
#endif
public:
HashContext()
{
mBufOffset = 0;
mBufSize = 0;
#ifdef BF_PLATFORM_WINDOWS
mDbgViz = false;
mDbgVizStream = NULL;
#endif
}
~HashContext();

View file

@ -157,10 +157,92 @@ namespace IDE
return didCommands ? .HadCommands : .NoCommands;
}
bool QueueProjectGNUArchive(Project project, String targetPath, Workspace.Options workspaceOptions, Project.Options options, String objectsArg)
{
#if BF_PLATFORM_WINDOWS
String llvmDir = scope String(IDEApp.sApp.mInstallDir);
IDEUtils.FixFilePath(llvmDir);
llvmDir.Append("llvm/");
#else
String llvmDir = "";
#endif
//String error = scope String();
TestManager.ProjectInfo testProjectInfo = null;
if (gApp.mTestManager != null)
testProjectInfo = gApp.mTestManager.GetProjectInfo(project);
bool isExe = (project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) || (testProjectInfo != null);
if (!isExe)
return true;
String arCmds = scope String(""); //-O2 -Rpass=inline
//(doClangCPP ? "-lc++abi " : "") +
arCmds.AppendF("CREATE {}\n", targetPath);
for (let obj in objectsArg.Split(' '))
{
if (!obj.IsEmpty)
{
arCmds.AppendF("ADDMOD {}\n", obj);
}
}
arCmds.AppendF("SAVE\n");
if (project.mNeedsTargetRebuild)
{
if (File.Delete(targetPath) case .Err)
{
gApp.OutputLine("Failed to delete {0}", targetPath);
return false;
}
String arPath = scope .();
#if BF_PLATFORM_WINDOWS
arPath.Clear();
arPath.Append(gApp.mInstallDir);
arPath.Append(@"llvm\bin\llvm-ar.exe");
#else
arPath.Append("/usr/bin/ar");
#endif
String workingDir = scope String();
workingDir.Append(gApp.mInstallDir);
String scriptPath = scope .();
if (Path.GetTempFileName(scriptPath) case .Err)
{
return false;
}
if (File.WriteAllText(scriptPath, arCmds) case .Err)
{
gApp.OutputLine("Failed to write archive script {0}", scriptPath);
return false;
}
String cmdLine = scope .();
cmdLine.AppendF("-M");
var runCmd = gApp.QueueRun(arPath, cmdLine, workingDir, .UTF8);
runCmd.mOnlyIfNotFailed = true;
runCmd.mStdInData = new .(arCmds);
var tagetCompletedCmd = new IDEApp.TargetCompletedCmd(project);
tagetCompletedCmd.mOnlyIfNotFailed = true;
gApp.mExecutionQueue.Add(tagetCompletedCmd);
project.mLastDidBuild = true;
}
return true;
}
bool QueueProjectGNULink(Project project, String targetPath, Workspace.Options workspaceOptions, Project.Options options, String objectsArg)
{
bool isDebug = gApp.mConfigName.IndexOf("Debug", true) != -1;
#if BF_PLATFORM_WINDOWS
String llvmDir = scope String(IDEApp.sApp.mInstallDir);
IDEUtils.FixFilePath(llvmDir);
@ -1070,7 +1152,12 @@ namespace IDE
if (workspaceOptions.mToolsetType == .GNU)
{
if (!QueueProjectGNULink(project, targetPath, workspaceOptions, options, objectsArg))
if ((options.mBuildOptions.mBuildKind == .StaticLib) || (options.mBuildOptions.mBuildKind == .DynamicLib))
{
if (!QueueProjectGNUArchive(project, targetPath, workspaceOptions, options, objectsArg))
return false;
}
else if (!QueueProjectGNULink(project, targetPath, workspaceOptions, options, objectsArg))
return false;
}
else // MS

View file

@ -45,6 +45,25 @@ namespace IDE
return (this != .Og) && (this != .OgPlus) && (this != .O0);
}
}
public enum RelocType
{
NotSet,
Static,
PIC,
DynamicNoPIC,
ROPI,
RWPI,
ROPI_RWPI
}
public enum PICLevel
{
NotSet,
Not,
Small,
Big
}
}
public class DistinctBuildOptions

View file

@ -7,6 +7,7 @@ using System.Diagnostics;
using Beefy.widgets;
using Beefy;
using Beefy.utils;
using IDE.Util;
namespace IDE.Compiler
{
@ -465,6 +466,9 @@ namespace IDE.Compiler
var options = IDEApp.sApp.GetCurWorkspaceOptions();
String targetTriple = scope .();
if (TargetTriple.IsTargetTriple(gApp.mPlatformName))
targetTriple.Set(gApp.mPlatformName);
else
Workspace.PlatformType.GetTargetTripleByName(gApp.mPlatformName, options.mToolsetType, targetTriple);
bool enableObjectDebugFlags = options.mEnableObjectDebugFlags;

View file

@ -34,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, Flags flags);
int32 optLevel, int32 ltoType, int32 relocType, int32 picLevel, Flags flags);
public void* mNativeBfProject;
public bool mDisabled;
@ -61,7 +61,8 @@ 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)
BuildOptions.BfOptimizationLevel optLevel, BuildOptions.LTOType ltoType, BuildOptions.RelocType relocType, BuildOptions.PICLevel picLevel,
bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP)
{
Flags flags = default;
void SetFlags(bool val, Flags flag)
@ -77,7 +78,7 @@ namespace IDE.Compiler
String macrosStr = scope String();
macrosStr.Join("\n", preprocessorMacros.GetEnumerator());
BfProject_SetOptions(mNativeBfProject, (int32)targetType, startupObject, macrosStr,
(int32)optLevel, (int32)ltoType, flags);
(int32)optLevel, (int32)ltoType, (int32)relocType, (int32)picLevel, flags);
}
}

View file

@ -420,6 +420,7 @@ namespace IDE
public ArgsFileKind mUseArgsFile;
public int32 mParallelGroup = -1;
public bool mIsTargetRun;
public String mStdInData ~ delete _;
}
public List<ExecutionCmd> mExecutionQueue = new List<ExecutionCmd>() ~ DeleteContainerAndItems!(_);
@ -435,9 +436,11 @@ namespace IDE
public Task<String> mErrorTask /*~ delete _*/;
public Action<Task<String>> mOnErrorTaskComplete /*~ delete _*/;
public Monitor mMonitor = new Monitor() ~ delete _;
public String mStdInData ~ delete _;
public Thread mOutputThread;
public Thread mErrorThread;
public Thread mInputThread;
public int? mExitCode;
public bool mAutoDelete = true;
@ -450,9 +453,14 @@ namespace IDE
/*if (mProcess != null)
mProcess.Close();*/
if (mInputThread != null)
mInputThread.Join();
delete mInputThread;
if (mOutputThread != null)
mOutputThread.Join();
delete mOutputThread;
if (mErrorThread != null)
mErrorThread.Join();
delete mErrorThread;
@ -7092,6 +7100,26 @@ namespace IDE
}
}
static void WriteInputThread(Object obj)
{
ExecutionInstance executionInstance = (ExecutionInstance)obj;
FileStream fileStream = scope FileStream();
if (executionInstance.mProcess.AttachStandardInput(fileStream) case .Err)
return;
while (!executionInstance.mStdInData.IsEmpty)
{
switch (fileStream.TryWrite(.((.)executionInstance.mStdInData.Ptr, executionInstance.mStdInData.Length)))
{
case .Ok(int len):
executionInstance.mStdInData.Remove(0, len);
case .Err:
break;
}
}
}
static void ReadOutputThread(Object obj)
{
ExecutionInstance executionInstance = (ExecutionInstance)obj;
@ -7131,7 +7159,7 @@ namespace IDE
}
}
public ExecutionInstance DoRun(String inFileName, String args, String workingDir, ArgsFileKind useArgsFile, Dictionary<String, String> envVars = null)
public ExecutionInstance DoRun(String inFileName, String args, String workingDir, ArgsFileKind useArgsFile, Dictionary<String, String> envVars = null, String stdInData = null)
{
//Debug.Assert(executionInstance == null);
@ -7146,6 +7174,8 @@ namespace IDE
startInfo.SetArguments(args);
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
if (stdInData != null)
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
if (envVars != null)
{
@ -7224,6 +7254,13 @@ namespace IDE
executionInstance.mErrorThread = new Thread(new => ReadErrorThread);
executionInstance.mErrorThread.Start(executionInstance, false);
if (stdInData != null)
{
executionInstance.mStdInData = new String(stdInData);
executionInstance.mInputThread = new Thread(new => WriteInputThread);
executionInstance.mInputThread.Start(executionInstance, false);
}
return executionInstance;
}
@ -7502,7 +7539,7 @@ namespace IDE
else if (next is ExecutionQueueCmd)
{
var executionQueueCmd = (ExecutionQueueCmd)next;
var executionInstance = DoRun(executionQueueCmd.mFileName, executionQueueCmd.mArgs, executionQueueCmd.mWorkingDir, executionQueueCmd.mUseArgsFile, executionQueueCmd.mEnvVars);
var executionInstance = DoRun(executionQueueCmd.mFileName, executionQueueCmd.mArgs, executionQueueCmd.mWorkingDir, executionQueueCmd.mUseArgsFile, executionQueueCmd.mEnvVars, executionQueueCmd.mStdInData);
executionInstance.mParallelGroup = executionQueueCmd.mParallelGroup;
executionInstance.mIsTargetRun = executionQueueCmd.mIsTargetRun;
}
@ -7903,12 +7940,23 @@ namespace IDE
success = false;
}
}
else if (options.mBuildOptions.mBuildKind == .StaticLib)
{
if (project.mGeneralOptions.mTargetType.IsBeefApplication)
targetType = .BeefApplication_StaticLib;
}
else if (options.mBuildOptions.mBuildKind == .DynamicLib)
{
if (project.mGeneralOptions.mTargetType.IsBeefApplication)
targetType = .BeefApplication_DynamicLib;
}
}
bfProject.SetOptions(targetType,
project.mBeefGlobalOptions.mStartupObject,
preprocessorMacros.mDefines,
optimizationLevel, ltoType, options.mBeefOptions.mMergeFunctions, options.mBeefOptions.mCombineLoads,
optimizationLevel, ltoType, options.mBeefOptions.mRelocType, options.mBeefOptions.mPICLevel,
options.mBeefOptions.mMergeFunctions, options.mBeefOptions.mCombineLoads,
options.mBeefOptions.mVectorizeLoops, options.mBeefOptions.mVectorizeSLP);
List<Project> depProjectList = scope List<Project>();
@ -8378,6 +8426,27 @@ namespace IDE
return false;
let platformType = Workspace.PlatformType.GetFromName(platformName);
if (options.mBuildOptions.mBuildKind.IsApplicationLib)
{
switch (platformType)
{
case .Windows:
newString.Append(".lib");
case .iOS:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".dylib");
else
newString.Append(".a");
default:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".so");
else
newString.Append(".a");
}
}
else
{
switch (platformType)
{
case .Windows:
@ -8395,6 +8464,7 @@ namespace IDE
newString.Append(".so");
}
}
}
case "ProjectDir":
if (project.IsDebugSession)
{
@ -8633,6 +8703,9 @@ namespace IDE
else
{
clangOptions.Append("--target=");
if (TargetTriple.IsTargetTriple(gApp.mPlatformName))
clangOptions.Append(gApp.mPlatformName);
else
Workspace.PlatformType.GetTargetTripleByName(gApp.mPlatformName, workspaceOptions.mToolsetType, clangOptions);
clangOptions.Append(" ");

View file

@ -792,6 +792,16 @@ namespace IDE
{
case Normal;
case Test;
case StaticLib;
case DynamicLib;
public bool IsApplicationLib
{
get
{
return (this == .StaticLib) || (this == .DynamicLib);
}
}
}
public enum COptimizationLevel
@ -838,7 +848,9 @@ namespace IDE
CustomBuild,
C_ConsoleApplication,
C_WindowsApplication,
BeefTest;
BeefTest,
BeefApplication_StaticLib,
BeefApplication_DynamicLib;
public bool IsBeef
{
@ -850,8 +862,25 @@ namespace IDE
BeefWindowsApplication,
BeefLib,
BeefDynLib,
BeefTest: return true;
default: return false;
BeefTest:
return true;
default:
return false;
}
}
}
public bool IsBeefApplication
{
get
{
switch (this)
{
case BeefConsoleApplication,
BeefWindowsApplication:
return true;
default:
return false;
}
}
}
@ -1005,6 +1034,10 @@ namespace IDE
[Reflect]
public List<String> mPreprocessorMacros = new List<String>() ~ DeleteContainerAndItems!(_);
[Reflect]
public BuildOptions.RelocType mRelocType;
[Reflect]
public BuildOptions.PICLevel mPICLevel;
[Reflect]
public BuildOptions.BfOptimizationLevel? mOptimizationLevel;
[Reflect]
public BuildOptions.LTOType? mLTOType;
@ -1103,6 +1136,8 @@ namespace IDE
Set!(newOptions.mBeefOptions.mPreprocessorMacros, mBeefOptions.mPreprocessorMacros);
Set!(newOptions.mBeefOptions.mOptimizationLevel, mBeefOptions.mOptimizationLevel);
Set!(newOptions.mBeefOptions.mLTOType, mBeefOptions.mLTOType);
Set!(newOptions.mBeefOptions.mRelocType, mBeefOptions.mRelocType);
Set!(newOptions.mBeefOptions.mPICLevel, mBeefOptions.mPICLevel);
Set!(newOptions.mBeefOptions.mMergeFunctions, mBeefOptions.mMergeFunctions);
Set!(newOptions.mBeefOptions.mCombineLoads, mBeefOptions.mCombineLoads);
Set!(newOptions.mBeefOptions.mVectorizeLoops, mBeefOptions.mVectorizeLoops);
@ -1522,6 +1557,8 @@ namespace IDE
data.Add(macro);
}
}
data.ConditionalAdd("RelocType", options.mBeefOptions.mRelocType, .NotSet);
data.ConditionalAdd("PICLevel", options.mBeefOptions.mPICLevel, .NotSet);
data.ConditionalAdd("OptimizationLevel", options.mBeefOptions.mOptimizationLevel);
data.ConditionalAdd("LTOType", options.mBeefOptions.mLTOType);
data.ConditionalAdd("MergeFunctions", options.mBeefOptions.mMergeFunctions);
@ -1826,6 +1863,8 @@ namespace IDE
options.mBeefOptions.mPreprocessorMacros.Add(new String("TEST"));
}
options.mBeefOptions.mRelocType = data.GetEnum<BuildOptions.RelocType>("RelocType");
options.mBeefOptions.mPICLevel = data.GetEnum<BuildOptions.PICLevel>("PICLevel");
if (data.Contains("OptimizationLevel"))
options.mBeefOptions.mOptimizationLevel = data.GetEnum<BuildOptions.BfOptimizationLevel>("OptimizationLevel");
if (data.Contains("LTOType"))
@ -2135,6 +2174,7 @@ namespace IDE
bool isParanoid = configName.Contains("Paranoid");
bool isDebug = isParanoid || configName.Contains("Debug");
bool isTest = configName.Contains("Test");
let platformType = Workspace.PlatformType.GetFromName(platformName);
if (isRelease)
options.mBeefOptions.mPreprocessorMacros.Add(new String("RELEASE"));
@ -2149,7 +2189,20 @@ namespace IDE
options.mBuildOptions.mBeefLibType = isRelease ? .Static : .Dynamic;
options.mBuildOptions.mStackSize = 0;
switch (platformType)
{
case .Linux,
.Windows,
.macOS:
options.mBuildOptions.mBuildKind = isTest ? .Test : .Normal;
default:
options.mBuildOptions.mBuildKind = .StaticLib;
}
if (platformType == .Android)
{
options.mBeefOptions.mRelocType = .PIC;
}
options.mBuildOptions.mOtherLinkFlags.Set("$(LinkFlags)");

View file

@ -27,6 +27,7 @@ namespace IDE
case Linux;
case macOS;
case iOS;
case Android;
public static PlatformType GetFromName(String name)
{
@ -36,7 +37,8 @@ namespace IDE
case "Linux32", "Linux64": return .Linux;
case "macOS": return .macOS;
case "iOS": return .iOS;
default: return .Unknown;
default:
return TargetTriple.GetPlatformType(name);
}
}
@ -60,7 +62,11 @@ namespace IDE
public static int GetPtrSizeByName(String name)
{
if (name.EndsWith("32"))
if ((name.EndsWith("32")) && (!TargetTriple.IsTargetTriple(name)))
return 4;
if (name.StartsWith("armv"))
return 4;
if (name.StartsWith("i686-"))
return 4;
return 8;
}
@ -80,7 +86,7 @@ namespace IDE
case "macOS":
outTriple.Append("x86_64-apple-macosx10.14.0");
case "iOS":
outTriple.Append("aarch64-apple-ios");
outTriple.Append("arm64-apple-ios");
default:
return false;
}
@ -167,6 +173,8 @@ namespace IDE
{
[Reflect]
public List<String> mPreprocessorMacros = new List<String>() ~ DeleteContainerAndItems!(_);
/*[Reflect]
public String mTargetTriple = new .() ~ delete _;*/
[Reflect]
public List<DistinctBuildOptions> mDistinctBuildOptions = new List<DistinctBuildOptions>() ~ DeleteContainerAndItems!(_);
}
@ -505,6 +513,7 @@ namespace IDE
if (mStartupProject != null)
data.Add("StartupProject", mStartupProject.mProjectName);
WriteStrings("PreprocessorMacros", mBeefGlobalOptions.mPreprocessorMacros);
//data.ConditionalAdd("TargetTriple", mBeefGlobalOptions.mTargetTriple, "");
WriteDistinctOptions(mBeefGlobalOptions.mDistinctBuildOptions);
data.RemoveIfEmpty();
}
@ -697,15 +706,20 @@ namespace IDE
bool isTest = configName.Contains("Test");
let platformType = PlatformType.GetFromName(platformName);
/*if (TargetTriple.IsTargetTriple(platformName))
{
options.mToolsetType = .None;
}*/
options.mBfOptimizationLevel = isRelease ? .O2 : .O0;
options.mBfSIMDSetting = .SSE2;
if (platformType == .Windows)
{
options.mBfOptimizationLevel = isRelease ? .O2 : (platformName == "Win64") ? .OgPlus : .O0;
options.mToolsetType = .Microsoft;
}
else
else if ((platformType == .macOS) == (platformType == .Linux))
{
options.mBfOptimizationLevel = isRelease ? .O2 : .O0;
options.mToolsetType = .GNU;
}
@ -757,6 +771,7 @@ namespace IDE
data.GetCurString(str);
mBeefGlobalOptions.mPreprocessorMacros.Add(str);
}
//data.GetString("TargetTriple", mBeefGlobalOptions.mTargetTriple);
for (data.Enumerate("DistinctOptions"))
{

View file

@ -824,6 +824,8 @@ namespace IDE.ui
(category, propEntry) = AddPropertiesItem(root, "Code Generation");
category.mIsBold = true;
category.mTextColor = cHeaderColor;
AddPropertiesItem(category, "Reloc Model", "mBeefOptions.mRelocType");
AddPropertiesItem(category, "PIC Level", "mBeefOptions.mPICLevel");
AddPropertiesItem(category, "Optimization Level", "mBeefOptions.mOptimizationLevel",
scope String[] { "O0", "O1", "O2", "O3", "Og", "Og+" }); // -O0 .. -O3, -Os, -Ofast, -Og
AddPropertiesItem(category, "LTO", "mBeefOptions.mLTOType");

View file

@ -724,17 +724,20 @@ namespace IDE.ui
void PopulateBeefGlobalOptions()
{
var root = (DarkListViewItem)mPropPage.mPropertiesListView.GetRoot();
var (category, ?) = AddPropertiesItem(root, "General");
/*var (category, ?) = AddPropertiesItem(root, "General");
category.mIsBold = true;
category.mTextColor = 0xFFE8E8E8;
category.mTextColor = 0xFFE8E8E8;*/
AddPropertiesItem(category, "Preprocessor Macros", "mPreprocessorMacros");
AddPropertiesItem(root, "Preprocessor Macros", "mPreprocessorMacros");
DistinctOptionBuilder dictinctOptionBuilder = scope .(this);
dictinctOptionBuilder.Add(gApp.mWorkspace.mBeefGlobalOptions.mDistinctBuildOptions);
dictinctOptionBuilder.Finish();
//AddPropertiesItem(root, "Target Triple", "mTargetTriple");
AddNewDistinctBuildOptions();
//parent.MakeParent();
category.Open(true, true);
//category.Open(true, true);
}
void PopulateBeefTargetedOptions()

View file

@ -0,0 +1,55 @@
using System;
namespace IDE.Util
{
class TargetTriple
{
public static bool IsTargetTriple(StringView str)
{
int dashCount = 0;
for (let c in str.RawChars)
if (c == '-')
dashCount++;
return dashCount >= 2;
}
public static Workspace.PlatformType GetPlatformType(StringView str)
{
var str;
// Remove version from the end
while (!str.IsEmpty)
{
char8 c = str[str.Length - 1];
if ((c.IsDigit) || (c == '.'))
str.RemoveFromEnd(1);
else
break;
}
bool hasLinux = false;
for (let elem in str.Split('-'))
{
switch (elem)
{
case "linux":
hasLinux = true;
case "windows":
return .Windows;
case "macosx":
return .macOS;
case "ios":
return .iOS;
case "android",
"androideabi":
return .Android;
}
}
if (hasLinux)
return .Linux;
return .Unknown;
}
}
}

View file

@ -1598,7 +1598,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
paramTypes.push_back(nullPtrType); // lpvReserved
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain");
if (mSystem->mPtrSize == 4)
if (mOptions.mMachineType == BfMachineType_x86)
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
bfModule->SetupIRMethod(NULL, mainFunc, false);
}
@ -1611,7 +1611,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
paramTypes.push_back(int32Type); // nCmdShow
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain");
if (mSystem->mPtrSize == 4)
if (mOptions.mMachineType == BfMachineType_x86)
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
bfModule->SetupIRMethod(NULL, mainFunc, false);
}
@ -1620,7 +1620,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
SmallVector<BfIRType, 2> paramTypes;
paramTypes.push_back(int32Type);
paramTypes.push_back(nullPtrType);
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain");
bfModule->SetupIRMethod(NULL, mainFunc, false);
}
@ -1711,7 +1711,8 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
}
BfIRValue retValue;
if ((project->mTargetType == BfTargetType_BeefConsoleApplication) || (project->mTargetType == BfTargetType_BeefWindowsApplication))
if ((project->mTargetType == BfTargetType_BeefConsoleApplication) || (project->mTargetType == BfTargetType_BeefWindowsApplication) ||
(project->mTargetType == BfTargetType_BeefApplication_StaticLib) || (project->mTargetType == BfTargetType_BeefApplication_DynamicLib))
{
bool hadRet = false;
@ -1785,7 +1786,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
}
BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefMain");
BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefStartProgram");
bfModule->SetupIRMethod(NULL, thunkMainFunc, false);
bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc);
@ -5879,7 +5880,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
if ((bfProject->mTargetType != BfTargetType_BeefConsoleApplication) && (bfProject->mTargetType != BfTargetType_BeefWindowsApplication) &&
(bfProject->mTargetType != BfTargetType_BeefDynLib) &&
(bfProject->mTargetType != BfTargetType_C_ConsoleApplication) && (bfProject->mTargetType != BfTargetType_C_WindowsApplication) &&
(bfProject->mTargetType != BfTargetType_BeefTest))
(bfProject->mTargetType != BfTargetType_BeefTest) &&
(bfProject->mTargetType != BfTargetType_BeefApplication_StaticLib) && (bfProject->mTargetType != BfTargetType_BeefApplication_DynamicLib))
continue;
if (bfProject->mTargetType == BfTargetType_BeefTest)
@ -8122,6 +8124,38 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_HotResolve_Finish(BfCompiler* bfCom
return outString.c_str();
}
static BfPlatformType GetPlatform(StringView str)
{
while (!str.IsEmpty())
{
char c = str[str.mLength - 1];
if (((c >= '0') && (c <= '9')) || (c == '.'))
str.RemoveFromEnd(1);
else
break;
}
bool hasLinux = false;
for (auto elem : str.Split('-'))
{
if (elem == "linux")
hasLinux = true;
else if (elem == "windows")
return BfPlatformType_Windows;
else if (elem == "macosx")
return BfPlatformType_macOS;
else if (elem == "ios")
return BfPlatformType_iOS;
else if ((elem == "android") || (elem == "androideabi"))
return BfPlatformType_Android;
}
if (hasLinux)
return BfPlatformType_Linux;
return BfPlatformType_Unknown;
}
BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProject* hotProject, int hotIdx,
const char* targetTriple, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads,
BfCompilerOptionFlags optionFlags, char* mallocLinkName, char* freeLinkName)
@ -8141,9 +8175,22 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje
options->mMachineType = BfMachineType_x64;
else if (options->mTargetTriple.StartsWith("i686-"))
options->mMachineType = BfMachineType_x86;
else if ((options->mTargetTriple.StartsWith("arm64")) || (options->mTargetTriple.StartsWith("aarch64")))
options->mMachineType = BfMachineType_AArch64;
else if (options->mTargetTriple.StartsWith("armv"))
options->mMachineType = BfMachineType_ARM;
else
options->mMachineType = BfMachineType_x64; // Default
options->mPlatformType = GetPlatform(options->mTargetTriple);
options->mCLongSize = 4;
if ((options->mMachineType == BfMachineType_AArch64) || (options->mMachineType == BfMachineType_x64))
{
if ((options->mPlatformType == BfPlatformType_macOS) || (options->mPlatformType == BfPlatformType_iOS) || (options->mPlatformType == BfPlatformType_Android))
options->mCLongSize = 8;
}
bfCompiler->mCodeGen.SetMaxThreads(maxWorkerThreads);
if (!bfCompiler->mIsResolveOnly)
@ -8169,15 +8216,15 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje
options->mOmitDebugHelpers = (optionFlags & BfCompilerOptionFlag_OmitDebugHelpers) != 0;
#ifdef _WINDOWS
if (options->mToolsetType == BfToolsetType_GNU)
{
options->mErrorString = "Toolset 'GNU' is not available on this platform. Consider changing 'Workspace/General/Toolset'.";
}
// if (options->mToolsetType == BfToolsetType_GNU)
// {
// options->mErrorString = "Toolset 'GNU' is not available on this platform. Consider changing 'Workspace/General/Toolset'.";
// }
#else
if (options->mToolsetType == BfToolsetType_Microsoft)
{
options->mErrorString = "Toolset 'Microsoft' is not available on this platform. Consider changing 'Workspace/General/Toolset'.";
}
// if (options->mToolsetType == BfToolsetType_Microsoft)
// {
// options->mErrorString = "Toolset 'Microsoft' is not available on this platform. Consider changing 'Workspace/General/Toolset'.";
// }
BF_ASSERT(!options->mEnableRealtimeLeakCheck);
#endif
options->mEmitObjectAccessCheck = (optionFlags & BfCompilerOptionFlag_EmitDebugInfo) != 0;

View file

@ -94,7 +94,9 @@ public:
int32 mForceRebuildIdx;
BfCompileOnDemandKind mCompileOnDemandKind;
String mTargetTriple;
BfPlatformType mPlatformType;
BfMachineType mMachineType;
int mCLongSize;
BfToolsetType mToolsetType;
BfSIMDSetting mSIMDSetting;
int mMaxWorkerThreads;
@ -140,7 +142,9 @@ public:
mHotCompileIdx = 0;
mForceRebuildIdx = 0;
mCompileOnDemandKind = BfCompileOnDemandKind_AlwaysInclude;
mPlatformType = BfPlatformType_Unknown;
mMachineType = BfMachineType_x86;
mCLongSize = 4;
mToolsetType = BfToolsetType_Microsoft;
mSIMDSetting = BfSIMDSetting_None;
mHotProject = NULL;

View file

@ -1632,7 +1632,8 @@ void BfContext::UpdateRevisedTypes()
BP_ZONE("BfContext::UpdateRevisedTypes");
int wantPtrSize;
if (mCompiler->mOptions.mMachineType == BfMachineType_x86)
if ((mCompiler->mOptions.mMachineType == BfMachineType_x86) |
(mCompiler->mOptions.mMachineType == BfMachineType_ARM))
wantPtrSize = 4;
else
wantPtrSize = 8;
@ -1788,9 +1789,12 @@ void BfContext::UpdateRevisedTypes()
//
{
AutoCrit autoCrit(mSystem->mDataLock);
auto options = &mCompiler->mOptions;
HashContext workspaceConfigHashCtx;
workspaceConfigHashCtx.MixinStr(options->mTargetTriple);
workspaceConfigHashCtx.Mixin(options->mForceRebuildIdx);
workspaceConfigHashCtx.Mixin(options->mMachineType);
@ -1813,6 +1817,8 @@ void BfContext::UpdateRevisedTypes()
workspaceConfigHashCtx.Mixin(options->mEnableCustodian);
workspaceConfigHashCtx.Mixin(options->mEnableSideStack);
workspaceConfigHashCtx.Mixin(options->mHasVDataExtender);
workspaceConfigHashCtx.Mixin(options->mDebugAlloc);
workspaceConfigHashCtx.Mixin(options->mOmitDebugHelpers);
workspaceConfigHashCtx.Mixin(options->mUseDebugBackingParams);
@ -1821,6 +1827,7 @@ void BfContext::UpdateRevisedTypes()
workspaceConfigHashCtx.Mixin(options->mAllocStackCount);
workspaceConfigHashCtx.Mixin(options->mExtraResolveChecks);
workspaceConfigHashCtx.Mixin(options->mMaxSplatRegs);
workspaceConfigHashCtx.MixinStr(options->mMallocLinkName);
workspaceConfigHashCtx.MixinStr(options->mFreeLinkName);
@ -1842,6 +1849,11 @@ void BfContext::UpdateRevisedTypes()
workspaceConfigHashCtx.Mixin(typeOptions.mAllocStackTraceDepth);
}
// for (auto project : mSystem->mProjects)
// {
// workspaceConfigHashCtx.MixinStr(project->mName);
// }
Val128 workspaceConfigHash = workspaceConfigHashCtx.Finish128();
mSystem->mWorkspaceConfigChanged = mSystem->mWorkspaceConfigHash != workspaceConfigHash;
@ -1853,7 +1865,6 @@ void BfContext::UpdateRevisedTypes()
mSystem->mWorkspaceConfigHash = workspaceConfigHash;
}
AutoCrit autoCrit(mSystem->mDataLock);
for (auto project : mSystem->mProjects)
{
HashContext buildConfigHashCtx;
@ -1863,6 +1874,9 @@ void BfContext::UpdateRevisedTypes()
{
auto& codeGenOptions = project->mCodeGenOptions;
buildConfigHashCtx.Mixin(project->mAlwaysIncludeAll);
buildConfigHashCtx.Mixin(project->mSingleModule);
bool isTestConfig = project->mTargetType == BfTargetType_BeefTest;
buildConfigHashCtx.Mixin(isTestConfig);
@ -1888,6 +1902,7 @@ void BfContext::UpdateRevisedTypes()
buildConfigHashCtx.Mixin(codeGenOptions.mRunSLPAfterLoopVectorization);
buildConfigHashCtx.Mixin(codeGenOptions.mUseGVNAfterVectorization);
}
buildConfigHashCtx.Mixin(project->mDisabled);
buildConfigHashCtx.Mixin(project->mTargetType);
for (auto dep : project->mDependencies)
@ -2226,6 +2241,12 @@ String BfContext::GenerateModuleName(BfTypeInstance* typeInst)
name.RemoveToEnd(80);
name += "__";
}
for (int i = 0; i < (int)name.length(); i++)
{
char c = name[i];
if (c == '@')
name[i] = '_';
}
String tryName = name;
for (int i = 2; true; i++)

View file

@ -2110,7 +2110,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDefine)
String prefix = typeDef->mProject->mName + ".";
StringT<128> mangledName;
mangledName += prefix;
BfMangler::Mangle(mangledName, mModule->mCompiler->GetMangleKind(), typeInstance);
BfMangler::Mangle(mangledName, mModule->mCompiler->GetMangleKind(), typeInstance, typeInstance->mModule);
BfIRType irStructType = CreateStructType(mangledName);
if (type->IsObjectOrInterface())
{

View file

@ -4009,6 +4009,41 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen
llvm::Optional<llvm::Reloc::Model> relocModel;
llvm::CodeModel::Model cmModel = llvm::CodeModel::Small;
switch (codeGenOptions.mRelocType)
{
case BfRelocType_Static:
relocModel = llvm::Reloc::Model::DynamicNoPIC;
break;
case BfRelocType_PIC:
relocModel = llvm::Reloc::Model::PIC_;
break;
case BfRelocType_DynamicNoPIC:
relocModel = llvm::Reloc::Model::DynamicNoPIC;
break;
case BfRelocType_ROPI:
relocModel = llvm::Reloc::Model::ROPI;
break;
case BfRelocType_RWPI:
relocModel = llvm::Reloc::Model::RWPI;
break;
case BfRelocType_ROPI_RWPI:
relocModel = llvm::Reloc::Model::ROPI_RWPI;
break;
}
switch (codeGenOptions.mPICLevel)
{
case BfPICLevel_Not:
mLLVMModule->setPICLevel(llvm::PICLevel::Level::NotPIC);
break;
case BfPICLevel_Small:
mLLVMModule->setPICLevel(llvm::PICLevel::Level::SmallPIC);
break;
case BfPICLevel_Big:
mLLVMModule->setPICLevel(llvm::PICLevel::Level::BigPIC);
break;
}
std::unique_ptr<llvm::TargetMachine> target(
theTarget->createTargetMachine(theTriple.getTriple(), cpuName.c_str(), featuresStr.c_str(),
Options, relocModel, cmModel, optLvl));
@ -4188,6 +4223,11 @@ void BfIRCodeGen::StaticInit()
LLVMInitializeX86AsmParser();
LLVMInitializeX86Disassembler();
LLVMInitializeARMTargetInfo();
LLVMInitializeARMTarget();
LLVMInitializeARMTargetMC();
LLVMInitializeARMAsmPrinter();
LLVMInitializeAArch64TargetInfo();
LLVMInitializeAArch64Target();
LLVMInitializeAArch64TargetMC();

View file

@ -56,13 +56,10 @@ BfTypeCode BfGNUMangler::GetPrimTypeAt(MangleContext& mangleContext, StringImpl&
case 't': return BfTypeCode_UInt16;
case 'i': return BfTypeCode_Int32;
case 'j': return BfTypeCode_UInt32;
#if __SIZEOF_LONG__ == 8
case 'l': return BfTypeCode_Int64;
case 'm': return BfTypeCode_UInt64;
#else
case 'x': return BfTypeCode_Int64;
case 'y': return BfTypeCode_UInt64;
#endif
case 'u':
if (name[strIdx + 1] == '3')
return BfTypeCode_IntPtr;
@ -234,9 +231,9 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl&
else
name += "4";
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
name += "@M";
name += "`M";
else
name += "@T";
name += "`T";
itoa(genericParamType->mGenericParamIdx, str, 10);
name += str;
}
@ -289,7 +286,7 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name
BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
String fieldName = fieldDef->mName;
if ((fieldName[0] < '0') || (fieldName[0] > '9'))
name += StrFormat("U%d@%s", fieldName.length() + 1, fieldName.c_str());
name += StrFormat("U%d`%s", fieldName.length() + 1, fieldName.c_str());
Mangle(mangleContext, name, fieldInstance->mResolvedType, postfixTypeInstance);
}
name += "E";
@ -444,25 +441,25 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType
name += "i"; return;
case BfTypeCode_UInt32:
name += "j"; return;
#if __SIZEOF_LONG__ == 8
case BfTypeCode_Int64:
name += "l"; return;
if (mangleContext.mModule->mCompiler->mOptions.mCLongSize == 8)
name += "l";
else
name += "x";
return;
case BfTypeCode_UInt64:
name += "m"; return;
#else
case BfTypeCode_Int64:
name += "x"; return;
case BfTypeCode_UInt64:
name += "y"; return;
#endif
if (mangleContext.mModule->mCompiler->mOptions.mCLongSize == 8)
name += "m";
else
name += "y";
return;
case BfTypeCode_UIntPtr:
if ((mangleContext.mCCompat) || (mangleContext.mInArgs))
{
#if __SIZEOF_LONG__ == 8
if (mangleContext.mModule->mCompiler->mOptions.mCLongSize == 8)
name += (primType->mSize == 8) ? "m" : "j";
#else
else
name += (primType->mSize == 8) ? "y" : "j";
#endif
return;
}
name += "u4uint";
@ -470,11 +467,10 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType
case BfTypeCode_IntPtr:
if ((mangleContext.mCCompat) || (mangleContext.mInArgs))
{
#if __SIZEOF_LONG__ == 8
if (mangleContext.mModule->mCompiler->mOptions.mCLongSize == 8)
name += (primType->mSize == 8) ? "l" : "i";
#else
else
name += (primType->mSize == 8) ? "x" : "i";
#endif
return;
}
name += "u3int";
@ -635,7 +631,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType
}
name += strP;
name += '@';
name += '`';
}
}
else
@ -834,7 +830,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst)
{
if (methodInst->mMangleWithIdx)
{
methodName += StrFormat("@%d", methodInst->mMethodDef->mIdx);
methodName += StrFormat("`%d", methodInst->mMethodDef->mIdx);
mangledMethodIdx = true;
}
@ -842,9 +838,9 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst)
}
if (methodDef->mCheckedKind == BfCheckedKind_Checked)
name += "@CHK";
name += "`CHK";
else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked)
name += "@UCHK";
name += "`UCHK";
if ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (!methodInst->mIsForeignMethodDef))
{
@ -877,14 +873,14 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst)
if ((methodInst->mMangleWithIdx) && (!mangledMethodIdx))
{
methodName += StrFormat("@%d", methodInst->mMethodDef->mIdx);
methodName += StrFormat("`%d", methodInst->mMethodDef->mIdx);
}
//
if ((prefixLen) && (methodInst->mMethodInstanceGroup->mOwner->mTypeDef->IsGlobalsContainer()) && (methodInst->mMethodDef->mMethodDeclaration == NULL))
{
methodName += '@';
methodName += '`';
methodName += methodInst->mMethodInstanceGroup->mOwner->mTypeDef->mProject->mName;
}

View file

@ -4319,12 +4319,12 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
{
BfMangler::MangleStaticFieldName(typeDataName, mCompiler->GetMangleKind(), typeInstance, "sBfTypeData");
if (typeInstance->mTypeDef->IsGlobalsContainer())
typeDataName += "@" + typeInstance->mTypeDef->mProject->mName;
typeDataName += "`G`" + typeInstance->mTypeDef->mProject->mName;
}
else
{
typeDataName += "sBfTypeData.";
BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type);
BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, mContext->mScratchModule);
}
int typeCode = BfTypeCode_None;
@ -4460,7 +4460,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfTypeDef* typeDef = typeInstance->mTypeDef;
StringT<128> mangledName;
BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), typeInstance);
BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), typeInstance, typeInstance->mModule);
for (int methodIdx = 0; methodIdx < (int)typeDef->mMethods.size(); methodIdx++)
{
@ -13619,7 +13619,7 @@ void BfModule::CreateDllImportMethod()
BfIRCallingConv BfModule::GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef)
{
if (mSystem->mPtrSize == 8)
if ((mCompiler->mOptions.mMachineType != BfMachineType_x86) || (mCompiler->mOptions.mPlatformType != BfPlatformType_Windows))
return BfIRCallingConv_CDecl;
if (methodDef->mCallingConvention == BfCallingConvention_Stdcall)
return BfIRCallingConv_StdCall;

View file

@ -3593,7 +3593,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, BfProjectFlags flags)
int optLevel, int ltoType, int relocType, int picLevel, BfProjectFlags flags)
{
bfProject->mTargetType = (BfTargetType)targetType;
bfProject->mStartupObject = startupObject;
@ -3601,6 +3601,8 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target
BfCodeGenOptions codeGenOptions;
codeGenOptions.mOptLevel = (BfOptLevel)optLevel;
codeGenOptions.mLTOType = (BfLTOType)ltoType;
codeGenOptions.mRelocType = (BfRelocType)relocType;
codeGenOptions.mPICLevel = (BfPICLevel)picLevel;
codeGenOptions.mMergeFunctions = (flags & BfProjectFlags_MergeFunctions) != 0;
codeGenOptions.mLoadCombine = (flags & BfProjectFlags_CombineLoads) != 0;
codeGenOptions.mLoopVectorize = (flags & BfProjectFlags_VectorizeLoops) != 0;

View file

@ -204,11 +204,22 @@ enum BfCustomAttributeFlags
BfCustomAttributeFlags_AlwaysIncludeTarget = 8
};
enum BfPlatformType
{
BfPlatformType_Unknown,
BfPlatformType_Windows,
BfPlatformType_Linux,
BfPlatformType_macOS,
BfPlatformType_iOS,
BfPlatformType_Android,
};
enum BfMachineType
{
BfMachineType_Unknown,
BfMachineType_x86,
BfMachineType_x64,
BfMachineType_ARM,
BfMachineType_AArch64
};
@ -265,6 +276,25 @@ enum BfCFLAAType
BfCFLAAType_Both
};
enum BfRelocType
{
BfRelocType_NotSet,
BfRelocType_Static,
BfRelocType_PIC,
BfRelocType_DynamicNoPIC,
BfRelocType_ROPI,
BfRelocType_RWPI,
BfRelocType_ROPI_RWPI
};
enum BfPICLevel
{
BfPICLevel_NotSet,
BfPICLevel_Not,
BfPICLevel_Small,
BfPICLevel_Big
};
struct BfCodeGenOptions
{
bool mIsHotCompile;
@ -277,6 +307,8 @@ struct BfCodeGenOptions
int16 mVirtualMethodOfs;
int16 mDynSlotOfs;
BfRelocType mRelocType;
BfPICLevel mPICLevel;
BfSIMDSetting mSIMDSetting;
BfOptLevel mOptLevel;
BfLTOType mLTOType;
@ -328,6 +360,8 @@ struct BfCodeGenOptions
mVirtualMethodOfs = 0;
mDynSlotOfs = 0;
mRelocType = BfRelocType_NotSet;
mPICLevel = BfPICLevel_NotSet;
mSIMDSetting = BfSIMDSetting_None;
mOptLevel = BfOptLevel_O0;
mLTOType = BfLTOType_None;
@ -378,6 +412,8 @@ struct BfCodeGenOptions
hashCtx.Mixin(mVirtualMethodOfs);
hashCtx.Mixin(mDynSlotOfs);
hashCtx.Mixin(mRelocType);
hashCtx.Mixin(mPICLevel);
hashCtx.Mixin(mSIMDSetting);
hashCtx.Mixin(mOptLevel);
hashCtx.Mixin(mLTOType);
@ -950,7 +986,9 @@ enum BfTargetType
BfTargetType_CustomBuild,
BfTargetType_C_ConsoleApplication,
BfTargetType_C_WindowsApplication,
BfTargetType_BeefTest
BfTargetType_BeefTest,
BfTargetType_BeefApplication_StaticLib,
BfTargetType_BeefApplication_DynamicLib
};
enum BfProjectFlags

View file

@ -171,7 +171,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<OutputFile>$(SolutionDir)\IDE\dist\$(TargetName).dll</OutputFile>
<AdditionalDependencies>rpcrt4.lib;cabinet.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;libcurl_a.lib;wininet.lib;LLVMMCDisassembler.lib;LLVMSupport.lib;LLVMMC.lib;LLVMObject.lib;LLVMCore.lib;LLVMBitReader.lib;LLVMAsmParser.lib;LLVMMCParser.lib;LLVMCodeGen.lib;LLVMTarget.lib;LLVMScalarOpts.lib;LLVMInstCombine.lib;LLVMSelectionDAG.lib;LLVMProfileData.lib;LLVMTransformUtils.lib;LLVMAnalysis.lib;LLVMAsmPrinter.lib;LLVMBitWriter.lib;LLVMVectorize.lib;LLVMipo.lib;LLVMInstrumentation.lib;LLVMDebugInfoDWARF.lib;LLVMDebugInfoPDB.lib;LLVMDebugInfoCodeView.lib;LLVMGlobalISel.lib;LLVMBinaryFormat.lib;LLVMLTO.lib;LLVMPasses.lib;LLVMLinker.lib;LLVMIRReader.lib;LLVMDemangle.lib;LLVMAggressiveInstCombine.lib;LLVMX86Info.lib;LLVMX86Utils.lib;LLVMX86AsmPrinter.lib;LLVMX86Desc.lib;LLVMX86CodeGen.lib;LLVMX86AsmParser.lib;LLVMX86Disassembler.lib;LLVMAArch64Info.lib;LLVMAArch64Utils.lib;LLVMAArch64AsmPrinter.lib;LLVMAArch64Desc.lib;LLVMAArch64CodeGen.lib;LLVMAArch64AsmParser.lib;LLVMAArch64Disassembler.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>rpcrt4.lib;cabinet.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;libcurl_a.lib;wininet.lib;LLVMMCDisassembler.lib;LLVMSupport.lib;LLVMMC.lib;LLVMObject.lib;LLVMCore.lib;LLVMBitReader.lib;LLVMAsmParser.lib;LLVMMCParser.lib;LLVMCodeGen.lib;LLVMTarget.lib;LLVMScalarOpts.lib;LLVMInstCombine.lib;LLVMSelectionDAG.lib;LLVMProfileData.lib;LLVMTransformUtils.lib;LLVMAnalysis.lib;LLVMAsmPrinter.lib;LLVMBitWriter.lib;LLVMVectorize.lib;LLVMipo.lib;LLVMInstrumentation.lib;LLVMDebugInfoDWARF.lib;LLVMDebugInfoPDB.lib;LLVMDebugInfoCodeView.lib;LLVMGlobalISel.lib;LLVMBinaryFormat.lib;LLVMLTO.lib;LLVMPasses.lib;LLVMLinker.lib;LLVMIRReader.lib;LLVMDemangle.lib;LLVMAggressiveInstCombine.lib;LLVMX86Info.lib;LLVMX86Utils.lib;LLVMX86AsmPrinter.lib;LLVMX86Desc.lib;LLVMX86CodeGen.lib;LLVMX86AsmParser.lib;LLVMX86Disassembler.lib;LLVMAArch64Info.lib;LLVMAArch64Utils.lib;LLVMAArch64AsmPrinter.lib;LLVMAArch64Desc.lib;LLVMAArch64CodeGen.lib;LLVMAArch64AsmParser.lib;LLVMAArch64Disassembler.lib;LLVMARMInfo.lib;LLVMARMUtils.lib;LLVMARMAsmPrinter.lib;LLVMARMDesc.lib;LLVMARMCodeGen.lib;LLVMARMAsmParser.lib;LLVMARMDisassembler.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\extern\llvm_win64_8_0_1\Debug\lib; ..\extern\curl\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-winssl\lib;..\extern\curl\deps\lib;..\extern\jemalloc_win\x64\debug</AdditionalLibraryDirectories>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<ImportLibrary>$(SolutionDir)\IDE\dist\$(TargetName).lib</ImportLibrary>
@ -230,7 +230,7 @@
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(SolutionDir)\IDE\dist\$(TargetName).dll</OutputFile>
<AdditionalLibraryDirectories>..\extern\llvm_win64_8_0_1\Release\lib; ..\extern\curl\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-winssl\lib;..\extern\curl\deps\lib;..\extern\jemalloc_win\x64\release</AdditionalLibraryDirectories>
<AdditionalDependencies>rpcrt4.lib;cabinet.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;libcurl_a.lib;wininet.lib;LLVMMCDisassembler.lib;LLVMSupport.lib;LLVMMC.lib;LLVMObject.lib;LLVMCore.lib;LLVMBitReader.lib;LLVMAsmParser.lib;LLVMMCParser.lib;LLVMCodeGen.lib;LLVMTarget.lib;LLVMScalarOpts.lib;LLVMInstCombine.lib;LLVMSelectionDAG.lib;LLVMProfileData.lib;LLVMTransformUtils.lib;LLVMAnalysis.lib;LLVMAsmPrinter.lib;LLVMBitWriter.lib;LLVMVectorize.lib;LLVMipo.lib;LLVMInstrumentation.lib;LLVMDebugInfoDWARF.lib;LLVMDebugInfoPDB.lib;LLVMDebugInfoCodeView.lib;LLVMGlobalISel.lib;LLVMBinaryFormat.lib;LLVMLTO.lib;LLVMPasses.lib;LLVMLinker.lib;LLVMIRReader.lib;LLVMDemangle.lib;LLVMAggressiveInstCombine.lib;LLVMX86Info.lib;LLVMX86Utils.lib;LLVMX86AsmPrinter.lib;LLVMX86Desc.lib;LLVMX86CodeGen.lib;LLVMX86AsmParser.lib;LLVMX86Disassembler.lib;LLVMAArch64Info.lib;LLVMAArch64Utils.lib;LLVMAArch64AsmPrinter.lib;LLVMAArch64Desc.lib;LLVMAArch64CodeGen.lib;LLVMAArch64AsmParser.lib;LLVMAArch64Disassembler.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>rpcrt4.lib;cabinet.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;libcurl_a.lib;wininet.lib;LLVMMCDisassembler.lib;LLVMSupport.lib;LLVMMC.lib;LLVMObject.lib;LLVMCore.lib;LLVMBitReader.lib;LLVMAsmParser.lib;LLVMMCParser.lib;LLVMCodeGen.lib;LLVMTarget.lib;LLVMScalarOpts.lib;LLVMInstCombine.lib;LLVMSelectionDAG.lib;LLVMProfileData.lib;LLVMTransformUtils.lib;LLVMAnalysis.lib;LLVMAsmPrinter.lib;LLVMBitWriter.lib;LLVMVectorize.lib;LLVMipo.lib;LLVMInstrumentation.lib;LLVMDebugInfoDWARF.lib;LLVMDebugInfoPDB.lib;LLVMDebugInfoCodeView.lib;LLVMGlobalISel.lib;LLVMBinaryFormat.lib;LLVMLTO.lib;LLVMPasses.lib;LLVMLinker.lib;LLVMIRReader.lib;LLVMDemangle.lib;LLVMAggressiveInstCombine.lib;LLVMX86Info.lib;LLVMX86Utils.lib;LLVMX86AsmPrinter.lib;LLVMX86Desc.lib;LLVMX86CodeGen.lib;LLVMX86AsmParser.lib;LLVMX86Disassembler.lib;LLVMAArch64Info.lib;LLVMAArch64Utils.lib;LLVMAArch64AsmPrinter.lib;LLVMAArch64Desc.lib;LLVMAArch64CodeGen.lib;LLVMAArch64AsmParser.lib;LLVMAArch64Disassembler.lib;LLVMARMInfo.lib;LLVMARMUtils.lib;LLVMARMAsmPrinter.lib;LLVMARMDesc.lib;LLVMARMCodeGen.lib;LLVMARMAsmParser.lib;LLVMARMDisassembler.lib;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<FullProgramDatabaseFile>true</FullProgramDatabaseFile>
<ImportLibrary>$(SolutionDir)\IDE\dist\$(TargetName).lib</ImportLibrary>

210
bin/build_android.bat Normal file
View file

@ -0,0 +1,210 @@
PUSHD %~dp0..\
SET NDK=C:\Users\Brian\AppData\Local\Android\Sdk\ndk\20.0.5594570
SET NINJA=C:\Users\Brian\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe
@REM SET NDK=C:\NVPACK\android-ndk-r14b
@REM i686-none-linux-android16
@REM i686-linux-android armv7-none-linux-androideabi16
cd builds
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
@IF EXIST android_x86 GOTO DO_BUILD
mkdir android_x86_d
cd android_x86_d
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=x86 ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=x86 ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Debug ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_x86
cd android_x86
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=x86 ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=x86 ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Release ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_x86_64_d
cd android_x86_64_d
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=x86_64 ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=x86_64 ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Debug ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_x86_64
cd android_x86_64
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=x86_64 ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=x86_64 ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Release ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_arm_d
cd android_arm_d
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=armeabi-v7a ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Debug ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_arm
cd android_arm
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=armeabi-v7a ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-16 ^
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=16 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Release ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_arm64_d
cd android_arm64_d
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=arm64-v8a ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-21 ^
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=21 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Debug ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
mkdir android_arm64
cd android_arm64
cmake -GNinja ^
-DANDROID_ABI:UNINITIALIZED=arm64-v8a ^
-DANDROID_NDK=%NDK% ^
-DANDROID_PLATFORM=android-21 ^
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a ^
-DCMAKE_ANDROID_NDK=%NDK% ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_SYSTEM_VERSION=21 ^
-DCMAKE_TOOLCHAIN_FILE=%NDK%\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%NINJA% ^
-DCMAKE_BUILD_TYPE=Release ^
..\..\BeefRT
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
:DO_BUILD
cd android_x86_d
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_x86
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_x86_64_d
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_x86_64
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_arm_d
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_arm
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_arm64_d
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
cd android_arm64
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cmake --build .
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
cd ..
:SUCCESS
@ECHO SUCCESS!
@POPD
@EXIT /b 0
:HADERROR
@ECHO =================FAILED=================
@POPD
@EXIT /b %ERRORLEVEL%