mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 03:50:29 +00:00
Add chibicc
This program popped up on Hacker News recently. It's the only modern compiler I've ever seen that doesn't have dependencies and is easily modified. So I added all of the missing GNU extensions I like to use which means it might be possible soon to build on non-Linux and have third party not vendor gcc binaries.
This commit is contained in:
parent
e44a0cf6f8
commit
8da931a7f6
298 changed files with 19493 additions and 11950 deletions
|
@ -68,7 +68,7 @@
|
|||
#include "libc/time/time.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
#include "tool/build/lib/address.h"
|
||||
#include "tool/build/lib/breakpoint.h"
|
||||
|
@ -277,8 +277,9 @@ static struct sigaction oldsig[4];
|
|||
static void SetupDraw(void);
|
||||
static void Redraw(void);
|
||||
|
||||
static char *FormatDouble(char *b, double x) {
|
||||
return g_fmt(b, x);
|
||||
static char *FormatDouble(char buf[32], long double x) {
|
||||
g_xfmt_p(buf, &x, 15, 32, 0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int64_t SignExtend(uint64_t x, char b) {
|
||||
|
@ -2463,7 +2464,7 @@ static void HandleBreakpointFlag(const char *s) {
|
|||
PushBreakpoint(&breakpoints, &b);
|
||||
}
|
||||
|
||||
static noreturn void PrintUsage(int rc, FILE *f) {
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "SYNOPSIS\n\n %s%s", program_invocation_name, USAGE);
|
||||
exit(rc);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ TOOL_BUILD_DIRECTDEPS = \
|
|||
LIBC_X \
|
||||
TOOL_BUILD_LIB \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DTOA \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/tinymath/emodl.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
|
||||
#define INT intmax_t
|
||||
|
@ -162,7 +162,7 @@ INT Popcnt(INT x) {
|
|||
char *Repr(struct Value x) {
|
||||
static char buf[64];
|
||||
if (x.t == kFloat) {
|
||||
g_fmt(buf, x.f);
|
||||
g_xfmt_p(buf, &x.f, 16, sizeof(buf), 0);
|
||||
} else {
|
||||
sprintf(buf, "%jd", x.i);
|
||||
}
|
||||
|
@ -256,36 +256,47 @@ void Pushf(FLOAT f) {
|
|||
void OpDrop(void) {
|
||||
Pop();
|
||||
}
|
||||
|
||||
void OpDup(void) {
|
||||
Push(Push(Pop()));
|
||||
}
|
||||
|
||||
void OpExit(void) {
|
||||
exit(Popi());
|
||||
}
|
||||
|
||||
void OpSrand(void) {
|
||||
srand(Popi());
|
||||
}
|
||||
|
||||
void OpEmit(void) {
|
||||
fputwc(Popi(), stdout);
|
||||
}
|
||||
|
||||
void OpCr(void) {
|
||||
Cr(stdout);
|
||||
}
|
||||
|
||||
void OpPrint(void) {
|
||||
printf("%s ", Repr(Pop()));
|
||||
}
|
||||
|
||||
void OpComment(void) {
|
||||
comment = true;
|
||||
}
|
||||
|
||||
void Glue0f(FLOAT fn(void)) {
|
||||
Pushf(fn());
|
||||
}
|
||||
|
||||
void Glue0i(INT fn(void)) {
|
||||
Pushi(fn());
|
||||
}
|
||||
|
||||
void Glue1f(FLOAT fn(FLOAT)) {
|
||||
Pushf(fn(Popf()));
|
||||
}
|
||||
|
||||
void Glue1i(INT fn(INT)) {
|
||||
Pushi(fn(Popi()));
|
||||
}
|
||||
|
@ -562,12 +573,16 @@ void GotoStartOfLine(void) {
|
|||
|
||||
void GotoEndOfLine(void) {
|
||||
}
|
||||
|
||||
void GotoPrevLine(void) {
|
||||
}
|
||||
|
||||
void GotoNextLine(void) {
|
||||
}
|
||||
|
||||
void GotoPrevChar(void) {
|
||||
}
|
||||
|
||||
void GotoNextChar(void) {
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ nan isnormal ! assert
|
|||
0 0 / dup isnan assert signbit assert # is this right?
|
||||
1 0 / dup isinf assert signbit ! assert # is this right?
|
||||
nan nan != assert # is this right?
|
||||
-nan -nan != assert # is this right?
|
||||
# -nan -nan != assert # is this right?
|
||||
inf inf = assert # is this right?
|
||||
-inf -inf = assert # is this right?
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
|
||||
#define USAGE \
|
||||
|
@ -60,7 +60,7 @@ static struct Flags {
|
|||
.H = 255,
|
||||
};
|
||||
|
||||
static noreturn void PrintUsage(int rc, FILE *f) {
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "Usage: %s%s", program_invocation_name, USAGE);
|
||||
exit(rc);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
#include "third_party/stb/stb_image.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
|
@ -69,7 +69,7 @@ static struct Flags {
|
|||
.p = 1,
|
||||
};
|
||||
|
||||
static noreturn void PrintUsage(int rc, FILE *f) {
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "Usage: %s%s", program_invocation_name, USAGE);
|
||||
exit(rc);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ struct Machine {
|
|||
uint8_t *p;
|
||||
} real;
|
||||
uint64_t cr3;
|
||||
uint8_t xmm[16][16] aligned(16);
|
||||
uint8_t xmm[16][16];
|
||||
uint8_t es[8];
|
||||
uint8_t ds[8];
|
||||
uint8_t fs[8];
|
||||
|
@ -165,7 +165,7 @@ struct Machine {
|
|||
uint8_t icache[1024][40];
|
||||
void (*onbinbase)(struct Machine *);
|
||||
void (*onlongbranch)(struct Machine *);
|
||||
} aligned(64);
|
||||
} forcealign(64);
|
||||
|
||||
struct Machine *NewMachine(void) nodiscard;
|
||||
void FreeMachine(struct Machine *);
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
(!IsModeDbg() && __SSE3__ + 0 && \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408)
|
||||
|
||||
typedef int int_v _Vector_size(16) aligned(16);
|
||||
typedef long long_v _Vector_size(16) aligned(16);
|
||||
typedef int int_v _Vector_size(16) forcealign(16);
|
||||
typedef long long_v _Vector_size(16) forcealign(16);
|
||||
|
||||
static float_v Addps(struct Machine *m, float_v x, float_v y) {
|
||||
return x + y;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef float float_v _Vector_size(16) aligned(16);
|
||||
typedef double double_v _Vector_size(16) aligned(16);
|
||||
typedef float float_v _Vector_size(16) forcealign(16);
|
||||
typedef double double_v _Vector_size(16) forcealign(16);
|
||||
|
||||
void OpUnpcklpsd(struct Machine *, uint32_t);
|
||||
void OpUnpckhpsd(struct Machine *, uint32_t);
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void OpUd(struct Machine *, uint32_t) noreturn;
|
||||
void HaltMachine(struct Machine *, int) noreturn;
|
||||
void ThrowDivideError(struct Machine *) noreturn;
|
||||
void ThrowSegmentationFault(struct Machine *, int64_t) noreturn;
|
||||
void ThrowProtectionFault(struct Machine *) noreturn;
|
||||
void OpHlt(struct Machine *, uint32_t) noreturn;
|
||||
void OpUd(struct Machine *, uint32_t) wontreturn;
|
||||
void HaltMachine(struct Machine *, int) wontreturn;
|
||||
void ThrowDivideError(struct Machine *) wontreturn;
|
||||
void ThrowSegmentationFault(struct Machine *, int64_t) wontreturn;
|
||||
void ThrowProtectionFault(struct Machine *) wontreturn;
|
||||
void OpHlt(struct Machine *, uint32_t) wontreturn;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
struct stat st_;
|
||||
size_t extractedsize;
|
||||
|
||||
noreturn void usage(char *argv[], FILE *f, int rc) {
|
||||
wontreturn void usage(char *argv[], FILE *f, int rc) {
|
||||
fprintf(f, "%s: %s [-o %s] [-s %s] %s\n", "Usage", argv[0], "PATH", "SYMBOL",
|
||||
"FILE");
|
||||
exit(rc);
|
||||
|
|
|
@ -210,7 +210,7 @@ bool ShouldSkipSource(const char *src) {
|
|||
return false;
|
||||
}
|
||||
|
||||
noreturn void OnMissingFile(const char *list, const char *src) {
|
||||
wontreturn void OnMissingFile(const char *list, const char *src) {
|
||||
DCHECK_EQ(ENOENT, errno, "%s", src);
|
||||
/*
|
||||
* This code helps GNU Make automatically fix itself when we
|
||||
|
|
|
@ -118,7 +118,7 @@ forceinline pureconst size_t GreatestTwoDivisor(size_t x) {
|
|||
return x & (~x + 1);
|
||||
}
|
||||
|
||||
noreturn void ShowUsage(FILE *f, int rc) {
|
||||
wontreturn void ShowUsage(FILE *f, int rc) {
|
||||
fprintf(f, "Usage: %s RUNITD PROGRAM HOSTNAME[:RUNITDPORT[:SSHPORT]]...\n",
|
||||
program_invocation_name);
|
||||
exit(rc);
|
||||
|
|
|
@ -121,7 +121,7 @@ void OnChildTerminated(int sig) {
|
|||
g_childterm = true;
|
||||
}
|
||||
|
||||
noreturn void ShowUsage(FILE *f, int rc) {
|
||||
wontreturn void ShowUsage(FILE *f, int rc) {
|
||||
fprintf(f, "%s: %s %s\n", "Usage", program_invocation_name,
|
||||
"[-d] [-r] [-l LISTENIP] [-p PORT] [-t TIMEOUTMS]");
|
||||
exit(rc);
|
||||
|
|
|
@ -75,7 +75,7 @@ const char kNoCompressExts[][8] = {".gz", ".xz", ".jpg", ".png",
|
|||
".gif", ".zip", ".bz2", ".mpg",
|
||||
".mp4", ".lz4", ".webp", ".mpeg"};
|
||||
|
||||
noreturn void PrintUsage(int rc, FILE *f) {
|
||||
wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "%s%s%s\n", "Usage: ", program_invocation_name,
|
||||
" [-o FILE] [-s SYMBOL] [-y YOINK] [FILE...]\n");
|
||||
exit(rc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue