Skip to content

Commit 3749c9b

Browse files
Put misc instruction handlers together
Reducing the number of small files to improve build scheduling performance.
1 parent 8eac109 commit 3749c9b

File tree

6 files changed

+72
-72
lines changed

6 files changed

+72
-72
lines changed

Sources/WasmKit/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ add_wasmkit_library(WasmKit
88
Component/CanonicalCall.swift
99
Component/CanonicalOptions.swift
1010
Component/ComponentTypes.swift
11-
Execution/Instructions/Reference.swift
1211
Execution/Instructions/Control.swift
1312
Execution/Instructions/Instruction.swift
14-
Execution/Instructions/Parametric.swift
1513
Execution/Instructions/Table.swift
1614
Execution/Instructions/Memory.swift
15+
Execution/Instructions/Misc.swift
1716
Execution/Instructions/InstructionSupport.swift
18-
Execution/Instructions/Numeric.swift
19-
Execution/Instructions/Variable.swift
2017
Execution/DispatchInstruction.swift
2118
Execution/Errors.swift
2219
Execution/Execution.swift
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/// > Note:
2+
/// <https://webassembly.github.io/spec/core/syntax/instructions.html#variable-instructions>
3+
extension Execution {
4+
mutating func globalGet(sp: Sp, immediate: Instruction.GlobalAndVRegOperand) {
5+
immediate.global.withValue{
6+
sp[immediate.reg] = $0.rawValue
7+
}
8+
}
9+
mutating func globalSet(sp: Sp, immediate: Instruction.GlobalAndVRegOperand) {
10+
let value = sp[immediate.reg]
11+
immediate.global.withValue{ $0.rawValue = value }
12+
}
13+
14+
mutating func copyStack(sp: Sp, immediate: Instruction.CopyStackOperand) {
15+
sp[immediate.dest] = sp[immediate.source]
16+
}
17+
}
18+
19+
/// > Note:
20+
/// <https://webassembly.github.io/spec/core/exec/instructions.html#reference-instructions>
21+
extension Execution {
22+
mutating func refNull(sp: Sp, immediate: Instruction.RefNullOperand) {
23+
let value: Value
24+
switch immediate.type {
25+
case .externRef:
26+
value = .ref(.extern(nil))
27+
case .funcRef:
28+
value = .ref(.function(nil))
29+
}
30+
sp[immediate.result] = UntypedValue(value)
31+
}
32+
mutating func refIsNull(sp: Sp, immediate: Instruction.RefIsNullOperand) {
33+
let value = sp[immediate.value]
34+
35+
let result: Value
36+
if value.isNullRef {
37+
result = .i32(1)
38+
} else {
39+
result = .i32(0)
40+
}
41+
sp[immediate.result] = UntypedValue(result)
42+
}
43+
mutating func refFunc(sp: Sp, immediate: Instruction.RefFuncOperand) {
44+
let function = currentInstance(sp: sp).functions[Int(immediate.index)]
45+
sp[immediate.result] = UntypedValue(.ref(.function(from: function)))
46+
}
47+
}
48+
49+
/// > Note:
50+
/// <https://webassembly.github.io/spec/core/exec/instructions.html#numeric-instructions>
51+
extension Execution {
52+
@inline(__always)
53+
mutating func const32(sp: Sp, immediate: Instruction.Const32Operand) {
54+
sp[immediate.result] = UntypedValue(storage32: immediate.value)
55+
}
56+
@inline(__always)
57+
mutating func const64(sp: Sp, immediate: Instruction.Const64Operand) {
58+
sp[immediate.result] = immediate.value
59+
}
60+
}
61+
62+
/// > Note:
63+
/// <https://webassembly.github.io/spec/core/exec/instructions.html#parametric-instructions>
64+
extension Execution {
65+
mutating func select(sp: Sp, immediate: Instruction.SelectOperand) {
66+
let flag = sp[i32: immediate.condition]
67+
let selected = flag != 0 ? immediate.onTrue : immediate.onFalse
68+
let value = sp[selected]
69+
sp[immediate.result] = value
70+
}
71+
}

Sources/WasmKit/Execution/Instructions/Numeric.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sources/WasmKit/Execution/Instructions/Parametric.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

Sources/WasmKit/Execution/Instructions/Reference.swift

Lines changed: 0 additions & 29 deletions
This file was deleted.

Sources/WasmKit/Execution/Instructions/Variable.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)