kOS.Safe.Compilation.CodePart.MergeSections C# (CSharp) Method

MergeSections() public method

public MergeSections ( ) : List
return List
        public List<Opcode> MergeSections()
        {
            var mergedCode = new List<Opcode>();
            mergedCode.AddRange(FunctionsCode);
            mergedCode.AddRange(InitializationCode);
            mergedCode.AddRange(MainCode);
            return mergedCode;
        }

Usage Example

Beispiel #1
0
        public List <Opcode> BuildProgram()
        {
            var program = new List <Opcode>();

            foreach (var objectFile in objectFiles.Values)
            {
                var linkedObject = new CodePart();

                foreach (var part in objectFile.Parts)
                {
                    AddInitializationCode(linkedObject, part);
                    linkedObject.FunctionsCode.AddRange(part.FunctionsCode);
                    linkedObject.MainCode.AddRange(part.MainCode);
                }

                // we assume that the first object is the main program and the rest are subprograms/libraries
                bool isMainProgram = (objectFile == objectFiles.Values.First());
                // add a jump to the entry point so the execution skips the functions code
                if (isMainProgram)
                {
                    AddJumpToEntryPoint(linkedObject);
                }
                // add an instruction to indicate the end of the program
                AddEndOfProgram(linkedObject, isMainProgram);
                // save the entry point of the object
                objectFile.EntryPointLabel = GetEntryPointLabel(linkedObject);
                // add the linked object to the final program
                program.AddRange(linkedObject.MergeSections());
            }

            // replace all the labels references with the corresponding address
            ReplaceLabels(program);

            return(program);
        }
All Usage Examples Of kOS.Safe.Compilation.CodePart::MergeSections