コード例 #1
0
        public static List <TpmNamedConstant> GetBifieldElements(TpmBitfield bf)
        {
            var elements = new List <TpmNamedConstant>();

            foreach (var b in bf.Elements)
            {
                if (b.StartBit == b.EndBit)
                {
                    AddBitfieldElt(elements, b.TranslatedName, 1 << b.StartBit, b.Comment, b.OldStyleName);
                }
                else // multibit members of a bitfield
                {
                    string typeName = b.Name;
                    if (TpmTypes.Contains(typeName))
                    {
                        // Type typeName defines allowed values for this multi-bit field
                        var e = TpmTypes.Lookup(typeName) as TpmEnum;
                        if (e != null)
                        {
                            foreach (var v in e.Members)
                            {
                                AddBitfieldElt(elements, v.Name, v.NumericValue << b.EndBit, v.Comment);
                            }
                        }
                    }

                    // Multi-bit bitfield 'name' is additionally represented by several enumerators:
                    //   name_BIT_MASK - bit mask selecting all bits of the field
                    //   name_BIT_OFFSET - offset of the field's low order bit
                    //   name_BIT_LENGTH - number of bits in the field
                    string nameBase = b.Name.Contains("_") ? TargetLang.NameToDotNet(b.Name) : b.Name;
                    int    len      = b.StartBit - b.EndBit + 1;
                    var    suff     = TargetLang.DotNet ? new string[] { "BitMask", "BitOffset", "BitLength" }
                                                 : new string[] { "_BIT_MASK", "_BIT_OFFSET", "_BIT_LENGTH" };
                    AddBitfieldElt(elements, nameBase + suff[0], ((1 << len) - 1) << b.EndBit, b.Comment, null, true);
                    AddBitfieldElt(elements, nameBase + suff[1], b.EndBit, null, null, true);
                    AddBitfieldElt(elements, nameBase + suff[2], len, null, null, true);
                    if (TargetLang.DotNet && bf.Name == "LocalityAttr")
                    {
                        // For backward compatibility
                        for (int i = 0; i < len; ++i)
                        {
                            AddBitfieldElt(elements, $"{nameBase}Bit{i}", 1 << (b.EndBit + i), "", null, true);
                        }
                    }
                } // multibit members of a bitfield
            }
            return(elements);
        }
コード例 #2
0
 void GenBitfield(TpmBitfield bf)
 {
     GenEnum(bf, GetBifieldElements(bf));
 }
コード例 #3
0
 void GenBitfield(TpmBitfield bf)
 {
     GenEnum(bf, GetBifieldElements(bf), bf.GetSize());
 }