Beispiel #1
0
        /// <summary>
        /// Creates an empty ProgramDebugInfo object if the given debug info is null
        /// </summary>
        /// <param name="debugInfo">debug info to use if available</param>
        /// <returns>a valid ProgramDebugInfo object</returns>
        private static ProgramDebugInfo GetNotNull(ProgramDebugInfo debugInfo)
        {
            // Invalid?
            if (debugInfo == null)
            {
                debugInfo = new ProgramDebugInfo(new Dictionary<short, int>(),
                                                 new Dictionary<short, string>());
            }

            return debugInfo;
        }
        /// <summary>
        /// Creates a program from the information in the program builder
        /// </summary>
        /// <param name="processor">processor to pass to the program</param>
        /// <param name="keepDebugInfo">true to add a ProgramDebugInfo class to the Program</param>
        /// <returns>the created program</returns>
        public Program CreateProgram(Processor processor, bool keepDebugInfo = true)
        {
            // Resolve all fixups
            foreach (Tuple<short, string> fixup in fixups)
            {
                // Get the JumpCall instruction
                JumpCall oldInstruction = (JumpCall) store[fixup.Item1];
                short destination;

                // Lookup label
                if (!labels.TryGetValue(fixup.Item2, out destination))
                    throw new ImportException("Label \"" + fixup.Item2 + "\" is not defined");

                // Create and store new instruction
                store[fixup.Item1] = new JumpCall(oldInstruction, destination);
            }

            // Create debug info
            ProgramDebugInfo debugInfo = null;
            if (keepDebugInfo)
                debugInfo = new ProgramDebugInfo(lineNumbers, labelsReversed);

            // Create program object
            return new Program(processor, store, debugInfo);
        }