Assembler.Assembler.SectionCode.GetLabels C# (CSharp) Method

GetLabels() private static method

Gets the labels' positions for every section of the code.
private static GetLabels ( string[]>.IList sections, RegexOpcode[]>.Dictionary regexOpcodeDict, int offset ) : ushort>.Dictionary
sections string[]>.IList A **sorted** list of lines of code for each section (each section in alphabetical/rom layout order)
regexOpcodeDict RegexOpcode[]>.Dictionary A Dictionary of each list of RegexOpcodes in each section
offset int Where the "text" section starts
return ushort>.Dictionary
            private static Dictionary<string, ushort> GetLabels(IList<KeyValuePair<string, string[]>> sections, Dictionary<string, RegexOpcode[]> regexOpcodeDict, int offset)
            {
                Regex label = new Regex(@"^\s*([_a-zA-Z]\w+):");
                var labels = new Dictionary<string, ushort>();

                int pc = 0;

                foreach (var section in sections)
                {
                    var sectionName = section.Key;
                    var code = section.Value;
                    var regexOpcodes = regexOpcodeDict[sectionName];

                    pc = sectionName == "text" ? offset : int.Parse(sectionName.Substring(3, 2), NumberStyles.HexNumber);

                    for (int i = 0; i < code.Length; i++, pc++)
                    {
                        // If there is a label at the start of the line, add it and its position to the label dictionary
                        if (label.IsMatch(code[i]))
                            labels.Add(label.Match(code[i]).Groups[1].Value, (ushort) pc);

                        pc += regexOpcodes[i].BytesFollowing;
                    }
                }
                return labels;
            }