Skip to content

Commit eaec4c8

Browse files
committed
modified arithmetic-related c++ code to compile with the partial implementation of the draft standard of c++11 that gcc 4.4.x uses.
specificaly, modified: verilog_preprocessor generate_fir synth (in multless_consts/verilog) git-svn-id: https://vtr-verilog-to-routing.googlecode.com/svn/trunk@4466 8e3573b8-cf2c-4f14-ef6d-137439e28b8b
1 parent be76317 commit eaec4c8

File tree

9 files changed

+68
-47
lines changed

9 files changed

+68
-47
lines changed

verilog_preprocessor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ default: $(EXE)
99
run: Md5Core.vv
1010

1111
$(EXE): $(EXE).c++
12-
g++ -Wall -Wextra -Werror -pedantic -std=c++11 $< -o $@ -ggdb -D_GLIBCXX_DEBUG
12+
g++ -Wall -Wextra -Werror -pedantic -std=c++0x $< -o $@ -ggdb -D_GLIBCXX_DEBUG
1313

1414
test: Md5Core.v
1515
less $<

verilog_preprocessor/verilog_preprocessor.c++

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <deque>
2323
#include <stack>
2424
#include <math.h>
25+
#include <stdexcept>
2526

2627
using namespace std;
2728

@@ -130,9 +131,13 @@ private:
130131

