-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate_table_scalar_vhd.cc
76 lines (72 loc) · 2.91 KB
/
generate_table_scalar_vhd.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
/*
Generate table_scalar.vhd from table_scalar.txt
Copyright 2019 Ahmet Inan <[email protected]>
*/
#include <fstream>
#include "ldpc_scalar.hh"
int main()
{
int offsets[BLOCK_LOCATIONS_MAX];
int shifts[BLOCK_LOCATIONS_MAX];
int counts[BLOCK_PARITIES_MAX];
int parities = 0;
std::ifstream table_txt("table_scalar.txt");
for (int loc = 0; table_txt >> counts[parities]; ++parities) {
for (int num = 0; num < counts[parities]; ++num, ++loc) {
table_txt >> offsets[loc];
table_txt.ignore(1, ':');
table_txt >> shifts[loc];
}
}
std::ofstream table_vhd("table_scalar.vhd");
table_vhd << "-- code table generated from table_scalar.txt by generate_table_scalar_vhd.cc" << std::endl;
table_vhd << "--" << std::endl;
table_vhd << "-- Copyright 2019 Ahmet Inan <[email protected]>" << std::endl;
table_vhd << std::endl;
table_vhd << "use work.ldpc_scalar.all;" << std::endl;
table_vhd << std::endl;
table_vhd << "package table_scalar is" << std::endl;
table_vhd << " function init_block_parities return block_parities;" << std::endl;
table_vhd << " function init_block_counts return block_counts;" << std::endl;
table_vhd << " function init_block_offsets return block_offsets;" << std::endl;
table_vhd << " function init_block_shifts return block_shifts;" << std::endl;
table_vhd << "end package;" << std::endl;
table_vhd << std::endl;
table_vhd << "package body table_scalar is" << std::endl;
table_vhd << " function init_block_parities return block_parities is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return " << parities << ";" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_block_counts return block_counts is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0; pty < parities; ++pty)
table_vhd << counts[pty] << "," << std::endl;
table_vhd << " others => count_scalar'low);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_block_offsets return block_offsets is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0, loc = 0; pty < parities; ++pty) {
for (int num = 0; num < counts[pty]; ++num, ++loc)
table_vhd << offsets[loc] << ",";
table_vhd << std::endl;
}
table_vhd << " others => 0);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_block_shifts return block_shifts is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0, loc = 0; pty < parities; ++pty) {
for (int num = 0; num < counts[pty]; ++num, ++loc)
table_vhd << shifts[loc] << ",";
table_vhd << std::endl;
}
table_vhd << " others => 0);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << "end package body;" << std::endl;
return 0;
}