mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Restore missing cosmopolitan documentation on website
This commit is contained in:
parent
58352df0a4
commit
d9d5f45e2d
36 changed files with 715 additions and 228 deletions
1
third_party/chibicc/README.cosmo
vendored
1
third_party/chibicc/README.cosmo
vendored
|
@ -12,7 +12,6 @@ local enhancements
|
|||
- support __int128
|
||||
- support _Static_assert
|
||||
- support __vector_size__
|
||||
- support __builtin_add_overflow, etc.
|
||||
- support GCC C11 __atomic_* primitives
|
||||
- support __builtin_memcpy, strlen, strpbrk, etc.
|
||||
- support __builtin_constant_p, __builtin_likely, etc.
|
||||
|
|
2
third_party/chibicc/chibicc.h
vendored
2
third_party/chibicc/chibicc.h
vendored
|
@ -410,8 +410,6 @@ struct Node {
|
|||
Node *atomic_expr;
|
||||
// Variable
|
||||
Obj *var;
|
||||
// Arithmetic
|
||||
Node *overflow;
|
||||
// Numeric literal
|
||||
int64_t val;
|
||||
long double fval;
|
||||
|
|
6
third_party/chibicc/chibicc.mk
vendored
6
third_party/chibicc/chibicc.mk
vendored
|
@ -19,6 +19,10 @@ CHIBICC_FLAGS = \
|
|||
-DIMAGE_BASE_VIRTUAL=$(IMAGE_BASE_VIRTUAL) \
|
||||
-DMODE='"$(MODE)"'
|
||||
|
||||
o/$(MODE)/%.chibicc.o: private .UNSANDBOXED = true
|
||||
o/$(MODE)/%.chibicc.o: %.c $(CHIBICC)
|
||||
@$(COMPILE) $(CHIBICC) $(OBJECTIFY.c.flags) -c $< $(OUTPUT_OPTION)
|
||||
|
||||
PKGS += THIRD_PARTY_CHIBICC
|
||||
THIRD_PARTY_CHIBICC_ARTIFACTS += THIRD_PARTY_CHIBICC_A
|
||||
THIRD_PARTY_CHIBICC = $(THIRD_PARTY_CHIBICC_A_DEPS) $(THIRD_PARTY_CHIBICC_A)
|
||||
|
@ -101,7 +105,7 @@ o/$(MODE)/third_party/chibicc/as.com.dbg: \
|
|||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/third_party/chibicc/chibicc.o: private \
|
||||
CPPFLAGS += $(THIRD_PARTY_CHIBICC_DEFINES )
|
||||
CPPFLAGS += $(THIRD_PARTY_CHIBICC_DEFINES)
|
||||
|
||||
THIRD_PARTY_CHIBICC_LIBS = $(foreach x,$(THIRD_PARTY_CHIBICC_ARTIFACTS),$($(x)))
|
||||
THIRD_PARTY_CHIBICC_SRCS = $(foreach x,$(THIRD_PARTY_CHIBICC_ARTIFACTS),$($(x)_SRCS))
|
||||
|
|
27
third_party/chibicc/codegen.c
vendored
27
third_party/chibicc/codegen.c
vendored
|
@ -1152,19 +1152,6 @@ static int GetSseIntSuffix(Type *ty) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsOverflowArithmetic(Node *node) {
|
||||
return (node->kind == ND_ADD || node->kind == ND_SUB ||
|
||||
node->kind == ND_MUL || node->kind == ND_NEG) &&
|
||||
node->overflow;
|
||||
}
|
||||
|
||||
static void HandleOverflow(const char *ax) {
|
||||
pop("%rdi");
|
||||
println("\tmov\t%s,(%%rdi)", ax);
|
||||
emitlin("\tseto\t%al");
|
||||
emitlin("\tmovzbl\t%al,%eax");
|
||||
}
|
||||
|
||||
static void HandleAtomicArithmetic(Node *node, const char *op) {
|
||||
gen_expr(node->lhs);
|
||||
push();
|
||||
|
@ -1238,10 +1225,6 @@ void gen_expr(Node *node) {
|
|||
}
|
||||
}
|
||||
case ND_NEG:
|
||||
if (IsOverflowArithmetic(node)) {
|
||||
gen_expr(node->overflow);
|
||||
push();
|
||||
}
|
||||
gen_expr(node->lhs);
|
||||
switch (node->ty->kind) {
|
||||
case TY_FLOAT:
|
||||
|
@ -1277,9 +1260,6 @@ void gen_expr(Node *node) {
|
|||
ax = "%eax";
|
||||
}
|
||||
println("\tneg\t%s", ax);
|
||||
if (IsOverflowArithmetic(node)) {
|
||||
HandleOverflow(ax);
|
||||
}
|
||||
return;
|
||||
case ND_VAR:
|
||||
gen_addr(node);
|
||||
|
@ -1771,10 +1751,6 @@ void gen_expr(Node *node) {
|
|||
error_tok(node->tok, "invalid expression");
|
||||
}
|
||||
}
|
||||
if (IsOverflowArithmetic(node)) {
|
||||
gen_expr(node->overflow);
|
||||
push();
|
||||
}
|
||||
if (node->lhs->ty->vector_size == 16) {
|
||||
gen_expr(node->rhs);
|
||||
pushx();
|
||||
|
@ -2210,9 +2186,6 @@ void gen_expr(Node *node) {
|
|||
default:
|
||||
error_tok(node->tok, "invalid expression");
|
||||
}
|
||||
if (IsOverflowArithmetic(node)) {
|
||||
HandleOverflow(ax);
|
||||
}
|
||||
}
|
||||
|
||||
void gen_stmt(Node *node) {
|
||||
|
|
4
third_party/chibicc/help.txt
vendored
4
third_party/chibicc/help.txt
vendored
|
@ -198,10 +198,6 @@ BUILTIN FUNCTIONS
|
|||
_Bool __builtin_types_compatible_p(typename, typename)
|
||||
T __builtin_atomic_exchange(T *addr, T neu)
|
||||
T * __builtin_assume_aligned(T *addr)
|
||||
_Bool __builtin_add_overflow(T, T, T *)
|
||||
_Bool __builtin_sub_overflow(T, T, T *)
|
||||
_Bool __builtin_mul_overflow(T, T, T *)
|
||||
_Bool __builtin_neg_overflow(T, T, T *)
|
||||
void * __builtin_alloca(unsigned long)
|
||||
void __builtin_trap()
|
||||
int __builtin_clz(int)
|
||||
|
|
47
third_party/chibicc/parse.c
vendored
47
third_party/chibicc/parse.c
vendored
|
@ -2631,27 +2631,6 @@ static Node *new_mul(Node *lhs, Node *rhs, Token *tok) {
|
|||
return new_binary(ND_MUL, lhs, rhs, tok);
|
||||
}
|
||||
|
||||
static Node *builtin_overflow(Token **rest, Token *tok,
|
||||
Node *new_op(Node *, Node *, Token *)) {
|
||||
Token *start = tok;
|
||||
tok = skip(tok->next, '(');
|
||||
Node *lhs = assign(&tok, tok);
|
||||
tok = skip(tok, ',');
|
||||
Node *rhs = assign(&tok, tok);
|
||||
tok = skip(tok, ',');
|
||||
Node *dst = assign(&tok, tok);
|
||||
*rest = skip(tok, ')');
|
||||
Node *node = new_op(lhs, rhs, start);
|
||||
add_type(node);
|
||||
add_type(dst);
|
||||
if (!is_compatible(pointer_to(node->ty), dst->ty)) {
|
||||
error_tok(start, "output pointer type incompatible");
|
||||
}
|
||||
node->overflow = dst;
|
||||
node->ty = copy_type(ty_bool);
|
||||
return node;
|
||||
}
|
||||
|
||||
// add = mul ("+" mul | "-" mul)*
|
||||
static Node *add(Token **rest, Token *tok) {
|
||||
Node *node = mul(&tok, tok);
|
||||
|
@ -3378,32 +3357,6 @@ static Node *primary(Token **rest, Token *tok) {
|
|||
*rest = skip(tok, ')');
|
||||
return node;
|
||||
}
|
||||
if (kw == KW___BUILTIN_ADD_OVERFLOW) {
|
||||
return builtin_overflow(rest, tok, new_add);
|
||||
}
|
||||
if (kw == KW___BUILTIN_SUB_OVERFLOW) {
|
||||
return builtin_overflow(rest, tok, new_sub);
|
||||
}
|
||||
if (kw == KW___BUILTIN_MUL_OVERFLOW) {
|
||||
return builtin_overflow(rest, tok, new_mul);
|
||||
}
|
||||
if (kw == KW___BUILTIN_NEG_OVERFLOW) {
|
||||
Token *start = tok;
|
||||
tok = skip(tok->next, '(');
|
||||
Node *lhs = assign(&tok, tok);
|
||||
tok = skip(tok, ',');
|
||||
Node *dst = assign(&tok, tok);
|
||||
*rest = skip(tok, ')');
|
||||
Node *node = new_unary(ND_NEG, lhs, start);
|
||||
add_type(node);
|
||||
add_type(dst);
|
||||
if (!is_compatible(pointer_to(node->ty), dst->ty)) {
|
||||
error_tok(start, "output pointer type incompatible");
|
||||
}
|
||||
node->overflow = dst;
|
||||
node->ty = copy_type(ty_bool);
|
||||
return node;
|
||||
}
|
||||
if (kw == KW___BUILTIN_FPCLASSIFY) {
|
||||
Node *node = new_node(ND_FPCLASSIFY, tok);
|
||||
node->fpc = calloc(1, sizeof(FpClassify));
|
||||
|
|
1
third_party/chibicc/printast.c
vendored
1
third_party/chibicc/printast.c
vendored
|
@ -189,7 +189,6 @@ static void PrintNode(FILE *f, int l, const char *s, Node *n) {
|
|||
PrintInt(f, l + 2, "end: ", n->end);
|
||||
PrintMember(f, l + 2, "member: ", n->member);
|
||||
PrintObj(f, l + 2, "var: ", n->var);
|
||||
PrintNode(f, l + 2, "overflow: ", n->overflow);
|
||||
PrintInt(f, l + 2, "val: ", n->val);
|
||||
if (n->fval) PrintLine(f, l + 2, "fval: %Lf", n->fval);
|
||||
PrintLine(f, l, "}");
|
||||
|
|
102
third_party/chibicc/test/builtin_test.c
vendored
102
third_party/chibicc/test/builtin_test.c
vendored
|
@ -192,104 +192,6 @@ void test_memcpy(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void test_add_overflow(void) {
|
||||
{
|
||||
int z;
|
||||
ASSERT(0, ckd_add(&z, 2, 3));
|
||||
ASSERT(5, z);
|
||||
}
|
||||
{
|
||||
int x, y, z;
|
||||
x = 2;
|
||||
y = 3;
|
||||
ASSERT(0, ckd_add(&z, x, y));
|
||||
ASSERT(5, z);
|
||||
}
|
||||
{
|
||||
int x, y, z;
|
||||
x = 0x7fffffff;
|
||||
y = 1;
|
||||
ASSERT(1, ckd_add(&z, x, y));
|
||||
ASSERT(-2147483648, z);
|
||||
}
|
||||
{
|
||||
long x, y, z;
|
||||
x = 0x7fffffff;
|
||||
y = 1;
|
||||
ASSERT(0, ckd_add(&z, x, y));
|
||||
ASSERT(2147483648, z);
|
||||
}
|
||||
}
|
||||
|
||||
void test_sub_overflow(void) {
|
||||
{
|
||||
int x, y, z;
|
||||
x = 2;
|
||||
y = 3;
|
||||
ASSERT(0, ckd_sub(&z, x, y));
|
||||
ASSERT(-1, z);
|
||||
}
|
||||
{
|
||||
int x, y, z;
|
||||
x = -2147483648;
|
||||
y = 1;
|
||||
ASSERT(1, ckd_sub(&z, x, y));
|
||||
ASSERT(2147483647, z);
|
||||
}
|
||||
{
|
||||
long x, y, z;
|
||||
x = -2147483648;
|
||||
y = 1;
|
||||
ASSERT(0, ckd_sub(&z, x, y));
|
||||
ASSERT(-2147483649, z);
|
||||
}
|
||||
}
|
||||
|
||||
void test_mul_overflow(void) {
|
||||
{
|
||||
int x, y, z;
|
||||
x = 2;
|
||||
y = 3;
|
||||
ASSERT(0, ckd_mul(&z, x, y));
|
||||
ASSERT(6, z);
|
||||
}
|
||||
{
|
||||
int x, y, z;
|
||||
x = 2147483647;
|
||||
y = 2;
|
||||
ASSERT(1, ckd_mul(&z, x, y));
|
||||
ASSERT(-2, z);
|
||||
}
|
||||
{
|
||||
long x, y, z;
|
||||
x = 2147483647;
|
||||
y = 2;
|
||||
ASSERT(0, ckd_mul(&z, x, y));
|
||||
ASSERT(4294967294, z);
|
||||
}
|
||||
}
|
||||
|
||||
void test_neg_overflow(void) {
|
||||
{
|
||||
int x, z;
|
||||
x = 2;
|
||||
ASSERT(0, __builtin_neg_overflow(x, &z));
|
||||
ASSERT(-2, z);
|
||||
}
|
||||
{
|
||||
int x, z;
|
||||
x = -2147483648;
|
||||
ASSERT(1, __builtin_neg_overflow(x, &z));
|
||||
ASSERT(-2147483648, z);
|
||||
}
|
||||
{
|
||||
long x, z;
|
||||
x = -2147483648;
|
||||
ASSERT(0, __builtin_neg_overflow(x, &z));
|
||||
ASSERT(2147483648, z);
|
||||
}
|
||||
}
|
||||
|
||||
void test_inf(void) {
|
||||
ASSERT(0, __builtin_isinf(0));
|
||||
ASSERT(0, __builtin_isinf(1));
|
||||
|
@ -433,10 +335,6 @@ int main() {
|
|||
test_memcpy();
|
||||
test_offsetof();
|
||||
test_ignored();
|
||||
test_add_overflow();
|
||||
test_sub_overflow();
|
||||
test_mul_overflow();
|
||||
test_neg_overflow();
|
||||
test_strlen();
|
||||
test_strchr();
|
||||
test_strpbrk();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue