1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#ifndef PROG_H
#define PROG_H
#include <vector>
#include <map>
#include <string>
#include <sys/types.h>
#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
|