diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -66,9 +66,6 @@ include(LLVMLibCRules) include(LLVMLibCCheckCpuFeatures) -add_subdirectory(include) -add_subdirectory(config) - include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt") include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt") @@ -84,6 +81,8 @@ list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name}) endforeach() +add_subdirectory(include) +add_subdirectory(config) add_subdirectory(src) add_subdirectory(utils) diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake --- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake +++ b/libc/cmake/modules/LLVMLibCHeaderRules.cmake @@ -84,11 +84,15 @@ file(GLOB td_includes ${LIBC_SOURCE_DIR}/spec/*.td) + set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST}) + list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=") + add_custom_command( OUTPUT ${out_file} COMMAND $ -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR} --def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR} - ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td + ${ENTRYPOINT_NAME_LIST_ARG} + ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${in_file} ${fq_data_files} ${td_includes} diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -87,22 +87,6 @@ } def CTypeAPI : PublicAPI<"ctype.h"> { - let Functions = [ - "isalnum", - "isalpha", - "isblank", - "iscntrl", - "isdigit", - "isgraph", - "islower", - "isprint", - "ispunct", - "isspace", - "isupper", - "isxdigit", - "tolower", - "toupper", - ]; } def MathErrHandlingMacro : MacroDef<"math_errhandling"> { @@ -168,88 +152,9 @@ DoubleT, FloatT, ]; - let Functions = [ - "copysign", - "copysignf", - "copysignl", - "ceil", - "ceilf", - "ceill", - "cosf", - "fabs", - "fabsf", - "fabsl", - "floor", - "floorf", - "floorl", - "fmax", - "fmaxf", - "fmaxl", - "fmin", - "fminf", - "fminl", - "frexp", - "frexpf", - "frexpl", - "hypotf", - "logb", - "logbf", - "logbl", - "modf", - "modff", - "modfl", - "expf", - "exp2f", - "remainderf", - "remainder", - "remainderl", - "remquof", - "remquo", - "remquol", - "round", - "roundf", - "roundl", - "sincosf", - "sinf", - "sqrt", - "sqrtf", - "sqrtl", - "trunc", - "truncf", - "truncl", - ]; } def StringAPI : PublicAPI<"string.h"> { - let Functions = [ - "bzero", - "memchr", - "memcmp", - "memcpy", - "memmove", - "memrchr", - "memset", - "strcat", - "strchr", - "strcmp", - "strcoll", - "strcpy", - "strcspn", - "strerror", - "strlen", - "strncat", - "strncmp", - "strncpy", - "strnlen", - "strpbrk", - "strrchr", - "strspn", - "strstr", - "strtok", - "strtok_r", - "strxfrm", - ]; - let TypeDeclarations = [ SizeT, ]; @@ -264,17 +169,9 @@ SizeT, FILE, ]; - - let Functions = [ - "fwrite", - ]; } def StdlibAPI : PublicAPI<"stdlib.h"> { - let Functions = [ - "_Exit", - "abort", - ]; } def ErrnoAPI : PublicAPI<"errno.h"> { @@ -320,11 +217,6 @@ SizeT, OffT, ]; - - let Functions = [ - "mmap", - "munmap", - ]; } def StructSigactionDefn : TypeDecl<"struct sigaction"> { @@ -352,17 +244,6 @@ StructSigactionDefn, SighandlerTDefn, ]; - - let Functions = [ - "raise", - "sigaction", - "sigdelset", - "sigprocmask", - "sigemptyset", - "sigaddset", - "sigfillset", - "signal", - ]; } def OnceFlag : TypeDecl<"once_flag"> { @@ -412,15 +293,6 @@ "thrd_error", "thrd_nomem", ]; - - let Functions = [ - "call_once", - "mtx_init", - "mtx_lock", - "mtx_unlock", - "thrd_create", - "thrd_join", - ]; } def UniStdAPI : PublicAPI<"unistd.h"> { @@ -428,8 +300,4 @@ SSizeT, SizeT, ]; - - let Functions = [ - "write", - ]; } diff --git a/libc/utils/HdrGen/Generator.h b/libc/utils/HdrGen/Generator.h --- a/libc/utils/HdrGen/Generator.h +++ b/libc/utils/HdrGen/Generator.h @@ -31,6 +31,7 @@ class Generator { llvm::StringRef HeaderDefFile; + const std::vector &EntrypointNameList; llvm::StringRef StdHeader; std::unordered_map &ArgMap; @@ -44,9 +45,11 @@ void printError(llvm::StringRef Msg); public: - Generator(const std::string &DefFile, const std::string &Header, + Generator(const std::string &DefFile, const std::vector &EN, + const std::string &Header, std::unordered_map &Map) - : HeaderDefFile(DefFile), StdHeader(Header), ArgMap(Map) {} + : HeaderDefFile(DefFile), EntrypointNameList(EN), StdHeader(Header), + ArgMap(Map) {} void generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records); }; diff --git a/libc/utils/HdrGen/Generator.cpp b/libc/utils/HdrGen/Generator.cpp --- a/libc/utils/HdrGen/Generator.cpp +++ b/libc/utils/HdrGen/Generator.cpp @@ -40,7 +40,7 @@ return IncludeFileCmd.get(); } else if (CommandName == PublicAPICommand::Name) { if (!PublicAPICmd) - PublicAPICmd = std::make_unique(); + PublicAPICmd = std::make_unique(EntrypointNameList); return PublicAPICmd.get(); } else { return nullptr; diff --git a/libc/utils/HdrGen/Main.cpp b/libc/utils/HdrGen/Main.cpp --- a/libc/utils/HdrGen/Main.cpp +++ b/libc/utils/HdrGen/Main.cpp @@ -24,6 +24,11 @@ "header", llvm::cl::desc("The standard header file which is to be generated."), llvm::cl::value_desc("
")); +llvm::cl::list EntrypointNamesOption( + "e", llvm::cl::value_desc(""), + llvm::cl::desc( + "Each --e is one entrypoint (generated from entrypoints.txt)"), + llvm::cl::OneOrMore); llvm::cl::list ReplacementValues( "args", llvm::cl::desc("Command separated = pairs."), llvm::cl::value_desc("[,name=value]")); @@ -42,7 +47,7 @@ bool HeaderGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &Records) { std::unordered_map ArgMap; ParseArgValuePairs(ArgMap); - Generator G(HeaderDefFile, StandardHeader, ArgMap); + Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader, ArgMap); G.generate(OS, Records); return false; diff --git a/libc/utils/HdrGen/PublicAPICommand.h b/libc/utils/HdrGen/PublicAPICommand.h --- a/libc/utils/HdrGen/PublicAPICommand.h +++ b/libc/utils/HdrGen/PublicAPICommand.h @@ -26,9 +26,15 @@ namespace llvm_libc { class PublicAPICommand : public Command { +private: + const std::vector &EntrypointNameList; + public: static const char Name[]; + PublicAPICommand(const std::vector &EntrypointNames) + : EntrypointNameList(EntrypointNames) {} + void run(llvm::raw_ostream &OS, const ArgVector &Args, llvm::StringRef StdHeader, llvm::RecordKeeper &Records, const Command::ErrorReporter &Reporter) const override; diff --git a/libc/utils/HdrGen/PublicAPICommand.cpp b/libc/utils/HdrGen/PublicAPICommand.cpp --- a/libc/utils/HdrGen/PublicAPICommand.cpp +++ b/libc/utils/HdrGen/PublicAPICommand.cpp @@ -40,7 +40,9 @@ namespace llvm_libc { -void writeAPIFromIndex(APIIndexer &G, llvm::raw_ostream &OS) { +void writeAPIFromIndex(APIIndexer &G, + std::vector EntrypointNameList, + llvm::raw_ostream &OS) { for (auto &Pair : G.MacroDefsMap) { const std::string &Name = Pair.first; if (G.MacroSpecMap.find(Name) == G.MacroSpecMap.end()) @@ -83,9 +85,15 @@ OS << "};\n\n"; OS << "__BEGIN_C_DECLS\n\n"; - for (auto &Name : G.Functions) { - if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end()) - llvm::PrintFatalError(Name + " not found in any standard spec.\n"); + for (auto &Name : EntrypointNameList) { + if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end()) { + continue; // Functions that aren't in this header file are skipped as + // opposed to erroring out because the list of functions being + // iterated over is the complete list of functions with + // entrypoints. Thus this is filtering out the functions that + // don't go to this header file, whereas the other, similar + // conditionals above are more of a sanity check. + } llvm::Record *FunctionSpec = G.FunctionSpecMap[Name]; llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return"); @@ -119,7 +127,7 @@ } APIIndexer G(StdHeader, Records); - writeAPIFromIndex(G, OS); + writeAPIFromIndex(G, EntrypointNameList, OS); } } // namespace llvm_libc