Example #1
0
        private static StartupFileGenerator.InterruptVector[] ParseInterruptVectors(string fullName)
        {
            var numOfReservedInterrupts = 0;
            var vectors = new List<StartupFileGenerator.InterruptVector>();
            var insideTable = false;
            Match match = null;
            var externalInterrupts = false;

            foreach (var line in File.ReadLines(fullName))
            {
                if (!insideTable)
                {
                    match = VECTOR_TABLE_START.Match(line);
                    if (!match.Success)
                    {
                        continue;
                    }

                    vectors.Add(new StartupFileGenerator.InterruptVector
                    {
                        Name = match.Groups[1].Value,
                        OptionalComment = match.Groups[2].Value
                    });
                    insideTable = true;
                }
                else
                {
                    match = VECTOR_TABLE_ENTRY.Match(line);
                    if (match.Success)
                    {
                        var vectorName = match.Groups[1].Value;
                        var comment = match.Groups[1].Value;

                        if (vectorName == UNINTIALIZED_VECTOR_ENTRY)
                        {
                            vectorName = string.Format(
                                "Reserved_{0}_{1}",
                                numOfReservedInterrupts++,
                                externalInterrupts ? "_IRQHandler" : "_Handler");
                        }

                        var vector = new StartupFileGenerator.InterruptVector
                        {
                            Name = vectorName,
                            OptionalComment = comment
                        };

                        vectors.Add(vector);
                        continue;
                    }

                    if (EXTERNAL_INTERRUPTS.Match(line).Success)
                    {
                        externalInterrupts = true;
                        continue;
                    }

                    if (VECTOR_TABLE_END.Match(line).Success)
                    {
                        break;
                    }

                    if (IGNORE_LINE.Match(line).Success)
                    {
                        continue;
                    }

                    throw new Exception("Failed to parse vector table");
                }
            }

            return vectors.ToArray();
        }