1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
include "config/public_api.td"
include "spec/gnu_ext.td"
include "spec/linux.td"
include "spec/llvm_libc_ext.td"
include "spec/posix.td"
include "spec/stdc.td"
def SizeT : TypeDecl<"size_t"> {
let Decl = [{
#define __need_size_t
#include <stddef.h>
}];
}
def SSizeT : TypeDecl<"ssize_t"> {
let Decl = [{
#define __need_ssize_t
#include <__posix-types.h>
}];
}
def StructTm: TypeDecl<"struct tm"> {
let Decl = [{
struct tm {
int tm_sec; // seconds after the minute
int tm_min; // minutes after the hour
int tm_hour; // hours since midnight
int tm_mday; // day of the month
int tm_mon; // months since January
int tm_year; // years since 1900
int tm_wday; // days since Sunday
int tm_yday; // days since January
int tm_isdst; // Daylight Saving Time flag
};
}];
}
def TimeT: TypeDecl<"time_t"> {
let Decl = [{
typedef long time_t;
}];
}
def OffT : TypeDecl<"off_t"> {
let Decl = [{
#define __need_off_t
#include <__posix-types.h>
}];
}
def FILE : TypeDecl<"FILE"> {
let Decl = [{
typedef struct FILE FILE;
}];
}
def AssertMacro : MacroDef<"assert"> {
let Defn = [{
#undef assert
#ifdef NDEBUG
#define assert(e) (void)0
#else
#ifdef __cplusplus
extern "C"
#endif
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *);
#define assert(e) \
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#endif
}];
}
def StaticAssertMacro : MacroDef<"static_assert"> {
let Defn = [{
#ifndef __cplusplus
#undef static_assert
#define static_assert _Static_assert
#endif
}];
}
def NullMacro : MacroDef<"NULL"> {
let Defn = [{
#define __need_NULL
#include <stddef.h>
}];
}
def ErrnoMacro : MacroDef<"errno"> {
let Defn = [{
#ifdef __cplusplus
extern "C"
#endif
int *__errno_location();
#define errno (*__errno_location())
}];
}
def AssertAPI : PublicAPI<"assert.h"> {
let Macros = [
AssertMacro,
StaticAssertMacro,
];
}
def CTypeAPI : PublicAPI<"ctype.h"> {
}
def MathErrHandlingMacro : MacroDef<"math_errhandling"> {
let Defn = [{
#ifndef math_errhandling
#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined __NO_MATH_ERRNO__
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif
#endif // math_errhandling not defined
}];
}
def IsFiniteMacro : MacroDef<"isfinite"> {
let Defn = [{
#define isfinite(x) __builtin_isfinite(x)
}];
}
def IsInfMacro : MacroDef<"isinf"> {
let Defn = [{
#define isinf(x) __builtin_isinf(x)
}];
}
def IsNanMacro : MacroDef<"isnan"> {
let Defn = [{
#define isnan(x) __builtin_isnan(x)
}];
}
def FloatT : TypeDecl<"float_t"> {
let Decl = [{
#define __need_float_t
#include <__llvm-libc-stdc-types.h>
}];
}
def DoubleT : TypeDecl<"double_t"> {
let Decl = [{
#define __need_double_t
#include <__llvm-libc-stdc-types.h>
}];
}
def MathAPI : PublicAPI<"math.h"> {
let Macros = [
SimpleMacroDef<"MATH_ERRNO", "1">,
SimpleMacroDef<"MATH_ERREXCEPT", "2">,
MathErrHandlingMacro,
SimpleMacroDef<"INFINITY", "__builtin_inff()">,
SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,
SimpleMacroDef<"FP_ILOGB0", "(-__INT_MAX__ - 1)">, // INT_MIN
SimpleMacroDef<"FP_ILOGBNAN", "__INT_MAX__">,
IsFiniteMacro,
IsInfMacro,
IsNanMacro,
];
let TypeDeclarations = [
DoubleT,
FloatT,
];
}
def FEnvT : TypeDecl<"fenv_t"> {
let Decl = [{
#ifdef __aarch64__
typedef struct {
unsigned char __control_word[4];
unsigned char __status_word[4];
} fenv_t;
#endif
#ifdef __x86_64__
typedef struct {
unsigned char __x86_status[28];
unsigned char __mxcsr[4];
} fenv_t;
#endif
}];
}
def FExceptT : TypeDecl<"fexcept_t"> {
let Decl = [{
typedef int fexcept_t;
}];
}
def FenvAPI: PublicAPI<"fenv.h"> {
let Macros = [
SimpleMacroDef<"FE_DIVBYZERO", "1">,
SimpleMacroDef<"FE_INEXACT", "2">,
SimpleMacroDef<"FE_INVALID", "4">,
SimpleMacroDef<"FE_OVERFLOW", "8">,
SimpleMacroDef<"FE_UNDERFLOW", "16">,
SimpleMacroDef<"FE_ALL_EXCEPT", "(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW)">,
SimpleMacroDef<"FE_DOWNWARD", "1">,
SimpleMacroDef<"FE_TONEAREST", "2">,
SimpleMacroDef<"FE_TOWARDZERO", "4">,
SimpleMacroDef<"FE_UPWARD", "8">,
];
let TypeDeclarations = [
FEnvT,
FExceptT,
];
}
def StringAPI : PublicAPI<"string.h"> {
let TypeDeclarations = [
SizeT,
];
let Macros = [
NullMacro,
];
}
def StdIOAPI : PublicAPI<"stdio.h"> {
let TypeDeclarations = [
SizeT,
FILE,
];
}
def StdlibAPI : PublicAPI<"stdlib.h"> {
}
def TimeAPI : PublicAPI<"time.h"> {
let TypeDeclarations = [
StructTm,
TimeT,
];
let Functions = [
"asctime",
"asctime_r",
"gmtime",
"gmtime_r",
"mktime",
];
}
def ErrnoAPI : PublicAPI<"errno.h"> {
let Macros = [
ErrnoMacro,
// We largely depend on linux/errno.h to give us the
// various error macro definitions. However, some libc
// implementations have chosen to provide definitions
// for some of the error macros to account for the ones
// missing in linux/errno.h. There is no harm in doing
// the same here if we define the macros only when they
// are not already defined.
MacroDefineIfNot<"ENOTSUP", "EOPNOTSUPP">,
MacroDefineIfNot<"ECANCELED", "125">,
MacroDefineIfNot<"EOWNERDEAD", "130">,
MacroDefineIfNot<"ENOTRECOVERABLE", "131">,
MacroDefineIfNot<"ERFKILL", "132">,
MacroDefineIfNot<"EHWPOISON", "133">,
];
}
def SysMManAPI : PublicAPI<"sys/mman.h"> {
let Macros = [
SimpleMacroDef<"PROT_NONE", "0">,
SimpleMacroDef<"PROT_READ", "1">,
SimpleMacroDef<"PROT_WRITE", "2">,
SimpleMacroDef<"PROT_EXEC", "4">,
SimpleMacroDef<"MAP_FIXED", "1">,
SimpleMacroDef<"MAP_PRIVATE", "2">,
SimpleMacroDef<"MAP_SHARED", "4">,
SimpleMacroDef<"MAP_FAILED", "((void*)-1)">,
// TODO: The value of 0x20 is good for x86_64, but has to be extended
// in some manner to accommodate other machine architectures.
SimpleMacroDef<"MAP_ANONYMOUS", "0x20">
// TODO: Add other MAP_* macros used by Linux.
];
let TypeDeclarations = [
SizeT,
OffT,
];
}
def StructSigactionDefn : TypeDecl<"struct sigaction"> {
let Decl = [{
struct __sigaction {
union {
void (*sa_handler)(int);
void (*sa_action)(int, siginfo_t *, void *);
};
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
};
}];
}
def SighandlerTDefn : TypeDecl<"__sighandler_t"> {
let Decl = [{
typedef void(*__sighandler_t)(int);
}];
}
def SignalAPI : PublicAPI<"signal.h"> {
let TypeDeclarations = [
StructSigactionDefn,
SighandlerTDefn,
];
}
def OnceFlag : TypeDecl<"once_flag"> {
let Decl = [{
typedef unsigned int once_flag;
}];
}
def MtxT : TypeDecl<"mtx_t"> {
let Decl = [{
typedef struct {
unsigned char __internal_data[4];
int __mtx_type;
} mtx_t;
}];
}
def ThreadStartT : TypeDecl<"thrd_start_t"> {
let Decl = "typedef int (*thrd_start_t)(void *);";
}
def CallOnceFuncT : TypeDecl<"__call_once_func_t"> {
let Decl = [{
typedef void(*__call_once_func_t)(void);
}];
}
def ThreadsAPI : PublicAPI<"threads.h"> {
let Macros = [
SimpleMacroDef<"ONCE_FLAG_INIT", "0">,
];
let TypeDeclarations = [
OnceFlag,
CallOnceFuncT,
MtxT,
ThreadStartT,
];
let Enumerations = [
"mtx_plain",
"mtx_recursive",
"mtx_timed",
"thrd_timedout",
"thrd_success",
"thrd_busy",
"thrd_error",
"thrd_nomem",
];
}
def UniStdAPI : PublicAPI<"unistd.h"> {
let TypeDeclarations = [
SSizeT,
SizeT,
];
}
|