[hackers] [scc] Transform constconv() to constcode() || Roberto E. Vargas Caballero
commit 475fdec2b580ce32a5e53a3d33c139e23d977b07
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Sep 1 20:09:06 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Sep 1 20:09:06 2015 +0200
Transform constconv() to constcode()
The work was duplicated between convert() and constconv(), and it fact,
it is a bit duplicated, but this version is better than the previous
one.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index 5a3e8b2..628c931 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -362,7 +362,7 @@ extern void freetree(Node *np);
/* fold.c */
extern Node *simplify(int op, Type *tp, Node *lp, Node *rp);
-extern Node *constconv(Node *np, Type *newtp);
+extern Node *castcode(Node *np, Type *newtp);
/* expr.c */
extern Node *expr(void), *negate(Node *np), *constexpr(void);
diff --git a/cc1/expr.c b/cc1/expr.c
index 777b72c..55b482f 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -151,12 +151,9 @@ Node *
convert(Node *np, Type *newtp, char iscast)
{
Type *oldtp = np->type;
- Node *p;
if (eqtype(newtp, oldtp))
return np;
- if (np->constant && (p = constconv(np, newtp)) != NULL)
- return p;
switch (oldtp->op) {
case ENUM:
_AT_@ -202,7 +199,7 @@ convert(Node *np, Type *newtp, char iscast)
default:
return NULL;
}
- return node(OCAST, newtp, np, NULL);
+ return castcode(np, newtp);
}
static Node *
diff --git a/cc1/fold.c b/cc1/fold.c
index e56a88b..78600ed 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
_AT_@ -375,14 +375,16 @@ simplify(int op, Type *tp, Node *lp, Node *rp)
}
/* TODO: check validity of types */
-/* TODO: Integrate it with simplify */
Node *
-constconv(Node *np, Type *newtp)
+castcode(Node *np, Type *newtp)
{
Type *oldtp = np->type;
Symbol aux, *sym, *osym = np->sym;
+ if (!np->constant)
+ goto noconstant;
+
switch (newtp->op) {
case PTR:
case INT:
_AT_@ -405,14 +407,14 @@ constconv(Node *np, Type *newtp)
aux.u.u = osym->u.f;
break;
default:
- return NULL;
+ goto noconstant;
}
break;
case FLOAT:
aux.u.f = (oldtp->sign) ? osym->u.i : osym->u.u;
break;
default:
- return NULL;
+ goto noconstant;
}
sym = newsym(NS_IDEN);
_AT_@ -421,4 +423,7 @@ constconv(Node *np, Type *newtp)
sym->u = aux.u;
return np;
+
+noconstant:
+ return node(OCAST, newtp, np, NULL);
}
Received on Tue Sep 01 2015 - 20:10:55 CEST
This archive was generated by hypermail 2.3.0
: Tue Sep 01 2015 - 20:12:15 CEST