WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(LoopOpcode opcode, WasmNodeArg arg) { var loopNode = new LoopNode(opcode.Signature); arg.Push(loopNode); arg.PushBlock(loopNode.Nodes); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64ReinterpretI64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new F64ReinterpretI64Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32EqzOpcode opcode, WasmNodeArg arg) { var expr = arg.Pop(); arg.Push(new I32EqzNode(expr)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(DropOpcode opcode, WasmNodeArg arg) { var op = arg.Pop(); arg.Push(new DropNode(op)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(SetGlobalOpcode opcode, WasmNodeArg arg) { var expr = arg.Pop(); var variable = arg.ResolveGlobal(opcode.GlobalIndex); arg.Push(new SetGlobalNode(variable, expr)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64PromoteF32Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new F64PromoteF32Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64TruncUF64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I64TruncUF64Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(BrIfOpcode opcode, WasmNodeArg arg) { var label = arg.ResolveLabel(opcode.RelativeDepth); var condition = arg.Pop(); var node = new BrIfNode(condition, label); arg.Push(node); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(BrTableOpcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); var node = new BrTableNode(operand); foreach (var target in opcode.Targets) { var label = arg.ResolveLabel(target); node.Targets.Add(label); } node.DefaultTarget = arg.ResolveLabel(opcode.DefaultTarget); arg.Push(node); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(EndOpcode opcode, WasmNodeArg arg) { if (arg.HasBlock) { arg.PopBlock(); } else { throw new WasmNodeException("there is no block to end"); } return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(BrOpcode opcode, WasmNodeArg arg) { var label = arg.ResolveLabel(opcode.RelativeDepth); var node = new BrNode(label); arg.Push(node); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(UnreachableOpcode opcode, WasmNodeArg arg) { arg.Push(new UnreachableNode()); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(ElseOpcode opcode, WasmNodeArg arg) { arg.PopBlock(); var parentNode = arg.Pop(); var ifNode = parentNode as IfNode; if (ifNode == null) { throw new WasmNodeException("if node expected"); } var elseBlock = new NodesList(ifNode.Signature); ifNode.Else = elseBlock; arg.Push(ifNode); arg.PushBlock(elseBlock); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(IfOpcode opcode, WasmNodeArg arg) { var condition = arg.Pop(); var ifNode = new IfNode(condition, opcode.Signature); var thenBlock = new NodesList(opcode.Signature); ifNode.Then = thenBlock; arg.Push(ifNode); arg.PushBlock(thenBlock); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CallOpcode opcode, WasmNodeArg arg) { var target = arg.Context.ResolveFunction(opcode.FunctionIndex); var node = new CallNode(target); for (var i = target.Signature.Parameters.Count - 1; i >= 0; i--) { var param = arg.Pop(); node.Arguments.Insert(0, param); } arg.Push(node); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CurrentMemoryOpcode opcode, WasmNodeArg arg) { arg.Push(new CurrentMemoryNode()); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F32ConvertUI64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new F32ConvertUI64Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(GrowMemoryOpcode opcode, WasmNodeArg arg) { var value = arg.Pop(); arg.Push(new GrowMemoryNode(value)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64ExtendUI32Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I64ExtendUI32Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32Store16Opcode opcode, WasmNodeArg arg) { var value = arg.Pop(); var address = arg.Pop(); arg.Push(new I32Store16Node(opcode.Immediate, address, value)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(SelectOpcode opcode, WasmNodeArg arg) { var condition = arg.Pop(); var second = arg.Pop(); var first = arg.Pop(); arg.Push(new SelectNode(condition, first, second)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64Load8UOpcode opcode, WasmNodeArg arg) { var address = arg.Pop(); arg.Push(new I64Load8UNode(opcode.Immediate, address)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32ConstOpcode opcode, WasmNodeArg arg) { arg.Push(new I32ConstNode(opcode.Value)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64SqrtOpcode opcode, WasmNodeArg arg) { var expr = arg.Pop(); arg.Push(new F64SqrtNode(expr)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(GetLocalOpcode opcode, WasmNodeArg arg) { arg.Push(new GetLocalNode(arg.ResolveLocal(opcode.LocalIndex))); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64CopySignOpcode opcode, WasmNodeArg arg) { var right = arg.Pop(); var left = arg.Pop(); arg.Push(new F64CopySignNode(left, right)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32ReinterpretF32Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I32ReinterpretF32Node(operand)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CallIndirectOpcode opcode, WasmNodeArg arg) { var target = arg.Context.ResolveType(opcode.TypeIndex); var element = arg.Pop(); var node = new CallIndirectNode(target, element); for (var i = target.Parameters.Count - 1; i >= 0; i--) { var param = arg.Pop(); node.Arguments.Insert(0, param); } arg.Push(node); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32GeuOpcode opcode, WasmNodeArg arg) { var right = arg.Pop(); var left = arg.Pop(); arg.Push(new I32GeuNode(left, right)); return(null); }
WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(BlockOpcode opcode, WasmNodeArg arg) { var blockNode = new BlockNode(opcode.Signature); arg.Push(blockNode); arg.PushBlock(blockNode.Nodes); return(null); }