Skip to content

Commit 665ae2a

Browse files
committed
Add isDebugging flag to InstructionTranslator
1 parent 76019bf commit 665ae2a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Sources/WasmKit/Execution/Function.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct WasmFunctionEntity {
262262
locals: code.locals,
263263
functionIndex: index,
264264
codeSize: code.expression.count,
265-
intercepting: engine.interceptor != nil
265+
isIntercepting: engine.interceptor != nil
266266
)
267267
let iseq = try code.withValue { code in
268268
try translator.translate(code: code)

Sources/WasmKit/Translator.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ struct InstructionTranslator: InstructionVisitor {
820820
/// The index of the function in the module
821821
let functionIndex: FunctionIndex
822822
/// Whether a call to this function should be intercepted
823-
let intercepting: Bool
823+
let isIntercepting: Bool
824+
/// Whether Wasm debugging facilities are currently enabled.
825+
let isDebugging: Bool
824826
var constantSlots: ConstSlots
825827
let validator: InstructionValidator
826828

@@ -833,7 +835,8 @@ struct InstructionTranslator: InstructionVisitor {
833835
locals: [WasmTypes.ValueType],
834836
functionIndex: FunctionIndex,
835837
codeSize: Int,
836-
intercepting: Bool
838+
isIntercepting: Bool,
839+
isDebugging: Bool = false
837840
) throws {
838841
self.allocator = allocator
839842
self.funcTypeInterner = funcTypeInterner
@@ -849,7 +852,8 @@ struct InstructionTranslator: InstructionVisitor {
849852
self.valueStack = ValueStack(stackLayout: stackLayout)
850853
self.locals = Locals(types: type.parameters + locals)
851854
self.functionIndex = functionIndex
852-
self.intercepting = intercepting
855+
self.isIntercepting = isIntercepting
856+
self.isDebugging = isDebugging
853857
self.constantSlots = ConstSlots(stackLayout: stackLayout)
854858
self.validator = InstructionValidator(context: module)
855859

@@ -1059,7 +1063,7 @@ struct InstructionTranslator: InstructionVisitor {
10591063
return emittedCopy
10601064
}
10611065
private mutating func translateReturn() throws {
1062-
if intercepting {
1066+
if isIntercepting {
10631067
// Emit `onExit` instruction before every `return` instruction
10641068
emit(.onExit(functionIndex))
10651069
}
@@ -1098,7 +1102,7 @@ struct InstructionTranslator: InstructionVisitor {
10981102

10991103
/// Translate a Wasm expression into a sequence of instructions.
11001104
mutating func translate(code: Code) throws -> InstructionSequence {
1101-
if intercepting {
1105+
if isIntercepting {
11021106
// Emit `onEnter` instruction at the beginning of the function
11031107
emit(.onEnter(functionIndex))
11041108
}
@@ -2241,7 +2245,7 @@ struct InstructionTranslator: InstructionVisitor {
22412245
}
22422246

22432247
mutating func visitUnknown(_ opcode: [UInt8]) throws -> Bool {
2244-
guard opcode.count == 1 && opcode[0] == 0xFF else {
2248+
guard self.isDebugging && opcode.count == 1 && opcode[0] == 0xFF else {
22452249
return false
22462250
}
22472251

0 commit comments

Comments
 (0)