Example #1
0
 public DefhPragma(IZ80AsmVisitorContext visitorContext, Z80AsmParser.DefhPragmaContext context)
 {
     if (context.expr() != null)
     {
         ByteVector = visitorContext.GetExpression(context.expr());
     }
 }
Example #2
0
        public CompoundOperation(IZ80AsmVisitorContext visitorContext, Z80AsmParser.CompoundOperationContext context) : base(context)
        {
            var operands = context.operand();

            if (operands == null)
            {
                return;
            }
            for (var i = 0; i < operands.Length; i++)
            {
                // --- Collect operands
                var operandCtx = operands[i];
                switch (i)
                {
                case 0:
                    Operand = visitorContext.GetOperand(operandCtx);
                    break;

                case 1:
                    Operand2 = visitorContext.GetOperand(operandCtx);
                    break;

                default:
                    Operand3 = visitorContext.GetOperand(operandCtx);
                    break;
                }
            }
        }
 protected ExpressionPragmaBase(IZ80AsmVisitorContext visitorContext, IParseTree context)
 {
     if (context.ChildCount > 1)
     {
         Expression = visitorContext.GetExpression(context.GetChild(1));
     }
 }
Example #4
0
 public TracePragma(IZ80AsmVisitorContext visitorContext, Z80AsmParser.TracePragmaContext context)
 {
     IsHex = context.TRACEHEX() != null;
     Exprs = context.expr() != null
         ? context.expr().Select(visitorContext.GetExpression).ToList()
         : new List <ExpressionNode>();
 }
Example #5
0
 public BankPragma(IZ80AsmVisitorContext visitorContext, IParseTree context)
     : base(visitorContext, context)
 {
     if (context.ChildCount > 3)
     {
         StartOffset = visitorContext.GetExpression(context.GetChild(3));
     }
 }
Example #6
0
 public SkipPragma(IZ80AsmVisitorContext visitorContext, IParseTree context)
     : base(visitorContext, context)
 {
     if (context.ChildCount > 3)
     {
         Fill = visitorContext.GetExpression(context.GetChild(3));
     }
 }
Example #7
0
 public DefwPragma(IZ80AsmVisitorContext visitorContext, IParseTree context)
 {
     Exprs = new List <ExpressionNode>();
     for (var i = 1; i < context.ChildCount; i += 2)
     {
         Exprs.Add(visitorContext.GetExpression(context.GetChild(i)));
     }
 }
Example #8
0
 public MacroStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.MacroStatementContext context)
 {
     Arguments = new List <string>();
     foreach (var id in context.IDENTIFIER())
     {
         visitorContext.AddIdentifier(id);
         Arguments.Add(id.NormalizeToken());
     }
 }
Example #9
0
 public ModuleStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.ModuleStatementContext context)
 {
     if (context.IDENTIFIER() == null)
     {
         return;
     }
     Name = context.IDENTIFIER().GetText().ToUpper();
     visitorContext.AddIdentifier(context.IDENTIFIER());
 }
Example #10
0
 public IncludeDirective(IZ80AsmVisitorContext visitorContext, Z80AsmParser.DirectiveContext context) :
     base(context)
 {
     if (context.STRING() != null)
     {
         visitorContext.AddString(context.STRING());
     }
     Filename = context.GetChild(1).NormalizeString();
 }
Example #11
0
 public DefmnPragma(IZ80AsmVisitorContext visitorContext, IParseTree context,
                    bool nullTerminator, bool bit7Terminator)
 {
     if (context.ChildCount > 1)
     {
         Message = visitorContext.GetExpression(context.GetChild(1));
     }
     NullTerminator = nullTerminator;
     Bit7Terminator = bit7Terminator;
 }
Example #12
0
        public MacroStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.MacroStatementContext context)
        {
            Arguments = new List <string>();
            var paramIds = context.IDENTIFIER();

            foreach (var id in paramIds)
            {
                visitorContext.AddIdentifier(id);
                Arguments.Add(id.GetText());
            }
        }
Example #13
0
 public Directive(IZ80AsmVisitorContext visitorContext, IParseTree context) : base(context)
 {
     if (context.ChildCount > 1)
     {
         Identifier = context.GetChild(1).NormalizeToken();
     }
     if (context.GetChild(1) is Z80AsmParser.ExprContext)
     {
         Expr = visitorContext.GetExpression(context.GetChild(1));
     }
 }
Example #14
0
        public IfStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.IfStatementContext context)
        {
            if (context.IFSTMT() != null)
            {
                Expr = visitorContext.GetExpression(context.expr());
                Type = IfStatementType.If;
                return;
            }

            Type   = context.IFUSED() != null ? IfStatementType.IfUsed : IfStatementType.IfNotUsed;
            Symbol = visitorContext.GetSymbol(context.symbolExpr());
        }
