Ejemplo n.º 1
0
        public EncodeLine[] PreprocessLines(string[] lines, uint pc)
        {
            ASMProcessEquivalencesResult processEquivalencesResult = ASMEquivalenceHelper.ProcessEquivalences(lines);

            if (processEquivalencesResult.ErrorCode > 0)
            {
                _errorTextBuilder.Append(processEquivalencesResult.ErrorMessage);
            }
            else
            {
                lines = processEquivalencesResult.Lines;
            }

            EncodeLine[] encodeLines = TranslatePseudo(lines, pc, true);

            ASMFindLabelsResult findLabelsResult = ValueHelper.LabelHelper.FindLabels(lines, encodeLines, pc);

            if (findLabelsResult.ErrorCode > 0)
            {
                _errorTextBuilder.Append(findLabelsResult.ErrorMessage);
            }

            encodeLines = TranslatePseudo(lines, pc);

            if (encodeLines == null)
            {
                encodeLines = new List <EncodeLine>().ToArray();
            }

            return(encodeLines);
        }
Ejemplo n.º 2
0
        public static ASMProcessEquivalencesResult ProcessEquivalences(string[] lines)
        {
            ASMProcessEquivalencesResult result = new ASMProcessEquivalencesResult();

            result.ErrorCode = 0;

            StringBuilder errorTextBuilder = new StringBuilder();

            Dictionary <string, string> eqvDict = new Dictionary <string, string>();

            ASMFindEquivalencesResult findEquivalencesResult = FindEquivalences(eqvDict, lines);

            if (findEquivalencesResult != null)
            {
                if (findEquivalencesResult.ErrorCode > 0)
                {
                    result.ErrorCode = 1;
                    errorTextBuilder.Append(findEquivalencesResult.ErrorMessage);
                }
            }

            List <string> newLines = new List <string>();

            foreach (string line in lines)
            {
                string processLine = ASMStringHelper.RemoveLeadingBracketBlock(line);
                processLine = ASMStringHelper.RemoveLeadingSpaces(processLine);
                processLine = ASMStringHelper.RemoveComment(processLine).ToLower();
                string[] parts         = ASMStringHelper.SplitLine(processLine);
                bool     isEquivalence = ((!string.IsNullOrEmpty(parts[0])) && (parts[0].ToLower().Trim() == ".eqv"));

                string newLine = (string)line.Clone();

                if (!isEquivalence)
                {
                    foreach (KeyValuePair <string, string> eqv in eqvDict)
                    {
                        newLine = newLine.Replace(eqv.Key, eqv.Value);
                    }
                }

                newLines.Add(newLine);
            }

            result.ErrorMessage = errorTextBuilder.ToString();
            result.Lines        = newLines.ToArray();

            return(result);
        }
Ejemplo n.º 3
0
        public static ASMProcessEquivalencesResult ProcessEquivalences(string[] lines)
        {
            ASMProcessEquivalencesResult result = new ASMProcessEquivalencesResult();
            result.ErrorCode = 0;

            StringBuilder errorTextBuilder = new StringBuilder();

            Dictionary<string, string> eqvDict = new Dictionary<string, string>();

            ASMFindEquivalencesResult findEquivalencesResult = FindEquivalences(eqvDict, lines);
            if (findEquivalencesResult != null)
            {
                if (findEquivalencesResult.ErrorCode > 0)
                {
                    result.ErrorCode = 1;
                    errorTextBuilder.Append(findEquivalencesResult.ErrorMessage);
                }
            }

            List<string> newLines = new List<string>();
            foreach (string line in lines)
            {
                string processLine = ASMStringHelper.RemoveLeadingBracketBlock(line);
                processLine = ASMStringHelper.RemoveLeadingSpaces(processLine);
                processLine = ASMStringHelper.RemoveComment(processLine).ToLower();
                string[] parts = ASMStringHelper.SplitLine(processLine);
                bool isEquivalence = ((!string.IsNullOrEmpty(parts[0])) && (parts[0].ToLower().Trim() == ".eqv"));

                string newLine = (string)line.Clone();

                if (!isEquivalence)
                {
                    foreach (KeyValuePair<string, string> eqv in eqvDict)
                    {
                        newLine = newLine.Replace(eqv.Key, eqv.Value);
                    }
                }

                newLines.Add(newLine);
            }

            result.ErrorMessage = errorTextBuilder.ToString();
            result.Lines = newLines.ToArray();

            return result;
        }
        public static ASMProcessEquivalencesResult ProcessEquivalences(string[] lines)
        {
            ASMProcessEquivalencesResult result = new ASMProcessEquivalencesResult();

            result.ErrorCode = 0;

            StringBuilder errorTextBuilder = new StringBuilder();

            Dictionary <string, string> eqvMap = new Dictionary <string, string>();

            ASMFindEquivalencesResult findEquivalencesResult = FindEquivalences(eqvMap, lines);

            if (findEquivalencesResult != null)
            {
                if (findEquivalencesResult.ErrorCode > 0)
                {
                    result.ErrorCode = 1;
                    errorTextBuilder.Append(findEquivalencesResult.ErrorMessage);
                }
            }

            List <string> eqvKeys = new List <string>(eqvMap.Keys);

            eqvKeys.Sort((a, b) => a.Length.CompareTo(b.Length));
            eqvKeys.Reverse();

            List <string> newLines = new List <string>();

            foreach (string line in lines)
            {
                string processLine = ASMStringHelper.RemoveLeadingBracketBlock(line);
                processLine = ASMStringHelper.RemoveLeadingSpaces(processLine);
                processLine = ASMStringHelper.RemoveComment(processLine).ToLower();
                string[] parts         = ASMStringHelper.SplitLine(processLine);
                bool     isEquivalence = ((!string.IsNullOrEmpty(parts[0])) && (parts[0].ToLower().Trim() == ".eqv"));

                string newLine = (string)line.Clone();

                if (!isEquivalence)
                {
                    /*
                     * foreach (KeyValuePair<string, string> eqv in eqvDict)
                     * {
                     *  //newLine = newLine.Replace(eqv.Key, eqv.Value);
                     *  newLine = System.Text.RegularExpressions.Regex.Replace(newLine, System.Text.RegularExpressions.Regex.Escape(eqv.Key), eqv.Value.Replace("$", "$$"),
                     *      System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                     * }
                     */

                    foreach (string eqvKey in eqvKeys)
                    {
                        newLine = System.Text.RegularExpressions.Regex.Replace(newLine, System.Text.RegularExpressions.Regex.Escape(eqvKey), eqvMap[eqvKey].Replace("$", "$$"),
                                                                               System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    }
                }

                newLines.Add(newLine);
            }

            result.ErrorMessage = errorTextBuilder.ToString();
            result.Lines        = newLines.ToArray();

            return(result);
        }