示例#1
0
        private void DecompileLabelTable()
        {
            PopByte();
            var name = ReadNameRef();
            var ofs  = ReadUInt32();

            while (ofs != 0x0000FFFF) // ends with non-ref + max-offset
            {
                var entry = new LabelTableEntry();
                entry.NameRef = name;
                entry.Name    = PCC.GetName(name);
                entry.Offset  = ofs;
                LabelTable.Add(entry);

                name = ReadNameRef();
                ofs  = ReadUInt32();
            }
        }
示例#2
0
        private void DecompileLabelTable()
        {
            PopByte();
            var name = ReadNameReference();
            var ofs  = ReadUInt32();

            while (ofs != 0x0000FFFF) // ends with non-ref + max-offset
            {
                LabelTable.Add(new LabelTableEntry
                {
                    NameRef = name,
                    Offset  = ofs
                });

                name = ReadNameReference();
                ofs  = ReadUInt32();
            }
        }
示例#3
0
        public StatusEntry(string id, string level, string label_enu, string detail_enu, string label_fra, string detail_fra)
        {
            int.TryParse(id, out int IdInt);
            Id = IdInt;

            int.TryParse(level, out int LevelInt);
            Level = LevelInt;

            string EnglishLabel = Language.ReplaceHtml(label_enu);

            LabelTable.Add(LanguageStates.English, EnglishLabel);

            string EnglishDetail = Language.ReplaceHtml(detail_enu);

            DetailTable.Add(LanguageStates.English, EnglishDetail);

            string FrenchLabel = Language.ReplaceHtml(label_fra);

            LabelTable.Add(LanguageStates.French, FrenchLabel);

            string FrenchDetail = Language.ReplaceHtml(detail_fra);

            DetailTable.Add(LanguageStates.French, FrenchDetail);
        }
示例#4
0
        public void Preprocess()
        {
            int current_section = -1;

            if (InputData.Count != 0)
            {
                current_section = 0;
            }

            int LabelIndex;

            if (current_section == 0)
            {
                for (int i = 0; i < InputData.Count; i++)
                {
                    ReadInstruction(i, false);
                    CurrentInstruction = RemoveSpaces(CurrentInstruction);
                    if (CurrentInstruction == "")
                    {
                        continue;
                    }
                    LabelIndex = CurrentInstruction.IndexOf(':');
                    if (LabelIndex == -1)
                    {
                        break;
                    }
                    if (LabelIndex == 0)
                    {
                        gui.ReportError("Error: Label name expected");
                        return;
                    }
                    int j = LabelIndex - 1;
                    while (j > 0 && (CurrentInstruction.ElementAt(j) == ' ' || CurrentInstruction.ElementAt(j) == '\t'))
                    {
                        j--;
                    }
                    string tempString = "";
                    bool   doneFlag   = false;
                    for (; j >= 0; j--)
                    {
                        char tempChar = CurrentInstruction.ElementAt(j);
                        if (tempChar != ' ' && tempChar != '\t' && !doneFlag)
                        {
                            tempString = tempChar + tempString;
                        }
                        else if (tempChar != ' ' && tempChar != '\t' && doneFlag)
                        {
                            gui.ReportError("Error: Unexpected text before label name");
                            return;
                        }
                        else
                        {
                            doneFlag = true;
                        }
                    }

                    if (!assertLabelAllowed(tempString))
                    {
                        return;
                    }
                    MemoryData tempMemory = new MemoryData();
                    tempMemory.Label = tempString;
                    int wordIndex  = CurrentInstruction.IndexOf(".word"); // TODO: Add directives for .float
                    int floatIndex = CurrentInstruction.IndexOf(".float");

                    if (!(floatIndex != -1 || wordIndex != -1))
                    {
                        gui.ReportError("Error: .word or .float not found");
                        return;
                    }
                    bool floatFlag;
                    int  Index;
                    if (wordIndex == -1)
                    {
                        floatFlag = true;
                        Index     = floatIndex;
                    }
                    else
                    {
                        floatFlag = false;
                        Index     = wordIndex;
                    }
                    tempMemory.floatFlag = floatFlag;
                    if (tempMemory.floatFlag)
                    {
                        MemoryData.StaticMemory += 4;
                    }
                    if (!OnlySpaces(LabelIndex + 1, Index, CurrentInstruction))
                    {
                        return;
                    }
                    bool foundValue  = false;
                    bool doneFinding = false;
                    tempString = "";
                    for (j = Index + (floatFlag ? 6 : 5); j < CurrentInstruction.Length; j++)
                    {
                        char temp = CurrentInstruction.ElementAt(j);
                        if (foundValue && (temp == ' ' || temp == '\t') && !doneFinding)
                        {
                            doneFinding = true;
                        }
                        else if (foundValue && temp != ' ' && temp != '\t' && doneFinding)
                        {
                            gui.ReportError("Error: Unexpected text after value");
                            return;
                        }
                        else if (!foundValue && temp != ' ' && temp != '\t')
                        {
                            foundValue = true;
                            tempString = tempString + temp;
                        }
                        else if (foundValue && temp != ' ' && temp != '\t')
                        {
                            tempString = tempString + temp;
                        }
                    }
                    if (floatFlag)
                    {
                        double tempValue;
                        if (!double.TryParse(tempString, out tempValue))
                        {
                            gui.ReportError("Error: Float conversion error");
                            return;
                        }
                        tempMemory.Value = tempString;
                    }
                    else
                    {
                        int tempValue;
                        if (!int.TryParse(tempString, out tempValue))
                        {
                            gui.ReportError("Error: Int conversion error");
                            return;
                        }
                        tempMemory.Value = tempString;
                    }
                    MemoryTable.Add(tempMemory);
                }
            }
            MemoryTable.Sort(delegate(MemoryData m1, MemoryData m2) { return(m1.Label.CompareTo(m2.Label)); });
            for (int i = 0; i < MemoryTable.Count - 1; i++)
            {
                if (MemoryTable.ElementAt(i) == MemoryTable.ElementAt(i + 1))
                {
                    gui.ReportError("Error: One or more labels are repeated");
                    return;
                }
            }

            if (InputText.Count != 0)
            {
                current_section = 1;
            }

            if (current_section != 1)
            {
                gui.ReportError("Error: Text section does not exist or found unknown string");
                return;
            }
            int  MainIndex = 0;
            bool FoundMain = false;

            LabelIndex = 0;
            for (int i = 0; i < InputText.Count; i++)
            {
                ReadInstruction(i, true);
                if (CurrentInstruction == "")
                {
                    continue;
                }
                LabelIndex = CurrentInstruction.IndexOf(":");
                if (LabelIndex == 0)
                {
                    gui.ReportError("Error: Label name expected");
                    return;
                }
                if (LabelIndex == -1)
                {
                    continue;
                }
                int j = LabelIndex - 1;
                while (j > 0 && CurrentInstruction.ElementAt(j) == ' ' && CurrentInstruction.ElementAt(j) == '\t')
                {
                    j--;
                }
                string tempString = "";
                bool   isLabel    = false;
                bool   doneFlag   = false;
                for (; j >= 0; j--)
                {
                    char temp = CurrentInstruction.ElementAt(j);
                    if (temp != ' ' && temp != '\t' && !doneFlag)
                    {
                        isLabel    = true;
                        tempString = temp + tempString;
                    }
                    else if (temp != ' ' && temp != '\t' && doneFlag)
                    {
                        gui.ReportError("Error: Unexpected text before label name");
                        return;
                    }
                    else if (!isLabel)
                    {
                        gui.ReportError("Error: Label name expected");
                        return;
                    }
                    else
                    {
                        doneFlag = true;
                    }
                }
                if (!assertLabelAllowed(tempString))
                {
                    return;
                }
                if (!OnlySpaces(LabelIndex + 1, CurrentInstruction.Length, CurrentInstruction))
                {
                    return;
                }
                if (tempString == "main")
                {
                    FoundMain = true;
                    MainIndex = CurrentLine;
                }
                else
                {
                    LabelData tempLabel = new LabelData();;
                    tempLabel.Address = CurrentLine;
                    tempLabel.Label   = tempString;
                    LabelTable.Add(tempLabel);
                }
            }
            LabelTable.Sort(delegate(LabelData l1, LabelData l2) { return(l1.Label.CompareTo(l2.Label)); });
            for (int i = 0; LabelTable.Count > 0 && i < LabelTable.Count - 1; i++)
            {
                if (LabelTable[i].Label == LabelTable[i + 1].Label)
                {
                    gui.ReportError("Error: One or more labels are repeated");
                    return;
                }
            }
            if (!FoundMain)
            {
                gui.ReportError("Error: Could not find main");
                return;
            }
            CurrentLine = MainIndex;
            gui.SendLog("Initialized and ready to execute.");
            gui.updateState();
        }