Пример #1
0
        public List <Opcode> BuildProgram(bool interpreted)
        {
            CodePart program = new CodePart();

            foreach (CodePart part in _parts)
            {
                if (interpreted)
                {
                    program.MainCode.AddRange(part.InitializationCode);
                }
                else
                {
                    program.InitializationCode.AddRange(part.InitializationCode);
                }

                program.FunctionsCode.AddRange(part.FunctionsCode);
                program.MainCode.AddRange(part.MainCode);
            }

            AddJumpToEntryPoint(program);
            AddEndOfProgram(program, interpreted);
            List <Opcode> mergedProgram = program.MergeSections();

            ReplaceLabels(mergedProgram);

            return(mergedProgram);
        }
Пример #2
0
 private void AddJumpToEntryPoint(CodePart program)
 {
     if (program.MainCode.Count > 0)
     {
         OpcodeBranchJump jumpOpcode = new OpcodeBranchJump();
         jumpOpcode.DestinationLabel = program.MainCode[0].Label;
         program.FunctionsCode.Insert(0, jumpOpcode);
     }
 }
Пример #3
0
 private void AddEndOfProgram(CodePart program, bool interpreted)
 {
     if (interpreted)
     {
         program.MainCode.Add(new OpcodeEOF());
     }
     else
     {
         program.MainCode.Add(new OpcodeEOP());
     }
 }
Пример #4
0
 public void Add(CodePart part)
 {
     _parts.Add(part);
 }