Example #15
0
        public FillbPragma(IZ80AsmVisitorContext visitorContext, IParseTree context)
        {
            if (context.ChildCount > 1)
            {
                Count = visitorContext.GetExpression(context.GetChild(1));
            }

            if (context.ChildCount > 3)
            {
                Expression = visitorContext.GetExpression(context.GetChild(3));
            }
        }
Example #16
0
        public DefsPragma(IZ80AsmVisitorContext visitorContext, Z80AsmParser.DefsPragmaContext context)
        {
            if (context.ChildCount > 1)
            {
                Count = visitorContext.GetExpression(context.GetChild(1));
            }

            if (context.ChildCount > 3)
            {
                Value = visitorContext.GetExpression(context.GetChild(3));
            }
        }
Example #17
0
        public LineDirective(IZ80AsmVisitorContext visitorContext, Z80AsmParser.DirectiveContext context) :
            base(context)
        {
            if (context.expr() != null)
            {
                Expr = visitorContext.GetExpression(context.expr());
            }

            if (context.STRING() != null)
            {
                visitorContext.AddString(context.STRING());
            }
            Filename = context.STRING().NormalizeString();
        }
Example #18
0
        public LocalStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.LocalStatementContext context)
        {
            if (context.IDENTIFIER() == null)
            {
                return;
            }

            Locals = new List <string>();
            foreach (var expr in context.IDENTIFIER())
            {
                Locals.Add(expr.GetText());
                visitorContext.AddIdentifier(expr);
            }
        }
Example #19
0
        public MacroOrStructInvocation(IZ80AsmVisitorContext visitorContext, Z80AsmParser.MacroOrStructInvocationContext context)
        {
            Parameters = new List <Operand>();
            if (context.macroArgument().Length > 1 ||
                context.macroArgument().Length > 0 && context.macroArgument()[0].operand() != null)
            {
                Parameters.AddRange(context.macroArgument()
                                    .Select(arg => arg.operand() != null
                        ? visitorContext.GetOperand(arg.operand())
                        : new Operand()));
            }

            KeywordSpan = new TextSpan(context.Start.StartIndex, context.Start.StopIndex + 1);
            Name        = context.IDENTIFIER().GetText();
        }
Example #20
0
 public ConditionalExpressionNode(IZ80AsmVisitorContext visitorContext,
                                  Z80AsmParser.ExprContext context,
                                  string sourceText,
                                  ExpressionNode condition)
 {
     SourceText = sourceText;
     Condition  = condition;
     if (context.expr().Length > 0)
     {
         TrueExpression = visitorContext.GetExpression(context.expr()[0]);
     }
     if (context.expr().Length > 1)
     {
         FalseExpression = visitorContext.GetExpression(context.expr()[1]);
     }
 }
Example #21
0
        public IncludeBinPragma(IZ80AsmVisitorContext visitorContext, Z80AsmParser.IncBinPragmaContext context)
        {
            if (context.expr() == null)
            {
                return;
            }

            if (context.expr().Length > 0)
            {
                FileExpr = visitorContext.GetExpression(context.expr()[0]);
            }
            if (context.expr().Length > 1)
            {
                OffsetExpr = visitorContext.GetExpression(context.expr()[1]);
            }
            if (context.expr().Length > 2)
            {
                LengthExpr = visitorContext.GetExpression(context.expr()[2]);
            }
        }
Example #22
0
        public ForStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.ForStatementContext context)
        {
            if (context.IDENTIFIER() != null)
            {
                visitorContext.AddIdentifier(context.IDENTIFIER());
                ForVariable = context.IDENTIFIER()?.NormalizeToken();
            }
            if (context.TO() != null)
            {
                visitorContext.AddStatement(context.TO());
            }

            if (context.STEP() != null)
            {
                visitorContext.AddStatement(context.STEP());
            }

            From = context.expr().Length > 0 ? visitorContext.GetExpression(context.expr()[0]) : null;
            To   = context.expr().Length > 1 ? visitorContext.GetExpression(context.expr()[1]) : null;
            Step = context.expr().Length > 2 ? visitorContext.GetExpression(context.expr()[2]) : null;
        }
Example #23
0
 public UntilStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.UntilStatementContext context)
 {
     Expression = visitorContext.GetExpression(context.expr());
 }
Example #24
0
 public EntPragma(IZ80AsmVisitorContext visitorContext, IParseTree context)
     : base(visitorContext, context)
 {
 }
Example #25
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);
            }
        }
Example #26
0
 public LoopStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.ExprContext context)
 {
     Expression = visitorContext.GetExpression(context);
 }
Example #27
0
 public WhileStatement(IZ80AsmVisitorContext visitorContext, Z80AsmParser.WhileStatementContext context)
 {
     Expr = visitorContext.GetExpression(context.expr());
 }