]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.c
added --nocolor and fixed bug
[xonotic/gmqcc.git] / ir.c
diff --git a/ir.c b/ir.c
index c792b24184980544f3dabe76f0d404ee55443233..4ae49d93968cd638f9c0328ecaae895811cf1f81 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -38,10 +38,11 @@ const char *type_name[TYPE_COUNT] = {
     "field",
     "function",
     "pointer",
-#if 0
     "integer",
-#endif
-    "variant"
+    "variant",
+    "struct",
+    "union",
+    "array"
 };
 
 size_t type_sizeof[TYPE_COUNT] = {
@@ -53,10 +54,11 @@ size_t type_sizeof[TYPE_COUNT] = {
     1, /* TYPE_FIELD    */
     1, /* TYPE_FUNCTION */
     1, /* TYPE_POINTER  */
-#if 0
     1, /* TYPE_INTEGER  */
-#endif
     3, /* TYPE_VARIANT  */
+    0, /* TYPE_STRUCT   */
+    0, /* TYPE_UNION    */
+    0, /* TYPE_ARRAY    */
 };
 
 uint16_t type_store_instr[TYPE_COUNT] = {
@@ -70,9 +72,37 @@ uint16_t type_store_instr[TYPE_COUNT] = {
     INSTR_STORE_ENT, /* should use I */
 #if 0
     INSTR_STORE_I, /* integer type */
+#else
+    INSTR_STORE_F,
 #endif
 
     INSTR_STORE_V, /* variant, should never be accessed */
+
+    AINSTR_END, /* struct */
+    AINSTR_END, /* union  */
+    AINSTR_END, /* array  */
+};
+
+uint16_t field_store_instr[TYPE_COUNT] = {
+    INSTR_STORE_FLD,
+    INSTR_STORE_FLD,
+    INSTR_STORE_FLD,
+    INSTR_STORE_V,
+    INSTR_STORE_FLD,
+    INSTR_STORE_FLD,
+    INSTR_STORE_FLD,
+    INSTR_STORE_FLD,
+#if 0
+    INSTR_STORE_FLD, /* integer type */
+#else
+    INSTR_STORE_FLD,
+#endif
+
+    INSTR_STORE_V, /* variant, should never be accessed */
+
+    AINSTR_END, /* struct */
+    AINSTR_END, /* union  */
+    AINSTR_END, /* array  */
 };
 
 uint16_t type_storep_instr[TYPE_COUNT] = {
@@ -86,9 +116,15 @@ uint16_t type_storep_instr[TYPE_COUNT] = {
     INSTR_STOREP_ENT, /* should use I */
 #if 0
     INSTR_STOREP_ENT, /* integer type */
+#else
+    INSTR_STOREP_F,
 #endif
 
     INSTR_STOREP_V, /* variant, should never be accessed */
+
+    AINSTR_END, /* struct */
+    AINSTR_END, /* union  */
+    AINSTR_END, /* array  */
 };
 
 uint16_t type_eq_instr[TYPE_COUNT] = {
@@ -102,9 +138,15 @@ uint16_t type_eq_instr[TYPE_COUNT] = {
     INSTR_EQ_E, /* should use I */
 #if 0
     INSTR_EQ_I,
+#else
+    INSTR_EQ_F,
 #endif
 
     INSTR_EQ_V, /* variant, should never be accessed */
+
+    AINSTR_END, /* struct */
+    AINSTR_END, /* union  */
+    AINSTR_END, /* array  */
 };
 
 uint16_t type_ne_instr[TYPE_COUNT] = {
@@ -118,9 +160,15 @@ uint16_t type_ne_instr[TYPE_COUNT] = {
     INSTR_NE_E, /* should use I */
 #if 0
     INSTR_NE_I,
+#else
+    INSTR_NE_F,
 #endif
 
     INSTR_NE_V, /* variant, should never be accessed */
+
+    AINSTR_END, /* struct */
+    AINSTR_END, /* union  */
+    AINSTR_END, /* array  */
 };
 
 MEM_VEC_FUNCTIONS(ir_value_vector, ir_value*, v)
@@ -129,7 +177,7 @@ static void irerror(lex_ctx ctx, const char *msg, ...)
 {
     va_list ap;
     va_start(ap, msg);
-    cvprintmsg(ctx, LVL_ERROR, "internal error", msg, ap);
+    con_cvprintmsg((void*)&ctx, LVL_ERROR, "internal error", msg, ap);
     va_end(ap);
 }
 
@@ -145,7 +193,7 @@ static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
            lvl = LVL_ERROR;
 
        va_start(ap, fmt);
-    vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
+    con_vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
        va_end(ap);
 
        return opts_werror;
@@ -1545,6 +1593,7 @@ ir_value* ir_block_create_load_from_ent(ir_block *self, const char *label, ir_va
         case TYPE_INTEGER: op = INSTR_LOAD_I;   break;
 #endif
         default:
+            irerror(self->context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
             return NULL;
     }
 
@@ -1561,6 +1610,7 @@ ir_value* ir_block_create_add(ir_block *self,
     if (l == r) {
         switch (l) {
             default:
+                irerror(self->context, "invalid type for ir_block_create_add: %s", type_name[l]);
                 return NULL;
             case TYPE_FLOAT:
                 op = INSTR_ADD_F;
@@ -1582,7 +1632,10 @@ ir_value* ir_block_create_add(ir_block *self,
             op = INSTR_ADD_IF;
         else
 #endif
+        {
+            irerror(self->context, "invalid type for ir_block_create_add: %s", type_name[l]);
             return NULL;
+        }
     }
     return ir_block_create_binop(self, label, op, left, right);
 }
@@ -1598,6 +1651,7 @@ ir_value* ir_block_create_sub(ir_block *self,
 
         switch (l) {
             default:
+                irerror(self->context, "invalid type for ir_block_create_sub: %s", type_name[l]);
                 return NULL;
             case TYPE_FLOAT:
                 op = INSTR_SUB_F;
@@ -1619,7 +1673,10 @@ ir_value* ir_block_create_sub(ir_block *self,
             op = INSTR_SUB_IF;
         else
 #endif
+        {
+            irerror(self->context, "invalid type for ir_block_create_sub: %s", type_name[l]);
             return NULL;
+        }
     }
     return ir_block_create_binop(self, label, op, left, right);
 }
@@ -1635,6 +1692,7 @@ ir_value* ir_block_create_mul(ir_block *self,
 
         switch (l) {
             default:
+                irerror(self->context, "invalid type for ir_block_create_mul: %s", type_name[l]);
                 return NULL;
             case TYPE_FLOAT:
                 op = INSTR_MUL_F;
@@ -1663,8 +1721,10 @@ ir_value* ir_block_create_mul(ir_block *self,
         else if ( (l == TYPE_INTEGER && r == TYPE_FLOAT) )
             op = INSTR_MUL_IF;
 #endif
-        else
+        else {
+            irerror(self->context, "invalid type for ir_block_create_mul: %s", type_name[l]);
             return NULL;
+        }
     }
     return ir_block_create_binop(self, label, op, left, right);
 }
@@ -1680,6 +1740,7 @@ ir_value* ir_block_create_div(ir_block *self,
 
         switch (l) {
             default:
+                irerror(self->context, "invalid type for ir_block_create_div: %s", type_name[l]);
                 return NULL;
             case TYPE_FLOAT:
                 op = INSTR_DIV_F;
@@ -1700,7 +1761,10 @@ ir_value* ir_block_create_div(ir_block *self,
             op = INSTR_DIV_IF;
         else
 #endif
+        {
+            irerror(self->context, "invalid type for ir_block_create_div: %s", type_name[l]);
             return NULL;
+        }
     }
     return ir_block_create_binop(self, label, op, left, right);
 }
@@ -2231,7 +2295,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
                      * since this function is run multiple times.
                      */
                     /* For now: debug info: */
-                    /* fprintf(stderr, "Value only written %s\n", value->name); */
+                    /* con_err( "Value only written %s\n", value->name); */
                     tempbool = ir_value_life_merge(value, instr->eid);
                     *changed = *changed || tempbool;
                     /*
@@ -2246,7 +2310,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
                     tempbool = ir_value_life_merge(value, instr->eid);
                     /*
                     if (tempbool)
-                        fprintf(stderr, "value added id %s %i\n", value->name, (int)instr->eid);
+                        con_err( "value added id %s %i\n", value->name, (int)instr->eid);
                     */
                     *changed = *changed || tempbool;
                     /* Then remove */
@@ -2257,7 +2321,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
         }
         /* (A) */
         tempbool = ir_block_living_add_instr(self, instr->eid);
-        /*fprintf(stderr, "living added values\n");*/
+        /*con_err( "living added values\n");*/
         *changed = *changed || tempbool;
 
     }
@@ -2502,7 +2566,10 @@ tailcall:
                 stmt.opcode = INSTR_STORE_F;
                 stmt.o3.u1 = 0;
 
-                stmt.opcode = type_store_instr[param->vtype];
+                if (param->vtype == TYPE_FIELD)
+                    stmt.opcode = field_store_instr[param->fieldtype];
+                else
+                    stmt.opcode = type_store_instr[param->vtype];
                 stmt.o1.u1 = ir_value_code_addr(param);
                 stmt.o2.u1 = OFS_PARM0 + 3 * p;
                 if (code_statements_add(stmt) < 0)
@@ -2521,7 +2588,10 @@ tailcall:
             if (retvalue && retvalue->store != store_return && retvalue->life_count)
             {
                 /* not to be kept in OFS_RETURN */
-                stmt.opcode = type_store_instr[retvalue->vtype];
+                if (retvalue->vtype == TYPE_FIELD)
+                    stmt.opcode = field_store_instr[retvalue->vtype];
+                else
+                    stmt.opcode = type_store_instr[retvalue->vtype];
                 stmt.o1.u1 = OFS_RETURN;
                 stmt.o2.u1 = ir_value_code_addr(retvalue);
                 stmt.o3.u1 = 0;
@@ -2986,8 +3056,6 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
 
 #ifdef WIN32
 # define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE)
-#else
-# define strncat strncat
 #endif
 
 const char *qc_opname(int op)