[Wasm] Rename WasmImportPair -> WasmImportDescriptor

This commit is contained in:
Svyatoslav Kuzmich
2022-12-28 10:11:11 +01:00
parent dd53998c2d
commit 62217b39ec
5 changed files with 13 additions and 13 deletions
@@ -84,7 +84,7 @@ class DeclarationGenerator(
// check(declaration.isExternal) { "Non-external fun with @JsFun ${declaration.fqNameWhenAvailable}"} // check(declaration.isExternal) { "Non-external fun with @JsFun ${declaration.fqNameWhenAvailable}"}
val jsCodeName = jsCodeName(declaration) val jsCodeName = jsCodeName(declaration)
context.addJsFun(jsCodeName, jsCode) context.addJsFun(jsCodeName, jsCode)
WasmImportPair("js_code", jsCodeName(declaration)) WasmImportDescriptor("js_code", jsCodeName(declaration))
} }
else -> { else -> {
null null
@@ -16,17 +16,17 @@ import org.jetbrains.kotlin.ir.util.defaultType
import org.jetbrains.kotlin.ir.util.getAnnotation import org.jetbrains.kotlin.ir.util.getAnnotation
import org.jetbrains.kotlin.ir.util.hasAnnotation import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.wasm.ir.WasmImportPair import org.jetbrains.kotlin.wasm.ir.WasmImportDescriptor
fun IrAnnotationContainer.hasExcludedFromCodegenAnnotation(): Boolean = fun IrAnnotationContainer.hasExcludedFromCodegenAnnotation(): Boolean =
hasAnnotation(FqName("kotlin.wasm.internal.ExcludedFromCodegen")) hasAnnotation(FqName("kotlin.wasm.internal.ExcludedFromCodegen"))
fun IrFunction.getWasmImportDescriptor(): WasmImportPair? { fun IrFunction.getWasmImportDescriptor(): WasmImportDescriptor? {
val annotation = getAnnotation(FqName("kotlin.wasm.WasmImport")) val annotation = getAnnotation(FqName("kotlin.wasm.WasmImport"))
?: return null ?: return null
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return WasmImportPair( return WasmImportDescriptor(
(annotation.getValueArgument(0) as IrConst<String>).value, (annotation.getValueArgument(0) as IrConst<String>).value,
(annotation.getValueArgument(1) as? IrConst<String>)?.value ?: this.name.asString() (annotation.getValueArgument(1) as? IrConst<String>)?.value ?: this.name.asString()
) )
@@ -51,13 +51,13 @@ sealed class WasmFunction(
class Imported( class Imported(
name: String, name: String,
type: WasmSymbolReadOnly<WasmFunctionType>, type: WasmSymbolReadOnly<WasmFunctionType>,
val importPair: WasmImportPair val importPair: WasmImportDescriptor
) : WasmFunction(name, type) ) : WasmFunction(name, type)
} }
class WasmMemory( class WasmMemory(
val limits: WasmLimits, val limits: WasmLimits,
val importPair: WasmImportPair? = null, val importPair: WasmImportDescriptor? = null,
) : WasmNamedModuleField() ) : WasmNamedModuleField()
sealed class WasmDataMode { sealed class WasmDataMode {
@@ -81,7 +81,7 @@ class WasmData(
class WasmTable( class WasmTable(
var limits: WasmLimits = WasmLimits(1u, null), var limits: WasmLimits = WasmLimits(1u, null),
val elementType: WasmType, val elementType: WasmType,
val importPair: WasmImportPair? = null val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField() { ) : WasmNamedModuleField() {
sealed class Value { sealed class Value {
@@ -108,7 +108,7 @@ class WasmElement(
class WasmTag( class WasmTag(
val type: WasmFunctionType, val type: WasmFunctionType,
val importPair: WasmImportPair? = null val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField() { ) : WasmNamedModuleField() {
init { init {
assert(type.resultTypes.isEmpty()) { "Must have empty return as per current spec" } assert(type.resultTypes.isEmpty()) { "Must have empty return as per current spec" }
@@ -127,7 +127,7 @@ class WasmGlobal(
val type: WasmType, val type: WasmType,
val isMutable: Boolean, val isMutable: Boolean,
val init: List<WasmInstr>, val init: List<WasmInstr>,
val importPair: WasmImportPair? = null val importPair: WasmImportDescriptor? = null
) : WasmNamedModuleField() ) : WasmNamedModuleField()
sealed class WasmExport<T : WasmNamedModuleField>( sealed class WasmExport<T : WasmNamedModuleField>(
@@ -199,7 +199,7 @@ data class WasmLimits(
val maxSize: UInt? val maxSize: UInt?
) )
data class WasmImportPair( data class WasmImportDescriptor(
val moduleName: String, val moduleName: String,
val declarationName: String val declarationName: String
) )
@@ -91,7 +91,7 @@ class WasmBinaryToIR(val b: MyByteReader) {
// Import section // Import section
2 -> { 2 -> {
forEachVectorElement { forEachVectorElement {
val importPair = WasmImportPair(readString(), readString()) val importPair = WasmImportDescriptor(readString(), readString())
when (val kind = b.readByte().toInt()) { when (val kind = b.readByte().toInt()) {
0 -> { 0 -> {
val type = functionTypes[b.readVarUInt32AsInt()] val type = functionTypes[b.readVarUInt32AsInt()]
@@ -359,7 +359,7 @@ class WasmBinaryToIR(val b: MyByteReader) {
) )
} }
private fun readTag(importPair: WasmImportPair? = null): WasmTag { private fun readTag(importPair: WasmImportDescriptor? = null): WasmTag {
val attribute = b.readByte() val attribute = b.readByte()
check(attribute.toInt() == 0) { "as per spec" } check(attribute.toInt() == 0) { "as per spec" }
val type = functionTypes[b.readVarUInt32AsInt()] val type = functionTypes[b.readVarUInt32AsInt()]
@@ -320,7 +320,7 @@ class WasmIrToText : SExpressionBuilder() {
} }
} }
private fun WasmImportPair.appendImportPair() { private fun WasmImportDescriptor.appendImportPair() {
sameLineList("import") { sameLineList("import") {
toWatString(moduleName) toWatString(moduleName)
toWatString(declarationName) toWatString(declarationName)