X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ir.h;h=e3b4fbdea62b30dd84809105fb40272f82125da2;hp=7964b74a90bf1bec096d655a94014ab12a99237d;hb=90f190f5e19c1981280eedb37b9439cd9542372d;hpb=90b5a6538a10f60d08ee3059b8f70e4e076dc30d diff --git a/ir.h b/ir.h index 7964b74..e3b4fbd 100644 --- a/ir.h +++ b/ir.h @@ -27,8 +27,8 @@ enum { IR_FLAG_INCLUDE_DEF = 1 << 3, IR_FLAG_ERASABLE = 1 << 4, IR_FLAG_BLOCK_COVERAGE = 1 << 5, - - IR_FLAG_SPLIT_VECTOR = 1 << 6, + IR_FLAG_NOREF = 1 << 6, + IR_FLAG_SPLIT_VECTOR = 1 << 7, IR_FLAG_LAST, IR_FLAG_MASK_NO_OVERLAP = (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED), @@ -37,8 +37,30 @@ enum { struct ir_value { ir_value(std::string&& name, store_type storetype, qc_type vtype); + ir_value(ir_function *owner, std::string&& name, store_type storetype, qc_type vtype); ~ir_value(); + ir_value *vectorMember(unsigned int member); + + bool GMQCC_WARN setFloat(float); + bool GMQCC_WARN setFunc(int); + bool GMQCC_WARN setString(const char*); + bool GMQCC_WARN setVector(vec3_t); + bool GMQCC_WARN setField(ir_value*); +#if 0 + bool GMQCC_WARN setInt(int); +#endif + + bool lives(size_t at); + void dumpLife(int (*oprintf)(const char*, ...)) const; + + void setCodeAddress(int32_t gaddr); + int32_t codeAddress() const; + + bool insertLife(size_t idx, ir_life_entry_t); + bool setAlive(size_t position); + bool mergeLife(const ir_value *other); + std::string m_name; qc_type m_vtype; @@ -81,21 +103,11 @@ struct ir_value { bool m_callparam; std::vector m_life; // For the temp allocator -}; -/* - * ir_value can be a variable, or created by an operation - * if a result of an operation: the function should store - * it to remember to delete it / garbage collect it - */ -ir_value* ir_value_vector_member(ir_value*, unsigned int member); -bool GMQCC_WARN ir_value_set_float(ir_value*, float f); -bool GMQCC_WARN ir_value_set_func(ir_value*, int f); -bool GMQCC_WARN ir_value_set_string(ir_value*, const char *s); -bool GMQCC_WARN ir_value_set_vector(ir_value*, vec3_t v); -bool GMQCC_WARN ir_value_set_field(ir_value*, ir_value *fld); -bool ir_value_lives(ir_value*, size_t); -void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...)); + size_t size() const; + + void dump(int (*oprintf)(const char*, ...)) const; +}; /* PHI data */ struct ir_phi_entry_t { @@ -137,8 +149,8 @@ struct ir_block { bool m_final = false; /* once a jump is added we're done */ ir_instr **m_instr = nullptr; - ir_block **m_entries = nullptr; - ir_block **m_exits = nullptr; + std::vector m_entries; + std::vector m_exits; std::vector m_living; /* For the temp-allocation */ @@ -243,6 +255,18 @@ struct ir_builder { ir_builder(const std::string& modulename); ~ir_builder(); + ir_function *createFunction(const std::string &name, qc_type outtype); + ir_value *createGlobal(const std::string &name, qc_type vtype); + ir_value *createField(const std::string &name, qc_type vtype); + ir_value *get_va_count(); + bool generate(const char *filename); + void dump(int (*oprintf)(const char*, ...)) const; + + ir_value *generateExtparamProto(); + void generateExtparam(); + + ir_value *literalFloat(float value, bool add_to_list); + std::string m_name; std::vector> m_functions; std::vector> m_globals; @@ -282,14 +306,14 @@ struct ir_builder { /* code generator */ std::unique_ptr m_code; -}; -ir_function* ir_builder_create_function(ir_builder*, const std::string& name, qc_type outtype); -ir_value* ir_builder_create_global(ir_builder*, const std::string& name, qc_type vtype); -ir_value* ir_builder_create_field(ir_builder*, const std::string& name, qc_type vtype); -ir_value* ir_builder_get_va_count(ir_builder*); -bool ir_builder_generate(ir_builder *self, const char *filename); -void ir_builder_dump(ir_builder*, int (*oprintf)(const char*, ...)); +private: + qcint_t filestring(const char *filename); + bool generateGlobal(ir_value*, bool is_local); + bool generateGlobalFunction(ir_value*); + bool generateGlobalFunctionCode(ir_value*); + bool generateFunctionLocals(ir_value*); +}; /* * This code assumes 32 bit floats while generating binary