diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td index d8a2b8bdc97b..a70eb18dd61b 100644 --- a/libc/spec/llvm_libc_ext.td +++ b/libc/spec/llvm_libc_ext.td @@ -1,20 +1,55 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> { HeaderSpec String = HeaderSpec< "string.h", [], // Macros [], // Types [], // Enumerations [ FunctionSpec< "bzero", RetValSpec, [ArgSpec, ArgSpec] >, ] >; + HeaderSpec Assert = HeaderSpec< + "assert.h", + [], // Macros + [], // Types + [], // Enumerations + [ + FunctionSpec< + "__assert_fail", + RetValSpec, + [ArgSpec, + ArgSpec, + ArgSpec, + ArgSpec,] + + >, + ] + >; + + HeaderSpec Errno = HeaderSpec< + "errno.h", + [], // Macros + [], // Types + [], // Enumerations + [ + FunctionSpec< + "__errno_location", + RetValSpec, + [ArgSpec] + + >, + ] + >; + let Headers = [ String, + Assert, + Errno, ]; } diff --git a/libc/spec/spec.td b/libc/spec/spec.td index bfbeb6a6fe3d..35d51e206b09 100644 --- a/libc/spec/spec.td +++ b/libc/spec/spec.td @@ -1,100 +1,129 @@ class Type {} class NamedType : Type { string Name = name; } class Field { string Name = name; Type FieldType = type; } // Class to describe concrete structs specified by a standard. class Struct : NamedType { list Fields; } class EnumNameValue { string Name = name; string Value = value; } class Enum enumerations> : NamedType { list Enumerations = enumerations; } class PtrType : Type { Type PointeeType = type; } class ConstType : Type { Type UnqualifiedType = type; } class RestrictedPtrType : Type { Type PointeeType = type; } // Builtin types. def VarArgType : Type {} def VoidType : NamedType<"void">; def IntType : NamedType<"int">; def FloatType : NamedType<"float">; def DoubleType : NamedType<"double">; def LongDoubleType : NamedType<"long double">; def CharType : NamedType<"char">; // Common types def VoidPtr : PtrType; def ConstVoidPtr : ConstType; def SizeTType : NamedType<"size_t">; -def FloatPtr : PtrType; def LongDoublePtr : PtrType; // _Noreturn is really not a type, but it is convenient to treat it as a type. def NoReturn : NamedType<"_Noreturn void">; +//types moved from stdc.td +def VoidRestrictedPtr : RestrictedPtrType; +def ConstVoidRestrictedPtr : ConstType; + +def CharPtr : PtrType; +def ConstCharPtr : ConstType; +def CharRestrictedPtr : RestrictedPtrType; +def ConstCharRestrictedPtr : ConstType; + +def OnceFlagType : NamedType<"once_flag">; +def OnceFlagTypePtr : PtrType; +// TODO(sivachandra): Remove this non-standard type when a formal +// way to describe callable types is available. +def CallOnceFuncType : NamedType<"__call_once_func_t">; +def MtxTType : NamedType<"mtx_t">; +def MtxTTypePtr : PtrType; +def ThrdStartTType : NamedType<"thrd_start_t">; +def ThrdTType : NamedType<"thrd_t">; +def ThrdTTypePtr : PtrType; + +def IntPtr : PtrType; +def FloatPtr : PtrType; +def DoublePtr : PtrType; + +def SigHandlerT : NamedType<"__sighandler_t">; + +//added because __assert_fail needs it. +def UnsignedType : NamedType<"unsigned">; + + class Macro { string Name = name; } class EnumeratedNameValue { string Name = name; string Value = value; } class Annotation {} class RetValSpec annotations = []> { Type ReturnType = type; list Annotations = annotations; } class ArgSpec annotations = [], string name = ""> { Type ArgType = type; list Annotations = annotations; string Name = name; } class FunctionSpec args> { string Name = name; RetValSpec Return = return; list Args = args; } class HeaderSpec macros = [], list types = [], list enumerations = [], list functions = []> { string Name = name; list Functions = functions; list Types = types; list Macros = macros; list Enumerations = enumerations; } class StandardSpec { string Name = name; list Headers; } diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 61b3dcb24ef0..7d082d28b0eb 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -1,491 +1,466 @@ def StdC : StandardSpec<"stdc"> { - ConstType ConstVoidPtr = ConstType; - RestrictedPtrType VoidRestrictedPtr = RestrictedPtrType; - ConstType ConstVoidRestrictedPtr = ConstType; - - PtrType CharPtr = PtrType; - ConstType ConstCharPtr = ConstType; - RestrictedPtrType CharRestrictedPtr = RestrictedPtrType; - ConstType ConstCharRestrictedPtr = ConstType; - - NamedType OnceFlagType = NamedType<"once_flag">; - PtrType OnceFlagTypePtr = PtrType; - // TODO(sivachandra): Remove this non-standard type when a formal - // way to describe callable types is available. - NamedType CallOnceFuncType = NamedType<"__call_once_func_t">; - NamedType MtxTType = NamedType<"mtx_t">; - PtrType MtxTTypePtr = PtrType; - NamedType ThrdStartTType = NamedType<"thrd_start_t">; - NamedType ThrdTType = NamedType<"thrd_t">; - PtrType ThrdTTypePtr = PtrType; - - PtrType IntPtr = PtrType; - PtrType FloatPtr = PtrType; - PtrType DoublePtr = PtrType; - - NamedType SigHandlerT = NamedType<"__sighandler_t">; NamedType FILE = NamedType<"FILE">; PtrType FILEPtr = PtrType; RestrictedPtrType FILERestrictedPtr = RestrictedPtrType; HeaderSpec Assert = HeaderSpec< "assert.h", [ Macro<"static_assert">, Macro<"assert">, ], [], // Types [], // Enumerations [] >; HeaderSpec CType = HeaderSpec< "ctype.h", [], // Macros [], // Types [], // Enumerations [ FunctionSpec< "isalnum", RetValSpec, [ArgSpec] >, FunctionSpec< "isalpha", RetValSpec, [ArgSpec] >, FunctionSpec< "isblank", RetValSpec, [ArgSpec] >, FunctionSpec< "iscntrl", RetValSpec, [ArgSpec] >, FunctionSpec< "isdigit", RetValSpec, [ArgSpec] >, FunctionSpec< "isgraph", RetValSpec, [ArgSpec] >, FunctionSpec< "islower", RetValSpec, [ArgSpec] >, FunctionSpec< "isprint", RetValSpec, [ArgSpec] >, FunctionSpec< "ispunct", RetValSpec, [ArgSpec] >, FunctionSpec< "isspace", RetValSpec, [ArgSpec] >, FunctionSpec< "isupper", RetValSpec, [ArgSpec] >, FunctionSpec< "isxdigit", RetValSpec, [ArgSpec] >, FunctionSpec< "tolower", RetValSpec, [ArgSpec] >, FunctionSpec< "toupper", RetValSpec, [ArgSpec] >, ] >; HeaderSpec String = HeaderSpec< "string.h", [ Macro<"NULL">, ], [ SizeTType, ], [], // Enumerations [ FunctionSpec< "memcpy", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "memmove", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "memcmp", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "memchr", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "memset", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "strcpy", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strncpy", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "strcat", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strncat", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "strcmp", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strcoll", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strncmp", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "strxfrm", RetValSpec, [ArgSpec, ArgSpec, ArgSpec] >, FunctionSpec< "strchr", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strcspn", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strpbrk", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strrchr", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strspn", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strstr", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strtok", RetValSpec, [ArgSpec, ArgSpec] >, FunctionSpec< "strerror", RetValSpec, [ArgSpec] >, FunctionSpec< "strlen", RetValSpec, [ArgSpec] >, ] >; HeaderSpec Math = HeaderSpec< "math.h", [ Macro<"MATH_ERRNO">, Macro<"MATH_ERREXCEPT">, Macro<"math_errhandling">, Macro<"INFINITY">, Macro<"NAN">, Macro<"isfinite">, Macro<"isinf">, Macro<"isnan">, ], [ NamedType<"float_t">, NamedType<"double_t">, ], [], // Enumerations [ FunctionSpec<"copysign", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"copysignf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"copysignl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"ceil", RetValSpec, [ArgSpec]>, FunctionSpec<"ceilf", RetValSpec, [ArgSpec]>, FunctionSpec<"ceill", RetValSpec, [ArgSpec]>, FunctionSpec<"fabs", RetValSpec, [ArgSpec]>, FunctionSpec<"fabsf", RetValSpec, [ArgSpec]>, FunctionSpec<"fabsl", RetValSpec, [ArgSpec]>, FunctionSpec<"floor", RetValSpec, [ArgSpec]>, FunctionSpec<"floorf", RetValSpec, [ArgSpec]>, FunctionSpec<"floorl", RetValSpec, [ArgSpec]>, FunctionSpec<"fmin", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fminf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fminl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmax", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"frexp", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"frexpf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"frexpl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"hypotf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"logb", RetValSpec, [ArgSpec]>, FunctionSpec<"logbf", RetValSpec, [ArgSpec]>, FunctionSpec<"logbl", RetValSpec, [ArgSpec]>, FunctionSpec<"modf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"modff", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"modfl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"cosf", RetValSpec, [ArgSpec]>, FunctionSpec<"sinf", RetValSpec, [ArgSpec]>, FunctionSpec<"expf", RetValSpec, [ArgSpec]>, FunctionSpec<"exp2f", RetValSpec, [ArgSpec]>, FunctionSpec<"remainderf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"remainder", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"remainderl", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"remquof", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, FunctionSpec<"remquo", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, FunctionSpec<"remquol", RetValSpec, [ArgSpec, ArgSpec, ArgSpec]>, FunctionSpec<"round", RetValSpec, [ArgSpec]>, FunctionSpec<"roundf", RetValSpec, [ArgSpec]>, FunctionSpec<"roundl", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtl", RetValSpec, [ArgSpec]>, FunctionSpec<"trunc", RetValSpec, [ArgSpec]>, FunctionSpec<"truncf", RetValSpec, [ArgSpec]>, FunctionSpec<"truncl", RetValSpec, [ArgSpec]>, ] >; HeaderSpec StdIO = HeaderSpec< "stdio.h", [], // Macros [ // Types SizeTType, FILE, ], [], // Enumerations [ FunctionSpec< "fwrite", RetValSpec, [ArgSpec, ArgSpec, ArgSpec, ArgSpec] >, ] >; HeaderSpec StdLib = HeaderSpec< "stdlib.h", [], // Macros [], // Types [], // Enumerations [ FunctionSpec<"abort", RetValSpec, [ArgSpec]>, FunctionSpec<"_Exit", RetValSpec, [ArgSpec]>, ] >; HeaderSpec Errno = HeaderSpec< "errno.h", [ Macro<"errno">, Macro<"EDOM">, Macro<"EILSEQ">, Macro<"ERANGE">, ] >; HeaderSpec Signal = HeaderSpec< "signal.h", [ Macro<"SIG_BLOCK">, Macro<"SIG_UNBLOCK">, Macro<"SIG_SETMASK">, Macro<"SIGABRT">, Macro<"SIGFPE">, Macro<"SIGILL">, Macro<"SIGINT">, Macro<"SIGSEGV">, Macro<"SIGTERM"> ], [ SizeTType, SigHandlerT, ], [], // Enumerations [ FunctionSpec<"raise", RetValSpec, [ArgSpec]>, FunctionSpec< "signal", RetValSpec, [ArgSpec, ArgSpec] >, ] >; HeaderSpec Threads = HeaderSpec< "threads.h", [ Macro<"ONCE_FLAG_INIT">, ], [ OnceFlagType, CallOnceFuncType, MtxTType, ThrdStartTType, ThrdTType, ], [ EnumeratedNameValue<"mtx_plain">, EnumeratedNameValue<"mtx_recursive">, EnumeratedNameValue<"mtx_timed">, EnumeratedNameValue<"thrd_timedout">, EnumeratedNameValue<"thrd_success">, EnumeratedNameValue<"thrd_busy">, EnumeratedNameValue<"thrd_error">, EnumeratedNameValue<"thrd_nomem">, ], [ FunctionSpec< "call_once", RetValSpec, [ ArgSpec, ArgSpec, ] >, FunctionSpec< "mtx_init", RetValSpec, [ ArgSpec, ArgSpec, ] >, FunctionSpec< "mtx_lock", RetValSpec, [ ArgSpec, ] >, FunctionSpec< "mtx_unlock", RetValSpec, [ ArgSpec, ] >, FunctionSpec< "thrd_create", RetValSpec, [ ArgSpec, ArgSpec, ArgSpec, ] >, FunctionSpec< "thrd_join", RetValSpec, [ ArgSpec, ArgSpec, ] > ] >; let Headers = [ Assert, CType, Errno, Math, String, StdIO, StdLib, Signal, Threads, ]; }