Mercurial > hg > CbC > CbC_llvm
diff 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 |
line wrap: on
line diff
--- a/libc/utils/HdrGen/PublicAPICommand.cpp Wed Jul 21 10:27:27 2021 +0900 +++ b/libc/utils/HdrGen/PublicAPICommand.cpp Wed Nov 09 17:45:10 2022 +0900 @@ -10,6 +10,7 @@ #include "utils/LibcTableGenUtil/APIIndexer.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/SourceMgr.h" @@ -38,6 +39,12 @@ } } +static std::string getTypeHdrName(const std::string &Name) { + llvm::SmallVector<llvm::StringRef> Parts; + llvm::SplitString(llvm::StringRef(Name), Parts); + return llvm::join(Parts.begin(), Parts.end(), "_"); +} + namespace llvm_libc { void writeAPIFromIndex(APIIndexer &G, @@ -54,16 +61,12 @@ OS << '\n'; } - for (auto &Pair : G.TypeDeclsMap) { - const std::string &Name = Pair.first; - if (G.TypeSpecMap.find(Name) == G.TypeSpecMap.end()) - llvm::PrintFatalError(Name + " not found in any standard spec.\n"); - - llvm::Record *TypeDecl = Pair.second; - dedentAndWrite(TypeDecl->getValueAsString("Decl"), OS); - - OS << '\n'; + for (auto &TypeName : G.RequiredTypes) { + if (G.TypeSpecMap.find(TypeName) == G.TypeSpecMap.end()) + llvm::PrintFatalError(TypeName + " not found in any standard spec.\n"); + OS << "#include <llvm-libc-types/" << getTypeHdrName(TypeName) << ".h>\n"; } + OS << '\n'; if (G.Enumerations.size() != 0) OS << "enum {" << '\n'; @@ -111,6 +114,15 @@ OS << ");\n\n"; } + + // Make another pass over entrypoints to emit object declarations. + for (const auto &Name : EntrypointNameList) { + if (G.ObjectSpecMap.find(Name) == G.ObjectSpecMap.end()) + continue; + llvm::Record *ObjectSpec = G.ObjectSpecMap[Name]; + auto Type = ObjectSpec->getValueAsString("Type"); + OS << "extern " << Type << " " << Name << ";\n"; + } OS << "__END_C_DECLS\n"; }