Example #1
0
        /// <summary>
        /// Checks if the operand is used as a macro parameter node
        /// </summary>
        /// <param name="context"></param>
        private void CheckForMacroParamNode(Z80AsmParser.OperandContext context)
        {
            if (context == null)
            {
                return;
            }

            var op = (Operand)VisitOperand(context);

            if (!MacroParsingPhase && (op.Type != OperandType.Expr || !(op.Expression is MacroParamNode)))
            {
                // --- Built in function can use only macro parameters during the collection phase
                IssueToEmit = Errors.Z0421;
            }
        }
Example #2
0
 public override object VisitOperand(Z80AsmParser.OperandContext context)
 => new Operand(this, context);
Example #3
0
 /// <summary>
 /// Gets an operand from the specified context
 /// </summary>
 /// <param name="context">Context to get the operand from</param>
 /// <returns>Node that represents the operand</returns>
 public Operand GetOperand(Z80AsmParser.OperandContext context)
 {
     return((Operand)VisitOperand(context));
 }
 /// <summary>
 /// Visit a parse tree produced by <see cref="Z80AsmParser.operand"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitOperand([NotNull] Z80AsmParser.OperandContext context)
 {
     return(VisitChildren(context));
 }
Example #5
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="Z80AsmParser.operand"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitOperand([NotNull] Z80AsmParser.OperandContext context)
 {
 }
Example #6
0
        /// <summary>
        /// Visit a parse tree produced by <see cref="Generated.Z80AsmParser.operand"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        /// <return>The visitor result.</return>
        public override object VisitOperand(Z80AsmParser.OperandContext context)
        {
            if (IsInvalidContext(context))
            {
                return(null);
            }

            // --- The context has exactly one child
            var child = context.GetChild(0);
            var op    = new Operand();

            if (child is Z80AsmParser.Reg8Context)
            {
                op.Type     = OperandType.Reg8;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.Reg8IdxContext)
            {
                op.Type     = OperandType.Reg8Idx;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.Reg8SpecContext)
            {
                op.Type     = OperandType.Reg8Spec;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.Reg16Context)
            {
                op.Type     = OperandType.Reg16;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.Reg16IdxContext)
            {
                op.Type     = OperandType.Reg16Idx;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.Reg16SpecContext)
            {
                op.Type     = OperandType.Reg16Spec;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.MemIndirectContext)
            {
                var expContext = child.GetChild(1) as Z80AsmParser.ExprContext;
                op.Type       = OperandType.MemIndirect;
                op.Expression = (ExpressionNode)VisitExpr(expContext);
            }
            else if (child is Z80AsmParser.RegIndirectContext)
            {
                op.Type     = OperandType.RegIndirect;
                op.Register = child.GetText().NormalizeToken();
            }
            else if (child is Z80AsmParser.CPortContext)
            {
                op.Type = OperandType.CPort;
            }
            else if (child is Z80AsmParser.IndexedAddrContext)
            {
                op.Type = OperandType.IndexedAddress;
                var indexedAddrContext = child as Z80AsmParser.IndexedAddrContext;
                if (indexedAddrContext.ChildCount > 3)
                {
                    op.Expression = indexedAddrContext.GetChild(3) is Z80AsmParser.LiteralExprContext
                        ? (ExpressionNode)VisitLiteralExpr(
                        indexedAddrContext.GetChild(3) as Z80AsmParser.LiteralExprContext)
                        : indexedAddrContext.GetChild(3).NormalizeToken() == "["
                            ? (ExpressionNode)VisitExpr(indexedAddrContext.GetChild(4) as Z80AsmParser.ExprContext)
                            : (ExpressionNode)VisitSymbolExpr(
                        indexedAddrContext.GetChild(3) as Z80AsmParser.SymbolExprContext);
                }
                op.Register = indexedAddrContext.GetChild(1).NormalizeToken();
                op.Sign     = indexedAddrContext.ChildCount > 3
                    ? indexedAddrContext.GetChild(2).NormalizeToken()
                    : null;
            }
            else if (child is Z80AsmParser.ExprContext)
            {
                op.Type       = OperandType.Expr;
                op.Expression = (ExpressionNode)VisitExpr(child as Z80AsmParser.ExprContext);
            }
            return(op);
        }
