diff options
Diffstat (limited to 'masm/gen.h')
| -rw-r--r-- | masm/gen.h | 93 |
1 files changed, 71 insertions, 22 deletions
@@ -37,8 +37,26 @@ struct section { struct reference_table reftab; }; +/* get a section from the generator by name, and return it into res. if the + * section does not exist, one will be created. */ +int gen_get_section(struct generator *gen, struct section **res, + struct string *name); + +/* initalize a section */ +int section_init(struct section *section, struct string *name); + +/* free a section */ void section_free(struct section *section); +/* extend a section by space bytes plus alignment */ +int section_extend(struct section *section, size_t space); + +/* push data into a section */ +int section_push(struct section *section, void *data, size_t len); + +/* push zeros (empty space) to a section */ +int section_zero(struct section *section, size_t len); + /// /// instruction generation state /// @@ -55,36 +73,35 @@ struct gen_ins_state { enum mips32_fp_register fd; // immd - uint16_t immd; // 16 bit + uint16_t immd; // cc - uint16_t cc; // 3 bit + uint16_t cc; // code - uint32_t code; // 5 bit + uint32_t code; // pos - uint32_t pos; // 5 bit + uint32_t pos; // size - uint32_t size; // 5 bit - 1 - - // hb - bool hb; // 1 bit - 1 - - // index - uint32_t index; + uint32_t size; // hint uint32_t hint; - // offset(base) - uint16_t offset; // 16 bit - enum mips32_register base; + // hazard barrier + bool hb; // 1 bit - 1 // target uint32_t target; + // index(base) + // offset(base) + uint32_t index; + uint16_t offset; + enum mips32_register base; + // current referencd label struct string *label; }; @@ -95,16 +112,11 @@ struct gen_ins_override { uint32_t immd; }; -/// -/// grammer type -/// - enum grammer_type { // registers GMR_RD, GMR_RS, GMR_RT, - GMR_INDEX_BASE, // fp registers GMR_FS, GMR_FT, @@ -118,13 +130,47 @@ enum grammer_type { GMR_HB, GMR_HINT, // addresses - GMR_OFFSET, - GMR_OFFSET_BASE, - GMR_TARGET, GMR_HI, GMR_LO, + GMR_TARGET, + GMR_OFFSET, + GMR_INDEX_BASE, + GMR_OFFSET_BASE, + // len + __GMR_LEN }; +/* Parses the input string and matches it to a grammer type. Returns + * the number of characters consumed, or -1 on error. + */ +int gen_parse_grammer_type(const char *name, enum grammer_type *res); + +/* Parses a register name, returing 0 on success, 1 on error*/ +int gen_parse_register(enum mips32_register *reg, struct string *name); + +/* Parses a floating point register name, returing 0 on success, 1 on error*/ +int gen_parse_fp_register(enum mips32_fp_register *reg, struct string *name); + +/* Parses the overide expression (after the =) in the dsl for the grammer. + * returns the number of characters consumed, or -1 on error. */ +int gen_parse_grammer_overide(struct gen_ins_state *state, + struct gen_ins_override *over, char *value); + +/* Given a grammer for an instruction, read all args as values into the + * instruction generator state. */ +int gen_read_grammer_state(struct generator *gen, + struct expr *const expr, + struct gen_ins_state *state, + struct mips32_grammer *grammer); + +/* Given a grammer for an instruction, and a read state, output multiple + * instructions into the current section in the generator. note: + * this write_grammer is different from the read grammer such that + * it supports paramater reassignment and overides. */ +int gen_write_grammer_state(struct generator *gen, + struct gen_ins_state *state, + char *write_grammer); + /// /// generates assembley /// from a parser stream @@ -152,6 +198,9 @@ struct generator { struct symbol_table symtab; }; +/* output the source code lines for a provided expression */ +void gen_output_expr(struct generator *gen, struct expr *expr); + /* generate the input as mips32r6 */ int generate_mips32r6(struct generator *gen); /* run codegen with the mips32r2 specification */ |