]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.h
gcc lost it's magic analyzer and now complains about uninitialized stuff... <sadface>
[xonotic/gmqcc.git] / ir.h
diff --git a/ir.h b/ir.h
index eda1fbde866f7289a9d19b82f7cf6553d692fa34..a7f41d0c79f80da57d137305ef09b81a7b317d4f 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -52,11 +52,10 @@ typedef struct ir_value_s {
         float    vfloat;
         int      vint;
         vector   vvec;
+        int32_t  ivec[3];
         char    *vstring;
         struct ir_value_s *vpointer;
         struct ir_function_s *vfunc;
-        quaternion vquat;
-        matrix     vmat;
     } constval;
 
     struct {
@@ -64,12 +63,20 @@ typedef struct ir_value_s {
         int32_t name;
         /* filled by the local-allocator */
         int32_t local;
+        /* added for members */
+        int32_t addroffset;
     } code;
 
+    /* for acessing vectors */
+    struct ir_value_s *members[3];
+    struct ir_value_s *memberof;
+
     /* For the temp allocator */
     MEM_VECTOR_MAKE(ir_life_entry_t, life);
 } ir_value;
 
+int32_t ir_value_code_addr(const ir_value*);
+
 /* ir_value can be a variable, or created by an operation */
 ir_value* ir_value_var(const char *name, int st, int vtype);
 /* if a result of an operation: the function should store
@@ -77,7 +84,8 @@ ir_value* ir_value_var(const char *name, int st, int vtype);
  */
 ir_value* ir_value_out(struct ir_function_s *owner, const char *name, int st, int vtype);
 void      ir_value_delete(ir_value*);
-void      ir_value_set_name(ir_value*, const char *name);
+bool      ir_value_set_name(ir_value*, const char *name);
+ir_value* ir_value_vector_member(ir_value*, unsigned int member);
 
 MEM_VECTOR_PROTO_ALL(ir_value, struct ir_instr_s*, reads);
 MEM_VECTOR_PROTO_ALL(ir_value, struct ir_instr_s*, writes);
@@ -89,10 +97,9 @@ bool GMQCC_WARN ir_value_set_int(ir_value*, int i);
 #endif
 bool GMQCC_WARN ir_value_set_string(ir_value*, const char *s);
 bool GMQCC_WARN ir_value_set_vector(ir_value*, vector v);
+bool GMQCC_WARN ir_value_set_field(ir_value*, ir_value *fld);
 /*bool   ir_value_set_pointer_v(ir_value*, ir_value* p); */
 /*bool   ir_value_set_pointer_i(ir_value*, int i);       */
-bool GMQCC_WARN ir_value_set_quaternion(ir_value*, quaternion v);
-bool GMQCC_WARN ir_value_set_matrix(ir_value*, matrix v);
 
 MEM_VECTOR_PROTO(ir_value, ir_life_entry_t, life);
 /* merge an instruction into the life-range */
@@ -105,7 +112,7 @@ bool ir_value_lives(ir_value*, size_t);
 bool ir_values_overlap(const ir_value*, const ir_value*);
 
 void ir_value_dump(ir_value*, int (*oprintf)(const char*,...));
-void ir_value_dump_life(ir_value *self, int (*oprintf)(const char*,...));
+void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...));
 
 /* A vector of IR values */
 typedef struct {
@@ -255,6 +262,14 @@ typedef struct ir_function_s
 
     lex_ctx       context;
 
+    /* for prototypes - first we generate all the
+     * globals, and we remember teh function-defs
+     * so we can later fill in the entry pos
+     *
+     * remember the ID:
+     */
+    qcint code_function_def;
+
     /* for temp allocation */
     size_t run_id;
 
@@ -290,6 +305,12 @@ typedef struct ir_builder_s
     char *name;
     MEM_VECTOR_MAKE(ir_function*, functions);
     MEM_VECTOR_MAKE(ir_value*, globals);
+    MEM_VECTOR_MAKE(ir_value*, fields);
+
+    MEM_VECTOR_MAKE(const char*, filenames);
+    MEM_VECTOR_MAKE(qcint,       filestrings);
+    /* we cache the #IMMEDIATE string here */
+    qcint str_immediate;
 } ir_builder;
 
 ir_builder* ir_builder_new(const char *modulename);
@@ -298,13 +319,18 @@ void        ir_builder_delete(ir_builder*);
 bool ir_builder_set_name(ir_builder *self, const char *name);
 
 MEM_VECTOR_PROTO(ir_builder, ir_function*, functions);
-MEM_VECTOR_PROTO(ir_builder, ir_value*, globals);
+MEM_VECTOR_PROTO(ir_builder, ir_value*,    globals);
+MEM_VECTOR_PROTO(ir_builder, ir_value*,    fields);
+MEM_VECTOR_PROTO(ir_builder, const char*,  filenames);
+MEM_VECTOR_PROTO(ir_builder, qcint,        filestrings);
 
 ir_function* ir_builder_get_function(ir_builder*, const char *fun);
 ir_function* ir_builder_create_function(ir_builder*, const char *name, int outtype);
 
 ir_value* ir_builder_get_global(ir_builder*, const char *fun);
 ir_value* ir_builder_create_global(ir_builder*, const char *name, int vtype);
+ir_value* ir_builder_get_field(ir_builder*, const char *fun);
+ir_value* ir_builder_create_field(ir_builder*, const char *name, int vtype);
 
 bool ir_builder_generate(ir_builder *self, const char *filename);
 
@@ -312,6 +338,6 @@ void ir_builder_dump(ir_builder*, int (*oprintf)(const char*, ...));
 
 /* This code assumes 32 bit floats while generating binary */
 extern int check_int_and_float_size
-[ (sizeof(int32_t) == sizeof(( (ir_value*)(NULL) )->constval.vvec.x)) ? 1 : -1 ];
+[ (sizeof(int32_t) == sizeof(qcfloat)) ? 1 : -1 ];
 
 #endif