Exemple #1
0
        /// <summary>
        /// Assemble the parsed <see cref="SourceLine"/>.
        /// </summary>
        /// <param name="line">The line to assembly.</param>
        /// <returns>The disassembly output from the assembly operation.</returns>
        /// <exception cref="BlockClosureException"/>
        /// <exception cref="DirectoryNotFoundException"/>
        /// <exception cref="DivideByZeroException"/>
        /// <exception cref="ExpressionException"/>
        /// <exception cref="FileNotFoundException"/>
        /// <exception cref="FormatException"/>
        /// <exception cref="InvalidPCAssignmentException"/>
        /// <exception cref="BlockAssemblerException"/>
        /// <exception cref="OverflowException"/>
        /// <exception cref="ProgramOverflowException"/>
        /// <exception cref="ReturnException"/>
        /// <exception cref="SectionException"/>
        /// <exception cref="SymbolException"/>
        /// <exception cref="SyntaxException"/>
        public string Assemble(RandomAccessIterator <SourceLine> lines)
        {
            var  first     = lines.Current;
            bool isSpecial = first.Label != null && first.Label.IsSpecialOperator();

            PCOnAssemble = Services.Output.LogicalPC;
            if (first.Label != null && !first.Label.Name.Equals("*"))
            {
                if (isSpecial)
                {
                    Services.SymbolManager.DefineLineReference(first.Label, PCOnAssemble);
                }
                else if (first.Instruction == null || !ExcludedInstructionsForLabelDefines.Contains(first.Instruction.Name))
                {
                    DefineLabel(first.Label, PCOnAssemble, true);
                }
            }
            if (first.Instruction != null)
            {
                return(OnAssemble(lines));
            }
            if (first.Label != null && !isSpecial)
            {
                var symbol = Services.SymbolManager.GetSymbol(first.Label, false);
                if (symbol != null && symbol.IsNumeric && symbol.StorageType == StorageType.Scalar && !double.IsNaN(symbol.NumericValue))
                {
                    return(string.Format(".{0}{1}",
                                         ((int)symbol.NumericValue).ToString("x4").PadRight(42),
                                         Services.Options.NoSource ? string.Empty : first.Source));
                }
            }
            return(string.Empty);
        }
Exemple #2
0
 /// <summary>
 /// Constructs a DotNetAsm.MiscAssembler class.
 /// </summary>
 /// <param name="services">The shared <see cref="AssemblyServices"/> object.</param>
 public MiscAssembler(AssemblyServices services)
     : base(services)
 {
     Reserved.DefineType("Directives",
                         ".assert", ".bank", ".end",
                         ".eor", ".echo", ".forcepass",
                         ".format", ".invoke",
                         ".initmem", ".target",
                         ".error", ".errorif",
                         ".pron", ".proff",
                         ".warnif", ".warn",
                         ".dsection", ".section"
                         );
     ExcludedInstructionsForLabelDefines.Add(".section");
     Services.PassChanged += (s, a) => Services.PrintOff = false;
 }
Exemple #3
0
        /// <summary>
        /// Constructs a new instance of a block assembler.
        /// </summary>
        /// <param name="services">The shared <see cref="AssemblyServices"/> object.</param>
        public BlockAssembler(AssemblyServices services)
            : base(services)
        {
            _blocks       = new Stack <BlockProcessorBase>();
            _functionDefs = new Dictionary <StringView, Function>(services.StringViewComparer);

            _currentBlock = null;

            _openClosures = new Dictionary <StringView, StringView>(services.StringViewComparer)
            {
                { ".block", ".endblock" },
                { ".for", ".next" },
                { ".foreach", ".next" },
                { ".function", ".endfunction" },
                { ".if", ".endif" },
                { ".ifdef", ".endif" },
                { ".ifndef", ".endif" },
                { ".namespace", ".endnamespace" },
                { ".page", ".endpage" },
                { ".repeat", ".endrepeat" },
                { ".switch", ".endswitch" },
                { ".while", ".endwhile" }
            };

            Reserved.DefineType("Functional",
                                ".function", ".endfunction");

            Reserved.DefineType("NonOpens",
                                ".break", ".case", ".continue", ".default", ".endblock", ".endif",
                                ".endfunction", ".endpage", ".endnamespace", ".endrepeat", ".endswitch",
                                ".endwhile", ".else", ".elseif", ".elseifdef", ".elseifdef", ".elseifndef", ".next");

            Reserved.DefineType("BreakContinue", ".break", ".continue");

            Reserved.DefineType("Goto", ".goto");

            ExcludedInstructionsForLabelDefines.Add(".function");
            ExcludedInstructionsForLabelDefines.Add(".block");

            Services.Evaluator.AddFunctionEvaluator(this);

            Services.IsReserved.Add(s => _functionDefs.ContainsKey(s));
        }
        /// <summary>
        /// Constructs a new instance of the assignment assembler class.
        /// </summary>
        /// <param name="services">The shared <see cref="AssemblyServices"/> object.</param>
        public AssignmentAssembler(AssemblyServices services)
            : base(services)
        {
            Reserved.DefineType("Assignments", ".equ", ".global", "=");

            Reserved.DefineType("Pseudo",
                                ".relocate", ".pseudopc", ".endrelocate", ".realpc");

            Reserved.DefineType("Directives", ".let", ".org");

            Reserved.DefineType("Functions", "len");

            ExcludedInstructionsForLabelDefines.Add(".org");
            ExcludedInstructionsForLabelDefines.Add(".equ");
            ExcludedInstructionsForLabelDefines.Add("=");
            ExcludedInstructionsForLabelDefines.Add(".global");

            Services.Evaluator.AddFunctionEvaluator(this);
        }