(void)func;
(void)lvalue;
if (m_vtype == TYPE_NIL) {
- *out = func->m_ir_func->m_owner->m_nil;
+ *out = func->m_ir_func->m_owner.m_nil;
return true;
}
// NOTE: This is the codegen for a variable used in an expression.
return true;
}
-bool ast_value::generateGlobal(ir_builder *ir, bool isfield)
+bool ast_value::generateGlobal(ir_builder &ir, bool isfield)
{
if (m_vtype == TYPE_NIL) {
compile_error(m_context, "internal error: trying to generate a variable of TYPE_NIL");
} else {
// Arrays don't do this since there's no "array" value which spans across the
// whole thing.
- v = ir->createGlobal(m_name, m_vtype);
+ v = ir.createGlobal(m_name, m_vtype);
if (!v) {
compile_error(m_context, "ir_builder::createGlobal failed on `%s`", m_name);
return false;
m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
if (m_flags & AST_FLAG_ERASEABLE)
m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_v->m_flags |= IR_FLAG_NOREF;
/* initialize */
if (m_hasvalue) {
return true;
}
-bool ast_value::generateGlobalFunction(ir_builder *ir)
+bool ast_value::generateGlobalFunction(ir_builder &ir)
{
- ir_function *func = ir->createFunction(m_name, m_next->m_vtype);
+ ir_function *func = ir.createFunction(m_name, m_next->m_vtype);
if (!func)
return false;
func->m_context = m_context;
return true;
}
-bool ast_value::generateGlobalField(ir_builder *ir)
+bool ast_value::generateGlobalField(ir_builder &ir)
{
ast_expression *fieldtype = m_next;
ast_expression *elemtype = array->m_next;
qc_type vtype = elemtype->m_vtype;
- ir_value *v = ir->createField(m_name, vtype);
+ ir_value *v = ir.createField(m_name, vtype);
if (!v) {
compile_error(m_context, "ir_builder::createGlobal failed on `%s`", m_name);
return false;
m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
if (m_flags & AST_FLAG_ERASEABLE)
m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_v->m_flags |= IR_FLAG_NOREF;
const size_t namelen = m_name.length();
std::unique_ptr<char[]> name(new char[namelen+16]);
array->m_ir_values[0] = v;
for (size_t ai = 1; ai < array->m_count; ++ai) {
util_snprintf(name.get() + namelen, 16, "[%u]", (unsigned int)ai);
- array->m_ir_values[ai] = ir->createField(name.get(), vtype);
+ array->m_ir_values[ai] = ir.createField(name.get(), vtype);
if (!array->m_ir_values[ai]) {
compile_error(m_context, "ir_builder::createGlobal failed on `%s`", name.get());
return false;
array->m_ir_values[ai]->m_unique_life = true;
array->m_ir_values[ai]->m_locked = true;
if (m_flags & AST_FLAG_INCLUDE_DEF)
- m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+ array->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (m_flags & AST_FLAG_NOREF)
+ array->m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
}
}
else
{
- ir_value *v = ir->createField(m_name, m_next->m_vtype);
+ ir_value *v = ir.createField(m_name, m_next->m_vtype);
if (!v)
return false;
v->m_context = m_context;
m_ir_v = v;
if (m_flags & AST_FLAG_INCLUDE_DEF)
m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
-
if (m_flags & AST_FLAG_ERASEABLE)
m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_v->m_flags |= IR_FLAG_NOREF;
}
return true;
}
-ir_value *ast_value::prepareGlobalArray(ir_builder *ir)
+ir_value *ast_value::prepareGlobalArray(ir_builder &ir)
{
ast_expression *elemtype = m_next;
qc_type vtype = elemtype->m_vtype;
if (!checkArray(*this))
return nullptr;
- ir_value *v = ir->createGlobal(m_name, vtype);
+ ir_value *v = ir.createGlobal(m_name, vtype);
if (!v) {
compile_error(m_context, "ir_builder::createGlobal failed `%s`", m_name);
return nullptr;
if (m_flags & AST_FLAG_INCLUDE_DEF)
v->m_flags |= IR_FLAG_INCLUDE_DEF;
if (m_flags & AST_FLAG_ERASEABLE)
- m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+ v->m_flags |= IR_FLAG_ERASABLE;
+ if (m_flags & AST_FLAG_NOREF)
+ v->m_flags |= IR_FLAG_NOREF;
const size_t namelen = m_name.length();
std::unique_ptr<char[]> name(new char[namelen+16]);
m_ir_values[0] = v;
for (size_t ai = 1; ai < m_count; ++ai) {
util_snprintf(name.get() + namelen, 16, "[%u]", (unsigned int)ai);
- m_ir_values[ai] = ir->createGlobal(name.get(), vtype);
+ m_ir_values[ai] = ir.createGlobal(name.get(), vtype);
if (!m_ir_values[ai]) {
compile_error(m_context, "ir_builder::createGlobal failed `%s`", name.get());
return nullptr;
m_ir_values[ai]->m_locked = true;
if (m_flags & AST_FLAG_INCLUDE_DEF)
m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
}
return v;
v->m_unique_life = true;
v->m_locked = true;
+ if (m_flags & AST_FLAG_NOREF)
+ v->m_flags |= IR_FLAG_NOREF;
+
const size_t namelen = m_name.length();
std::unique_ptr<char[]> name(new char[namelen+16]);
util_strncpy(name.get(), m_name.c_str(), namelen);
}
m_ir_values[ai]->m_context = m_context;
m_ir_values[ai]->m_unique_life = true;
- m_ir_values[ai]->m_locked = true;
+ m_ir_values[ai]->m_locked = true;
+
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
}
}
else
v->m_cvq = m_cvq;
m_ir_v = v;
+ if (m_flags & AST_FLAG_NOREF)
+ m_ir_v->m_flags |= IR_FLAG_NOREF;
+
if (!generateAccessors(func->m_owner))
return false;
return true;
return false;
}
-bool ast_value::generateAccessors(ir_builder *ir)
+bool ast_value::generateAccessors(ir_builder &ir)
{
size_t i;
bool warn = OPTS_WARN(WARN_USED_UNINITIALIZED);
return true;
}
-bool ast_function::generateFunction(ir_builder *ir)
+bool ast_function::generateFunction(ir_builder &ir)
{
(void)ir;
/* fill the parameter list */
for (auto &it : m_function_type->m_type_params) {
if (it->m_vtype == TYPE_FIELD)
- vec_push(irf->m_params, it->m_next->m_vtype);
+ irf->m_params.push_back(it->m_next->m_vtype);
else
- vec_push(irf->m_params, it->m_vtype);
+ irf->m_params.push_back(it->m_vtype);
if (!m_builtin) {
if (!it->generateLocal(m_ir_func, true))
return false;
return false;
sub = ir_block_create_binop(m_curblock, m_context,
makeLabel("va_count"), INSTR_SUB_F,
- ir->get_va_count(), fixed);
+ ir.get_va_count(), fixed);
if (!sub)
return false;
if (!ir_block_create_store_op(m_curblock, m_context, INSTR_STORE_F,
{
return ir_block_create_return(m_curblock, m_context, nullptr);
}
- else if (vec_size(m_curblock->m_entries) || m_curblock == irf->m_first)
+ else if (m_curblock->m_entries.size() || m_curblock == irf->m_first)
{
if (m_return_value) {
if (!m_return_value->codegen(this, false, &dummy))
return false;
}
/* use the likely flag */
- vec_last(func->m_curblock->m_instr)->m_likely = true;
+ func->m_curblock->m_instr.back()->m_likely = true;
/* enter the right-expression's block */
func->m_curblock = other;
/* varargs counter */
if (m_va_count) {
ir_value *va_count;
- ir_builder *builder = func->m_curblock->m_owner->m_owner;
+ ir_builder &builder = func->m_curblock->m_owner->m_owner;
if (!m_va_count->codegen(func, false, &va_count))
return false;
if (!ir_block_create_store_op(func->m_curblock, m_context, INSTR_STORE_F,
- builder->get_va_count(), va_count))
+ builder.get_va_count(), va_count))
{
return false;
}