]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
c++: ir_block::m_entries
authorWolfgang Bumiller <wry.git@bumiller.com>
Sat, 3 Dec 2016 19:32:26 +0000 (20:32 +0100)
committerWolfgang Bumiller <wry.git@bumiller.com>
Sat, 3 Dec 2016 19:32:26 +0000 (20:32 +0100)
ast.cpp
ir.cpp
ir.h

diff --git a/ast.cpp b/ast.cpp
index b507a6b45bfa56b932ca7699f2cb0689697e2f4d..1b6d40131aa66738af83cf21e1d5b47d89092758 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1582,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))
diff --git a/ir.cpp b/ir.cpp
index 6f06bdf95e23312cb1a52cddacd99ecf8e2bc161..5f2ef7e3801037ee504702ee9aca50cd5b935ea5 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -235,15 +235,14 @@ static bool GMQCC_WARN vec_ir_value_find(std::vector<ir_value *> &vec, const ir_
     return false;
 }
 
-static bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t *idx)
+static bool GMQCC_WARN vec_ir_block_find(std::vector<ir_block *> &vec, ir_block *what, size_t *idx)
 {
-    size_t i;
-    size_t len = vec_size(vec);
-    for (i = 0; i < len; ++i) {
-        if (vec[i] == what) {
-            if (idx) *idx = i;
-            return true;
-        }
+    for (auto &it : vec) {
+        if (it != what)
+            continue;
+        if (idx)
+            *idx = &it - &vec[0];
+        return true;
     }
     return false;
 }
@@ -746,7 +745,6 @@ ir_block::~ir_block()
     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);
 }
 
@@ -1383,8 +1381,8 @@ bool ir_block_create_if(ir_block *self, lex_ctx_t ctx, ir_value *v,
 
     vec_push(self->m_exits, ontrue);
     vec_push(self->m_exits, onfalse);
-    vec_push(ontrue->m_entries,  self);
-    vec_push(onfalse->m_entries, self);
+    ontrue->m_entries.push_back(self);
+    onfalse->m_entries.push_back(self);
     return true;
 }
 
@@ -1402,7 +1400,7 @@ bool ir_block_create_jump(ir_block *self, lex_ctx_t ctx, ir_block *to)
     vec_push(self->m_instr, in);
 
     vec_push(self->m_exits, to);
-    vec_push(to->m_entries, self);
+    to->m_entries.push_back(self);
     return true;
 }
 
diff --git a/ir.h b/ir.h
index fe07198ab5cc0c8798606d718b90b415647f242a..3b063b604cb2a7d0b890192438f03f9a9a41e1c3 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -149,7 +149,7 @@ struct ir_block {
     bool m_final = false; /* once a jump is added we're done */
 
     ir_instr **m_instr = nullptr;
-    ir_block **m_entries = nullptr;
+    std::vector<ir_block *> m_entries;
     ir_block **m_exits = nullptr;
     std::vector<ir_value *> m_living;