Skip to content

Commit 4b70f1b

Browse files
Merge pull request #97 from swiftwasm/katei/remove-legacy-types
Remove unused types and functions
2 parents 3ece12e + 39cef2f commit 4b70f1b

File tree

8 files changed

+1
-153
lines changed

8 files changed

+1
-153
lines changed

Sources/WasmKit/Execution/Instructions/Control.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ extension ExecutionState {
88
programCounter += 1
99
}
1010

11-
typealias BlockType = Instruction.BlockType
12-
1311
mutating func ifThen(runtime: Runtime, stack: inout Stack, elseOrEndRef: ExpressionRef) {
1412
let isTrue = stack.popValue().i32 != 0
1513
if isTrue {

Sources/WasmKit/Execution/Instructions/Expression.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
import WasmParser
22

3-
/// See spec's
4-
/// [definition](https://webassembly.github.io/spec/core/text/instructions.html?highlight=pseudo#control-instructions).
5-
/// > The `block`, `loop` and `if` instructions are structured instructions. They bracket nested sequences of
6-
/// > instructions, called blocks, terminated with, or separated by, end or else pseudo-instructions. As the
7-
/// > grammar prescribes, they must be well-nested.
8-
enum PseudoInstruction {
9-
case `else`
10-
case end
11-
}
12-
133
struct InstructionSequence: Equatable {
144
let instructions: UnsafeBufferPointer<Instruction>
155

@@ -52,8 +42,3 @@ struct ExpressionRef: Equatable {
5242
self._relativeOffset = UInt32(relativeOffset)
5343
}
5444
}
55-
56-
/// > Note:
57-
/// <https://webassembly.github.io/spec/core/syntax/instructions.html#expressions>
58-
59-
typealias Expression = [WasmParser.Instruction]

Sources/WasmKit/Execution/Instructions/InstructionSupport.swift

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,6 @@ import WasmParser
33
extension Instruction {
44
typealias Memarg = MemArg
55

6-
struct BlockType: Equatable {
7-
let parameters: UInt16
8-
let results: UInt16
9-
10-
init(parameters: UInt16, results: UInt16) {
11-
self.parameters = parameters
12-
self.results = results
13-
}
14-
15-
init(blockType: WasmParser.BlockType, typeSection: [FunctionType]) throws {
16-
switch blockType {
17-
case .type:
18-
self = Instruction.BlockType(parameters: 0, results: 1)
19-
case .empty:
20-
self = Instruction.BlockType(parameters: 0, results: 0)
21-
case let .funcType(typeIndex):
22-
let typeIndex = Int(typeIndex)
23-
guard typeIndex < typeSection.count else {
24-
throw WasmParserError.invalidTypeSectionReference
25-
}
26-
let funcType = typeSection[typeIndex]
27-
self = Instruction.BlockType(
28-
parameters: UInt16(funcType.parameters.count),
29-
results: UInt16(funcType.results.count)
30-
)
31-
}
32-
}
33-
}
34-
356
struct BrTable: Equatable {
367
struct Entry {
378
var labelIndex: LabelIndex
@@ -46,38 +17,6 @@ extension Instruction {
4617
}
4718
}
4819

49-
struct LegacyBrTable: Equatable {
50-
private let bufferBase: UnsafePointer<LabelIndex>
51-
private let bufferCount: UInt32
52-
var labelIndices: UnsafeBufferPointer<LabelIndex> {
53-
UnsafeBufferPointer(start: bufferBase, count: Int(bufferCount - 1))
54-
}
55-
var defaultIndex: LabelIndex {
56-
bufferBase[Int(bufferCount - 1)]
57-
}
58-
59-
init(labelIndices: [LabelIndex], defaultIndex: LabelIndex) {
60-
let buffer = UnsafeMutableBufferPointer<LabelIndex>.allocate(capacity: labelIndices.count + 1)
61-
for (index, labelindex) in labelIndices.enumerated() {
62-
buffer[index] = labelindex
63-
}
64-
buffer[labelIndices.count] = defaultIndex
65-
self.bufferBase = UnsafePointer(buffer.baseAddress!)
66-
self.bufferCount = UInt32(buffer.count)
67-
}
68-
69-
static func == (lhs: Instruction.LegacyBrTable, rhs: Instruction.LegacyBrTable) -> Bool {
70-
lhs.labelIndices.baseAddress == rhs.labelIndices.baseAddress
71-
}
72-
}
73-
74-
// Just for migration purpose
75-
static func control(_ x: Instruction) -> Instruction { x }
76-
static func numeric(_ x: Instruction) -> Instruction { x }
77-
static func parametric(_ x: Instruction) -> Instruction { x }
78-
static func variable(_ x: Instruction) -> Instruction { x }
79-
static func reference(_ x: Instruction) -> Instruction { x }
80-
8120
static let f32Lt: Instruction = .numericFloatBinary(.lt(.f32))
8221
static let f32Gt: Instruction = .numericFloatBinary(.gt(.f32))
8322
static let f32Le: Instruction = .numericFloatBinary(.le(.f32))

Sources/WasmKit/Execution/Runtime/ExecutionState.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,3 @@ extension ExecutionState {
8282
store.module(address: stack.currentFrame.module)
8383
}
8484
}
85-
86-
extension ExecutionState {
87-
mutating func pseudo(runtime: Runtime, pseudoInstruction: PseudoInstruction) throws {
88-
fatalError("Unimplemented instruction: pseudo")
89-
}
90-
}

Sources/WasmKit/Execution/Runtime/Stack.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
/// > Note:
22
/// <https://webassembly.github.io/spec/core/exec/runtime.html#stack>
33
struct Stack {
4-
enum Element: Equatable {
5-
case value(Value)
6-
case frame(Frame)
7-
}
84

95
private var limit: UInt16 { UInt16.max }
106
private var valueStack: ValueStack
117
private var numberOfValues: Int { valueStack.count }
128
private var frames: FixedSizeStack<Frame>
139
var currentFrame: Frame!
1410

15-
var isEmpty: Bool {
16-
self.frames.isEmpty && self.numberOfValues == 0
17-
}
18-
1911
init() {
2012
let limit = UInt16.max
2113
self.valueStack = ValueStack(capacity: Int(limit))

Sources/WasmKit/Execution/Types/Value.swift

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -445,30 +445,6 @@ extension Value {
445445
}
446446
}
447447

448-
var leadingZeroBitCount: Value {
449-
switch self {
450-
case let .i32(rawValue): return .i32(UInt32(rawValue.leadingZeroBitCount))
451-
case let .i64(rawValue): return .i64(UInt64(rawValue.leadingZeroBitCount))
452-
default: fatalError("Invalid type \(type) for `Value.\(#function)` implementation")
453-
}
454-
}
455-
456-
var trailingZeroBitCount: Value {
457-
switch self {
458-
case let .i32(rawValue): return .i32(UInt32(rawValue.trailingZeroBitCount))
459-
case let .i64(rawValue): return .i64(UInt64(rawValue.trailingZeroBitCount))
460-
default: fatalError("Invalid type \(type) for `Value.\(#function)` implementation")
461-
}
462-
}
463-
464-
var nonzeroBitCount: Value {
465-
switch self {
466-
case let .i32(rawValue): return .i32(UInt32(rawValue.nonzeroBitCount))
467-
case let .i64(rawValue): return .i64(UInt64(rawValue.nonzeroBitCount))
468-
default: fatalError("Invalid type \(type) for `Value.\(#function)` implementation")
469-
}
470-
}
471-
472448
func rotl(_ l: Self) -> Self {
473449
switch (self, l) {
474450
case let (.i32(rawValue), .i32(l)):
@@ -527,36 +503,6 @@ extension Value {
527503
}
528504
}
529505

530-
static func + (lhs: Self, rhs: Self) -> Self {
531-
switch (lhs, rhs) {
532-
case let (.i32(lhs), .i32(rhs)): return .i32(lhs &+ rhs)
533-
case let (.i64(lhs), .i64(rhs)): return .i64(lhs &+ rhs)
534-
case let (.f32(lhs), .f32(rhs)): return .f32((Float32(bitPattern: lhs) + Float32(bitPattern: rhs)).bitPattern)
535-
case let (.f64(lhs), .f64(rhs)): return .f64((Float64(bitPattern: lhs) + Float64(bitPattern: rhs)).bitPattern)
536-
default: fatalError("Invalid types \(lhs.type) and \(rhs.type) for `Value.\(#function)` implementation")
537-
}
538-
}
539-
540-
static func - (lhs: Self, rhs: Self) -> Self {
541-
switch (lhs, rhs) {
542-
case let (.i32(lhs), .i32(rhs)): return .i32(lhs &- rhs)
543-
case let (.i64(lhs), .i64(rhs)): return .i64(lhs &- rhs)
544-
case let (.f32(lhs), .f32(rhs)): return .f32((Float32(bitPattern: lhs) - Float32(bitPattern: rhs)).bitPattern)
545-
case let (.f64(lhs), .f64(rhs)): return .f64((Float64(bitPattern: lhs) - Float64(bitPattern: rhs)).bitPattern)
546-
default: fatalError("Invalid types \(lhs.type) and \(rhs.type) for `Value.\(#function)` implementation")
547-
}
548-
}
549-
550-
static func * (lhs: Self, rhs: Self) -> Self {
551-
switch (lhs, rhs) {
552-
case let (.i32(lhs), .i32(rhs)): return .i32(lhs &* rhs)
553-
case let (.i64(lhs), .i64(rhs)): return .i64(lhs &* rhs)
554-
case let (.f32(lhs), .f32(rhs)): return .f32((Float32(bitPattern: lhs) * Float32(bitPattern: rhs)).bitPattern)
555-
case let (.f64(lhs), .f64(rhs)): return .f64((Float64(bitPattern: lhs) * Float64(bitPattern: rhs)).bitPattern)
556-
default: fatalError("Invalid types \(lhs.type) and \(rhs.type) for `Value.\(#function)` implementation")
557-
}
558-
}
559-
560506
static func / (lhs: Self, rhs: Self) -> Self {
561507
switch (lhs, rhs) {
562508
case let (.f32(lhs), .f32(rhs)): return .f32((Float32(bitPattern: lhs) / Float32(bitPattern: rhs)).bitPattern)

Sources/WasmKit/Translator.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,3 @@ fileprivate extension FunctionType {
970970
}
971971
}
972972
}
973-
974-
fileprivate extension Instruction.BlockType {
975-
init(_ functionType: FunctionType) {
976-
self.init(parameters: UInt16(functionType.parameters.count), results: UInt16(functionType.results.count))
977-
}
978-
}

Tests/WasmKitTests/Execution/HostModuleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class HostModuleTests: XCTestCase {
4343
type: 0, locals: [],
4444
body: {
4545
[
46-
.control(.call(functionIndex: 1))
46+
.call(functionIndex: 1)
4747
]
4848
}),
4949
],

0 commit comments

Comments
 (0)