X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.cpp;h=7529acdd4ce0ac373fad7420f5c93c4d967602e6;hp=cf8ffc70f445bb029b6bfa76396c8be4147e679a;hb=0b94d7583cd56c5c57b35b0891d5fdf6249aaf37;hpb=4c48bae203c332ad51367ddc3d89681ef5eb0169 diff --git a/ast.cpp b/ast.cpp index cf8ffc7..7529acd 100644 --- a/ast.cpp +++ b/ast.cpp @@ -2098,13 +2098,45 @@ bool ast_member::codegen(ast_function *func, bool lvalue, ir_value **out) compile_error(m_context, "not an l-value (member access)"); return false; } - if (m_outl) { + if (lvalue && m_outl) { *out = m_outl; return true; } + if (!lvalue && m_outr) { + *out = m_outr; + return true; + } - if (!m_owner->codegen(func, false, &vec)) - return false; + if (ast_istype(m_owner, ast_entfield)) { + ir_value *ent, *field; + auto entfield = reinterpret_cast(m_owner); + if (!entfield->m_entity->codegen(func, false, &ent)) + return false; + if (!entfield->m_field->codegen(func, false, &vec)) + return false; + field = vec->vectorMember(m_field); + if (lvalue) { + *out = ir_block_create_fieldaddress(func->m_curblock, m_context, func->makeLabel("mefa"), + ent, field); + } else { + *out = ir_block_create_load_from_ent(func->m_curblock, m_context, func->makeLabel("mefv"), + ent, field, m_vtype); + } + if (!*out) { + compile_error(m_context, "failed to create %s instruction (output type %s)", + (lvalue ? "ADDRESS" : "FIELD"), + type_name[m_vtype]); + return false; + } + if (lvalue) + m_outl = *out; + else + m_outr = *out; + return (*out != nullptr); + } else { + if (!m_owner->codegen(func, false, &vec)) + return false; + } if (vec->m_vtype != TYPE_VECTOR && !(vec->m_vtype == TYPE_FIELD && m_owner->m_next->m_vtype == TYPE_VECTOR))