103 lines
3.0 KiB
Groovy
103 lines
3.0 KiB
Groovy
configurations {
|
|
cli_bc
|
|
}
|
|
|
|
dependencies {
|
|
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
|
}
|
|
|
|
public class KonanTest extends DefaultTask {
|
|
protected String source
|
|
def backendNative = project.project(":backend.native")
|
|
def runtimeProject = project.project(":runtime")
|
|
def llvmLlc = llvmTool("llc")
|
|
def llvmC = llvmTool("clang")
|
|
|
|
public KonanTest(){
|
|
dependsOn([project.project(":runtime").tasks['build'],
|
|
project.parent.tasks['build']])
|
|
}
|
|
|
|
@TaskAction
|
|
public void compileBc() {
|
|
def sourceKt = project.file(source)
|
|
def sourceBc = new File("${sourceKt.absolutePath}.bc")
|
|
def runtimeBc = new File("${runtimeProject.buildDir.canonicalPath}/runtime.bc")
|
|
println "${runtimeBc}"
|
|
project.javaexec {
|
|
main='org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.configurations.cli_bc
|
|
args "-output", "${sourceBc.absolutePath}",
|
|
"-runtime", "${runtimeBc.absolutePath}",
|
|
"${sourceKt.absolutePath}",
|
|
project.project(':runtime').file('src/main/kotlin')
|
|
|
|
jvmArgs "-Djava.library.path=${backendNative.buildDir.canonicalPath}/nativelibs"
|
|
}
|
|
def runtimeS = bc2s(runtimeBc)
|
|
def sourceS = bc2s(sourceBc)
|
|
def testC = sourceS.absolutePath.replace(".kt.S", "-test.c")
|
|
def mainC = "main.c"
|
|
def exe = sourceS.absolutePath.replace(".kt.S", "")
|
|
project.exec {
|
|
commandLine "${llvmC}", "${testC}", "${runtimeS.absolutePath}", "${sourceS.absolutePath}", "${mainC}",
|
|
"-o", "${exe}"
|
|
}
|
|
def res = project.exec {
|
|
commandLine "${exe}"
|
|
}
|
|
}
|
|
|
|
private File bc2s(File bcFile) {
|
|
def outputFile = new File("${bcFile.absolutePath.replace(".bc",".S")}")
|
|
println "${bcFile.absolutePath} -> ${outputFile.absolutePath}"
|
|
println "tool: ${llvmLlc}"
|
|
project.exec {
|
|
commandLine "${llvmLlc}", "-o", "${outputFile.absolutePath}" , "${bcFile}"
|
|
}
|
|
return outputFile
|
|
}
|
|
|
|
private String llvmTool(String tool) {
|
|
return "${project.llvmDir}/bin/${tool}"
|
|
}
|
|
}
|
|
|
|
task run() {
|
|
dependsOn(tasks.withType(KonanTest))
|
|
}
|
|
|
|
task sum (type:KonanTest) {
|
|
source = "codegen/function/sum.kt"
|
|
}
|
|
|
|
/* Investigate
|
|
task objectInitialization(type: KonanTest) {
|
|
source = "codegen/object/initialization.kt"
|
|
}
|
|
*/
|
|
|
|
/* task objectBasic(type: KonanTest) {
|
|
source = "$codegen/klass/basic.kt"
|
|
} */
|
|
|
|
task aritmetic(type: KonanTest) {
|
|
source = "codegen/function/arithmetic.kt"
|
|
}
|
|
|
|
task sum1(type: KonanTest) {
|
|
source = "codegen/function/sum_foo_bar.kt"
|
|
}
|
|
|
|
task sum2(type: KonanTest) {
|
|
source = "codegen/function/sum_imm.kt"
|
|
}
|
|
|
|
task sum_3const(type: KonanTest) {
|
|
source = "codegen/function/sum_3const.kt"
|
|
}
|
|
|
|
// TODO: waiting for boolean to be implemented
|
|
//task bool_yes(type: KonanTest) {
|
|
// source = "codegen/function/boolean.kt"
|
|
//} |