org.jetbrains.kotlin.wasm.ir.Declarations.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.wasm.ir
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
class WasmModule(
val functionTypes: List = emptyList(),
val recGroupTypes: List = emptyList(),
val importsInOrder: List = emptyList(),
val importedFunctions: List = emptyList(),
val importedMemories: List = emptyList(),
val importedTables: List = emptyList(),
val importedGlobals: List = emptyList(),
val importedTags: List = emptyList(),
val definedFunctions: List = emptyList(),
val tables: List = emptyList(),
val memories: List = emptyList(),
val globals: List = emptyList(),
val exports: List> = emptyList(),
val elements: List = emptyList(),
val tags: List = emptyList(),
val startFunction: WasmFunction? = null,
val data: List = emptyList(),
val dataCount: Boolean = true,
)
sealed class WasmNamedModuleField {
var id: Int? = null
open val name: String = ""
}
sealed class WasmFunction(
override val name: String,
val type: WasmSymbolReadOnly
) : WasmNamedModuleField() {
class Defined(
name: String,
type: WasmSymbolReadOnly,
val locals: MutableList = mutableListOf(),
val instructions: MutableList = mutableListOf()
) : WasmFunction(name, type)
class Imported(
name: String,
type: WasmSymbolReadOnly,
val importPair: WasmImportDescriptor
) : WasmFunction(name, type)
}
class WasmMemory(
val limits: WasmLimits,
val importPair: WasmImportDescriptor? = null,
) : WasmNamedModuleField()
sealed class WasmDataMode {
class Active(
val memoryIdx: Int,
val offset: MutableList
) : WasmDataMode() {
constructor(memoryIdx: Int, offset: Int) : this(memoryIdx, mutableListOf().also> {
WasmIrExpressionBuilder(it).buildConstI32(offset, SourceLocation.NoLocation("Offset value for WasmDataMode.Active "))
})
}
object Passive : WasmDataMode()
}
class WasmData(
val mode: WasmDataMode,
val bytes: ByteArray,
) : WasmNamedModuleField()
class WasmTable(
var limits: WasmLimits = WasmLimits(1u, null),
val elementType: WasmType,
val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField() {
sealed class Value {
class Function(val function: WasmSymbol) : Value() {
constructor(function: WasmFunction) : this(WasmSymbol(function))
}
class Expression(val expr: List) : Value()
}
}
class WasmElement(
val type: WasmType,
val values: List,
val mode: Mode,
) : WasmNamedModuleField() {
sealed class Mode {
object Passive : Mode()
class Active(val table: WasmTable, val offset: List) : Mode()
object Declarative : Mode()
}
}
class WasmTag(
val type: WasmFunctionType,
val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField() {
init {
assert(type.resultTypes.isEmpty()) { "Must have empty return as per current spec" }
}
}
class WasmLocal(
val id: Int,
val name: String,
val type: WasmType,
val isParameter: Boolean
)
class WasmGlobal(
override val name: String,
val type: WasmType,
val isMutable: Boolean,
val init: List,
val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField()
sealed class WasmExport(
val name: String,
val field: T,
val kind: Byte,
val keyword: String
) {
class Function(name: String, field: WasmFunction) : WasmExport(name, field, 0x0, "func")
class Table(name: String, field: WasmTable) : WasmExport(name, field, 0x1, "table")
class Memory(name: String, field: WasmMemory) : WasmExport(name, field, 0x2, "memory")
class Global(name: String, field: WasmGlobal) : WasmExport(name, field, 0x3, "global")
class Tag(name: String, field: WasmTag) : WasmExport(name, field, 0x4, "tag")
}
sealed class WasmTypeDeclaration(
override val name: String
) : WasmNamedModuleField()
data class WasmFunctionType(
val parameterTypes: List,
val resultTypes: List
) : WasmTypeDeclaration("")
class WasmStructDeclaration(
name: String,
val fields: List,
val superType: WasmSymbolReadOnly?
) : WasmTypeDeclaration(name)
class WasmArrayDeclaration(
name: String,
val field: WasmStructFieldDeclaration
) : WasmTypeDeclaration(name)
class WasmStructFieldDeclaration(
val name: String,
val type: WasmType,
val isMutable: Boolean
)
sealed class WasmInstr(
val operator: WasmOp,
val immediates: List = emptyList()
) {
abstract val location: SourceLocation?
}
class WasmInstrWithLocation(
operator: WasmOp,
immediates: List,
override val location: SourceLocation
) : WasmInstr(operator, immediates) {
constructor(
operator: WasmOp,
location: SourceLocation
) : this(operator, emptyList(), location)
}
class WasmInstrWithoutLocation(
operator: WasmOp,
immediates: List = emptyList(),
) : WasmInstr(operator, immediates) {
override val location: SourceLocation? get() = null
}
data class WasmLimits(
val minSize: UInt,
val maxSize: UInt?
)
data class WasmImportDescriptor(
val moduleName: String,
val declarationName: String
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy