Example #1
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(LoopOpcode opcode, WasmNodeArg arg)
        {
            var loopNode = new LoopNode(opcode.Signature);

            arg.Push(loopNode);
            arg.PushBlock(loopNode.Nodes);
            return(null);
        }
Example #2
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64PromoteF32Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

            arg.Push(new F64PromoteF32Node(operand));
            return(null);
        }
Example #7
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64TruncUF64Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

            arg.Push(new I64TruncUF64Node(operand));
            return(null);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 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);
 }
Example #11
0
        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);
        }
Example #12
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(UnreachableOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new UnreachableNode());
     return(null);
 }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        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);
        }
Example #16
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CurrentMemoryOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new CurrentMemoryNode());
     return(null);
 }
Example #17
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F32ConvertUI64Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

            arg.Push(new F32ConvertUI64Node(operand));
            return(null);
        }
Example #18
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(GrowMemoryOpcode opcode, WasmNodeArg arg)
        {
            var value = arg.Pop();

            arg.Push(new GrowMemoryNode(value));
            return(null);
        }
Example #19
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64ExtendUI32Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

            arg.Push(new I64ExtendUI32Node(operand));
            return(null);
        }
Example #20
0
        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);
        }
Example #22
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I64Load8UOpcode opcode, WasmNodeArg arg)
        {
            var address = arg.Pop();

            arg.Push(new I64Load8UNode(opcode.Immediate, address));
            return(null);
        }
Example #23
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32ConstOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new I32ConstNode(opcode.Value));
     return(null);
 }
Example #24
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64SqrtOpcode opcode, WasmNodeArg arg)
        {
            var expr = arg.Pop();

            arg.Push(new F64SqrtNode(expr));
            return(null);
        }
Example #25
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(GetLocalOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new GetLocalNode(arg.ResolveLocal(opcode.LocalIndex)));
     return(null);
 }
Example #26
0
        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);
        }
Example #27
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(I32ReinterpretF32Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

            arg.Push(new I32ReinterpretF32Node(operand));
            return(null);
        }
Example #28
0
        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);
        }
Example #30
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(BlockOpcode opcode, WasmNodeArg arg)
        {
            var blockNode = new BlockNode(opcode.Signature);

            arg.Push(blockNode);
            arg.PushBlock(blockNode.Nodes);
            return(null);
        }