![JAR search and dependency download from the Maven repository](/logo.png)
com.jtransc.gen.d.DCompiler.kt Maven / Gradle / Ivy
package com.jtransc.gen.d
import com.jtransc.env.OS
import com.jtransc.error.invalidOp
import com.jtransc.gen.common.BaseCompiler
import java.io.File
object DCompiler {
fun genCommand(programFile: File, debug: Boolean = false, libs: List = listOf(), extraVars: Map>): List {
val provider = listOf(DMD, GDC, LDC).firstOrNull { it.available } ?: invalidOp("Can't find D compiler (dmd, gdc or ldc), please install one of them and put in the path.")
return provider.genCommand(programFile, BaseCompiler.Config(debug, libs, extraVars = extraVars))
}
object DMD : BaseCompiler("dmd") {
override fun genCommand(programFile: File, config: Config): List {
val march = if (OS.isWindows) "-m32" else "-m64"
if (config.debug) {
// @TODO: DMD bug -gc allows to print good stacktraces but -gc makes compiler fail on large files
//return listOf(cmd!!, "-debug", "-gc", "-gx", programFile.absolutePath)
return listOf(cmd!!, "-debug", march, programFile.absolutePath)
} else {
//return listOf(cmd!!, "-release", "-O", "-m64", "-inline", programFile.absolutePath)
return listOf(cmd!!, "-release", "-O", march, programFile.absolutePath)
}
}
}
object GDC : BaseCompiler("gdc") {
override fun genCommand(programFile: File, config: Config): List {
if (config.debug) {
return listOf(cmd!!, "-fdebug=1", "-g", "-O0", programFile.absolutePath)
} else {
return listOf(cmd!!, "-s", "-O3", programFile.absolutePath)
}
}
}
object LDC : BaseCompiler("ldc2") {
override fun genCommand(programFile: File, config: Config): List {
if (config.debug) {
return listOf(cmd!!, "-O0", programFile.absolutePath)
} else {
return listOf(cmd!!, "-O3", programFile.absolutePath)
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy