mirror of https://github.com/flysand7/ciabatta.git
I have no idea but something for linux
This commit is contained in:
parent
328e9f6c35
commit
d70de47c01
|
@ -1,4 +1,5 @@
|
||||||
bin
|
bin
|
||||||
|
a.out
|
||||||
*.exe
|
*.exe
|
||||||
*.lib
|
*.lib
|
||||||
*.obj
|
*.obj
|
||||||
|
|
23
Makefile
23
Makefile
|
@ -19,35 +19,44 @@ endif
|
||||||
# If we're compiling under windows we'll link to these libraries
|
# If we're compiling under windows we'll link to these libraries
|
||||||
ifeq ($(PLATFORM),win)
|
ifeq ($(PLATFORM),win)
|
||||||
LIBS := -lDbghelp -lkernel32 -luser32 -lshell32
|
LIBS := -lDbghelp -lkernel32 -luser32 -lshell32
|
||||||
|
MKDIR_P_FLAG :=
|
||||||
|
NUL_FILE := NUL
|
||||||
|
else
|
||||||
|
LIBS := -lrt -lpthread -ldl
|
||||||
|
MKDIR_P_FLAG := '-p'
|
||||||
|
NUL_FILE := /dev/null
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
ifeq ($(CC), clang)
|
ifeq ($(CC), clang)
|
||||||
CFLAGS=$(GNUFLAGS) -Werror -Wall -msse2 $(IFLAGS)
|
CFLAGS=$(GNUFLAGS) -Wall -msse2 -mfma $(IFLAGS)
|
||||||
else
|
else
|
||||||
echo BAD CC
|
echo BAD CC
|
||||||
exit 1
|
exit 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Figure out what we want to compile at the end
|
# Figure out what we want to compile at the end
|
||||||
SRC_FILES := $(wildcard $(SRC_DIR)/code/*.c) $(wildcard $(SRC_DIR)/$(PLATFORM)/*.c)
|
SRC_FILES := \
|
||||||
|
$(wildcard $(SRC_DIR)/code/*.c) \
|
||||||
|
$(wildcard $(SRC_DIR)/code/**/*.c) \
|
||||||
|
$(wildcard $(SRC_DIR)/$(PLATFORM)/*.c) \
|
||||||
|
$(wildcard $(SRC_DIR)/$(PLATFORM)/**/*.c)
|
||||||
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.obj,$(SRC_FILES))
|
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.obj,$(SRC_FILES))
|
||||||
|
|
||||||
$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.c
|
$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.c
|
||||||
|
@-mkdir $(MKDIR_P_FLAG) "$(dir $@)" 2> $(NUL_FILE)
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
ciabatta.lib: $(OBJ_FILES)
|
ciabatta.lib: $(OBJ_FILES)
|
||||||
llvm-ar rc $@ $^
|
llvm-ar rc $@ $^
|
||||||
|
|
||||||
test: ciabatta.lib
|
test: ciabatta.lib
|
||||||
clang test/test_$(test).c ciabatta.lib -std=c11 $(LIBS) -nostdlib -Iinc
|
clang -g test/test_$(test).c ciabatta.lib -std=c11 $(LIBS) -nostdlib -Iinc
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rd/s/q bin || true
|
rd/s/q bin || true
|
||||||
rm -Rf bin || true
|
rm -Rf bin || true
|
||||||
mkdir bin
|
rm -f ciabatta.lib || true
|
||||||
mkdir bin/code
|
del ciabatta.lib || true
|
||||||
mkdir bin/win
|
|
||||||
mkdir bin/linux
|
|
||||||
|
|
||||||
.PHONY: ciabatta.lib test
|
.PHONY: ciabatta.lib test
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <fenv.h>
|
#include <fenv.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
static double LN2 = 0.693147180559945309417232121458176;
|
static double LN2 = 0.693147180559945309417232121458176;
|
||||||
static double HALF_PI = 1.570796326794896619231321691639751;
|
static double HALF_PI = 1.570796326794896619231321691639751;
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
#define asdouble(x) ((union {double f; uint64_t i;}){x}).f
|
#define asdouble(x) ((union {double f; uint64_t i;}){x}).f
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define just_do_it(t) __attribute__((unused)) volatile t
|
#define just_do_it(v) do{__attribute__((unused)) volatile double t = v;}while(0)
|
||||||
#else
|
#else
|
||||||
#define just_do_it(t) volatile t
|
#define just_do_it(v) do{volatile double t = v;}while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double nearbyint(double x) {
|
double nearbyint(double x) {
|
||||||
|
@ -53,9 +53,9 @@ double nextafter(double x, double y) {
|
||||||
}
|
}
|
||||||
e = ux.i >> 52 & 0x7ff;
|
e = ux.i >> 52 & 0x7ff;
|
||||||
/* raise overflow if ux.f is infinite and x is finite */
|
/* raise overflow if ux.f is infinite and x is finite */
|
||||||
if (e == 0x7ff) just_do_it(float) _x = x+x;
|
if (e == 0x7ff) just_do_it(x+x);
|
||||||
/* raise underflow if ux.f is subnormal or zero */
|
/* raise underflow if ux.f is subnormal or zero */
|
||||||
if (e == 0) just_do_it(float) _x = x*x + ux.f*ux.f;
|
if (e == 0) just_do_it(x*x + ux.f*ux.f);
|
||||||
return ux.f;
|
return ux.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ float nextafterf(float x, float y) {
|
||||||
}
|
}
|
||||||
e = ux.i & 0x7f800000;
|
e = ux.i & 0x7f800000;
|
||||||
/* raise overflow if ux.f is infinite and x is finite */
|
/* raise overflow if ux.f is infinite and x is finite */
|
||||||
if (e == 0x7f800000) just_do_it(float) _x = x+x;
|
if (e == 0x7f800000) just_do_it(x+x);
|
||||||
/* raise underflow if ux.f is subnormal or zero */
|
/* raise underflow if ux.f is subnormal or zero */
|
||||||
if (e == 0) just_do_it(float) _x = x*x + ux.f*ux.f;
|
if (e == 0) just_do_it(x*x + ux.f*ux.f);
|
||||||
return ux.f;
|
return ux.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +109,9 @@ float nexttowardf(float x, long double y) {
|
||||||
}
|
}
|
||||||
e = ux.i & 0x7f800000;
|
e = ux.i & 0x7f800000;
|
||||||
/* raise overflow if ux.f is infinite and x is finite */
|
/* raise overflow if ux.f is infinite and x is finite */
|
||||||
if (e == 0x7f800000) just_do_it(float) _x = x+x;
|
if (e == 0x7f800000) just_do_it(x+x);
|
||||||
/* raise underflow if ux.f is subnormal or zero */
|
/* raise underflow if ux.f is subnormal or zero */
|
||||||
if (e == 0) just_do_it(float) _x = x*x + ux.f*ux.f;
|
if (e == 0) just_do_it(x*x + ux.f*ux.f);
|
||||||
return ux.f;
|
return ux.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ double round(double x) {
|
||||||
if (u.i >> 63) x = -x;
|
if (u.i >> 63) x = -x;
|
||||||
if (e < 0x3ff-1) {
|
if (e < 0x3ff-1) {
|
||||||
/* raise inexact if x!=0 */
|
/* raise inexact if x!=0 */
|
||||||
just_do_it(float) _x = x + toint;
|
just_do_it(x + toint);
|
||||||
return 0*u.f;
|
return 0*u.f;
|
||||||
}
|
}
|
||||||
y = x + toint - toint - x;
|
y = x + toint - toint - x;
|
||||||
|
@ -229,7 +229,7 @@ float roundf(float x) {
|
||||||
if (e >= 0x7f+23) return x;
|
if (e >= 0x7f+23) return x;
|
||||||
if (u.i >> 31) x = -x;
|
if (u.i >> 31) x = -x;
|
||||||
if (e < 0x7f-1) {
|
if (e < 0x7f-1) {
|
||||||
just_do_it(float) _x = x + toint;
|
just_do_it(x + toint);
|
||||||
return 0*u.f;
|
return 0*u.f;
|
||||||
}
|
}
|
||||||
y = x + toint - toint - x;
|
y = x + toint - toint - x;
|
||||||
|
@ -283,7 +283,7 @@ double ceil(double x) {
|
||||||
y = x + toint - toint - x;
|
y = x + toint - toint - x;
|
||||||
/* special case because of non-nearest rounding modes */
|
/* special case because of non-nearest rounding modes */
|
||||||
if (e <= 0x3ff-1) {
|
if (e <= 0x3ff-1) {
|
||||||
just_do_it(double) _x = y;
|
just_do_it(y);
|
||||||
return u.i >> 63 ? -0.0 : 1;
|
return u.i >> 63 ? -0.0 : 1;
|
||||||
}
|
}
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
|
@ -302,12 +302,12 @@ float ceilf(float x) {
|
||||||
m = 0x007fffff >> e;
|
m = 0x007fffff >> e;
|
||||||
if ((u.i & m) == 0)
|
if ((u.i & m) == 0)
|
||||||
return x;
|
return x;
|
||||||
just_do_it(float) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
if (u.i >> 31 == 0)
|
if (u.i >> 31 == 0)
|
||||||
u.i += m;
|
u.i += m;
|
||||||
u.i &= ~m;
|
u.i &= ~m;
|
||||||
} else {
|
} else {
|
||||||
just_do_it(float) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
if (u.i >> 31)
|
if (u.i >> 31)
|
||||||
u.f = -0.0;
|
u.f = -0.0;
|
||||||
else if (u.i << 1)
|
else if (u.i << 1)
|
||||||
|
@ -334,7 +334,7 @@ double floor(double x) {
|
||||||
y = x + toint - toint - x;
|
y = x + toint - toint - x;
|
||||||
/* special case because of non-nearest rounding modes */
|
/* special case because of non-nearest rounding modes */
|
||||||
if (e <= 0x3ff-1) {
|
if (e <= 0x3ff-1) {
|
||||||
just_do_it(double) _x = (y);
|
just_do_it(y);
|
||||||
return u.i >> 63 ? -1 : 0;
|
return u.i >> 63 ? -1 : 0;
|
||||||
}
|
}
|
||||||
if (y > 0)
|
if (y > 0)
|
||||||
|
@ -353,12 +353,12 @@ float floorf(float x) {
|
||||||
m = 0x007fffff >> e;
|
m = 0x007fffff >> e;
|
||||||
if ((u.i & m) == 0)
|
if ((u.i & m) == 0)
|
||||||
return x;
|
return x;
|
||||||
just_do_it(float) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
if (u.i >> 31)
|
if (u.i >> 31)
|
||||||
u.i += m;
|
u.i += m;
|
||||||
u.i &= ~m;
|
u.i &= ~m;
|
||||||
} else {
|
} else {
|
||||||
just_do_it(float) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
if (u.i >> 31 == 0)
|
if (u.i >> 31 == 0)
|
||||||
u.i = 0;
|
u.i = 0;
|
||||||
else if (u.i << 1)
|
else if (u.i << 1)
|
||||||
|
@ -383,7 +383,7 @@ double trunc(double x) {
|
||||||
m = -1ULL >> e;
|
m = -1ULL >> e;
|
||||||
if ((u.i & m) == 0)
|
if ((u.i & m) == 0)
|
||||||
return x;
|
return x;
|
||||||
just_do_it(double) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
u.i &= ~m;
|
u.i &= ~m;
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ float truncf(float x) {
|
||||||
m = -1U >> e;
|
m = -1U >> e;
|
||||||
if ((u.i & m) == 0)
|
if ((u.i & m) == 0)
|
||||||
return x;
|
return x;
|
||||||
just_do_it(float) _x = (x + 0x1p120f);
|
just_do_it(x + 0x1p120f);
|
||||||
u.i &= ~m;
|
u.i &= ~m;
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ static intull strtoi_generic(const char *restrict nptr,
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
value = int_max;
|
value = int_max;
|
||||||
goto finish;
|
goto finish;
|
||||||
finish:
|
finish:;
|
||||||
// If no conversion is performed we return the value of 0 and *endptr
|
// If no conversion is performed we return the value of 0 and *endptr
|
||||||
// is set to the nptr.
|
// is set to the nptr.
|
||||||
bool conv_performed = (digits_read > 0);
|
bool conv_performed = (digits_read > 0);
|
||||||
|
|
|
@ -6,18 +6,18 @@ int mblen(const char *s, size_t n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n) {
|
int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mbstowcs(wchar_t *restrict pwcs, const char *restrict s, size_t n) {
|
size_t mbstowcs(wchar_t *restrict pwcs, const char *restrict s, size_t n) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wctomb(char *s, wchar_t wchar) {
|
int wctomb(char *s, wchar_t wchar) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wcstombs(char *restrict s, const wchar_t *restrict pwcs, size_t n) {
|
size_t wcstombs(char *restrict s, const wchar_t *restrict pwcs, size_t n) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -14,17 +15,23 @@ static void (*atqexit_funcs[ATQEXIT_FUNC_COUNT])(void);
|
||||||
static int atexit_func_count;
|
static int atexit_func_count;
|
||||||
static int atqexit_func_count;
|
static int atqexit_func_count;
|
||||||
|
|
||||||
|
static char **get_command_args(int *argcp);
|
||||||
|
|
||||||
|
// TODO: Instead of using static arrays, allocate this memory dynamically
|
||||||
|
static char cmdline[4096];
|
||||||
|
static char *cmdargs[1024];
|
||||||
extern int main(int argc, char** argv);
|
extern int main(int argc, char** argv);
|
||||||
|
|
||||||
void _start() {
|
|
||||||
|
|
||||||
|
void _start() {
|
||||||
srand(0);
|
srand(0);
|
||||||
setlocale(LC_ALL, "C");
|
setlocale(LC_ALL, "C");
|
||||||
|
|
||||||
int argc = 0;
|
int argc;
|
||||||
char *argv[1] = {NULL};
|
char **argv = get_command_args(&argc);
|
||||||
int code = main(argc, argv);
|
int exit_code = main(argc, argv);
|
||||||
_exit(code);
|
|
||||||
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Noreturn void quick_exit(int status) {
|
_Noreturn void quick_exit(int status) {
|
||||||
|
@ -66,3 +73,18 @@ int at_quick_exit(void (*func)(void)) {
|
||||||
atqexit_funcs[atqexit_func_count++] = func;
|
atqexit_funcs[atqexit_func_count++] = func;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char **get_command_args(int *argcp) {
|
||||||
|
int fd = open("/proc/self/cmdline", O_RDONLY);
|
||||||
|
ssize_t size = read(fd, cmdline, sizeof cmdline);
|
||||||
|
ssize_t i = 0;
|
||||||
|
ssize_t cmd_idx = 0;
|
||||||
|
while(i != size) {
|
||||||
|
cmdargs[cmd_idx] = &cmdline[i];
|
||||||
|
while(cmdline[i] != 0) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return cmdargs;
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include <stdio.h>
|
// #include <stdio.h>
|
||||||
#include <errno.h>
|
// #include <errno.h>
|
||||||
#include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
for (int i = 0; i < argv; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
printf("[%d] = %s\n", i, argv[i]);
|
// printf("[%d] = %s\n", i, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue