コード例 #1
0
        public override object VisitAddExpr(Z80AsmParser.AddExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var subExprs = context.multExpr();
            var expr     = VisitMultExpr(subExprs[0]);
            var opIndex  = 1;

            for (var i = 1; i < subExprs.Length; i++)
            {
                var rightExpr = VisitMultExpr(subExprs[i]);
                var opToken   = context.GetChild(opIndex).GetText();
                BinaryOperationNode addExpr;
                switch (opToken)
                {
                case "+":
                    addExpr = new AddOperationNode(expr, rightExpr);
                    break;

                default:     // -
                    addExpr = new SubtractOperationNode(expr, rightExpr);
                    break;
                }
                expr     = addExpr;
                opIndex += 2;
            }
            return(expr);
        }
コード例 #2
0
ファイル: DotProduct2.cs プロジェクト: harnold/cobe
        protected void CreateSingleLoop(
            ProgramGraph g, ValueNode ap, ValueNode bp, ValueNode s,
            ValueNode ap1, ValueNode bp1, ValueNode s1)
        {
            OperationNode[] o = new OperationNode[8];

            o[0] = new AddOperationNode();
            o[1] = new MulOperationNode();
            o[2] = new LoadOperationNode();
            o[3] = new AddOperationNode();
            o[4] = new LoadOperationNode();
            o[5] = new AddOperationNode();
            o[6] = new ConstOperationNode();
            o[7] = new ConstOperationNode();

            foreach (OperationNode op in o)
                g.AddNode(op);

            ValueNode[] v = new ValueNode[7];

            v[0] = new FloatRegisterNode();
            v[1] = new FloatRegisterNode();
            v[2] = new FloatRegisterNode();
            v[3] = new IntRegisterNode();
            v[4] = new IntRegisterNode();
            v[5] = new IntConstantNode(4);
            v[6] = new IntConstantNode(4);

            foreach (ValueNode val in v)
                g.AddNode(val);

            g.AddEdge(v[0], o[0]);
            g.AddEdge(s, o[0]);
            g.AddEdge(o[0], s1);
            g.AddEdge(v[1], o[1]);
            g.AddEdge(v[2], o[1]);
            g.AddEdge(o[1], v[0]);
            g.AddEdge(ap, o[2]);
            g.AddEdge(o[2], v[1]);
            g.AddEdge(ap, o[3]);
            g.AddEdge(v[3], o[3]);
            g.AddEdge(o[3], ap1);
            g.AddEdge(bp, o[4]);
            g.AddEdge(o[4], v[2]);
            g.AddEdge(bp, o[5]);
            g.AddEdge(v[4], o[5]);
            g.AddEdge(o[5], bp1);
            g.AddEdge(v[5], o[6]);
            g.AddEdge(o[6], v[3]);
            g.AddEdge(v[6], o[7]);
            g.AddEdge(o[7], v[4]);
        }
