-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* libc cleanup * Suggested changes, small alloca tweak * Remove printf include
- Loading branch information
Showing
46 changed files
with
575 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef ALLOCA_H | ||
#define ALLOCA_H | ||
|
||
#include "stddef.h" | ||
|
||
void* alloca(size_t); | ||
#define alloca(size) __builtin_alloca(size) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef ASSERT_H | ||
#define ASSERT_H | ||
|
||
#if !defined(__GNUC__) && !defined(__attribute__) | ||
#define __attribute__(x) | ||
#endif | ||
|
||
// Runtime assertions | ||
|
||
__attribute__((noreturn)) void __assert(const char* assertion, const char* file, int line); | ||
|
||
// assert for matching | ||
#ifndef NDEBUG | ||
# ifndef NON_MATCHING | ||
# define ASSERT(cond, msg, file, line) ((cond) ? ((void)0) : __assert(msg, file, line)) | ||
# else | ||
# define ASSERT(cond, msg, file, line) ((cond) ? ((void)0) : __assert(#cond, __FILE__, __LINE__)) | ||
# endif | ||
#else | ||
# define ASSERT(cond, msg, file, line) ((void)0) | ||
#endif | ||
|
||
// standard assert macro | ||
#ifndef NDEBUG | ||
# define assert(cond) ASSERT(cond, #cond, __FILE__, __LINE__) | ||
#else | ||
# define assert(cond) ((void)0) | ||
#endif | ||
|
||
// Static/compile-time assertions | ||
|
||
#if defined(__GNUC__) || (__STDC_VERSION__ >= 201112L) | ||
# define static_assert(cond, msg) _Static_assert(cond, msg) | ||
#else | ||
# ifndef GLUE | ||
# define GLUE(a, b) a##b | ||
# endif | ||
# ifndef GLUE2 | ||
# define GLUE2(a, b) GLUE(a, b) | ||
# endif | ||
|
||
# define static_assert(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1] | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,57 @@ | ||
#ifndef STDARG_H | ||
#define STDARG_H | ||
|
||
// When building with GCC, use the official vaarg macros to avoid warnings | ||
// and possibly bad codegen. | ||
// When building with GCC, use the official vaarg macros to avoid warnings and possibly bad codegen. | ||
|
||
#ifdef __GNUC__ | ||
#define va_list __builtin_va_list | ||
|
||
#define va_list __builtin_va_list | ||
#define va_start __builtin_va_start | ||
#define va_arg __builtin_va_arg | ||
#define va_end __builtin_va_end | ||
#define va_arg __builtin_va_arg | ||
#define va_end __builtin_va_end | ||
|
||
#else | ||
|
||
#ifndef _VA_LIST_ | ||
# define _VA_LIST_ | ||
typedef char* va_list; | ||
#define _FP 1 | ||
#define _INT 0 | ||
#endif | ||
|
||
#define _INT 0 | ||
#define _FP 1 | ||
#define _STRUCT 2 | ||
|
||
#define _VA_FP_SAVE_AREA 0x10 | ||
#define _VA_ALIGN(p, a) (((u32)(((char*)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) | ||
#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) | ||
|
||
#define __va_stack_arg(list, mode) \ | ||
( \ | ||
((list) = (char*)_VA_ALIGN(list, __builtin_alignof(mode)) + \ | ||
_VA_ALIGN(sizeof(mode), 4)), \ | ||
(((char*)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) | ||
|
||
#define __va_double_arg(list, mode) \ | ||
( \ | ||
(((s32)list & 0x1) /* 1 byte aligned? */ \ | ||
? (list = (char*)((s32)list + 7), (char*)((s32)list - 6 - _VA_FP_SAVE_AREA)) \ | ||
: (((s32)list & 0x2) /* 2 byte aligned? */ \ | ||
? (list = (char*)((s32)list + 10), (char*)((s32)list - 24 - _VA_FP_SAVE_AREA)) \ | ||
: __va_stack_arg(list, mode)))) | ||
|
||
#define va_arg(list, mode) ((mode*)(((__builtin_classof(mode) == _FP && \ | ||
__builtin_alignof(mode) == sizeof(f64)) \ | ||
? __va_double_arg(list, mode) \ | ||
: __va_stack_arg(list, mode))))[-1] | ||
|
||
#define _VA_ALIGN(p, a) (((unsigned int)(((char*)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) | ||
|
||
#define va_start(list, parmN) (list = ((va_list)&parmN + sizeof(parmN))) | ||
|
||
#define __va_stack_arg(list, mode) \ | ||
( \ | ||
((list) = (char*)_VA_ALIGN(list, __builtin_alignof(mode)) + \ | ||
_VA_ALIGN(sizeof(mode), 4)), \ | ||
(((char*)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode))) \ | ||
) | ||
|
||
#define __va_double_arg(list, mode) \ | ||
( \ | ||
(((long)list & 0x1) /* 1 byte aligned? */ \ | ||
? (list = (char*)((long)list + 7), (char*)((long)list - 6 - _VA_FP_SAVE_AREA)) \ | ||
: (((long)list & 0x2) /* 2 byte aligned? */ \ | ||
? (list = (char*)((long)list + 10), (char*)((long)list - 24 - _VA_FP_SAVE_AREA)) \ | ||
: __va_stack_arg(list, mode))) \ | ||
) | ||
|
||
#define va_arg(list, mode) \ | ||
((mode*)(((__builtin_classof(mode) == _FP && \ | ||
__builtin_alignof(mode) == sizeof(double)) \ | ||
? __va_double_arg(list, mode) \ | ||
: __va_stack_arg(list, mode))))[-1] | ||
|
||
/* No cleanup processing is required for the end of a varargs list: */ | ||
#define va_end(__list) | ||
|
||
#endif | ||
#endif /* __GNUC__ */ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.