Пример #1
0
        public Macrocall Clone(Block parentBlock)
        {
            var res = new Macrocall()
            {
                AssemblePosition = this.AssemblePosition,
                CallerName       = this.CallerName,
                DebugText        = this.DebugText,
                WrittenBlock     = parentBlock
            };

            //Labels
            res.Labels = new List <Assemble.Label>();
            for (int i = 0; i < this.Labels.Count; i++)
            {
                Label clonedLbl = this.Labels[i].Clone(parentBlock);
                res.Labels.Add(clonedLbl);
            }

            //Operands
            res.Operands = new OperandElement[this.Operands.Length];
            for (int i = 0; i < this.Operands.Length; i++)
            {
                res.Operands[i] = this.Operands[i].Clone(parentBlock, res);
            }

            return(res);
        }
Пример #2
0
        public bool ExpandMacro(int statementIdx, List <AssembleError> errorList)
        {
            StatementElement stmt      = Statements[statementIdx];
            Macrocall        macrocall = stmt.Macrocall;

            //マクロ定義を有効なスコープと全セクションから検索する
            MacroDefinition macrodef;

            if (!FindMacrodef(macrocall.CallerName, out macrodef))
            {
                errorList.Add(new AssembleError()
                {
                    Title    = "Macro expanding",
                    Detail   = "Macro definition '" + macrocall.CallerName + "' not found.",
                    Position = this.AssemblePosition
                });
                return(false);
            }

            //展開先のブロックを作成しする
            Block expandedBlock = new Block()
            {
                AssemblePosition = stmt.Macrocall.AssemblePosition,
                Name             = stmt.Macrocall.CallerName + "_expanded",
                ParentBlock      = this,
                RootCode         = this.RootCode
            };
            StatementElement expandedStmt = new StatementElement()
            {
                Type  = enumStatementType.Block,
                Block = expandedBlock
            };

            //マクロの内容をコピーする
            macrodef.CopyToBlock(expandedBlock);

            //置換を行う
            if (!expandedStmt.ReplaceByIdentifiers(macrodef.Arguments, macrocall.Operands, errorList))
            {
                return(false);
            }

            //マクロ呼出しのラベルを展開先のブロックに設定する
            foreach (var lbl in macrocall.Labels)
            {
                var newLbl = lbl.Clone(expandedBlock.ParentBlock);
                expandedBlock.Labels.Add(newLbl);
                newLbl.SetLabelPlacedInfo(expandedBlock.PlacedInfo);
            }

            //マクロ呼出しを削除して展開先ブロックに置き換える
            Statements[statementIdx] = expandedStmt;

            return(true);
        }
Пример #3
0
            public OperandElement Clone(Block parentBlock, Macrocall writtenMacro)
            {
                var res = new OperandElement()
                {
                    AssemblePosition = this.AssemblePosition,
                    Immediate        = this.Immediate.Clone(parentBlock),
                    WrittenMacrocall = writtenMacro
                };

                return(res);
            }