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(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(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(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(F64ReinterpretI64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new F64ReinterpretI64Node(operand)); 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(I64Load8UOpcode opcode, WasmNodeArg arg) { var address = arg.Pop(); arg.Push(new I64Load8UNode(opcode.Immediate, address)); 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(I32ReinterpretF32Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I32ReinterpretF32Node(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(I64TruncUF64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I64TruncUF64Node(operand)); 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(I64ExtendUI32Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new I64ExtendUI32Node(operand)); 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(F32ConvertUI64Opcode opcode, WasmNodeArg arg) { var operand = arg.Pop(); arg.Push(new F32ConvertUI64Node(operand)); 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(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(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(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(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(ReturnOpcode opcode, WasmNodeArg arg) { var farg = (WasmFunctionNodeArg)arg; //todo: var returnType = farg.Function.Signature.Return; switch (returnType) { case WasmType.I32: case WasmType.I64: case WasmType.F32: case WasmType.F64: var res = arg.Pop(); arg.Push(new ReturnNode(res)); break; default: arg.Push(new ReturnNode()); break; } return(null); }