131132
void macro_expansion_pass(istream& is, ostream& os, const vector<string>& predef_macros) {
132133
unordered_map<string,Macro> name2macro;
133-
for (const string& predef_macro_name : predef_macros) {
134-
name2macro.insert(make_pair(predef_macro_name, Macro(predef_macro_name, {}, "")));
135-
os << "`define " << predef_macro_name << "\n";
134+
for (
135+
auto predef_macro_name = predef_macros.begin();
136+
predef_macro_name != predef_macros.end();
137+
++predef_macro_name
138+
) {
139+
name2macro.insert(make_pair(*predef_macro_name, Macro(*predef_macro_name, {}, "")));
140+
os << "`define " << *predef_macro_name << "\n";
136141
}
137142
IfdefState ifdef_state{};
138143

@@ -265,8 +270,8 @@ void module_redeclaration_pass(istream& is, ostream& os) {
265270
os << '(';
266271

267272
bool needs_redecl = false;
268-
for (auto& param : module_params) {
269-
if (param.find("input ") == 0 || param.find("output ") == 0) {
273+
for (auto param = module_params.begin(); param != module_params.end(); ++param) {
274+
if (param->find("input ") == 0 || param->find("output ") == 0) {
270275
needs_redecl = true;
271276
break;
272277
}
@@ -299,7 +304,6 @@ void module_redeclaration_pass(istream& is, ostream& os) {
299304
if (needs_redecl) {
300305
for (size_t i = 0; i < module_params.size(); ++i) {
301306
string::size_type position_of_reg = string::npos;
302-
string::size_type position_of_wire = string::npos;
303307
if (module_param_types[i].find("output") != string::npos
304308
&& (position_of_reg = module_param_types[i].find("reg")) != string::npos) {
305309
// the case of an output reg
@@ -392,10 +396,14 @@ void twodim_reduction_pass_rewrite(
392396
unordered_multimap<size_t,string> length2name;
393397
size_t longest_name = 2;
394398

395-
for (const auto& name_and_size : name2size) {
396-
length2name.insert(make_pair(name_and_size.first.size(),name_and_size.first));
397-
if (name_and_size.first.size() > longest_name) {
398-
longest_name = name_and_size.first.size();
399+
for (
400+
auto name_and_size = name2size.begin();
401+
name_and_size != name2size.end();
402+
++name_and_size
403+
) {
404+
length2name.insert(make_pair(name_and_size->first.size(),name_and_size->first));
405+
if (name_and_size->first.size() > longest_name) {
406+
longest_name = name_and_size->first.size();
399407
}
400408
}
401409

@@ -414,8 +422,8 @@ void twodim_reduction_pass_rewrite(
414422
if (!is.eof()) {
415423
string comment_line = skipToNextLineIfComment(last_few_chars[0],last_few_chars[1],is);
416424
if (comment_line.size() > 0) {
417-
for (char c : comment_line) {
418-
last_few_chars.push_back(c);
425+
for (size_t i = 0; i < comment_line.size(); ++i) {
426+
last_few_chars.push_back(comment_line[i]);
419427
}
420428
flush_buffer = true;
421429
goto continue_and_ouput;
@@ -487,8 +495,8 @@ void twodim_reduction_pass_rewrite(
487495

488496
if (!good) {
489497
last_few_chars.push_back('[');
490-
for (char c : inside_brackets) {
491-
last_few_chars.push_back(c);
498+
for (size_t i = 0; i < inside_brackets.size(); ++i) {
499+
last_few_chars.push_back(inside_brackets[i]);
492500
}
493501
flush_buffer = true;
494502
goto continue_and_ouput;
@@ -537,10 +545,14 @@ void final_touches_pass(istream& is, ostream& os) {
537545
size_t buffer_size = 0;
538546
unordered_multimap<size_t,string> length2name;
539547

540-
for (const auto& string_to_find : ft_strings_to_find) {
541-
length2name.insert(make_pair(string_to_find.first.size(),string_to_find.first));
542-
if (string_to_find.first.size() > buffer_size) {
543-
buffer_size = string_to_find.first.size();
548+
for (
549+
auto string_to_find = ft_strings_to_find.begin();
550+
string_to_find != ft_strings_to_find.end();
551+
++string_to_find
552+
) {
553+
length2name.insert(make_pair(string_to_find->first.size(),string_to_find->first));
554+
if (string_to_find->first.size() > buffer_size) {
555+
buffer_size = string_to_find->first.size();
544556
}
545557
}
546558

@@ -559,8 +571,8 @@ void final_touches_pass(istream& is, ostream& os) {
559571
if (!is.eof()) {
560572
string comment_line = skipToNextLineIfComment(last_few_chars[0],last_few_chars[1],is);
561573
if (comment_line.size() > 0) {
562-
for (char c : comment_line) {
563-
last_few_chars.push_back(c);
574+
for (size_t i = 0; i < comment_line.size(); ++i) {
575+
last_few_chars.push_back(comment_line[i]);
564576
}
565577
flush_buffer = true;
566578
goto continue_and_ouput;
@@ -621,8 +633,8 @@ void final_touches_pass(istream& is, ostream& os) {
621633
for (size_t i = 0; i < found_match.size(); ++i) {
622634
last_few_chars.pop_back();
623635
}
624-
for (char c : output_str) {
625-
last_few_chars.push_back(c);
636+
for (size_t i = 0; i < output_str.size(); ++i) {
637+
last_few_chars.push_back(output_str[i]);
626638
}
627639
}
628640
}
@@ -804,10 +816,14 @@ std::pair<bool,WireInfo> WireInfo::parseWire(string& decl) {
804816
);
805817
success = false;
806818
} else {
807-
for (auto bracket_location : bracket_locations) {
819+
for (
820+
auto bracket_location = bracket_locations.begin();
821+
bracket_location != bracket_locations.end();
822+
++bracket_location
823+
) {
808824
string dim_decl = decl.substr(
809-
bracket_location + 1,
810-
decl.find_first_of("]",bracket_location) - (bracket_location + 1)
825+
*bracket_location + 1,
826+
decl.find_first_of("]",*bracket_location) - (*bracket_location + 1)
811827
);
812828
try {
813829
std::pair<size_t,size_t> dim_pair = parseVectorDeclation(dim_decl);
@@ -970,7 +986,7 @@ enum class GendefineType : size_t {
970986
CHOOSE_TO,
971987
CHOOSE_FROM,
972988
ALWAYS_LIST,
973-
MOD_OP,
989+
MOD_OP
974990
};
975991

976992
namespace std {

vtr_flow/benchmarks/arithmetic/FIR_filters/verilog/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ODIN=odin_II.exe
22

33
generate_fir: generate_fir.c++
4-
g++ -Wall -Wextra -Werror -pedantic -std=c++11 generate_fir.c++ -o generate_fir
4+
g++ -Wall -Wextra -Werror -pedantic -std=c++0x generate_fir.c++ -o generate_fir
55

66
test: generate_fir
77
./generate_fir | less

vtr_flow/benchmarks/arithmetic/FIR_filters/verilog/generate_fir.c++

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ int main(int argc, char const *argv[]) {
186186
" o_out\n"
187187
");\n"
188188
" // Data Width\n"
189-
" parameter dw = %zu; //Data input/output bits\n"
189+
" parameter dw = %lu; //Data input/output bits\n"
190190
"\n"
191191
" // Number of filter coefficients\n"
192-
" parameter N = %zu;\n"
193-
" parameter N_UNIQ = %zu; // ciel(N/2) assuming symmetric filter coefficients\n"
192+
" parameter N = %lu;\n"
193+
" parameter N_UNIQ = %lu; // ciel(N/2) assuming symmetric filter coefficients\n"
194194
"\n"
195195
" //Number of extra valid cycles needed to align output (i.e. computation pipeline depth + input/output registers\n"
196-
" localparam N_VALID_REGS = %zu;\n"
196+
" localparam N_VALID_REGS = %lu;\n"
197197
"\n"
198198
" input clk;\n"
199199
" input reset;\n"
@@ -204,12 +204,12 @@ int main(int argc, char const *argv[]) {
204204
" output [dw-1:0] o_out; // signed\n"
205205
"\n"
206206
" // Data Width dervied parameters\n"
207-
" localparam dw_add_int = %zu; //Internal adder precision bits\n"
208-
" localparam dw_mult_int = %zu; //Internal multiplier precision bits\n"
209-
" localparam scale_factor = %zu; //Multiplier normalization shift amount\n"
207+
" localparam dw_add_int = %lu; //Internal adder precision bits\n"
208+
" localparam dw_mult_int = %lu; //Internal multiplier precision bits\n"
209+
" localparam scale_factor = %lu; //Multiplier normalization shift amount\n"
210210
"\n"
211211
" // Number of extra registers in INPUT_PIPELINE_REG to prevent contention for CHAIN_END's chain adders\n"
212-
" localparam N_INPUT_REGS = %zu;\n"
212+
" localparam N_INPUT_REGS = %lu;\n"
213213
"\n"
214214
,
215215
DATA_WIDTH,

vtr_flow/benchmarks/arithmetic/multless_consts/verilog/synth/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC=gcc
22
CXX=g++
3-
CXXFLAGS ?= -O3 -fomit-frame-pointer -Wall -Wextra -pedantic -Werror -std=c++11
3+
CXXFLAGS ?= -O3 -fomit-frame-pointer -Wall -Wextra -pedantic -Werror -Wno-long-long
44
CFLAGS=$(CXXFLAGS)
55
LINKFLAGS=
66

vtr_flow/benchmarks/arithmetic/multless_consts/verilog/synth/arith.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdlib.h>
2+
13
inline coeff_t fundamental(coeff_t z) {
24
ASSERT(z > (coeff_t)0);
35
while((z & (coeff_t)1) == 0)

vtr_flow/benchmarks/arithmetic/multless_consts/verilog/synth/chains.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
int MAX_NPRINT = 5;
66
bool PRINT_INSTRS = false;
77
bool PRINT_CHAINS = false;
8-
enum { CHAINS_PLAIN, CHAINS_C } PRINT_CHAINS_MODE = CHAINS_PLAIN;
8+
typedef enum { CHAINS_PLAIN, CHAINS_C } t_print_chains_mode;
9+
t_print_chains_mode PRINT_CHAINS_MODE = CHAINS_PLAIN;
10+
911
bool PRINT_ALL_CHAINS = true;
1012

1113
bool PRINT_COSTS = false;
12-
enum { COSTS_PLAIN, COSTS_C } PRINT_COSTS_MODE = COSTS_C;
14+
typedef enum { COSTS_PLAIN, COSTS_C } t_print_costs_mode;
15+
t_print_costs_mode PRINT_COSTS_MODE = COSTS_C;
1316
int MIN_SHIFT = 0;
1417

1518
coeff_t MAX_NUM;
@@ -107,7 +110,7 @@ void insert_all_sumdiffs(cost_t dest_cost, coeff_t num1, coeff_t num2) {
107110
void generate_add_coeffs(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
108111
cfvec_t &src1 = COSTVECS[src1_cost];
109112
cfvec_t &src2 = COSTVECS[src2_cost];
110-
cfvec_t &dest = COSTVECS[dest_cost];
113+
// cfvec_t &dest = COSTVECS[dest_cost];
111114
for(cfviter_t s1 = src1.begin(); s1 != src1.end(); ++s1) {
112115
for(cfviter_t s2 = src2.begin(); s2 != src2.end(); ++s2) {
113116
insert_all_sumdiffs(dest_cost, *s1, *s2);
@@ -118,7 +121,7 @@ void generate_add_coeffs(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
118121
void generate_mul_coeffs(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
119122
cfvec_t &src1 = COSTVECS[src1_cost];
120123
cfvec_t &src2 = COSTVECS[src2_cost];
121-
cfvec_t &dest = COSTVECS[dest_cost];
124+
// cfvec_t &dest = COSTVECS[dest_cost];
122125
for(cfviter_t s1 = src1.begin(); s1 != src1.end(); ++s1) {
123126
for(cfviter_t s2 = src2.begin(); s2 != src2.end(); ++s2) {
124127
coeff_t prod = (*s1) * (*s2);
@@ -131,7 +134,7 @@ void generate_mul_coeffs(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
131134
void generate_leapfrog2(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
132135
cfvec_t &src1 = COSTVECS[src1_cost];
133136
cfvec_t &src2 = COSTVECS[src2_cost];
134-
cfvec_t &dest = COSTVECS[dest_cost];
137+
// cfvec_t &dest = COSTVECS[dest_cost];
135138
for(cfviter_t s1 = src1.begin(); s1 != src1.end(); ++s1) {
136139
addmap_t leap1;
137140
compute_all_sumdiffs(leap1, *s1, 1);
@@ -156,7 +159,7 @@ void generate_leapfrog2(cost_t src1_cost, cost_t src2_cost, cost_t dest_cost) {
156159
void generate_leapfrog3(cost_t src1_cost, cost_t src3_cost, cost_t dest_cost) {
157160
cfvec_t &src1 = COSTVECS[src1_cost];
158161
cfvec_t &src3 = COSTVECS[src3_cost];
159-
cfvec_t &dest = COSTVECS[dest_cost];
162+
// cfvec_t &dest = COSTVECS[dest_cost];
160163
for(cfviter_t s1 = src1.begin(); s1 != src1.end(); ++s1) {
161164
addmap_t leap1;
162165
compute_all_sumdiffs(leap1, *s1, 1);

vtr_flow/benchmarks/arithmetic/multless_consts/verilog/synth/cmdline.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@
1111
#define xfree free
1212
#define xstrdup strdup
1313

14-
char * flatten_string_array(char** strings, int count, char *delimitor) {
15-
if(count > 0) {
14+
char * flatten_string_array(char** strings, int count, const char* delimitor) {
1615
int len = 0, i, ofs;
1716
char * result;
1817
for(i = 0; i < count; i++)
1918
len += strlen(strings[i])+1;
2019

2120
result = (char*) xmalloc( sizeof(char) * len + 1 );
21+
result[0] = '\0';
2222
ofs = 0;
2323
for(i = 0; i < count; i++) {
2424
if(i!=0) ofs += strlen(strings[i-1]) + 1;
2525
sprintf(result + ofs, "%s%s", strings[i], delimitor);
2626
}
2727
return result;
28-
}
29-
else return "";
3028
}
3129

3230
cmdline_t * cmdline_new(int argc, char **argv) {

vtr_flow/benchmarks/arithmetic/multless_consts/verilog/synth/synth_main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "synth.cpp"
22

3+
#include <stdio.h>
4+
35
reg_t tmpreg() { static int c=100; return c++; }
46
reg_t destreg() { static int c=1; return c++; }
57
regmap_t regs;

0 commit comments

Comments
 (0)