#include "algo.h"
-#define ast_instantiate(T, ctx, destroyfn) \
- T* self = (T*)mem_a(sizeof(T)); \
- if (!self) { \
- return nullptr; \
- } \
- new (self) T(); \
- ast_node_init((ast_node*)self, ctx, TYPE_##T); \
- ( (ast_node*)self )->destroy = (ast_node_delete*)destroyfn
+#define ast_instantiate(T, ctx, destroyfn) \
+ T* self = new T; \
+ if (!self) return nullptr; \
+ ast_node_init(self, ctx, TYPE_##T); \
+ self->m_destroy = (ast_node_delete*)destroyfn
/*
* forward declarations, these need not be in ast.h for obvious
/* Initialize main ast node aprts */
static void ast_node_init(ast_node *self, lex_ctx_t ctx, int node_type)
{
- self->context = ctx;
- self->destroy = &_ast_node_destroy;
- self->keep_node = false;
- self->node_type = node_type;
- self->side_effects = false;
+ self->m_context = ctx;
+ self->m_destroy = &_ast_node_destroy;
+ self->m_keep_node = false;
+ self->m_node_type = node_type;
+ self->m_side_effects = false;
}
/* weight and side effects */
static void _ast_propagate_effects(ast_node *self, ast_node *other)
{
- if (ast_side_effects(other))
- ast_side_effects(self) = true;
+ if (other->m_side_effects)
+ self->m_side_effects = true;
}
#define ast_propagate_effects(s,o) _ast_propagate_effects(((ast_node*)(s)), ((ast_node*)(o)))
static void ast_expression_init(ast_expression *self,
ast_expression_codegen *codegen)
{
- self->codegen = codegen;
- self->vtype = TYPE_VOID;
- self->next = nullptr;
- self->outl = nullptr;
- self->outr = nullptr;
- self->count = 0;
- self->varparam = nullptr;
- self->flags = 0;
+ self->m_codegen = codegen;
+ self->m_vtype = TYPE_VOID;
+ self->m_next = nullptr;
+ self->m_outl = nullptr;
+ self->m_outr = nullptr;
+ self->m_count = 0;
+ self->m_varparam = nullptr;
+ self->m_flags = 0;
if (OPTS_OPTION_BOOL(OPTION_COVERAGE))
- self->flags |= AST_FLAG_BLOCK_COVERAGE;
+ self->m_flags |= AST_FLAG_BLOCK_COVERAGE;
}
static void ast_expression_delete(ast_expression *self)
{
- if (self->next)
- ast_delete(self->next);
- for (auto &it : self->type_params)
+ if (self->m_next)
+ ast_delete(self->m_next);
+ for (auto &it : self->m_type_params)
ast_delete(it);
- if (self->varparam)
- ast_delete(self->varparam);
+ if (self->m_varparam)
+ ast_delete(self->m_varparam);
}
static void ast_expression_delete_full(ast_expression *self)
ast_value* ast_value_copy(const ast_value *self)
{
- ast_value *cp = ast_value_new(self->context, self->name, self->vtype);
- if (self->next) {
- cp->next = ast_type_copy(self->context, self->next);
+ ast_value *cp = ast_value_new(self->m_context, self->m_name, self->m_vtype);
+ if (self->m_next) {
+ cp->m_next = ast_type_copy(self->m_context, self->m_next);
}
const ast_expression *fromex = self;
ast_expression *selfex = cp;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (auto &it : fromex->type_params) {
+ selfex->m_count = fromex->m_count;
+ selfex->m_flags = fromex->m_flags;
+ for (auto &it : fromex->m_type_params) {
ast_value *v = ast_value_copy(it);
- selfex->type_params.push_back(v);
+ selfex->m_type_params.push_back(v);
}
return cp;
}
{
const ast_expression *fromex;
ast_expression *selfex;
- self->vtype = other->vtype;
- if (other->next) {
- self->next = (ast_expression*)ast_type_copy(ast_ctx(self), other->next);
+ self->m_vtype = other->m_vtype;
+ if (other->m_next) {
+ self->m_next = (ast_expression*)ast_type_copy(self->m_context, other->m_next);
}
fromex = other;
selfex = self;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (auto &it : fromex->type_params) {
+ selfex->m_count = fromex->m_count;
+ selfex->m_flags = fromex->m_flags;
+ for (auto &it : fromex->m_type_params) {
ast_value *v = ast_value_copy(it);
- selfex->type_params.push_back(v);
+ selfex->m_type_params.push_back(v);
}
}
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
ast_expression_init(self, nullptr);
- self->codegen = nullptr;
- self->next = nullptr;
- self->vtype = vtype;
+ self->m_codegen = nullptr;
+ self->m_next = nullptr;
+ self->m_vtype = vtype;
return self;
}
selfex = self;
/* This may never be codegen()d */
- selfex->codegen = nullptr;
+ selfex->m_codegen = nullptr;
- selfex->vtype = fromex->vtype;
- if (fromex->next)
- selfex->next = ast_type_copy(ctx, fromex->next);
+ selfex->m_vtype = fromex->m_vtype;
+ if (fromex->m_next)
+ selfex->m_next = ast_type_copy(ctx, fromex->m_next);
else
- selfex->next = nullptr;
+ selfex->m_next = nullptr;
- selfex->count = fromex->count;
- selfex->flags = fromex->flags;
- for (auto &it : fromex->type_params) {
+ selfex->m_count = fromex->m_count;
+ selfex->m_flags = fromex->m_flags;
+ for (auto &it : fromex->m_type_params) {
ast_value *v = ast_value_copy(it);
- selfex->type_params.push_back(v);
+ selfex->m_type_params.push_back(v);
}
return self;
bool ast_compare_type(ast_expression *a, ast_expression *b)
{
- if (a->vtype == TYPE_NIL ||
- b->vtype == TYPE_NIL)
+ if (a->m_vtype == TYPE_NIL ||
+ b->m_vtype == TYPE_NIL)
return true;
- if (a->vtype != b->vtype)
+ if (a->m_vtype != b->m_vtype)
return false;
- if (!a->next != !b->next)
+ if (!a->m_next != !b->m_next)
return false;
- if (a->type_params.size() != b->type_params.size())
+ if (a->m_type_params.size() != b->m_type_params.size())
return false;
- if ((a->flags & AST_FLAG_TYPE_MASK) !=
- (b->flags & AST_FLAG_TYPE_MASK) )
+ if ((a->m_flags & AST_FLAG_TYPE_MASK) !=
+ (b->m_flags & AST_FLAG_TYPE_MASK) )
{
return false;
}
- if (a->type_params.size()) {
+ if (a->m_type_params.size()) {
size_t i;
- for (i = 0; i < a->type_params.size(); ++i) {
- if (!ast_compare_type((ast_expression*)a->type_params[i],
- (ast_expression*)b->type_params[i]))
+ for (i = 0; i < a->m_type_params.size(); ++i) {
+ if (!ast_compare_type((ast_expression*)a->m_type_params[i],
+ (ast_expression*)b->m_type_params[i]))
return false;
}
}
- if (a->next)
- return ast_compare_type(a->next, b->next);
+ if (a->m_next)
+ return ast_compare_type(a->m_next, b->m_next);
return true;
}
if (pos + 1 >= bufsize)
goto full;
- switch (e->vtype) {
+ switch (e->m_vtype) {
case TYPE_VARIANT:
util_strncpy(buf + pos, "(variant)", 9);
return pos + 9;
case TYPE_FIELD:
buf[pos++] = '.';
- return ast_type_to_string_impl(e->next, buf, bufsize, pos);
+ return ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
case TYPE_POINTER:
if (pos + 3 >= bufsize)
goto full;
buf[pos++] = '*';
buf[pos++] = '(';
- pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+ pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
if (pos + 1 >= bufsize)
goto full;
buf[pos++] = ')';
return pos;
case TYPE_FUNCTION:
- pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+ pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
if (pos + 2 >= bufsize)
goto full;
- if (e->type_params.empty()) {
+ if (e->m_type_params.empty()) {
buf[pos++] = '(';
buf[pos++] = ')';
return pos;
}
buf[pos++] = '(';
- pos = ast_type_to_string_impl((ast_expression*)(e->type_params[0]), buf, bufsize, pos);
- for (i = 1; i < e->type_params.size(); ++i) {
+ pos = ast_type_to_string_impl((ast_expression*)(e->m_type_params[0]), buf, bufsize, pos);
+ for (i = 1; i < e->m_type_params.size(); ++i) {
if (pos + 2 >= bufsize)
goto full;
buf[pos++] = ',';
buf[pos++] = ' ';
- pos = ast_type_to_string_impl((ast_expression*)(e->type_params[i]), buf, bufsize, pos);
+ pos = ast_type_to_string_impl((ast_expression*)(e->m_type_params[i]), buf, bufsize, pos);
}
if (pos + 1 >= bufsize)
goto full;
return pos;
case TYPE_ARRAY:
- pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+ pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
if (pos + 1 >= bufsize)
goto full;
buf[pos++] = '[';
- pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->count);
+ pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->m_count);
if (pos + 1 >= bufsize)
goto full;
buf[pos++] = ']';
return pos;
default:
- typestr = type_name[e->vtype];
+ typestr = type_name[e->m_vtype];
typelen = strlen(typestr);
if (pos + typelen >= bufsize)
goto full;
ast_instantiate(ast_value, ctx, ast_value_delete);
ast_expression_init((ast_expression*)self,
(ast_expression_codegen*)&ast_value_codegen);
- self->keep_node = true; /* keep */
-
- self->name = name ? util_strdup(name) : nullptr;
- self->vtype = t;
- self->next = nullptr;
- self->isfield = false;
- self->cvq = CV_NONE;
- self->hasvalue = false;
- self->isimm = false;
- self->inexact = false;
- self->uses = 0;
- memset(&self->constval, 0, sizeof(self->constval));
-
- self->ir_v = nullptr;
- self->ir_values = nullptr;
- self->ir_value_count = 0;
-
- self->setter = nullptr;
- self->getter = nullptr;
- self->desc = nullptr;
-
- self->argcounter = nullptr;
- self->intrinsic = false;
+ self->m_keep_node = true; /* keep */
+
+ self->m_name = name ? util_strdup(name) : nullptr;
+ self->m_vtype = t;
+ self->m_next = nullptr;
+ self->m_isfield = false;
+ self->m_cvq = CV_NONE;
+ self->m_hasvalue = false;
+ self->m_isimm = false;
+ self->m_inexact = false;
+ self->m_uses = 0;
+ memset(&self->m_constval, 0, sizeof(self->m_constval));
+
+ self->m_ir_v = nullptr;
+ self->m_ir_values = nullptr;
+ self->m_ir_value_count = 0;
+
+ self->m_setter = nullptr;
+ self->m_getter = nullptr;
+ self->m_desc = nullptr;
+
+ self->m_argcounter = nullptr;
+ self->m_intrinsic = false;
return self;
}
void ast_value_delete(ast_value* self)
{
- if (self->name)
- mem_d((void*)self->name);
- if (self->argcounter)
- mem_d((void*)self->argcounter);
- if (self->hasvalue) {
- switch (self->vtype)
+ if (self->m_name)
+ mem_d((void*)self->m_name);
+ if (self->m_argcounter)
+ mem_d((void*)self->m_argcounter);
+ if (self->m_hasvalue) {
+ switch (self->m_vtype)
{
case TYPE_STRING:
- mem_d((void*)self->constval.vstring);
+ mem_d((void*)self->m_constval.vstring);
break;
case TYPE_FUNCTION:
/* unlink us from the function node */
- self->constval.vfunc->function_type = nullptr;
+ self->m_constval.vfunc->m_function_type = nullptr;
break;
/* NOTE: delete function? currently collected in
* the parser structure
break;
}
}
- if (self->ir_values)
- mem_d(self->ir_values);
+ if (self->m_ir_values)
+ mem_d(self->m_ir_values);
- if (self->desc)
- mem_d(self->desc);
+ if (self->m_desc)
+ mem_d(self->m_desc);
// initlist imples an array which implies .next in the expression exists.
- if (self->initlist.size() && self->next->vtype == TYPE_STRING) {
- for (auto &it : self->initlist)
+ if (self->m_initlist.size() && self->m_next->m_vtype == TYPE_STRING) {
+ for (auto &it : self->m_initlist)
if (it.vstring)
mem_d(it.vstring);
}
void ast_value_params_add(ast_value *self, ast_value *p)
{
- self->type_params.push_back(p);
+ self->m_type_params.push_back(p);
}
bool ast_value_set_name(ast_value *self, const char *name)
{
- if (self->name)
- mem_d((void*)self->name);
- self->name = util_strdup(name);
- return !!self->name;
+ if (self->m_name)
+ mem_d((void*)self->m_name);
+ self->m_name = util_strdup(name);
+ return !!self->m_name;
}
ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
if (ast_istype(right, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
ast_unary *unary = ((ast_unary*)right);
- ast_expression *normal = unary->operand;
+ ast_expression *normal = unary->m_operand;
/* make a-(-b) => a + b */
- if (unary->op == VINSTR_NEG_F || unary->op == VINSTR_NEG_V) {
+ if (unary->m_op == VINSTR_NEG_F || unary->m_op == VINSTR_NEG_V) {
if (op == INSTR_SUB_F) {
op = INSTR_ADD_F;
right = normal;
}
}
- self->op = op;
- self->left = left;
- self->right = right;
- self->right_first = false;
+ self->m_op = op;
+ self->m_left = left;
+ self->m_right = right;
+ self->m_right_first = false;
ast_propagate_effects(self, left);
ast_propagate_effects(self, right);
if (op >= INSTR_EQ_F && op <= INSTR_GT)
- self->vtype = TYPE_FLOAT;
+ self->m_vtype = TYPE_FLOAT;
else if (op == INSTR_AND || op == INSTR_OR) {
if (OPTS_FLAG(PERL_LOGIC))
ast_type_adopt(self, right);
else
- self->vtype = TYPE_FLOAT;
+ self->m_vtype = TYPE_FLOAT;
}
else if (op == INSTR_BITAND || op == INSTR_BITOR)
- self->vtype = TYPE_FLOAT;
+ self->m_vtype = TYPE_FLOAT;
else if (op == INSTR_MUL_VF || op == INSTR_MUL_FV)
- self->vtype = TYPE_VECTOR;
+ self->m_vtype = TYPE_VECTOR;
else if (op == INSTR_MUL_V)
- self->vtype = TYPE_FLOAT;
+ self->m_vtype = TYPE_FLOAT;
else
- self->vtype = left->vtype;
+ self->m_vtype = left->m_vtype;
/* references all */
- self->refs = AST_REF_ALL;
+ self->m_refs = AST_REF_ALL;
return self;
}
void ast_binary_delete(ast_binary *self)
{
- if (self->refs & AST_REF_LEFT) ast_unref(self->left);
- if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
+ if (self->m_refs & AST_REF_LEFT) ast_unref(self->m_left);
+ if (self->m_refs & AST_REF_RIGHT) ast_unref(self->m_right);
ast_expression_delete((ast_expression*)self);
self->~ast_binary();
ast_instantiate(ast_binstore, ctx, ast_binstore_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binstore_codegen);
- ast_side_effects(self) = true;
+ self->m_side_effects = true;
- self->opstore = storop;
- self->opbin = op;
- self->dest = left;
- self->source = right;
+ self->m_opstore = storop;
+ self->m_opbin = op;
+ self->m_dest = left;
+ self->m_source = right;
- self->keep_dest = false;
+ self->m_keep_dest = false;
ast_type_adopt(self, left);
return self;
void ast_binstore_delete(ast_binstore *self)
{
- if (!self->keep_dest)
- ast_unref(self->dest);
- ast_unref(self->source);
+ if (!self->m_keep_dest)
+ ast_unref(self->m_dest);
+ ast_unref(self->m_source);
ast_expression_delete((ast_expression*)self);
self->~ast_binstore();
mem_d(self);
ast_instantiate(ast_unary, ctx, ast_unary_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_unary_codegen);
- self->op = op;
- self->operand = expr;
+ self->m_op = op;
+ self->m_operand = expr;
if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
- ast_unary *prev = (ast_unary*)((ast_unary*)expr)->operand;
+ ast_unary *prev = (ast_unary*)((ast_unary*)expr)->m_operand;
/* Handle for double negation */
- if (((ast_unary*)expr)->op == op)
- prev = (ast_unary*)((ast_unary*)expr)->operand;
+ if (((ast_unary*)expr)->m_op == op)
+ prev = (ast_unary*)((ast_unary*)expr)->m_operand;
if (ast_istype(prev, ast_unary)) {
ast_expression_delete((ast_expression*)self);
ast_propagate_effects(self, expr);
if ((op >= INSTR_NOT_F && op <= INSTR_NOT_FNC) || op == VINSTR_NEG_F) {
- self->vtype = TYPE_FLOAT;
+ self->m_vtype = TYPE_FLOAT;
} else if (op == VINSTR_NEG_V) {
- self->vtype = TYPE_VECTOR;
+ self->m_vtype = TYPE_VECTOR;
} else {
compile_error(ctx, "cannot determine type of unary operation %s", util_instr_str[op]);
}
void ast_unary_delete(ast_unary *self)
{
- if (self->operand) ast_unref(self->operand);
+ if (self->m_operand) ast_unref(self->m_operand);
ast_expression_delete((ast_expression*)self);
self->~ast_unary();
mem_d(self);
ast_instantiate(ast_return, ctx, ast_return_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_return_codegen);
- self->operand = expr;
+ self->m_operand = expr;
if (expr)
ast_propagate_effects(self, expr);
void ast_return_delete(ast_return *self)
{
- if (self->operand)
- ast_unref(self->operand);
+ if (self->m_operand)
+ ast_unref(self->m_operand);
ast_expression_delete((ast_expression*)self);
self->~ast_return();
mem_d(self);
ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field)
{
- if (field->vtype != TYPE_FIELD) {
+ if (field->m_vtype != TYPE_FIELD) {
compile_error(ctx, "ast_entfield_new with expression not of type field");
return nullptr;
}
- return ast_entfield_new_force(ctx, entity, field, field->next);
+ return ast_entfield_new_force(ctx, entity, field, field->m_next);
}
ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype)
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen);
- self->entity = entity;
- self->field = field;
+ self->m_entity = entity;
+ self->m_field = field;
ast_propagate_effects(self, entity);
ast_propagate_effects(self, field);
void ast_entfield_delete(ast_entfield *self)
{
- ast_unref(self->entity);
- ast_unref(self->field);
+ ast_unref(self->m_entity);
+ ast_unref(self->m_field);
ast_expression_delete((ast_expression*)self);
self->~ast_entfield();
mem_d(self);
return nullptr;
}
- if (owner->vtype != TYPE_VECTOR &&
- owner->vtype != TYPE_FIELD) {
- compile_error(ctx, "member-access on an invalid owner of type %s", type_name[owner->vtype]);
+ if (owner->m_vtype != TYPE_VECTOR &&
+ owner->m_vtype != TYPE_FIELD) {
+ compile_error(ctx, "member-access on an invalid owner of type %s", type_name[owner->m_vtype]);
mem_d(self);
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
- self->keep_node = true; /* keep */
+ self->m_keep_node = true; /* keep */
- if (owner->vtype == TYPE_VECTOR) {
- self->vtype = TYPE_FLOAT;
- self->next = nullptr;
+ if (owner->m_vtype == TYPE_VECTOR) {
+ self->m_vtype = TYPE_FLOAT;
+ self->m_next = nullptr;
} else {
- self->vtype = TYPE_FIELD;
- self->next = ast_shallow_type(ctx, TYPE_FLOAT);
+ self->m_vtype = TYPE_FIELD;
+ self->m_next = ast_shallow_type(ctx, TYPE_FLOAT);
}
- self->rvalue = false;
- self->owner = owner;
+ self->m_rvalue = false;
+ self->m_owner = owner;
ast_propagate_effects(self, owner);
- self->field = field;
+ self->m_field = field;
if (name)
- self->name = util_strdup(name);
+ self->m_name = util_strdup(name);
else
- self->name = nullptr;
+ self->m_name = nullptr;
return self;
}
/* The owner is always an ast_value, which has .keep_node=true,
* also: ast_members are usually deleted after the owner, thus
* this will cause invalid access
- ast_unref(self->owner);
+ ast_unref(self->m_owner);
* once we allow (expression).x to access a vector-member, we need
* to change this: preferably by creating an alternate ast node for this
* purpose that is not garbage-collected.
*/
ast_expression_delete((ast_expression*)self);
- mem_d(self->name);
+ mem_d(self->m_name);
self->~ast_member();
mem_d(self);
}
bool ast_member_set_name(ast_member *self, const char *name)
{
- if (self->name)
- mem_d((void*)self->name);
- self->name = util_strdup(name);
- return !!self->name;
+ if (self->m_name)
+ mem_d((void*)self->m_name);
+ self->m_name = util_strdup(name);
+ return !!self->m_name;
}
ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index)
ast_expression *outtype;
ast_instantiate(ast_array_index, ctx, ast_array_index_delete);
- outtype = array->next;
+ outtype = array->m_next;
if (!outtype) {
mem_d(self);
/* Error: field has no type... */
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_array_index_codegen);
- self->array = array;
- self->index = index;
+ self->m_array = array;
+ self->m_index = index;
ast_propagate_effects(self, array);
ast_propagate_effects(self, index);
ast_type_adopt(self, outtype);
- if (array->vtype == TYPE_FIELD && outtype->vtype == TYPE_ARRAY) {
- if (self->vtype != TYPE_ARRAY) {
- compile_error(ast_ctx(self), "array_index node on type");
+ if (array->m_vtype == TYPE_FIELD && outtype->m_vtype == TYPE_ARRAY) {
+ if (self->m_vtype != TYPE_ARRAY) {
+ compile_error(self->m_context, "array_index node on type");
ast_array_index_delete(self);
return nullptr;
}
- self->array = outtype;
- self->vtype = TYPE_FIELD;
+ self->m_array = outtype;
+ self->m_vtype = TYPE_FIELD;
}
return self;
void ast_array_index_delete(ast_array_index *self)
{
- if (self->array)
- ast_unref(self->array);
- if (self->index)
- ast_unref(self->index);
+ if (self->m_array)
+ ast_unref(self->m_array);
+ if (self->m_index)
+ ast_unref(self->m_index);
ast_expression_delete((ast_expression*)self);
mem_d(self);
}
{
ast_instantiate(ast_argpipe, ctx, ast_argpipe_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_argpipe_codegen);
- self->index = index;
- self->vtype = TYPE_NOEXPR;
+ self->m_index = index;
+ self->m_vtype = TYPE_NOEXPR;
return self;
}
void ast_argpipe_delete(ast_argpipe *self)
{
- if (self->index)
- ast_unref(self->index);
+ if (self->m_index)
+ ast_unref(self->m_index);
ast_expression_delete((ast_expression*)self);
self->~ast_argpipe();
mem_d(self);
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ifthen_codegen);
- self->cond = cond;
- self->on_true = ontrue;
- self->on_false = onfalse;
+ self->m_cond = cond;
+ self->m_on_true = ontrue;
+ self->m_on_false = onfalse;
ast_propagate_effects(self, cond);
if (ontrue)
ast_propagate_effects(self, ontrue);
void ast_ifthen_delete(ast_ifthen *self)
{
- ast_unref(self->cond);
- if (self->on_true)
- ast_unref(self->on_true);
- if (self->on_false)
- ast_unref(self->on_false);
+ ast_unref(self->m_cond);
+ if (self->m_on_true)
+ ast_unref(self->m_on_true);
+ if (self->m_on_false)
+ ast_unref(self->m_on_false);
ast_expression_delete((ast_expression*)self);
self->~ast_ifthen();
mem_d(self);
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ternary_codegen);
- self->cond = cond;
- self->on_true = ontrue;
- self->on_false = onfalse;
+ self->m_cond = cond;
+ self->m_on_true = ontrue;
+ self->m_on_false = onfalse;
ast_propagate_effects(self, cond);
ast_propagate_effects(self, ontrue);
ast_propagate_effects(self, onfalse);
- if (ontrue->vtype == TYPE_NIL)
+ if (ontrue->m_vtype == TYPE_NIL)
exprtype = onfalse;
ast_type_adopt(self, exprtype);
/* the if()s are only there because computed-gotos can set them
* to nullptr
*/
- if (self->cond) ast_unref(self->cond);
- if (self->on_true) ast_unref(self->on_true);
- if (self->on_false) ast_unref(self->on_false);
+ if (self->m_cond) ast_unref(self->m_cond);
+ if (self->m_on_true) ast_unref(self->m_on_true);
+ if (self->m_on_false) ast_unref(self->m_on_false);
ast_expression_delete((ast_expression*)self);
self->~ast_ternary();
mem_d(self);
ast_instantiate(ast_loop, ctx, ast_loop_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_loop_codegen);
- self->initexpr = initexpr;
- self->precond = precond;
- self->postcond = postcond;
- self->increment = increment;
- self->body = body;
+ self->m_initexpr = initexpr;
+ self->m_precond = precond;
+ self->m_postcond = postcond;
+ self->m_increment = increment;
+ self->m_body = body;
- self->pre_not = pre_not;
- self->post_not = post_not;
+ self->m_pre_not = pre_not;
+ self->m_post_not = post_not;
if (initexpr)
ast_propagate_effects(self, initexpr);
void ast_loop_delete(ast_loop *self)
{
- if (self->initexpr)
- ast_unref(self->initexpr);
- if (self->precond)
- ast_unref(self->precond);
- if (self->postcond)
- ast_unref(self->postcond);
- if (self->increment)
- ast_unref(self->increment);
- if (self->body)
- ast_unref(self->body);
+ if (self->m_initexpr)
+ ast_unref(self->m_initexpr);
+ if (self->m_precond)
+ ast_unref(self->m_precond);
+ if (self->m_postcond)
+ ast_unref(self->m_postcond);
+ if (self->m_increment)
+ ast_unref(self->m_increment);
+ if (self->m_body)
+ ast_unref(self->m_body);
ast_expression_delete((ast_expression*)self);
self->~ast_loop();
mem_d(self);
ast_instantiate(ast_breakcont, ctx, ast_breakcont_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_breakcont_codegen);
- self->is_continue = iscont;
- self->levels = levels;
+ self->m_is_continue = iscont;
+ self->m_levels = levels;
return self;
}
ast_instantiate(ast_switch, ctx, ast_switch_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen);
- self->operand = op;
+ self->m_operand = op;
ast_propagate_effects(self, op);
void ast_switch_delete(ast_switch *self)
{
- ast_unref(self->operand);
+ ast_unref(self->m_operand);
- for (auto &it : self->cases) {
- if (it.value)
- ast_unref(it.value);
- ast_unref(it.code);
+ for (auto &it : self->m_cases) {
+ if (it.m_value)
+ ast_unref(it.m_value);
+ ast_unref(it.m_code);
}
ast_expression_delete((ast_expression*)self);
ast_instantiate(ast_label, ctx, ast_label_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen);
- self->vtype = TYPE_NOEXPR;
+ self->m_vtype = TYPE_NOEXPR;
- self->name = util_strdup(name);
- self->irblock = nullptr;
- self->undefined = undefined;
+ self->m_name = util_strdup(name);
+ self->m_irblock = nullptr;
+ self->m_undefined = undefined;
return self;
}
void ast_label_delete(ast_label *self)
{
- mem_d((void*)self->name);
+ mem_d((void*)self->m_name);
ast_expression_delete((ast_expression*)self);
self->~ast_label();
mem_d(self);
static void ast_label_register_goto(ast_label *self, ast_goto *g)
{
- self->gotos.push_back(g);
+ self->m_gotos.push_back(g);
}
ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
ast_instantiate(ast_goto, ctx, ast_goto_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_goto_codegen);
- self->name = util_strdup(name);
- self->target = nullptr;
- self->irblock_from = nullptr;
+ self->m_name = util_strdup(name);
+ self->m_target = nullptr;
+ self->m_irblock_from = nullptr;
return self;
}
void ast_goto_delete(ast_goto *self)
{
- mem_d((void*)self->name);
+ mem_d((void*)self->m_name);
ast_expression_delete((ast_expression*)self);
self->~ast_goto();
mem_d(self);
void ast_goto_set_label(ast_goto *self, ast_label *label)
{
- self->target = label;
+ self->m_target = label;
}
ast_state* ast_state_new(lex_ctx_t ctx, ast_expression *frame, ast_expression *think)
{
ast_instantiate(ast_state, ctx, ast_state_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_state_codegen);
- self->framenum = frame;
- self->nextthink = think;
+ self->m_framenum = frame;
+ self->m_nextthink = think;
return self;
}
void ast_state_delete(ast_state *self)
{
- if (self->framenum)
- ast_unref(self->framenum);
- if (self->nextthink)
- ast_unref(self->nextthink);
+ if (self->m_framenum)
+ ast_unref(self->m_framenum);
+ if (self->m_nextthink)
+ ast_unref(self->m_nextthink);
ast_expression_delete((ast_expression*)self);
self->~ast_state();
ast_expression *funcexpr)
{
ast_instantiate(ast_call, ctx, ast_call_delete);
- if (!funcexpr->next) {
+ if (!funcexpr->m_next) {
compile_error(ctx, "not a function");
mem_d(self);
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_call_codegen);
- ast_side_effects(self) = true;
+ self->m_side_effects = true;
- self->func = funcexpr;
- self->va_count = nullptr;
+ self->m_func = funcexpr;
+ self->m_va_count = nullptr;
- ast_type_adopt(self, funcexpr->next);
+ ast_type_adopt(self, funcexpr->m_next);
return self;
}
void ast_call_delete(ast_call *self)
{
- for (auto &it : self->params)
+ for (auto &it : self->m_params)
ast_unref(it);
- if (self->func)
- ast_unref(self->func);
+ if (self->m_func)
+ ast_unref(self->m_func);
- if (self->va_count)
- ast_unref(self->va_count);
+ if (self->m_va_count)
+ ast_unref(self->m_va_count);
ast_expression_delete((ast_expression*)self);
self->~ast_call();
ast_type_to_string(va_type, tgot, sizeof(tgot));
ast_type_to_string(exp_type, texp, sizeof(texp));
if (OPTS_FLAG(UNSAFE_VARARGS)) {
- if (compile_warning(ast_ctx(self), WARN_UNSAFE_TYPES,
+ if (compile_warning(self->m_context, WARN_UNSAFE_TYPES,
"piped variadic argument differs in type: constrained to type %s, expected type %s",
tgot, texp))
return false;
} else {
- compile_error(ast_ctx(self),
+ compile_error(self->m_context,
"piped variadic argument differs in type: constrained to type %s, expected type %s",
tgot, texp);
return false;
{
ast_type_to_string(exp_type, texp, sizeof(texp));
if (OPTS_FLAG(UNSAFE_VARARGS)) {
- if (compile_warning(ast_ctx(self), WARN_UNSAFE_TYPES,
+ if (compile_warning(self->m_context, WARN_UNSAFE_TYPES,
"piped variadic argument may differ in type: expected type %s",
texp))
return false;
} else {
- compile_error(ast_ctx(self),
+ compile_error(self->m_context,
"piped variadic argument may differ in type: expected type %s",
texp);
return false;
char tgot[1024];
size_t i;
bool retval = true;
- const ast_expression *func = self->func;
- size_t count = self->params.size();
- if (count > func->type_params.size())
- count = func->type_params.size();
+ const ast_expression *func = self->m_func;
+ size_t count = self->m_params.size();
+ if (count > func->m_type_params.size())
+ count = func->m_type_params.size();
for (i = 0; i < count; ++i) {
- if (ast_istype(self->params[i], ast_argpipe)) {
+ if (ast_istype(self->m_params[i], ast_argpipe)) {
/* warn about type safety instead */
if (i+1 != count) {
- compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call");
+ compile_error(self->m_context, "argpipe must be the last parameter to a function call");
return false;
}
- if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->type_params[i]))
+ if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->m_type_params[i]))
retval = false;
}
- else if (!ast_compare_type(self->params[i], (ast_expression*)(func->type_params[i])))
+ else if (!ast_compare_type(self->m_params[i], (ast_expression*)(func->m_type_params[i])))
{
- ast_type_to_string(self->params[i], tgot, sizeof(tgot));
- ast_type_to_string((ast_expression*)func->type_params[i], texp, sizeof(texp));
- compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
+ ast_type_to_string(self->m_params[i], tgot, sizeof(tgot));
+ ast_type_to_string((ast_expression*)func->m_type_params[i], texp, sizeof(texp));
+ compile_error(self->m_context, "invalid type for parameter %u in function call: expected %s, got %s",
(unsigned int)(i+1), texp, tgot);
/* we don't immediately return */
retval = false;
}
}
- count = self->params.size();
- if (count > func->type_params.size() && func->varparam) {
+ count = self->m_params.size();
+ if (count > func->m_type_params.size() && func->m_varparam) {
for (; i < count; ++i) {
- if (ast_istype(self->params[i], ast_argpipe)) {
+ if (ast_istype(self->m_params[i], ast_argpipe)) {
/* warn about type safety instead */
if (i+1 != count) {
- compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call");
+ compile_error(self->m_context, "argpipe must be the last parameter to a function call");
return false;
}
- if (!ast_call_check_vararg(self, va_type, func->varparam))
+ if (!ast_call_check_vararg(self, va_type, func->m_varparam))
retval = false;
}
- else if (!ast_compare_type(self->params[i], func->varparam))
+ else if (!ast_compare_type(self->m_params[i], func->m_varparam))
{
- ast_type_to_string(self->params[i], tgot, sizeof(tgot));
- ast_type_to_string(func->varparam, texp, sizeof(texp));
- compile_error(ast_ctx(self), "invalid type for variadic parameter %u in function call: expected %s, got %s",
+ ast_type_to_string(self->m_params[i], tgot, sizeof(tgot));
+ ast_type_to_string(func->m_varparam, texp, sizeof(texp));
+ compile_error(self->m_context, "invalid type for variadic parameter %u in function call: expected %s, got %s",
(unsigned int)(i+1), texp, tgot);
/* we don't immediately return */
retval = false;
ast_instantiate(ast_store, ctx, ast_store_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_store_codegen);
- ast_side_effects(self) = true;
+ self->m_side_effects = true;
- self->op = op;
- self->dest = dest;
- self->source = source;
+ self->m_op = op;
+ self->m_dest = dest;
+ self->m_source = source;
ast_type_adopt(self, dest);
void ast_store_delete(ast_store *self)
{
- ast_unref(self->dest);
- ast_unref(self->source);
+ ast_unref(self->m_dest);
+ ast_unref(self->m_source);
ast_expression_delete((ast_expression*)self);
self->~ast_store();
mem_d(self);
bool ast_block_add_expr(ast_block *self, ast_expression *e)
{
ast_propagate_effects(self, e);
- self->exprs.push_back(e);
- if (self->next) {
- ast_delete(self->next);
- self->next = nullptr;
+ self->m_exprs.push_back(e);
+ if (self->m_next) {
+ ast_delete(self->m_next);
+ self->m_next = nullptr;
}
ast_type_adopt(self, e);
return true;
void ast_block_collect(ast_block *self, ast_expression *expr)
{
- self->collect.push_back(expr);
- expr->keep_node = true;
+ self->m_collect.push_back(expr);
+ expr->m_keep_node = true;
}
void ast_block_delete(ast_block *self)
{
- for (auto &it : self->exprs) ast_unref(it);
- for (auto &it : self->locals) ast_delete(it);
- for (auto &it : self->collect) ast_delete(it);
+ for (auto &it : self->m_exprs) ast_unref(it);
+ for (auto &it : self->m_locals) ast_delete(it);
+ for (auto &it : self->m_collect) ast_delete(it);
ast_expression_delete((ast_expression*)self);
self->~ast_block();
mem_d(self);
void ast_block_set_type(ast_block *self, ast_expression *from)
{
- if (self->next)
- ast_delete(self->next);
+ if (self->m_next)
+ ast_delete(self->m_next);
ast_type_adopt(self, from);
}
ast_instantiate(ast_function, ctx, ast_function_delete);
if (!vtype) {
- compile_error(ast_ctx(self), "internal error: ast_function_new condition 0");
+ compile_error(self->m_context, "internal error: ast_function_new condition 0");
goto cleanup;
- } else if (vtype->hasvalue || vtype->vtype != TYPE_FUNCTION) {
- compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
+ } else if (vtype->m_hasvalue || vtype->m_vtype != TYPE_FUNCTION) {
+ compile_error(self->m_context, "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
(int)!vtype,
- (int)vtype->hasvalue,
- vtype->vtype);
+ (int)vtype->m_hasvalue,
+ vtype->m_vtype);
goto cleanup;
}
- self->function_type = vtype;
- self->name = name ? util_strdup(name) : nullptr;
+ self->m_function_type = vtype;
+ self->m_name = name ? util_strdup(name) : nullptr;
- self->labelcount = 0;
- self->builtin = 0;
+ self->m_labelcount = 0;
+ self->m_builtin = 0;
- self->ir_func = nullptr;
- self->curblock = nullptr;
+ self->m_ir_func = nullptr;
+ self->m_curblock = nullptr;
- vtype->hasvalue = true;
- vtype->constval.vfunc = self;
+ vtype->m_hasvalue = true;
+ vtype->m_constval.vfunc = self;
- self->varargs = nullptr;
- self->argc = nullptr;
- self->fixedparams = nullptr;
- self->return_value = nullptr;
- self->static_count = 0;
+ self->m_varargs = nullptr;
+ self->m_argc = nullptr;
+ self->m_fixedparams = nullptr;
+ self->m_return_value = nullptr;
+ self->m_static_count = 0;
return self;
void ast_function_delete(ast_function *self)
{
- if (self->name)
- mem_d((void*)self->name);
- if (self->function_type) {
- /* ast_value_delete(self->function_type); */
- self->function_type->hasvalue = false;
- self->function_type->constval.vfunc = nullptr;
+ if (self->m_name)
+ mem_d((void*)self->m_name);
+ if (self->m_function_type) {
+ /* ast_value_delete(self->m_function_type); */
+ self->m_function_type->m_hasvalue = false;
+ self->m_function_type->m_constval.vfunc = nullptr;
/* We use unref - if it was stored in a global table it is supposed
* to be deleted from *there*
*/
- ast_unref(self->function_type);
+ ast_unref(self->m_function_type);
}
- for (auto &it : self->static_names)
+ for (auto &it : self->m_static_names)
mem_d(it);
// FIXME::DELME:: unique_ptr used on ast_block
- //for (auto &it : self->blocks)
+ //for (auto &it : self->m_blocks)
// ast_delete(it);
- if (self->varargs)
- ast_delete(self->varargs);
- if (self->argc)
- ast_delete(self->argc);
- if (self->fixedparams)
- ast_unref(self->fixedparams);
- if (self->return_value)
- ast_unref(self->return_value);
+ if (self->m_varargs)
+ ast_delete(self->m_varargs);
+ if (self->m_argc)
+ ast_delete(self->m_argc);
+ if (self->m_fixedparams)
+ ast_unref(self->m_fixedparams);
+ if (self->m_return_value)
+ ast_unref(self->m_return_value);
self->~ast_function();
mem_d(self);
}
return nullptr;
}
- id = (self->labelcount++);
+ id = (self->m_labelcount++);
len = strlen(prefix);
- from = self->labelbuf + sizeof(self->labelbuf)-1;
+ from = self->m_labelbuf + sizeof(self->m_labelbuf)-1;
*from-- = 0;
do {
*from-- = (id%10) + '0';
static void _ast_codegen_output_type(ast_expression *self, ir_value *out)
{
- if (out->vtype == TYPE_FIELD)
- out->fieldtype = self->next->vtype;
- if (out->vtype == TYPE_FUNCTION)
- out->outtype = self->next->vtype;
+ if (out->m_vtype == TYPE_FIELD)
+ out->m_fieldtype = self->m_next->m_vtype;
+ if (out->m_vtype == TYPE_FUNCTION)
+ out->m_outtype = self->m_next->m_vtype;
}
#define codegen_output_type(a,o) (_ast_codegen_output_type(static_cast<ast_expression*>((a)),(o)))
{
(void)func;
(void)lvalue;
- if (self->vtype == TYPE_NIL) {
- *out = func->ir_func->owner->nil;
+ if (self->m_vtype == TYPE_NIL) {
+ *out = func->m_ir_func->m_owner->m_nil;
return true;
}
/* NOTE: This is the codegen for a variable used in an
* and the ast-user should take care of ast_global_codegen to be used
* on all the globals.
*/
- if (!self->ir_v) {
+ if (!self->m_ir_v) {
char tname[1024]; /* typename is reserved in C++ */
ast_type_to_string((ast_expression*)self, tname, sizeof(tname));
- compile_error(ast_ctx(self), "ast_value used before generated %s %s", tname, self->name);
+ compile_error(self->m_context, "ast_value used before generated %s %s", tname, self->m_name);
return false;
}
- *out = self->ir_v;
+ *out = self->m_ir_v;
return true;
}
static bool ast_global_array_set(ast_value *self)
{
- size_t count = self->initlist.size();
+ size_t count = self->m_initlist.size();
size_t i;
- if (count > self->count) {
- compile_error(ast_ctx(self), "too many elements in initializer");
- count = self->count;
+ if (count > self->m_count) {
+ compile_error(self->m_context, "too many elements in initializer");
+ count = self->m_count;
}
- else if (count < self->count) {
+ else if (count < self->m_count) {
/* add this?
- compile_warning(ast_ctx(self), "not all elements are initialized");
+ compile_warning(self->m_context, "not all elements are initialized");
*/
}
for (i = 0; i != count; ++i) {
- switch (self->next->vtype) {
+ switch (self->m_next->m_vtype) {
case TYPE_FLOAT:
- if (!ir_value_set_float(self->ir_values[i], self->initlist[i].vfloat))
+ if (!ir_value_set_float(self->m_ir_values[i], self->m_initlist[i].vfloat))
return false;
break;
case TYPE_VECTOR:
- if (!ir_value_set_vector(self->ir_values[i], self->initlist[i].vvec))
+ if (!ir_value_set_vector(self->m_ir_values[i], self->m_initlist[i].vvec))
return false;
break;
case TYPE_STRING:
- if (!ir_value_set_string(self->ir_values[i], self->initlist[i].vstring))
+ if (!ir_value_set_string(self->m_ir_values[i], self->m_initlist[i].vstring))
return false;
break;
case TYPE_ARRAY:
/* we don't support them in any other place yet either */
- compile_error(ast_ctx(self), "TODO: nested arrays");
+ compile_error(self->m_context, "TODO: nested arrays");
return false;
case TYPE_FUNCTION:
/* this requiers a bit more work - similar to the fields I suppose */
- compile_error(ast_ctx(self), "global of type function not properly generated");
+ compile_error(self->m_context, "global of type function not properly generated");
return false;
case TYPE_FIELD:
- if (!self->initlist[i].vfield) {
- compile_error(ast_ctx(self), "field constant without vfield set");
+ if (!self->m_initlist[i].vfield) {
+ compile_error(self->m_context, "field constant without vfield set");
return false;
}
- if (!self->initlist[i].vfield->ir_v) {
- compile_error(ast_ctx(self), "field constant generated before its field");
+ if (!self->m_initlist[i].vfield->m_ir_v) {
+ compile_error(self->m_context, "field constant generated before its field");
return false;
}
- if (!ir_value_set_field(self->ir_values[i], self->initlist[i].vfield->ir_v))
+ if (!ir_value_set_field(self->m_ir_values[i], self->m_initlist[i].vfield->m_ir_v))
return false;
break;
default:
- compile_error(ast_ctx(self), "TODO: global constant type %i", self->vtype);
+ compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
break;
}
}
static bool check_array(ast_value *self, ast_value *array)
{
- if (array->flags & AST_FLAG_ARRAY_INIT && array->initlist.empty()) {
- compile_error(ast_ctx(self), "array without size: %s", self->name);
+ if (array->m_flags & AST_FLAG_ARRAY_INIT && array->m_initlist.empty()) {
+ compile_error(self->m_context, "array without size: %s", self->m_name);
return false;
}
/* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
- if (!array->count || array->count > OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE)) {
- compile_error(ast_ctx(self), "Invalid array of size %lu", (unsigned long)array->count);
+ if (!array->m_count || array->m_count > OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE)) {
+ compile_error(self->m_context, "Invalid array of size %lu", (unsigned long)array->m_count);
return false;
}
return true;
{
ir_value *v = nullptr;
- if (self->vtype == TYPE_NIL) {
- compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
+ if (self->m_vtype == TYPE_NIL) {
+ compile_error(self->m_context, "internal error: trying to generate a variable of TYPE_NIL");
return false;
}
- if (self->hasvalue && self->vtype == TYPE_FUNCTION)
+ if (self->m_hasvalue && self->m_vtype == TYPE_FUNCTION)
{
- ir_function *func = ir_builder_create_function(ir, self->name, self->next->vtype);
+ ir_function *func = ir_builder_create_function(ir, self->m_name, self->m_next->m_vtype);
if (!func)
return false;
- func->context = ast_ctx(self);
- func->value->context = ast_ctx(self);
-
- self->constval.vfunc->ir_func = func;
- self->ir_v = func->value;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
- if (self->flags & AST_FLAG_ERASEABLE)
- self->ir_v->flags |= IR_FLAG_ERASABLE;
- if (self->flags & AST_FLAG_BLOCK_COVERAGE)
- func->flags |= IR_FLAG_BLOCK_COVERAGE;
+ func->m_context = self->m_context;
+ func->m_value->m_context = self->m_context;
+
+ self->m_constval.vfunc->m_ir_func = func;
+ self->m_ir_v = func->m_value;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->m_flags & AST_FLAG_ERASEABLE)
+ self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+ if (self->m_flags & AST_FLAG_BLOCK_COVERAGE)
+ func->m_flags |= IR_FLAG_BLOCK_COVERAGE;
/* The function is filled later on ast_function_codegen... */
return true;
}
- if (isfield && self->vtype == TYPE_FIELD) {
- ast_expression *fieldtype = self->next;
+ if (isfield && self->m_vtype == TYPE_FIELD) {
+ ast_expression *fieldtype = self->m_next;
- if (self->hasvalue) {
- compile_error(ast_ctx(self), "TODO: constant field pointers with value");
+ if (self->m_hasvalue) {
+ compile_error(self->m_context, "TODO: constant field pointers with value");
goto error;
}
- if (fieldtype->vtype == TYPE_ARRAY) {
+ if (fieldtype->m_vtype == TYPE_ARRAY) {
size_t ai;
char *name;
size_t namelen;
ast_value *array = (ast_value*)fieldtype;
if (!ast_istype(fieldtype, ast_value)) {
- compile_error(ast_ctx(self), "internal error: ast_value required");
+ compile_error(self->m_context, "internal error: ast_value required");
return false;
}
if (!check_array(self, array))
return false;
- elemtype = array->next;
- vtype = elemtype->vtype;
+ elemtype = array->m_next;
+ vtype = elemtype->m_vtype;
- v = ir_builder_create_field(ir, self->name, vtype);
+ v = ir_builder_create_field(ir, self->m_name, vtype);
if (!v) {
- compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name);
+ compile_error(self->m_context, "ir_builder_create_global failed on `%s`", self->m_name);
return false;
}
- v->context = ast_ctx(self);
- v->unique_life = true;
- v->locked = true;
- array->ir_v = self->ir_v = v;
+ v->m_context = self->m_context;
+ v->m_unique_life = true;
+ v->m_locked = true;
+ array->m_ir_v = self->m_ir_v = v;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
- if (self->flags & AST_FLAG_ERASEABLE)
- self->ir_v->flags |= IR_FLAG_ERASABLE;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->m_flags & AST_FLAG_ERASEABLE)
+ self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
- namelen = strlen(self->name);
+ namelen = strlen(self->m_name);
name = (char*)mem_a(namelen + 16);
- util_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->m_name, namelen);
- array->ir_values = (ir_value**)mem_a(sizeof(array->ir_values[0]) * array->count);
- array->ir_values[0] = v;
- for (ai = 1; ai < array->count; ++ai) {
+ array->m_ir_values = (ir_value**)mem_a(sizeof(array->m_ir_values[0]) * array->m_count);
+ array->m_ir_values[0] = v;
+ for (ai = 1; ai < array->m_count; ++ai) {
util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
- array->ir_values[ai] = ir_builder_create_field(ir, name, vtype);
- if (!array->ir_values[ai]) {
+ array->m_ir_values[ai] = ir_builder_create_field(ir, name, vtype);
+ if (!array->m_ir_values[ai]) {
mem_d(name);
- compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", name);
+ compile_error(self->m_context, "ir_builder_create_global failed on `%s`", name);
return false;
}
- array->ir_values[ai]->context = ast_ctx(self);
- array->ir_values[ai]->unique_life = true;
- array->ir_values[ai]->locked = true;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
+ array->m_ir_values[ai]->m_context = self->m_context;
+ array->m_ir_values[ai]->m_unique_life = true;
+ array->m_ir_values[ai]->m_locked = true;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
}
mem_d(name);
}
else
{
- v = ir_builder_create_field(ir, self->name, self->next->vtype);
+ v = ir_builder_create_field(ir, self->m_name, self->m_next->m_vtype);
if (!v)
return false;
- v->context = ast_ctx(self);
- self->ir_v = v;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+ v->m_context = self->m_context;
+ self->m_ir_v = v;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
- if (self->flags & AST_FLAG_ERASEABLE)
- self->ir_v->flags |= IR_FLAG_ERASABLE;
+ if (self->m_flags & AST_FLAG_ERASEABLE)
+ self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
}
return true;
}
- if (self->vtype == TYPE_ARRAY) {
+ if (self->m_vtype == TYPE_ARRAY) {
size_t ai;
char *name;
size_t namelen;
- ast_expression *elemtype = self->next;
- qc_type vtype = elemtype->vtype;
+ ast_expression *elemtype = self->m_next;
+ qc_type vtype = elemtype->m_vtype;
- if (self->flags & AST_FLAG_ARRAY_INIT && !self->count) {
- compile_error(ast_ctx(self), "array `%s' has no size", self->name);
+ if (self->m_flags & AST_FLAG_ARRAY_INIT && !self->m_count) {
+ compile_error(self->m_context, "array `%s' has no size", self->m_name);
return false;
}
if (!check_array(self, self))
return false;
- v = ir_builder_create_global(ir, self->name, vtype);
+ v = ir_builder_create_global(ir, self->m_name, vtype);
if (!v) {
- compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", self->name);
+ compile_error(self->m_context, "ir_builder_create_global failed `%s`", self->m_name);
return false;
}
- v->context = ast_ctx(self);
- v->unique_life = true;
- v->locked = true;
+ v->m_context = self->m_context;
+ v->m_unique_life = true;
+ v->m_locked = true;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- v->flags |= IR_FLAG_INCLUDE_DEF;
- if (self->flags & AST_FLAG_ERASEABLE)
- self->ir_v->flags |= IR_FLAG_ERASABLE;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ v->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->m_flags & AST_FLAG_ERASEABLE)
+ self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
- namelen = strlen(self->name);
+ namelen = strlen(self->m_name);
name = (char*)mem_a(namelen + 16);
- util_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->m_name, namelen);
- self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->count);
- self->ir_values[0] = v;
- for (ai = 1; ai < self->count; ++ai) {
+ self->m_ir_values = (ir_value**)mem_a(sizeof(self->m_ir_values[0]) * self->m_count);
+ self->m_ir_values[0] = v;
+ for (ai = 1; ai < self->m_count; ++ai) {
util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
- self->ir_values[ai] = ir_builder_create_global(ir, name, vtype);
- if (!self->ir_values[ai]) {
+ self->m_ir_values[ai] = ir_builder_create_global(ir, name, vtype);
+ if (!self->m_ir_values[ai]) {
mem_d(name);
- compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", name);
+ compile_error(self->m_context, "ir_builder_create_global failed `%s`", name);
return false;
}
- self->ir_values[ai]->context = ast_ctx(self);
- self->ir_values[ai]->unique_life = true;
- self->ir_values[ai]->locked = true;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
+ self->m_ir_values[ai]->m_context = self->m_context;
+ self->m_ir_values[ai]->m_unique_life = true;
+ self->m_ir_values[ai]->m_locked = true;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
}
mem_d(name);
}
/* Arrays don't do this since there's no "array" value which spans across the
* whole thing.
*/
- v = ir_builder_create_global(ir, self->name, self->vtype);
+ v = ir_builder_create_global(ir, self->m_name, self->m_vtype);
if (!v) {
- compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name);
+ compile_error(self->m_context, "ir_builder_create_global failed on `%s`", self->m_name);
return false;
}
codegen_output_type(self, v);
- v->context = ast_ctx(self);
+ v->m_context = self->m_context;
}
/* link us to the ir_value */
- v->cvq = self->cvq;
- self->ir_v = v;
+ v->m_cvq = self->m_cvq;
+ self->m_ir_v = v;
- if (self->flags & AST_FLAG_INCLUDE_DEF)
- self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
- if (self->flags & AST_FLAG_ERASEABLE)
- self->ir_v->flags |= IR_FLAG_ERASABLE;
+ if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+ self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (self->m_flags & AST_FLAG_ERASEABLE)
+ self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
/* initialize */
- if (self->hasvalue) {
- switch (self->vtype)
+ if (self->m_hasvalue) {
+ switch (self->m_vtype)
{
case TYPE_FLOAT:
- if (!ir_value_set_float(v, self->constval.vfloat))
+ if (!ir_value_set_float(v, self->m_constval.vfloat))
goto error;
break;
case TYPE_VECTOR:
- if (!ir_value_set_vector(v, self->constval.vvec))
+ if (!ir_value_set_vector(v, self->m_constval.vvec))
goto error;
break;
case TYPE_STRING:
- if (!ir_value_set_string(v, self->constval.vstring))
+ if (!ir_value_set_string(v, self->m_constval.vstring))
goto error;
break;
case TYPE_ARRAY:
ast_global_array_set(self);
break;
case TYPE_FUNCTION:
- compile_error(ast_ctx(self), "global of type function not properly generated");
+ compile_error(self->m_context, "global of type function not properly generated");
goto error;
/* Cannot generate an IR value for a function,
* need a pointer pointing to a function rather.
*/
case TYPE_FIELD:
- if (!self->constval.vfield) {
- compile_error(ast_ctx(self), "field constant without vfield set");
+ if (!self->m_constval.vfield) {
+ compile_error(self->m_context, "field constant without vfield set");
goto error;
}
- if (!self->constval.vfield->ir_v) {
- compile_error(ast_ctx(self), "field constant generated before its field");
+ if (!self->m_constval.vfield->m_ir_v) {
+ compile_error(self->m_context, "field constant generated before its field");
goto error;
}
- if (!ir_value_set_field(v, self->constval.vfield->ir_v))
+ if (!ir_value_set_field(v, self->m_constval.vfield->m_ir_v))
goto error;
break;
default:
- compile_error(ast_ctx(self), "TODO: global constant type %i", self->vtype);
+ compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
break;
}
}
{
ir_value *v = nullptr;
- if (self->vtype == TYPE_NIL) {
- compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
+ if (self->m_vtype == TYPE_NIL) {
+ compile_error(self->m_context, "internal error: trying to generate a variable of TYPE_NIL");
return false;
}
- if (self->hasvalue && self->vtype == TYPE_FUNCTION)
+ if (self->m_hasvalue && self->m_vtype == TYPE_FUNCTION)
{
/* Do we allow local functions? I think not...
* this is NOT a function pointer atm.
return false;
}
- if (self->vtype == TYPE_ARRAY) {
+ if (self->m_vtype == TYPE_ARRAY) {
size_t ai;
char *name;
size_t namelen;
- ast_expression *elemtype = self->next;
- qc_type vtype = elemtype->vtype;
+ ast_expression *elemtype = self->m_next;
+ qc_type vtype = elemtype->m_vtype;
- func->flags |= IR_FLAG_HAS_ARRAYS;
+ func->m_flags |= IR_FLAG_HAS_ARRAYS;
- if (param && !(self->flags & AST_FLAG_IS_VARARG)) {
- compile_error(ast_ctx(self), "array-parameters are not supported");
+ if (param && !(self->m_flags & AST_FLAG_IS_VARARG)) {
+ compile_error(self->m_context, "array-parameters are not supported");
return false;
}
if (!check_array(self, self))
return false;
- self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->count);
- if (!self->ir_values) {
- compile_error(ast_ctx(self), "failed to allocate array values");
+ self->m_ir_values = (ir_value**)mem_a(sizeof(self->m_ir_values[0]) * self->m_count);
+ if (!self->m_ir_values) {
+ compile_error(self->m_context, "failed to allocate array values");
return false;
}
- v = ir_function_create_local(func, self->name, vtype, param);
+ v = ir_function_create_local(func, self->m_name, vtype, param);
if (!v) {
- compile_error(ast_ctx(self), "internal error: ir_function_create_local failed");
+ compile_error(self->m_context, "internal error: ir_function_create_local failed");
return false;
}
- v->context = ast_ctx(self);
- v->unique_life = true;
- v->locked = true;
+ v->m_context = self->m_context;
+ v->m_unique_life = true;
+ v->m_locked = true;
- namelen = strlen(self->name);
+ namelen = strlen(self->m_name);
name = (char*)mem_a(namelen + 16);
- util_strncpy(name, self->name, namelen);
+ util_strncpy(name, self->m_name, namelen);
- self->ir_values[0] = v;
- for (ai = 1; ai < self->count; ++ai) {
+ self->m_ir_values[0] = v;
+ for (ai = 1; ai < self->m_count; ++ai) {
util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
- self->ir_values[ai] = ir_function_create_local(func, name, vtype, param);
- if (!self->ir_values[ai]) {
- compile_error(ast_ctx(self), "internal_error: ir_builder_create_global failed on `%s`", name);
+ self->m_ir_values[ai] = ir_function_create_local(func, name, vtype, param);
+ if (!self->m_ir_values[ai]) {
+ compile_error(self->m_context, "internal_error: ir_builder_create_global failed on `%s`", name);
return false;
}
- self->ir_values[ai]->context = ast_ctx(self);
- self->ir_values[ai]->unique_life = true;
- self->ir_values[ai]->locked = true;
+ self->m_ir_values[ai]->m_context = self->m_context;
+ self->m_ir_values[ai]->m_unique_life = true;
+ self->m_ir_values[ai]->m_locked = true;
}
mem_d(name);
}
else
{
- v = ir_function_create_local(func, self->name, self->vtype, param);
+ v = ir_function_create_local(func, self->m_name, self->m_vtype, param);
if (!v)
return false;
codegen_output_type(self, v);
- v->context = ast_ctx(self);
+ v->m_context = self->m_context;
}
/* A constant local... hmmm...
* I suppose the IR will have to deal with this
*/
- if (self->hasvalue) {
- switch (self->vtype)
+ if (self->m_hasvalue) {
+ switch (self->m_vtype)
{
case TYPE_FLOAT:
- if (!ir_value_set_float(v, self->constval.vfloat))
+ if (!ir_value_set_float(v, self->m_constval.vfloat))
goto error;
break;
case TYPE_VECTOR:
- if (!ir_value_set_vector(v, self->constval.vvec))
+ if (!ir_value_set_vector(v, self->m_constval.vvec))
goto error;
break;
case TYPE_STRING:
- if (!ir_value_set_string(v, self->constval.vstring))
+ if (!ir_value_set_string(v, self->m_constval.vstring))
goto error;
break;
default:
- compile_error(ast_ctx(self), "TODO: global constant type %i", self->vtype);
+ compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
break;
}
}
/* link us to the ir_value */
- v->cvq = self->cvq;
- self->ir_v = v;
+ v->m_cvq = self->m_cvq;
+ self->m_ir_v = v;
- if (!ast_generate_accessors(self, func->owner))
+ if (!ast_generate_accessors(self, func->m_owner))
return false;
return true;
{
size_t i;
bool warn = OPTS_WARN(WARN_USED_UNINITIALIZED);
- if (!self->setter || !self->getter)
+ if (!self->m_setter || !self->m_getter)
return true;
- for (i = 0; i < self->count; ++i) {
- if (!self->ir_values) {
- compile_error(ast_ctx(self), "internal error: no array values generated for `%s`", self->name);
+ for (i = 0; i < self->m_count; ++i) {
+ if (!self->m_ir_values) {
+ compile_error(self->m_context, "internal error: no array values generated for `%s`", self->m_name);
return false;
}
- if (!self->ir_values[i]) {
- compile_error(ast_ctx(self), "internal error: not all array values have been generated for `%s`", self->name);
+ if (!self->m_ir_values[i]) {
+ compile_error(self->m_context, "internal error: not all array values have been generated for `%s`", self->m_name);
return false;
}
- if (!self->ir_values[i]->life.empty()) {
- compile_error(ast_ctx(self), "internal error: function containing `%s` already generated", self->name);
+ if (!self->m_ir_values[i]->m_life.empty()) {
+ compile_error(self->m_context, "internal error: function containing `%s` already generated", self->m_name);
return false;
}
}
opts_set(opts.warn, WARN_USED_UNINITIALIZED, false);
- if (self->setter) {
- if (!ast_global_codegen (self->setter, ir, false) ||
- !ast_function_codegen(self->setter->constval.vfunc, ir) ||
- !ir_function_finalize(self->setter->constval.vfunc->ir_func))
+ if (self->m_setter) {
+ if (!ast_global_codegen (self->m_setter, ir, false) ||
+ !ast_function_codegen(self->m_setter->m_constval.vfunc, ir) ||
+ !ir_function_finalize(self->m_setter->m_constval.vfunc->m_ir_func))
{
- compile_error(ast_ctx(self), "internal error: failed to generate setter for `%s`", self->name);
+ compile_error(self->m_context, "internal error: failed to generate setter for `%s`", self->m_name);
opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
return false;
}
}
- if (self->getter) {
- if (!ast_global_codegen (self->getter, ir, false) ||
- !ast_function_codegen(self->getter->constval.vfunc, ir) ||
- !ir_function_finalize(self->getter->constval.vfunc->ir_func))
+ if (self->m_getter) {
+ if (!ast_global_codegen (self->m_getter, ir, false) ||
+ !ast_function_codegen(self->m_getter->m_constval.vfunc, ir) ||
+ !ir_function_finalize(self->m_getter->m_constval.vfunc->m_ir_func))
{
- compile_error(ast_ctx(self), "internal error: failed to generate getter for `%s`", self->name);
+ compile_error(self->m_context, "internal error: failed to generate getter for `%s`", self->m_name);
opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
return false;
}
}
- for (i = 0; i < self->count; ++i)
- self->ir_values[i]->life.clear();
+ for (i = 0; i < self->m_count; ++i)
+ self->m_ir_values[i]->m_life.clear();
opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
return true;
}
(void)ir;
- irf = self->ir_func;
+ irf = self->m_ir_func;
if (!irf) {
- compile_error(ast_ctx(self), "internal error: ast_function's related ast_value was not generated yet");
+ compile_error(self->m_context, "internal error: ast_function's related ast_value was not generated yet");
return false;
}
/* fill the parameter list */
- ec = self->function_type;
- for (auto &it : ec->type_params) {
- if (it->vtype == TYPE_FIELD)
- vec_push(irf->params, it->next->vtype);
+ ec = self->m_function_type;
+ for (auto &it : ec->m_type_params) {
+ if (it->m_vtype == TYPE_FIELD)
+ vec_push(irf->m_params, it->m_next->m_vtype);
else
- vec_push(irf->params, it->vtype);
- if (!self->builtin) {
- if (!ast_local_codegen(it, self->ir_func, true))
+ vec_push(irf->m_params, it->m_vtype);
+ if (!self->m_builtin) {
+ if (!ast_local_codegen(it, self->m_ir_func, true))
return false;
}
}
- if (self->varargs) {
- if (!ast_local_codegen(self->varargs, self->ir_func, true))
+ if (self->m_varargs) {
+ if (!ast_local_codegen(self->m_varargs, self->m_ir_func, true))
return false;
- irf->max_varargs = self->varargs->count;
+ irf->m_max_varargs = self->m_varargs->m_count;
}
- if (self->builtin) {
- irf->builtin = self->builtin;
+ if (self->m_builtin) {
+ irf->m_builtin = self->m_builtin;
return true;
}
/* have a local return value variable? */
- if (self->return_value) {
- if (!ast_local_codegen(self->return_value, self->ir_func, false))
+ if (self->m_return_value) {
+ if (!ast_local_codegen(self->m_return_value, self->m_ir_func, false))
return false;
}
- if (self->blocks.empty()) {
- compile_error(ast_ctx(self), "function `%s` has no body", self->name);
+ if (self->m_blocks.empty()) {
+ compile_error(self->m_context, "function `%s` has no body", self->m_name);
return false;
}
- irf->first = self->curblock = ir_function_create_block(ast_ctx(self), irf, "entry");
- if (!self->curblock) {
- compile_error(ast_ctx(self), "failed to allocate entry block for `%s`", self->name);
+ irf->m_first = self->m_curblock = ir_function_create_block(self->m_context, irf, "entry");
+ if (!self->m_curblock) {
+ compile_error(self->m_context, "failed to allocate entry block for `%s`", self->m_name);
return false;
}
- if (self->argc) {
+ if (self->m_argc) {
ir_value *va_count;
ir_value *fixed;
ir_value *sub;
- if (!ast_local_codegen(self->argc, self->ir_func, true))
+ if (!ast_local_codegen(self->m_argc, self->m_ir_func, true))
return false;
- cgen = self->argc->codegen;
- if (!(*cgen)((ast_expression*)(self->argc), self, false, &va_count))
+ cgen = self->m_argc->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_argc), self, false, &va_count))
return false;
- cgen = self->fixedparams->codegen;
- if (!(*cgen)((ast_expression*)(self->fixedparams), self, false, &fixed))
+ cgen = self->m_fixedparams->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_fixedparams), self, false, &fixed))
return false;
- sub = ir_block_create_binop(self->curblock, ast_ctx(self),
+ sub = ir_block_create_binop(self->m_curblock, self->m_context,
ast_function_label(self, "va_count"), INSTR_SUB_F,
ir_builder_get_va_count(ir), fixed);
if (!sub)
return false;
- if (!ir_block_create_store_op(self->curblock, ast_ctx(self), INSTR_STORE_F,
+ if (!ir_block_create_store_op(self->m_curblock, self->m_context, INSTR_STORE_F,
va_count, sub))
{
return false;
}
}
- for (auto &it : self->blocks) {
- cgen = it->codegen;
+ for (auto &it : self->m_blocks) {
+ cgen = it->m_codegen;
if (!(*cgen)(it.get(), self, false, &dummy))
return false;
}
/* TODO: check return types */
- if (!self->curblock->final)
+ if (!self->m_curblock->m_final)
{
- if (!self->function_type->next ||
- self->function_type->next->vtype == TYPE_VOID)
+ if (!self->m_function_type->m_next ||
+ self->m_function_type->m_next->m_vtype == TYPE_VOID)
{
- return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
+ return ir_block_create_return(self->m_curblock, self->m_context, nullptr);
}
- else if (vec_size(self->curblock->entries) || self->curblock == irf->first)
+ else if (vec_size(self->m_curblock->m_entries) || self->m_curblock == irf->m_first)
{
- if (self->return_value) {
- cgen = self->return_value->codegen;
- if (!(*cgen)((ast_expression*)(self->return_value), self, false, &dummy))
+ if (self->m_return_value) {
+ cgen = self->m_return_value->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_return_value), self, false, &dummy))
return false;
- return ir_block_create_return(self->curblock, ast_ctx(self), dummy);
+ return ir_block_create_return(self->m_curblock, self->m_context, dummy);
}
- else if (compile_warning(ast_ctx(self), WARN_MISSING_RETURN_VALUES,
+ else if (compile_warning(self->m_context, WARN_MISSING_RETURN_VALUES,
"control reaches end of non-void function (`%s`) via %s",
- self->name, self->curblock->label.c_str()))
+ self->m_name, self->m_curblock->m_label.c_str()))
{
return false;
}
- return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
+ return ir_block_create_return(self->m_curblock, self->m_context, nullptr);
}
}
return true;
{
while (ex && ast_istype(ex, ast_block)) {
ast_block *b = (ast_block*)ex;
- ex = b->exprs[0];
+ ex = b->m_exprs[0];
}
if (!ex)
return false;
* of the form: (a, b, c) = x should not assign to c...
*/
if (lvalue) {
- compile_error(ast_ctx(self), "not an l-value (code-block)");
+ compile_error(self->m_context, "not an l-value (code-block)");
return false;
}
- if (self->outr) {
- *out = self->outr;
+ if (self->m_outr) {
+ *out = self->m_outr;
return true;
}
*out = nullptr;
/* generate locals */
- for (auto &it : self->locals) {
- if (!ast_local_codegen(it, func->ir_func, false)) {
+ for (auto &it : self->m_locals) {
+ if (!ast_local_codegen(it, func->m_ir_func, false)) {
if (OPTS_OPTION_BOOL(OPTION_DEBUG))
- compile_error(ast_ctx(self), "failed to generate local `%s`", it->name);
+ compile_error(self->m_context, "failed to generate local `%s`", it->m_name);
return false;
}
}
- for (auto &it : self->exprs) {
+ for (auto &it : self->m_exprs) {
ast_expression_codegen *gen;
- if (func->curblock->final && !starts_a_label(it)) {
- if (compile_warning(ast_ctx(it), WARN_UNREACHABLE_CODE, "unreachable statement"))
+ if (func->m_curblock->m_final && !starts_a_label(it)) {
+ if (compile_warning(it->m_context, WARN_UNREACHABLE_CODE, "unreachable statement"))
return false;
continue;
}
- gen = it->codegen;
+ gen = it->m_codegen;
if (!(*gen)(it, func, false, out))
return false;
}
- self->outr = *out;
+ self->m_outr = *out;
return true;
}
ast_value *idx = 0;
ast_array_index *ai = nullptr;
- if (lvalue && self->outl) {
- *out = self->outl;
+ if (lvalue && self->m_outl) {
+ *out = self->m_outl;
return true;
}
- if (!lvalue && self->outr) {
- *out = self->outr;
+ if (!lvalue && self->m_outr) {
+ *out = self->m_outr;
return true;
}
- if (ast_istype(self->dest, ast_array_index))
+ if (ast_istype(self->m_dest, ast_array_index))
{
- ai = (ast_array_index*)self->dest;
- idx = (ast_value*)ai->index;
+ ai = (ast_array_index*)self->m_dest;
+ idx = (ast_value*)ai->m_index;
- if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
+ if (ast_istype(ai->m_index, ast_value) && idx->m_hasvalue && idx->m_cvq == CV_CONST)
ai = nullptr;
}
ir_instr *call;
if (lvalue) {
- compile_error(ast_ctx(self), "array-subscript assignment cannot produce lvalues");
+ compile_error(self->m_context, "array-subscript assignment cannot produce lvalues");
return false;
}
- arr = (ast_value*)ai->array;
- if (!ast_istype(ai->array, ast_value) || !arr->setter) {
- compile_error(ast_ctx(self), "value has no setter (%s)", arr->name);
+ arr = (ast_value*)ai->m_array;
+ if (!ast_istype(ai->m_array, ast_value) || !arr->m_setter) {
+ compile_error(self->m_context, "value has no setter (%s)", arr->m_name);
return false;
}
- cgen = idx->codegen;
+ cgen = idx->m_codegen;
if (!(*cgen)((ast_expression*)(idx), func, false, &iridx))
return false;
- cgen = arr->setter->codegen;
- if (!(*cgen)((ast_expression*)(arr->setter), func, true, &funval))
+ cgen = arr->m_setter->m_codegen;
+ if (!(*cgen)((ast_expression*)(arr->m_setter), func, true, &funval))
return false;
- cgen = self->source->codegen;
- if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+ cgen = self->m_source->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
return false;
- call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "store"), funval, false);
+ call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "store"), funval, false);
if (!call)
return false;
ir_call_param(call, iridx);
ir_call_param(call, right);
- self->outr = right;
+ self->m_outr = right;
}
else
{
/* regular code */
- cgen = self->dest->codegen;
+ cgen = self->m_dest->m_codegen;
/* lvalue! */
- if (!(*cgen)((ast_expression*)(self->dest), func, true, &left))
+ if (!(*cgen)((ast_expression*)(self->m_dest), func, true, &left))
return false;
- self->outl = left;
+ self->m_outl = left;
- cgen = self->source->codegen;
+ cgen = self->m_source->m_codegen;
/* rvalue! */
- if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+ if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
return false;
- if (!ir_block_create_store_op(func->curblock, ast_ctx(self), self->op, left, right))
+ if (!ir_block_create_store_op(func->m_curblock, self->m_context, self->m_op, left, right))
return false;
- self->outr = right;
+ self->m_outr = right;
}
/* Theoretically, an assinment returns its left side as an
/* A binary operation cannot yield an l-value */
if (lvalue) {
- compile_error(ast_ctx(self), "not an l-value (binop)");
+ compile_error(self->m_context, "not an l-value (binop)");
return false;
}
- if (self->outr) {
- *out = self->outr;
+ if (self->m_outr) {
+ *out = self->m_outr;
return true;
}
if ((OPTS_FLAG(SHORT_LOGIC) || OPTS_FLAG(PERL_LOGIC)) &&
- (self->op == INSTR_AND || self->op == INSTR_OR))
+ (self->m_op == INSTR_AND || self->m_op == INSTR_OR))
{
/* NOTE: The short-logic path will ignore right_first */
size_t merge_id;
/* prepare end-block */
- merge_id = func->ir_func->blocks.size();
- merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "sce_merge"));
+ merge_id = func->m_ir_func->m_blocks.size();
+ merge = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "sce_merge"));
/* generate the left expression */
- cgen = self->left->codegen;
- if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+ cgen = self->m_left->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
return false;
/* remember the block */
- from_left = func->curblock;
+ from_left = func->m_curblock;
/* create a new block for the right expression */
- other = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "sce_other"));
- if (self->op == INSTR_AND) {
+ other = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "sce_other"));
+ if (self->m_op == INSTR_AND) {
/* on AND: left==true -> other */
- if (!ir_block_create_if(func->curblock, ast_ctx(self), left, other, merge))
+ if (!ir_block_create_if(func->m_curblock, self->m_context, left, other, merge))
return false;
} else {
/* on OR: left==false -> other */
- if (!ir_block_create_if(func->curblock, ast_ctx(self), left, merge, other))
+ if (!ir_block_create_if(func->m_curblock, self->m_context, left, merge, other))
return false;
}
/* use the likely flag */
- vec_last(func->curblock->instr)->likely = true;
+ vec_last(func->m_curblock->m_instr)->m_likely = true;
/* enter the right-expression's block */
- func->curblock = other;
+ func->m_curblock = other;
/* generate */
- cgen = self->right->codegen;
- if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+ cgen = self->m_right->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
return false;
/* remember block */
- from_right = func->curblock;
+ from_right = func->m_curblock;
/* jump to the merge block */
- if (!ir_block_create_jump(func->curblock, ast_ctx(self), merge))
+ if (!ir_block_create_jump(func->m_curblock, self->m_context, merge))
return false;
- algo::shiftback(func->ir_func->blocks.begin() + merge_id,
- func->ir_func->blocks.end());
+ algo::shiftback(func->m_ir_func->m_blocks.begin() + merge_id,
+ func->m_ir_func->m_blocks.end());
// FIXME::DELME::
- //func->ir_func->blocks[merge_id].release();
- //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + merge_id);
- //func->ir_func->blocks.emplace_back(merge);
+ //func->m_ir_func->m_blocks[merge_id].release();
+ //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + merge_id);
+ //func->m_ir_func->m_blocks.emplace_back(merge);
- func->curblock = merge;
- phi = ir_block_create_phi(func->curblock, ast_ctx(self),
+ func->m_curblock = merge;
+ phi = ir_block_create_phi(func->m_curblock, self->m_context,
ast_function_label(func, "sce_value"),
- self->vtype);
+ self->m_vtype);
ir_phi_add(phi, from_left, left);
ir_phi_add(phi, from_right, right);
*out = ir_phi_value(phi);
if (!OPTS_FLAG(PERL_LOGIC)) {
/* cast-to-bool */
- if (OPTS_FLAG(CORRECT_LOGIC) && (*out)->vtype == TYPE_VECTOR) {
- *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+ if (OPTS_FLAG(CORRECT_LOGIC) && (*out)->m_vtype == TYPE_VECTOR) {
+ *out = ir_block_create_unary(func->m_curblock, self->m_context,
ast_function_label(func, "sce_bool_v"),
INSTR_NOT_V, *out);
if (!*out)
return false;
- *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+ *out = ir_block_create_unary(func->m_curblock, self->m_context,
ast_function_label(func, "sce_bool"),
INSTR_NOT_F, *out);
if (!*out)
return false;
}
- else if (OPTS_FLAG(FALSE_EMPTY_STRINGS) && (*out)->vtype == TYPE_STRING) {
- *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+ else if (OPTS_FLAG(FALSE_EMPTY_STRINGS) && (*out)->m_vtype == TYPE_STRING) {
+ *out = ir_block_create_unary(func->m_curblock, self->m_context,
ast_function_label(func, "sce_bool_s"),
INSTR_NOT_S, *out);
if (!*out)
return false;
- *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+ *out = ir_block_create_unary(func->m_curblock, self->m_context,
ast_function_label(func, "sce_bool"),
INSTR_NOT_F, *out);
if (!*out)
return false;
}
else {
- *out = ir_block_create_binop(func->curblock, ast_ctx(self),
+ *out = ir_block_create_binop(func->m_curblock, self->m_context,
ast_function_label(func, "sce_bool"),
INSTR_AND, *out, *out);
if (!*out)
}
}
- self->outr = *out;
+ self->m_outr = *out;
codegen_output_type(self, *out);
return true;
}
- if (self->right_first) {
- cgen = self->right->codegen;
- if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+ if (self->m_right_first) {
+ cgen = self->m_right->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
return false;
- cgen = self->left->codegen;
- if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+ cgen = self->m_left->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
return false;
} else {
- cgen = self->left->codegen;
- if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+ cgen = self->m_left->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
return false;
- cgen = self->right->codegen;
- if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+ cgen = self->m_right->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
return false;
}
- *out = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "bin"),
- self->op, left, right);
+ *out = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "bin"),
+ self->m_op, left, right);
if (!*out)
return false;
- self->outr = *out;
+ self->m_outr = *out;
codegen_output_type(self, *out);
return true;
ast_array_index *ai = nullptr;
ir_value *iridx = nullptr;
- if (lvalue && self->outl) {
- *out = self->outl;
+ if (lvalue && self->m_outl) {
+ *out = self->m_outl;
return true;
}
- if (!lvalue && self->outr) {
- *out = self->outr;
+ if (!lvalue && self->m_outr) {
+ *out = self->m_outr;
return true;
}
- if (ast_istype(self->dest, ast_array_index))
+ if (ast_istype(self->m_dest, ast_array_index))
{
- ai = (ast_array_index*)self->dest;
- idx = (ast_value*)ai->index;
+ ai = (ast_array_index*)self->m_dest;
+ idx = (ast_value*)ai->m_index;
- if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
+ if (ast_istype(ai->m_index, ast_value) && idx->m_hasvalue && idx->m_cvq == CV_CONST)
ai = nullptr;
}
/* for a binstore we need both an lvalue and an rvalue for the left side */
/* rvalue of destination! */
if (ai) {
- cgen = idx->codegen;
+ cgen = idx->m_codegen;
if (!(*cgen)((ast_expression*)(idx), func, false, &iridx))
return false;
}
- cgen = self->dest->codegen;
- if (!(*cgen)((ast_expression*)(self->dest), func, false, &leftr))
+ cgen = self->m_dest->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_dest), func, false, &leftr))
return false;
/* source as rvalue only */
- cgen = self->source->codegen;
- if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+ cgen = self->m_source->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
return false;
/* now the binary */
- bin = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "binst"),
- self->opbin, leftr, right);
- self->outr = bin;
+ bin = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "binst"),
+ self->m_opbin, leftr, right);
+ self->m_outr = bin;
if (ai) {
/* we need to call the setter */
ir_instr *call;
if (lvalue) {
- compile_error(ast_ctx(self), "array-subscript assignment cannot produce lvalues");
+ compile_error(self->m_context, "array-subscript assignment cannot produce lvalues");
return false;
}
- arr = (ast_value*)ai->array;
- if (!ast_istype(ai->array, ast_value) || !arr->setter) {
- compile_error(ast_ctx(self), "value has no setter (%s)", arr->name);
+ arr = (ast_value*)ai->m_array;
+ if (!ast_istype(ai->m_array, ast_value) || !arr->m_setter) {
+ compile_error(self->m_context, "value has no setter (%s)", arr->m_name);
return false;
}
- cgen = arr->setter->codegen;
- if (!(*cgen)((ast_expression*)(arr->setter), func, true, &funval))
+ cgen = arr->m_setter->m_codegen;
+ if (!(*cgen)((ast_expression*)(arr->m_setter), func, true, &funval))
return false;
- call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "store"), funval, false);
+ call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "store"), funval, false);
if (!call)
return false;
ir_call_param(call, iridx);
ir_call_param(call, bin);
- self->outr = bin;
+ self->m_outr = bin;
} else {
/* now store them */
- cgen = self->dest->codegen;
+ cgen = self->m_dest->m_codegen;
/* lvalue of destination */
- if (!(*cgen)((ast_expression*)(self->dest), func, true, &leftl))
+ if (!(*cgen)((ast_expression*)(self->m_dest), func, true, &leftl))
return false;
- self->outl = leftl;
+ self->m_outl = leftl;
- if (!ir_block_create_store_op(func->curblock, ast_ctx(self), self->opstore, leftl, bin))
+ if (!ir_block_create_store_op(func->m_curblock, self->m_context, self->m_opstore, leftl, bin))
return false;
- self->outr = bin;
+ self->m_outr = bin;
}
/* Theoretically, an assinment returns its left side as an
/* An unary operation cannot yield an l-value */
if (lvalue) {
- compile_error(ast_ctx(self), "not an l-value (binop)");
+ compile_error(self->m_context, "not an l-value (binop)");
return false;
}
- if (self->outr) {
- *out = self->outr;
+ if (self->m_outr) {
+ *out = self->m_outr;
return true;
}
- cgen = self->operand->codegen;
+ cgen = self->m_operand->m_codegen;
/* lvalue! */
- if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
+ if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &operand))
return false;
- *out = ir_block_create_unary(func->curblock, ast_ctx(self), ast_function_label(func, "unary"),
- self->op, operand);
+ *out = ir_block_create_unary(func->m_curblock, self->m_context, ast_function_label(func, "unary"),
+ self->m_op, operand);
if (!*out)
return false;
- self->outr = *out;
+ self->m_outr = *out;
return true;
}
* anything...
*/
if (lvalue) {
- compile_error(ast_ctx(self), "return-expression is not an l-value");
+ compile_error(self->m_context, "return-expression is not an l-value");
return false;
}
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_return cannot be reused, it bears no result!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_return cannot be reused, it bears no result!");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
- if (self->operand) {
- cgen = self->operand->codegen;
+ if (self->m_operand) {
+ cgen = self->m_operand->m_codegen;
/* lvalue! */
- if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
+ if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &operand))
return false;
- if (!ir_block_create_return(func->curblock, ast_ctx(self), operand))
+ if (!ir_block_create_return(func->m_curblock, self->m_context, operand))
return false;
} else {
- if (!ir_block_create_return(func->curblock, ast_ctx(self), nullptr))
+ if (!ir_block_create_return(func->m_curblock, self->m_context, nullptr))
return false;
}
* value in a temp.
*/
- if (lvalue && self->outl) {
- *out = self->outl;
+ if (lvalue && self->m_outl) {
+ *out = self->m_outl;
return true;
}
- if (!lvalue && self->outr) {
- *out = self->outr;
+ if (!lvalue && self->m_outr) {
+ *out = self->m_outr;
return true;
}
- cgen = self->entity->codegen;
- if (!(*cgen)((ast_expression*)(self->entity), func, false, &ent))
+ cgen = self->m_entity->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_entity), func, false, &ent))
return false;
- cgen = self->field->codegen;
- if (!(*cgen)((ast_expression*)(self->field), func, false, &field))
+ cgen = self->m_field->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_field), func, false, &field))
return false;
if (lvalue) {
/* address! */
- *out = ir_block_create_fieldaddress(func->curblock, ast_ctx(self), ast_function_label(func, "efa"),
+ *out = ir_block_create_fieldaddress(func->m_curblock, self->m_context, ast_function_label(func, "efa"),
ent, field);
} else {
- *out = ir_block_create_load_from_ent(func->curblock, ast_ctx(self), ast_function_label(func, "efv"),
- ent, field, self->vtype);
+ *out = ir_block_create_load_from_ent(func->m_curblock, self->m_context, ast_function_label(func, "efv"),
+ ent, field, self->m_vtype);
/* Done AFTER error checking:
codegen_output_type(self, *out);
*/
}
if (!*out) {
- compile_error(ast_ctx(self), "failed to create %s instruction (output type %s)",
+ compile_error(self->m_context, "failed to create %s instruction (output type %s)",
(lvalue ? "ADDRESS" : "FIELD"),
- type_name[self->vtype]);
+ type_name[self->m_vtype]);
return false;
}
if (!lvalue)
codegen_output_type(self, *out);
if (lvalue)
- self->outl = *out;
+ self->m_outl = *out;
else
- self->outr = *out;
+ self->m_outr = *out;
/* Hm that should be it... */
return true;
ir_value *vec;
/* in QC this is always an lvalue */
- if (lvalue && self->rvalue) {
- compile_error(ast_ctx(self), "not an l-value (member access)");
+ if (lvalue && self->m_rvalue) {
+ compile_error(self->m_context, "not an l-value (member access)");
return false;
}
- if (self->outl) {
- *out = self->outl;
+ if (self->m_outl) {
+ *out = self->m_outl;
return true;
}
- cgen = self->owner->codegen;
- if (!(*cgen)((ast_expression*)(self->owner), func, false, &vec))
+ cgen = self->m_owner->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_owner), func, false, &vec))
return false;
- if (vec->vtype != TYPE_VECTOR &&
- !(vec->vtype == TYPE_FIELD && self->owner->next->vtype == TYPE_VECTOR))
+ if (vec->m_vtype != TYPE_VECTOR &&
+ !(vec->m_vtype == TYPE_FIELD && self->m_owner->m_next->m_vtype == TYPE_VECTOR))
{
return false;
}
- *out = ir_value_vector_member(vec, self->field);
- self->outl = *out;
+ *out = ir_value_vector_member(vec, self->m_field);
+ self->m_outl = *out;
return (*out != nullptr);
}
ast_value *arr;
ast_value *idx;
- if (!lvalue && self->outr) {
- *out = self->outr;
+ if (!lvalue && self->m_outr) {
+ *out = self->m_outr;
return true;
}
- if (lvalue && self->outl) {
- *out = self->outl;
+ if (lvalue && self->m_outl) {
+ *out = self->m_outl;
return true;
}
- if (!ast_istype(self->array, ast_value)) {
- compile_error(ast_ctx(self), "array indexing this way is not supported");
+ if (!ast_istype(self->m_array, ast_value)) {
+ compile_error(self->m_context, "array indexing this way is not supported");
/* note this would actually be pointer indexing because the left side is
* not an actual array but (hopefully) an indexable expression.
* Once we get integer arithmetic, and GADDRESS/GSTORE/GLOAD instruction
return false;
}
- arr = (ast_value*)self->array;
- idx = (ast_value*)self->index;
+ arr = (ast_value*)self->m_array;
+ idx = (ast_value*)self->m_index;
- if (!ast_istype(self->index, ast_value) || !idx->hasvalue || idx->cvq != CV_CONST) {
+ if (!ast_istype(self->m_index, ast_value) || !idx->m_hasvalue || idx->m_cvq != CV_CONST) {
/* Time to use accessor functions */
ast_expression_codegen *cgen;
ir_value *iridx, *funval;
ir_instr *call;
if (lvalue) {
- compile_error(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
+ compile_error(self->m_context, "(.2) array indexing here needs a compile-time constant");
return false;
}
- if (!arr->getter) {
- compile_error(ast_ctx(self), "value has no getter, don't know how to index it");
+ if (!arr->m_getter) {
+ compile_error(self->m_context, "value has no getter, don't know how to index it");
return false;
}
- cgen = self->index->codegen;
- if (!(*cgen)((ast_expression*)(self->index), func, false, &iridx))
+ cgen = self->m_index->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_index), func, false, &iridx))
return false;
- cgen = arr->getter->codegen;
- if (!(*cgen)((ast_expression*)(arr->getter), func, true, &funval))
+ cgen = arr->m_getter->m_codegen;
+ if (!(*cgen)((ast_expression*)(arr->m_getter), func, true, &funval))
return false;
- call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "fetch"), funval, false);
+ call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "fetch"), funval, false);
if (!call)
return false;
ir_call_param(call, iridx);
*out = ir_call_value(call);
- self->outr = *out;
- (*out)->vtype = self->vtype;
+ self->m_outr = *out;
+ (*out)->m_vtype = self->m_vtype;
codegen_output_type(self, *out);
return true;
}
- if (idx->vtype == TYPE_FLOAT) {
- unsigned int arridx = idx->constval.vfloat;
- if (arridx >= self->array->count)
+ if (idx->m_vtype == TYPE_FLOAT) {
+ unsigned int arridx = idx->m_constval.vfloat;
+ if (arridx >= self->m_array->m_count)
{
- compile_error(ast_ctx(self), "array index out of bounds: %i", arridx);
+ compile_error(self->m_context, "array index out of bounds: %i", arridx);
return false;
}
- *out = arr->ir_values[arridx];
+ *out = arr->m_ir_values[arridx];
}
- else if (idx->vtype == TYPE_INTEGER) {
- unsigned int arridx = idx->constval.vint;
- if (arridx >= self->array->count)
+ else if (idx->m_vtype == TYPE_INTEGER) {
+ unsigned int arridx = idx->m_constval.vint;
+ if (arridx >= self->m_array->m_count)
{
- compile_error(ast_ctx(self), "array index out of bounds: %i", arridx);
+ compile_error(self->m_context, "array index out of bounds: %i", arridx);
return false;
}
- *out = arr->ir_values[arridx];
+ *out = arr->m_ir_values[arridx];
}
else {
- compile_error(ast_ctx(self), "array indexing here needs an integer constant");
+ compile_error(self->m_context, "array indexing here needs an integer constant");
return false;
}
- (*out)->vtype = self->vtype;
+ (*out)->m_vtype = self->m_vtype;
codegen_output_type(self, *out);
return true;
}
{
*out = nullptr;
if (lvalue) {
- compile_error(ast_ctx(self), "argpipe node: not an lvalue");
+ compile_error(self->m_context, "argpipe node: not an lvalue");
return false;
}
(void)func;
(void)out;
- compile_error(ast_ctx(self), "TODO: argpipe codegen not implemented");
+ compile_error(self->m_context, "TODO: argpipe codegen not implemented");
return false;
}
(void)out;
(void)lvalue;
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_ifthen cannot be reused, it bears no result!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_ifthen cannot be reused, it bears no result!");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
/* generate the condition */
- cgen = self->cond->codegen;
- if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+ cgen = self->m_cond->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_cond), func, false, &condval))
return false;
/* update the block which will get the jump - because short-logic or ternaries may have changed this */
- cond = func->curblock;
+ cond = func->m_curblock;
/* try constant folding away the condition */
if ((folded = fold::cond_ifthen(condval, func, self)) != -1)
return folded;
- if (self->on_true) {
+ if (self->m_on_true) {
/* create on-true block */
- ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "ontrue"));
+ ontrue = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "ontrue"));
if (!ontrue)
return false;
/* enter the block */
- func->curblock = ontrue;
+ func->m_curblock = ontrue;
/* generate */
- cgen = self->on_true->codegen;
- if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
+ cgen = self->m_on_true->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_on_true), func, false, &dummy))
return false;
/* we now need to work from the current endpoint */
- ontrue_endblock = func->curblock;
+ ontrue_endblock = func->m_curblock;
} else
ontrue = nullptr;
/* on-false path */
- if (self->on_false) {
+ if (self->m_on_false) {
/* create on-false block */
- onfalse = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "onfalse"));
+ onfalse = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "onfalse"));
if (!onfalse)
return false;
/* enter the block */
- func->curblock = onfalse;
+ func->m_curblock = onfalse;
/* generate */
- cgen = self->on_false->codegen;
- if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
+ cgen = self->m_on_false->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_on_false), func, false, &dummy))
return false;
/* we now need to work from the current endpoint */
- onfalse_endblock = func->curblock;
+ onfalse_endblock = func->m_curblock;
} else
onfalse = nullptr;
/* Merge block were they all merge in to */
- if (!ontrue || !onfalse || !ontrue_endblock->final || !onfalse_endblock->final)
+ if (!ontrue || !onfalse || !ontrue_endblock->m_final || !onfalse_endblock->m_final)
{
- merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "endif"));
+ merge = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "endif"));
if (!merge)
return false;
/* add jumps ot the merge block */
- if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, ast_ctx(self), merge))
+ if (ontrue && !ontrue_endblock->m_final && !ir_block_create_jump(ontrue_endblock, self->m_context, merge))
return false;
- if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, ast_ctx(self), merge))
+ if (onfalse && !onfalse_endblock->m_final && !ir_block_create_jump(onfalse_endblock, self->m_context, merge))
return false;
/* Now enter the merge block */
- func->curblock = merge;
+ func->m_curblock = merge;
}
/* we create the if here, that way all blocks are ordered :)
*/
- if (!ir_block_create_if(cond, ast_ctx(self), condval,
+ if (!ir_block_create_if(cond, self->m_context, condval,
(ontrue ? ontrue : merge),
(onfalse ? onfalse : merge)))
{
ir_value *trueval, *falseval;
ir_instr *phi;
- ir_block *cond = func->curblock;
+ ir_block *cond = func->m_curblock;
ir_block *cond_out = nullptr;
ir_block *ontrue, *ontrue_out = nullptr;
ir_block *onfalse, *onfalse_out = nullptr;
* may still happen, thus we remember a created ir_value and simply return one
* if it already exists.
*/
- if (self->outr) {
- *out = self->outr;
+ if (self->m_outr) {
+ *out = self->m_outr;
return true;
}
/* In the following, contraty to ast_ifthen, we assume both paths exist. */
/* generate the condition */
- func->curblock = cond;
- cgen = self->cond->codegen;
- if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+ func->m_curblock = cond;
+ cgen = self->m_cond->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_cond), func, false, &condval))
return false;
- cond_out = func->curblock;
+ cond_out = func->m_curblock;
/* try constant folding away the condition */
if ((folded = fold::cond_ternary(condval, func, self)) != -1)
return folded;
/* create on-true block */
- ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_T"));
+ ontrue = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_T"));
if (!ontrue)
return false;
else
{
/* enter the block */
- func->curblock = ontrue;
+ func->m_curblock = ontrue;
/* generate */
- cgen = self->on_true->codegen;
- if (!(*cgen)((ast_expression*)(self->on_true), func, false, &trueval))
+ cgen = self->m_on_true->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_on_true), func, false, &trueval))
return false;
- ontrue_out = func->curblock;
+ ontrue_out = func->m_curblock;
}
/* create on-false block */
- onfalse = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_F"));
+ onfalse = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_F"));
if (!onfalse)
return false;
else
{
/* enter the block */
- func->curblock = onfalse;
+ func->m_curblock = onfalse;
/* generate */
- cgen = self->on_false->codegen;
- if (!(*cgen)((ast_expression*)(self->on_false), func, false, &falseval))
+ cgen = self->m_on_false->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_on_false), func, false, &falseval))
return false;
- onfalse_out = func->curblock;
+ onfalse_out = func->m_curblock;
}
/* create merge block */
- merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_out"));
+ merge = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_out"));
if (!merge)
return false;
/* jump to merge block */
- if (!ir_block_create_jump(ontrue_out, ast_ctx(self), merge))
+ if (!ir_block_create_jump(ontrue_out, self->m_context, merge))
return false;
- if (!ir_block_create_jump(onfalse_out, ast_ctx(self), merge))
+ if (!ir_block_create_jump(onfalse_out, self->m_context, merge))
return false;
/* create if instruction */
- if (!ir_block_create_if(cond_out, ast_ctx(self), condval, ontrue, onfalse))
+ if (!ir_block_create_if(cond_out, self->m_context, condval, ontrue, onfalse))
return false;
/* Now enter the merge block */
- func->curblock = merge;
+ func->m_curblock = merge;
/* Here, now, we need a PHI node
* but first some sanity checking...
*/
- if (trueval->vtype != falseval->vtype && trueval->vtype != TYPE_NIL && falseval->vtype != TYPE_NIL) {
+ if (trueval->m_vtype != falseval->m_vtype && trueval->m_vtype != TYPE_NIL && falseval->m_vtype != TYPE_NIL) {
/* error("ternary with different types on the two sides"); */
- compile_error(ast_ctx(self), "internal error: ternary operand types invalid");
+ compile_error(self->m_context, "internal error: ternary operand types invalid");
return false;
}
/* create PHI */
- phi = ir_block_create_phi(merge, ast_ctx(self), ast_function_label(func, "phi"), self->vtype);
+ phi = ir_block_create_phi(merge, self->m_context, ast_function_label(func, "phi"), self->m_vtype);
if (!phi) {
- compile_error(ast_ctx(self), "internal error: failed to generate phi node");
+ compile_error(self->m_context, "internal error: failed to generate phi node");
return false;
}
ir_phi_add(phi, ontrue_out, trueval);
ir_phi_add(phi, onfalse_out, falseval);
- self->outr = ir_phi_value(phi);
- *out = self->outr;
+ self->m_outr = ir_phi_value(phi);
+ *out = self->m_outr;
codegen_output_type(self, *out);
(void)lvalue;
(void)out;
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_loop cannot be reused, it bears no result!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_loop cannot be reused, it bears no result!");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
/* NOTE:
* Should we ever need some kind of block ordering, better make this function
/* initexpr doesn't get its own block, it's pointless, it could create more blocks
* anyway if for example it contains a ternary.
*/
- if (self->initexpr)
+ if (self->m_initexpr)
{
- cgen = self->initexpr->codegen;
- if (!(*cgen)((ast_expression*)(self->initexpr), func, false, &dummy))
+ cgen = self->m_initexpr->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_initexpr), func, false, &dummy))
return false;
}
/* Store the block from which we enter this chaos */
- bin = func->curblock;
+ bin = func->m_curblock;
/* The pre-loop condition needs its own block since we
* need to be able to jump to the start of that expression.
*/
- if (self->precond)
+ if (self->m_precond)
{
- bprecond = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "pre_loop_cond"));
+ bprecond = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "pre_loop_cond"));
if (!bprecond)
return false;
bcontinue = bprecond;
/* enter */
- func->curblock = bprecond;
+ func->m_curblock = bprecond;
/* generate */
- cgen = self->precond->codegen;
- if (!(*cgen)((ast_expression*)(self->precond), func, false, &precond))
+ cgen = self->m_precond->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_precond), func, false, &precond))
return false;
- end_bprecond = func->curblock;
+ end_bprecond = func->m_curblock;
} else {
bprecond = end_bprecond = nullptr;
}
/* Now the next blocks won't be ordered nicely, but we need to
* generate them this early for 'break' and 'continue'.
*/
- if (self->increment) {
- bincrement = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "loop_increment"));
+ if (self->m_increment) {
+ bincrement = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "loop_increment"));
if (!bincrement)
return false;
bcontinue = bincrement; /* increment comes before the pre-loop-condition */
bincrement = end_bincrement = nullptr;
}
- if (self->postcond) {
- bpostcond = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "post_loop_cond"));
+ if (self->m_postcond) {
+ bpostcond = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "post_loop_cond"));
if (!bpostcond)
return false;
bcontinue = bpostcond; /* postcond comes before the increment */
bpostcond = end_bpostcond = nullptr;
}
- bout_id = func->ir_func->blocks.size();
- bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_loop"));
+ bout_id = func->m_ir_func->m_blocks.size();
+ bout = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "after_loop"));
if (!bout)
return false;
bbreak = bout;
/* The loop body... */
- /* if (self->body) */
+ /* if (self->m_body) */
{
- bbody = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "loop_body"));
+ bbody = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "loop_body"));
if (!bbody)
return false;
/* enter */
- func->curblock = bbody;
+ func->m_curblock = bbody;
- func->breakblocks.push_back(bbreak);
+ func->m_breakblocks.push_back(bbreak);
if (bcontinue)
- func->continueblocks.push_back(bcontinue);
+ func->m_continueblocks.push_back(bcontinue);
else
- func->continueblocks.push_back(bbody);
+ func->m_continueblocks.push_back(bbody);
/* generate */
- if (self->body) {
- cgen = self->body->codegen;
- if (!(*cgen)((ast_expression*)(self->body), func, false, &dummy))
+ if (self->m_body) {
+ cgen = self->m_body->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_body), func, false, &dummy))
return false;
}
- end_bbody = func->curblock;
- func->breakblocks.pop_back();
- func->continueblocks.pop_back();
+ end_bbody = func->m_curblock;
+ func->m_breakblocks.pop_back();
+ func->m_continueblocks.pop_back();
}
/* post-loop-condition */
- if (self->postcond)
+ if (self->m_postcond)
{
/* enter */
- func->curblock = bpostcond;
+ func->m_curblock = bpostcond;
/* generate */
- cgen = self->postcond->codegen;
- if (!(*cgen)((ast_expression*)(self->postcond), func, false, &postcond))
+ cgen = self->m_postcond->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_postcond), func, false, &postcond))
return false;
- end_bpostcond = func->curblock;
+ end_bpostcond = func->m_curblock;
}
/* The incrementor */
- if (self->increment)
+ if (self->m_increment)
{
/* enter */
- func->curblock = bincrement;
+ func->m_curblock = bincrement;
/* generate */
- cgen = self->increment->codegen;
- if (!(*cgen)((ast_expression*)(self->increment), func, false, &dummy))
+ cgen = self->m_increment->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_increment), func, false, &dummy))
return false;
- end_bincrement = func->curblock;
+ end_bincrement = func->m_curblock;
}
/* In any case now, we continue from the outgoing block */
- func->curblock = bout;
+ func->m_curblock = bout;
/* Now all blocks are in place */
/* From 'bin' we jump to whatever comes first */
else tmpblock = bout;
*/
- if (!ir_block_create_jump(bin, ast_ctx(self), tmpblock))
+ if (!ir_block_create_jump(bin, self->m_context, tmpblock))
return false;
/* From precond */
*/
onfalse = bout;
- if (self->pre_not) {
+ if (self->m_pre_not) {
tmpblock = ontrue;
ontrue = onfalse;
onfalse = tmpblock;
}
- if (!ir_block_create_if(end_bprecond, ast_ctx(self), precond, ontrue, onfalse))
+ if (!ir_block_create_if(end_bprecond, self->m_context, precond, ontrue, onfalse))
return false;
}
else if (bpostcond) tmpblock = bpostcond;
else if (bprecond) tmpblock = bprecond;
else tmpblock = bbody;
- if (!end_bbody->final && !ir_block_create_jump(end_bbody, ast_ctx(self), tmpblock))
+ if (!end_bbody->m_final && !ir_block_create_jump(end_bbody, self->m_context, tmpblock))
return false;
}
else if (bprecond) tmpblock = bprecond;
else if (bbody) tmpblock = bbody;
else tmpblock = bout;
- if (!ir_block_create_jump(end_bincrement, ast_ctx(self), tmpblock))
+ if (!ir_block_create_jump(end_bincrement, self->m_context, tmpblock))
return false;
}
*/
onfalse = bout;
- if (self->post_not) {
+ if (self->m_post_not) {
tmpblock = ontrue;
ontrue = onfalse;
onfalse = tmpblock;
}
- if (!ir_block_create_if(end_bpostcond, ast_ctx(self), postcond, ontrue, onfalse))
+ if (!ir_block_create_if(end_bpostcond, self->m_context, postcond, ontrue, onfalse))
return false;
}
/* Move 'bout' to the end */
- algo::shiftback(func->ir_func->blocks.begin() + bout_id,
- func->ir_func->blocks.end());
+ algo::shiftback(func->m_ir_func->m_blocks.begin() + bout_id,
+ func->m_ir_func->m_blocks.end());
// FIXME::DELME::
- //func->ir_func->blocks[bout_id].release(); // it's a vector<unique_ptr<>>
- //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
- //func->ir_func->blocks.emplace_back(bout);
+ //func->m_ir_func->m_blocks[bout_id].release(); // it's a vector<unique_ptr<>>
+ //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bout_id);
+ //func->m_ir_func->m_blocks.emplace_back(bout);
return true;
}
*out = nullptr;
if (lvalue) {
- compile_error(ast_ctx(self), "break/continue expression is not an l-value");
+ compile_error(self->m_context, "break/continue expression is not an l-value");
return false;
}
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_breakcont cannot be reused!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_breakcont cannot be reused!");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
- if (self->is_continue)
- target = func->continueblocks[func->continueblocks.size()-1-self->levels];
+ if (self->m_is_continue)
+ target = func->m_continueblocks[func->m_continueblocks.size()-1-self->m_levels];
else
- target = func->breakblocks[func->breakblocks.size()-1-self->levels];
+ target = func->m_breakblocks[func->m_breakblocks.size()-1-self->m_levels];
if (!target) {
- compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
+ compile_error(self->m_context, "%s is lacking a target block", (self->m_is_continue ? "continue" : "break"));
return false;
}
- if (!ir_block_create_jump(func->curblock, ast_ctx(self), target))
+ if (!ir_block_create_jump(func->m_curblock, self->m_context, target))
return false;
return true;
}
uint16_t cmpinstr;
if (lvalue) {
- compile_error(ast_ctx(self), "switch expression is not an l-value");
+ compile_error(self->m_context, "switch expression is not an l-value");
return false;
}
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_switch cannot be reused!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_switch cannot be reused!");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
(void)lvalue;
(void)out;
- cgen = self->operand->codegen;
- if (!(*cgen)((ast_expression*)(self->operand), func, false, &irop))
+ cgen = self->m_operand->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &irop))
return false;
- if (self->cases.empty())
+ if (self->m_cases.empty())
return true;
- cmpinstr = type_eq_instr[irop->vtype];
+ cmpinstr = type_eq_instr[irop->m_vtype];
if (cmpinstr >= VINSTR_END) {
- ast_type_to_string(self->operand, typestr, sizeof(typestr));
- compile_error(ast_ctx(self), "invalid type to perform a switch on: %s", typestr);
+ ast_type_to_string(self->m_operand, typestr, sizeof(typestr));
+ compile_error(self->m_context, "invalid type to perform a switch on: %s", typestr);
return false;
}
- bout_id = func->ir_func->blocks.size();
- bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_switch"));
+ bout_id = func->m_ir_func->m_blocks.size();
+ bout = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "after_switch"));
if (!bout)
return false;
/* setup the break block */
- func->breakblocks.push_back(bout);
+ func->m_breakblocks.push_back(bout);
/* Now create all cases */
- for (auto &it : self->cases) {
+ for (auto &it : self->m_cases) {
ir_value *cond, *val;
ir_block *bcase, *bnot;
size_t bnot_id;
ast_switch_case *swcase = ⁢
- if (swcase->value) {
+ if (swcase->m_value) {
/* A regular case */
/* generate the condition operand */
- cgen = swcase->value->codegen;
- if (!(*cgen)((ast_expression*)(swcase->value), func, false, &val))
+ cgen = swcase->m_value->m_codegen;
+ if (!(*cgen)((ast_expression*)(swcase->m_value), func, false, &val))
return false;
/* generate the condition */
- cond = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "switch_eq"), cmpinstr, irop, val);
+ cond = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "switch_eq"), cmpinstr, irop, val);
if (!cond)
return false;
- bcase = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "case"));
- bnot_id = func->ir_func->blocks.size();
- bnot = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "not_case"));
+ bcase = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "case"));
+ bnot_id = func->m_ir_func->m_blocks.size();
+ bnot = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "not_case"));
if (!bcase || !bnot)
return false;
if (set_def_bfall_to) {
set_def_bfall_to = false;
def_bfall_to = bcase;
}
- if (!ir_block_create_if(func->curblock, ast_ctx(self), cond, bcase, bnot))
+ if (!ir_block_create_if(func->m_curblock, self->m_context, cond, bcase, bnot))
return false;
/* Make the previous case-end fall through */
- if (bfall && !bfall->final) {
- if (!ir_block_create_jump(bfall, ast_ctx(self), bcase))
+ if (bfall && !bfall->m_final) {
+ if (!ir_block_create_jump(bfall, self->m_context, bcase))
return false;
}
/* enter the case */
- func->curblock = bcase;
- cgen = swcase->code->codegen;
- if (!(*cgen)((ast_expression*)swcase->code, func, false, &dummy))
+ func->m_curblock = bcase;
+ cgen = swcase->m_code->m_codegen;
+ if (!(*cgen)((ast_expression*)swcase->m_code, func, false, &dummy))
return false;
/* remember this block to fall through from */
- bfall = func->curblock;
+ bfall = func->m_curblock;
/* enter the else and move it down */
- func->curblock = bnot;
- algo::shiftback(func->ir_func->blocks.begin() + bnot_id,
- func->ir_func->blocks.end());
+ func->m_curblock = bnot;
+ algo::shiftback(func->m_ir_func->m_blocks.begin() + bnot_id,
+ func->m_ir_func->m_blocks.end());
// FIXME::DELME::
- //func->ir_func->blocks[bnot_id].release();
- //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bnot_id);
- //func->ir_func->blocks.emplace_back(bnot);
+ //func->m_ir_func->m_blocks[bnot_id].release();
+ //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bnot_id);
+ //func->m_ir_func->m_blocks.emplace_back(bnot);
} else {
/* The default case */
/* Remember where to fall through from: */
}
/* Jump from the last bnot to bout */
- if (bfall && !bfall->final && !ir_block_create_jump(bfall, ast_ctx(self), bout)) {
+ if (bfall && !bfall->m_final && !ir_block_create_jump(bfall, self->m_context, bout)) {
/*
- astwarning(ast_ctx(bfall), WARN_???, "missing break after last case");
+ astwarning(bfall->m_context, WARN_???, "missing break after last case");
*/
return false;
}
ir_block *bcase;
/* No need to create an extra block */
- bcase = func->curblock;
+ bcase = func->m_curblock;
/* Insert the fallthrough jump */
- if (def_bfall && !def_bfall->final) {
- if (!ir_block_create_jump(def_bfall, ast_ctx(self), bcase))
+ if (def_bfall && !def_bfall->m_final) {
+ if (!ir_block_create_jump(def_bfall, self->m_context, bcase))
return false;
}
/* Now generate the default code */
- cgen = def_case->code->codegen;
- if (!(*cgen)((ast_expression*)def_case->code, func, false, &dummy))
+ cgen = def_case->m_code->m_codegen;
+ if (!(*cgen)((ast_expression*)def_case->m_code, func, false, &dummy))
return false;
/* see if we need to fall through */
- if (def_bfall_to && !func->curblock->final)
+ if (def_bfall_to && !func->m_curblock->m_final)
{
- if (!ir_block_create_jump(func->curblock, ast_ctx(self), def_bfall_to))
+ if (!ir_block_create_jump(func->m_curblock, self->m_context, def_bfall_to))
return false;
}
}
/* Jump from the last bnot to bout */
- if (!func->curblock->final && !ir_block_create_jump(func->curblock, ast_ctx(self), bout))
+ if (!func->m_curblock->m_final && !ir_block_create_jump(func->m_curblock, self->m_context, bout))
return false;
/* enter the outgoing block */
- func->curblock = bout;
+ func->m_curblock = bout;
/* restore the break block */
- func->breakblocks.pop_back();
+ func->m_breakblocks.pop_back();
/* Move 'bout' to the end, it's nicer */
- algo::shiftback(func->ir_func->blocks.begin() + bout_id,
- func->ir_func->blocks.end());
+ algo::shiftback(func->m_ir_func->m_blocks.begin() + bout_id,
+ func->m_ir_func->m_blocks.end());
// FIXME::DELME::
- //func->ir_func->blocks[bout_id].release();
- //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
- //func->ir_func->blocks.emplace_back(bout);
+ //func->m_ir_func->m_blocks[bout_id].release();
+ //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bout_id);
+ //func->m_ir_func->m_blocks.emplace_back(bout);
return true;
}
{
ir_value *dummy;
- if (self->undefined) {
- compile_error(ast_ctx(self), "internal error: ast_label never defined");
+ if (self->m_undefined) {
+ compile_error(self->m_context, "internal error: ast_label never defined");
return false;
}
*out = nullptr;
if (lvalue) {
- compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");
+ compile_error(self->m_context, "internal error: ast_label cannot be an lvalue");
return false;
}
/* simply create a new block and jump to it */
- self->irblock = ir_function_create_block(ast_ctx(self), func->ir_func, self->name);
- if (!self->irblock) {
- compile_error(ast_ctx(self), "failed to allocate label block `%s`", self->name);
+ self->m_irblock = ir_function_create_block(self->m_context, func->m_ir_func, self->m_name);
+ if (!self->m_irblock) {
+ compile_error(self->m_context, "failed to allocate label block `%s`", self->m_name);
return false;
}
- if (!func->curblock->final) {
- if (!ir_block_create_jump(func->curblock, ast_ctx(self), self->irblock))
+ if (!func->m_curblock->m_final) {
+ if (!ir_block_create_jump(func->m_curblock, self->m_context, self->m_irblock))
return false;
}
/* enter the new block */
- func->curblock = self->irblock;
+ func->m_curblock = self->m_irblock;
/* Generate all the leftover gotos */
- for (auto &it : self->gotos) {
+ for (auto &it : self->m_gotos) {
if (!ast_goto_codegen(it, func, false, &dummy))
return false;
}
{
*out = nullptr;
if (lvalue) {
- compile_error(ast_ctx(self), "internal error: ast_goto cannot be an lvalue");
+ compile_error(self->m_context, "internal error: ast_goto cannot be an lvalue");
return false;
}
- if (self->target->irblock) {
- if (self->irblock_from) {
+ if (self->m_target->m_irblock) {
+ if (self->m_irblock_from) {
/* we already tried once, this is the callback */
- self->irblock_from->final = false;
- if (!ir_block_create_goto(self->irblock_from, ast_ctx(self), self->target->irblock)) {
- compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name);
+ self->m_irblock_from->m_final = false;
+ if (!ir_block_create_goto(self->m_irblock_from, self->m_context, self->m_target->m_irblock)) {
+ compile_error(self->m_context, "failed to generate goto to `%s`", self->m_name);
return false;
}
}
else
{
- if (!ir_block_create_goto(func->curblock, ast_ctx(self), self->target->irblock)) {
- compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name);
+ if (!ir_block_create_goto(func->m_curblock, self->m_context, self->m_target->m_irblock)) {
+ compile_error(self->m_context, "failed to generate goto to `%s`", self->m_name);
return false;
}
}
/* the target has not yet been created...
* close this block in a sneaky way:
*/
- func->curblock->final = true;
- self->irblock_from = func->curblock;
- ast_label_register_goto(self->target, self);
+ func->m_curblock->m_final = true;
+ self->m_irblock_from = func->m_curblock;
+ ast_label_register_goto(self->m_target, self);
}
return true;
ir_value *frameval, *thinkval;
if (lvalue) {
- compile_error(ast_ctx(self), "not an l-value (state operation)");
+ compile_error(self->m_context, "not an l-value (state operation)");
return false;
}
- if (self->outr) {
- compile_error(ast_ctx(self), "internal error: ast_state cannot be reused!");
+ if (self->m_outr) {
+ compile_error(self->m_context, "internal error: ast_state cannot be reused!");
return false;
}
*out = nullptr;
- cgen = self->framenum->codegen;
- if (!(*cgen)((ast_expression*)(self->framenum), func, false, &frameval))
+ cgen = self->m_framenum->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_framenum), func, false, &frameval))
return false;
if (!frameval)
return false;
- cgen = self->nextthink->codegen;
- if (!(*cgen)((ast_expression*)(self->nextthink), func, false, &thinkval))
+ cgen = self->m_nextthink->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_nextthink), func, false, &thinkval))
return false;
if (!frameval)
return false;
- if (!ir_block_create_state_op(func->curblock, ast_ctx(self), frameval, thinkval)) {
- compile_error(ast_ctx(self), "failed to create STATE instruction");
+ if (!ir_block_create_state_op(func->m_curblock, self->m_context, frameval, thinkval)) {
+ compile_error(self->m_context, "failed to create STATE instruction");
return false;
}
- self->outr = (ir_value*)1;
+ self->m_outr = (ir_value*)1;
return true;
}
/* return values are never lvalues */
if (lvalue) {
- compile_error(ast_ctx(self), "not an l-value (function call)");
+ compile_error(self->m_context, "not an l-value (function call)");
return false;
}
- if (self->outr) {
- *out = self->outr;
+ if (self->m_outr) {
+ *out = self->m_outr;
return true;
}
- cgen = self->func->codegen;
- if (!(*cgen)((ast_expression*)(self->func), func, false, &funval))
+ cgen = self->m_func->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_func), func, false, &funval))
return false;
if (!funval)
return false;
/* parameters */
- for (auto &it : self->params) {
+ for (auto &it : self->m_params) {
ir_value *param;
- cgen = it->codegen;
+ cgen = it->m_codegen;
if (!(*cgen)(it, func, false, ¶m))
return false;
if (!param)
}
/* varargs counter */
- if (self->va_count) {
+ if (self->m_va_count) {
ir_value *va_count;
- ir_builder *builder = func->curblock->owner->owner;
- cgen = self->va_count->codegen;
- if (!(*cgen)((ast_expression*)(self->va_count), func, false, &va_count))
+ ir_builder *builder = func->m_curblock->m_owner->m_owner;
+ cgen = self->m_va_count->m_codegen;
+ if (!(*cgen)((ast_expression*)(self->m_va_count), func, false, &va_count))
return false;
- if (!ir_block_create_store_op(func->curblock, ast_ctx(self), INSTR_STORE_F,
+ if (!ir_block_create_store_op(func->m_curblock, self->m_context, INSTR_STORE_F,
ir_builder_get_va_count(builder), va_count))
{
return false;
}
}
- callinstr = ir_block_create_call(func->curblock, ast_ctx(self),
+ callinstr = ir_block_create_call(func->m_curblock, self->m_context,
ast_function_label(func, "call"),
- funval, !!(self->func->flags & AST_FLAG_NORETURN));
+ funval, !!(self->m_func->m_flags & AST_FLAG_NORETURN));
if (!callinstr)
return false;
ir_call_param(callinstr, it);
*out = ir_call_value(callinstr);
- self->outr = *out;
+ self->m_outr = *out;
codegen_output_type(self, *out);
util_snprintf(stype, sizeof(stype), "<%s>", type_name[vtype]);
value = ast_value_new(ctx(), buffer, TYPE_FUNCTION);
- value->intrinsic = true;
- value->next = (ast_expression*)ast_value_new(ctx(), stype, vtype);
+ value->m_intrinsic = true;
+ value->m_next = (ast_expression*)ast_value_new(ctx(), stype, vtype);
func = ast_function_new(ctx(), buffer, value);
- value->flags |= AST_FLAG_ERASEABLE;
+ value->m_flags |= AST_FLAG_ERASEABLE;
*out = value;
return func;
ast_block *block = ast_block_new(ctx());
/* float x; */
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* <callisnan> = isnan(x); */
- callisnan->params.push_back((ast_expression*)x);
+ callisnan->m_params.push_back((ast_expression*)x);
/* <callisinf> = isinf(x); */
- callisinf->params.push_back((ast_expression*)x);
+ callisinf->m_params.push_back((ast_expression*)x);
/* return (!<callisnan> || <callisinf>); */
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_unary_new(
)
);
- func->blocks.emplace_back(block);
+ func->m_blocks.emplace_back(block);
reg(val, func);
return (ast_expression*)val;;
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "isinf", TYPE_FLOAT);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- val->type_params.push_back(x);
- func->blocks.emplace_back(body);
+ val->m_type_params.push_back(x);
+ func->m_blocks.emplace_back(body);
reg(val, func);
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "isnan", TYPE_FLOAT);
- body->locals.push_back(local);
- body->exprs.push_back(
+ body->m_locals.push_back(local);
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- val->type_params.push_back(arg1);
- func->blocks.emplace_back(body);
+ val->m_type_params.push_back(arg1);
+ func->m_blocks.emplace_back(body);
reg(val, func);
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "isnormal", TYPE_FLOAT);
- val->type_params.push_back(x);
- callisfinite->params.push_back((ast_expression*)x);
+ val->m_type_params.push_back(x);
+ callisfinite->m_params.push_back((ast_expression*)x);
/* return <callisfinite> */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)callisfinite
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "signbit", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* return (x < 0); */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_ternary_new(
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "acosh", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* <callsqrt> = sqrt((x * x) - 1); */
- callsqrt->params.push_back(
+ callsqrt->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_SUB_F,
);
/* <calllog> = log(x + <callsqrt>); */
- calllog->params.push_back(
+ calllog->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_ADD_F,
);
/* return <calllog>; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)calllog
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "asinh", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* <callsqrt> = sqrt((x * x) + 1); */
- callsqrt->params.push_back(
+ callsqrt->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_ADD_F,
);
/* <calllog> = log(x + <callsqrt>); */
- calllog->params.push_back(
+ calllog->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_ADD_F,
);
/* return <calllog>; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)calllog
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "atanh", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* <callog> = log((1 + x) / (1 - x)); */
- calllog->params.push_back(
+ calllog->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_DIV_F,
);
/* return 0.5 * <calllog>; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_MUL_F,
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "exp", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
- body->locals.push_back(sum);
- body->locals.push_back(acc);
- body->locals.push_back(i);
+ body->m_locals.push_back(sum);
+ body->m_locals.push_back(acc);
+ body->m_locals.push_back(i);
/* sum = 1.0; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* acc = 1.0; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* for (i = 1; i < 200; ++i)
* sum += (acc *= x / i);
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
/* i = 1; */
);
/* return sum; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)sum
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "exp2", TYPE_FLOAT);
- val->type_params.push_back(arg1);
+ val->m_type_params.push_back(arg1);
- callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
- callpow->params.push_back((ast_expression*)arg1);
+ callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]);
+ callpow->m_params.push_back((ast_expression*)arg1);
/* return <callpow> */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)callpow
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "expm1", TYPE_FLOAT);
- val->type_params.push_back(x);
+ val->m_type_params.push_back(x);
/* <callexp> = exp(x); */
- callexp->params.push_back((ast_expression*)x);
+ callexp->m_params.push_back((ast_expression*)x);
/* return <callexp> - 1; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_value *square = ast_value_new(ctx(), "square", TYPE_FLOAT);
ast_value *accumulate = ast_value_new(ctx(), "accumulate", TYPE_FLOAT);
ast_value *mid = ast_value_new(ctx(), "mid", TYPE_FLOAT);
- body->locals.push_back(result);
- body->locals.push_back(low);
- body->locals.push_back(high);
- body->locals.push_back(square);
- body->locals.push_back(accumulate);
- body->locals.push_back(mid);
+ body->m_locals.push_back(result);
+ body->m_locals.push_back(low);
+ body->m_locals.push_back(high);
+ body->m_locals.push_back(square);
+ body->m_locals.push_back(accumulate);
+ body->m_locals.push_back(mid);
- val->type_params.push_back(base);
- val->type_params.push_back(exp);
+ val->m_type_params.push_back(base);
+ val->m_type_params.push_back(exp);
/*
* if (exp == 0.0)
* return 1;
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
* if (exp == 1.0)
* return base;
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
);
/* <callpow1> = pow(base, -exp) */
- callpow1->params.push_back((ast_expression*)base);
- callpow1->params.push_back(
+ callpow1->m_params.push_back((ast_expression*)base);
+ callpow1->m_params.push_back(
(ast_expression*)ast_unary_new(
ctx(),
VINSTR_NEG_F,
* if (exp < 0)
* return 1.0 / <callpow1>;
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
);
/* <callpow2> = pow(base, exp / 2) */
- callpow2->params.push_back((ast_expression*)base);
- callpow2->params.push_back(
+ callpow2->m_params.push_back((ast_expression*)base);
+ callpow2->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_DIV_F,
* return result * result;
* }
*/
- expgt1->exprs.push_back(
+ expgt1->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
(ast_expression*)callpow2
)
);
- expgt1->exprs.push_back(
+ expgt1->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
* <expgt1>
* }
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
/*
* <callsqrt1> = sqrt(base)
*/
- callsqrt1->params.push_back((ast_expression*)base);
+ callsqrt1->m_params.push_back((ast_expression*)base);
/*
* low = 0.0f;
* accumulate = square;
* mid = high / 2.0f;
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(ctx(),
INSTR_STORE_F,
(ast_expression*)low,
(ast_expression*)m_fold->m_imm_float[0]
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
(ast_expression*)square
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* accumulate *= square;
* }
*/
- midltexp->exprs.push_back(
+ midltexp->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
(ast_expression*)mid
)
);
- midltexp->exprs.push_back(
+ midltexp->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
* accumulate *= (1.0 / square);
* }
*/
- midltexpelse->exprs.push_back(
+ midltexpelse->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
(ast_expression*)mid
)
);
- midltexpelse->exprs.push_back(
+ midltexpelse->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
/*
* <callsqrt2> = sqrt(square)
*/
- callsqrt2->params.push_back((ast_expression*)square);
+ callsqrt2->m_params.push_back((ast_expression*)square);
/*
* <whileblock> = {
* mid = (low + high) / 2;
* }
*/
- whileblock->exprs.push_back(
+ whileblock->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
(ast_expression*)callsqrt2
)
);
- whileblock->exprs.push_back(
+ whileblock->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
(ast_expression*)midltexpelse
)
);
- whileblock->exprs.push_back(
+ whileblock->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
/*
* <callabs> = fabs(mid - exp)
*/
- callfabs->params.push_back(
+ callfabs->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_SUB_F,
* while (<callfabs> > epsilon)
* <whileblock>
*/
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
/* init */
);
/* return accumulate */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)accumulate
);
/* } */
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "mod", TYPE_FLOAT);
- val->type_params.push_back(a);
- val->type_params.push_back(b);
+ val->m_type_params.push_back(a);
+ val->m_type_params.push_back(b);
- body->locals.push_back(div);
- body->locals.push_back(sign);
+ body->m_locals.push_back(div);
+ body->m_locals.push_back(sign);
/* div = a / b; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* sign = (div < 0.0f) ? -1 : 1; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* floor(sign * div) */
- call->params.push_back(
+ call->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
INSTR_MUL_F,
);
/* return a - b * sign * <call> */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "fabs", TYPE_FLOAT);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_ternary_new(
)
);
- val->type_params.push_back(arg1);
+ val->m_type_params.push_back(arg1);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, "epsilon", TYPE_FLOAT);
- body->locals.push_back(eps);
+ body->m_locals.push_back(eps);
/* eps = 1.0f; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
);
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
nullptr,
);
/* return eps; */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)eps
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_function *func = value(&val, "nan", TYPE_FLOAT);
ast_block *block = ast_block_new(ctx());
- block->locals.push_back(x);
+ block->m_locals.push_back(x);
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
);
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- func->blocks.emplace_back(block);
+ func->m_blocks.emplace_back(block);
reg(val, func);
return (ast_expression*)val;
}
ast_block *block = ast_block_new(ctx());
size_t i;
- block->locals.push_back(x);
- block->locals.push_back(y);
+ block->m_locals.push_back(x);
+ block->m_locals.push_back(y);
/* to keep code size down */
for (i = 0; i <= 1; i++) {
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
}
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- func->blocks.emplace_back(block);
+ func->m_blocks.emplace_back(block);
reg(val, func);
return (ast_expression*)val;
}
ast_function *func = value(&val, "ln", TYPE_FLOAT);
size_t i;
- val->type_params.push_back(power);
- val->type_params.push_back(base);
+ val->m_type_params.push_back(power);
+ val->m_type_params.push_back(base);
- block->locals.push_back(whole);
- block->locals.push_back(nth);
- block->locals.push_back(sign);
- block->locals.push_back(eps);
- block->locals.push_back(A_i);
- block->locals.push_back(B_i);
- block->locals.push_back(A_iminus1);
- block->locals.push_back(B_iminus1);
+ block->m_locals.push_back(whole);
+ block->m_locals.push_back(nth);
+ block->m_locals.push_back(sign);
+ block->m_locals.push_back(eps);
+ block->m_locals.push_back(A_i);
+ block->m_locals.push_back(B_i);
+ block->m_locals.push_back(A_iminus1);
+ block->m_locals.push_back(B_iminus1);
/* sign = 1.0f; */
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* eps = __builtin_epsilon(); */
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
for (i = 0; i <= 1; i++) {
int j;
for (j = 1; j >= 0; j--) {
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* }
*/
for (i = 0; i <= 1; i++) {
- ((i) ? blt1 : plt1)->exprs.push_back(
+ ((i) ? blt1 : plt1)->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
)
)
);
- plt1->exprs.push_back(
+ plt1->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
* <blt1>
* }
*/
- plt1orblt1->exprs.push_back(
+ plt1orblt1->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
);
for (i = 0; i <= 1; i++) {
- plt1orblt1->exprs.push_back(
+ plt1orblt1->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
);
}
- block->exprs.push_back((ast_expression*)plt1orblt1);
+ block->m_exprs.push_back((ast_expression*)plt1orblt1);
/* whole = power; */
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* nth = 0.0f; */
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* base2 = base; */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* n2 = 1.0f; */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* newbase2 = base2 * base2; */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* while loop locals */
- whileloop->locals.push_back(base2);
- whileloop->locals.push_back(n2);
- whileloop->locals.push_back(newbase2);
+ whileloop->m_locals.push_back(base2);
+ whileloop->m_locals.push_back(n2);
+ whileloop->m_locals.push_back(newbase2);
/* base2 = newbase2; */
- nestwhile->exprs.push_back(
+ nestwhile->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
);
/* n2 *= 2; */
- nestwhile->exprs.push_back(
+ nestwhile->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
);
/* newbase2 *= newbase2; */
- nestwhile->exprs.push_back(
+ nestwhile->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
);
/* while (whole >= newbase2) */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
nullptr,
);
/* whole /= base2; */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
);
/* nth += n2; */
- whileloop->exprs.push_back(
+ whileloop->m_exprs.push_back(
(ast_expression*)ast_binstore_new(
ctx(),
INSTR_STORE_F,
);
/* while (whole >= base) */
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
nullptr,
)
);
- forloop->locals.push_back(b_iplus1);
- forloop->locals.push_back(A_iplus1);
- forloop->locals.push_back(B_iplus1);
+ forloop->m_locals.push_back(b_iplus1);
+ forloop->m_locals.push_back(A_iplus1);
+ forloop->m_locals.push_back(B_iplus1);
/* b_iplus1 = nth; */
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* B_iplus1 = b_iplus1 * B_i + B_iminus1;
*/
for (i = 0; i <= 1; i++) {
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* B_iminus1 = B_i;
*/
for (i = 0; i <= 1; i++) {
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* B_i = B_iplus1;
*/
for (i = 0; i <= 1; i++) {
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
* if (whole <= 1.0f + eps)
* break;
*/
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_ifthen_new(
ctx(),
(ast_expression*)ast_binary_new(
* base = whole;
*/
for (i = 0; i <= 1; i++) {
- forloop->exprs.push_back(
+ forloop->m_exprs.push_back(
(ast_expression*)ast_store_new(
ctx(),
INSTR_STORE_F,
}
/* add the for loop block */
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_loop_new(
ctx(),
nullptr,
);
/* return sign * A_i / B_il */
- block->exprs.push_back(
+ block->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)ast_binary_new(
)
);
- func->blocks.emplace_back(block);
+ func->m_blocks.emplace_back(block);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, name, TYPE_FLOAT);
- val->type_params.push_back(arg1);
+ val->m_type_params.push_back(arg1);
- callln->params.push_back((ast_expression*)arg1);
- callln->params.push_back((ast_expression*)m_fold->constgen_float(base, false));
+ callln->m_params.push_back((ast_expression*)arg1);
+ callln->m_params.push_back((ast_expression*)m_fold->constgen_float(base, false));
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)callln
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
ast_block *body = ast_block_new(ctx());
ast_function *func = value(&val, name, TYPE_FLOAT);
- val->type_params.push_back(a);
- val->type_params.push_back(b);
+ val->m_type_params.push_back(a);
+ val->m_type_params.push_back(b);
/* <callpow> = pow(2, b) */
- callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
- callpow->params.push_back((ast_expression*)b);
+ callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]);
+ callpow->m_params.push_back((ast_expression*)b);
/* <callfloor> = floor(a [instr] <callpow>) */
- callfloor->params.push_back(
+ callfloor->m_params.push_back(
(ast_expression*)ast_binary_new(
ctx(),
instr,
);
/* return <callfloor> */
- body->exprs.push_back(
+ body->m_exprs.push_back(
(ast_expression*)ast_return_new(
ctx(),
(ast_expression*)callfloor
)
);
- func->blocks.emplace_back(body);
+ func->m_blocks.emplace_back(body);
reg(val, func);
return (ast_expression*)val;
}
}
ast_expression *intrin::do_fold(ast_value *val, ast_expression **exprs) {
- if (!val || !val->name)
+ if (!val || !val->m_name)
return nullptr;
static constexpr size_t kPrefixLength = 10; // "__builtin_"
for (auto &it : m_intrinsics) {
- if (!strcmp(val->name, it.name))
+ if (!strcmp(val->m_name, it.name))
return (vec_size(exprs) != it.args)
? nullptr
- : m_fold->intrinsic(val->name + kPrefixLength, exprs);
+ : m_fold->intrinsic(val->m_name + kPrefixLength, exprs);
}
return nullptr;
}
ast_expression *intrin::func_self(const char *name, const char *from) {
ast_expression *find;
/* try current first */
- if ((find = parser_find_global(m_parser, name)) && ((ast_value*)find)->vtype == TYPE_FUNCTION)
+ if ((find = parser_find_global(m_parser, name)) && ((ast_value*)find)->m_vtype == TYPE_FUNCTION)
for (auto &it : m_parser->functions)
- if (((ast_value*)find)->name && !strcmp(it->name, ((ast_value*)find)->name) && it->builtin < 0)
+ if (((ast_value*)find)->m_name && !strcmp(it->m_name, ((ast_value*)find)->m_name) && it->m_builtin < 0)
return find;
/* try name second */
if ((find = func_try(offsetof(intrin_func_t, name), name)))
static void ir_instr_delete_quick(ir_instr *self);
static void ir_function_delete_quick(ir_function *self);
-void* ir_builder::operator new(std::size_t bytes)
-{
- return mem_a(bytes);
-}
-
-void ir_builder::operator delete(void *ptr)
-{
- mem_d(ptr);
-}
-
ir_builder::ir_builder(const std::string& modulename)
-: name(modulename),
- code(new code_t)
+: m_name(modulename),
+ m_code(new code_t)
{
- htglobals = util_htnew(IR_HT_SIZE);
- htfields = util_htnew(IR_HT_SIZE);
- htfunctions = util_htnew(IR_HT_SIZE);
+ m_htglobals = util_htnew(IR_HT_SIZE);
+ m_htfields = util_htnew(IR_HT_SIZE);
+ m_htfunctions = util_htnew(IR_HT_SIZE);
- nil = new ir_value("nil", store_value, TYPE_NIL);
- nil->cvq = CV_CONST;
+ m_nil = new ir_value("nil", store_value, TYPE_NIL);
+ m_nil->m_cvq = CV_CONST;
for (size_t i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
/* we write to them, but they're not supposed to be used outside the IR, so
* let's not allow the generation of ir_instrs which use these.
* So it's a constant noexpr.
*/
- vinstr_temp[i] = new ir_value("vinstr_temp", store_value, TYPE_NOEXPR);
- vinstr_temp[i]->cvq = CV_CONST;
+ m_vinstr_temp[i] = new ir_value("vinstr_temp", store_value, TYPE_NOEXPR);
+ m_vinstr_temp[i]->m_cvq = CV_CONST;
}
}
ir_builder::~ir_builder()
{
- util_htdel(htglobals);
- util_htdel(htfields);
- util_htdel(htfunctions);
- for (auto& f : functions)
+ util_htdel(m_htglobals);
+ util_htdel(m_htfields);
+ util_htdel(m_htfunctions);
+ for (auto& f : m_functions)
ir_function_delete_quick(f.release());
- functions.clear(); // delete them now before deleting the rest:
+ m_functions.clear(); // delete them now before deleting the rest:
- delete nil;
+ delete m_nil;
for (size_t i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
- delete vinstr_temp[i];
+ delete m_vinstr_temp[i];
}
- extparams.clear();
- extparam_protos.clear();
+ m_extparams.clear();
+ m_extparam_protos.clear();
}
static ir_function* ir_builder_get_function(ir_builder *self, const char *name)
{
- return (ir_function*)util_htget(self->htfunctions, name);
+ return (ir_function*)util_htget(self->m_htfunctions, name);
}
ir_function* ir_builder_create_function(ir_builder *self, const std::string& name, qc_type outtype)
}
fn = new ir_function(self, outtype);
- fn->name = name;
- self->functions.emplace_back(fn);
- util_htset(self->htfunctions, name.c_str(), fn);
+ fn->m_name = name;
+ self->m_functions.emplace_back(fn);
+ util_htset(self->m_htfunctions, name.c_str(), fn);
- fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION);
- if (!fn->value) {
+ fn->m_value = ir_builder_create_global(self, fn->m_name, TYPE_FUNCTION);
+ if (!fn->m_value) {
delete fn;
return nullptr;
}
- fn->value->hasvalue = true;
- fn->value->outtype = outtype;
- fn->value->constval.vfunc = fn;
- fn->value->context = fn->context;
+ fn->m_value->m_hasvalue = true;
+ fn->m_value->m_outtype = outtype;
+ fn->m_value->m_constval.vfunc = fn;
+ fn->m_value->m_context = fn->m_context;
return fn;
}
static ir_value* ir_builder_get_global(ir_builder *self, const char *name)
{
- return (ir_value*)util_htget(self->htglobals, name);
+ return (ir_value*)util_htget(self->m_htglobals, name);
}
ir_value* ir_builder_create_global(ir_builder *self, const std::string& name, qc_type vtype)
}
ve = new ir_value(std::string(name), store_global, vtype);
- self->globals.emplace_back(ve);
- util_htset(self->htglobals, name.c_str(), ve);
+ self->m_globals.emplace_back(ve);
+ util_htset(self->m_htglobals, name.c_str(), ve);
return ve;
}
ir_value* ir_builder_get_va_count(ir_builder *self)
{
- if (self->reserved_va_count)
- return self->reserved_va_count;
- return (self->reserved_va_count = ir_builder_create_global(self, "reserved:va_count", TYPE_FLOAT));
+ if (self->m_reserved_va_count)
+ return self->m_reserved_va_count;
+ return (self->m_reserved_va_count = ir_builder_create_global(self, "reserved:va_count", TYPE_FLOAT));
}
static ir_value* ir_builder_get_field(ir_builder *self, const char *name)
{
- return (ir_value*)util_htget(self->htfields, name);
+ return (ir_value*)util_htget(self->m_htfields, name);
}
}
ve = new ir_value(std::string(name), store_global, TYPE_FIELD);
- ve->fieldtype = vtype;
- self->fields.emplace_back(ve);
- util_htset(self->htfields, name.c_str(), ve);
+ ve->m_fieldtype = vtype;
+ self->m_fields.emplace_back(ve);
+ util_htset(self->m_htfields, name.c_str(), ve);
return ve;
}
static bool ir_function_calculate_liferanges(ir_function*);
static bool ir_function_allocate_locals(ir_function*);
-void* ir_function::operator new(std::size_t bytes)
-{
- return mem_a(bytes);
-}
-
-void ir_function::operator delete(void *ptr)
-{
- mem_d(ptr);
-}
-
ir_function::ir_function(ir_builder* owner_, qc_type outtype_)
-: owner(owner_),
- name("<@unnamed>"),
- outtype(outtype_)
+: m_owner(owner_),
+ m_name("<@unnamed>"),
+ m_outtype(outtype_)
{
- context.file = "<@no context>";
- context.line = 0;
+ m_context.file = "<@no context>";
+ m_context.line = 0;
}
ir_function::~ir_function()
static void ir_function_delete_quick(ir_function *self)
{
- for (auto& b : self->blocks)
+ for (auto& b : self->m_blocks)
ir_block_delete_quick(b.release());
delete self;
}
static void ir_function_collect_value(ir_function *self, ir_value *v)
{
- self->values.emplace_back(v);
+ self->m_values.emplace_back(v);
}
ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function *self, const char *label)
{
ir_block* bn = new ir_block(self, label ? std::string(label) : std::string());
- bn->context = ctx;
- self->blocks.emplace_back(bn);
+ bn->m_context = ctx;
+ self->m_blocks.emplace_back(bn);
- if ((self->flags & IR_FLAG_BLOCK_COVERAGE) && self->owner->coverage_func)
- (void)ir_block_create_call(bn, ctx, nullptr, self->owner->coverage_func, false);
+ if ((self->m_flags & IR_FLAG_BLOCK_COVERAGE) && self->m_owner->m_coverage_func)
+ (void)ir_block_create_call(bn, ctx, nullptr, self->m_owner->m_coverage_func, false);
return bn;
}
static bool ir_function_pass_peephole(ir_function *self)
{
- for (auto& bp : self->blocks) {
+ for (auto& bp : self->m_blocks) {
ir_block *block = bp.get();
- for (size_t i = 0; i < vec_size(block->instr); ++i) {
+ for (size_t i = 0; i < vec_size(block->m_instr); ++i) {
ir_instr *inst;
- inst = block->instr[i];
+ inst = block->m_instr[i];
if (i >= 1 &&
- (inst->opcode >= INSTR_STORE_F &&
- inst->opcode <= INSTR_STORE_FNC))
+ (inst->m_opcode >= INSTR_STORE_F &&
+ inst->m_opcode <= INSTR_STORE_FNC))
{
ir_instr *store;
ir_instr *oper;
store = inst;
- oper = block->instr[i-1];
- if (!instr_is_operation(oper->opcode))
+ oper = block->m_instr[i-1];
+ if (!instr_is_operation(oper->m_opcode))
continue;
/* Don't change semantics of MUL_VF in engines where these may not alias. */
if (OPTS_FLAG(LEGACY_VECTOR_MATHS)) {
- if (oper->opcode == INSTR_MUL_VF && oper->_ops[2]->memberof == oper->_ops[1])
+ if (oper->m_opcode == INSTR_MUL_VF && oper->_m_ops[2]->m_memberof == oper->_m_ops[1])
continue;
- if (oper->opcode == INSTR_MUL_FV && oper->_ops[1]->memberof == oper->_ops[2])
+ if (oper->m_opcode == INSTR_MUL_FV && oper->_m_ops[1]->m_memberof == oper->_m_ops[2])
continue;
}
- value = oper->_ops[0];
+ value = oper->_m_ops[0];
/* only do it for SSA values */
- if (value->store != store_value)
+ if (value->m_store != store_value)
continue;
/* don't optimize out the temp if it's used later again */
- if (value->reads.size() != 1)
+ if (value->m_reads.size() != 1)
continue;
/* The very next store must use this value */
- if (value->reads[0] != store)
+ if (value->m_reads[0] != store)
continue;
/* And of course the store must _read_ from it, so it's in
* OP 1 */
- if (store->_ops[1] != value)
+ if (store->_m_ops[1] != value)
continue;
++opts_optimizationcount[OPTIM_PEEPHOLE];
- (void)!ir_instr_op(oper, 0, store->_ops[0], true);
+ (void)!ir_instr_op(oper, 0, store->_m_ops[0], true);
- vec_remove(block->instr, i, 1);
+ vec_remove(block->m_instr, i, 1);
delete store;
}
- else if (inst->opcode == VINSTR_COND)
+ else if (inst->m_opcode == VINSTR_COND)
{
/* COND on a value resulting from a NOT could
* remove the NOT and swap its operands
size_t inotid;
ir_instr *inot;
ir_value *value;
- value = inst->_ops[0];
+ value = inst->_m_ops[0];
- if (value->store != store_value || value->reads.size() != 1 || value->reads[0] != inst)
+ if (value->m_store != store_value || value->m_reads.size() != 1 || value->m_reads[0] != inst)
break;
- inot = value->writes[0];
- if (inot->_ops[0] != value ||
- inot->opcode < INSTR_NOT_F ||
- inot->opcode > INSTR_NOT_FNC ||
- inot->opcode == INSTR_NOT_V || /* can't do these */
- inot->opcode == INSTR_NOT_S)
+ inot = value->m_writes[0];
+ if (inot->_m_ops[0] != value ||
+ inot->m_opcode < INSTR_NOT_F ||
+ inot->m_opcode > INSTR_NOT_FNC ||
+ inot->m_opcode == INSTR_NOT_V || /* can't do these */
+ inot->m_opcode == INSTR_NOT_S)
{
break;
}
/* count */
++opts_optimizationcount[OPTIM_PEEPHOLE];
/* change operand */
- (void)!ir_instr_op(inst, 0, inot->_ops[1], false);
+ (void)!ir_instr_op(inst, 0, inot->_m_ops[1], false);
/* remove NOT */
- tmp = inot->owner;
- for (inotid = 0; inotid < vec_size(tmp->instr); ++inotid) {
- if (tmp->instr[inotid] == inot)
+ tmp = inot->m_owner;
+ for (inotid = 0; inotid < vec_size(tmp->m_instr); ++inotid) {
+ if (tmp->m_instr[inotid] == inot)
break;
}
- if (inotid >= vec_size(tmp->instr)) {
- compile_error(inst->context, "sanity-check failed: failed to find instruction to optimize out");
+ if (inotid >= vec_size(tmp->m_instr)) {
+ compile_error(inst->m_context, "sanity-check failed: failed to find instruction to optimize out");
return false;
}
- vec_remove(tmp->instr, inotid, 1);
+ vec_remove(tmp->m_instr, inotid, 1);
delete inot;
/* swap ontrue/onfalse */
- tmp = inst->bops[0];
- inst->bops[0] = inst->bops[1];
- inst->bops[1] = tmp;
+ tmp = inst->m_bops[0];
+ inst->m_bops[0] = inst->m_bops[1];
+ inst->m_bops[1] = tmp;
}
continue;
}
{
size_t p;
- for (auto& bp : self->blocks) {
+ for (auto& bp : self->m_blocks) {
ir_block *block = bp.get();
ir_value *funcval;
ir_instr *ret, *call, *store = nullptr;
- if (!block->final || vec_size(block->instr) < 2)
+ if (!block->m_final || vec_size(block->m_instr) < 2)
continue;
- ret = block->instr[vec_size(block->instr)-1];
- if (ret->opcode != INSTR_DONE && ret->opcode != INSTR_RETURN)
+ ret = block->m_instr[vec_size(block->m_instr)-1];
+ if (ret->m_opcode != INSTR_DONE && ret->m_opcode != INSTR_RETURN)
continue;
- call = block->instr[vec_size(block->instr)-2];
- if (call->opcode >= INSTR_STORE_F && call->opcode <= INSTR_STORE_FNC) {
+ call = block->m_instr[vec_size(block->m_instr)-2];
+ if (call->m_opcode >= INSTR_STORE_F && call->m_opcode <= INSTR_STORE_FNC) {
/* account for the unoptimized
* CALL
* STORE %return, %tmp
* RETURN %tmp
* version
*/
- if (vec_size(block->instr) < 3)
+ if (vec_size(block->m_instr) < 3)
continue;
store = call;
- call = block->instr[vec_size(block->instr)-3];
+ call = block->m_instr[vec_size(block->m_instr)-3];
}
- if (call->opcode < INSTR_CALL0 || call->opcode > INSTR_CALL8)
+ if (call->m_opcode < INSTR_CALL0 || call->m_opcode > INSTR_CALL8)
continue;
if (store) {
/* optimize out the STORE */
- if (ret->_ops[0] &&
- ret->_ops[0] == store->_ops[0] &&
- store->_ops[1] == call->_ops[0])
+ if (ret->_m_ops[0] &&
+ ret->_m_ops[0] == store->_m_ops[0] &&
+ store->_m_ops[1] == call->_m_ops[0])
{
++opts_optimizationcount[OPTIM_PEEPHOLE];
- call->_ops[0] = store->_ops[0];
- vec_remove(block->instr, vec_size(block->instr) - 2, 1);
+ call->_m_ops[0] = store->_m_ops[0];
+ vec_remove(block->m_instr, vec_size(block->m_instr) - 2, 1);
delete store;
}
else
continue;
}
- if (!call->_ops[0])
+ if (!call->_m_ops[0])
continue;
- funcval = call->_ops[1];
+ funcval = call->_m_ops[1];
if (!funcval)
continue;
- if (funcval->vtype != TYPE_FUNCTION || funcval->constval.vfunc != self)
+ if (funcval->m_vtype != TYPE_FUNCTION || funcval->m_constval.vfunc != self)
continue;
/* now we have a CALL and a RET, check if it's a tailcall */
- if (ret->_ops[0] && call->_ops[0] != ret->_ops[0])
+ if (ret->_m_ops[0] && call->_m_ops[0] != ret->_m_ops[0])
continue;
++opts_optimizationcount[OPTIM_TAIL_RECURSION];
- vec_shrinkby(block->instr, 2);
+ vec_shrinkby(block->m_instr, 2);
- block->final = false; /* open it back up */
+ block->m_final = false; /* open it back up */
/* emite parameter-stores */
- for (p = 0; p < call->params.size(); ++p) {
+ for (p = 0; p < call->m_params.size(); ++p) {
/* assert(call->params_count <= self->locals_count); */
- if (!ir_block_create_store(block, call->context, self->locals[p].get(), call->params[p])) {
- irerror(call->context, "failed to create tailcall store instruction for parameter %i", (int)p);
+ if (!ir_block_create_store(block, call->m_context, self->m_locals[p].get(), call->m_params[p])) {
+ irerror(call->m_context, "failed to create tailcall store instruction for parameter %i", (int)p);
return false;
}
}
- if (!ir_block_create_jump(block, call->context, self->blocks[0].get())) {
- irerror(call->context, "failed to create tailcall jump");
+ if (!ir_block_create_jump(block, call->m_context, self->m_blocks[0].get())) {
+ irerror(call->m_context, "failed to create tailcall jump");
return false;
}
bool ir_function_finalize(ir_function *self)
{
- if (self->builtin)
+ if (self->m_builtin)
return true;
if (OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
if (!ir_function_pass_peephole(self)) {
- irerror(self->context, "generic optimization pass broke something in `%s`", self->name.c_str());
+ irerror(self->m_context, "generic optimization pass broke something in `%s`", self->m_name.c_str());
return false;
}
}
if (OPTS_OPTIMIZATION(OPTIM_TAIL_RECURSION)) {
if (!ir_function_pass_tailrecursion(self)) {
- irerror(self->context, "tail-recursion optimization pass broke something in `%s`", self->name.c_str());
+ irerror(self->m_context, "tail-recursion optimization pass broke something in `%s`", self->m_name.c_str());
return false;
}
}
if (!ir_function_naive_phi(self)) {
- irerror(self->context, "internal error: ir_function_naive_phi failed");
+ irerror(self->m_context, "internal error: ir_function_naive_phi failed");
return false;
}
- for (auto& lp : self->locals) {
+ for (auto& lp : self->m_locals) {
ir_value *v = lp.get();
- if (v->vtype == TYPE_VECTOR ||
- (v->vtype == TYPE_FIELD && v->outtype == TYPE_VECTOR))
+ if (v->m_vtype == TYPE_VECTOR ||
+ (v->m_vtype == TYPE_FIELD && v->m_outtype == TYPE_VECTOR))
{
ir_value_vector_member(v, 0);
ir_value_vector_member(v, 1);
ir_value_vector_member(v, 2);
}
}
- for (auto& vp : self->values) {
+ for (auto& vp : self->m_values) {
ir_value *v = vp.get();
- if (v->vtype == TYPE_VECTOR ||
- (v->vtype == TYPE_FIELD && v->outtype == TYPE_VECTOR))
+ if (v->m_vtype == TYPE_VECTOR ||
+ (v->m_vtype == TYPE_FIELD && v->m_outtype == TYPE_VECTOR))
{
ir_value_vector_member(v, 0);
ir_value_vector_member(v, 1);
ir_value *ve;
if (param &&
- !self->locals.empty() &&
- self->locals.back()->store != store_param)
+ !self->m_locals.empty() &&
+ self->m_locals.back()->m_store != store_param)
{
- irerror(self->context, "cannot add parameters after adding locals");
+ irerror(self->m_context, "cannot add parameters after adding locals");
return nullptr;
}
ve = new ir_value(std::string(name), (param ? store_param : store_local), vtype);
if (param)
- ve->locked = true;
- self->locals.emplace_back(ve);
+ ve->m_locked = true;
+ self->m_locals.emplace_back(ve);
return ve;
}
*IR Block
*/
-void* ir_block::operator new(std::size_t bytes) {
- return mem_a(bytes);
-}
-
-void ir_block::operator delete(void *data) {
- mem_d(data);
-}
-
ir_block::ir_block(ir_function* owner, const std::string& name)
-: owner(owner),
- label(name)
+: m_owner(owner),
+ m_label(name)
{
- context.file = "<@no context>";
- context.line = 0;
+ m_context.file = "<@no context>";
+ m_context.line = 0;
}
ir_block::~ir_block()
{
- for (size_t i = 0; i != vec_size(instr); ++i)
- delete instr[i];
- vec_free(instr);
- vec_free(entries);
- vec_free(exits);
+ for (size_t i = 0; i != vec_size(m_instr); ++i)
+ delete m_instr[i];
+ vec_free(m_instr);
+ vec_free(m_entries);
+ vec_free(m_exits);
}
static void ir_block_delete_quick(ir_block* self)
{
size_t i;
- for (i = 0; i != vec_size(self->instr); ++i)
- ir_instr_delete_quick(self->instr[i]);
- vec_free(self->instr);
+ for (i = 0; i != vec_size(self->m_instr); ++i)
+ ir_instr_delete_quick(self->m_instr[i]);
+ vec_free(self->m_instr);
delete self;
}
*IR Instructions
*/
-void* ir_instr::operator new(std::size_t bytes) {
- return mem_a(bytes);
-}
-
-void ir_instr::operator delete(void *data) {
- mem_d(data);
-}
-
ir_instr::ir_instr(lex_ctx_t ctx, ir_block* owner_, int op)
-: opcode(op),
- context(ctx),
- owner(owner_)
+: m_opcode(op),
+ m_context(ctx),
+ m_owner(owner_)
{
}
// so ignore the return value. Since with the warn_unused_result attribute
// gcc doesn't care about an explicit: (void)foo(); to ignore the result,
// I have to improvise here and use if(foo());
- for (auto &it : phi) {
+ for (auto &it : m_phi) {
size_t idx;
- if (vec_ir_instr_find(it.value->writes, this, &idx))
- it.value->writes.erase(it.value->writes.begin() + idx);
- if (vec_ir_instr_find(it.value->reads, this, &idx))
- it.value->reads.erase(it.value->reads.begin() + idx);
+ if (vec_ir_instr_find(it.value->m_writes, this, &idx))
+ it.value->m_writes.erase(it.value->m_writes.begin() + idx);
+ if (vec_ir_instr_find(it.value->m_reads, this, &idx))
+ it.value->m_reads.erase(it.value->m_reads.begin() + idx);
}
- for (auto &it : params) {
+ for (auto &it : m_params) {
size_t idx;
- if (vec_ir_instr_find(it->writes, this, &idx))
- it->writes.erase(it->writes.begin() + idx);
- if (vec_ir_instr_find(it->reads, this, &idx))
- it->reads.erase(it->reads.begin() + idx);
+ if (vec_ir_instr_find(it->m_writes, this, &idx))
+ it->m_writes.erase(it->m_writes.begin() + idx);
+ if (vec_ir_instr_find(it->m_reads, this, &idx))
+ it->m_reads.erase(it->m_reads.begin() + idx);
}
(void)!ir_instr_op(this, 0, nullptr, false);
(void)!ir_instr_op(this, 1, nullptr, false);
static void ir_instr_delete_quick(ir_instr *self)
{
- self->phi.clear();
- self->params.clear();
+ self->m_phi.clear();
+ self->m_params.clear();
delete self;
}
static bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing)
{
- if (v && v->vtype == TYPE_NOEXPR) {
- irerror(self->context, "tried to use a NOEXPR value");
+ if (v && v->m_vtype == TYPE_NOEXPR) {
+ irerror(self->m_context, "tried to use a NOEXPR value");
return false;
}
- if (self->_ops[op]) {
+ if (self->_m_ops[op]) {
size_t idx;
- if (writing && vec_ir_instr_find(self->_ops[op]->writes, self, &idx))
- self->_ops[op]->writes.erase(self->_ops[op]->writes.begin() + idx);
- else if (vec_ir_instr_find(self->_ops[op]->reads, self, &idx))
- self->_ops[op]->reads.erase(self->_ops[op]->reads.begin() + idx);
+ if (writing && vec_ir_instr_find(self->_m_ops[op]->m_writes, self, &idx))
+ self->_m_ops[op]->m_writes.erase(self->_m_ops[op]->m_writes.begin() + idx);
+ else if (vec_ir_instr_find(self->_m_ops[op]->m_reads, self, &idx))
+ self->_m_ops[op]->m_reads.erase(self->_m_ops[op]->m_reads.begin() + idx);
}
if (v) {
if (writing)
- v->writes.push_back(self);
+ v->m_writes.push_back(self);
else
- v->reads.push_back(self);
+ v->m_reads.push_back(self);
}
- self->_ops[op] = v;
+ self->_m_ops[op] = v;
return true;
}
static void ir_value_code_setaddr(ir_value *self, int32_t gaddr)
{
- self->code.globaladdr = gaddr;
- if (self->members[0]) self->members[0]->code.globaladdr = gaddr;
- if (self->members[1]) self->members[1]->code.globaladdr = gaddr;
- if (self->members[2]) self->members[2]->code.globaladdr = gaddr;
+ self->m_code.globaladdr = gaddr;
+ if (self->m_members[0]) self->m_members[0]->m_code.globaladdr = gaddr;
+ if (self->m_members[1]) self->m_members[1]->m_code.globaladdr = gaddr;
+ if (self->m_members[2]) self->m_members[2]->m_code.globaladdr = gaddr;
}
static int32_t ir_value_code_addr(const ir_value *self)
{
- if (self->store == store_return)
- return OFS_RETURN + self->code.addroffset;
- return self->code.globaladdr + self->code.addroffset;
-}
-
-void* ir_value::operator new(std::size_t bytes) {
- return mem_a(bytes);
-}
-
-void ir_value::operator delete(void *data) {
- mem_d(data);
+ if (self->m_store == store_return)
+ return OFS_RETURN + self->m_code.addroffset;
+ return self->m_code.globaladdr + self->m_code.addroffset;
}
ir_value::ir_value(std::string&& name_, store_type store_, qc_type vtype_)
-: name(move(name_)),
- vtype(vtype_),
- store(store_)
+: m_name(move(name_)),
+ m_vtype(vtype_),
+ m_store(store_)
{
- fieldtype = TYPE_VOID;
- outtype = TYPE_VOID;
- flags = 0;
-
- cvq = CV_NONE;
- hasvalue = false;
- context.file = "<@no context>";
- context.line = 0;
-
- memset(&constval, 0, sizeof(constval));
- memset(&code, 0, sizeof(code));
-
- members[0] = nullptr;
- members[1] = nullptr;
- members[2] = nullptr;
- memberof = nullptr;
-
- unique_life = false;
- locked = false;
- callparam = false;
+ m_fieldtype = TYPE_VOID;
+ m_outtype = TYPE_VOID;
+ m_flags = 0;
+
+ m_cvq = CV_NONE;
+ m_hasvalue = false;
+ m_context.file = "<@no context>";
+ m_context.line = 0;
+
+ memset(&m_constval, 0, sizeof(m_constval));
+ memset(&m_code, 0, sizeof(m_code));
+
+ m_members[0] = nullptr;
+ m_members[1] = nullptr;
+ m_members[2] = nullptr;
+ m_memberof = nullptr;
+
+ m_unique_life = false;
+ m_locked = false;
+ m_callparam = false;
}
ir_value::~ir_value()
{
size_t i;
- if (hasvalue) {
- if (vtype == TYPE_STRING)
- mem_d((void*)constval.vstring);
+ if (m_hasvalue) {
+ if (m_vtype == TYPE_STRING)
+ mem_d((void*)m_constval.vstring);
}
- if (!(flags & IR_FLAG_SPLIT_VECTOR)) {
+ if (!(m_flags & IR_FLAG_SPLIT_VECTOR)) {
for (i = 0; i < 3; ++i) {
- if (members[i])
- delete members[i];
+ if (m_members[i])
+ delete m_members[i];
}
}
}
/* helper function */
static ir_value* ir_builder_imm_float(ir_builder *self, float value, bool add_to_list) {
ir_value *v = new ir_value("#IMMEDIATE", store_global, TYPE_FLOAT);
- v->flags |= IR_FLAG_ERASABLE;
- v->hasvalue = true;
- v->cvq = CV_CONST;
- v->constval.vfloat = value;
+ v->m_flags |= IR_FLAG_ERASABLE;
+ v->m_hasvalue = true;
+ v->m_cvq = CV_CONST;
+ v->m_constval.vfloat = value;
- self->globals.emplace_back(v);
+ self->m_globals.emplace_back(v);
if (add_to_list)
- self->const_floats.emplace_back(v);
+ self->m_const_floats.emplace_back(v);
return v;
}
if (member >= 3)
return nullptr;
- if (self->members[member])
- return self->members[member];
+ if (self->m_members[member])
+ return self->m_members[member];
- if (!self->name.empty()) {
+ if (!self->m_name.empty()) {
char member_name[3] = { '_', char('x' + member), 0 };
- name = self->name + member_name;
+ name = self->m_name + member_name;
}
- if (self->vtype == TYPE_VECTOR)
+ if (self->m_vtype == TYPE_VECTOR)
{
- m = new ir_value(move(name), self->store, TYPE_FLOAT);
+ m = new ir_value(move(name), self->m_store, TYPE_FLOAT);
if (!m)
return nullptr;
- m->context = self->context;
+ m->m_context = self->m_context;
- self->members[member] = m;
- m->code.addroffset = member;
+ self->m_members[member] = m;
+ m->m_code.addroffset = member;
}
- else if (self->vtype == TYPE_FIELD)
+ else if (self->m_vtype == TYPE_FIELD)
{
- if (self->fieldtype != TYPE_VECTOR)
+ if (self->m_fieldtype != TYPE_VECTOR)
return nullptr;
- m = new ir_value(move(name), self->store, TYPE_FIELD);
+ m = new ir_value(move(name), self->m_store, TYPE_FIELD);
if (!m)
return nullptr;
- m->fieldtype = TYPE_FLOAT;
- m->context = self->context;
+ m->m_fieldtype = TYPE_FLOAT;
+ m->m_context = self->m_context;
- self->members[member] = m;
- m->code.addroffset = member;
+ self->m_members[member] = m;
+ m->m_code.addroffset = member;
}
else
{
- irerror(self->context, "invalid member access on %s", self->name.c_str());
+ irerror(self->m_context, "invalid member access on %s", self->m_name.c_str());
return nullptr;
}
- m->memberof = self;
+ m->m_memberof = self;
return m;
}
static GMQCC_INLINE size_t ir_value_sizeof(const ir_value *self)
{
- if (self->vtype == TYPE_FIELD && self->fieldtype == TYPE_VECTOR)
+ if (self->m_vtype == TYPE_FIELD && self->m_fieldtype == TYPE_VECTOR)
return type_sizeof_[TYPE_VECTOR];
- return type_sizeof_[self->vtype];
+ return type_sizeof_[self->m_vtype];
}
static ir_value* ir_value_out(ir_function *owner, const char *name, store_type storetype, qc_type vtype)
bool ir_value_set_float(ir_value *self, float f)
{
- if (self->vtype != TYPE_FLOAT)
+ if (self->m_vtype != TYPE_FLOAT)
return false;
- self->constval.vfloat = f;
- self->hasvalue = true;
+ self->m_constval.vfloat = f;
+ self->m_hasvalue = true;
return true;
}
bool ir_value_set_func(ir_value *self, int f)
{
- if (self->vtype != TYPE_FUNCTION)
+ if (self->m_vtype != TYPE_FUNCTION)
return false;
- self->constval.vint = f;
- self->hasvalue = true;
+ self->m_constval.vint = f;
+ self->m_hasvalue = true;
return true;
}
bool ir_value_set_vector(ir_value *self, vec3_t v)
{
- if (self->vtype != TYPE_VECTOR)
+ if (self->m_vtype != TYPE_VECTOR)
return false;
- self->constval.vvec = v;
- self->hasvalue = true;
+ self->m_constval.vvec = v;
+ self->m_hasvalue = true;
return true;
}
bool ir_value_set_field(ir_value *self, ir_value *fld)
{
- if (self->vtype != TYPE_FIELD)
+ if (self->m_vtype != TYPE_FIELD)
return false;
- self->constval.vpointer = fld;
- self->hasvalue = true;
+ self->m_constval.vpointer = fld;
+ self->m_hasvalue = true;
return true;
}
bool ir_value_set_string(ir_value *self, const char *str)
{
- if (self->vtype != TYPE_STRING)
+ if (self->m_vtype != TYPE_STRING)
return false;
- self->constval.vstring = util_strdupe(str);
- self->hasvalue = true;
+ self->m_constval.vstring = util_strdupe(str);
+ self->m_hasvalue = true;
return true;
}
#if 0
bool ir_value_set_int(ir_value *self, int i)
{
- if (self->vtype != TYPE_INTEGER)
+ if (self->m_vtype != TYPE_INTEGER)
return false;
- self->constval.vint = i;
- self->hasvalue = true;
+ self->m_constval.vint = i;
+ self->m_hasvalue = true;
return true;
}
#endif
bool ir_value_lives(ir_value *self, size_t at)
{
- for (auto& l : self->life) {
+ for (auto& l : self->m_life) {
if (l.start <= at && at <= l.end)
return true;
if (l.start > at) /* since it's ordered */
static bool ir_value_life_insert(ir_value *self, size_t idx, ir_life_entry_t e)
{
- self->life.insert(self->life.begin() + idx, e);
+ self->m_life.insert(self->m_life.begin() + idx, e);
return true;
}
static bool ir_value_life_merge(ir_value *self, size_t s)
{
size_t i;
- const size_t vs = self->life.size();
+ const size_t vs = self->m_life.size();
ir_life_entry_t *life_found = nullptr;
ir_life_entry_t *before = nullptr;
ir_life_entry_t new_entry;
for (i = 0; i < vs; ++i)
{
before = life_found;
- life_found = &self->life[i];
+ life_found = &self->m_life[i];
if (life_found->start > s)
break;
}
if (life_found && life_found->end >= s)
return false;
e.start = e.end = s;
- self->life.emplace_back(e);
+ self->m_life.emplace_back(e);
return true;
}
/* found */
{
/* merge */
before->end = life_found->end;
- self->life.erase(self->life.begin()+i);
+ self->m_life.erase(self->m_life.begin()+i);
return true;
}
if (before->end + 1 == s)
{
size_t i, myi;
- if (other->life.empty())
+ if (other->m_life.empty())
return true;
- if (self->life.empty()) {
- self->life = other->life;
+ if (self->m_life.empty()) {
+ self->m_life = other->m_life;
return true;
}
myi = 0;
- for (i = 0; i < other->life.size(); ++i)
+ for (i = 0; i < other->m_life.size(); ++i)
{
- const ir_life_entry_t &otherlife = other->life[i];
+ const ir_life_entry_t &otherlife = other->m_life[i];
while (true)
{
- ir_life_entry_t *entry = &self->life[myi];
+ ir_life_entry_t *entry = &self->m_life[myi];
if (otherlife.end+1 < entry->start)
{
}
/* see if our change combines it with the next ranges */
- while (myi+1 < self->life.size() &&
- entry->end+1 >= self->life[1+myi].start)
+ while (myi+1 < self->m_life.size() &&
+ entry->end+1 >= self->m_life[1+myi].start)
{
/* overlaps with (myi+1) */
- if (entry->end < self->life[1+myi].end)
- entry->end = self->life[1+myi].end;
- self->life.erase(self->life.begin() + (myi + 1));
- entry = &self->life[myi];
+ if (entry->end < self->m_life[1+myi].end)
+ entry->end = self->m_life[1+myi].end;
+ self->m_life.erase(self->m_life.begin() + (myi + 1));
+ entry = &self->m_life[myi];
}
/* see if we're after the entry */
{
++myi;
/* append if we're at the end */
- if (myi >= self->life.size()) {
- self->life.emplace_back(otherlife);
+ if (myi >= self->m_life.size()) {
+ self->m_life.emplace_back(otherlife);
break;
}
/* otherweise check the next range */
const ir_life_entry_t *la, *lb, *enda, *endb;
/* first of all, if either has no life range, they cannot clash */
- if (a->life.empty() || b->life.empty())
+ if (a->m_life.empty() || b->m_life.empty())
return false;
- la = &a->life.front();
- lb = &b->life.front();
- enda = &a->life.back() + 1;
- endb = &b->life.back() + 1;
+ la = &a->m_life.front();
+ lb = &b->m_life.front();
+ enda = &a->m_life.back() + 1;
+ endb = &b->m_life.back() + 1;
while (true)
{
/* check if the entries overlap, for that,
static bool ir_check_unreachable(ir_block *self)
{
/* The IR should never have to deal with unreachable code */
- if (!self->final/* || OPTS_FLAG(ALLOW_UNREACHABLE_CODE)*/)
+ if (!self->m_final/* || OPTS_FLAG(ALLOW_UNREACHABLE_CODE)*/)
return true;
- irerror(self->context, "unreachable statement (%s)", self->label.c_str());
+ irerror(self->m_context, "unreachable statement (%s)", self->m_label.c_str());
return false;
}
if (!ir_check_unreachable(self))
return false;
- if (target->store == store_value &&
+ if (target->m_store == store_value &&
(op < INSTR_STOREP_F || op > INSTR_STOREP_FNC))
{
- irerror(self->context, "cannot store to an SSA value");
- irerror(self->context, "trying to store: %s <- %s", target->name.c_str(), what->name.c_str());
- irerror(self->context, "instruction: %s", util_instr_str[op]);
+ irerror(self->m_context, "cannot store to an SSA value");
+ irerror(self->m_context, "trying to store: %s <- %s", target->m_name.c_str(), what->m_name.c_str());
+ irerror(self->m_context, "instruction: %s", util_instr_str[op]);
return false;
}
delete in;
return false;
}
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
return true;
}
delete in;
return false;
}
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
return true;
}
{
int op = 0;
qc_type vtype;
- if (target->vtype == TYPE_VARIANT)
- vtype = what->vtype;
+ if (target->m_vtype == TYPE_VARIANT)
+ vtype = what->m_vtype;
else
- vtype = target->vtype;
+ vtype = target->m_vtype;
#if 0
- if (vtype == TYPE_FLOAT && what->vtype == TYPE_INTEGER)
+ if (vtype == TYPE_FLOAT && what->m_vtype == TYPE_INTEGER)
op = INSTR_CONV_ITOF;
- else if (vtype == TYPE_INTEGER && what->vtype == TYPE_FLOAT)
+ else if (vtype == TYPE_INTEGER && what->m_vtype == TYPE_FLOAT)
op = INSTR_CONV_FTOI;
#endif
op = type_store_instr[vtype];
if (OPTS_FLAG(ADJUST_VECTOR_FIELDS)) {
- if (op == INSTR_STORE_FLD && what->fieldtype == TYPE_VECTOR)
+ if (op == INSTR_STORE_FLD && what->m_fieldtype == TYPE_VECTOR)
op = INSTR_STORE_V;
}
int op = 0;
qc_type vtype;
- if (target->vtype != TYPE_POINTER)
+ if (target->m_vtype != TYPE_POINTER)
return false;
/* storing using pointer - target is a pointer, type must be
* inferred from source
*/
- vtype = what->vtype;
+ vtype = what->m_vtype;
op = type_storep_instr[vtype];
if (OPTS_FLAG(ADJUST_VECTOR_FIELDS)) {
- if (op == INSTR_STOREP_FLD && what->fieldtype == TYPE_VECTOR)
+ if (op == INSTR_STOREP_FLD && what->m_fieldtype == TYPE_VECTOR)
op = INSTR_STOREP_V;
}
if (!ir_check_unreachable(self))
return false;
- self->final = true;
+ self->m_final = true;
- self->is_return = true;
+ self->m_is_return = true;
in = new ir_instr(ctx, self, INSTR_RETURN);
if (!in)
return false;
return false;
}
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
return true;
}
ir_instr *in;
if (!ir_check_unreachable(self))
return false;
- self->final = true;
- /*in = new ir_instr(ctx, self, (v->vtype == TYPE_STRING ? INSTR_IF_S : INSTR_IF_F));*/
+ self->m_final = true;
+ /*in = new ir_instr(ctx, self, (v->m_vtype == TYPE_STRING ? INSTR_IF_S : INSTR_IF_F));*/
in = new ir_instr(ctx, self, VINSTR_COND);
if (!in)
return false;
return false;
}
- in->bops[0] = ontrue;
- in->bops[1] = onfalse;
+ in->m_bops[0] = ontrue;
+ in->m_bops[1] = onfalse;
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
- vec_push(self->exits, ontrue);
- vec_push(self->exits, onfalse);
- vec_push(ontrue->entries, self);
- vec_push(onfalse->entries, self);
+ vec_push(self->m_exits, ontrue);
+ vec_push(self->m_exits, onfalse);
+ vec_push(ontrue->m_entries, self);
+ vec_push(onfalse->m_entries, self);
return true;
}
ir_instr *in;
if (!ir_check_unreachable(self))
return false;
- self->final = true;
+ self->m_final = true;
in = new ir_instr(ctx, self, VINSTR_JUMP);
if (!in)
return false;
- in->bops[0] = to;
- vec_push(self->instr, in);
+ in->m_bops[0] = to;
+ vec_push(self->m_instr, in);
- vec_push(self->exits, to);
- vec_push(to->entries, self);
+ vec_push(self->m_exits, to);
+ vec_push(to->m_entries, self);
return true;
}
bool ir_block_create_goto(ir_block *self, lex_ctx_t ctx, ir_block *to)
{
- self->owner->flags |= IR_FLAG_HAS_GOTO;
+ self->m_owner->m_flags |= IR_FLAG_HAS_GOTO;
return ir_block_create_jump(self, ctx, to);
}
in = new ir_instr(ctx, self, VINSTR_PHI);
if (!in)
return nullptr;
- out = ir_value_out(self->owner, label, store_value, ot);
+ out = ir_value_out(self->m_owner, label, store_value, ot);
if (!out) {
delete in;
return nullptr;
delete in;
return nullptr;
}
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
return in;
}
ir_value* ir_phi_value(ir_instr *self)
{
- return self->_ops[0];
+ return self->_m_ops[0];
}
void ir_phi_add(ir_instr* self, ir_block *b, ir_value *v)
{
ir_phi_entry_t pe;
- if (!vec_ir_block_find(self->owner->entries, b, nullptr)) {
+ if (!vec_ir_block_find(self->m_owner->m_entries, b, nullptr)) {
// Must not be possible to cause this, otherwise the AST
// is doing something wrong.
- irerror(self->context, "Invalid entry block for PHI");
+ irerror(self->m_context, "Invalid entry block for PHI");
exit(EXIT_FAILURE);
}
pe.value = v;
pe.from = b;
- v->reads.push_back(self);
- self->phi.push_back(pe);
+ v->m_reads.push_back(self);
+ self->m_phi.push_back(pe);
}
/* call related code */
if (!in)
return nullptr;
if (noreturn) {
- self->final = true;
- self->is_return = true;
+ self->m_final = true;
+ self->m_is_return = true;
}
- out = ir_value_out(self->owner, label, (func->outtype == TYPE_VOID) ? store_return : store_value, func->outtype);
+ out = ir_value_out(self->m_owner, label, (func->m_outtype == TYPE_VOID) ? store_return : store_value, func->m_outtype);
if (!out) {
delete in;
return nullptr;
delete in;
return nullptr;
}
- vec_push(self->instr, in);
+ vec_push(self->m_instr, in);
/*
if (noreturn) {
if (!ir_block_create_return(self, ctx, nullptr)) {
ir_value* ir_call_value(ir_instr *self)
{
- return self->_ops[0];
+ return self->_m_ops[0];
}
void ir_call_param(ir_instr* self, ir_value *v)
{
- self->params.push_back(v);
- v->reads.push_back(self);
+ self->m_params.push_back(v);
+ v->m_reads.push_back(self);
}
/* binary op related code */
return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, nullptr, operand, TYPE_VECTOR);
default:
- ot = operand->vtype;
+ ot = operand->m_vtype;
break;
};
if (ot == TYPE_VOID) {
ir_instr *instr;
ir_value *out;
- out = ir_value_out(self->owner, label, store_value, outype);
+ out = ir_value_out(self->m_owner, label, store_value, outype);
if (!out)
return nullptr;
goto on_error;
}
- vec_push(self->instr, instr);
+ vec_push(self->m_instr, instr);
return out;
on_error:
ir_value *v;
/* Support for various pointer types todo if so desired */
- if (ent->vtype != TYPE_ENTITY)
+ if (ent->m_vtype != TYPE_ENTITY)
return nullptr;
- if (field->vtype != TYPE_FIELD)
+ if (field->m_vtype != TYPE_FIELD)
return nullptr;
v = ir_block_create_general_instr(self, ctx, label, INSTR_ADDRESS, ent, field, TYPE_POINTER);
- v->fieldtype = field->fieldtype;
+ v->m_fieldtype = field->m_fieldtype;
return v;
}
ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field, qc_type outype)
{
int op;
- if (ent->vtype != TYPE_ENTITY)
+ if (ent->m_vtype != TYPE_ENTITY)
return nullptr;
/* at some point we could redirect for TYPE_POINTER... but that could lead to carelessness */
- if (field->vtype != TYPE_FIELD)
+ if (field->m_vtype != TYPE_FIELD)
return nullptr;
switch (outype)
case TYPE_INTEGER: op = INSTR_LOAD_I; break;
#endif
default:
- irerror(self->context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
+ irerror(self->m_context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
return nullptr;
}
static bool ir_block_naive_phi(ir_block *self);
bool ir_function_naive_phi(ir_function *self)
{
- for (auto& b : self->blocks)
+ for (auto& b : self->m_blocks)
if (!ir_block_naive_phi(b.get()))
return false;
return true;
* to a list so we don't need to loop through blocks
* - anyway: "don't optimize YET"
*/
- for (i = 0; i < vec_size(self->instr); ++i)
+ for (i = 0; i < vec_size(self->m_instr); ++i)
{
- ir_instr *instr = self->instr[i];
- if (instr->opcode != VINSTR_PHI)
+ ir_instr *instr = self->m_instr[i];
+ if (instr->m_opcode != VINSTR_PHI)
continue;
- vec_remove(self->instr, i, 1);
+ vec_remove(self->m_instr, i, 1);
--i; /* NOTE: i+1 below */
- for (auto &it : instr->phi) {
+ for (auto &it : instr->m_phi) {
ir_value *v = it.value;
ir_block *b = it.from;
- if (v->store == store_value && v->reads.size() == 1 && v->writes.size() == 1) {
+ if (v->m_store == store_value && v->m_reads.size() == 1 && v->m_writes.size() == 1) {
/* replace the value */
- if (!ir_instr_op(v->writes[0], 0, instr->_ops[0], true))
+ if (!ir_instr_op(v->m_writes[0], 0, instr->_m_ops[0], true))
return false;
} else {
/* force a move instruction */
- ir_instr *prevjump = vec_last(b->instr);
- vec_pop(b->instr);
- b->final = false;
- instr->_ops[0]->store = store_global;
- if (!ir_block_create_store(b, instr->context, instr->_ops[0], v))
+ ir_instr *prevjump = vec_last(b->m_instr);
+ vec_pop(b->m_instr);
+ b->m_final = false;
+ instr->_m_ops[0]->m_store = store_global;
+ if (!ir_block_create_store(b, instr->m_context, instr->_m_ops[0], v))
return false;
- instr->_ops[0]->store = store_value;
- vec_push(b->instr, prevjump);
- b->final = true;
+ instr->_m_ops[0]->m_store = store_value;
+ vec_push(b->m_instr, prevjump);
+ b->m_final = true;
}
}
delete instr;
{
size_t i;
size_t eid = *_eid;
- for (i = 0; i < vec_size(self->instr); ++i)
+ for (i = 0; i < vec_size(self->m_instr); ++i)
{
- self->instr[i]->eid = eid++;
+ self->m_instr[i]->m_eid = eid++;
}
*_eid = eid;
}
{
size_t instruction_id = 0;
size_t block_eid = 0;
- for (auto& block : self->blocks)
+ for (auto& block : self->m_blocks)
{
/* each block now gets an additional "entry" instruction id
* we can use to avoid point-life issues
*/
- block->entry_id = instruction_id;
- block->eid = block_eid;
+ block->m_entry_id = instruction_id;
+ block->m_eid = block_eid;
++instruction_id;
++block_eid;
ir_value *slot;
size_t vsize = ir_value_sizeof(var);
- var->code.local = vec_size(alloc->locals);
+ var->m_code.local = vec_size(alloc->locals);
- slot = new ir_value("reg", store_global, var->vtype);
+ slot = new ir_value("reg", store_global, var->m_vtype);
if (!slot)
return false;
vec_push(alloc->locals, slot);
vec_push(alloc->sizes, vsize);
- vec_push(alloc->unique, var->unique_life);
+ vec_push(alloc->unique, var->m_unique_life);
return true;
size_t a;
ir_value *slot;
- if (v->unique_life)
+ if (v->m_unique_life)
return function_allocator_alloc(alloc, v);
for (a = 0; a < vec_size(alloc->locals); ++a)
/* never resize parameters
* will be required later when overlapping temps + locals
*/
- if (a < vec_size(self->params) &&
+ if (a < vec_size(self->m_params) &&
alloc->sizes[a] < ir_value_sizeof(v))
{
continue;
if (alloc->sizes[a] < ir_value_sizeof(v))
alloc->sizes[a] = ir_value_sizeof(v);
- v->code.local = a;
+ v->m_code.local = a;
return true;
}
if (a >= vec_size(alloc->locals)) {
function_allocator lockalloc, globalloc;
- if (self->locals.empty() && self->values.empty())
+ if (self->m_locals.empty() && self->m_values.empty())
return true;
globalloc.locals = nullptr;
lockalloc.unique = nullptr;
size_t i;
- for (i = 0; i < self->locals.size(); ++i)
+ for (i = 0; i < self->m_locals.size(); ++i)
{
- ir_value *v = self->locals[i].get();
- if ((self->flags & IR_FLAG_MASK_NO_LOCAL_TEMPS) || !OPTS_OPTIMIZATION(OPTIM_LOCAL_TEMPS)) {
- v->locked = true;
- v->unique_life = true;
+ ir_value *v = self->m_locals[i].get();
+ if ((self->m_flags & IR_FLAG_MASK_NO_LOCAL_TEMPS) || !OPTS_OPTIMIZATION(OPTIM_LOCAL_TEMPS)) {
+ v->m_locked = true;
+ v->m_unique_life = true;
}
- else if (i >= vec_size(self->params))
+ else if (i >= vec_size(self->m_params))
break;
else
- v->locked = true; /* lock parameters locals */
- if (!function_allocator_alloc((v->locked || !opt_gt ? &lockalloc : &globalloc), v))
+ v->m_locked = true; /* lock parameters locals */
+ if (!function_allocator_alloc((v->m_locked || !opt_gt ? &lockalloc : &globalloc), v))
goto error;
}
- for (; i < self->locals.size(); ++i)
+ for (; i < self->m_locals.size(); ++i)
{
- ir_value *v = self->locals[i].get();
- if (v->life.empty())
+ ir_value *v = self->m_locals[i].get();
+ if (v->m_life.empty())
continue;
- if (!ir_function_allocator_assign(self, (v->locked || !opt_gt ? &lockalloc : &globalloc), v))
+ if (!ir_function_allocator_assign(self, (v->m_locked || !opt_gt ? &lockalloc : &globalloc), v))
goto error;
}
/* Allocate a slot for any value that still exists */
- for (i = 0; i < self->values.size(); ++i)
+ for (i = 0; i < self->m_values.size(); ++i)
{
- ir_value *v = self->values[i].get();
+ ir_value *v = self->m_values[i].get();
- if (v->life.empty())
+ if (v->m_life.empty())
continue;
/* CALL optimization:
* If the value is a parameter-temp: 1 write, 1 read from a CALL
* and it's not "locked", write it to the OFS_PARM directly.
*/
- if (OPTS_OPTIMIZATION(OPTIM_CALL_STORES) && !v->locked && !v->unique_life) {
- if (v->reads.size() == 1 && v->writes.size() == 1 &&
- (v->reads[0]->opcode == VINSTR_NRCALL ||
- (v->reads[0]->opcode >= INSTR_CALL0 && v->reads[0]->opcode <= INSTR_CALL8)
+ if (OPTS_OPTIMIZATION(OPTIM_CALL_STORES) && !v->m_locked && !v->m_unique_life) {
+ if (v->m_reads.size() == 1 && v->m_writes.size() == 1 &&
+ (v->m_reads[0]->m_opcode == VINSTR_NRCALL ||
+ (v->m_reads[0]->m_opcode >= INSTR_CALL0 && v->m_reads[0]->m_opcode <= INSTR_CALL8)
)
)
{
size_t param;
- ir_instr *call = v->reads[0];
- if (!vec_ir_value_find(call->params, v, ¶m)) {
- irerror(call->context, "internal error: unlocked parameter %s not found", v->name.c_str());
+ ir_instr *call = v->m_reads[0];
+ if (!vec_ir_value_find(call->m_params, v, ¶m)) {
+ irerror(call->m_context, "internal error: unlocked parameter %s not found", v->m_name.c_str());
goto error;
}
++opts_optimizationcount[OPTIM_CALL_STORES];
- v->callparam = true;
+ v->m_callparam = true;
if (param < 8)
ir_value_code_setaddr(v, OFS_PARM0 + 3*param);
else {
- size_t nprotos = self->owner->extparam_protos.size();
+ size_t nprotos = self->m_owner->m_extparam_protos.size();
ir_value *ep;
param -= 8;
if (nprotos > param)
- ep = self->owner->extparam_protos[param].get();
+ ep = self->m_owner->m_extparam_protos[param].get();
else
{
- ep = ir_gen_extparam_proto(self->owner);
+ ep = ir_gen_extparam_proto(self->m_owner);
while (++nprotos <= param)
- ep = ir_gen_extparam_proto(self->owner);
+ ep = ir_gen_extparam_proto(self->m_owner);
}
- ir_instr_op(v->writes[0], 0, ep, true);
- call->params[param+8] = ep;
+ ir_instr_op(v->m_writes[0], 0, ep, true);
+ call->m_params[param+8] = ep;
}
continue;
}
- if (v->writes.size() == 1 && v->writes[0]->opcode == INSTR_CALL0) {
- v->store = store_return;
- if (v->members[0]) v->members[0]->store = store_return;
- if (v->members[1]) v->members[1]->store = store_return;
- if (v->members[2]) v->members[2]->store = store_return;
+ if (v->m_writes.size() == 1 && v->m_writes[0]->m_opcode == INSTR_CALL0) {
+ v->m_store = store_return;
+ if (v->m_members[0]) v->m_members[0]->m_store = store_return;
+ if (v->m_members[1]) v->m_members[1]->m_store = store_return;
+ if (v->m_members[2]) v->m_members[2]->m_store = store_return;
++opts_optimizationcount[OPTIM_CALL_STORES];
continue;
}
}
- if (!ir_function_allocator_assign(self, (v->locked || !opt_gt ? &lockalloc : &globalloc), v))
+ if (!ir_function_allocator_assign(self, (v->m_locked || !opt_gt ? &lockalloc : &globalloc), v))
goto error;
}
pos = lockalloc.positions[i-1] + lockalloc.sizes[i-1];
vec_push(lockalloc.positions, pos);
}
- self->allocated_locals = pos + vec_last(lockalloc.sizes);
+ self->m_allocated_locals = pos + vec_last(lockalloc.sizes);
}
if (globalloc.sizes) {
pos = (vec_size(globalloc.sizes) ? globalloc.positions[0] : 0);
pos = globalloc.positions[i-1] + globalloc.sizes[i-1];
vec_push(globalloc.positions, pos);
}
- self->globaltemps = pos + vec_last(globalloc.sizes);
+ self->m_globaltemps = pos + vec_last(globalloc.sizes);
}
/* Locals need to know their new position */
- for (auto& local : self->locals) {
- if (local->locked || !opt_gt)
- local->code.local = lockalloc.positions[local->code.local];
+ for (auto& local : self->m_locals) {
+ if (local->m_locked || !opt_gt)
+ local->m_code.local = lockalloc.positions[local->m_code.local];
else
- local->code.local = globalloc.positions[local->code.local];
+ local->m_code.local = globalloc.positions[local->m_code.local];
}
/* Take over the actual slot positions on values */
- for (auto& value : self->values) {
- if (value->locked || !opt_gt)
- value->code.local = lockalloc.positions[value->code.local];
+ for (auto& value : self->m_values) {
+ if (value->m_locked || !opt_gt)
+ value->m_code.local = lockalloc.positions[value->m_code.local];
else
- value->code.local = globalloc.positions[value->code.local];
+ value->m_code.local = globalloc.positions[value->m_code.local];
}
goto cleanup;
static bool ir_block_living_add_instr(ir_block *self, size_t eid) {
bool changed = false;
- for (auto &it : self->living)
+ for (auto &it : self->m_living)
if (ir_value_life_merge(it, eid))
changed = true;
return changed;
static bool ir_block_living_lock(ir_block *self) {
bool changed = false;
- for (auto &it : self->living) {
- if (it->locked)
+ for (auto &it : self->m_living) {
+ if (it->m_locked)
continue;
- it->locked = true;
+ it->m_locked = true;
changed = true;
}
return changed;
// bitmasks which operands are read from or written to
size_t read, write;
- self->living.clear();
+ self->m_living.clear();
- p = vec_size(self->exits);
+ p = vec_size(self->m_exits);
for (i = 0; i < p; ++i) {
- ir_block *prev = self->exits[i];
- for (auto &it : prev->living)
- if (!vec_ir_value_find(self->living, it, nullptr))
- self->living.push_back(it);
+ ir_block *prev = self->m_exits[i];
+ for (auto &it : prev->m_living)
+ if (!vec_ir_value_find(self->m_living, it, nullptr))
+ self->m_living.push_back(it);
}
- i = vec_size(self->instr);
+ i = vec_size(self->m_instr);
while (i)
{ --i;
- instr = self->instr[i];
+ instr = self->m_instr[i];
/* See which operands are read and write operands */
- ir_op_read_write(instr->opcode, &read, &write);
+ ir_op_read_write(instr->m_opcode, &read, &write);
/* Go through the 3 main operands
* writes first, then reads
*/
for (o = 0; o < 3; ++o)
{
- if (!instr->_ops[o]) /* no such operand */
+ if (!instr->_m_ops[o]) /* no such operand */
continue;
- value = instr->_ops[o];
+ value = instr->_m_ops[o];
/* We only care about locals */
/* we also calculate parameter liferanges so that locals
* can take up parameter slots */
- if (value->store != store_value &&
- value->store != store_local &&
- value->store != store_param)
+ if (value->m_store != store_value &&
+ value->m_store != store_local &&
+ value->m_store != store_param)
continue;
/* write operands */
if (write & (1<<o))
{
size_t idx;
- bool in_living = vec_ir_value_find(self->living, value, &idx);
+ bool in_living = vec_ir_value_find(self->m_living, value, &idx);
if (!in_living)
{
/* If the value isn't alive it hasn't been read before... */
* and make sure it's only printed once
* since this function is run multiple times.
*/
- /* con_err( "Value only written %s\n", value->name); */
- if (ir_value_life_merge(value, instr->eid))
+ /* con_err( "Value only written %s\n", value->m_name); */
+ if (ir_value_life_merge(value, instr->m_eid))
*changed = true;
} else {
/* since 'living' won't contain it
* anymore, merge the value, since
* (A) doesn't.
*/
- if (ir_value_life_merge(value, instr->eid))
+ if (ir_value_life_merge(value, instr->m_eid))
*changed = true;
// Then remove
- self->living.erase(self->living.begin() + idx);
+ self->m_living.erase(self->m_living.begin() + idx);
}
/* Removing a vector removes all members */
for (mem = 0; mem < 3; ++mem) {
- if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], &idx)) {
- if (ir_value_life_merge(value->members[mem], instr->eid))
+ if (value->m_members[mem] && vec_ir_value_find(self->m_living, value->m_members[mem], &idx)) {
+ if (ir_value_life_merge(value->m_members[mem], instr->m_eid))
*changed = true;
- self->living.erase(self->living.begin() + idx);
+ self->m_living.erase(self->m_living.begin() + idx);
}
}
/* Removing the last member removes the vector */
- if (value->memberof) {
- value = value->memberof;
+ if (value->m_memberof) {
+ value = value->m_memberof;
for (mem = 0; mem < 3; ++mem) {
- if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], nullptr))
+ if (value->m_members[mem] && vec_ir_value_find(self->m_living, value->m_members[mem], nullptr))
break;
}
- if (mem == 3 && vec_ir_value_find(self->living, value, &idx)) {
- if (ir_value_life_merge(value, instr->eid))
+ if (mem == 3 && vec_ir_value_find(self->m_living, value, &idx)) {
+ if (ir_value_life_merge(value, instr->m_eid))
*changed = true;
- self->living.erase(self->living.begin() + idx);
+ self->m_living.erase(self->m_living.begin() + idx);
}
}
}
/* These operations need a special case as they can break when using
* same source and destination operand otherwise, as the engine may
* read the source multiple times. */
- if (instr->opcode == INSTR_MUL_VF ||
- instr->opcode == VINSTR_BITAND_VF ||
- instr->opcode == VINSTR_BITOR_VF ||
- instr->opcode == VINSTR_BITXOR ||
- instr->opcode == VINSTR_BITXOR_VF ||
- instr->opcode == VINSTR_BITXOR_V ||
- instr->opcode == VINSTR_CROSS)
+ if (instr->m_opcode == INSTR_MUL_VF ||
+ instr->m_opcode == VINSTR_BITAND_VF ||
+ instr->m_opcode == VINSTR_BITOR_VF ||
+ instr->m_opcode == VINSTR_BITXOR ||
+ instr->m_opcode == VINSTR_BITXOR_VF ||
+ instr->m_opcode == VINSTR_BITXOR_V ||
+ instr->m_opcode == VINSTR_CROSS)
{
- value = instr->_ops[2];
+ value = instr->_m_ops[2];
/* the float source will get an additional lifetime */
- if (ir_value_life_merge(value, instr->eid+1))
+ if (ir_value_life_merge(value, instr->m_eid+1))
*changed = true;
- if (value->memberof && ir_value_life_merge(value->memberof, instr->eid+1))
+ if (value->m_memberof && ir_value_life_merge(value->m_memberof, instr->m_eid+1))
*changed = true;
}
- if (instr->opcode == INSTR_MUL_FV ||
- instr->opcode == INSTR_LOAD_V ||
- instr->opcode == VINSTR_BITXOR ||
- instr->opcode == VINSTR_BITXOR_VF ||
- instr->opcode == VINSTR_BITXOR_V ||
- instr->opcode == VINSTR_CROSS)
+ if (instr->m_opcode == INSTR_MUL_FV ||
+ instr->m_opcode == INSTR_LOAD_V ||
+ instr->m_opcode == VINSTR_BITXOR ||
+ instr->m_opcode == VINSTR_BITXOR_VF ||
+ instr->m_opcode == VINSTR_BITXOR_V ||
+ instr->m_opcode == VINSTR_CROSS)
&nb