Skip to content

Commit c964b8c

Browse files
Dominik KlembaV8-internal LUCI CQ
authored andcommitted
Refactor: add registerWasmMemoryUse helper
This introduces a helper function to reduce code duplication when typing wasm memory operations. Change-Id: I70a34b0034d069236040bafcb2e15974506b06cc Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8465497 Reviewed-by: Matthias Liedtke <[email protected]> Commit-Queue: Dominik Klemba <[email protected]>
1 parent bc5dd0a commit c964b8c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Sources/Fuzzilli/FuzzIL/JSTyper.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ public struct JSTyper: Analyzer {
408408
assert(dynamicObjectGroupManager.isEmpty)
409409
}
410410

411+
private mutating func registerWasmMemoryUse(for memory: Variable) {
412+
let definingInstruction = defUseAnalyzer.definition(of: memory)
413+
dynamicObjectGroupManager.addWasmMemory(withType: type(of: memory), forDefinition: definingInstruction, forVariable: memory)
414+
}
415+
411416
// Array for collecting type changes during instruction execution.
412417
// Not currently used, but could be used for example to validate the analysis by adding these as comments to programs.
413418
private var typeChanges = [(Variable, ILType)]()
@@ -659,7 +664,7 @@ public struct JSTyper: Analyzer {
659664
}
660665
case .wasmDefineMemory(let op):
661666
setType(of: instr.output, to: op.wasmMemory)
662-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.output), forDefinition: instr, forVariable: instr.output)
667+
registerWasmMemoryUse(for: instr.output)
663668
case .wasmDefineTag(let op):
664669
setType(of: instr.output, to: .object(ofGroup: "WasmTag", withWasmType: WasmTagType(op.parameterTypes)))
665670
dynamicObjectGroupManager.addWasmTag(withType: type(of: instr.output), forDefinition: instr, forVariable: instr.output)
@@ -681,28 +686,22 @@ public struct JSTyper: Analyzer {
681686
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
682687
dynamicObjectGroupManager.addWasmTable(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
683688
case .wasmMemoryStore(_):
684-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
685-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
689+
registerWasmMemoryUse(for: instr.input(0))
686690
case .wasmMemoryLoad(let op):
687-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
688-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
691+
registerWasmMemoryUse(for: instr.input(0))
689692
setType(of: instr.output, to: op.loadType.numberType())
690693
case .wasmAtomicLoad(let op):
691-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
692-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
694+
registerWasmMemoryUse(for: instr.input(0))
693695
setType(of: instr.output, to: op.loadType.numberType())
694696
case .wasmAtomicStore(_):
695-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
696-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
697+
registerWasmMemoryUse(for: instr.input(0))
697698
case .wasmAtomicRMW(let op):
698-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
699-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
699+
registerWasmMemoryUse(for: instr.input(0))
700700
setType(of: instr.output, to: op.op.type)
701701
case .wasmMemorySize(_),
702702
.wasmMemoryGrow(_):
703703
let isMemory64 = type(of: instr.input(0)).wasmMemoryType?.isMemory64 ?? false
704-
let definingInstruction = defUseAnalyzer.definition(of: instr.input(0))
705-
dynamicObjectGroupManager.addWasmMemory(withType: type(of: instr.input(0)), forDefinition: definingInstruction, forVariable: instr.input(0))
704+
registerWasmMemoryUse(for: instr.input(0))
706705
setType(of: instr.output, to: isMemory64 ? .wasmi64 : .wasmi32)
707706
case .wasmJsCall(let op):
708707
let sigOutputTypes = op.functionSignature.outputTypes

0 commit comments

Comments
 (0)