diff options
| author | Ataberk <olgunataberk@gmail.com> | 2022-09-25 17:22:03 +0200 |
|---|---|---|
| committer | Ataberk <olgunataberk@gmail.com> | 2022-09-25 17:22:03 +0200 |
| commit | dc0b3db1b4f1895a07e5fe280ee3790e87f97b9f (patch) | |
| tree | b47203aa281bdd959def4451c84d310cd9cf2e12 /sources/api/prog.h | |
| download | dram-bender-dc0b3db1b4f1895a07e5fe280ee3790e87f97b9f.tar.gz | |
Initial commit
Diffstat (limited to 'sources/api/prog.h')
| -rw-r--r-- | sources/api/prog.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/sources/api/prog.h b/sources/api/prog.h new file mode 100644 index 0000000..d9febd7 --- /dev/null +++ b/sources/api/prog.h @@ -0,0 +1,120 @@ +#ifndef PROG_H +#define PROG_H + +#include <vector> +#include <map> +#include <string> +#include "instruction.h" + +class Program{ +private: + std::map<std::string, uint> labels; + std::map<uint, std::string> branches; + std::map<uint, Inst> warnings; + std::vector<Inst> program; + std::vector<Mininst> minprogram; + int spc = 0; + + bool dumpRegsCalled; + + void preprocess_branches(); + void linear_analysis(); + void insert_generated(); + Inst* get_insts(); + +public: + enum class SEQ_TYPE { WRITE, READ }; + enum BR_TYPE { BEQ, BL, JUMP }; + + + Program(); + + /** + * Load an instruction stream from file + * @param fname name of the file + */ + Program(std::string fname); + + void add_mininst(Mininst mi, int wait_after); + void add_wait(int wait_cycles); + void pack_minprogram(); + /** + * Add an instruction to the program + * @param i instruction to add, usually generated by instruction.h functions (e.g. SMC_ADD()) + */ + void add_inst(Inst i); + /** + * Add four mininsts to the program + */ + void add_inst(Mininst,Mininst,Mininst,Mininst); + void add_label(std::string name); + /** + * Add a conditional branch to the program + * @bt the type of branch instruction to be executed: + * either one of: BR_TYPE.BEQ, BR_TYPE.BL or BR_TYPE.JUMP + * @rs1 branch instr. operand 1 + * @rs2 branch instr. operand 2 + * @tgt branch target to jump to if condition is satisfied + */ + void add_branch(BR_TYPE bt, int rs1, int rs2, std::string tgt); + + /** + * Append another program to this program. + * @param p program to append to the end of this program. + */ + void add_below(const Program &p); + + /** + * Parse SMC programs + * @param fname file to read from + */ + void parse_from_file(std::string fname); + + Inst* get_inst_array(); + + /** + * @return size of the program in bytes + */ + int size(); + + /** + * Print instructions in a human readable form + */ + void pretty_print(); + + /** + * Print instruction binaries + */ + void bin_dump(); + /** + * Save this instruction stream to file + * @param fname name of the file + */ + void save_bin(const std::string &fname); + void save_coe_here(const std::string &prj_dir); + void save_coe(const std::string &prj_dir); + void debug(const std::string &prj_dir, bool first); + void debug(const std::string &prj_dir, const std::string &filename); + + /** + * Insert routine required to dump register file content. + * The generated routine requires registers 13-15 to operate correctly. + * It won't do any context-switch and registers 13-15 will have garbage + * values when this routine is executed. It will also use DRAM bank + * 15 row 0-1 to store and readback data, it will also precharge all banks. + * This routine will also mess with WDATA reg content *after* dumping it. + * + * Aside from all the above, you need to intercept reads yourself. Make sure + * that there is no other data left in the buffers before this routine executes + * and call platform::readRegisterDump(). + * You have been warned. + * You have been warned twice. + * You did not hear that wrong, this will dump all register content. + */ + void dump_registers(); + + bool isDumpRegsCalled(); + +}; + +#endif |
