Codegen casts
This commit is contained in:
parent
fe0baa26a0
commit
6789984bd1
2
src/cg.c
2
src/cg.c
@ -111,7 +111,7 @@ static const char *xop_sz(AST *e, int sz) {
|
|||||||
if(v->kind == VARTABLEENTRY_VAR) {
|
if(v->kind == VARTABLEENTRY_VAR) {
|
||||||
return xv_sz(v, sz);
|
return xv_sz(v, sz);
|
||||||
} else if(v->kind == VARTABLEENTRY_SYMBOL) {
|
} else if(v->kind == VARTABLEENTRY_SYMBOL) {
|
||||||
snprintf(ret, XOPBUFSZ, "[%s]", v->data.symbol.name);
|
snprintf(ret, XOPBUFSZ, "%s [%s]", spec(sz), v->data.symbol.name);
|
||||||
} else abort();
|
} else abort();
|
||||||
} else if(e->nodeKind == AST_EXPR_PRIMITIVE) {
|
} else if(e->nodeKind == AST_EXPR_PRIMITIVE) {
|
||||||
snprintf(ret, XOPBUFSZ, "%i", e->exprPrim.val);
|
snprintf(ret, XOPBUFSZ, "%i", e->exprPrim.val);
|
||||||
|
10
src/parse.c
10
src/parse.c
@ -213,11 +213,17 @@ AST *nct_cast_expr(AST *what, Type *to) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(what->nodeKind == AST_EXPR_PRIMITIVE && to->type == TYPE_TYPE_PRIMITIVE) {
|
if(what->nodeKind == AST_EXPR_PRIMITIVE && (to->type == TYPE_TYPE_PRIMITIVE || to->type == TYPE_TYPE_POINTER)) {
|
||||||
ASTExprPrimitive *ret = malloc(sizeof(*ret));
|
ASTExprPrimitive *ret = malloc(sizeof(*ret));
|
||||||
ret->nodeKind = AST_EXPR_PRIMITIVE;
|
ret->nodeKind = AST_EXPR_PRIMITIVE;
|
||||||
ret->type = to;
|
ret->type = to;
|
||||||
ret->val = what->exprPrim.val & (((int64_t) 1 << to->primitive.width) - 1);
|
|
||||||
|
if(to->type == TYPE_TYPE_PRIMITIVE) {
|
||||||
|
ret->val = what->exprPrim.val & ((1UL << to->primitive.width) - 1);
|
||||||
|
} else {
|
||||||
|
ret->val = what->exprPrim.val & ((1UL << (8 * type_size(to))) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
return (AST*) ret;
|
return (AST*) ret;
|
||||||
} else {
|
} else {
|
||||||
ASTExprCast *ret = malloc(sizeof(*ret));
|
ASTExprCast *ret = malloc(sizeof(*ret));
|
||||||
|
@ -2,7 +2,7 @@ extern s32() getchar;
|
|||||||
extern u0(s32) putchar;
|
extern u0(s32) putchar;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
u8 z = 5;
|
s32 z = 5;
|
||||||
s32 a = getchar();
|
s32 a = getchar();
|
||||||
if(a == -1) {
|
if(a == -1) {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user