comparison libc/utils/HdrGen/PublicAPICommand.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
8 8
9 #include "PublicAPICommand.h" 9 #include "PublicAPICommand.h"
10 10
11 #include "utils/LibcTableGenUtil/APIIndexer.h" 11 #include "utils/LibcTableGenUtil/APIIndexer.h"
12 12
13 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringExtras.h" 14 #include "llvm/ADT/StringExtras.h"
14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/SourceMgr.h" 16 #include "llvm/Support/SourceMgr.h"
16 #include "llvm/TableGen/Record.h" 17 #include "llvm/TableGen/Record.h"
17 18
36 if (L.size() >= shortest_indent) 37 if (L.size() >= shortest_indent)
37 OS << L.drop_front(shortest_indent) << '\n'; 38 OS << L.drop_front(shortest_indent) << '\n';
38 } 39 }
39 } 40 }
40 41
42 static std::string getTypeHdrName(const std::string &Name) {
43 llvm::SmallVector<llvm::StringRef> Parts;
44 llvm::SplitString(llvm::StringRef(Name), Parts);
45 return llvm::join(Parts.begin(), Parts.end(), "_");
46 }
47
41 namespace llvm_libc { 48 namespace llvm_libc {
42 49
43 void writeAPIFromIndex(APIIndexer &G, 50 void writeAPIFromIndex(APIIndexer &G,
44 std::vector<std::string> EntrypointNameList, 51 std::vector<std::string> EntrypointNameList,
45 llvm::raw_ostream &OS) { 52 llvm::raw_ostream &OS) {
52 dedentAndWrite(MacroDef->getValueAsString("Defn"), OS); 59 dedentAndWrite(MacroDef->getValueAsString("Defn"), OS);
53 60
54 OS << '\n'; 61 OS << '\n';
55 } 62 }
56 63
57 for (auto &Pair : G.TypeDeclsMap) { 64 for (auto &TypeName : G.RequiredTypes) {
58 const std::string &Name = Pair.first; 65 if (G.TypeSpecMap.find(TypeName) == G.TypeSpecMap.end())
59 if (G.TypeSpecMap.find(Name) == G.TypeSpecMap.end()) 66 llvm::PrintFatalError(TypeName + " not found in any standard spec.\n");
60 llvm::PrintFatalError(Name + " not found in any standard spec.\n"); 67 OS << "#include <llvm-libc-types/" << getTypeHdrName(TypeName) << ".h>\n";
61
62 llvm::Record *TypeDecl = Pair.second;
63 dedentAndWrite(TypeDecl->getValueAsString("Decl"), OS);
64
65 OS << '\n';
66 } 68 }
69 OS << '\n';
67 70
68 if (G.Enumerations.size() != 0) 71 if (G.Enumerations.size() != 0)
69 OS << "enum {" << '\n'; 72 OS << "enum {" << '\n';
70 for (const auto &Name : G.Enumerations) { 73 for (const auto &Name : G.Enumerations) {
71 if (G.EnumerationSpecMap.find(Name) == G.EnumerationSpecMap.end()) 74 if (G.EnumerationSpecMap.find(Name) == G.EnumerationSpecMap.end())
109 OS << ", "; 112 OS << ", ";
110 } 113 }
111 114
112 OS << ");\n\n"; 115 OS << ");\n\n";
113 } 116 }
117
118 // Make another pass over entrypoints to emit object declarations.
119 for (const auto &Name : EntrypointNameList) {
120 if (G.ObjectSpecMap.find(Name) == G.ObjectSpecMap.end())
121 continue;
122 llvm::Record *ObjectSpec = G.ObjectSpecMap[Name];
123 auto Type = ObjectSpec->getValueAsString("Type");
124 OS << "extern " << Type << " " << Name << ";\n";
125 }
114 OS << "__END_C_DECLS\n"; 126 OS << "__END_C_DECLS\n";
115 } 127 }
116 128
117 void writePublicAPI(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {} 129 void writePublicAPI(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) {}
118 130