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 "--ent=") + 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/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td --- a/libc/spec/llvm_libc_ext.td +++ b/libc/spec/llvm_libc_ext.td @@ -13,7 +13,6 @@ >, ] >; - let Headers = [ String, ]; diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -1,4 +1,5 @@ def StdC : StandardSpec<"stdc"> { + ConstType ConstVoidPtr = ConstType; RestrictedPtrType VoidRestrictedPtr = RestrictedPtrType; ConstType ConstVoidRestrictedPtr = ConstType; diff --git a/libc/utils/HdrGen/Command.h b/libc/utils/HdrGen/Command.h --- a/libc/utils/HdrGen/Command.h +++ b/libc/utils/HdrGen/Command.h @@ -45,7 +45,9 @@ virtual ~Command(); virtual void run(llvm::raw_ostream &OS, const ArgVector &Args, - llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + llvm::StringRef StdHeader, + std::vector EntrypointNameList, + llvm::RecordKeeper &Records, const ErrorReporter &Reporter) const = 0; }; 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; + std::vector EntrypointNameList; llvm::StringRef StdHeader; std::unordered_map &ArgMap; @@ -44,9 +45,12 @@ void printError(llvm::StringRef Msg); public: - Generator(const std::string &DefFile, const std::string &Header, + Generator(const std::string &DefFile, + const std::vector EntrypointNamesOption, + const std::string &Header, std::unordered_map &Map) - : HeaderDefFile(DefFile), StdHeader(Header), ArgMap(Map) {} + : HeaderDefFile(DefFile), EntrypointNameList(EntrypointNamesOption), + 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 @@ -105,7 +105,7 @@ Command::ErrorReporter Reporter( llvm::SMLoc::getFromPointer(CommandName.data()), SrcMgr); - Cmd->run(OS, Args, StdHeader, Records, Reporter); + Cmd->run(OS, Args, StdHeader, EntrypointNameList, Records, Reporter); } else if (!Line.startswith(CommentPrefix)) { // There is no comment or command on this line so we just write it as is. OS << P.first << "\n"; diff --git a/libc/utils/HdrGen/IncludeFileCommand.h b/libc/utils/HdrGen/IncludeFileCommand.h --- a/libc/utils/HdrGen/IncludeFileCommand.h +++ b/libc/utils/HdrGen/IncludeFileCommand.h @@ -23,7 +23,9 @@ static const char Name[]; void run(llvm::raw_ostream &OS, const ArgVector &Args, - llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + llvm::StringRef StdHeader, + std::vector EntrypointNameList, + llvm::RecordKeeper &Records, const Command::ErrorReporter &Reporter) const override; }; diff --git a/libc/utils/HdrGen/IncludeFileCommand.cpp b/libc/utils/HdrGen/IncludeFileCommand.cpp --- a/libc/utils/HdrGen/IncludeFileCommand.cpp +++ b/libc/utils/HdrGen/IncludeFileCommand.cpp @@ -19,6 +19,7 @@ void IncludeFileCommand::run(llvm::raw_ostream &OS, const ArgVector &Args, llvm::StringRef StdHeader, + std::vector EntrypointNameList, llvm::RecordKeeper &Records, const Command::ErrorReporter &Reporter) const { if (Args.size() != 1) { 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,9 @@ "header", llvm::cl::desc("The standard header file which is to be generated."), llvm::cl::value_desc("
")); +llvm::cl::list + EntrypointNamesOption("ent", llvm::cl::desc(""), + llvm::cl::OneOrMore); llvm::cl::list ReplacementValues( "args", llvm::cl::desc("Command separated = pairs."), llvm::cl::value_desc("[,name=value]")); @@ -42,7 +45,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 @@ -30,7 +30,9 @@ static const char Name[]; void run(llvm::raw_ostream &OS, const ArgVector &Args, - llvm::StringRef StdHeader, llvm::RecordKeeper &Records, + llvm::StringRef StdHeader, + std::vector EntrypointNameList, + 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,13 @@ 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; // this used to be an error, but isn't anymore because + // we're getting the full function list from entrypoints.txt + // and then using this as a filter to get only + // the appropriate ones for each header file. + } llvm::Record *FunctionSpec = G.FunctionSpecMap[Name]; llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return"); @@ -112,6 +118,7 @@ void PublicAPICommand::run(llvm::raw_ostream &OS, const ArgVector &Args, llvm::StringRef StdHeader, + std::vector EntrypointNameList, llvm::RecordKeeper &Records, const Command::ErrorReporter &Reporter) const { if (Args.size() != 0) { @@ -119,7 +126,7 @@ } APIIndexer G(StdHeader, Records); - writeAPIFromIndex(G, OS); + writeAPIFromIndex(G, EntrypointNameList, OS); } } // namespace llvm_libc