return NULL;
}
- fn->value->isconst = true;
+ fn->value->hasvalue = true;
fn->value->outtype = outtype;
fn->value->constval.vfunc = fn;
fn->value->context = fn->context;
self->reads = NULL;
self->writes = NULL;
- self->isconst = false;
+ self->cvq = CV_NONE;
+ self->hasvalue = false;
self->context.file = "<@no context>";
self->context.line = 0;
self->name = NULL;
size_t i;
if (self->name)
mem_d((void*)self->name);
- if (self->isconst)
+ if (self->hasvalue)
{
if (self->vtype == TYPE_STRING)
mem_d((void*)self->constval.vstring);
if (self->vtype != TYPE_FLOAT)
return false;
self->constval.vfloat = f;
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
if (self->vtype != TYPE_FUNCTION)
return false;
self->constval.vint = f;
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
if (self->vtype != TYPE_VECTOR)
return false;
self->constval.vvec = v;
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
if (self->vtype != TYPE_FIELD)
return false;
self->constval.vpointer = fld;
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
if (self->vtype != TYPE_STRING)
return false;
self->constval.vstring = ir_strdup(str);
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
if (self->vtype != TYPE_INTEGER)
return false;
self->constval.vint = i;
- self->isconst = true;
+ self->hasvalue = true;
return true;
}
#endif
static bool gen_global_field(ir_value *global)
{
- if (global->isconst)
+ if (global->hasvalue)
{
ir_value *fld = global->constval.vpointer;
if (!fld) {
static bool gen_global_pointer(ir_value *global)
{
- if (global->isconst)
+ if (global->hasvalue)
{
ir_value *target = global->constval.vpointer;
if (!target) {
size_t i;
size_t local_var_end;
- if (!global->isconst || (!global->constval.vfunc))
+ if (!global->hasvalue || (!global->constval.vfunc))
{
irerror(global->context, "Invalid state of function-global: not constant: %s", global->name);
return false;
case TYPE_FLOAT:
{
ir_value_code_setaddr(global, vec_size(code_globals));
- if (global->isconst) {
+ if (global->hasvalue) {
iptr = (int32_t*)&global->constval.ivec[0];
vec_push(code_globals, *iptr);
} else {
case TYPE_STRING:
{
ir_value_code_setaddr(global, vec_size(code_globals));
- if (global->isconst) {
+ if (global->hasvalue) {
vec_push(code_globals, code_genstring(global->constval.vstring));
} else {
vec_push(code_globals, 0);
{
size_t d;
ir_value_code_setaddr(global, vec_size(code_globals));
- if (global->isconst) {
+ if (global->hasvalue) {
iptr = (int32_t*)&global->constval.ivec[0];
vec_push(code_globals, iptr[0]);
if (global->code.globaladdr < 0)
}
case TYPE_FUNCTION:
ir_value_code_setaddr(global, vec_size(code_globals));
- if (!global->isconst) {
+ if (!global->hasvalue) {
vec_push(code_globals, 0);
if (global->code.globaladdr < 0)
return false;
for (i = 0; i < vec_size(b->globals); ++i)
{
oprintf("global ");
- if (b->globals[i]->isconst)
+ if (b->globals[i]->hasvalue)
oprintf("%s = ", b->globals[i]->name);
ir_value_dump(b->globals[i], oprintf);
oprintf("\n");
void ir_value_dump(ir_value* v, int (*oprintf)(const char*, ...))
{
- if (v->isconst) {
+ if (v->hasvalue) {
switch (v->vtype) {
default:
case TYPE_VOID:
qcint memberof;
} parser_t;
-#define CV_NONE 0
-#define CV_CONST 1
-#define CV_VAR -1
-
static void parser_enterblock(parser_t *parser);
static bool parser_leaveblock(parser_t *parser);
static void parser_addlocal(parser_t *parser, const char *name, ast_expression *e);
return parser->imm_float[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_FLOAT);
- out->constant = true;
+ out->cvq = CV_CONST;
out->hasvalue = true;
out->constval.vfloat = d;
vec_push(parser->imm_float, out);
out = ast_value_new(parser_ctx(parser), name, TYPE_STRING);
} else
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_STRING);
- out->constant = true;
+ out->cvq = CV_CONST;
out->hasvalue = true;
out->constval.vstring = parser_strdup(str);
vec_push(parser->imm_string, out);
return parser->imm_vector[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_VECTOR);
- out->constant = true;
+ out->cvq = CV_CONST;
out->hasvalue = true;
out->constval.vvec = v;
vec_push(parser->imm_vector, out);
(exprs[0]->expression.vtype != exprs[1]->expression.vtype || \
exprs[0]->expression.vtype != T)
#define CanConstFold1(A) \
- (ast_istype((A), ast_value) && ((ast_value*)(A))->hasvalue && ((ast_value*)(A))->constant)
+ (ast_istype((A), ast_value) && ((ast_value*)(A))->hasvalue && (((ast_value*)(A))->cvq == CV_CONST))
#define CanConstFold(A, B) \
(CanConstFold1(A) && CanConstFold1(B))
#define ConstV(i) (asvalue[(i)]->constval.vvec)
parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
}
}
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
out = (ast_expression*)ast_store_new(ctx, assignop, exprs[0], exprs[1]);
addop = INSTR_ADD_F;
else
addop = INSTR_SUB_F;
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
if (ast_istype(exprs[0], ast_entfield)) {
addop = INSTR_SUB_F;
subop = INSTR_ADD_F;
}
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
if (ast_istype(exprs[0], ast_entfield)) {
ty1, ty2);
return false;
}
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
if (ast_istype(exprs[0], ast_entfield))
ty1, ty2);
return false;
}
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
if (ast_istype(exprs[0], ast_entfield))
ty1, ty2);
return false;
}
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
if (ast_istype(exprs[0], ast_entfield))
out = (ast_expression*)ast_binary_new(ctx, INSTR_BITAND, exprs[0], exprs[1]);
if (!out)
return false;
- if (ast_istype(exprs[0], ast_value) && asvalue[0]->constant) {
+ if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
parseerror(parser, "assignment to constant `%s`", asvalue[0]->name);
}
asbinstore = ast_binstore_new(ctx, assignop, INSTR_SUB_F, exprs[0], out);
}
if (!OPTS_FLAG(RELAXED_SWITCH)) {
opval = (ast_value*)swcase.value;
- if (!ast_istype(swcase.value, ast_value)) { /* || !opval->constant) { */
+ if (!ast_istype(swcase.value, ast_value)) { /* || opval->cvq != CV_CONST) { */
parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch");
ast_unref(operand);
return false;
}
if (is_const_var == CV_CONST)
- var->constant = true;
+ var->cvq = CV_CONST;
/* Part 1:
* check for validity: (end_sys_..., multiple-definitions, prototypes, ...)
if (!localblock) {
cval = (ast_value*)cexp;
- if (!ast_istype(cval, ast_value) || !cval->hasvalue || !cval->constant)
+ if (!ast_istype(cval, ast_value) || !cval->hasvalue || cval->cvq != CV_CONST)
parseerror(parser, "cannot initialize a global constant variable with a non-constant expression");
else
{
!OPTS_FLAG(INITIALIZED_NONCONSTANTS) &&
is_const_var != CV_VAR)
{
- var->constant = true;
+ var->cvq = CV_CONST;
}
var->hasvalue = true;
if (cval->expression.vtype == TYPE_STRING)
} else {
bool cvq;
shunt sy = { NULL, NULL };
- cvq = var->constant;
- var->constant = false;
+ cvq = var->cvq;
+ var->cvq = CV_NONE;
vec_push(sy.out, syexp(ast_ctx(var), (ast_expression*)var));
vec_push(sy.out, syexp(ast_ctx(cexp), (ast_expression*)cexp));
vec_push(sy.ops, syop(ast_ctx(var), parser->assign_op));
}
vec_free(sy.out);
vec_free(sy.ops);
- var->constant = cvq;
+ var->cvq = cvq;
}
}