Skip to content

Commit

Permalink
[libc] Move the remaining public types to their own type headers.
Browse files Browse the repository at this point in the history
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D117838
  • Loading branch information
Siva Chandra Reddy committed Jan 20, 2022
1 parent fa8bb22 commit 284cd69
Show file tree
Hide file tree
Showing 23 changed files with 378 additions and 78 deletions.
98 changes: 28 additions & 70 deletions libc/config/linux/api.td
Expand Up @@ -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>
}];
}

Expand All @@ -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>
}];
}

Expand Down Expand Up @@ -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>
}];
}

Expand Down Expand Up @@ -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>
}];
}

Expand Down Expand Up @@ -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>
}];
}

Expand Down Expand Up @@ -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>
}];
}

Expand All @@ -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>
}];
}

Expand All @@ -440,6 +397,7 @@ def ThreadsAPI : PublicAPI<"threads.h"> {
CallOnceFuncT,
MtxT,
CndT,
ThrdT,
ThreadStartT,
];

Expand Down
27 changes: 23 additions & 4 deletions libc/include/CMakeLists.txt
Expand Up @@ -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(
Expand All @@ -28,6 +30,7 @@ add_gen_header(
GEN_HDR inttypes.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.imaxdiv_t
)

add_gen_header(
Expand All @@ -54,6 +57,7 @@ add_gen_header(
GEN_HDR string.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.size_t
)

add_gen_header(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
@@ -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)
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/FILE.h
@@ -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__
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/__bsearchcompare_t.h
@@ -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__
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/__call_once_func_t.h
@@ -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__
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/__qsortcompare_t.h
@@ -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__
22 changes: 22 additions & 0 deletions libc/include/llvm-libc-types/__sigaction.h
@@ -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__

0 comments on commit 284cd69

Please sign in to comment.