Example #7
0
        public Operand(IZ80AsmVisitorContext visitorContext, Z80AsmParser.OperandContext context)
        {
            // --- The context has exactly one child
            ParserRuleContext regContext = null;

            if (context.reg8() != null)
            {
                Type       = OperandType.Reg8;
                Register   = context.reg8().NormalizeToken();
                regContext = context.reg8();
            }
            else if (context.reg8Idx() != null)
            {
                Type       = OperandType.Reg8Idx;
                Register   = context.reg8Idx().NormalizeToken();
                regContext = context.reg8Idx();
            }
            else if (context.reg8Spec() != null)
            {
                Type       = OperandType.Reg8Spec;
                Register   = context.reg8Spec().NormalizeToken();
                regContext = context.reg8Spec();
            }
            else if (context.reg16() != null)
            {
                Type       = OperandType.Reg16;
                Register   = context.reg16().NormalizeToken();
                regContext = context.reg16();
            }
            else if (context.reg16Idx() != null)
            {
                Type       = OperandType.Reg16Idx;
                Register   = context.reg16Idx().NormalizeToken();
                regContext = context.reg16Idx();
            }
            else if (context.reg16Spec() != null)
            {
                Type       = OperandType.Reg16Spec;
                Register   = context.reg16Spec().NormalizeToken();
                regContext = context.reg16Spec();
            }
            else if (context.memIndirect() != null)
            {
                var miContext  = context.memIndirect();
                var expContext = miContext.expr();
                Type       = OperandType.MemIndirect;
                Expression = visitorContext.GetExpression(expContext);
                if (miContext.LPAR() != null)
                {
                    visitorContext.AddOperand(miContext.LPAR());
                }
                if (miContext.RPAR() != null)
                {
                    visitorContext.AddOperand(miContext.RPAR());
                }
            }
            else if (context.regIndirect() != null)
            {
                Type       = OperandType.RegIndirect;
                Register   = context.regIndirect().NormalizeToken();
                regContext = context.regIndirect();
            }
            else if (context.cPort() != null)
            {
                Type       = OperandType.CPort;
                regContext = context.cPort();
            }
            else if (context.indexedAddr() != null)
            {
                Type = OperandType.IndexedAddress;
                var idContext = context.indexedAddr();
                regContext = idContext.reg16Idx();
                if (idContext.ChildCount > 3)
                {
                    Expression = visitorContext.GetExpression(idContext.expr());
                }
                Register = idContext.reg16Idx().NormalizeToken();
                Sign     = idContext.ChildCount > 3
                    ? idContext.GetChild(2).NormalizeToken()
                    : null;
                if (idContext.LPAR() != null)
                {
                    visitorContext.AddOperand(idContext.LPAR());
                }
                if (idContext.RPAR() != null)
                {
                    visitorContext.AddOperand(idContext.RPAR());
                }
            }
            else if (context.expr() != null)
            {
                Type       = OperandType.Expr;
                Expression = visitorContext.GetExpression(context.expr());
            }
            else if (context.condition() != null)
            {
                Type       = OperandType.Condition;
                Condition  = context.condition().NormalizeToken();
                regContext = context.condition();
            }
            else if (context.macroParam() != null)
            {
                // --- LREG or HREG with macro parameter
                visitorContext.AddFunction(context);
                visitorContext.AddMacroParam(context.macroParam());
                if (context.macroParam().IDENTIFIER() != null)
                {
                    visitorContext.AddMacroParamName(context.macroParam().IDENTIFIER().GetText());
                }
            }
            else if (context.reg16Std() != null)
            {
                // --- LREG or HREG with 16-bit register
                visitorContext.AddFunction(context);
                Type     = OperandType.Reg8;
                Register = string.Empty;

                if (context.HREG() != null)
                {
                    regContext = context.reg16Std();
                    switch (context.reg16Std().NormalizeToken())
                    {
                    case "BC":
                        Register = "B";
                        break;

                    case "DE":
                        Register = "D";
                        break;

                    case "HL":
                        Register = "H";
                        break;

                    case "IX":
                        Register = "IXH";
                        Type     = OperandType.Reg8Idx;
                        break;

                    case "IY":
                        Register = "IYH";
                        Type     = OperandType.Reg8Idx;
                        break;

                    default:
                        regContext = null;
                        break;
                    }
                }
                else
                {
                    regContext = context.reg16Std();
                    switch (context.reg16Std().NormalizeToken())
                    {
                    case "BC":
                        Register = "C";
                        break;

                    case "DE":
                        Register = "E";
                        break;

                    case "HL":
                        Register = "L";
                        break;

                    case "IX":
                        Register = "IXL";
                        Type     = OperandType.Reg8Idx;
                        break;

                    case "IY":
                        Register = "IYL";
                        Type     = OperandType.Reg8Idx;
                        break;

                    default:
                        regContext = null;
                        break;
                    }
                }
            }
            else if (context.NONEARG() != null)
            {
                // --- This can happen only as the result of a macro substitution
                Type = OperandType.None;
            }

            if (regContext != null)
            {
                visitorContext.AddOperand(regContext);
            }
        }