コード例 #1
0
ファイル: AcmePDBRandD.cs プロジェクト: martinpiper/ACME
        public string PostEnterKeyForCommand(string command)
        {
            // Produce a list of variable names and values relevant to the current PC and its zone
            List <LabelInfo> allLabels = new List <LabelInfo>();

            try
            {
                int theZone = m_PDBData.getAddrInfoForAddr(m_registerSet.GetPC()).mZone; //mAddrInfoByAddr[mPC].mZone;
                while (theZone >= 0)
                {
                    List <LabelInfo> theLabels = m_PDBData.getLabelsForZone(theZone); //mLabelInfoByZone[theZone];
                    allLabels.AddRange(theLabels);

                    // MPi: TODO: Replace with previous zone in the hierarchy when ACME saves it
                    if (theZone > 0)
                    {
                        theZone = 0;    // For now just display the global zone
                    }
                    else
                    {
                        break;
                    }
                }
                allLabels.Sort((a, b) => b.mLabel.Length.CompareTo(a.mLabel.Length));
            }
            catch (System.Exception)
            {
            }

            // Now add all other labels to the end of the list
            allLabels.AddRange(m_PDBData.getAllLabels()); // mAllLabels);

            // Look for labels after each whitespace
            int pos = 0;

            while (pos < command.Length)
            {
                int testPos = command.IndexOf(' ', pos);
                if (testPos < 0)
                {
                    testPos = command.IndexOf('~', pos);
                }
                if (testPos < 0)
                {
                    break;
                }
                pos = testPos + 1;

                string remaining = command.Substring(pos);
                if (remaining[0] == '.')
                {
                    remaining = remaining.Substring(1);
                }

                // Note the length order gets the most precise match
                LabelInfo found = null;

                if (remaining.Length > 0)
                {
                    foreach (LabelInfo label in allLabels)
                    {
                        if (label.mLabel.Length >= remaining.Length && remaining.StartsWith(label.mLabel))
                        {
                            found = label;
                            break;
                        }
                    }
                }

                // If it's found then reconstruct the command with the label replaced as a hex number
                if (null != found)
                {
                    string theHex = "$" + found.mAddr.ToString("X");
                    command = command.Substring(0, pos) + theHex + remaining.Substring(found.mLabel.Length);
                    pos    += theHex.Length;
                }
                else
                {
                    pos++;
                }
            }

            return(command);
        }
コード例 #2
0
ファイル: PDBData.cs プロジェクト: martinpiper/ACME
        public void parseData(string[] commandLineArgs)
        {
            int    i;
            string line;

            for (i = 1; i < commandLineArgs.Length; i++)
            {
                int localFileIndex = 0;

                // Read the file and parse it line by line.
                using (System.IO.StreamReader file = new System.IO.StreamReader(commandLineArgs[i]))
                {
                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.IndexOf("INCLUDES:") == 0)
                        {
                            int lines = int.Parse(line.Substring(9));
                            mSourceIncludes.Clear();
                            mSourceIncludes.Add(".\\");
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                mSourceIncludes.Add(line);
                            }
                        }
                        else if (line.IndexOf("FILES:") == 0)
                        {
                            localFileIndex = mSourceFileNamesLength;
                            int lines = int.Parse(line.Substring(6));
                            mSourceFileNamesLength += lines;
                            if (mSourceFileNames != null)
                            {
                                // Copy old into new
                                string[] tempNames = new string[mSourceFileNamesLength];
                                int      j;
                                for (j = 0; j < localFileIndex; j++)
                                {
                                    tempNames[j] = mSourceFileNames[j];
                                }
                                mSourceFileNames = tempNames;
                            }
                            else
                            {
                                mSourceFileNames = new string[mSourceFileNamesLength];
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();

                                Char[]   separator = { ':' };
                                string[] tokens    = line.Split(separator, 2);
                                mSourceFileNames[localFileIndex + int.Parse(tokens[0])] = tokens[1];
                            }
                        }
                        else if (line.IndexOf("ADDRS:") == 0)
                        {
                            int lines    = int.Parse(line.Substring(6));
                            int baseZone = 0;
                            if (mLabelInfoByZone.Count > 0)
                            {
                                baseZone = mLabelInfoByZone.Keys.Max();
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                string[] tokens   = line.Split(':');
                                AddrInfo addrInfo = new AddrInfo();
                                addrInfo.mAddr = int.Parse(tokens[0].Substring(1), NumberStyles.HexNumber);
                                addrInfo.mZone = int.Parse(tokens[1]);
                                if (addrInfo.mZone > 0)
                                {
                                    addrInfo.mZone += baseZone;
                                }
                                addrInfo.mFile = localFileIndex + int.Parse(tokens[2]);
                                addrInfo.mLine = int.Parse(tokens[3]) - 1;  // Files lines are 1 based in the debug file
                                                                            //								mAddrInfoByAddr.Add(addrInfo.mAddr, addrInfo);
                                mAddrInfoByAddr[addrInfo.mAddr] = addrInfo;
                            }
                        }
                        else if (line.IndexOf("LABELS:") == 0)
                        {
                            int lines    = int.Parse(line.Substring(7));
                            int baseZone = 0;
                            if (mLabelInfoByZone.Count > 0)
                            {
                                baseZone = mLabelInfoByZone.Keys.Max() + 1;
                            }
                            while (lines-- > 0)
                            {
                                line = file.ReadLine();
                                string[]  tokens    = line.Split(':');
                                LabelInfo labelInfo = new LabelInfo();
                                labelInfo.mAddr = int.Parse(tokens[0].Substring(1), NumberStyles.HexNumber);
                                labelInfo.mZone = int.Parse(tokens[1]);
                                if (labelInfo.mZone > 0)
                                {
                                    labelInfo.mZone += baseZone;    // Helps to distinguish zones for multiple PDB files
                                }
                                labelInfo.mLabel  = tokens[2];
                                labelInfo.mUsed   = int.Parse(tokens[3]) == 1;
                                labelInfo.mMemory = int.Parse(tokens[4]) == 1;
                                if (labelInfo.mLabel.Equals("APUCode_Start"))
                                {
                                    mAPUCode_Start = labelInfo.mAddr;
                                }
                                mAllLabels.Add(labelInfo);
                                mLabelInfoByAddr.Add(labelInfo.mAddr, labelInfo);
                                mLabelInfoByZone.Add(labelInfo.mZone, labelInfo);
                                mLabelInfoByLabel.Add(labelInfo.mLabel, labelInfo);
                            }
                        }
                    }

                    mAllLabels.Sort((a, b) => b.mLabel.Length.CompareTo(a.mLabel.Length));

                    file.Close();
                }
                int l;
                // Only process new names this iteration
                // Use mSourceIncludes
                for (l = localFileIndex; l < mSourceFileNamesLength; l++)
                {
                    string name = mSourceFileNames[l];
                    try
                    {
                        List <string> aFile   = new List <string>();
                        string        newPath = name;
                        if (!System.IO.File.Exists(newPath))
                        {
                            foreach (string prefix in mSourceIncludes)
                            {
                                string newName = System.IO.Path.Combine(prefix, name);
                                newPath = newName;
                                if (!System.IO.File.Exists(newPath))
                                {
                                    newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), newName);
                                    if (!System.IO.File.Exists(newPath))
                                    {
                                        newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), newName);
                                        if (!System.IO.File.Exists(newPath))
                                        {
                                            newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]), System.IO.Path.GetFileName(newName));
                                            if (!System.IO.File.Exists(newPath))
                                            {
                                                newPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(commandLineArgs[i]) + "..\\", System.IO.Path.GetFileName(newName));
                                            }
                                        }
                                    }
                                }

                                if (System.IO.File.Exists(newPath))
                                {
                                    break;
                                }
                            }
                        }
                        using (System.IO.StreamReader file = new System.IO.StreamReader(newPath))
                        {
                            while ((line = file.ReadLine()) != null)
                            {
                                aFile.Add(line);
                            }
                            file.Close();
                        }
                        mSourceFiles.Add(aFile);
                        mSourceFileNamesFound.Add(newPath);
                    }
                    catch (System.Exception)
                    {
                        mSourceFiles.Add(new List <string>());
                        mSourceFileNamesFound.Add("");
                    }
                }
            }

            int thePrevAddr = -1;

            foreach (KeyValuePair <int, AddrInfo> pair in mAddrInfoByAddr)
            {
                pair.Value.mPrevAddr = thePrevAddr;
                thePrevAddr          = pair.Value.mAddr;
            }
            thePrevAddr = -1;
            foreach (KeyValuePair <int, AddrInfo> pair in mAddrInfoByAddr.Reverse())
            {
                pair.Value.mNextAddr = thePrevAddr;
                thePrevAddr          = pair.Value.mAddr;
            }
        }