コード例 #3
0
ファイル: Z80AsmVisitor.cs プロジェクト: Toysoft/spectnetide
        public override object VisitExpr(Z80AsmParser.ExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            // --- Extract the expression text
            var sb = new StringBuilder(400);

            for (var i = 0; i < context.ChildCount; i++)
            {
                var token = context.GetChild(i).GetText();
                sb.Append(token);
            }

            ExpressionNode expr = null;

            switch (context)
            {
            // --- Primary operators
            case Z80AsmParser.BuiltInFunctionExprContext ctx:
                expr = (ExpressionNode)VisitBuiltinFunctionInvocation(ctx.builtinFunctionInvocation());
                break;

            case Z80AsmParser.FunctionInvocationExprContext ctx:
                expr = new FunctionInvocationNode(ctx.functionInvocation(), this);
                break;

            case Z80AsmParser.MacroParamExprContext ctx:
                expr = new MacroParamNode(ctx.macroParam(), this);
                break;

            // --- Unary operators
            case Z80AsmParser.UnaryPlusExprContext ctx:
                expr = new UnaryPlusNode(ctx, this);
                break;

            case Z80AsmParser.UnaryMinusExprContext ctx:
                expr = new UnaryMinusNode(ctx, this);
                break;

            case Z80AsmParser.BinaryNotExprContext ctx:
                expr = new UnaryBitwiseNotNode(ctx, this);
                break;

            case Z80AsmParser.LogicalNotExprContext ctx:
                expr = new UnaryLogicalNotNode(ctx, this);
                break;

            // --- Bracketed/Parenthesized expressions
            case Z80AsmParser.BracketedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            case Z80AsmParser.ParenthesizedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            // --- Literals
            case Z80AsmParser.LiteralExprContext ctx:
                expr = (ExpressionNode)VisitLiteral(ctx.literal());
                break;

            case Z80AsmParser.SymbolExprContext ctx:
                if (ctx.ChildCount != 0 && ctx.symbol()?.IDENTIFIER() != null)
                {
                    AddIdentifier(ctx);
                    expr = new IdentifierNode(ctx.symbol());
                }
                break;

            // --- Min/Max operators
            case Z80AsmParser.MinMaxExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<?":
                    expr = new MinOperationNode(ctx, this);
                    break;

                default:
                    expr = new MaxOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Multiplication operators
            case Z80AsmParser.MultExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "*":
                    expr = new MultiplyOperationNode(ctx, this);
                    break;

                case "/":
                    expr = new DivideOperationNode(ctx, this);
                    break;

                default:
                    expr = new ModuloOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Addition operators
            case Z80AsmParser.AddExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "+":
                    expr = new AddOperationNode(ctx, this);
                    break;

                default:
                    expr = new SubtractOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Shift operators
            case Z80AsmParser.ShiftExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<<":
                    expr = new ShiftLeftOperationNode(ctx, this);
                    break;

                default:
                    expr = new ShiftRightOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Relational operators
            case Z80AsmParser.RelExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<":
                    expr = new LessThanOperationNode(ctx, this);
                    break;

                case "<=":
                    expr = new LessThanOrEqualOperationNode(ctx, this);
                    break;

                case ">":
                    expr = new GreaterThanOperationNode(ctx, this);
                    break;

                default:
                    expr = new GreaterThanOrEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Equality operators
            case Z80AsmParser.EquExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "==":
                    expr = new EqualOperationNode(ctx, this);
                    break;

                case "===":
                    expr = new CaseInsensitiveEqualOperationNode(ctx, this);
                    break;

                case "!=":
                    expr = new NotEqualOperationNode(ctx, this);
                    break;

                default:
                    expr = new CaseInsensitiveNotEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Bitwise operators
            case Z80AsmParser.AndExprContext ctx:
                expr = new BitwiseAndOperationNode(ctx, this);
                break;

            case Z80AsmParser.XorExprContext ctx:
                expr = new BitwiseXorOperationNode(ctx, this);
                break;

            case Z80AsmParser.OrExprContext ctx:
                expr = new BitwiseOrOperationNode(ctx, this);
                break;

            // --- Ternary operator
            case Z80AsmParser.TernaryExprContext ctx:
                expr = new ConditionalExpressionNode(ctx, this);
                break;
            }

            if (expr != null)
            {
                expr.SourceText = sb.ToString();
            }
            return(expr);
        }
コード例 #4
0
ファイル: IIRFilter1.cs プロジェクト: harnold/cobe
        protected void CreateSingleLoop(
            ProgramGraph g, ValueNode xp, ValueNode yp, ValueNode x, ValueNode y,
            ValueNode c0, ValueNode c1, ValueNode c2, ValueNode xp1, ValueNode yp1,
            ValueNode x1, ValueNode y1)
        {
            OperationNode[] o = new OperationNode[11];

            o[0]  = new StoreOperationNode();
            o[1]  = new AddOperationNode();
            o[2]  = new AddOperationNode();
            o[3]  = new ConstOperationNode();
            o[4]  = new AddOperationNode();
            o[5]  = new MulOperationNode();
            o[6]  = new MulOperationNode();
            o[7]  = new MulOperationNode();
            o[8]  = new LoadOperationNode();
            o[9]  = new AddOperationNode();
            o[10] = new ConstOperationNode();

            foreach (OperationNode op in o)
                g.AddNode(op);

            ValueNode[] v = new ValueNode[9];

            v[0]  = new FloatMemoryNode(null);
            v[1]  = new IntRegisterNode();
            v[2]  = new FloatRegisterNode();
            v[3]  = new FloatRegisterNode();
            v[4]  = new IntConstantNode(4);
            v[5]  = new FloatRegisterNode();
            v[6]  = new FloatRegisterNode();
            v[7]  = new IntRegisterNode();
            v[8]  = new IntConstantNode(4);

            foreach (ValueNode val in v)
                g.AddNode(val);

            g.AddEdge(y1, o[0]);
            g.AddEdge(yp, o[0]);
            g.AddEdge(o[0], v[0]);
            g.AddEdge(yp, o[1]);
            g.AddEdge(v[1], o[1]);
            g.AddEdge(o[1], yp1);
            g.AddEdge(v[2], o[2]);
            g.AddEdge(v[3], o[2]);
            g.AddEdge(o[2], y1);
            g.AddEdge(v[4], o[3]);
            g.AddEdge(o[3], v[1]);
            g.AddEdge(v[5], o[4]);
            g.AddEdge(v[6], o[4]);
            g.AddEdge(o[4], v[2]);
            g.AddEdge(c2, o[5]);
            g.AddEdge(y, o[5]);
            g.AddEdge(o[5], v[3]);
            g.AddEdge(c1, o[6]);
            g.AddEdge(x, o[6]);
            g.AddEdge(o[6], v[5]);
            g.AddEdge(c0, o[7]);
            g.AddEdge(x1, o[7]);
            g.AddEdge(o[7], v[6]);
            g.AddEdge(xp, o[8]);
            g.AddEdge(o[8], x1);
            g.AddEdge(xp, o[9]);
            g.AddEdge(v[7], o[9]);
            g.AddEdge(o[9], xp1);
            g.AddEdge(v[8], o[10]);
            g.AddEdge(o[10], v[7]);
        }
コード例 #5
0
ファイル: LatticeFilter1.cs プロジェクト: harnold/cobe
        protected void CreateStoreIncGraph(
            OperationValueGraph g, ValueNode x, ValueNode p,
            ValueNode pi, int inc)
        {
            OperationNode storeOp = new StoreOperationNode();
            OperationNode addOp   = new AddOperationNode();
            OperationNode constOp = new ConstOperationNode();

            g.AddNode(storeOp);
            g.AddNode(addOp);
            g.AddNode(constOp);

            ValueNode m = new MemoryValueNode(x.Datatype, null);
            g.AddNode(m);

            ValueNode t = new IntRegisterNode();
            ValueNode i = new IntConstantNode(inc);

            g.AddNode(t);
            g.AddNode(i);

            g.AddEdge(x, storeOp);
            g.AddEdge(p, storeOp);
            g.AddEdge(storeOp, m);
            g.AddEdge(p, addOp);
            g.AddEdge(i, constOp);
            g.AddEdge(constOp, t);
            g.AddEdge(t, addOp);
            g.AddEdge(addOp, pi);
        }
コード例 #6
0
ファイル: LatticeFilter1.cs プロジェクト: harnold/cobe
        protected void CreateSingleFilterLoop(
            ProgramGraph g, ValueNode x, ValueNode x0, ValueNode x1,
            ValueNode c0, ValueNode c1, ValueNode c2, ValueNode c3, ValueNode c4,
            ValueNode z0, ValueNode z1, ValueNode y)
        {
            OperationNode[] o = new OperationNode[13];

            o[0]  = new AddOperationNode();
            o[1]  = new MulOperationNode();
            o[2]  = new AddOperationNode();
            o[3]  = new AddOperationNode();
            o[4]  = new MulOperationNode();
            o[5]  = new AddOperationNode();
            o[6]  = new AddOperationNode();
            o[7]  = new AddOperationNode();
            o[8]  = new MulOperationNode();
            o[9]  = new MulOperationNode();
            o[10] = new MulOperationNode();
            o[11] = new AddOperationNode();
            o[12] = new AddOperationNode();

            foreach (OperationNode opNode in o)
                g.AddNode(opNode);

            ValueNode[] v = new ValueNode[10];

            for (int i = 0; i < v.Length; i++)
                v[i] = new FloatRegisterNode();

            foreach (ValueNode vNode in v)
                g.AddNode(vNode);

            g.AddEdge(x,     o[0]);
            g.AddEdge(x0,    o[0]);
            g.AddEdge(o[0],  v[0]);
            g.AddEdge(c0,    o[1]);
            g.AddEdge(v[0],  o[1]);
            g.AddEdge(o[1],  v[1]);
            g.AddEdge(x,     o[2]);
            g.AddEdge(v[1],  o[2]);
            g.AddEdge(o[2],  v[2]);
            g.AddEdge(v[2],  o[3]);
            g.AddEdge(x1,    o[3]);
            g.AddEdge(o[3],  v[3]);
            g.AddEdge(c1,    o[4]);
            g.AddEdge(v[3],  o[4]);
            g.AddEdge(o[4],  v[4]);
            g.AddEdge(v[2],  o[5]);
            g.AddEdge(v[4],  o[5]);
            g.AddEdge(o[5],  z1);
            g.AddEdge(v[1],  o[6]);
            g.AddEdge(x0,    o[6]);
            g.AddEdge(o[6],  v[5]);
            g.AddEdge(v[4],  o[7]);
            g.AddEdge(x1,    o[7]);
            g.AddEdge(o[7],  z0);
            g.AddEdge(v[5],  o[8]);
            g.AddEdge(c2,    o[8]);
            g.AddEdge(o[8],  v[6]);
            g.AddEdge(z0,    o[9]);
            g.AddEdge(c3,    o[9]);
            g.AddEdge(o[9],  v[7]);
            g.AddEdge(z1,    o[10]);
            g.AddEdge(c4,    o[10]);
            g.AddEdge(o[10], v[9]);
            g.AddEdge(v[6],  o[11]);
            g.AddEdge(v[7],  o[11]);
            g.AddEdge(o[11], v[8]);
            g.AddEdge(v[8],  o[12]);
            g.AddEdge(v[9],  o[12]);
            g.AddEdge(o[12], y);
        }
コード例 #7
0
ファイル: LatticeFilter1.cs プロジェクト: harnold/cobe
        protected void CreateLoadIncGraph(
            OperationValueGraph g, ValueNode x, ValueNode p,
            ValueNode pi, int inc)
        {
            OperationNode loadOp  = new LoadOperationNode();
            OperationNode addOp   = new AddOperationNode();
            OperationNode constOp = new ConstOperationNode();

            g.AddNode(loadOp);
            g.AddNode(addOp);
            g.AddNode(constOp);

            ValueNode t = new IntRegisterNode();
            ValueNode i = new IntConstantNode(inc);

            g.AddNode(t);
            g.AddNode(i);

            g.AddEdge(p, loadOp);
            g.AddEdge(loadOp, x);
            g.AddEdge(p, addOp);
            g.AddEdge(i, constOp);
            g.AddEdge(constOp, t);
            g.AddEdge(t, addOp);
            g.AddEdge(addOp, pi);
        }
コード例 #8
0
ファイル: WeightedVectorSum1.cs プロジェクト: harnold/cobe
        protected void CreateSingleLoop(
            ProgramGraph g, ValueNode ap, ValueNode bp, ValueNode cp,
            ValueNode k0, ValueNode k1,
            ValueNode ap1, ValueNode bp1, ValueNode cp1)
        {
            OperationNode[] o = new OperationNode[12];

            o[0]  = new AddOperationNode();
            o[1]  = new MulOperationNode();
            o[2]  = new MulOperationNode();
            o[3]  = new LoadOperationNode();
            o[4]  = new AddOperationNode();
            o[5]  = new LoadOperationNode();
            o[6]  = new AddOperationNode();
            o[7]  = new ConstOperationNode();
            o[8]  = new ConstOperationNode();
            o[9]  = new StoreOperationNode();
            o[10] = new AddOperationNode();
            o[11] = new ConstOperationNode();

            foreach (OperationNode op in o)
                g.AddNode(op);

            ValueNode[] v = new ValueNode[12];

            v[0]  = new FloatRegisterNode();
            v[1]  = new FloatRegisterNode();
            v[2]  = new FloatRegisterNode();
            v[3]  = new FloatRegisterNode();
            v[4]  = new IntRegisterNode();
            v[5]  = new IntRegisterNode();
            v[6]  = new IntConstantNode(4);
            v[7]  = new IntConstantNode(4);
            v[8]  = new FloatRegisterNode();
            v[9]  = new FloatMemoryNode(null);
            v[10] = new IntRegisterNode();
            v[11] = new IntConstantNode(4);

            foreach (ValueNode val in v)
                g.AddNode(val);

            g.AddEdge(v[0], o[0]);
            g.AddEdge(v[1], o[0]);
            g.AddEdge(o[0], v[8]);
            g.AddEdge(v[2], o[1]);
            g.AddEdge(k0, o[1]);
            g.AddEdge(o[1], v[0]);
            g.AddEdge(v[3], o[2]);
            g.AddEdge(k1, o[2]);
            g.AddEdge(o[2], v[1]);
            g.AddEdge(ap, o[3]);
            g.AddEdge(o[3], v[2]);
            g.AddEdge(ap, o[4]);
            g.AddEdge(v[4], o[4]);
            g.AddEdge(o[4], ap1);
            g.AddEdge(bp, o[5]);
            g.AddEdge(o[5], v[3]);
            g.AddEdge(bp, o[6]);
            g.AddEdge(v[5], o[6]);
            g.AddEdge(o[6], bp1);
            g.AddEdge(v[6], o[7]);
            g.AddEdge(o[7], v[4]);
            g.AddEdge(v[7], o[8]);
            g.AddEdge(o[8], v[5]);
            g.AddEdge(v[8], o[9]);
            g.AddEdge(cp, o[9]);
            g.AddEdge(o[9], v[9]);
            g.AddEdge(cp, o[10]);
            g.AddEdge(v[10], o[10]);
            g.AddEdge(o[10], cp1);
            g.AddEdge(v[11], o[11]);
            g.AddEdge(o[11], v[10]);
        }