-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cd4280
commit 0cf076e
Showing
14 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
backend/common/src/commonMain/kotlin/intrinsic/IntrinsicFunction.kt
This file was deleted.
Oops, something went wrong.
6 changes: 2 additions & 4 deletions
6
backend/common/src/commonMain/kotlin/intrinsic/IntrinsicFunctionExecutor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package me.gabriel.selene.backend.common.intrinsic | ||
|
||
abstract class IntrinsicFunctionExecutor<T : IntrinsicFunction>( | ||
val function: T | ||
) { | ||
abstract fun execute(): String | ||
abstract class IntrinsicFunctionExecutor<Context : Any> { | ||
abstract fun onCall(context: Context) | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/common/src/commonMain/kotlin/intrinsic/IntrinsicFunctionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package me.gabriel.selene.backend.common.intrinsic | ||
|
||
abstract class IntrinsicFunctionRepository<Context : Any> { | ||
abstract val intrinsics: MutableMap<String, IntrinsicFunctionExecutor<Context>> | ||
|
||
fun register(name: String, executor: IntrinsicFunctionExecutor<Context>) { | ||
intrinsics[name] = executor | ||
} | ||
|
||
fun find(name: String): IntrinsicFunctionExecutor<Context>? { | ||
return intrinsics[name] | ||
} | ||
|
||
fun unregister(name: String) { | ||
intrinsics.remove(name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.gabriel.selene.backend.llvm | ||
|
||
import me.gabriel.ryujin.DragonModule | ||
import me.gabriel.ryujin.dsl.FunctionScopeDsl | ||
import me.gabriel.ryujin.dsl.ModuleScopeDsl | ||
import me.gabriel.ryujin.function.DragonFunction | ||
|
||
class DragonHookContext( | ||
val module: DragonModule, | ||
val function: DragonFunction, | ||
val moduleDsl: ModuleScopeDsl, | ||
val functionDsl: FunctionScopeDsl | ||
) |
11 changes: 11 additions & 0 deletions
11
backend/llvm/src/commonMain/kotlin/intrinsic/DragonIntrinsicFunctionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.gabriel.selene.backend.llvm.intrinsic | ||
|
||
import me.gabriel.selene.backend.common.intrinsic.IntrinsicFunctionExecutor | ||
import me.gabriel.selene.backend.common.intrinsic.IntrinsicFunctionRepository | ||
import me.gabriel.selene.backend.llvm.DragonHookContext | ||
|
||
class DragonIntrinsicFunctionRepository: IntrinsicFunctionRepository<DragonHookContext>() { | ||
override val intrinsics: MutableMap<String, IntrinsicFunctionExecutor<DragonHookContext>> = mutableMapOf( | ||
|
||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package me.gabriel.selene.backend.llvm.intrinsic | ||
|
||
import me.gabriel.ryujin.struct.Constant | ||
import me.gabriel.ryujin.struct.DragonType | ||
import me.gabriel.selene.backend.common.intrinsic.IntrinsicFunctionExecutor | ||
import me.gabriel.selene.backend.llvm.DragonHookContext | ||
|
||
class PrintlnIntrinsicFunctionExecutor : IntrinsicFunctionExecutor<DragonHookContext>() { | ||
override fun onCall(context: DragonHookContext) { | ||
context.functionDsl.run { | ||
callExternal( | ||
functionName = "printf", | ||
returnType = DragonType.Pointer(DragonType.Int8), | ||
arguments = listOf( | ||
Constant.DeclaredConstantPtr("%s\\0A"), | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.gabriel.ryujin.statement | ||
|
||
import me.gabriel.ryujin.struct.DragonType | ||
import me.gabriel.ryujin.struct.Value | ||
|
||
class CallStatement( | ||
val functionName: String, | ||
override val type: DragonType, | ||
val arguments: List<Value> | ||
) : TypedDragonStatement { | ||
override val memoryDependencies: Set<Value> = arguments.toSet() | ||
|
||
override fun llvm(): String { | ||
return "call ${type.llvm} @${functionName}(${arguments.joinToString { "${it.type.llvm} ${it.llvm()}" }})" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters