Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F64PromoteF32Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

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

            arg.Push(new I64TruncUF64Node(operand));
            return(null);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 12
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(UnreachableOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new UnreachableNode());
     return(null);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 16
0
 WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(CurrentMemoryOpcode opcode, WasmNodeArg arg)
 {
     arg.Push(new CurrentMemoryNode());
     return(null);
 }
Exemplo n.º 17
0
        WasmNodeResult IWasmOpcodeVisitor <WasmNodeArg, WasmNodeResult> .Visit(F32ConvertUI64Opcode opcode, WasmNodeArg arg)
        {
            var operand = arg.Pop();

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

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

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

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

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

            arg.Push(new I32ReinterpretF32Node(operand));
            return(null);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }