1 //===-- A class to index libc API listed in tablegen files ------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H
10 #define LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/TableGen/Record.h"
17 #include <unordered_map>
18 #include <unordered_set>
24 std::optional
<llvm::StringRef
> StdHeader
;
26 // TableGen classes in spec.td.
27 llvm::Record
*NamedTypeClass
;
28 llvm::Record
*PtrTypeClass
;
29 llvm::Record
*RestrictedPtrTypeClass
;
30 llvm::Record
*ConstTypeClass
;
31 llvm::Record
*StructClass
;
32 llvm::Record
*StandardSpecClass
;
33 llvm::Record
*PublicAPIClass
;
35 bool isaNamedType(llvm::Record
*Def
);
36 bool isaStructType(llvm::Record
*Def
);
37 bool isaPtrType(llvm::Record
*Def
);
38 bool isaConstType(llvm::Record
*Def
);
39 bool isaRestrictedPtrType(llvm::Record
*Def
);
40 bool isaStandardSpec(llvm::Record
*Def
);
41 bool isaPublicAPI(llvm::Record
*Def
);
43 void indexStandardSpecDef(llvm::Record
*StandardSpec
);
44 void indexPublicAPIDef(llvm::Record
*PublicAPI
);
45 void index(llvm::RecordKeeper
&Records
);
48 using NameToRecordMapping
= std::unordered_map
<std::string
, llvm::Record
*>;
49 using NameSet
= std::unordered_set
<std::string
>;
51 // This indexes all headers, not just a specified one.
52 explicit APIIndexer(llvm::RecordKeeper
&Records
) : StdHeader(std::nullopt
) {
56 APIIndexer(llvm::StringRef Header
, llvm::RecordKeeper
&Records
)
61 // Mapping from names to records defining them.
62 NameToRecordMapping MacroSpecMap
;
63 NameToRecordMapping TypeSpecMap
;
64 NameToRecordMapping EnumerationSpecMap
;
65 NameToRecordMapping FunctionSpecMap
;
66 NameToRecordMapping MacroDefsMap
;
67 NameToRecordMapping ObjectSpecMap
;
69 std::unordered_map
<std::string
, std::string
> FunctionToHeaderMap
;
70 std::unordered_map
<std::string
, std::string
> ObjectToHeaderMap
;
72 NameSet RequiredTypes
;
77 NameSet PublicHeaders
;
79 std::string
getTypeAsString(llvm::Record
*TypeRecord
);
82 } // namespace llvm_libc
84 #endif // LLVM_LIBC_UTILS_LIBC_TABLE_GEN_UTILS_API_INDEXER_H