WebAssembly effort (#721)
This commit is contained in:
@@ -27,7 +27,8 @@ targetList.each { targetName ->
|
||||
target targetName
|
||||
compilerArgs '-g'
|
||||
compilerArgs '-I' + project.file('../common/src/hash/headers')
|
||||
compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include")
|
||||
if (rootProject.hasProperty("${targetName}LibffiDir"))
|
||||
compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include")
|
||||
linkerArgs project.file("../common/build/$targetName/hash.bc").path
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,5 +20,10 @@
|
||||
#define RUNTIME_NOTHROW __attribute__((nothrow))
|
||||
#define RUNTIME_CONST __attribute__((const))
|
||||
#define RUNTIME_PURE __attribute__((pure))
|
||||
#if KONAN_NO_THREADS
|
||||
#define THREAD_LOCAL_VARIABLE
|
||||
#else
|
||||
#define THREAD_LOCAL_VARIABLE __thread
|
||||
#endif
|
||||
|
||||
#endif // RUNTIME_COMMON_H
|
||||
|
||||
@@ -30,7 +30,7 @@ void Kotlin_io_Console_print(KString message) {
|
||||
// TODO: system stdout must be aware about UTF-8.
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(message, 0);
|
||||
KStdString utf8;
|
||||
utf8::utf16to8(utf16, utf16 + message->count_, back_inserter(utf8));
|
||||
utf8::unchecked::utf16to8(utf16, utf16 + message->count_, back_inserter(utf8));
|
||||
konan::consoleWriteUtf8(utf8.c_str(), utf8.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if KONAN_NO_EXCEPTIONS
|
||||
#define OMIT_BACKTRACE 1
|
||||
#endif
|
||||
#ifndef OMIT_BACKTRACE
|
||||
#if USE_GCC_UNWIND
|
||||
// GCC unwinder for backtrace.
|
||||
@@ -54,7 +58,7 @@ class AutoFree {
|
||||
struct Backtrace {
|
||||
Backtrace(int count, int skip) : index(0), skipCount(skip) {
|
||||
auto result = AllocArrayInstance(
|
||||
theArrayTypeInfo, count - skipCount, arrayHolder.slot());
|
||||
theArrayTypeInfo, count - skipCount, arrayHolder.slot());
|
||||
// TODO: throw cached OOME?
|
||||
RuntimeAssert(result != nullptr, "Cannot create backtrace array");
|
||||
}
|
||||
@@ -156,8 +160,10 @@ OBJ_GETTER0(GetCurrentStackTrace) {
|
||||
|
||||
void ThrowException(KRef exception) {
|
||||
RuntimeAssert(exception != nullptr && IsInstance(exception, theThrowableTypeInfo),
|
||||
"Throwing something non-throwable");
|
||||
|
||||
"Throwing something non-throwable");
|
||||
#if KONAN_NO_EXCEPTIONS
|
||||
RuntimeAssert(false, "Exceptions unsupported");
|
||||
#else
|
||||
#if (__MINGW32__ || __MINGW64__)
|
||||
// Workaround for https://bugs.llvm.org/show_bug.cgi?id=33220
|
||||
// This code forces the function to have at least one landingpad:
|
||||
@@ -165,6 +171,7 @@ void ThrowException(KRef exception) {
|
||||
#endif
|
||||
|
||||
throw ObjHolder(exception);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,14 +17,20 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef KONAN_NO_FFI
|
||||
#include <ffi.h>
|
||||
#endif
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
typedef int FfiTypeKind;
|
||||
|
||||
#ifndef KONAN_NO_FFI
|
||||
// Also declared in Varargs.kt
|
||||
const FfiTypeKind FFI_TYPE_KIND_VOID = 0;
|
||||
const FfiTypeKind FFI_TYPE_KIND_SINT8 = 1;
|
||||
@@ -49,6 +55,7 @@ ffi_type* convertFfiTypeKindToType(FfiTypeKind typeKind) {
|
||||
default: assert(false); return nullptr;
|
||||
}
|
||||
}
|
||||
#endif // KONAN_NO_FFI
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -57,8 +64,9 @@ extern "C" {
|
||||
void Kotlin_Interop_callWithVarargs(void* codePtr, void* returnValuePtr, FfiTypeKind returnTypeKind,
|
||||
void** arguments, intptr_t* argumentTypeKinds,
|
||||
int fixedArgumentsNumber, int totalArgumentsNumber) {
|
||||
|
||||
|
||||
#ifdef KONAN_NO_FFI
|
||||
RuntimeAssert(false, "Vararg calls are not supported on this platform");
|
||||
#else
|
||||
ffi_type** argumentTypes = (ffi_type**)argumentTypeKinds;
|
||||
// In-place convertion:
|
||||
for (int i = 0; i < totalArgumentsNumber; ++i) {
|
||||
@@ -71,6 +79,7 @@ void Kotlin_Interop_callWithVarargs(void* codePtr, void* returnValuePtr, FfiType
|
||||
convertFfiTypeKindToType(returnTypeKind), argumentTypes);
|
||||
|
||||
ffi_call(&cif, (void (*)())codePtr, returnValuePtr, arguments);
|
||||
#endif
|
||||
}
|
||||
|
||||
KNativePtr Kotlin_Interop_createStablePointer(KRef any) {
|
||||
|
||||
@@ -38,12 +38,12 @@
|
||||
namespace {
|
||||
|
||||
OBJ_GETTER(utf8ToUtf16, const char* rawString, size_t rawStringLength) {
|
||||
uint32_t charCount = utf8::distance(rawString, rawString + rawStringLength);
|
||||
uint32_t charCount = utf8::unchecked::distance(rawString, rawString + rawStringLength);
|
||||
ArrayHeader* result = AllocArrayInstance(
|
||||
theStringTypeInfo, charCount, OBJ_RESULT)->array();
|
||||
KChar* rawResult = CharArrayAddressOfElementAt(result, 0);
|
||||
auto convertResult =
|
||||
utf8::utf8to16(rawString, rawString + rawStringLength, rawResult);
|
||||
utf8::unchecked::utf8to16(rawString, rawString + rawStringLength, rawResult);
|
||||
RETURN_OBJ(result->obj());
|
||||
}
|
||||
|
||||
@@ -738,7 +738,7 @@ OBJ_GETTER(Kotlin_String_toUtf8Array, KString thiz, KInt start, KInt size) {
|
||||
}
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(thiz, start);
|
||||
KStdString utf8;
|
||||
utf8::utf16to8(utf16, utf16 + size, back_inserter(utf8));
|
||||
utf8::unchecked::utf16to8(utf16, utf16 + size, back_inserter(utf8));
|
||||
ArrayHeader* result = AllocArrayInstance(
|
||||
theByteArrayTypeInfo, utf8.size() + 1, OBJ_RESULT)->array();
|
||||
::memcpy(ByteArrayAddressOfElementAt(result, 0), utf8.c_str(), utf8.size());
|
||||
|
||||
@@ -94,7 +94,7 @@ struct MemoryState {
|
||||
namespace {
|
||||
|
||||
// TODO: can we pass this variable as an explicit argument?
|
||||
__thread MemoryState* memoryState = nullptr;
|
||||
THREAD_LOCAL_VARIABLE MemoryState* memoryState = nullptr;
|
||||
|
||||
inline bool isFreeable(const ContainerHeader* header) {
|
||||
return (header->refCount_ & CONTAINER_TAG_MASK) < CONTAINER_TAG_PERMANENT;
|
||||
@@ -649,6 +649,13 @@ OBJ_GETTER(InitInstance,
|
||||
|
||||
ObjHeader* object = AllocInstance(type_info, OBJ_RESULT);
|
||||
UpdateRef(location, object);
|
||||
#if KONAN_NO_EXCEPTIONS
|
||||
ctor(object);
|
||||
#if TRACE_MEMORY
|
||||
memoryState->globalObjects->push_back(location);
|
||||
#endif
|
||||
return object;
|
||||
#else
|
||||
try {
|
||||
ctor(object);
|
||||
#if TRACE_MEMORY
|
||||
@@ -660,6 +667,7 @@ OBJ_GETTER(InitInstance,
|
||||
UpdateRef(location, nullptr);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SetRef(ObjHeader** location, const ObjHeader* object) {
|
||||
@@ -882,7 +890,9 @@ OBJ_GETTER(DerefStablePointer, KNativePtr pointer) {
|
||||
}
|
||||
|
||||
OBJ_GETTER(AdoptStablePointer, KNativePtr pointer) {
|
||||
#ifndef KONAN_NO_THREADS
|
||||
__sync_synchronize();
|
||||
#endif
|
||||
KRef ref = reinterpret_cast<KRef>(pointer);
|
||||
// Somewhat hacky.
|
||||
*OBJ_RESULT = ref;
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
#ifndef RUNTIME_TYPES_H
|
||||
#define RUNTIME_TYPES_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if KONAN_WASM
|
||||
// assert() is needed by WASM STL.
|
||||
#define assert(cond) if (!(cond)) abort()
|
||||
#endif
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define WITH_WORKERS 1
|
||||
|
||||
#ifndef KONAN_NO_THREADS
|
||||
# define WITH_WORKERS 1
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -462,6 +465,11 @@ KInt stateOfFuture(KInt id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
KInt schedule(KInt id, KInt transferMode, KRef producer, KNativePtr jobFunction) {
|
||||
ThrowWorkerUnsupported();
|
||||
return 0;
|
||||
}
|
||||
|
||||
OBJ_GETTER(consumeFuture, KInt id) {
|
||||
ThrowWorkerUnsupported();
|
||||
RETURN_OBJ(nullptr);
|
||||
|
||||
@@ -525,7 +525,9 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
|
||||
|
||||
/**** Start of Konan-specific dlmalloc configuration. ****/
|
||||
#define USE_DL_PREFIX 1
|
||||
#if !KONAN_WASM
|
||||
#define USE_LOCKS 1
|
||||
#endif
|
||||
#define DLMALLOC_EXPORT extern "C"
|
||||
#define HAVE_MORECORE 1
|
||||
#define MORECORE konan::moreCore
|
||||
|
||||
@@ -642,7 +642,7 @@ KDouble Konan_FloatingPointParser_parseDoubleImpl (KString s, KInt e)
|
||||
{
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(s, 0);
|
||||
KStdString utf8;
|
||||
utf8::utf16to8(utf16, utf16 + s->count_, back_inserter(utf8));
|
||||
utf8::unchecked::utf16to8(utf16, utf16 + s->count_, back_inserter(utf8));
|
||||
const char *str = utf8.c_str();
|
||||
auto dbl = createDouble (str, e);
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ Konan_FloatingPointParser_parseFloatImpl (KString s, KInt e)
|
||||
{
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(s, 0);
|
||||
KStdString utf8;
|
||||
utf8::utf16to8(utf16, utf16 + s->count_, back_inserter(utf8));
|
||||
utf8::unchecked::utf16to8(utf16, utf16 + s->count_, back_inserter(utf8));
|
||||
const char *str = utf8.c_str();
|
||||
auto flt = createFloat (str, e);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ DEALINGS IN THE SOFTWARE.
|
||||
#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
|
||||
#include "utf8/checked.h"
|
||||
#include "utf8/unchecked.h"
|
||||
|
||||
#endif // header guard
|
||||
|
||||
Reference in New Issue
Block a user