All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bennyhuo.kotlin.ir.printer.gradle.LlvmDisTask.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-1.1.4
Show newest version
package com.bennyhuo.kotlin.ir.printer.gradle

import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction

/**
 * Created by benny.
 */
@CacheableTask
abstract class LlvmDisTask : DefaultTask() {

    init {
        group = "build"
    }

    @get:Input
    abstract val llvmDisPath: Property>

    @get:InputDirectory
    @get:PathSensitive(PathSensitivity.RELATIVE)
    abstract val konanTempDir: Property

    @get:OutputDirectory
    abstract val outputPath: Property

    @TaskAction
    fun run() {
        val inputDir = File(konanTempDir.get())
        inputDir.list()?.filter { it.endsWith(".bc") }?.forEach {
            val result = executeCommand("${llvmDisPath.get().value} $it", inputDir, logger)
            if(!result.isOk) {
                throw GradleException("Failed to disassemble $it.")
            }
        }
        inputDir.listFiles()?.filter { it.name.endsWith(".ll") }?.forEach {
            it.renameTo(File(outputPath.get(), it.name))
        }
        // copy api.cpp if exists.
        inputDir.listFiles()?.filter { it.name.endsWith(".cpp") }?.forEach {
            it.copyTo(File(outputPath.get(), it.name), overwrite = true)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy