[libc-commits] [libc] [libc][RFC] add support for function level attributes (PR #79891)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Jan 30 08:48:53 PST 2024


================
@@ -87,6 +89,94 @@ void writeAPIFromIndex(APIIndexer &G,
   if (G.Enumerations.size() != 0)
     OS << "};\n\n";
 
+  // declare macros for attributes
+  llvm::DenseMap<llvm::StringRef, llvm::Record *> MacroAttr;
+  for (auto &Name : EntrypointNameList) {
+    if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end()) {
+      continue;
+    }
+    llvm::Record *FunctionSpec = G.FunctionSpecMap[Name];
+    auto Attributes = FunctionSpec->getValueAsListOfDefs("Attributes");
+    for (auto *Attr : Attributes) {
+      MacroAttr[Attr->getValueAsString("Macro")] = Attr;
+    }
+  }
+
+  auto GetStyle = [](llvm::Record *Instance) {
+    auto Style = Instance->getValueAsString("Style");
+    if (Style == "cxx11")
+      return AttributeStyle::Cxx11;
+    if (Style == "gnu")
+      return AttributeStyle::Gnu;
+    return AttributeStyle::Declspec;
+  };
+
+  auto GetNamespace = [](llvm::Record *Instance) {
+    auto Namespace = Instance->getValueAsString("Namespace");
+    // Empty namespace is likely to be most standard-compliant.
+    if (Namespace.empty())
+      return AttributeNamespace::None;
+    // Dispatch clang version before gnu version.
+    if (Namespace == "clang")
+      return AttributeNamespace::Clang;
+    return AttributeNamespace::Gnu;
----------------
nickdesaulniers wrote:

`llvm::StringSwitch`

https://github.com/llvm/llvm-project/pull/79891


More information about the libc-commits mailing list