Various fixes for HelloWorld. (#27)
This commit is contained in:
@@ -50,6 +50,8 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME,
|
configuration.put(CommonConfigurationKeys.MODULE_NAME,
|
||||||
JvmAbi.DEFAULT_MODULE_NAME)
|
JvmAbi.DEFAULT_MODULE_NAME)
|
||||||
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
||||||
|
// TODO: add to source set, once we know how to not compile them.
|
||||||
|
configuration.addKotlinSourceRoots(arguments.headers.asList())
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
||||||
configuration, Arrays.asList<String>("extensions/common.xml"))
|
configuration, Arrays.asList<String>("extensions/common.xml"))
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,8 @@ public class K2NativeCompilerArguments extends CommonCompilerArguments {
|
|||||||
@ValueDescription("<path>")
|
@ValueDescription("<path>")
|
||||||
public String runtimeFile;
|
public String runtimeFile;
|
||||||
|
|
||||||
|
@Argument(value = "headers", description = "Header files used for compilation")
|
||||||
|
@ValueDescription("<path>")
|
||||||
|
public String[] headers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -29,6 +29,7 @@ fun emitLLVM(module: IrModuleFragment, runtimeFile: String, outFile: String) {
|
|||||||
// TODO: use LLVMDisposeMessage() on errorRef, once possible in interop.
|
// TODO: use LLVMDisposeMessage() on errorRef, once possible in interop.
|
||||||
if (LLVMVerifyModule(
|
if (LLVMVerifyModule(
|
||||||
llvmModule, LLVMVerifierFailureAction.LLVMPrintMessageAction, errorRef) == 1) {
|
llvmModule, LLVMVerifierFailureAction.LLVMPrintMessageAction, errorRef) == 1) {
|
||||||
|
LLVMDumpModule(llvmModule)
|
||||||
throw Error("Invalid module");
|
throw Error("Invalid module");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -127,6 +127,19 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val arrayClasses = mapOf(
|
||||||
|
Pair("kotlin_native.ByteArray", -1),
|
||||||
|
Pair("kotlin_native.CharArray", -2),
|
||||||
|
Pair("kotlin_native.IntArray", -4),
|
||||||
|
Pair("kotlin_native.String", -1)
|
||||||
|
);
|
||||||
|
|
||||||
|
private fun getInstanceSize(classType: LLVMOpaqueType?, className: FqName) : Int {
|
||||||
|
val arraySize = arrayClasses.get(className.asString());
|
||||||
|
if (arraySize != null) return arraySize;
|
||||||
|
return LLVMStoreSizeOfType(runtime.targetData, classType).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
fun generate(classDesc: ClassDescriptor) {
|
fun generate(classDesc: ClassDescriptor) {
|
||||||
|
|
||||||
val className = classDesc.fqNameSafe
|
val className = classDesc.fqNameSafe
|
||||||
@@ -135,7 +148,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
|||||||
|
|
||||||
val name = className.globalHash
|
val name = className.globalHash
|
||||||
|
|
||||||
val size = LLVMStoreSizeOfType(runtime.targetData, classType).toInt()
|
val size = getInstanceSize(classType, className)
|
||||||
|
|
||||||
val superType = classDesc.getSuperClassOrAny().llvmTypeInfoPtr
|
val superType = classDesc.getSuperClassOrAny().llvmTypeInfoPtr
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ public class KonanTest extends DefaultTask {
|
|||||||
classpath = project.configurations.cli_bc
|
classpath = project.configurations.cli_bc
|
||||||
args "-output", "${sourceBc.absolutePath}",
|
args "-output", "${sourceBc.absolutePath}",
|
||||||
"-runtime", "${runtimeBc.absolutePath}",
|
"-runtime", "${runtimeBc.absolutePath}",
|
||||||
"${sourceKt.absolutePath}",
|
"-headers", project.project(':runtime').file('src/main/kotlin'),
|
||||||
project.project(':runtime').file('src/main/kotlin')
|
"${sourceKt.absolutePath}"
|
||||||
|
|
||||||
jvmArgs "-Djava.library.path=${backendNative.buildDir.canonicalPath}/nativelibs"
|
jvmArgs "-Djava.library.path=${backendNative.buildDir.canonicalPath}/nativelibs"
|
||||||
}
|
}
|
||||||
@@ -75,11 +75,9 @@ task sum (type:KonanTest) {
|
|||||||
source = "codegen/function/sum.kt"
|
source = "codegen/function/sum.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Investigate
|
|
||||||
task objectInitialization(type: KonanTest) {
|
task objectInitialization(type: KonanTest) {
|
||||||
source = "codegen/object/initialization.kt"
|
source = "codegen/object/initialization.kt"
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/* task objectBasic(type: KonanTest) {
|
/* task objectBasic(type: KonanTest) {
|
||||||
source = "$codegen/klass/basic.kt"
|
source = "$codegen/klass/basic.kt"
|
||||||
@@ -101,7 +99,16 @@ task sum_3const(type: KonanTest) {
|
|||||||
source = "codegen/function/sum_3const.kt"
|
source = "codegen/function/sum_3const.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: enable, once kotlin.String -> kotlin_native.String is mapped.
|
||||||
|
task hello0(type: KonanTest) {
|
||||||
|
source = "runtime/basic/hello0.kt"
|
||||||
|
}
|
||||||
|
|
||||||
|
task hello1(type: KonanTest) {
|
||||||
|
source = "runtime/basic/hello1.kt"
|
||||||
|
} */
|
||||||
|
|
||||||
// TODO: waiting for boolean to be implemented
|
// TODO: waiting for boolean to be implemented
|
||||||
//task bool_yes(type: KonanTest) {
|
//task bool_yes(type: KonanTest) {
|
||||||
// source = "codegen/function/boolean.kt"
|
// source = "codegen/function/boolean.kt"
|
||||||
//}
|
//}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// TODO: remove kotlin_native.io once overrides are in place.
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
kotlin_native.io.print("Hello, world!")
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
extern void *resolve_symbol(const char*);
|
||||||
|
|
||||||
|
int
|
||||||
|
run_test() {
|
||||||
|
void (*main)(void*) = resolve_symbol("kfun:main");
|
||||||
|
|
||||||
|
main((void*)0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// TODO: remove kotlin_native.io once overrides are in place.
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
kotlin_native.io.print(kotlin_native.io.readLine())
|
||||||
|
}
|
||||||
@@ -20,21 +20,27 @@ ArenaContainer::ArenaContainer(uint32_t size) {
|
|||||||
|
|
||||||
void ObjectContainer::Init(const TypeInfo* type_info) {
|
void ObjectContainer::Init(const TypeInfo* type_info) {
|
||||||
RuntimeAssert(type_info->instanceSize_ >= 0, "Must be an object");
|
RuntimeAssert(type_info->instanceSize_ >= 0, "Must be an object");
|
||||||
header_ = reinterpret_cast<ContainerHeader*>(
|
uint32_t alloc_size =
|
||||||
calloc(sizeof(ContainerHeader) + sizeof(ObjHeader) +
|
sizeof(ContainerHeader) + sizeof(ObjHeader) + type_info->instanceSize_;
|
||||||
type_info->instanceSize_, 1));
|
header_ = reinterpret_cast<ContainerHeader*>(calloc(alloc_size, 1));
|
||||||
header_->ref_count_ = CONTAINER_TAG_INCREMENT;
|
if (header_) {
|
||||||
SetMeta(GetPlace(), type_info);
|
header_->ref_count_ = CONTAINER_TAG_INCREMENT;
|
||||||
|
SetMeta(GetPlace(), type_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayContainer::Init(const TypeInfo* type_info, uint32_t elements) {
|
void ArrayContainer::Init(const TypeInfo* type_info, uint32_t elements) {
|
||||||
RuntimeAssert(type_info->instanceSize_ < 0, "Must be an array");
|
RuntimeAssert(type_info->instanceSize_ < 0, "Must be an array");
|
||||||
header_ = reinterpret_cast<ContainerHeader*>(
|
uint32_t alloc_size =
|
||||||
calloc(sizeof(ContainerHeader) + sizeof(ArrayHeader) -
|
sizeof(ContainerHeader) + sizeof(ArrayHeader) -
|
||||||
type_info->instanceSize_ * elements, 1));
|
type_info->instanceSize_ * elements;
|
||||||
header_->ref_count_ = CONTAINER_TAG_INCREMENT;
|
header_ = reinterpret_cast<ContainerHeader*>(calloc(alloc_size, 1));
|
||||||
GetPlace()->count_ = elements;
|
RuntimeAssert(header_ != nullptr, "Cannot alloc memory");
|
||||||
SetMeta(GetPlace(), type_info);
|
if (header_) {
|
||||||
|
header_->ref_count_ = CONTAINER_TAG_INCREMENT;
|
||||||
|
GetPlace()->count_ = elements;
|
||||||
|
SetMeta(GetPlace(), type_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjHeader* ArenaContainer::PlaceObject(const TypeInfo* type_info) {
|
ObjHeader* ArenaContainer::PlaceObject(const TypeInfo* type_info) {
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ package kotlin_native.io
|
|||||||
external public fun print(message: kotlin_native.String)
|
external public fun print(message: kotlin_native.String)
|
||||||
|
|
||||||
@kotlin_native.SymbolName("Kotlin_io_Console_readLine")
|
@kotlin_native.SymbolName("Kotlin_io_Console_readLine")
|
||||||
external public fun readLine(): kotlin_native.String?
|
external public fun readLine(): kotlin_native.String
|
||||||
|
|||||||
Reference in New Issue
Block a user