@@ -66,6 +66,44 @@ namespace dwarf {
6666enum Tag : uint16_t ;
6767}
6868
69+ // / Wrapper structure that holds a language name and its version.
70+ // /
71+ // / Some debug-info formats, particularly DWARF, distniguish between
72+ // / language codes that include the version name and codes that don't.
73+ // / DISourceLanguageName may hold either of these.
74+ // /
75+ class DISourceLanguageName {
76+ // / Language name.
77+ // / If \ref Version is not std::nullopt, then this name
78+ // / is version independent (i.e., doesn't include the language
79+ // / version in its name).
80+ uint16_t Name;
81+
82+ // / Language version. The version scheme is language
83+ // / dependent.
84+ std::optional<uint32_t > Version;
85+
86+ public:
87+ bool hasVersionedName () const { return Version.has_value (); }
88+
89+ // / Returns a versioned or unversioned language name.
90+ uint16_t getName () const { return Name; }
91+
92+ // Transitional API for cases where we do not yet support
93+ // versioned source language names. Use \ref getName instead.
94+ //
95+ // FIXME: remove once all callers of this API account for versioned
96+ // names.
97+ uint16_t getUnversionedName () const {
98+ assert (!hasVersionedName ());
99+ return Name;
100+ }
101+
102+ DISourceLanguageName (uint16_t Lang, uint32_t Version)
103+ : Name(Lang), Version(Version) {};
104+ DISourceLanguageName (uint16_t Lang) : Name(Lang), Version(std::nullopt ) {};
105+ };
106+
69107class DbgVariableRecord ;
70108
71109LLVM_ABI extern cl::opt<bool > EnableFSDiscriminator;
@@ -2003,7 +2041,7 @@ class DICompileUnit : public DIScope {
20032041 LLVM_ABI static const char *nameTableKindString (DebugNameTableKind PK);
20042042
20052043private:
2006- unsigned SourceLanguage;
2044+ DISourceLanguageName SourceLanguage;
20072045 unsigned RuntimeVersion;
20082046 uint64_t DWOId;
20092047 unsigned EmissionKind;
@@ -2013,16 +2051,17 @@ class DICompileUnit : public DIScope {
20132051 bool DebugInfoForProfiling;
20142052 bool RangesBaseAddress;
20152053
2016- DICompileUnit (LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
2017- bool IsOptimized, unsigned RuntimeVersion,
2018- unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
2019- bool DebugInfoForProfiling, unsigned NameTableKind,
2020- bool RangesBaseAddress, ArrayRef<Metadata *> Ops);
2054+ DICompileUnit (LLVMContext &C, StorageType Storage,
2055+ DISourceLanguageName SourceLanguage, bool IsOptimized,
2056+ unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
2057+ bool SplitDebugInlining, bool DebugInfoForProfiling,
2058+ unsigned NameTableKind, bool RangesBaseAddress,
2059+ ArrayRef<Metadata *> Ops);
20212060 ~DICompileUnit () = default ;
20222061
20232062 static DICompileUnit *
2024- getImpl (LLVMContext &Context, unsigned SourceLanguage, DIFile *File ,
2025- StringRef Producer, bool IsOptimized, StringRef Flags,
2063+ getImpl (LLVMContext &Context, DISourceLanguageName SourceLanguage,
2064+ DIFile *File, StringRef Producer, bool IsOptimized, StringRef Flags,
20262065 unsigned RuntimeVersion, StringRef SplitDebugFilename,
20272066 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
20282067 DIScopeArray RetainedTypes,
@@ -2042,8 +2081,8 @@ class DICompileUnit : public DIScope {
20422081 getCanonicalMDString (Context, SDK), Storage, ShouldCreate);
20432082 }
20442083 LLVM_ABI static DICompileUnit *
2045- getImpl (LLVMContext &Context, unsigned SourceLanguage, Metadata *File ,
2046- MDString *Producer, bool IsOptimized, MDString *Flags,
2084+ getImpl (LLVMContext &Context, DISourceLanguageName SourceLanguage,
2085+ Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
20472086 unsigned RuntimeVersion, MDString *SplitDebugFilename,
20482087 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
20492088 Metadata *GlobalVariables, Metadata *ImportedEntities,
@@ -2068,7 +2107,7 @@ class DICompileUnit : public DIScope {
20682107
20692108 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY (
20702109 DICompileUnit,
2071- (unsigned SourceLanguage, DIFile *File, StringRef Producer,
2110+ (DISourceLanguageName SourceLanguage, DIFile *File, StringRef Producer,
20722111 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
20732112 StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
20742113 DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
@@ -2084,7 +2123,7 @@ class DICompileUnit : public DIScope {
20842123 SysRoot, SDK))
20852124 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY (
20862125 DICompileUnit,
2087- (unsigned SourceLanguage, Metadata *File, MDString *Producer,
2126+ (DISourceLanguageName SourceLanguage, Metadata *File, MDString *Producer,
20882127 bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
20892128 MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
20902129 Metadata *RetainedTypes, Metadata *GlobalVariables,
@@ -2099,7 +2138,7 @@ class DICompileUnit : public DIScope {
20992138
21002139 TempDICompileUnit clone () const { return cloneImpl (); }
21012140
2102- unsigned getSourceLanguage () const { return SourceLanguage; }
2141+ DISourceLanguageName getSourceLanguage () const { return SourceLanguage; }
21032142 bool isOptimized () const { return IsOptimized; }
21042143 unsigned getRuntimeVersion () const { return RuntimeVersion; }
21052144 DebugEmissionKind getEmissionKind () const {
0 commit comments