runtime: add TypeInfo struct definition

also add runtime as Gradle subproject producing bitcode
This commit is contained in:
Svyatoslav Scherbina
2016-09-29 13:27:18 +07:00
parent 3b7af125f7
commit 5dc871ec32
6 changed files with 119 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
// TODO: consider using some Gradle plugins to build and test
def srcDir = 'src/main/cpp'
def objDir = "$buildDir/bitcode"
def outFile = "$buildDir/runtime.bc"
task compile(type: Exec) {
doFirst {
new File(objDir).mkdirs()
}
inputs.dir srcDir
outputs.dir objDir
workingDir objDir
executable "$llvmInstallPath/bin/clang"
args '-std=c++11'
args '-c', '-emit-llvm'
args fileTree(srcDir).include('**/*.cpp')
}
task build(type: Exec) {
dependsOn compile
inputs.dir objDir
outputs.file outFile
executable "$llvmInstallPath/bin/llvm-link"
args '-o', outFile
doFirst {
args fileTree(objDir).include('**/*.bc')
}
}
task test {
dependsOn build
doLast {
exec {
commandLine "$llvmInstallPath/bin/clang", 'src/test/c/main.c', '-c', '-emit-llvm', '-o', "$buildDir/main.bc"
}
exec {
commandLine "$llvmInstallPath/bin/clang++", outFile, "$buildDir/main.bc", '-o', "$buildDir/main"
}
exec {
workingDir buildDir
commandLine './main'
}
}
}
task clean << {
delete buildDir
}
+9
View File
@@ -0,0 +1,9 @@
#include <cassert>
#include "TypeInfo.h"
extern "C" {
int lookupField(TypeInfo* info, NameHash nameSignature) {
assert(false); // not implemented yet
return -1;
}
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef RUNTIME_TYPEINFO_H
#define RUNTIME_TYPEINFO_H
#include <cstdint>
// All names in system are stored as hashes (or maybe, for debug builds,
// as pointers to uniqued C strings containing names?).
typedef int64_t NameHash;
// An element of sorted by hash in-place array representing methods.
struct MethodTableRecord {
NameHash nameSignature;
void* methodEntryPoint;
};
// An element of sorted by hash in-place array representing field offsets.
struct FieldTableRecord {
NameHash nameSignature;
int fieldOffset;
};
// This struct represents runtime type information and by itself is compile time
// constant.
struct TypeInfo {
NameHash name;
int size;
const TypeInfo* superType;
const int* objOffsets;
int objOffsetsCount;
TypeInfo* const* implementedInterfaces;
int implementedInterfacesCount;
const MethodTableRecord* methods;
int methodsCount;
const FieldTableRecord* fields;
int fieldsCount;
};
#endif //RUNTIME_TYPEINFO_H
+6
View File
@@ -0,0 +1,6 @@
extern "C" void kotlinNativeMain();
int main() {
kotlinNativeMain();
return 0;
}
+6
View File
@@ -0,0 +1,6 @@
#include <stddef.h>
#include <printf.h>
void kotlinNativeMain() {
// nothing to test yet
}
+1
View File
@@ -3,3 +3,4 @@ include ':Interop:StubGenerator'
include ':Interop:Runtime'
include ':InteropExample'
include ':backend.native'
include ':runtime'