]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.cpp
Forgot about this file
[xonotic/gmqcc.git] / ir.cpp
diff --git a/ir.cpp b/ir.cpp
index 5920361c7314bb36394bb16a09058adcb665754e..92cd11d41f318fd0ead169de7e6edc00cc9f5649 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -239,15 +239,14 @@ static bool GMQCC_WARN irwarning(lex_ctx_t ctx, int warntype, const char *fmt, .
  * Vector utility functions
  */
 
  * Vector utility functions
  */
 
-static bool GMQCC_WARN vec_ir_value_find(ir_value **vec, const ir_value *what, size_t *idx)
+static bool GMQCC_WARN vec_ir_value_find(std::vector<ir_value *> &vec, const ir_value *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;
 }
     }
     return false;
 }
@@ -265,15 +264,14 @@ static bool GMQCC_WARN vec_ir_block_find(ir_block **vec, ir_block *what, size_t
     return false;
 }
 
     return false;
 }
 
-static bool GMQCC_WARN vec_ir_instr_find(ir_instr **vec, ir_instr *what, size_t *idx)
+static bool GMQCC_WARN vec_ir_instr_find(std::vector<ir_instr *> &vec, ir_instr *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;
 }
     }
     return false;
 }
@@ -293,19 +291,19 @@ ir_builder* ir_builder_new(const char *modulename)
 
     self = (ir_builder*)mem_a(sizeof(*self));
     if (!self)
 
     self = (ir_builder*)mem_a(sizeof(*self));
     if (!self)
-        return NULL;
+        return nullptr;
 
 
-    self->functions   = NULL;
-    self->globals     = NULL;
-    self->fields      = NULL;
-    self->filenames   = NULL;
-    self->filestrings = NULL;
+    self->functions   = nullptr;
+    self->globals     = nullptr;
+    self->fields      = nullptr;
+    self->filenames   = nullptr;
+    self->filestrings = nullptr;
     self->htglobals   = util_htnew(IR_HT_SIZE);
     self->htfields    = util_htnew(IR_HT_SIZE);
     self->htfunctions = util_htnew(IR_HT_SIZE);
 
     self->htglobals   = util_htnew(IR_HT_SIZE);
     self->htfields    = util_htnew(IR_HT_SIZE);
     self->htfunctions = util_htnew(IR_HT_SIZE);
 
-    self->extparams       = NULL;
-    self->extparam_protos = NULL;
+    self->extparams       = nullptr;
+    self->extparam_protos = nullptr;
 
     self->first_common_globaltemp = 0;
     self->max_globaltemps         = 0;
 
     self->first_common_globaltemp = 0;
     self->max_globaltemps         = 0;
@@ -313,10 +311,10 @@ ir_builder* ir_builder_new(const char *modulename)
     self->max_locals              = 0;
 
     self->str_immediate = 0;
     self->max_locals              = 0;
 
     self->str_immediate = 0;
-    self->name = NULL;
+    self->name = nullptr;
     if (!ir_builder_set_name(self, modulename)) {
         mem_d(self);
     if (!ir_builder_set_name(self, modulename)) {
         mem_d(self);
-        return NULL;
+        return nullptr;
     }
 
     self->nil = ir_value_var("nil", store_value, TYPE_NIL);
     }
 
     self->nil = ir_value_var("nil", store_value, TYPE_NIL);
@@ -331,8 +329,8 @@ ir_builder* ir_builder_new(const char *modulename)
         self->vinstr_temp[i]->cvq = CV_CONST;
     }
 
         self->vinstr_temp[i]->cvq = CV_CONST;
     }
 
-    self->reserved_va_count = NULL;
-    self->coverage_func     = NULL;
+    self->reserved_va_count = nullptr;
+    self->coverage_func     = nullptr;
 
     self->code              = code_init();
 
 
     self->code              = code_init();
 
@@ -391,14 +389,14 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int
 {
     ir_function *fn = ir_builder_get_function(self, name);
     if (fn) {
 {
     ir_function *fn = ir_builder_get_function(self, name);
     if (fn) {
-        return NULL;
+        return nullptr;
     }
 
     fn = ir_function_new(self, outtype);
     if (!ir_function_set_name(fn, name))
     {
         ir_function_delete(fn);
     }
 
     fn = ir_function_new(self, outtype);
     if (!ir_function_set_name(fn, name))
     {
         ir_function_delete(fn);
-        return NULL;
+        return nullptr;
     }
     vec_push(self->functions, fn);
     util_htset(self->htfunctions, name, fn);
     }
     vec_push(self->functions, fn);
     util_htset(self->htfunctions, name, fn);
@@ -406,7 +404,7 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int
     fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION);
     if (!fn->value) {
         ir_function_delete(fn);
     fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION);
     if (!fn->value) {
         ir_function_delete(fn);
-        return NULL;
+        return nullptr;
     }
 
     fn->value->hasvalue = true;
     }
 
     fn->value->hasvalue = true;
@@ -430,7 +428,7 @@ ir_value* ir_builder_create_global(ir_builder *self, const char *name, int vtype
     {
         ve = ir_builder_get_global(self, name);
         if (ve) {
     {
         ve = ir_builder_get_global(self, name);
         if (ve) {
-            return NULL;
+            return nullptr;
         }
     }
 
         }
     }
 
@@ -457,7 +455,7 @@ ir_value* ir_builder_create_field(ir_builder *self, const char *name, int vtype)
 {
     ir_value *ve = ir_builder_get_field(self, name);
     if (ve) {
 {
     ir_value *ve = ir_builder_get_field(self, name);
     if (ve) {
-        return NULL;
+        return nullptr;
     }
 
     ve = ir_value_var(name, store_global, TYPE_FIELD);
     }
 
     ve = ir_value_var(name, store_global, TYPE_FIELD);
@@ -482,14 +480,14 @@ ir_function* ir_function_new(ir_builder* owner, int outtype)
     self = (ir_function*)mem_a(sizeof(*self));
 
     if (!self)
     self = (ir_function*)mem_a(sizeof(*self));
 
     if (!self)
-        return NULL;
+        return nullptr;
 
     memset(self, 0, sizeof(*self));
 
 
     memset(self, 0, sizeof(*self));
 
-    self->name = NULL;
+    self->name = nullptr;
     if (!ir_function_set_name(self, "<@unnamed>")) {
         mem_d(self);
     if (!ir_function_set_name(self, "<@unnamed>")) {
         mem_d(self);
-        return NULL;
+        return nullptr;
     }
     self->flags = 0;
 
     }
     self->flags = 0;
 
@@ -497,13 +495,13 @@ ir_function* ir_function_new(ir_builder* owner, int outtype)
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->outtype = outtype;
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->outtype = outtype;
-    self->value = NULL;
+    self->value = nullptr;
     self->builtin = 0;
 
     self->builtin = 0;
 
-    self->params = NULL;
-    self->blocks = NULL;
-    self->values = NULL;
-    self->locals = NULL;
+    self->params = nullptr;
+    self->blocks = nullptr;
+    self->values = nullptr;
+    self->locals = nullptr;
 
     self->max_varargs = 0;
 
 
     self->max_varargs = 0;
 
@@ -583,7 +581,7 @@ ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function *self, const char
     vec_push(self->blocks, bn);
 
     if ((self->flags & IR_FLAG_BLOCK_COVERAGE) && self->owner->coverage_func)
     vec_push(self->blocks, bn);
 
     if ((self->flags & IR_FLAG_BLOCK_COVERAGE) && self->owner->coverage_func)
-        (void)ir_block_create_call(bn, ctx, NULL, self->owner->coverage_func, false);
+        (void)ir_block_create_call(bn, ctx, nullptr, self->owner->coverage_func, false);
 
     return bn;
 }
 
     return bn;
 }
@@ -640,7 +638,7 @@ static bool ir_function_pass_peephole(ir_function *self)
                     continue;
 
                 /* don't optimize out the temp if it's used later again */
                     continue;
 
                 /* don't optimize out the temp if it's used later again */
-                if (vec_size(value->reads) != 1)
+                if (value->reads.size() != 1)
                     continue;
 
                 /* The very next store must use this value */
                     continue;
 
                 /* The very next store must use this value */
@@ -670,12 +668,8 @@ static bool ir_function_pass_peephole(ir_function *self)
                     ir_value *value;
                     value = inst->_ops[0];
 
                     ir_value *value;
                     value = inst->_ops[0];
 
-                    if (value->store != store_value ||
-                        vec_size(value->reads) != 1 ||
-                        value->reads[0] != inst)
-                    {
+                    if (value->store != store_value || value->reads.size() != 1 || value->reads[0] != inst)
                         break;
                         break;
-                    }
 
                     inot = value->writes[0];
                     if (inot->_ops[0] != value ||
 
                     inot = value->writes[0];
                     if (inot->_ops[0] != value ||
@@ -722,7 +716,7 @@ static bool ir_function_pass_tailrecursion(ir_function *self)
 
     for (b = 0; b < vec_size(self->blocks); ++b) {
         ir_value *funcval;
 
     for (b = 0; b < vec_size(self->blocks); ++b) {
         ir_value *funcval;
-        ir_instr *ret, *call, *store = NULL;
+        ir_instr *ret, *call, *store = nullptr;
         ir_block *block = self->blocks[b];
 
         if (!block->final || vec_size(block->instr) < 2)
         ir_block *block = self->blocks[b];
 
         if (!block->final || vec_size(block->instr) < 2)
@@ -784,7 +778,7 @@ static bool ir_function_pass_tailrecursion(ir_function *self)
         block->final = false; /* open it back up */
 
         /* emite parameter-stores */
         block->final = false; /* open it back up */
 
         /* emite parameter-stores */
-        for (p = 0; p < vec_size(call->params); ++p) {
+        for (p = 0; p < call->params.size(); ++p) {
             /* assert(call->params_count <= self->locals_count); */
             if (!ir_block_create_store(block, call->context, self->locals[p], call->params[p])) {
                 irerror(call->context, "failed to create tailcall store instruction for parameter %i", (int)p);
             /* assert(call->params_count <= self->locals_count); */
             if (!ir_block_create_store(block, call->context, self->locals[p], call->params[p])) {
                 irerror(call->context, "failed to create tailcall store instruction for parameter %i", (int)p);
@@ -867,7 +861,7 @@ ir_value* ir_function_create_local(ir_function *self, const char *name, int vtyp
         vec_size(self->locals) &&
         self->locals[vec_size(self->locals)-1]->store != store_param) {
         irerror(self->context, "cannot add parameters after adding locals");
         vec_size(self->locals) &&
         self->locals[vec_size(self->locals)-1]->store != store_param) {
         irerror(self->context, "cannot add parameters after adding locals");
-        return NULL;
+        return nullptr;
     }
 
     ve = ir_value_var(name, (param ? store_param : store_local), vtype);
     }
 
     ve = ir_value_var(name, (param ? store_param : store_local), vtype);
@@ -883,32 +877,25 @@ ir_value* ir_function_create_local(ir_function *self, const char *name, int vtyp
 
 ir_block* ir_block_new(ir_function* owner, const char *name)
 {
 
 ir_block* ir_block_new(ir_function* owner, const char *name)
 {
-    ir_block *self;
-    self = (ir_block*)mem_a(sizeof(*self));
-    if (!self)
-        return NULL;
-
+    ir_block *self = new ir_block;
     memset(self, 0, sizeof(*self));
 
     memset(self, 0, sizeof(*self));
 
-    self->label = NULL;
+    self->label = nullptr;
     if (name && !ir_block_set_label(self, name)) {
         mem_d(self);
     if (name && !ir_block_set_label(self, name)) {
         mem_d(self);
-        return NULL;
+        return nullptr;
     }
     self->owner = owner;
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->final = false;
 
     }
     self->owner = owner;
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->final = false;
 
-    self->instr   = NULL;
-    self->entries = NULL;
-    self->exits   = NULL;
+    self->instr = nullptr;
+    self->entries = nullptr;
+    self->exits = nullptr;
 
     self->eid = 0;
     self->is_return = false;
 
     self->eid = 0;
     self->is_return = false;
-
-    self->living = NULL;
-
     self->generated = false;
 
     return self;
     self->generated = false;
 
     return self;
@@ -923,8 +910,7 @@ static void ir_block_delete_quick(ir_block* self)
     vec_free(self->instr);
     vec_free(self->entries);
     vec_free(self->exits);
     vec_free(self->instr);
     vec_free(self->entries);
     vec_free(self->exits);
-    vec_free(self->living);
-    mem_d(self);
+    delete self;
 }
 
 void ir_block_delete(ir_block* self)
 }
 
 void ir_block_delete(ir_block* self)
@@ -936,8 +922,7 @@ void ir_block_delete(ir_block* self)
     vec_free(self->instr);
     vec_free(self->entries);
     vec_free(self->exits);
     vec_free(self->instr);
     vec_free(self->entries);
     vec_free(self->exits);
-    vec_free(self->living);
-    mem_d(self);
+    delete self;
 }
 
 bool ir_block_set_label(ir_block *self, const char *name)
 }
 
 bool ir_block_set_label(ir_block *self, const char *name)
@@ -954,64 +939,50 @@ bool ir_block_set_label(ir_block *self, const char *name)
 
 static ir_instr* ir_instr_new(lex_ctx_t ctx, ir_block* owner, int op)
 {
 
 static ir_instr* ir_instr_new(lex_ctx_t ctx, ir_block* owner, int op)
 {
-    ir_instr *self;
-    self = (ir_instr*)mem_a(sizeof(*self));
-    if (!self)
-        return NULL;
-
+    ir_instr *self = new ir_instr;
     self->owner = owner;
     self->context = ctx;
     self->opcode = op;
     self->owner = owner;
     self->context = ctx;
     self->opcode = op;
-    self->_ops[0] = NULL;
-    self->_ops[1] = NULL;
-    self->_ops[2] = NULL;
-    self->bops[0] = NULL;
-    self->bops[1] = NULL;
-
-    self->phi    = NULL;
-    self->params = NULL;
-
+    self->_ops[0] = nullptr;
+    self->_ops[1] = nullptr;
+    self->_ops[2] = nullptr;
+    self->bops[0] = nullptr;
+    self->bops[1] = nullptr;
     self->eid = 0;
     self->eid = 0;
-
     self->likely = true;
     return self;
 }
 
 static void ir_instr_delete_quick(ir_instr *self)
 {
     self->likely = true;
     return self;
 }
 
 static void ir_instr_delete_quick(ir_instr *self)
 {
-    vec_free(self->phi);
-    vec_free(self->params);
-    mem_d(self);
+    delete self;
 }
 
 static void ir_instr_delete(ir_instr *self)
 {
 }
 
 static void ir_instr_delete(ir_instr *self)
 {
-    size_t i;
     /* The following calls can only delete from
      * vectors, we still want to delete this instruction
      * 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());
      */
     /* The following calls can only delete from
      * vectors, we still want to delete this instruction
      * 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 (i = 0; i < vec_size(self->phi); ++i) {
+    for (auto &it : self->phi) {
         size_t idx;
         size_t idx;
-        if (vec_ir_instr_find(self->phi[i].value->writes, self, &idx))
-            vec_remove(self->phi[i].value->writes, idx, 1);
-        if (vec_ir_instr_find(self->phi[i].value->reads, self, &idx))
-            vec_remove(self->phi[i].value->reads, idx, 1);
+        if (vec_ir_instr_find(it.value->writes, self, &idx))
+            it.value->writes.erase(it.value->writes.begin() + idx);
+        if (vec_ir_instr_find(it.value->reads, self, &idx))
+            it.value->reads.erase(it.value->reads.begin() + idx);
     }
     }
-    vec_free(self->phi);
-    for (i = 0; i < vec_size(self->params); ++i) {
+    for (auto &it : self->params) {
         size_t idx;
         size_t idx;
-        if (vec_ir_instr_find(self->params[i]->writes, self, &idx))
-            vec_remove(self->params[i]->writes, idx, 1);
-        if (vec_ir_instr_find(self->params[i]->reads, self, &idx))
-            vec_remove(self->params[i]->reads, idx, 1);
-    }
-    vec_free(self->params);
-    (void)!ir_instr_op(self, 0, NULL, false);
-    (void)!ir_instr_op(self, 1, NULL, false);
-    (void)!ir_instr_op(self, 2, NULL, false);
+        if (vec_ir_instr_find(it->writes, self, &idx))
+            it->writes.erase(it->writes.begin() + idx);
+        if (vec_ir_instr_find(it->reads, self, &idx))
+            it->reads.erase(it->reads.begin() + idx);
+    }
+    (void)!ir_instr_op(self, 0, nullptr, false);
+    (void)!ir_instr_op(self, 1, nullptr, false);
+    (void)!ir_instr_op(self, 2, nullptr, false);
     mem_d(self);
 }
 
     mem_d(self);
 }
 
@@ -1025,15 +996,15 @@ static bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing)
     if (self->_ops[op]) {
         size_t idx;
         if (writing && vec_ir_instr_find(self->_ops[op]->writes, self, &idx))
     if (self->_ops[op]) {
         size_t idx;
         if (writing && vec_ir_instr_find(self->_ops[op]->writes, self, &idx))
-            vec_remove(self->_ops[op]->writes, idx, 1);
+            self->_ops[op]->writes.erase(self->_ops[op]->writes.begin() + idx);
         else if (vec_ir_instr_find(self->_ops[op]->reads, self, &idx))
         else if (vec_ir_instr_find(self->_ops[op]->reads, self, &idx))
-            vec_remove(self->_ops[op]->reads, idx, 1);
+            self->_ops[op]->reads.erase(self->_ops[op]->reads.begin() + idx);
     }
     if (v) {
         if (writing)
     }
     if (v) {
         if (writing)
-            vec_push(v->writes, self);
+            v->writes.push_back(self);
         else
         else
-            vec_push(v->reads, self);
+            v->reads.push_back(self);
     }
     self->_ops[op] = v;
     return true;
     }
     self->_ops[op] = v;
     return true;
@@ -1062,39 +1033,37 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype)
 {
     ir_value *self;
     self = (ir_value*)mem_a(sizeof(*self));
 {
     ir_value *self;
     self = (ir_value*)mem_a(sizeof(*self));
+    new (self) ir_value();
     self->vtype = vtype;
     self->fieldtype = TYPE_VOID;
     self->outtype = TYPE_VOID;
     self->store = storetype;
     self->flags = 0;
 
     self->vtype = vtype;
     self->fieldtype = TYPE_VOID;
     self->outtype = TYPE_VOID;
     self->store = storetype;
     self->flags = 0;
 
-    self->reads  = NULL;
-    self->writes = NULL;
-
-    self->cvq          = CV_NONE;
-    self->hasvalue     = false;
+    self->cvq = CV_NONE;
+    self->hasvalue = false;
     self->context.file = "<@no context>";
     self->context.line = 0;
     self->context.file = "<@no context>";
     self->context.line = 0;
-    self->name = NULL;
+    self->name = nullptr;
     if (name && !ir_value_set_name(self, name)) {
         irerror(self->context, "out of memory");
         mem_d(self);
     if (name && !ir_value_set_name(self, name)) {
         irerror(self->context, "out of memory");
         mem_d(self);
-        return NULL;
+        return nullptr;
     }
 
     memset(&self->constval, 0, sizeof(self->constval));
     memset(&self->code,     0, sizeof(self->code));
 
     }
 
     memset(&self->constval, 0, sizeof(self->constval));
     memset(&self->code,     0, sizeof(self->code));
 
-    self->members[0] = NULL;
-    self->members[1] = NULL;
-    self->members[2] = NULL;
-    self->memberof = NULL;
+    self->members[0] = nullptr;
+    self->members[1] = nullptr;
+    self->members[2] = nullptr;
+    self->memberof = nullptr;
 
     self->unique_life = false;
 
     self->unique_life = false;
-    self->locked      = false;
-    self->callparam   = false;
+    self->locked = false;
+    self->callparam  = false;
 
 
-    self->life = NULL;
+    self->life = nullptr;
     return self;
 }
 
     return self;
 }
 
@@ -1114,11 +1083,11 @@ static ir_value* ir_builder_imm_float(ir_builder *self, float value, bool add_to
 
 ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
 {
 
 ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
 {
-    char     *name;
-    size_t    len;
+    char *name;
+    size_t len;
     ir_value *m;
     if (member >= 3)
     ir_value *m;
     if (member >= 3)
-        return NULL;
+        return nullptr;
 
     if (self->members[member])
         return self->members[member];
 
     if (self->members[member])
         return self->members[member];
@@ -1132,7 +1101,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
         name[len+2] = '\0';
     }
     else
         name[len+2] = '\0';
     }
     else
-        name = NULL;
+        name = nullptr;
 
     if (self->vtype == TYPE_VECTOR)
     {
 
     if (self->vtype == TYPE_VECTOR)
     {
@@ -1140,7 +1109,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
         if (name)
             mem_d(name);
         if (!m)
         if (name)
             mem_d(name);
         if (!m)
-            return NULL;
+            return nullptr;
         m->context = self->context;
 
         self->members[member] = m;
         m->context = self->context;
 
         self->members[member] = m;
@@ -1149,12 +1118,12 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
     else if (self->vtype == TYPE_FIELD)
     {
         if (self->fieldtype != TYPE_VECTOR)
     else if (self->vtype == TYPE_FIELD)
     {
         if (self->fieldtype != TYPE_VECTOR)
-            return NULL;
+            return nullptr;
         m = ir_value_var(name, self->store, TYPE_FIELD);
         if (name)
             mem_d(name);
         if (!m)
         m = ir_value_var(name, self->store, TYPE_FIELD);
         if (name)
             mem_d(name);
         if (!m)
-            return NULL;
+            return nullptr;
         m->fieldtype = TYPE_FLOAT;
         m->context = self->context;
 
         m->fieldtype = TYPE_FLOAT;
         m->context = self->context;
 
@@ -1164,7 +1133,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
     else
     {
         irerror(self->context, "invalid member access on %s", self->name);
     else
     {
         irerror(self->context, "invalid member access on %s", self->name);
-        return NULL;
+        return nullptr;
     }
 
     m->memberof = self;
     }
 
     m->memberof = self;
@@ -1182,7 +1151,7 @@ static ir_value* ir_value_out(ir_function *owner, const char *name, int storetyp
 {
     ir_value *v = ir_value_var(name, storetype, vtype);
     if (!v)
 {
     ir_value *v = ir_value_var(name, storetype, vtype);
     if (!v)
-        return NULL;
+        return nullptr;
     ir_function_collect_value(owner, v);
     return v;
 }
     ir_function_collect_value(owner, v);
     return v;
 }
@@ -1203,8 +1172,6 @@ void ir_value_delete(ir_value* self)
                 ir_value_delete(self->members[i]);
         }
     }
                 ir_value_delete(self->members[i]);
         }
     }
-    vec_free(self->reads);
-    vec_free(self->writes);
     vec_free(self->life);
     mem_d(self);
 }
     vec_free(self->life);
     mem_d(self);
 }
@@ -1301,8 +1268,8 @@ static bool ir_value_life_merge(ir_value *self, size_t s)
 {
     size_t i;
     const size_t vs = vec_size(self->life);
 {
     size_t i;
     const size_t vs = vec_size(self->life);
-    ir_life_entry_t *life = NULL;
-    ir_life_entry_t *before = NULL;
+    ir_life_entry_t *life = nullptr;
+    ir_life_entry_t *before = nullptr;
     ir_life_entry_t new_entry;
 
     /* Find the first range >= s */
     ir_life_entry_t new_entry;
 
     /* Find the first range >= s */
@@ -1677,19 +1644,19 @@ ir_instr* ir_block_create_phi(ir_block *self, lex_ctx_t ctx, const char *label,
     ir_value *out;
     ir_instr *in;
     if (!ir_check_unreachable(self))
     ir_value *out;
     ir_instr *in;
     if (!ir_check_unreachable(self))
-        return NULL;
+        return nullptr;
     in = ir_instr_new(ctx, self, VINSTR_PHI);
     if (!in)
     in = ir_instr_new(ctx, self, VINSTR_PHI);
     if (!in)
-        return NULL;
+        return nullptr;
     out = ir_value_out(self->owner, label, store_value, ot);
     if (!out) {
         ir_instr_delete(in);
     out = ir_value_out(self->owner, label, store_value, ot);
     if (!out) {
         ir_instr_delete(in);
-        return NULL;
+        return nullptr;
     }
     if (!ir_instr_op(in, 0, out, true)) {
         ir_instr_delete(in);
         ir_value_delete(out);
     }
     if (!ir_instr_op(in, 0, out, true)) {
         ir_instr_delete(in);
         ir_value_delete(out);
-        return NULL;
+        return nullptr;
     }
     vec_push(self->instr, in);
     return in;
     }
     vec_push(self->instr, in);
     return in;
@@ -1704,7 +1671,7 @@ void ir_phi_add(ir_instr* self, ir_block *b, ir_value *v)
 {
     ir_phi_entry_t pe;
 
 {
     ir_phi_entry_t pe;
 
-    if (!vec_ir_block_find(self->owner->entries, b, NULL)) {
+    if (!vec_ir_block_find(self->owner->entries, b, nullptr)) {
         /* Must not be possible to cause this, otherwise the AST
          * is doing something wrong.
          */
         /* Must not be possible to cause this, otherwise the AST
          * is doing something wrong.
          */
@@ -1714,8 +1681,8 @@ void ir_phi_add(ir_instr* self, ir_block *b, ir_value *v)
 
     pe.value = v;
     pe.from = b;
 
     pe.value = v;
     pe.from = b;
-    vec_push(v->reads, self);
-    vec_push(self->phi, pe);
+    v->reads.push_back(self);
+    self->phi.push_back(pe);
 }
 
 /* call related code */
 }
 
 /* call related code */
@@ -1724,10 +1691,10 @@ ir_instr* ir_block_create_call(ir_block *self, lex_ctx_t ctx, const char *label,
     ir_value *out;
     ir_instr *in;
     if (!ir_check_unreachable(self))
     ir_value *out;
     ir_instr *in;
     if (!ir_check_unreachable(self))
-        return NULL;
+        return nullptr;
     in = ir_instr_new(ctx, self, (noreturn ? VINSTR_NRCALL : INSTR_CALL0));
     if (!in)
     in = ir_instr_new(ctx, self, (noreturn ? VINSTR_NRCALL : INSTR_CALL0));
     if (!in)
-        return NULL;
+        return nullptr;
     if (noreturn) {
         self->final = true;
         self->is_return = true;
     if (noreturn) {
         self->final = true;
         self->is_return = true;
@@ -1735,22 +1702,22 @@ ir_instr* ir_block_create_call(ir_block *self, lex_ctx_t ctx, const char *label,
     out = ir_value_out(self->owner, label, (func->outtype == TYPE_VOID) ? store_return : store_value, func->outtype);
     if (!out) {
         ir_instr_delete(in);
     out = ir_value_out(self->owner, label, (func->outtype == TYPE_VOID) ? store_return : store_value, func->outtype);
     if (!out) {
         ir_instr_delete(in);
-        return NULL;
+        return nullptr;
     }
     if (!ir_instr_op(in, 0, out, true) ||
         !ir_instr_op(in, 1, func, false))
     {
         ir_instr_delete(in);
         ir_value_delete(out);
     }
     if (!ir_instr_op(in, 0, out, true) ||
         !ir_instr_op(in, 1, func, false))
     {
         ir_instr_delete(in);
         ir_value_delete(out);
-        return NULL;
+        return nullptr;
     }
     vec_push(self->instr, in);
     /*
     if (noreturn) {
     }
     vec_push(self->instr, in);
     /*
     if (noreturn) {
-        if (!ir_block_create_return(self, ctx, NULL)) {
+        if (!ir_block_create_return(self, ctx, nullptr)) {
             compile_error(ctx, "internal error: failed to generate dummy-return instruction");
             ir_instr_delete(in);
             compile_error(ctx, "internal error: failed to generate dummy-return instruction");
             ir_instr_delete(in);
-            return NULL;
+            return nullptr;
         }
     }
     */
         }
     }
     */
@@ -1764,8 +1731,8 @@ ir_value* ir_call_value(ir_instr *self)
 
 void ir_call_param(ir_instr* self, ir_value *v)
 {
 
 void ir_call_param(ir_instr* self, ir_value *v)
 {
-    vec_push(self->params, v);
-    vec_push(v->reads, self);
+    self->params.push_back(v);
+    v->reads.push_back(self);
 }
 
 /* binary op related code */
 }
 
 /* binary op related code */
@@ -1883,7 +1850,7 @@ ir_value* ir_block_create_binop(ir_block *self, lex_ctx_t ctx,
     };
     if (ot == TYPE_VOID) {
         /* The AST or parser were supposed to check this! */
     };
     if (ot == TYPE_VOID) {
         /* The AST or parser were supposed to check this! */
-        return NULL;
+        return nullptr;
     }
 
     return ir_block_create_general_instr(self, ctx, label, opcode, left, right, ot);
     }
 
     return ir_block_create_general_instr(self, ctx, label, opcode, left, right, ot);
@@ -1909,9 +1876,9 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx,
          * the operand for 0 already exists so we just source it from here.
          */
         case VINSTR_NEG_F:
          * the operand for 0 already exists so we just source it from here.
          */
         case VINSTR_NEG_F:
-            return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_F, NULL, operand, ot);
+            return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_F, nullptr, operand, ot);
         case VINSTR_NEG_V:
         case VINSTR_NEG_V:
-            return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, NULL, operand, TYPE_VECTOR);
+            return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, nullptr, operand, TYPE_VECTOR);
 
         default:
             ot = operand->vtype;
 
         default:
             ot = operand->vtype;
@@ -1919,11 +1886,11 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx,
     };
     if (ot == TYPE_VOID) {
         /* The AST or parser were supposed to check this! */
     };
     if (ot == TYPE_VOID) {
         /* The AST or parser were supposed to check this! */
-        return NULL;
+        return nullptr;
     }
 
     }
 
-    /* let's use the general instruction creator and pass NULL for OPB */
-    return ir_block_create_general_instr(self, ctx, label, opcode, operand, NULL, ot);
+    /* let's use the general instruction creator and pass nullptr for OPB */
+    return ir_block_create_general_instr(self, ctx, label, opcode, operand, nullptr, ot);
 }
 
 static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, const char *label,
 }
 
 static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, const char *label,
@@ -1934,12 +1901,12 @@ static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, co
 
     out = ir_value_out(self->owner, label, store_value, outype);
     if (!out)
 
     out = ir_value_out(self->owner, label, store_value, outype);
     if (!out)
-        return NULL;
+        return nullptr;
 
     instr = ir_instr_new(ctx, self, op);
     if (!instr) {
         ir_value_delete(out);
 
     instr = ir_instr_new(ctx, self, op);
     if (!instr) {
         ir_value_delete(out);
-        return NULL;
+        return nullptr;
     }
 
     if (!ir_instr_op(instr, 0, out, true) ||
     }
 
     if (!ir_instr_op(instr, 0, out, true) ||
@@ -1955,7 +1922,7 @@ static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, co
 on_error:
     ir_instr_delete(instr);
     ir_value_delete(out);
 on_error:
     ir_instr_delete(instr);
     ir_value_delete(out);
-    return NULL;
+    return nullptr;
 }
 
 ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field)
 }
 
 ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field)
@@ -1964,10 +1931,10 @@ ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char
 
     /* Support for various pointer types todo if so desired */
     if (ent->vtype != TYPE_ENTITY)
 
     /* Support for various pointer types todo if so desired */
     if (ent->vtype != TYPE_ENTITY)
-        return NULL;
+        return nullptr;
 
     if (field->vtype != TYPE_FIELD)
 
     if (field->vtype != TYPE_FIELD)
-        return NULL;
+        return nullptr;
 
     v = ir_block_create_general_instr(self, ctx, label, INSTR_ADDRESS, ent, field, TYPE_POINTER);
     v->fieldtype = field->fieldtype;
 
     v = ir_block_create_general_instr(self, ctx, label, INSTR_ADDRESS, ent, field, TYPE_POINTER);
     v->fieldtype = field->fieldtype;
@@ -1978,11 +1945,11 @@ ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const cha
 {
     int op;
     if (ent->vtype != TYPE_ENTITY)
 {
     int op;
     if (ent->vtype != TYPE_ENTITY)
-        return NULL;
+        return nullptr;
 
     /* at some point we could redirect for TYPE_POINTER... but that could lead to carelessness */
     if (field->vtype != TYPE_FIELD)
 
     /* at some point we could redirect for TYPE_POINTER... but that could lead to carelessness */
     if (field->vtype != TYPE_FIELD)
-        return NULL;
+        return nullptr;
 
     switch (outype)
     {
 
     switch (outype)
     {
@@ -1998,7 +1965,7 @@ ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const cha
 #endif
         default:
             irerror(self->context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
 #endif
         default:
             irerror(self->context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
-            return NULL;
+            return nullptr;
     }
 
     return ir_block_create_general_instr(self, ctx, label, op, ent, field, outype);
     }
 
     return ir_block_create_general_instr(self, ctx, label, op, ent, field, outype);
@@ -2023,7 +1990,7 @@ bool ir_function_naive_phi(ir_function *self)
 
 static bool ir_block_naive_phi(ir_block *self)
 {
 
 static bool ir_block_naive_phi(ir_block *self)
 {
-    size_t i, p; /*, w;*/
+    size_t i;
     /* FIXME: optionally, create_phi can add the phis
      * to a list so we don't need to loop through blocks
      * - anyway: "don't optimize YET"
     /* FIXME: optionally, create_phi can add the phis
      * to a list so we don't need to loop through blocks
      * - anyway: "don't optimize YET"
@@ -2037,21 +2004,14 @@ static bool ir_block_naive_phi(ir_block *self)
         vec_remove(self->instr, i, 1);
         --i; /* NOTE: i+1 below */
 
         vec_remove(self->instr, i, 1);
         --i; /* NOTE: i+1 below */
 
-        for (p = 0; p < vec_size(instr->phi); ++p)
-        {
-            ir_value *v = instr->phi[p].value;
-            ir_block *b = instr->phi[p].from;
-
-            if (v->store == store_value &&
-                vec_size(v->reads) == 1 &&
-                vec_size(v->writes) == 1)
-            {
+        for (auto &it : instr->phi) {
+            ir_value *v = it.value;
+            ir_block *b = it.from;
+            if (v->store == store_value && v->reads.size() == 1 && v->writes.size() == 1) {
                 /* replace the value */
                 if (!ir_instr_op(v->writes[0], 0, instr->_ops[0], true))
                     return false;
                 /* replace the value */
                 if (!ir_instr_op(v->writes[0], 0, instr->_ops[0], true))
                     return false;
-            }
-            else
-            {
+            } else {
                 /* force a move instruction */
                 ir_instr *prevjump = vec_last(b->instr);
                 vec_pop(b->instr);
                 /* force a move instruction */
                 ir_instr *prevjump = vec_last(b->instr);
                 vec_pop(b->instr);
@@ -2118,12 +2078,12 @@ void ir_function_enumerate(ir_function *self)
  * we can allocate their global-positions.
  * This is the counterpart to register-allocation in register machines.
  */
  * we can allocate their global-positions.
  * This is the counterpart to register-allocation in register machines.
  */
-typedef struct {
+struct function_allocator {
     ir_value **locals;
     ir_value **locals;
-    size_t    *sizes;
-    size_t    *positions;
-    bool      *unique;
-} function_allocator;
+    size_t *sizes;
+    size_t *positions;
+    bool *unique;
+};
 
 static bool function_allocator_alloc(function_allocator *alloc, ir_value *var)
 {
 
 static bool function_allocator_alloc(function_allocator *alloc, ir_value *var)
 {
@@ -2209,14 +2169,14 @@ bool ir_function_allocate_locals(ir_function *self)
     if (!vec_size(self->locals) && !vec_size(self->values))
         return true;
 
     if (!vec_size(self->locals) && !vec_size(self->values))
         return true;
 
-    globalloc.locals    = NULL;
-    globalloc.sizes     = NULL;
-    globalloc.positions = NULL;
-    globalloc.unique    = NULL;
-    lockalloc.locals    = NULL;
-    lockalloc.sizes     = NULL;
-    lockalloc.positions = NULL;
-    lockalloc.unique    = NULL;
+    globalloc.locals    = nullptr;
+    globalloc.sizes     = nullptr;
+    globalloc.positions = nullptr;
+    globalloc.unique    = nullptr;
+    lockalloc.locals    = nullptr;
+    lockalloc.sizes     = nullptr;
+    lockalloc.positions = nullptr;
+    lockalloc.unique    = nullptr;
 
     for (i = 0; i < vec_size(self->locals); ++i)
     {
 
     for (i = 0; i < vec_size(self->locals); ++i)
     {
@@ -2254,13 +2214,13 @@ bool ir_function_allocate_locals(ir_function *self)
          * and it's not "locked", write it to the OFS_PARM directly.
          */
         if (OPTS_OPTIMIZATION(OPTIM_CALL_STORES) && !v->locked && !v->unique_life) {
          * and it's not "locked", write it to the OFS_PARM directly.
          */
         if (OPTS_OPTIMIZATION(OPTIM_CALL_STORES) && !v->locked && !v->unique_life) {
-            if (vec_size(v->reads) == 1 && vec_size(v->writes) == 1 &&
+            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)
                 )
                )
             {
                 (v->reads[0]->opcode == VINSTR_NRCALL ||
                  (v->reads[0]->opcode >= INSTR_CALL0 && v->reads[0]->opcode <= INSTR_CALL8)
                 )
                )
             {
-                size_t    param;
+                size_t param;
                 ir_instr *call = v->reads[0];
                 if (!vec_ir_value_find(call->params, v, &param)) {
                     irerror(call->context, "internal error: unlocked parameter %s not found", v->name);
                 ir_instr *call = v->reads[0];
                 if (!vec_ir_value_find(call->params, v, &param)) {
                     irerror(call->context, "internal error: unlocked parameter %s not found", v->name);
@@ -2287,8 +2247,7 @@ bool ir_function_allocate_locals(ir_function *self)
                 }
                 continue;
             }
                 }
                 continue;
             }
-            if (vec_size(v->writes) == 1 && v->writes[0]->opcode == INSTR_CALL0)
-            {
+            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;
                 v->store = store_return;
                 if (v->members[0]) v->members[0]->store = store_return;
                 if (v->members[1]) v->members[1]->store = store_return;
@@ -2404,29 +2363,21 @@ static void ir_op_read_write(int op, size_t *read, size_t *write)
     };
 }
 
     };
 }
 
-static bool ir_block_living_add_instr(ir_block *self, size_t eid)
-{
-    size_t       i;
-    const size_t vs = vec_size(self->living);
-    bool         changed = false;
-    for (i = 0; i != vs; ++i)
-    {
-        if (ir_value_life_merge(self->living[i], eid))
+static bool ir_block_living_add_instr(ir_block *self, size_t eid) {
+    bool changed = false;
+    for (auto &it : self->living)
+        if (ir_value_life_merge(it, eid))
             changed = true;
             changed = true;
-    }
     return changed;
 }
 
     return changed;
 }
 
-static bool ir_block_living_lock(ir_block *self)
-{
-    size_t i;
+static bool ir_block_living_lock(ir_block *self) {
     bool changed = false;
     bool changed = false;
-    for (i = 0; i != vec_size(self->living); ++i)
-    {
-        if (!self->living[i]->locked) {
-            self->living[i]->locked = true;
-            changed = true;
-        }
+    for (auto &it : self->living) {
+        if (it->locked)
+            continue;
+        it->locked = true;
+        changed = true;
     }
     return changed;
 }
     }
     return changed;
 }
@@ -2435,7 +2386,7 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
 {
     ir_instr *instr;
     ir_value *value;
 {
     ir_instr *instr;
     ir_value *value;
-    size_t i, o, p, mem, cnt;
+    size_t i, o, p, mem;
     /* bitmasks which operands are read from or written to */
     size_t read, write;
     char dbg_ind[16];
     /* bitmasks which operands are read from or written to */
     size_t read, write;
     char dbg_ind[16];
@@ -2443,16 +2394,14 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
     dbg_ind[1] = '0';
     (void)dbg_ind;
 
     dbg_ind[1] = '0';
     (void)dbg_ind;
 
-    vec_free(self->living);
+    self->living.clear();
 
     p = vec_size(self->exits);
     for (i = 0; i < p; ++i) {
         ir_block *prev = self->exits[i];
 
     p = vec_size(self->exits);
     for (i = 0; i < p; ++i) {
         ir_block *prev = self->exits[i];
-        cnt = vec_size(prev->living);
-        for (o = 0; o < cnt; ++o) {
-            if (!vec_ir_value_find(self->living, prev->living[o], NULL))
-                vec_push(self->living, prev->living[o]);
-        }
+        for (auto &it : prev->living)
+            if (!vec_ir_value_find(self->living, it, nullptr))
+                self->living.push_back(it);
     }
 
     i = vec_size(self->instr);
     }
 
     i = vec_size(self->instr);
@@ -2509,28 +2458,28 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
                      */
                     if (ir_value_life_merge(value, instr->eid))
                         *changed = true;
                      */
                     if (ir_value_life_merge(value, instr->eid))
                         *changed = true;
-                    /* Then remove */
-                    vec_remove(self->living, idx, 1);
+                    // Then remove
+                    self->living.erase(self->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))
                             *changed = true;
                 }
                 /* 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))
                             *changed = true;
-                        vec_remove(self->living, idx, 1);
+                        self->living.erase(self->living.begin() + idx);
                     }
                 }
                 /* Removing the last member removes the vector */
                 if (value->memberof) {
                     value = value->memberof;
                     for (mem = 0; mem < 3; ++mem) {
                     }
                 }
                 /* Removing the last member removes the vector */
                 if (value->memberof) {
                     value = value->memberof;
                     for (mem = 0; mem < 3; ++mem) {
-                        if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], NULL))
+                        if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], nullptr))
                             break;
                     }
                     if (mem == 3 && vec_ir_value_find(self->living, value, &idx)) {
                         if (ir_value_life_merge(value, instr->eid))
                             *changed = true;
                             break;
                     }
                     if (mem == 3 && vec_ir_value_find(self->living, value, &idx)) {
                         if (ir_value_life_merge(value, instr->eid))
                             *changed = true;
-                        vec_remove(self->living, idx, 1);
+                        self->living.erase(self->living.begin() + idx);
                     }
                 }
             }
                     }
                 }
             }
@@ -2588,29 +2537,28 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
             /* read operands */
             if (read & (1<<o))
             {
             /* read operands */
             if (read & (1<<o))
             {
-                if (!vec_ir_value_find(self->living, value, NULL))
-                    vec_push(self->living, value);
+                if (!vec_ir_value_find(self->living, value, nullptr))
+                    self->living.push_back(value);
                 /* reading adds the full vector */
                 /* reading adds the full vector */
-                if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
-                    vec_push(self->living, value->memberof);
+                if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
+                    self->living.push_back(value->memberof);
                 for (mem = 0; mem < 3; ++mem) {
                 for (mem = 0; mem < 3; ++mem) {
-                    if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
-                        vec_push(self->living, value->members[mem]);
+                    if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
+                        self->living.push_back(value->members[mem]);
                 }
             }
         }
         /* PHI operands are always read operands */
                 }
             }
         }
         /* PHI operands are always read operands */
-        for (p = 0; p < vec_size(instr->phi); ++p)
-        {
-            value = instr->phi[p].value;
-            if (!vec_ir_value_find(self->living, value, NULL))
-                vec_push(self->living, value);
+        for (auto &it : instr->phi) {
+            value = it.value;
+            if (!vec_ir_value_find(self->living, value, nullptr))
+                self->living.push_back(value);
             /* reading adds the full vector */
             /* reading adds the full vector */
-            if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
-                vec_push(self->living, value->memberof);
+            if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
+                self->living.push_back(value->memberof);
             for (mem = 0; mem < 3; ++mem) {
             for (mem = 0; mem < 3; ++mem) {
-                if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
-                    vec_push(self->living, value->members[mem]);
+                if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
+                    self->living.push_back(value->members[mem]);
             }
         }
 
             }
         }
 
@@ -2620,17 +2568,16 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
                 *changed = true;
         }
         /* call params are read operands too */
                 *changed = true;
         }
         /* call params are read operands too */
