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) {
|
||||
return xv_sz(v, sz);
|
||||
} 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 if(e->nodeKind == AST_EXPR_PRIMITIVE) {
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
ret->nodeKind = AST_EXPR_PRIMITIVE;
|
||||
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;
|
||||
} else {
|
||||
ASTExprCast *ret = malloc(sizeof(*ret));
|
||||
|
@ -2,7 +2,7 @@ extern s32() getchar;
|
||||
extern u0(s32) putchar;
|
||||
|
||||
loop {
|
||||
u8 z = 5;
|
||||
s32 z = 5;
|
||||
s32 a = getchar();
|
||||
if(a == -1) {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user