-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmifgenerator.cc
116 lines (101 loc) · 2.73 KB
/
mifgenerator.cc
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
#include "mifgenerator.h"
#include "binarygenerator.h"
#include <iostream>
#include <fstream>
#include <string>
#include "bytes.h"
MifGenerator::MifGenerator()
{
header = "-- begin_signature\n"
"-- Memory\n"
"-- end_signature\n";
greatestLine = -1;
}
void MifGenerator::open(std::string outputFile, bool isBios, bool isCompressed)
{
this->isCompressed = isBios || isCompressed;
std::string width = "32;\n";
std::string depth = std::to_string(MEMORY_SIZE) + ";\n";
if (isBios)
{
width = "16;\n";
depth = std::to_string(BIOS_SIZE) +";\n";
}
if(isCompressed)
depth = std::to_string(STORAGE_SIZE) + ";\n";
dontcare = isBios ? "XXXXXXXXXXXXXXXX"
: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
header += "WIDTH=" + width +
"DEPTH=" + depth +
"\n"
"ADDRESS_RADIX=UNS;\n"
"DATA_RADIX=BIN;\n"
"\n"
"CONTENT BEGIN\n";
file.open(outputFile.c_str(), std::ofstream::out);
file << header;
}
void MifGenerator::printLine(std::string line)
{
file << line;
}
void MifGenerator::jumpLine()
{
file << "\n";
}
void MifGenerator::printFooter()
{
file << "END;\n"
<< std::endl;
close();
}
void MifGenerator::close()
{
file.close();
}
void MifGenerator::printEmptyMemoryPosition(int position)
{
updateGreatestLine(position);
printLine(" " + std::to_string(position) +
" : " +
dontcare + ";\n");
}
void MifGenerator::printInstruction(int position, std::string binary, std::string assembly)
{
updateGreatestLine(position);
std::string firstHW = isCompressed ? "" : "0000000000000000";
printLine(" " + std::to_string(position) +
" : " + firstHW +
binary + "; -- " + assembly);
}
void MifGenerator::printMultipleEmptyPosition(int repeats)
{
int start = greatestLine + 1;
for (int i = start; i < repeats; i++)
printEmptyMemoryPosition(i);
}
void MifGenerator::printDebugMsg(std::string msg)
{
printLine(" ((" + msg + "))");
}
void MifGenerator::updateGreatestLine(int line)
{
if (line > greatestLine)
greatestLine = line;
}
void MifGenerator::printSize(int codeSize, int place)
{
Bytes size = Bytes(codeSize);
printInstruction(place,
size.to_string(),
"size = " +
std::to_string(codeSize) + "\n");
}
void MifGenerator::printUncompressedSize(int codeSize, int place)
{
Bytes size = Bytes(codeSize);
updateGreatestLine(place);
printLine(" " + std::to_string(place) +
" : " + size.to_string() +
"; -- size: " + std::to_string(codeSize) + "\n");
}