-        for (p = 0; p < vec_size(instr->params); ++p)
-        {
-            value = instr->params[p];
-            if (!vec_ir_value_find(self->living, value, NULL))
-                vec_push(self->living, value);
+        for (auto &it : instr->params) {
+            value = it;
+            if (!vec_ir_value_find(self->living, value, nullptr))
+                self->living.push_back(value);
             /* reading adds the full vector */
             /* reading adds the full vector */
-            if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
-                vec_push(self->living, value->memberof);
+            if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
+                self->living.push_back(value->memberof);
             for (mem = 0; mem < 3; ++mem) {
             for (mem = 0; mem < 3; ++mem) {
-                if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
-                    vec_push(self->living, value->members[mem]);
+                if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
+                    self->living.push_back(value->members[mem]);
             }
         }
 
             }
         }
 
@@ -2666,19 +2613,19 @@ bool ir_function_calculate_liferanges(ir_function *self)
 
     if (vec_size(self->blocks)) {
         ir_block *block = self->blocks[0];
 
     if (vec_size(self->blocks)) {
         ir_block *block = self->blocks[0];
-        for (i = 0; i < vec_size(block->living); ++i) {
-            ir_value *v = block->living[i];
+        for (auto &it : block->living) {
+            ir_value *v = it;
             if (v->store != store_local)
                 continue;
             if (v->vtype == TYPE_VECTOR)
                 continue;
             self->flags |= IR_FLAG_HAS_UNINITIALIZED;
             /* find the instruction reading from it */
             if (v->store != store_local)
                 continue;
             if (v->vtype == TYPE_VECTOR)
                 continue;
             self->flags |= IR_FLAG_HAS_UNINITIALIZED;
             /* find the instruction reading from it */
-            for (s = 0; s < vec_size(v->reads); ++s) {
+            for (s = 0; s < v->reads.size(); ++s) {
                 if (v->reads[s]->eid == v->life[0].end)
                     break;
             }
                 if (v->reads[s]->eid == v->life[0].end)
                     break;
             }
-            if (s < vec_size(v->reads)) {
+            if (s < v->reads.size()) {
                 if (irwarning(v->context, WARN_USED_UNINITIALIZED,
                               "variable `%s` may be used uninitialized in this function\n"
                               " -> %s:%i",
                 if (irwarning(v->context, WARN_USED_UNINITIALIZED,
                               "variable `%s` may be used uninitialized in this function\n"
                               " -> %s:%i",
@@ -2692,11 +2639,11 @@ bool ir_function_calculate_liferanges(ir_function *self)
             }
             if (v->memberof) {
                 ir_value *vec = v->memberof;
             }
             if (v->memberof) {
                 ir_value *vec = v->memberof;
-                for (s = 0; s < vec_size(vec->reads); ++s) {
+                for (s = 0; s < vec->reads.size(); ++s) {
                     if (vec->reads[s]->eid == v->life[0].end)
                         break;
                 }
                     if (vec->reads[s]->eid == v->life[0].end)
                         break;
                 }
-                if (s < vec_size(vec->reads)) {
+                if (s < vec->reads.size()) {
                     if (irwarning(v->context, WARN_USED_UNINITIALIZED,
                                   "variable `%s` may be used uninitialized in this function\n"
                                   " -> %s:%i",
                     if (irwarning(v->context, WARN_USED_UNINITIALIZED,
                                   "variable `%s` may be used uninitialized in this function\n"
                                   " -> %s:%i",
@@ -2747,20 +2694,20 @@ static bool gen_global_field(code_t *code, ir_value *global)
         }
 
         /* copy the field's value */
         }
 
         /* copy the field's value */
-        ir_value_code_setaddr(global, vec_size(code->globals));
-        vec_push(code->globals, fld->code.fieldaddr);
+        ir_value_code_setaddr(global, code->globals.size());
+        code->globals.push_back(fld->code.fieldaddr);
         if (global->fieldtype == TYPE_VECTOR) {
         if (global->fieldtype == TYPE_VECTOR) {
-            vec_push(code->globals, fld->code.fieldaddr+1);
-            vec_push(code->globals, fld->code.fieldaddr+2);
+            code->globals.push_back(fld->code.fieldaddr+1);
+            code->globals.push_back(fld->code.fieldaddr+2);
         }
     }
     else
     {
         }
     }
     else
     {
-        ir_value_code_setaddr(global, vec_size(code->globals));
-        vec_push(code->globals, 0);
+        ir_value_code_setaddr(global, code->globals.size());
+        code->globals.push_back(0);
         if (global->fieldtype == TYPE_VECTOR) {
         if (global->fieldtype == TYPE_VECTOR) {
-            vec_push(code->globals, 0);
-            vec_push(code->globals, 0);
+            code->globals.push_back(0);
+            code->globals.push_back(0);
         }
     }
     if (global->code.globaladdr < 0)
         }
     }
     if (global->code.globaladdr < 0)
@@ -2775,7 +2722,7 @@ static bool gen_global_pointer(code_t *code, ir_value *global)
         ir_value *target = global->constval.vpointer;
         if (!target) {
             irerror(global->context, "Invalid pointer constant: %s", global->name);
         ir_value *target = global->constval.vpointer;
         if (!target) {
             irerror(global->context, "Invalid pointer constant: %s", global->name);
-            /* NULL pointers are pointing to the NULL constant, which also
+            /* nullptr pointers are pointing to the nullptr constant, which also
              * sits at address 0, but still has an ir_value for itself.
              */
             return false;
              * sits at address 0, but still has an ir_value for itself.
              */
             return false;
@@ -2794,13 +2741,13 @@ static bool gen_global_pointer(code_t *code, ir_value *global)
             return false;
         }
 
             return false;
         }
 
-        ir_value_code_setaddr(global, vec_size(code->globals));
-        vec_push(code->globals, target->code.globaladdr);
+        ir_value_code_setaddr(global, code->globals.size());
+        code->globals.push_back(target->code.globaladdr);
     }
     else
     {
     }
     else
     {
-        ir_value_code_setaddr(global, vec_size(code->globals));
-        vec_push(code->globals, 0);
+        ir_value_code_setaddr(global, code->globals.size());
+        code->globals.push_back(0);
     }
     if (global->code.globaladdr < 0)
         return false;
     }
     if (global->code.globaladdr < 0)
         return false;
@@ -2819,7 +2766,7 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
     int       j;
 
     block->generated = true;
     int       j;
 
     block->generated = true;
-    block->code_start = vec_size(code->statements);
+    block->code_start = code->statements.size();
     for (i = 0; i < vec_size(block->instr); ++i)
     {
         instr = block->instr[i];
     for (i = 0; i < vec_size(block->instr); ++i)
     {
         instr = block->instr[i];
@@ -2839,7 +2786,7 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
 
             /* otherwise we generate a jump instruction */
             stmt.opcode = INSTR_GOTO;
 
             /* otherwise we generate a jump instruction */
             stmt.opcode = INSTR_GOTO;
-            stmt.o1.s1 = (target->code_start) - vec_size(code->statements);
+            stmt.o1.s1 = target->code_start - code->statements.size();
             stmt.o2.s1 = 0;
             stmt.o3.s1 = 0;
             if (stmt.o1.s1 != 1)
             stmt.o2.s1 = 0;
             stmt.o3.s1 = 0;
             if (stmt.o1.s1 != 1)
@@ -3023,13 +2970,13 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
 
             if (ontrue->generated) {
                 stmt.opcode = INSTR_IF;
 
             if (ontrue->generated) {
                 stmt.opcode = INSTR_IF;
-                stmt.o2.s1 = (ontrue->code_start) - vec_size(code->statements);
+                stmt.o2.s1 = ontrue->code_start - code->statements.size();
                 if (stmt.o2.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
             }
             if (onfalse->generated) {
                 stmt.opcode = INSTR_IFNOT;
                 if (stmt.o2.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
             }
             if (onfalse->generated) {
                 stmt.opcode = INSTR_IFNOT;
-                stmt.o2.s1 = (onfalse->code_start) - vec_size(code->statements);
+                stmt.o2.s1 = onfalse->code_start - code->statements.size();
                 if (stmt.o2.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
             }
                 if (stmt.o2.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
             }
@@ -3050,24 +2997,24 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
                 onfalse = ontrue;
                 ontrue = tmp;
             }
                 onfalse = ontrue;
                 ontrue = tmp;
             }
-            stidx = vec_size(code->statements);
+            stidx = code->statements.size();
             code_push_statement(code, &stmt, instr->context);
             /* on false we jump, so add ontrue-path */
             if (!gen_blocks_recursive(code, func, ontrue))
                 return false;
             /* fixup the jump address */
             code_push_statement(code, &stmt, instr->context);
             /* on false we jump, so add ontrue-path */
             if (!gen_blocks_recursive(code, func, ontrue))
                 return false;
             /* fixup the jump address */
-            code->statements[stidx].o2.s1 = vec_size(code->statements) - stidx;
+            code->statements[stidx].o2.s1 = code->statements.size() - stidx;
             /* generate onfalse path */
             if (onfalse->generated) {
                 /* fixup the jump address */
             /* generate onfalse path */
             if (onfalse->generated) {
                 /* fixup the jump address */
-                code->statements[stidx].o2.s1 = (onfalse->code_start) - (stidx);
-                if (stidx+2 == vec_size(code->statements) && code->statements[stidx].o2.s1 == 1) {
+                code->statements[stidx].o2.s1 = onfalse->code_start - stidx;
+                if (stidx+2 == code->statements.size() && code->statements[stidx].o2.s1 == 1) {
                     code->statements[stidx] = code->statements[stidx+1];
                     if (code->statements[stidx].o1.s1 < 0)
                         code->statements[stidx].o1.s1++;
                     code_pop_statement(code);
                 }
                     code->statements[stidx] = code->statements[stidx+1];
                     if (code->statements[stidx].o1.s1 < 0)
                         code->statements[stidx].o1.s1++;
                     code_pop_statement(code);
                 }
-                stmt.opcode = vec_last(code->statements).opcode;
+                stmt.opcode = code->statements.back().opcode;
                 if (stmt.opcode == INSTR_GOTO ||
                     stmt.opcode == INSTR_IF ||
                     stmt.opcode == INSTR_IFNOT ||
                 if (stmt.opcode == INSTR_GOTO ||
                     stmt.opcode == INSTR_IF ||
                     stmt.opcode == INSTR_IFNOT ||
@@ -3079,14 +3026,14 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
                 }
                 /* may have been generated in the previous recursive call */
                 stmt.opcode = INSTR_GOTO;
                 }
                 /* may have been generated in the previous recursive call */
                 stmt.opcode = INSTR_GOTO;
-                stmt.o1.s1 = (onfalse->code_start) - vec_size(code->statements);
+                stmt.o1.s1 = onfalse->code_start - code->statements.size();
                 stmt.o2.s1 = 0;
                 stmt.o3.s1 = 0;
                 if (stmt.o1.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
                 return true;
             }
                 stmt.o2.s1 = 0;
                 stmt.o3.s1 = 0;
                 if (stmt.o1.s1 != 1)
                     code_push_statement(code, &stmt, instr->context);
                 return true;
             }
-            else if (stidx+2 == vec_size(code->statements) && code->statements[stidx].o2.s1 == 1) {
+            else if (stidx+2 == code->statements.size() && code->statements[stidx].o2.s1 == 1) {
                 code->statements[stidx] = code->statements[stidx+1];
                 if (code->statements[stidx].o1.s1 < 0)
                     code->statements[stidx].o1.s1++;
                 code->statements[stidx] = code->statements[stidx+1];
                 if (code->statements[stidx].o1.s1 < 0)
                     code->statements[stidx].o1.s1++;
@@ -3102,7 +3049,7 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
             size_t p, first;
             ir_value *retvalue;
 
             size_t p, first;
             ir_value *retvalue;
 
-            first = vec_size(instr->params);
+            first = instr->params.size();
             if (first > 8)
                 first = 8;
             for (p = 0; p < first; ++p)
             if (first > 8)
                 first = 8;
             for (p = 0; p < first; ++p)
@@ -3139,7 +3086,7 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
                     code_push_statement(code, &stmt, instr->context);
             }
             /* Now handle extparams */
                     code_push_statement(code, &stmt, instr->context);
             }
             /* Now handle extparams */
-            first = vec_size(instr->params);
+            first = instr->params.size();
             for (; p < first; ++p)
             {
                 ir_builder *ir = func->owner;
             for (; p < first; ++p)
             {
                 ir_builder *ir = func->owner;
@@ -3181,7 +3128,7 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc
                     code_push_statement(code, &stmt, instr->context);
             }
 
                     code_push_statement(code, &stmt, instr->context);
             }
 
-            stmt.opcode = INSTR_CALL0 + vec_size(instr->params);
+            stmt.opcode = INSTR_CALL0 + instr->params.size();
             if (stmt.opcode > INSTR_CALL8)
                 stmt.opcode = INSTR_CALL8;
             stmt.o1.u1 = ir_value_code_addr(instr->_ops[1]);
             if (stmt.opcode > INSTR_CALL8)
                 stmt.opcode = INSTR_CALL8;
             stmt.o1.u1 = ir_value_code_addr(instr->_ops[1]);
@@ -3284,7 +3231,7 @@ static bool gen_function_code(code_t *code, ir_function *self)
     }
 
     /* code_write and qcvm -disasm need to know that the function ends here */
     }
 
     /* code_write and qcvm -disasm need to know that the function ends here */
-    retst = &vec_last(code->statements);
+    retst = &code->statements.back();
     if (OPTS_OPTIMIZATION(OPTIM_VOID_RETURN) &&
         self->outtype == TYPE_VOID &&
         retst->opcode == INSTR_RETURN &&
     if (OPTS_OPTIMIZATION(OPTIM_VOID_RETURN) &&
         self->outtype == TYPE_VOID &&
         retst->opcode == INSTR_RETURN &&
@@ -3299,8 +3246,8 @@ static bool gen_function_code(code_t *code, ir_function *self)
         stmt.o1.u1  = 0;
         stmt.o2.u1  = 0;
         stmt.o3.u1  = 0;
         stmt.o1.u1  = 0;
         stmt.o2.u1  = 0;
         stmt.o3.u1  = 0;
-        last.line   = vec_last(code->linenums);
-        last.column = vec_last(code->columnnums);
+        last.line   = code->linenums.back();
+        last.column = code->columnnums.back();
 
         code_push_statement(code, &stmt, last);
     }
 
         code_push_statement(code, &stmt, last);
     }
@@ -3333,22 +3280,20 @@ static bool gen_global_function(ir_builder *ir, ir_value *global)
 
     size_t i;
 
 
     size_t i;
 
-    if (!global->hasvalue || (!global->constval.vfunc))
-    {
+    if (!global->hasvalue || (!global->constval.vfunc)) {
         irerror(global->context, "Invalid state of function-global: not constant: %s", global->name);
         return false;
     }
 
     irfun = global->constval.vfunc;
         irerror(global->context, "Invalid state of function-global: not constant: %s", global->name);
         return false;
     }
 
     irfun = global->constval.vfunc;
-
-    fun.name    = global->code.name;
-    fun.file    = ir_builder_filestring(ir, global->context.file);
+    fun.name = global->code.name;
+    fun.file = ir_builder_filestring(ir, global->context.file);
     fun.profile = 0; /* always 0 */
     fun.profile = 0; /* always 0 */
-    fun.nargs   = vec_size(irfun->params);
+    fun.nargs = vec_size(irfun->params);
     if (fun.nargs > 8)
         fun.nargs = 8;
 
     if (fun.nargs > 8)
         fun.nargs = 8;
 
-    for (i = 0;i < 8; ++i) {
+    for (i = 0; i < 8; ++i) {
         if ((int32_t)i >= fun.nargs)
             fun.argsize[i] = 0;
         else
         if ((int32_t)i >= fun.nargs)
             fun.argsize[i] = 0;
         else
@@ -3356,16 +3301,16 @@ static bool gen_global_function(ir_builder *ir, ir_value *global)
     }
 
     fun.firstlocal = 0;
     }
 
     fun.firstlocal = 0;
-    fun.locals     = irfun->allocated_locals;
+    fun.locals = irfun->allocated_locals;
 
     if (irfun->builtin)
         fun.entry = irfun->builtin+1;
     else {
 
     if (irfun->builtin)
         fun.entry = irfun->builtin+1;
     else {
-        irfun->code_function_def = vec_size(ir->code->functions);
-        fun.entry                = vec_size(ir->code->statements);
+        irfun->code_function_def = ir->code->functions.size();
+        fun.entry = ir->code->statements.size();
     }
 
     }
 
-    vec_push(ir->code->functions, fun);
+    ir->code->functions.push_back(fun);
     return true;
 }
 
     return true;
 }
 
@@ -3391,17 +3336,17 @@ static void ir_gen_extparam(ir_builder *ir)
     else
         global = ir->extparam_protos[vec_size(ir->extparams)];
 
     else
         global = ir->extparam_protos[vec_size(ir->extparams)];
 
-    def.name   = code_genstring(ir->code, global->name);
-    def.type   = TYPE_VECTOR;
-    def.offset = vec_size(ir->code->globals);
+    def.name = code_genstring(ir->code, global->name);
+    def.type = TYPE_VECTOR;
+    def.offset = ir->code->globals.size();
 
 
-    vec_push(ir->code->defs, def);
+    ir->code->defs.push_back(def);
 
     ir_value_code_setaddr(global, def.offset);
 
 
     ir_value_code_setaddr(global, def.offset);
 
-    vec_push(ir->code->globals, 0);
-    vec_push(ir->code->globals, 0);
-    vec_push(ir->code->globals, 0);
+    ir->code->globals.push_back(0);
+    ir->code->globals.push_back(0);
+    ir->code->globals.push_back(0);
 
     vec_push(ir->extparams, global);
 }
 
     vec_push(ir->extparams, global);
 }
@@ -3485,13 +3430,13 @@ static bool gen_function_locals(ir_builder *ir, ir_value *global)
     uint32_t                 firstlocal, firstglobal;
 
     irfun = global->constval.vfunc;
     uint32_t                 firstlocal, firstglobal;
 
     irfun = global->constval.vfunc;
-    def   = ir->code->functions + irfun->code_function_def;
+    def   = &ir->code->functions[0] + irfun->code_function_def;
 
     if (OPTS_OPTION_BOOL(OPTION_G) ||
         !OPTS_OPTIMIZATION(OPTIM_OVERLAP_LOCALS)        ||
         (irfun->flags & IR_FLAG_MASK_NO_OVERLAP))
     {
 
     if (OPTS_OPTION_BOOL(OPTION_G) ||
         !OPTS_OPTIMIZATION(OPTIM_OVERLAP_LOCALS)        ||
         (irfun->flags & IR_FLAG_MASK_NO_OVERLAP))
     {
-        firstlocal = def->firstlocal = vec_size(ir->code->globals);
+        firstlocal = def->firstlocal = ir->code->globals.size();
     } else {
         firstlocal = def->firstlocal = ir->first_common_local;
         ++opts_optimizationcount[OPTIM_OVERLAP_LOCALS];
     } else {
         firstlocal = def->firstlocal = ir->first_common_local;
         ++opts_optimizationcount[OPTIM_OVERLAP_LOCALS];
@@ -3499,8 +3444,8 @@ static bool gen_function_locals(ir_builder *ir, ir_value *global)
 
     firstglobal = (OPTS_OPTIMIZATION(OPTIM_GLOBAL_TEMPS) ? ir->first_common_globaltemp : firstlocal);
 
 
     firstglobal = (OPTS_OPTIMIZATION(OPTIM_GLOBAL_TEMPS) ? ir->first_common_globaltemp : firstlocal);
 
-    for (i = vec_size(ir->code->globals); i < firstlocal + irfun->allocated_locals; ++i)
-        vec_push(ir->code->globals, 0);
+    for (i = ir->code->globals.size(); i < firstlocal + irfun->allocated_locals; ++i)
+        ir->code->globals.push_back(0);
     for (i = 0; i < vec_size(irfun->locals); ++i) {
         ir_value *v = irfun->locals[i];
         if (v->locked || !OPTS_OPTIMIZATION(OPTIM_GLOBAL_TEMPS)) {
     for (i = 0; i < vec_size(irfun->locals); ++i) {
         ir_value *v = irfun->locals[i];
         if (v->locked || !OPTS_OPTIMIZATION(OPTIM_GLOBAL_TEMPS)) {
@@ -3568,7 +3513,7 @@ static bool gen_global_function_code(ir_builder *ir, ir_value *global)
     }
     fundef = &ir->code->functions[irfun->code_function_def];
 
     }
     fundef = &ir->code->functions[irfun->code_function_def];
 
-    fundef->entry = vec_size(ir->code->statements);
+    fundef->entry = ir->code->statements.size();
     if (!gen_function_locals(ir, global)) {
         irerror(irfun->context, "Failed to generate locals for function %s", irfun->name);
         return false;
     if (!gen_function_locals(ir, global)) {
         irerror(irfun->context, "Failed to generate locals for function %s", irfun->name);
         return false;
@@ -3610,7 +3555,7 @@ static void gen_vector_defs(code_t *code, prog_section_def_t def, const char *na
 
     for (i = 0; i < 3; ++i) {
         def.name = code_genstring(code, component);
 
     for (i = 0; i < 3; ++i) {
         def.name = code_genstring(code, component);
-        vec_push(code->defs, def);
+        code->defs.push_back(def);
         def.offset++;
         component[len-1]++;
     }
         def.offset++;
         component[len-1]++;
     }
@@ -3640,7 +3585,7 @@ static void gen_vector_fields(code_t *code, prog_section_field_t fld, const char
 
     for (i = 0; i < 3; ++i) {
         fld.name = code_genstring(code, component);
 
     for (i = 0; i < 3; ++i) {
         fld.name = code_genstring(code, component);
-        vec_push(code->fields, fld);
+        code->fields.push_back(fld);
         fld.offset++;
         component[len-1]++;
     }
         fld.offset++;
         component[len-1]++;
     }
@@ -3659,9 +3604,9 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
     if (global->vtype == TYPE_VECTOR && (global->flags & IR_FLAG_SPLIT_VECTOR))
         return true;
 
     if (global->vtype == TYPE_VECTOR && (global->flags & IR_FLAG_SPLIT_VECTOR))
         return true;
 
-    def.type   = global->vtype;
-    def.offset = vec_size(self->code->globals);
-    def.name   = 0;
+    def.type = global->vtype;
+    def.offset = self->code->globals.size();
+    def.name = 0;
     if (OPTS_OPTION_BOOL(OPTION_G) || !islocal)
     {
         pushdef = true;
     if (OPTS_OPTION_BOOL(OPTION_G) || !islocal)
     {
         pushdef = true;
@@ -3670,7 +3615,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
          * if we're eraseable and the function isn't referenced ignore outputting
          * the function.
          */
          * if we're eraseable and the function isn't referenced ignore outputting
          * the function.
          */
-        if (global->flags & IR_FLAG_ERASABLE && vec_size(global->reads) == 0) {
+        if (global->flags & IR_FLAG_ERASABLE && global->reads.empty()) {
             return true;
         }
 
             return true;
         }
 
@@ -3694,7 +3639,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
             def.name   = 0;
         if (islocal) {
             def.offset = ir_value_code_addr(global);
             def.name   = 0;
         if (islocal) {
             def.offset = ir_value_code_addr(global);
-            vec_push(self->code->defs, def);
+            self->code->defs.push_back(def);
             if (global->vtype == TYPE_VECTOR)
                 gen_vector_defs(self->code, def, global->name);
             else if (global->vtype == TYPE_FIELD && global->fieldtype == TYPE_VECTOR)
             if (global->vtype == TYPE_VECTOR)
                 gen_vector_defs(self->code, def, global->name);
             else if (global->vtype == TYPE_FIELD && global->fieldtype == TYPE_VECTOR)
@@ -3728,17 +3673,17 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
          * Maybe this could be an -foption
          * fteqcc creates data for end_sys_* - of size 1, so let's do the same
          */
          * Maybe this could be an -foption
          * fteqcc creates data for end_sys_* - of size 1, so let's do the same
          */
-        ir_value_code_setaddr(global, vec_size(self->code->globals));
-        vec_push(self->code->globals, 0);
+        ir_value_code_setaddr(global, self->code->globals.size());
+        self->code->globals.push_back(0);
         /* Add the def */
         /* Add the def */
-        if (pushdef) vec_push(self->code->defs, def);
+        if (pushdef) self->code->defs.push_back(def);
         return true;
     case TYPE_POINTER:
         return true;
     case TYPE_POINTER:
-        if (pushdef) vec_push(self->code->defs, def);
+        if (pushdef) self->code->defs.push_back(def);
         return gen_global_pointer(self->code, global);
     case TYPE_FIELD:
         if (pushdef) {
         return gen_global_pointer(self->code, global);
     case TYPE_FIELD:
         if (pushdef) {
-            vec_push(self->code->defs, def);
+            self->code->defs.push_back(def);
             if (global->fieldtype == TYPE_VECTOR)
                 gen_vector_defs(self->code, def, global->name);
         }
             if (global->fieldtype == TYPE_VECTOR)
                 gen_vector_defs(self->code, def, global->name);
         }
@@ -3747,84 +3692,84 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
         /* fall through */
     case TYPE_FLOAT:
     {
         /* fall through */
     case TYPE_FLOAT:
     {
-        ir_value_code_setaddr(global, vec_size(self->code->globals));
+        ir_value_code_setaddr(global, self->code->globals.size());
         if (global->hasvalue) {
             iptr = (int32_t*)&global->constval.ivec[0];
         if (global->hasvalue) {
             iptr = (int32_t*)&global->constval.ivec[0];
-            vec_push(self->code->globals, *iptr);
+            self->code->globals.push_back(*iptr);
         } else {
         } else {
-            vec_push(self->code->globals, 0);
+            self->code->globals.push_back(0);
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
-        if (pushdef) vec_push(self->code->defs, def);
+        if (pushdef) self->code->defs.push_back(def);
 
         return global->code.globaladdr >= 0;
     }
     case TYPE_STRING:
     {
 
         return global->code.globaladdr >= 0;
     }
     case TYPE_STRING:
     {
-        ir_value_code_setaddr(global, vec_size(self->code->globals));
+        ir_value_code_setaddr(global, self->code->globals.size());
         if (global->hasvalue) {
             uint32_t load = code_genstring(self->code, global->constval.vstring);
         if (global->hasvalue) {
             uint32_t load = code_genstring(self->code, global->constval.vstring);
-            vec_push(self->code->globals, load);
+            self->code->globals.push_back(load);
         } else {
         } else {
-            vec_push(self->code->globals, 0);
+            self->code->globals.push_back(0);
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
-        if (pushdef) vec_push(self->code->defs, def);
+        if (pushdef) self->code->defs.push_back(def);
         return global->code.globaladdr >= 0;
     }
     case TYPE_VECTOR:
     {
         size_t d;
         return global->code.globaladdr >= 0;
     }
     case TYPE_VECTOR:
     {
         size_t d;
-        ir_value_code_setaddr(global, vec_size(self->code->globals));
+        ir_value_code_setaddr(global, self->code->globals.size());
         if (global->hasvalue) {
             iptr = (int32_t*)&global->constval.ivec[0];
         if (global->hasvalue) {
             iptr = (int32_t*)&global->constval.ivec[0];
-            vec_push(self->code->globals, iptr[0]);
+            self->code->globals.push_back(iptr[0]);
             if (global->code.globaladdr < 0)
                 return false;
             for (d = 1; d < type_sizeof_[global->vtype]; ++d) {
             if (global->code.globaladdr < 0)
                 return false;
             for (d = 1; d < type_sizeof_[global->vtype]; ++d) {
-                vec_push(self->code->globals, iptr[d]);
+                self->code->globals.push_back(iptr[d]);
             }
         } else {
             }
         } else {
-            vec_push(self->code->globals, 0);
+            self->code->globals.push_back(0);
             if (global->code.globaladdr < 0)
                 return false;
             for (d = 1; d < type_sizeof_[global->vtype]; ++d) {
             if (global->code.globaladdr < 0)
                 return false;
             for (d = 1; d < type_sizeof_[global->vtype]; ++d) {
-                vec_push(self->code->globals, 0);
+                self->code->globals.push_back(0);
             }
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
 
         if (pushdef) {
             }
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
 
         if (pushdef) {
-            vec_push(self->code->defs, def);
+            self->code->defs.push_back(def);
             def.type &= ~DEF_SAVEGLOBAL;
             gen_vector_defs(self->code, def, global->name);
         }
         return global->code.globaladdr >= 0;
     }
     case TYPE_FUNCTION:
             def.type &= ~DEF_SAVEGLOBAL;
             gen_vector_defs(self->code, def, global->name);
         }
         return global->code.globaladdr >= 0;
     }
     case TYPE_FUNCTION:
-        ir_value_code_setaddr(global, vec_size(self->code->globals));
+        ir_value_code_setaddr(global, self->code->globals.size());
         if (!global->hasvalue) {
         if (!global->hasvalue) {
-            vec_push(self->code->globals, 0);
+            self->code->globals.push_back(0);
             if (global->code.globaladdr < 0)
                 return false;
         } else {
             if (global->code.globaladdr < 0)
                 return false;
         } else {
-            vec_push(self->code->globals, vec_size(self->code->functions));
+            self->code->globals.push_back(self->code->functions.size());
             if (!gen_global_function(self, global))
                 return false;
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
             if (!gen_global_function(self, global))
                 return false;
         }
         if (!islocal && global->cvq != CV_CONST)
             def.type |= DEF_SAVEGLOBAL;
-        if (pushdef) vec_push(self->code->defs, def);
+        if (pushdef) self->code->defs.push_back(def);
         return true;
     case TYPE_VARIANT:
         /* assume biggest type */
         return true;
     case TYPE_VARIANT:
         /* assume biggest type */
-            ir_value_code_setaddr(global, vec_size(self->code->globals));
-            vec_push(self->code->globals, 0);
+            ir_value_code_setaddr(global, self->code->globals.size());
+            self->code->globals.push_back(0);
             for (i = 1; i < type_sizeof_[TYPE_VARIANT]; ++i)
             for (i = 1; i < type_sizeof_[TYPE_VARIANT]; ++i)
-                vec_push(self->code->globals, 0);
+                self->code->globals.push_back(0);
             return true;
     default:
         /* refuse to create 'void' type or any other fancy business. */
             return true;
     default:
         /* refuse to create 'void' type or any other fancy business. */
@@ -3847,7 +3792,7 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
     (void)self;
 
     def.type   = (uint16_t)field->vtype;
     (void)self;
 
     def.type   = (uint16_t)field->vtype;
-    def.offset = (uint16_t)vec_size(self->code->globals);
+    def.offset = (uint16_t)self->code->globals.size();
 
     /* create a global named the same as the field */
     if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
 
     /* create a global named the same as the field */
     if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
@@ -3881,7 +3826,7 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
 
     field->code.name = def.name;
 
 
     field->code.name = def.name;
 
-    vec_push(self->code->defs, def);
+    self->code->defs.push_back(def);
 
     fld.type = field->fieldtype;
 
 
     fld.type = field->fieldtype;
 
@@ -3892,13 +3837,13 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
 
     fld.offset = field->code.fieldaddr;
 
 
     fld.offset = field->code.fieldaddr;
 
-    vec_push(self->code->fields, fld);
+    self->code->fields.push_back(fld);
 
 
-    ir_value_code_setaddr(field, vec_size(self->code->globals));
-    vec_push(self->code->globals, fld.offset);
+    ir_value_code_setaddr(field, self->code->globals.size());
+    self->code->globals.push_back(fld.offset);
     if (fld.type == TYPE_VECTOR) {
     if (fld.type == TYPE_VECTOR) {
-        vec_push(self->code->globals, fld.offset+1);
-        vec_push(self->code->globals, fld.offset+2);
+        self->code->globals.push_back(fld.offset+1);
+        self->code->globals.push_back(fld.offset+2);
     }
 
     if (field->fieldtype == TYPE_VECTOR) {
     }
 
     if (field->fieldtype == TYPE_VECTOR) {
@@ -3911,7 +3856,7 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
 
 static void ir_builder_collect_reusables(ir_builder *builder) {
     size_t i;
 
 static void ir_builder_collect_reusables(ir_builder *builder) {
     size_t i;
-    ir_value **reusables = NULL;
+    ir_value **reusables = nullptr;
     for (i = 0; i < vec_size(builder->globals); ++i) {
         ir_value *value = builder->globals[i];
         if (value->vtype != TYPE_FLOAT || !value->hasvalue)
     for (i = 0; i < vec_size(builder->globals); ++i) {
         ir_value *value = builder->globals[i];
         if (value->vtype != TYPE_FLOAT || !value->hasvalue)
@@ -3925,16 +3870,16 @@ static void ir_builder_collect_reusables(ir_builder *builder) {
 
 static void ir_builder_split_vector(ir_builder *self, ir_value *vec) {
     size_t i, count;
 
 static void ir_builder_split_vector(ir_builder *self, ir_value *vec) {
     size_t i, count;
-    ir_value* found[3] = { NULL, NULL, NULL };
+    ir_value* found[3] = { nullptr, nullptr, nullptr };
 
     /* must not be written to */
 
     /* must not be written to */
-    if (vec_size(vec->writes))
+    if (vec->writes.size())
         return;
     /* must not be trying to access individual members */
     if (vec->members[0] || vec->members[1] || vec->members[2])
         return;
     /* should be actually used otherwise it won't be generated anyway */
         return;
     /* must not be trying to access individual members */
     if (vec->members[0] || vec->members[1] || vec->members[2])
         return;
     /* should be actually used otherwise it won't be generated anyway */
-    count = vec_size(vec->reads);
+    count = vec->reads.size();
     if (!count)
         return;
 
     if (!count)
         return;
 
@@ -3986,11 +3931,11 @@ static void ir_builder_split_vector(ir_builder *self, ir_value *vec) {
     vec->members[2] = found[2];
 
     /* register the readers for these floats */
     vec->members[2] = found[2];
 
     /* register the readers for these floats */
-    count = vec_size(vec->reads);
+    count = vec->reads.size();
     for (i = 0; i != count; ++i) {
     for (i = 0; i != count; ++i) {
-        vec_push(found[0]->reads, vec->reads[i]);
-        vec_push(found[1]->reads, vec->reads[i]);
-        vec_push(found[2]->reads, vec->reads[i]);
+        found[0]->reads.push_back(vec->reads[i]);
+        found[1]->reads.push_back(vec->reads[i]);
+        found[2]->reads.push_back(vec->reads[i]);
     }
 }
 
     }
 }
 
@@ -4008,7 +3953,7 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
 {
     prog_section_statement_t stmt;
     size_t i;
 {
     prog_section_statement_t stmt;
     size_t i;
-    char  *lnofile = NULL;
+    char  *lnofile = nullptr;
 
     if (OPTS_FLAG(SPLIT_VECTOR_PARAMETERS)) {
         ir_builder_collect_reusables(self);
 
     if (OPTS_FLAG(SPLIT_VECTOR_PARAMETERS)) {
         ir_builder_collect_reusables(self);
@@ -4046,28 +3991,28 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
     }
 
     /* generate nil */
     }
 
     /* generate nil */
-    ir_value_code_setaddr(self->nil, vec_size(self->code->globals));
-    vec_push(self->code->globals, 0);
-    vec_push(self->code->globals, 0);
-    vec_push(self->code->globals, 0);
+    ir_value_code_setaddr(self->nil, self->code->globals.size());
+    self->code->globals.push_back(0);
+    self->code->globals.push_back(0);
+    self->code->globals.push_back(0);
 
     /* generate virtual-instruction temps */
     for (i = 0; i < IR_MAX_VINSTR_TEMPS; ++i) {
 
     /* generate virtual-instruction temps */
     for (i = 0; i < IR_MAX_VINSTR_TEMPS; ++i) {
-        ir_value_code_setaddr(self->vinstr_temp[i], vec_size(self->code->globals));
-        vec_push(self->code->globals, 0);
-        vec_push(self->code->globals, 0);
-        vec_push(self->code->globals, 0);
+        ir_value_code_setaddr(self->vinstr_temp[i], self->code->globals.size());
+        self->code->globals.push_back(0);
+        self->code->globals.push_back(0);
+        self->code->globals.push_back(0);
     }
 
     /* generate global temps */
     }
 
     /* generate global temps */
-    self->first_common_globaltemp = vec_size(self->code->globals);
+    self->first_common_globaltemp = self->code->globals.size();
     for (i = 0; i < self->max_globaltemps; ++i) {
     for (i = 0; i < self->max_globaltemps; ++i) {
-        vec_push(self->code->globals, 0);
+        self->code->globals.push_back(0);
     }
     /* generate common locals */
     }
     /* generate common locals */
-    self->first_common_local = vec_size(self->code->globals);
+    self->first_common_local = self->code->globals.size();
     for (i = 0; i < self->max_locals; ++i) {
     for (i = 0; i < self->max_locals; ++i) {
-        vec_push(self->code->globals, 0);
+        self->code->globals.push_back(0);
     }
 
     /* generate function code */
     }
 
     /* generate function code */
@@ -4080,13 +4025,15 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
         }
     }
 
         }
     }
 
-    if (vec_size(self->code->globals) >= 65536) {
-        irerror(vec_last(self->globals)->context, "This progs file would require more globals than the metadata can handle (%u). Bailing out.", (unsigned int)vec_size(self->code->globals));
+    if (self->code->globals.size() >= 65536) {
+        irerror(vec_last(self->globals)->context,
+            "This progs file would require more globals than the metadata can handle (%zu). Bailing out.",
+            self->code->globals.size());
         return false;
     }
 
     /* DP errors if the last instruction is not an INSTR_DONE. */
         return false;
     }
 
     /* DP errors if the last instruction is not an INSTR_DONE. */
-    if (vec_last(self->code->statements).opcode != INSTR_DONE)
+    if (self->code->statements.back().opcode != INSTR_DONE)
     {
         lex_ctx_t last;
 
     {
         lex_ctx_t last;
 
@@ -4094,8 +4041,8 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
         stmt.o1.u1  = 0;
         stmt.o2.u1  = 0;
         stmt.o3.u1  = 0;
         stmt.o1.u1  = 0;
         stmt.o2.u1  = 0;
         stmt.o3.u1  = 0;
-        last.line   = vec_last(self->code->linenums);
-        last.column = vec_last(self->code->columnnums);
+        last.line   = self->code->linenums.back();
+        last.column = self->code->columnnums.back();
 
         code_push_statement(self->code, &stmt, last);
     }
 
         code_push_statement(self->code, &stmt, last);
     }
@@ -4103,10 +4050,10 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
     if (OPTS_OPTION_BOOL(OPTION_PP_ONLY))
         return true;
 
     if (OPTS_OPTION_BOOL(OPTION_PP_ONLY))
         return true;
 
-    if (vec_size(self->code->statements) != vec_size(self->code->linenums)) {
+    if (self->code->statements.size() != self->code->linenums.size()) {
         con_err("Linecounter wrong: %lu != %lu\n",
         con_err("Linecounter wrong: %lu != %lu\n",
-                (unsigned long)vec_size(self->code->statements),
-                (unsigned long)vec_size(self->code->linenums));
+                self->code->statements.size(),
+                self->code->linenums.size());
     } else if (OPTS_FLAG(LNO)) {
         char  *dot;
         size_t filelen = strlen(filename);
     } else if (OPTS_FLAG(LNO)) {
         char  *dot;
         size_t filelen = strlen(filename);
@@ -4301,12 +4248,10 @@ void ir_block_dump(ir_block* b, char *ind,
 
 static void dump_phi(ir_instr *in, int (*oprintf)(const char*, ...))
 {
 
 static void dump_phi(ir_instr *in, int (*oprintf)(const char*, ...))
 {
-    size_t i;
     oprintf("%s <- phi ", in->_ops[0]->name);
     oprintf("%s <- phi ", in->_ops[0]->name);
-    for (i = 0; i < vec_size(in->phi); ++i)
-    {
-        oprintf("([%s] : %s) ", in->phi[i].from->label,
-                                in->phi[i].value->name);
+    for (auto &it : in->phi) {
+        oprintf("([%s] : %s) ", it.from->label,
+                                it.value->name);
     }
     oprintf("\n");
 }
     }
     oprintf("\n");
 }
@@ -4315,7 +4260,7 @@ void ir_instr_dump(ir_instr *in, char *ind,
                        int (*oprintf)(const char*, ...))
 {
     size_t i;
                        int (*oprintf)(const char*, ...))
 {
     size_t i;
-    const char *comma = NULL;
+    const char *comma = nullptr;
 
     oprintf("%s (%i) ", ind, (int)in->eid);
 
 
     oprintf("%s (%i) ", ind, (int)in->eid);
 
@@ -4332,7 +4277,7 @@ void ir_instr_dump(ir_instr *in, char *ind,
             oprintf(" <- ");
     }
     if (in->opcode == INSTR_CALL0 || in->opcode == VINSTR_NRCALL) {
             oprintf(" <- ");
     }
     if (in->opcode == INSTR_CALL0 || in->opcode == VINSTR_NRCALL) {
-        oprintf("CALL%i\t", vec_size(in->params));
+        oprintf("CALL%i\t", in->params.size());
     } else
         oprintf("%s\t", qc_opname(in->opcode));
 
     } else
         oprintf("%s\t", qc_opname(in->opcode));
 
@@ -4359,11 +4304,10 @@ void ir_instr_dump(ir_instr *in, char *ind,
     }
     if (in->bops[1])
         oprintf("%s[%s]", comma, in->bops[1]->label);
     }
     if (in->bops[1])
         oprintf("%s[%s]", comma, in->bops[1]->label);
-    if (vec_size(in->params)) {
+    if (in->params.size()) {
         oprintf("\tparams: ");
         oprintf("\tparams: ");
-        for (i = 0; i != vec_size(in->params); ++i) {
-            oprintf("%s, ", in->params[i]->name);
-        }
+        for (auto &it : in->params)
+            oprintf("%s, ", it->name);
     }
     oprintf("\n");
     ind[strlen(ind)-1] = 0;
     }
     oprintf("\n");
     ind[strlen(ind)-1] = 0;