Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit e3357fe

Browse files
committed
Use namespacing conventions in TypeTransformer.
Import Wasm types as `watpe` (similar to `irtpe` or `jstpe`, which we use in the JS backend and the compiler backend). Import IR elements without namespacing.
1 parent 26f9a05 commit e3357fe

1 file changed

Lines changed: 34 additions & 40 deletions

File tree

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package org.scalajs.linker.backend.wasmemitter
22

3-
import org.scalajs.ir.ClassKind
4-
import org.scalajs.ir.{Types => IRTypes}
5-
import org.scalajs.ir.{Trees => IRTrees}
6-
import org.scalajs.ir.{Names => IRNames}
3+
import org.scalajs.ir.Names._
4+
import org.scalajs.ir.Types._
75

8-
import org.scalajs.linker.backend.webassembly._
9-
import org.scalajs.linker.backend.webassembly.Names._
6+
import org.scalajs.linker.backend.webassembly.{Types => watpe}
107

118
import VarGen._
129

@@ -22,60 +19,57 @@ object TypeTransformer {
2219
* @see
2320
* https://webassembly.github.io/spec/core/syntax/types.html#result-types
2421
*/
25-
def transformResultType(
26-
t: IRTypes.Type
27-
)(implicit ctx: WasmContext): List[Types.WasmType] =
22+
def transformResultType(t: Type)(implicit ctx: WasmContext): List[watpe.WasmType] = {
2823
t match {
29-
case IRTypes.NoType => Nil
30-
case IRTypes.NothingType => Nil
31-
case _ => List(transformType(t))
24+
case NoType => Nil
25+
case NothingType => Nil
26+
case _ => List(transformType(t))
3227
}
28+
}
3329

3430
/** Transforms a value type to a unique Wasm type.
3531
*
3632
* This method cannot be used for `void` and `nothing`, since they have no corresponding Wasm
3733
* value type.
3834
*/
39-
def transformType(t: IRTypes.Type)(implicit ctx: WasmContext): Types.WasmType =
35+
def transformType(t: Type)(implicit ctx: WasmContext): watpe.WasmType = {
4036
t match {
41-
case IRTypes.AnyType => Types.WasmRefType.anyref
37+
case AnyType => watpe.WasmRefType.anyref
38+
39+
case tpe: ArrayType =>
40+
watpe.WasmRefType.nullable(genTypeName.forArrayClass(tpe.arrayTypeRef))
4241

43-
case tpe: IRTypes.ArrayType =>
44-
Types.WasmRefType.nullable(genTypeName.forArrayClass(tpe.arrayTypeRef))
45-
case IRTypes.ClassType(className) => transformClassType(className)
46-
case IRTypes.RecordType(fields) => ???
47-
case IRTypes.StringType | IRTypes.UndefType =>
48-
Types.WasmRefType.any
49-
case p: IRTypes.PrimTypeWithRef => transformPrimType(p)
42+
case ClassType(className) => transformClassType(className)
43+
case RecordType(fields) => ???
44+
case StringType | UndefType => watpe.WasmRefType.any
45+
case p: PrimTypeWithRef => transformPrimType(p)
5046
}
47+
}
5148

52-
def transformClassType(
53-
className: IRNames.ClassName
54-
)(implicit ctx: WasmContext): Types.WasmRefType = {
49+
def transformClassType(className: ClassName)(implicit ctx: WasmContext): watpe.WasmRefType = {
5550
val info = ctx.getClassInfo(className)
5651
if (info.isAncestorOfHijackedClass)
57-
Types.WasmRefType.anyref
52+
watpe.WasmRefType.anyref
5853
else if (info.isInterface)
59-
Types.WasmRefType.nullable(genTypeName.ObjectStruct)
54+
watpe.WasmRefType.nullable(genTypeName.ObjectStruct)
6055
else
61-
Types.WasmRefType.nullable(genTypeName.forClass(className))
56+
watpe.WasmRefType.nullable(genTypeName.forClass(className))
6257
}
6358

64-
private def transformPrimType(
65-
t: IRTypes.PrimTypeWithRef
66-
): Types.WasmType =
59+
private def transformPrimType(t: PrimTypeWithRef): watpe.WasmType = {
6760
t match {
68-
case IRTypes.BooleanType => Types.WasmInt32
69-
case IRTypes.ByteType => Types.WasmInt32
70-
case IRTypes.ShortType => Types.WasmInt32
71-
case IRTypes.IntType => Types.WasmInt32
72-
case IRTypes.CharType => Types.WasmInt32
73-
case IRTypes.LongType => Types.WasmInt64
74-
case IRTypes.FloatType => Types.WasmFloat32
75-
case IRTypes.DoubleType => Types.WasmFloat64
76-
case IRTypes.NullType => Types.WasmRefType.nullref
61+
case BooleanType => watpe.WasmInt32
62+
case ByteType => watpe.WasmInt32
63+
case ShortType => watpe.WasmInt32
64+
case IntType => watpe.WasmInt32
65+
case CharType => watpe.WasmInt32
66+
case LongType => watpe.WasmInt64
67+
case FloatType => watpe.WasmFloat32
68+
case DoubleType => watpe.WasmFloat64
69+
case NullType => watpe.WasmRefType.nullref
7770

78-
case IRTypes.NoType | IRTypes.NothingType =>
71+
case NoType | NothingType =>
7972
throw new IllegalArgumentException(s"${t.show()} does not have a corresponding Wasm type")
8073
}
74+
}
8175
}

0 commit comments

Comments
 (0)