Skip to content

Commit

Permalink
refactor(lib/cc): Refactor libc organization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurPV committed Jan 19, 2025
1 parent b405265 commit 73b15c2
Show file tree
Hide file tree
Showing 60 changed files with 634 additions and 262 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR)
list(APPEND LILY_LLVM_LIBS "${ZLIB};${ZSTD}")

add_subdirectory(${CMAKE_SOURCE_DIR}/src/core/cc)
add_subdirectory(${CMAKE_SOURCE_DIR}/lib/cc/std/src)

# lily_libyaml
set(LIBYAML_SRC
Expand Down
1 change: 0 additions & 1 deletion GIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ command/lilyc
cc
cc/ci
cc/runtime
cpp
Expand Down
24 changes: 14 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ format:
${CLANG_FORMAT} ./include/core/cc/ci/extensions/*.h
${CLANG_FORMAT} ./include/core/cc/ci/resolver/*.h
${CLANG_FORMAT} ./include/core/cc/diagnostic/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/call_main/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/call_main/linux/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/sys/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/sys/table/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/sys/table/linux/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/syscall/*.h
${CLANG_FORMAT} ./include/core/cc/runtime/syscall/linux/*.h
${CLANG_FORMAT} ./include/core/cpp/diagnostic/*.h
${CLANG_FORMAT} ./include/core/lily/*.h
${CLANG_FORMAT} ./include/core/lily/parser/ast/*.h
Expand Down Expand Up @@ -129,6 +121,19 @@ format:
${CLANG_FORMAT} ./lib/*.h
${CLANG_FORMAT} ./lib/builtin/*.h
${CLANG_FORMAT} ./lib/builtin/*.c
${CLANG_FORMAT} ./lib/cc/std/include/call_main/*.h
${CLANG_FORMAT} ./lib/cc/std/include/call_main/linux/*.h
${CLANG_FORMAT} ./lib/cc/std/include/errno/*.h
${CLANG_FORMAT} ./lib/cc/std/include/sys/*.h
${CLANG_FORMAT} ./lib/cc/std/include/sys/table/linux/*.h
${CLANG_FORMAT} ./lib/cc/std/include/sys/table/*.h
${CLANG_FORMAT} ./lib/cc/std/include/syscall/linux/*.h
${CLANG_FORMAT} ./lib/cc/std/include/syscall/*.h
${CLANG_FORMAT} ./lib/cc/std/include/utils/*.h
${CLANG_FORMAT} ./lib/cc/std/include/*.h
${CLANG_FORMAT} ./lib/cc/std/src/string/*.c
${CLANG_FORMAT} ./lib/cc/std/src/sys/*.c
${CLANG_FORMAT} ./lib/cc/std/src/*.c
${CLANG_FORMAT} ./lib/sys/*.h
${CLANG_FORMAT} ./lib/sys/*.c
${CLANG_FORMAT} ./src/base/*.c
Expand Down Expand Up @@ -160,8 +165,6 @@ format:
${CLANG_FORMAT} ./src/core/cc/ci/extensions/*.c
${CLANG_FORMAT} ./src/core/cc/ci/resolver/*.c
${CLANG_FORMAT} ./src/core/cc/diagnostic/*.c
${CLANG_FORMAT} ./src/core/cc/runtime/*.c
${CLANG_FORMAT} ./src/core/cc/runtime/sys/*.c
${CLANG_FORMAT} ./src/core/cc/*.c
${CLANG_FORMAT} ./src/core/cpp/diagnostic/*.c
${CLANG_FORMAT} ./src/core/lily/parser/ast/*.c
Expand Down Expand Up @@ -222,6 +225,7 @@ format:
${CLANG_FORMAT} ./tests/core/lily/preparser/*.c
${CLANG_FORMAT} ./tests/core/lily/scanner/*.c
${CMAKE_FORMAT} ./CMakeLists.txt
${CMAKE_FORMAT} ./lib/cc/std/src/CMakeLists.txt
${CMAKE_FORMAT} ./src/core/cc/CMakeLists.txt
${CMAKE_FORMAT} ./src/core/cc/ci/CMakeLists.txt

Expand Down
42 changes: 25 additions & 17 deletions lib/cc/std/assert.h → lib/cc/std/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,39 @@
* ISO C99 Standard: 7.2 Diagnostics <assert.h>
*/

#ifndef _CC_ASSERT_H
#define _CC_ASSERT_H
#ifndef _CC_STD_ASSERT_H
#define _CC_STD_ASSERT_H

#include <utils/__attr.h>
#include <utils/__cast.h>
#include <utils/__extern.h>

#include "utils/__attr.h"
#include "utils/__cast.h"
#include "utils/__extern.h"

#undef __ASSERT_VOID_CAST
#undef assert

#define __ASSERT_VOID_CAST(x) __CAST(x, void)

#ifdef NDEBUG
#define assert(ignore) __ASSERT_VOID_CAST(0)
#else
__BEGIN_DECLS

__ATTR(noreturn) extern void __assert_fail(const char *__assertion, const char *__file, unsigned int __line, const char *__function);

__ATTR(noreturn) extern void __assert(const char *__assertion, const char *__file, int __line);


__ATTR(noreturn)
extern void
__assert_fail(const char *__assertion,
const char *__file,
unsigned int __line,
const char *__function);

__ATTR(noreturn)
extern void
__assert(const char *__assertion, const char *__file, int __line);

__END_DECLS

#define assert(expr) \
(expr) ? __ASSERT_VOID_CAST(0) : __assert_fail(#expr, __FILE__, __LINE__, __func__)

#define assert(expr) \
(expr) ? __ASSERT_VOID_CAST(0) \
: __assert_fail(#expr, __FILE__, __LINE__, __func__)
#endif /* NDEBUG */

#endif /* _CC_ASSERT_H */
#endif /* _CC_STD_ASSERT_H */
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
* SOFTWARE.
*/

#ifndef LILY_CORE_CC_RUNTIME_CALL_MAIN_H
#define LILY_CORE_CC_RUNTIME_CALL_MAIN_H
#ifndef _CC_STD_CALL_MAIN_H
#define _CC_STD_CALL_MAIN_H

#include <base/platform.h>
#include <platform.h>

#ifdef LILY_LINUX_OS
#include <core/cc/runtime/call_main/linux.h>
#ifdef _CC_STD_LINUX
#include <call_main/linux.h>
#else
#error "This OS is not yet supported"
#error
#endif

#endif // LILY_CORE_CC_RUNTIME_CALL_MAIN_H
#endif /* _CC_STD_CALL_MAIN_H */
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
* SOFTWARE.
*/

#ifndef LILY_CORE_CC_RUNTIME_SYSCALL_LINUX_H
#define LILY_CORE_CC_RUNTIME_SYSCALL_LINUX_H
#ifndef _CC_STD_CALL_MAIN_LINUX_H
#define _CC_STD_CALL_MAIN_LINUX_H

#include <base/platform.h>
#include <platform.h>

#ifdef LILY_X86_ARCH
#include <core/cc/runtime/syscall/linux/x86.h>
#elifdef LILY_X86_64_ARCH
#include <core/cc/runtime/syscall/linux/x86_64.h>
#if defined(_CC_STD_X86)
#include <call_main/linux/x86.h>
#elif defined(_CC_STD_X86_64)
#include <call_main/linux/x86_64.h>
#else
#error "This arch is not yet supported"
#error
#endif

#endif // LILY_CORE_CC_RUNTIME_SYSCALL_LINUX_H
#endif /* _CC_STD_CALL_MAIN_LINUX_H */
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

#ifndef LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_H
#define LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_H
#ifndef _CC_STD_CALL_MAIN_LINUX_X86_H
#define _CC_STD_CALL_MAIN_LINUX_X86_H

#define call_main(status) \
__asm("mov (%%esp), %%ebx\n" /* Get argc */ \
Expand All @@ -32,6 +32,6 @@
"mov %0, %%eax\n" /* Get the return status of main function */ \
: "=r"(status) \
: \
: "%ebx", "%ecx", "%eax");
: "%ebx", "%ecx");

#endif // LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_H
#endif /* _CC_STD_CALL_MAIN_LINUX_X86_H */
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

#ifndef LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_64_H
#define LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_64_H
#ifndef _CC_STD_CALL_MAIN_LINUX_X86_64_H
#define _CC_STD_CALL_MAIN_LINUX_X86_64_H

#define call_main(status) \
__asm("mov (%%rsp), %%rsi\n" /* Get argc */ \
Expand All @@ -32,6 +32,6 @@
"mov %0, %%eax\n" /* Get the return status of main function */ \
: "=r"(status) \
: \
: "%rsi", "%rdi", "%eax");
: "%rsi", "%rdi");

#endif // LILY_CORE_CC_RUNTIME_CALL_MAIN_LINUX_X86_64_H
#endif /* _CC_STD_CALL_MAIN_LINUX_X86_64_H */
Empty file added lib/cc/std/include/complex.h
Empty file.
50 changes: 32 additions & 18 deletions lib/cc/std/ctype.h → lib/cc/std/include/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,42 @@
* ISO C99 Standard: 7.4 Character handling <ctype.h>
*/

#ifndef _CC_CTYPE_H
#define _CC_CTYPE_H
#ifndef _CC_STD_CTYPE_H
#define _CC_STD_CTYPE_H

#include "utils/__extern.h"
#include <utils/__extern.h>

__BEGIN_DECLS

extern int isalnum(int c);
extern int isalpha(int c);
extern int isblank(int c);
extern int iscntrl(int c);
extern int isdigit(int c);
extern int isgraph(int c);
extern int islower(int c);
extern int isprint(int c);
extern int ispunct(int c);
extern int isspace(int c);
extern int isupper(int c);
extern int isxdigit(int c);
extern int tolower(int c);
extern int toupper(int c);
extern int
isalnum(int c);
extern int
isalpha(int c);
extern int
isblank(int c);
extern int
iscntrl(int c);
extern int
isdigit(int c);
extern int
isgraph(int c);
extern int
islower(int c);
extern int
isprint(int c);
extern int
ispunct(int c);
extern int
isspace(int c);
extern int
isupper(int c);
extern int
isxdigit(int c);
extern int
tolower(int c);
extern int
toupper(int c);

__END_DECLS

#endif /* _CC_CTYPE_H */
#endif /* _CC_STD_CTYPE_H */
18 changes: 12 additions & 6 deletions lib/cc/std/errno.h → lib/cc/std/include/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@
* ISO C99 Standard: 7.5 Errors <errno.h>
*/

#ifndef _CC_ERRNO_H
#define _CC_ERRNO_H
#ifndef _CC_STD_ERRNO_H
#define _CC_STD_ERRNO_H

#undef _ERRNO_H
#define _ERRNO_H

#include <bits/errno.h>
#include <platform.h>
#include <utils/__extern.h>

#include "utils/__extern.h"
#if defined(_CC_STD_LINUX)
#include <errno/linux.h>
#else
#error
#endif /* defined(_CC_STD_LINUX) */

__BEGIN_DECLS

extern int *__errno_location(void);
extern int *
__errno_location(void);

#define errno (*__errno_location())

__END_DECLS

#endif /* _CC_ERRNO_H */
#endif /* _CC_STD_ERRNO_H */
Loading

0 comments on commit 73b15c2

Please sign in to comment.