X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ast.cpp;h=848541f3dd0da4d64860134f8e05d1da4dcec76b;hb=refs%2Fheads%2FTimePath%2Fparser;hp=7529acdd4ce0ac373fad7420f5c93c4d967602e6;hpb=0b94d7583cd56c5c57b35b0891d5fdf6249aaf37;p=xonotic%2Fgmqcc.git diff --git a/ast.cpp b/ast.cpp index 7529acd..848541f 100644 --- a/ast.cpp +++ b/ast.cpp @@ -1004,7 +1004,7 @@ bool ast_value::codegen(ast_function *func, bool lvalue, ir_value **out) (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. @@ -1094,7 +1094,7 @@ bool ast_value::checkArray(const ast_value &array) const 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"); @@ -1115,7 +1115,7 @@ bool ast_value::generateGlobal(ir_builder *ir, bool isfield) } 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; @@ -1132,6 +1132,8 @@ bool ast_value::generateGlobal(ir_builder *ir, bool isfield) 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) { @@ -1180,9 +1182,9 @@ bool ast_value::generateGlobal(ir_builder *ir, bool isfield) 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; @@ -1200,7 +1202,7 @@ bool ast_value::generateGlobalFunction(ir_builder *ir) return true; } -bool ast_value::generateGlobalField(ir_builder *ir) +bool ast_value::generateGlobalField(ir_builder &ir) { ast_expression *fieldtype = m_next; @@ -1222,7 +1224,7 @@ bool ast_value::generateGlobalField(ir_builder *ir) 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; @@ -1236,6 +1238,8 @@ bool ast_value::generateGlobalField(ir_builder *ir) 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 name(new char[namelen+16]); @@ -1245,7 +1249,7 @@ bool ast_value::generateGlobalField(ir_builder *ir) 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; @@ -1254,26 +1258,29 @@ bool ast_value::generateGlobalField(ir_builder *ir) 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; @@ -1287,7 +1294,7 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir) 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; @@ -1299,7 +1306,9 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir) 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 name(new char[namelen+16]); @@ -1309,7 +1318,7 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir) 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; @@ -1319,6 +1328,8 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir) 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; @@ -1365,6 +1376,9 @@ bool ast_value::generateLocal(ir_function *func, bool param) 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 name(new char[namelen+16]); util_strncpy(name.get(), m_name.c_str(), namelen); @@ -1379,7 +1393,10 @@ bool ast_value::generateLocal(ir_function *func, bool param) } 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 @@ -1418,6 +1435,9 @@ bool ast_value::generateLocal(ir_function *func, bool param) 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; @@ -1427,7 +1447,7 @@ error: /* clean up */ 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); @@ -1475,7 +1495,7 @@ bool ast_value::generateAccessors(ir_builder *ir) return true; } -bool ast_function::generateFunction(ir_builder *ir) +bool ast_function::generateFunction(ir_builder &ir) { (void)ir; @@ -1490,9 +1510,9 @@ bool ast_function::generateFunction(ir_builder *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; @@ -1539,7 +1559,7 @@ bool ast_function::generateFunction(ir_builder *ir) 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, @@ -1562,7 +1582,7 @@ bool ast_function::generateFunction(ir_builder *ir) { 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)) @@ -1784,7 +1804,7 @@ bool ast_binary::codegen(ast_function *func, bool lvalue, ir_value **out) 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; @@ -3055,11 +3075,11 @@ bool ast_call::codegen(ast_function *func, bool lvalue, ir_value **out) /* 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; }