Created
December 27, 2016 09:20
-
-
Save joakim-noah/bf9f6fd748e8061ac918da0b1caf6e07 to your computer and use it in GitHub Desktop.
LDC for native Android/ARM, applied to the master branch 2.071
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ddmd/builtin.d b/ddmd/builtin.d | |
index 6f08ee1e..034e89d9 100644 | |
--- a/ddmd/builtin.d | |
+++ b/ddmd/builtin.d | |
@@ -51,21 +51,21 @@ extern (C++) Expression eval_sin(Loc loc, FuncDeclaration fd, Expressions* argum | |
{ | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, sinl(arg0.toReal()), arg0.type); | |
+ return new RealExp(loc, sin(arg0.toReal()), arg0.type); | |
} | |
extern (C++) Expression eval_cos(Loc loc, FuncDeclaration fd, Expressions* arguments) | |
{ | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, cosl(arg0.toReal()), arg0.type); | |
+ return new RealExp(loc, cos(arg0.toReal()), arg0.type); | |
} | |
extern (C++) Expression eval_tan(Loc loc, FuncDeclaration fd, Expressions* arguments) | |
{ | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, tanl(arg0.toReal()), arg0.type); | |
+ return new RealExp(loc, tan(arg0.toReal()), arg0.type); | |
} | |
extern (C++) Expression eval_sqrt(Loc loc, FuncDeclaration fd, Expressions* arguments) | |
@@ -79,7 +79,7 @@ extern (C++) Expression eval_fabs(Loc loc, FuncDeclaration fd, Expressions* argu | |
{ | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, fabsl(arg0.toReal()), arg0.type); | |
+ return new RealExp(loc, fabs(arg0.toReal()), arg0.type); | |
} | |
version(IN_LLVM) | |
@@ -132,7 +132,7 @@ extern (C++) Expression eval_llvmsin(Loc loc, FuncDeclaration fd, Expressions *a | |
Type type = getTypeOfOverloadedIntrinsic(fd); | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, sinl(arg0.toReal()), type); | |
+ return new RealExp(loc, sin(arg0.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmcos(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -140,7 +140,7 @@ extern (C++) Expression eval_llvmcos(Loc loc, FuncDeclaration fd, Expressions *a | |
Type type = getTypeOfOverloadedIntrinsic(fd); | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, cosl(arg0.toReal()), type); | |
+ return new RealExp(loc, cos(arg0.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmsqrt(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -148,7 +148,7 @@ extern (C++) Expression eval_llvmsqrt(Loc loc, FuncDeclaration fd, Expressions * | |
Type type = getTypeOfOverloadedIntrinsic(fd); | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, sqrtl(arg0.toReal()), type); | |
+ return new RealExp(loc, sqrt(arg0.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmlog(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -156,7 +156,7 @@ extern (C++) Expression eval_llvmlog(Loc loc, FuncDeclaration fd, Expressions *a | |
Type type = getTypeOfOverloadedIntrinsic(fd); | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, logl(arg0.toReal()), type); | |
+ return new RealExp(loc, log(arg0.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmfabs(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -164,7 +164,7 @@ extern (C++) Expression eval_llvmfabs(Loc loc, FuncDeclaration fd, Expressions * | |
Type type = getTypeOfOverloadedIntrinsic(fd); | |
Expression arg0 = (*arguments)[0]; | |
assert(arg0.op == TOKfloat64); | |
- return new RealExp(loc, fabsl(arg0.toReal()), type); | |
+ return new RealExp(loc, fabs(arg0.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmminnum(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -174,7 +174,7 @@ extern (C++) Expression eval_llvmminnum(Loc loc, FuncDeclaration fd, Expressions | |
assert(arg0.op == TOKfloat64); | |
Expression arg1 = (*arguments)[1]; | |
assert(arg1.op == TOKfloat64); | |
- return new RealExp(loc, fminl(arg0.toReal(), arg1.toReal()), type); | |
+ return new RealExp(loc, fmin(arg0.toReal(), arg1.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmmaxnum(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
@@ -184,7 +184,7 @@ extern (C++) Expression eval_llvmmaxnum(Loc loc, FuncDeclaration fd, Expressions | |
assert(arg0.op == TOKfloat64); | |
Expression arg1 = (*arguments)[1]; | |
assert(arg1.op == TOKfloat64); | |
- return new RealExp(loc, fmaxl(arg0.toReal(), arg1.toReal()), type); | |
+ return new RealExp(loc, fmax(arg0.toReal(), arg1.toReal()), type); | |
} | |
extern (C++) Expression eval_llvmfloor(Loc loc, FuncDeclaration fd, Expressions *arguments) | |
diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp | |
index 6e99c632..20d64ced 100644 | |
--- a/driver/ldmd.cpp | |
+++ b/driver/ldmd.cpp | |
@@ -1058,7 +1058,7 @@ int cppmain(int argc, char **argv) { | |
// Check if we need to write out a response file. | |
size_t totalLen = std::accumulate(args.begin(), args.end(), 0, addStrlen); | |
- if (totalLen > maxCommandLineLen()) { | |
+ if (totalLen > maxCommandLineLen() * 4) { | |
int rspFd; | |
llvm::SmallString<128> rspPath; | |
if (ls::fs::createUniqueFile("ldmd-%%-%%-%%-%%.rsp", rspFd, rspPath)) { | |
diff --git a/gen/inlineir.cpp b/gen/inlineir.cpp | |
index f6f2e41a..85c4eeca 100644 | |
--- a/gen/inlineir.cpp | |
+++ b/gen/inlineir.cpp | |
@@ -55,7 +55,9 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl, | |
// always inlined, this name does not escape the current compiled module; not | |
// even at -O0. | |
static size_t namecounter = 0; | |
- std::string mangled_name = "inline.ir." + std::to_string(namecounter++); | |
+ std::ostringstream os; | |
+ os << namecounter++; | |
+ std::string mangled_name = "inline.ir." + os.str(); | |
TemplateInstance *tinst = fdecl->parent->isTemplateInstance(); | |
assert(tinst); | |
diff --git a/gen/mangling.cpp b/gen/mangling.cpp | |
index 0d43d813..133d2d7f 100644 | |
--- a/gen/mangling.cpp | |
+++ b/gen/mangling.cpp | |
@@ -60,18 +60,26 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) { | |
if (auto packages = moddecl->packages) { | |
for (size_t i = 0; i < packages->dim; ++i) { | |
llvm::StringRef str = (*packages)[i]->toChars(); | |
- ret += std::to_string(str.size()); | |
+ std::ostringstream os; | |
+ os << str.size(); | |
+ ret += os.str(); | |
ret += str; | |
} | |
} | |
llvm::StringRef str = moddecl->id->toChars(); | |
- ret += std::to_string(str.size()); | |
+ std::ostringstream os; | |
+ os << str.size(); | |
+ ret += os.str(); | |
ret += str; | |
} | |
// source line number | |
- auto lineNo = std::to_string(symb->loc.linnum); | |
- ret += std::to_string(lineNo.size()+1); | |
+ std::ostringstream os; | |
+ os << symb->loc.linnum; | |
+ auto lineNo = os.str(); | |
+ std::ostringstream os2; | |
+ os2 << lineNo.size()+1; | |
+ ret += os2.str(); | |
ret += 'L'; | |
ret += lineNo; | |
@@ -83,13 +91,17 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) { | |
// top aggregate | |
if (auto agg = symb->isAggregateMember()) { | |
llvm::StringRef topaggr = agg->ident->toChars(); | |
- ret += std::to_string(topaggr.size()); | |
+ std::ostringstream os; | |
+ os << topaggr.size(); | |
+ ret += os.str(); | |
ret += topaggr; | |
} | |
// identifier | |
llvm::StringRef identifier = symb->toChars(); | |
- ret += std::to_string(identifier.size()); | |
+ std::ostringstream os3; | |
+ os3 << identifier.size(); | |
+ ret += os3.str(); | |
ret += identifier; | |
return ret; | |
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt | |
index d4c6838e..a0c39d38 100644 | |
--- a/runtime/CMakeLists.txt | |
+++ b/runtime/CMakeLists.txt | |
@@ -57,6 +57,7 @@ file(GLOB CORE_D ${RUNTIME_DIR}/src/core/*.d) | |
file(GLOB_RECURSE CORE_D_INTERNAL ${RUNTIME_DIR}/src/core/internal/*.d) | |
file(GLOB CORE_D_SYNC ${RUNTIME_DIR}/src/core/sync/*.d) | |
file(GLOB CORE_D_STDC ${RUNTIME_DIR}/src/core/stdc/*.d) | |
+list(REMOVE_ITEM CORE_D_STDC ${RUNTIME_DIR}/src/core/stdc/tgmath.d) | |
file(GLOB_RECURSE GC_D ${RUNTIME_DIR}/src/gc/*.d) | |
file(GLOB_RECURSE DCRT_D ${RUNTIME_DIR}/src/rt/*.d) | |
file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d) | |
@@ -514,7 +515,9 @@ include(profile-rt/DefineBuildProfileRT.cmake) | |
# Set up build targets. | |
# | |
-set(RT_CFLAGS "") | |
+set(RT_CFLAGS "-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security") | |
+set(RT_LDFLAGS "-Wl,-z,nocopyreloc;-lgcc;-target;armv7-none-linux-androideabi;-no-canonical-prefixes;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-mthumb;-Wl,--export-dynamic;-lc;-lm") | |
+set(TEST_SO_LDFLAGS "-Wl,-soname,libnative-activity${name_suffix}.so;-shared;-lgcc;-no-canonical-prefixes;-target;armv7-none-linux-androideabi;-Wl,--fix-cortex-a8;-Wl,--no-undefined;-Wl,-z,noexecstack;-Wl,-z,relro;-Wl,-z,now;-mthumb;-llog;-landroid;-lEGL;-lGLESv1_CM;-lc;-lm") | |
# This is a bit of a mess as we need to join the two libraries together on | |
# OS X before installing them. After this has run, LIBS_TO_INSTALL contains | |
@@ -680,6 +683,62 @@ macro(build_test_runner name_suffix path_suffix d_flags c_flags) | |
set_tests_properties(build-phobos2-test-runner${target_suffix} PROPERTIES | |
DEPENDS "build-druntime-ldc-unittest${target_suffix};build-phobos2-ldc-unittest${target_suffix}" | |
) | |
+ | |
+ set(test_runner_o "") | |
+ set(test_runner ${PROJECT_BINARY_DIR}/test-runner${name_suffix}${CMAKE_EXECUTABLE_SUFFIX}) | |
+ set(ANDROID_DIR "${PROJECT_PARENT_DIR}/../../android") | |
+ set(test_runner_so ${ANDROID_DIR}/samples/native-activity/libs/armeabi-v7a/libnative-activity${name_suffix}.so) | |
+ set(runner_flags "${flags}") | |
+ if("${flags}" MATCHES "-debug") | |
+ list(APPEND runner_flags -d-debug) | |
+ endif() | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" test_runner_o druntime_bc) | |
+ add_custom_command( | |
+ OUTPUT ${test_runner} | |
+ COMMAND ${CMAKE_C_COMPILER} ${RT_LDFLAGS} ${test_runner_o} | |
+ ${druntime_o} ${CORE_C} ${DCRT_C} ${DCRT_ASM} ${ZLIB_C} ${phobos2_o} | |
+ -o${test_runner} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${test_runner_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ) | |
+ add_custom_target(test-runner${name_suffix} DEPENDS ${test_runner}) | |
+ set(test_runner_apk_o "") | |
+ dc("${RUNTIME_DIR}/src/test_runner.d" "${runner_flags};-d-version=apk;-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "-apk${name_suffix}" test_runner_apk_o druntime_bc) | |
+ set(file_apk_o "") | |
+ dc("${PHOBOS2_DIR}/std/file.d" "${flags};-d-version=apk" "${PHOBOS2_DIR}" | |
+ "-apk-unittest${name_suffix}" file_apk_o phobos2_bc) | |
+ set(main_o "") | |
+ dc("${ANDROID_DIR}/samples/native-activity/jni/main.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" main_o druntime_bc) | |
+ set(sensor_o "") | |
+ dc("${ANDROID_DIR}/android/sensor.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" sensor_o druntime_bc) | |
+ string(REPLACE " " ";" RT_CFLAGS${name_suffix} ${RT_CFLAGS}) | |
+ set(android_native_app_glue_o "") | |
+ dc("${ANDROID_DIR}/android_native_app_glue.d" "${D_FLAGS};${d_flags};-I${ANDROID_DIR}" "${RUNTIME_DIR}" | |
+ "${name_suffix}" android_native_app_glue_o druntime_bc) | |
+ list(REMOVE_ITEM phobos2_o "${PROJECT_PARENT_DIR}/build/runtime/std/file-unittest${name_suffix}.o") | |
+ add_custom_command( | |
+ OUTPUT ${test_runner_so} | |
+ COMMAND ${CMAKE_C_COMPILER} ${TEST_SO_LDFLAGS} | |
+ ${main_o} ${sensor_o} ${test_runner_apk_o} | |
+ ${file_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} ${CORE_C} ${DCRT_C} ${DCRT_ASM} ${ZLIB_C} ${phobos2_o} | |
+ -o${test_runner_so} | |
+ WORKING_DIRECTORY ${PROJECT_PARENT_DIR} | |
+ DEPENDS ${CMAKE_C_COMPILER} | |
+ ${main_o} ${sensor_o} | |
+ ${test_runner_apk_o} ${android_native_app_glue_o} | |
+ ${druntime_o} | |
+ ${phobos2_o} | |
+ ${file_apk_o} | |
+ ) | |
+ add_custom_target(test-runner-apk${name_suffix} DEPENDS ${test_runner_so}) | |
endif() | |
endmacro() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment