Exemplo n.º 1
0
        /// <summary>
        /// Converts a label to displayable form by stripping the uniquification tag (if any),
        /// inserting the non-unique label prefix if appropriate, and appending the optional
        /// annotation character.
        /// </summary>
        /// <remarks>
        /// There's generally two ways to display a label:
        ///  (1) When displaying labels on-screen, we get a label with the uniquification tag,
        ///      and we want to show the non-unique label prefix ('@' or ':') and annotation.
        ///  (2) When generating assembly source, we get a remapped label with no uniquification
        ///      tag, and we don't want to show the prefix or annotation.
        /// For case #2, there's no reason to call here.  (We're currently doing so because
        /// remapping isn't happening yet, but that should change soon.  When that happens, we
        /// should be able to eliminate the showNonUnique arg.)
        /// </remarks>
        /// <param name="label">Base label string.  Has the uniquification tag, but no
        ///   annotation char or non-unique prefix.</param>
        /// <param name="anno">Annotation; may be None.</param>
        /// <param name="showNonUnique">Set true if the returned label should show the
        ///   non-unique label prefix.</param>
        /// <param name="formatter">Format object that holds the non-unique label prefix
        ///   string.</param>
        /// <returns>Formatted label.</returns>
        public static string ConvertLabelForDisplay(string label, LabelAnnotation anno,
                                                    bool showNonUnique, Asm65.Formatter formatter)
        {
            StringBuilder sb = new StringBuilder(label.Length + 2);

            if (label.Length > NON_UNIQUE_LEN &&
                label[label.Length - NON_UNIQUE_LEN] == UNIQUE_TAG_CHAR)
            {
                // showNonUnique may be false if generating assembly code (but by this
                // point the unique tag should be remapped away)
                if (showNonUnique)
                {
                    sb.Append(formatter.NonUniqueLabelPrefix);
                }
                sb.Append(label.Substring(0, label.Length - NON_UNIQUE_LEN));
            }
            else
            {
                sb.Append(label);
            }

            char annoChar = GetLabelAnnoChar(anno);

            if (annoChar != NO_ANNO_CHAR)
            {
                sb.Append(annoChar);
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        private MaterialType GetMaterialType(LabelAnnotation labelAnnotation)
        {
            var desc = labelAnnotation.Description.ToUpper();

            if (desc.Contains("FOOD") || desc.Contains("DISHES"))
            {
                return(MaterialType.BIO);
            }
            if (desc.Contains("GLASS"))
            {
                return(MaterialType.GLASS);
            }
            if (desc.Contains("PAPER"))
            {
                return(MaterialType.PAPER);
            }
            if (desc.Contains("PLASTIC"))
            {
                return(MaterialType.PLASTIC);
            }
            if (desc.Contains("METAL"))
            {
                return(MaterialType.METAL);
            }
            if (desc.Contains("ELECTRONIC"))
            {
                return(MaterialType.ELECTRONIC);
            }

            return(MaterialType.OTHER);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Internal base-object (Symbol) constructor, called by other constructors.
 /// </summary>
 private DefSymbol(string label, int value, Source source, Type type,
                   LabelAnnotation labelAnno)
     : base(label, value, source, type, labelAnno)
 {
     Debug.Assert(source == Source.Platform || source == Source.Project ||
                  source == Source.Variable);
     Debug.Assert(type == Type.ExternalAddr || type == Type.Constant);
     Xrefs = new XrefSet();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor for non-unique labels.
        /// </summary>
        /// <param name="label">Label string.  Syntax assumed valid.</param>
        /// <param name="value">Symbol value.</param>
        /// <param name="labelAnno">Optional annotation.</param>
        /// <param name="uniqueTag">Tag that makes a non-unique label unique, e.g. the
        ///   offset for which a user label has been created.</param>
        public Symbol(string label, int value, LabelAnnotation labelAnno, int uniqueTag)
            : this(label, 0xdead, Source.User, Type.NonUniqueLocalAddr, labelAnno)
        {
            Debug.Assert(uniqueTag >= 0 && uniqueTag < 0x01000000); // fit in 6 hex digits
            Debug.Assert(label.IndexOf(UNIQUE_TAG_CHAR) < 0);       // already extended?

            Value = value;                                          // passed a bogus value to base ctor for assert

            // Add tag to label to make it unique.
            Label = label + UNIQUE_TAG_CHAR + uniqueTag.ToString("x6");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the annotation suffix character, or NO_ANNO_CHAR if nothing appropriate.
        /// </summary>
        private static char GetLabelAnnoChar(LabelAnnotation anno)
        {
            char ch = NO_ANNO_CHAR;

            if (anno == LabelAnnotation.Uncertain)
            {
                ch = UNCERTAIN_CHAR;
            }
            else if (anno == LabelAnnotation.Generated)
            {
                //ch = '\u00a4';   // CURRENCY SIGN '¤'
            }
            return(ch);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Basic constructor.
        /// </summary>
        /// <param name="label">Label string.  Syntax assumed valid.</param>
        /// <param name="value">Symbol value.</param>
        /// <param name="source">User-defined, auto-generated, ?</param>
        /// <param name="type">Type of symbol this is.</param>
        /// <param name="labelAnno">Optional annotation.</param>
        public Symbol(string label, int value, Source source, Type type,
                      LabelAnnotation labelAnno)
        {
            Debug.Assert(Asm65.Label.ValidateLabel(label));
            Debug.Assert(type != Type.NonUniqueLocalAddr || value == 0xdead); // use other ctor
            Label        = label;
            Value        = value;
            SymbolType   = type;
            SymbolSource = source;
            LabelAnno    = labelAnno;

            // Generate SourceTypeString.
            char sc, tc;

            switch (SymbolSource)
            {
            case Source.Auto:               sc = 'A';   break;

            case Source.User:               sc = 'U';   break;

            case Source.AddrPreLabel:       sc = 'R';   break;

            case Source.Platform:           sc = 'P';   break;

            case Source.Project:            sc = 'J';   break;

            case Source.Variable:           sc = 'V';   break;

            default:                        sc = '?';   break;
            }
            switch (SymbolType)
            {
            case Type.NonUniqueLocalAddr:   tc = 'N';   break;

            case Type.LocalOrGlobalAddr:    tc = 'L';   break;

            case Type.GlobalAddr:           tc = 'G';   break;

            case Type.GlobalAddrExport:     tc = 'X';   break;

            case Type.ExternalAddr:         tc = 'E';   break;

            case Type.Constant:             tc = 'C';   break;

            default:                        tc = '?';   break;
            }
            SourceTypeString = "" + sc + tc;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs a detailed validation of a symbol label, breaking out different failure
        /// causes for the benefit of code that reports errors to the user.  The label may
        /// have additional characters, such as annotations, which are trimmed away.  The
        /// trimmed version of the string is returned.
        /// </summary>
        /// <param name="label">Label to examine.</param>
        /// <param name="nonUniquePrefix">For address symbols, the prefix string for
        ///   non-unique labels (e.g. '@' or ':').  May be null if not validating a user
        ///   label.</param>
        /// <param name="isValid">True if the entire label is valid.</param>
        /// <param name="isLenValid">True if the label has a valid length.</param>
        /// <param name="isFirstCharValid">True if the first character is valid.</param>
        /// <param name="hasNonUniquePrefix">True if the first character indicates that this is
        ///   a non-unique label.</param>
        /// <param name="anno">Annotation found, or None if none found.</param>
        /// <returns>Trimmed version of the string, or the original string if an error
        ///   is encountered.</returns>
        public static string TrimAndValidateLabel(string label, string nonUniquePrefix,
                                                  out bool isValid, out bool isLenValid, out bool isFirstCharValid,
                                                  out bool hasNonUniquePrefix, out LabelAnnotation anno)
        {
            anno = LabelAnnotation.None;
            hasNonUniquePrefix = false;

            // Do we have at least one char?
            if (string.IsNullOrEmpty(label))
            {
                isValid = isLenValid = isFirstCharValid = false;
                return(label);
            }

            string trimLabel = label;

            // Check for an annotation char, remove it if found.
            if (trimLabel[trimLabel.Length - 1] == UNCERTAIN_CHAR)
            {
                anno      = LabelAnnotation.Uncertain;
                trimLabel = trimLabel.Substring(0, trimLabel.Length - 1);
            }

            // Check for leading non-unique ident char.
            if (trimLabel.Length > 0 && !string.IsNullOrEmpty(nonUniquePrefix))
            {
                if (trimLabel[0] == nonUniquePrefix[0])
                {
                    hasNonUniquePrefix = true;
                    trimLabel          = trimLabel.Substring(1);
                }
            }

            // Now that we're down to the base string, do the full validation test.  If it
            // passes, we don't need to dig any deeper.
            isValid = Asm65.Label.ValidateLabelDetail(trimLabel, out isLenValid,
                                                      out isFirstCharValid);

            return(trimLabel);
        }
Exemplo n.º 8
0
            public LabelAnnotation[] DetectLabels(params string[] path)
            {
                var type           = Enumerable.Repeat(new string[] { "LABEL_DETECTION" }, path.Length).ToArray();
                var response       = PostRequests(path, type);
                var responseLength = response["responses"].ToArray().Length;

                string[][] descriptions = new string[responseLength][];
                double[][] scores       = new double[responseLength][];
                response["responses"].Select((value, index) => new { value, index })
                .ToList()
                .ForEach(x =>
                {
                    descriptions[x.index] = x.value["labelAnnotations"].Select(y => y["description"].ToString()).ToArray();
                    scores[x.index]       = x.value["labelAnnotations"].Select(y => y["score"].ToObject <double>()).ToArray();
                });
                var labelAnnotations = new LabelAnnotation[responseLength];

                for (var i = 0; i < responseLength; i++)
                {
                    labelAnnotations[i] = new LabelAnnotation(descriptions[i], scores[i]);
                }
                return(labelAnnotations);
            }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor.  General form.
        /// </summary>
        /// <param name="label">Symbol's label.</param>
        /// <param name="value">Symbol's value.</param>
        /// <param name="source">Symbol source (general point of origin).</param>
        /// <param name="type">Symbol type.</param>
        /// <param name="formatSubType">Format descriptor sub-type, so we know how the
        ///   user wants the value to be displayed.</param>
        /// <param name="width">Variable width.</param>
        /// <param name="widthSpecified">True if width was explicitly specified.  If this is
        /// <param name="comment">End-of-line comment.</param>
        /// <param name="direction">I/O direction.</param>
        /// <param name="multiMask">Bit mask to apply before comparisons.</param>
        /// <param name="tag">Symbol tag, used for grouping platform symbols.</param>
        ///   false, the value of the "width" argument is ignored.</param>
        public DefSymbol(string label, int value, Source source, Type type,
                         LabelAnnotation labelAnno, FormatDescriptor.SubType formatSubType,
                         int width, bool widthSpecified, string comment,
                         DirectionFlags direction, MultiAddressMask multiMask, string tag)
            : this(label, value, source, type, labelAnno)
        {
            Debug.Assert(comment != null);
            Debug.Assert(tag != null);

            if (widthSpecified && type == Type.Constant && source != Source.Variable)
            {
                // non-variable constants don't have a width; override arg
                Debug.WriteLine("Overriding constant DefSymbol width");
                widthSpecified = false;
            }
            HasWidth = widthSpecified;
            if (!widthSpecified)
            {
                width = DEFAULT_WIDTH;
            }
            Debug.Assert(width >= MIN_WIDTH && width <= MAX_WIDTH);

            DataDescriptor = FormatDescriptor.Create(width,
                                                     FormatDescriptor.Type.NumericLE, formatSubType);
            Comment = comment;

            Debug.Assert(((int)direction & ~(int)DirectionFlags.ReadWrite) == 0);
            Direction = direction;

            // constants don't have masks
            if (type != Type.Constant)
            {
                MultiMask = multiMask;
            }

            Tag = tag;
        }