mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 10:48: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
|
@ -42,7 +42,7 @@ FLAGS\n\
|
|||
int flags;
|
||||
bool force;
|
||||
|
||||
noreturn void PrintUsage(int rc, FILE *f) {
|
||||
wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f, "%s%s%s", "Usage: ", program_invocation_name, USAGE);
|
||||
exit(rc);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ EXAMPLES_DIRECTDEPS = \
|
|||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_DTOA \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_STB \
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Measure CPU clock mystery constants.
|
||||
|
@ -52,15 +52,18 @@ long double GetSample(void) {
|
|||
|
||||
void MeasureNanosecondsPerAlwaysRunningTimerCycle(void) {
|
||||
int i;
|
||||
long double avg, samp;
|
||||
long double avg, samp, elapsed;
|
||||
start_ = now();
|
||||
for (i = 1, avg = 1.0L; !isdone_; ++i) {
|
||||
samp = GetSample();
|
||||
avg += (samp - avg) / i;
|
||||
dsleep(kInterval);
|
||||
printf("1c = %sns (last=%sns spent=%ss)\n", g_fmt(dtoabuf_[0], (double)avg),
|
||||
g_fmt(dtoabuf_[1], (double)samp),
|
||||
g_fmt(dtoabuf_[2], (double)(now() - start_)));
|
||||
elapsed = now() - start_;
|
||||
g_xfmt_p(dtoabuf_[0], &avg, 15, 32, 0);
|
||||
g_xfmt_p(dtoabuf_[1], &samp, 15, 32, 0);
|
||||
g_xfmt_p(dtoabuf_[2], &elapsed, 15, 32, 0);
|
||||
printf("1c = %sns (last=%sns spent=%ss)\n", dtoabuf_[0], dtoabuf_[1],
|
||||
dtoabuf_[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1774,7 +1774,7 @@ Press enter to continue without sound: ",
|
|||
for (;;) CPU::Op();
|
||||
}
|
||||
|
||||
noreturn void PrintUsage(int rc, FILE* f) {
|
||||
wontreturn void PrintUsage(int rc, FILE* f) {
|
||||
fprintf(f, "%s%s%s", "Usage: ", program_invocation_name, USAGE);
|
||||
exit(rc);
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
|
||||
char dtoabuf_[3][32];
|
||||
|
||||
static long double avg;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
long double t2, t1 = nowl();
|
||||
dsleep(0.3);
|
||||
for (;;) {
|
||||
t2 = nowl();
|
||||
printf("%s %s avg=%s\n", g_fmt(dtoabuf_[0], t2),
|
||||
g_fmt(dtoabuf_[1], t2 - t1), g_fmt(dtoabuf_[2], avg));
|
||||
t1 = t2;
|
||||
dsleep(0.3);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -141,7 +141,7 @@
|
|||
#include "libc/sysv/consts/rlim.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/w.h"
|
||||
#include "third_party/dtoa/dtoa.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "third_party/musl/passwd.h"
|
||||
|
||||
#undef CEOF
|
||||
|
@ -1602,7 +1602,7 @@ static inline void sigclearmask(void) {
|
|||
* just do a longjmp to the exception handler. The type of exception is
|
||||
* stored in the global variable "exception".
|
||||
*/
|
||||
noreturn static void exraise(int e) {
|
||||
wontreturn static void exraise(int e) {
|
||||
if (vforked) _exit(exitstatus);
|
||||
INTOFF;
|
||||
exception = e;
|
||||
|
@ -1617,7 +1617,7 @@ noreturn static void exraise(int e) {
|
|||
* are held using the INTOFF macro. (The test for iflag is just
|
||||
* defensive programming.)
|
||||
*/
|
||||
noreturn static void onint(void) {
|
||||
wontreturn static void onint(void) {
|
||||
intpending = 0;
|
||||
sigclearmask();
|
||||
if (!(rootshell && iflag)) {
|
||||
|
@ -1896,20 +1896,20 @@ printfesque(1) static void sh_warnx(const char *fmt, ...) {
|
|||
* is not NULL then error prints an error message using printf style
|
||||
* formatting. It then raises the error exception.
|
||||
*/
|
||||
noreturn static void exverror(int cond, const char *msg, va_list ap) {
|
||||
wontreturn static void exverror(int cond, const char *msg, va_list ap) {
|
||||
exvwarning(msg, ap);
|
||||
flushall();
|
||||
exraise(cond);
|
||||
}
|
||||
|
||||
noreturn static void exerror(int cond, const char *msg, ...) {
|
||||
wontreturn static void exerror(int cond, const char *msg, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
exverror(cond, msg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
noreturn static void sh_error(const char *msg, ...) {
|
||||
wontreturn static void sh_error(const char *msg, ...) {
|
||||
va_list ap;
|
||||
exitstatus = 2;
|
||||
va_start(ap, msg);
|
||||
|
@ -1917,16 +1917,16 @@ noreturn static void sh_error(const char *msg, ...) {
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
noreturn static void badnum(const char *s) {
|
||||
wontreturn static void badnum(const char *s) {
|
||||
sh_error(illnum, s);
|
||||
}
|
||||
|
||||
noreturn static void synerror(const char *msg) {
|
||||
wontreturn static void synerror(const char *msg) {
|
||||
errlinno = plinno;
|
||||
sh_error("Syntax error: %s", msg);
|
||||
}
|
||||
|
||||
noreturn static void yyerror(const char *s) {
|
||||
wontreturn static void yyerror(const char *s) {
|
||||
sh_error("arithmetic expression: %s: \"%s\"", s, arith_startbuf);
|
||||
}
|
||||
|
||||
|
@ -1935,7 +1935,7 @@ noreturn static void yyerror(const char *s) {
|
|||
* argument is the token that is expected, or -1 if more than one type
|
||||
* of token can occur at this point.
|
||||
*/
|
||||
noreturn static void synexpect(int token) {
|
||||
wontreturn static void synexpect(int token) {
|
||||
char msg[64];
|
||||
if (token >= 0) {
|
||||
fmtstr(msg, 64, "%s unexpected (expecting %s)", tokname[lasttoken], tokname[token]);
|
||||
|
@ -1945,7 +1945,7 @@ noreturn static void synexpect(int token) {
|
|||
synerror(msg);
|
||||
}
|
||||
|
||||
noreturn static void varunset(const char *end, const char *var_, const char *umsg, int varflags) {
|
||||
wontreturn static void varunset(const char *end, const char *var_, const char *umsg, int varflags) {
|
||||
const char *msg;
|
||||
const char *tail;
|
||||
tail = nullstr;
|
||||
|
@ -2096,7 +2096,7 @@ static char *nodesavestr(s) char *s;
|
|||
return rtn;
|
||||
}
|
||||
|
||||
noreturn static void shellexec(char **, const char *, int);
|
||||
wontreturn static void shellexec(char **, const char *, int);
|
||||
static char **listvars(int, int, char ***);
|
||||
static char *argstr(char *p, int flag);
|
||||
static char *conv_escape(char *, int *);
|
||||
|
@ -3175,7 +3175,7 @@ out:
|
|||
return exitstatus;
|
||||
}
|
||||
|
||||
noreturn static void evaltreenr(union node *n, int flags) {
|
||||
wontreturn static void evaltreenr(union node *n, int flags) {
|
||||
evaltree(n, flags);
|
||||
abort();
|
||||
}
|
||||
|
@ -3876,7 +3876,7 @@ static int eprintlist(struct output *out, struct strlist *sp, int sep) {
|
|||
* Exec a program. Never returns. If you change this routine, you may
|
||||
* have to change the find_command routine as well.
|
||||
*/
|
||||
noreturn static void shellexec(char **argv, const char *path, int idx) {
|
||||
wontreturn static void shellexec(char **argv, const char *path, int idx) {
|
||||
char *cmdname;
|
||||
int e;
|
||||
char **envp;
|
||||
|
@ -9316,7 +9316,7 @@ static void setinteractive(int on) {
|
|||
/*
|
||||
* Called to exit the shell.
|
||||
*/
|
||||
noreturn static void exitshell(void) {
|
||||
wontreturn static void exitshell(void) {
|
||||
struct jmploc loc;
|
||||
char *p;
|
||||
savestatus = exitstatus;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue