@@ -50,6 +50,45 @@ class CIR_UnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
5050 let isOptional = 1;
5151}
5252
53+ //===----------------------------------------------------------------------===//
54+ // SourceLanguageAttr
55+ //===----------------------------------------------------------------------===//
56+
57+ // TODO: Add cases for other languages that Clang supports.
58+
59+ def CIR_SourceLanguage : CIR_I32EnumAttr<"SourceLanguage", "source language", [
60+ I32EnumAttrCase<"C", 1, "c">,
61+ I32EnumAttrCase<"CXX", 2, "cxx">
62+ ]> {
63+ // The enum attr class is defined in `CIR_SourceLanguageAttr` below,
64+ // so that it can define extra class methods.
65+ let genSpecializedAttr = 0;
66+ }
67+
68+ def CIR_SourceLanguageAttr : CIR_EnumAttr<CIR_SourceLanguage, "lang"> {
69+
70+ let summary = "Module source language";
71+ let description = [{
72+ Represents the source language used to generate the module.
73+
74+ Example:
75+ ```
76+ // Module compiled from C.
77+ module attributes {cir.lang = cir.lang<c>} {}
78+ // Module compiled from C++.
79+ module attributes {cir.lang = cir.lang<cxx>} {}
80+ ```
81+
82+ Module source language attribute name is `cir.lang` is defined by
83+ `getSourceLanguageAttrName` method in CIRDialect class.
84+ }];
85+
86+ let extraClassDeclaration = [{
87+ bool isC() const { return getValue() == SourceLanguage::C; }
88+ bool isCXX() const { return getValue() == SourceLanguage::CXX; }
89+ }];
90+ }
91+
5392//===----------------------------------------------------------------------===//
5493// OptInfoAttr
5594//===----------------------------------------------------------------------===//
0 commit comments