[libc] Move the remaining public types to their own type headers.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117838
This commit is contained in:
Siva Chandra Reddy 2022-01-20 08:11:54 +00:00
parent fa8bb22466
commit 284cd693f1
23 changed files with 378 additions and 78 deletions

View file

@ -24,23 +24,13 @@ def SSizeT : TypeDecl<"ssize_t"> {
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
};
#include <llvm-libc-types/tm.h>
}];
}
def TimeT: TypeDecl<"time_t"> {
let Decl = [{
typedef long time_t;
let Decl = [{
#include <llvm-libc-types/time_t.h>
}];
}
@ -52,7 +42,7 @@ def OffT : TypeDecl<"off_t"> {
def FILE : TypeDecl<"FILE"> {
let Decl = [{
typedef struct FILE FILE;
#include <llvm-libc-types/FILE.h>
}];
}
@ -114,10 +104,7 @@ def CTypeAPI : PublicAPI<"ctype.h"> {
def IMaxDivT : TypeDecl<"imaxdiv_t"> {
let Decl = [{
typedef struct {
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
#include <llvm-libc-types/imaxdiv_t.h>
}];
}
@ -195,24 +182,13 @@ def MathAPI : PublicAPI<"math.h"> {
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
#include <llvm-libc-types/fenv_t.h>
}];
}
def FExceptT : TypeDecl<"fexcept_t"> {
let Decl = [{
typedef int fexcept_t;
#include <llvm-libc-types/fexcept_t.h>
}];
}
@ -257,40 +233,31 @@ def StdIOAPI : PublicAPI<"stdio.h"> {
def DivT : TypeDecl<"div_t"> {
let Decl = [{
typedef struct {
int quot;
int rem;
} div_t;
#include <llvm-libc-types/div_t.h>
}];
}
def LDivT : TypeDecl<"ldiv_t"> {
let Decl = [{
typedef struct {
long quot;
long rem;
} ldiv_t;
#include <llvm-libc-types/ldiv_t.h>
}];
}
def LLDivT : TypeDecl<"lldiv_t"> {
let Decl = [{
typedef struct {
long long quot;
long long rem;
} lldiv_t;
#include <llvm-libc-types/lldiv_t.h>
}];
}
def BSearchCompareTDefn : TypeDecl<"__bsearchcompare_t"> {
let Decl = [{
typedef int(*__bsearchcompare_t)(const void *, const void *);
#include <llvm-libc-types/__bsearchcompare_t.h>
}];
}
def QSortCompareTDefn : TypeDecl<"__qsortcompare_t"> {
let Decl = [{
typedef int(*__qsortcompare_t)(const void *, const void *);
#include <llvm-libc-types/__qsortcompare_t.h>
}];
}
@ -367,21 +334,13 @@ def SysMManAPI : PublicAPI<"sys/mman.h"> {
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);
};
#include <llvm-libc-types/__sigaction.h>
}];
}
def SighandlerTDefn : TypeDecl<"__sighandler_t"> {
let Decl = [{
typedef void(*__sighandler_t)(int);
#include <llvm-libc-types/__sighandler_t.h>
}];
}
@ -394,39 +353,37 @@ def SignalAPI : PublicAPI<"signal.h"> {
def OnceFlag : TypeDecl<"once_flag"> {
let Decl = [{
typedef unsigned int once_flag;
#include <llvm-libc-types/once_flag.h>
}];
}
def MtxT : TypeDecl<"mtx_t"> {
let Decl = [{
typedef struct {
unsigned char __internal_data[4];
int __mtx_type;
} mtx_t;
#include <llvm-libc-types/mtx_t.h>
}];
}
def CndT : TypeDecl<"cnd_t"> {
let Decl = [{
typedef struct {
void *__qfront;
void *__qback;
struct {
unsigned char __w[4];
int __t;
} __qmtx;
} cnd_t;
#include <llvm-libc-types/cnd_t.h>
}];
}
def ThrdT : TypeDecl<"thrd_t"> {
let Decl = [{
#include <llvm-libc-types/thrd_t.h>
}];
}
def ThreadStartT : TypeDecl<"thrd_start_t"> {
let Decl = "typedef int (*thrd_start_t)(void *);";
let Decl = [{
#include <llvm-libc-types/thrd_start_t.h>
}];
}
def CallOnceFuncT : TypeDecl<"__call_once_func_t"> {
let Decl = [{
typedef void(*__call_once_func_t)(void);
#include <llvm-libc-types/__call_once_func_t.h>
}];
}
@ -440,6 +397,7 @@ def ThreadsAPI : PublicAPI<"threads.h"> {
CallOnceFuncT,
MtxT,
CndT,
ThrdT,
ThreadStartT,
];

View file

@ -20,6 +20,8 @@ add_gen_header(
GEN_HDR fenv.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.fenv_t
.llvm-libc-types.fexcept_t
)
add_gen_header(
@ -28,6 +30,7 @@ add_gen_header(
GEN_HDR inttypes.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.imaxdiv_t
)
add_gen_header(
@ -54,6 +57,7 @@ add_gen_header(
GEN_HDR string.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.size_t
)
add_gen_header(
@ -62,18 +66,22 @@ add_gen_header(
GEN_HDR time.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.time_t
.llvm-libc-types.tm
)
add_gen_header(
threads
DEF_FILE threads.h.def
GEN_HDR threads.h
PARAMS
platform_threads=../config/${LIBC_TARGET_OS}/threads.h.in
DEPENDS
.llvm_libc_common_h
DATA_FILES
../config/${LIBC_TARGET_OS}/threads.h.in
.llvm-libc-types.__call_once_func_t
.llvm-libc-types.cnd_t
.llvm-libc-types.mtx_t
.llvm-libc-types.once_flag
.llvm-libc-types.thrd_start_t
.llvm-libc-types.thrd_t
)
add_gen_header(
@ -94,6 +102,9 @@ add_gen_header(
GEN_HDR signal.h
DATA_FILES
../config/${LIBC_TARGET_OS}/signal.h.in
DEPENDS
.llvm-libc-types.__sigaction
.llvm-libc-types.__sighandler_t
)
add_gen_header(
@ -102,6 +113,8 @@ add_gen_header(
GEN_HDR stdio.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.FILE
.llvm-libc-types.size_t
)
add_gen_header(
@ -110,6 +123,12 @@ add_gen_header(
GEN_HDR stdlib.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.__bsearchcompare_t
.llvm-libc-types.__qsortcompare_t
.llvm-libc-types.div_t
.llvm-libc-types.ldiv_t
.llvm-libc-types.lldiv_t
.llvm-libc-types.size_t
)
add_gen_header(

View file

@ -1,5 +1,24 @@
add_header(__bsearchcompare_t HDR __bsearchcompare_t.h)
add_header(__call_once_func_t HDR __call_once_func_t.h)
add_header(__qsortcompare_t HDR __qsortcompare_t.h)
add_header(__sigaction HDR __sigaction.h)
add_header(__sighandler_t HDR __sighandler_t.h)
add_header(cnd_t HDR cnd_t.h)
add_header(double_t HDR double_t.h)
add_header(div_t HDR div_t.h)
add_header(ldiv_t HDR ldiv_t.h)
add_header(lldiv_t HDR lldiv_t.h)
add_header(FILE HDR FILE.h)
add_header(fenv_t HDR fenv_t.h)
add_header(fexcept_t HDR fexcept_t.h)
add_header(float_t HDR float_t.h)
add_header(imaxdiv_t HDR imaxdiv_t.h)
add_header(mtx_t HDR mtx_t.h)
add_header(off_t HDR off_t.h)
add_header(once_flag HDR once_flag.h)
add_header(size_t HDR size_t.h)
add_header(ssize_t HDR ssize_t.h)
add_header(thrd_start_t HDR thrd_start_t.h)
add_header(thrd_t HDR thrd_t.h)
add_header(time_t HDR time_t.h)
add_header(tm HDR tm.h)

View file

@ -0,0 +1,14 @@
//===-- Definition of the type FILE ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_FILE_H__
#define __LLVM_LIBC_TYPES_FILE_H__
typedef struct FILE FILE;
#endif // __LLVM_LIBC_TYPES_FILE_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of type __bsearchcompare_t -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_BSEARCHCOMPARE_T_H__
#define __LLVM_LIBC_TYPES_BSEARCHCOMPARE_T_H__
typedef int (*__bsearchcompare_t)(const void *, const void *);
#endif // __LLVM_LIBC_TYPES_BSEARCHCOMPARE_T_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of __call_once_func_t type -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_CALL_ONCE_FUNC_T_H__
#define __LLVM_LIBC_TYPES_CALL_ONCE_FUNC_T_H__
typedef void (*__call_once_func_t)(void);
#endif // __LLVM_LIBC_TYPES_CALL_ONCE_FUNC_T_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of type __qsortcompare_t -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_QSORTCOMPARE_T_H__
#define __LLVM_LIBC_TYPES_QSORTCOMPARE_T_H__
typedef int (*__qsortcompare_t)(const void *, const void *);
#endif // __LLVM_LIBC_TYPES_QSORTCOMPARE_T_H__

View file

@ -0,0 +1,22 @@
//===-- Definition of struct __sigaction ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_SIGACTION_H__
#define __LLVM_LIBC_TYPES_SIGACTION_H__
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);
};
#endif // __LLVM_LIBC_TYPES_SIGACTION_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of struct __sighandler_t -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_SIGHANDLER_T_H__
#define __LLVM_LIBC_TYPES_SIGHANDLER_T_H__
typedef void (*__sighandler_t)(int);
#endif // __LLVM_LIBC_TYPES_SIGHANDLER_T_H__

View file

@ -0,0 +1,21 @@
//===-- Definition of cnd_t type ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_CND_T_H__
#define __LLVM_LIBC_TYPES_CND_T_H__
typedef struct {
void *__qfront;
void *__qback;
struct {
unsigned char __w[4];
int __t;
} __qmtx;
} cnd_t;
#endif // __LLVM_LIBC_TYPES_CND_T_H__

View file

@ -0,0 +1,17 @@
//===-- Definition of type div_t ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_DIV_T_H__
#define __LLVM_LIBC_TYPES_DIV_T_H__
typedef struct {
int quot;
int rem;
} div_t;
#endif // __LLVM_LIBC_TYPES_DIV_T_H__

View file

@ -0,0 +1,25 @@
//===-- Definition of type fenv_t -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_FENV_T_H__
#define __LLVM_LIBC_TYPES_FENV_T_H__
#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
#endif // __LLVM_LIBC_TYPES_FENV_T_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of fexcept_t type --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_FEXCEPT_T_H__
#define __LLVM_LIBC_TYPES_FEXCEPT_T_H__
typedef int fexcept_t;
#endif // __LLVM_LIBC_TYPES_FEXCEPT_T_H__

View file

@ -0,0 +1,17 @@
//===-- Definition of type imaxdiv_t --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_IMAXDIV_T_H__
#define __LLVM_LIBC_TYPES_IMAXDIV_T_H__
typedef struct {
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
#endif // __LLVM_LIBC_TYPES_IMAXDIV_T_H__

View file

@ -0,0 +1,17 @@
//===-- Definition of type ldiv_t -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_LDIV_T_H__
#define __LLVM_LIBC_TYPES_LDIV_T_H__
typedef struct {
long quot;
long rem;
} ldiv_t;
#endif // __LLVM_LIBC_TYPES_LDIV_T_H__

View file

@ -0,0 +1,17 @@
//===-- Definition of type lldiv_t ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_LLDIV_T_H__
#define __LLVM_LIBC_TYPES_LLDIV_T_H__
typedef struct {
long long quot;
long long rem;
} lldiv_t;
#endif // __LLVM_LIBC_TYPES_LLDIV_T_H__

View file

@ -0,0 +1,17 @@
//===-- Definition of mtx_t type ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_MTX_T_H__
#define __LLVM_LIBC_TYPES_MTX_T_H__
typedef struct {
unsigned char __internal_data[4];
int __mtx_type;
} mtx_t;
#endif // __LLVM_LIBC_TYPES_MTX_T_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of once_flag type --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_ONCE_FLAG_H__
#define __LLVM_LIBC_TYPES_ONCE_FLAG_H__
typedef unsigned int once_flag;
#endif // __LLVM_LIBC_TYPES_ONCE_FLAg_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of thrd_start_t type -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_THRD_START_T_H__
#define __LLVM_LIBC_TYPES_THRD_START_T_H__
typedef int (*thrd_start_t)(void *);
#endif // __LLVM_LIBC_TYPES_THRD_START_T_H__

View file

@ -1,4 +1,4 @@
//===-- Linux specific definitions of types from threads.h ----------------===//
//===-- Definition of thrd_t type -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -6,7 +6,8 @@
//
//===----------------------------------------------------------------------===//
%%begin()
#ifndef __LLVM_LIBC_TYPES_THRD_T_H__
#define __LLVM_LIBC_TYPES_THRD_T_H__
typedef struct {
unsigned char __clear_tid[4];
@ -15,3 +16,5 @@ typedef struct {
int __stack_size;
int __retval;
} thrd_t;
#endif // __LLVM_LIBC_TYPES_THRD_T_H__

View file

@ -0,0 +1,14 @@
//===-- Definition of the type time_t -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_TIME_T_H__
#define __LLVM_LIBC_TYPES_TIME_T_H__
typedef long time_t;
#endif // __LLVM_LIBC_TYPES_TIME_T_H__

View file

@ -0,0 +1,24 @@
//===-- Definition of struct tm -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef __LLVM_LIBC_TYPES_TM_H__
#define __LLVM_LIBC_TYPES_TM_H__
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
};
#endif // __LLVM_LIBC_TYPES_TM_H__

View file

@ -11,8 +11,6 @@
#include <__llvm-libc-common.h>
%%include_file(${platform_threads})
%%public_api()
#endif // LLVM_LIBC_THREADS_H