scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 4f388adfd3574c516b7e7c6ef36324d483b0c2d6
parent 0df4f021feb170f1dbd7ec5946234f6a6334b167
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 25 Jan 2016 12:35:35 +0100

[cc1] Add ptrdiff_t type

This is the type used for the difference between pointers,
and it not always has the same size than int.

Diffstat:
Mcc1/arch/amd64-sysv/arch.c | 17+++++++++++++++--
Mcc1/arch/i386-sysv/arch.c | 19+++++++++++++++++--
Mcc1/arch/z80/arch.c | 17+++++++++++++++--
Mcc1/cc1.h | 3++-
Mcc1/expr.c | 2+-
5 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/cc1/arch/amd64-sysv/arch.c b/cc1/arch/amd64-sysv/arch.c @@ -211,7 +211,19 @@ static Type types[] = { .letter = L_ELLIPSIS, .defined = 1, .printed = 1 - } + }, + { /* 19 = pdifftype */ + .op = INT, + .letter = L_LONG, + .defined = 1, + .size = 8, + .integer = 1, + .arith = 1, + .align = 8, + .sign = 1, + .n.rank = RANK_LONG, + .printed = 1 + }, }; Type *voidtype = &types[0], *pvoidtype = &types[1], @@ -222,7 +234,8 @@ Type *voidtype = &types[0], *pvoidtype = &types[1], *longtype = &types[10], *ulongtype = &types[11], *ullongtype = &types[12], *llongtype = &types[13], *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], *sizettype = &types[17], + *ldoubletype = &types[16], + *sizettype = &types[17], *pdifftype = &types[19], *ellipsistype = &types[18]; static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, diff --git a/cc1/arch/i386-sysv/arch.c b/cc1/arch/i386-sysv/arch.c @@ -211,9 +211,22 @@ static Type types[] = { .letter = L_ELLIPSIS, .defined = 1, .printed = 1 - } + }, + { /* 19 = pdifftype */ + .op = INT, + .letter = L_INT, + .defined = 1, + .size = 4, + .integer = 1, + .arith = 1, + .align = 4, + .sign = 1, + .n.rank = RANK_INT, + .printed = 1 + }, }; + Type *voidtype = &types[0], *pvoidtype = &types[1], *booltype = &types[2], *schartype = &types[3], *uchartype = &types[4], *chartype = &types[5], @@ -222,9 +235,11 @@ Type *voidtype = &types[0], *pvoidtype = &types[1], *longtype = &types[10], *ulongtype = &types[11], *ullongtype = &types[12], *llongtype = &types[13], *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], *sizettype = &types[17], + *ldoubletype = &types[16], + *sizettype = &types[17], *pdifftype = &types[19], *ellipsistype = &types[18]; + static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, dummy1 = {.u.i = 1, .type = &types[9]}; Symbol *zero = &dummy0, *one = &dummy1; diff --git a/cc1/arch/z80/arch.c b/cc1/arch/z80/arch.c @@ -211,7 +211,19 @@ static Type types[] = { .letter = L_ELLIPSIS, .defined = 1, .printed = 1 - } + }, + { /* 7 = pdifftype */ + .op = INT, + .letter = L_SHORT, + .defined = 1, + .size = 2, + .integer = 1, + .arith = 1, + .align = 1, + .sign = 1, + .n.rank = RANK_SHORT, + .printed = 1 + }, }; Type *voidtype = &types[0], *pvoidtype = &types[1], @@ -222,7 +234,8 @@ Type *voidtype = &types[0], *pvoidtype = &types[1], *longtype = &types[10], *ulongtype = &types[11], *ullongtype = &types[12], *llongtype = &types[13], *floattype = &types[14], *doubletype = &types[15], - *ldoubletype = &types[16], *sizettype = &types[17], + *ldoubletype = &types[16], + *sizettype = &types[17], *pdifftype = &types[19], *ellipsistype = &types[18]; static Symbol dummy0 = {.u.i = 0, .type = &types[9]}, diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -433,7 +433,8 @@ extern Symbol *curfun, *zero, *one; extern Type *voidtype, *pvoidtype, *booltype, *uchartype, *chartype, *schartype, - *uinttype, *inttype, *sizettype, + *uinttype, *inttype, + *sizettype, *pdifftype, *ushortype, *shortype, *longtype, *ulongtype, *ullongtype, *llongtype, diff --git a/cc1/expr.c b/cc1/expr.c @@ -318,7 +318,7 @@ parithmetic(char op, Node *lp, Node *rp) if (op == OSUB && BTYPE(rp) == PTR) { if (tp != rp->type) goto incorrect; - lp = node(OSUB, inttype, lp, rp); + lp = node(OSUB, pdifftype, lp, rp); return node(ODIV, inttype, lp, size); } if (!rp->type->integer)