Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F480193
convert_bbdd.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Size
5 KB
Referenced Files
None
Subscribers
None
convert_bbdd.cpp
View Options
// Copyright 2025 Oliver Theimer
#include
<cstdlib>
#include
<filesystem>
#include
<iostream>
#include
<string>
#include
<vector>
#include
<cstdio>
#include
"bbdd/include/bbdd.hpp"
#include
"bbdd/include/unique_table.hpp"
#include
"util/cover_to_bbdd.hpp"
#include
<lorina/diagnostics.hpp>
#include
<lorina/lorina.hpp>
#include
<mockturtle/algorithms/cover_to_graph.hpp>
#include
<mockturtle/mockturtle.hpp>
int
main
(
int
argc
,
char
*
argv
[])
{
bool
vis
=
false
;
bool
use_height
=
false
;
bool
use_order_input
=
false
;
std
::
string
order_output_dir
;
int
sifting_repetitions
=
1
;
int
table_size
=
20000000
;
int
opt
;
while
((
opt
=
getopt
(
argc
,
argv
,
"i:vhr:t:"
))
!=
-1
)
{
switch
(
opt
)
{
case
'i'
:
use_order_input
=
true
;
order_output_dir
=
optarg
;
break
;
case
'v'
:
vis
=
true
;
break
;
case
'h'
:
use_height
=
true
;
break
;
case
't'
:
{
char
*
endptr
=
nullptr
;
table_size
=
std
::
strtol
(
optarg
,
&
endptr
,
10
);
if
(
*
endptr
!=
'\0'
)
{
std
::
cerr
<<
"[ERROR] Invalid integer for option -t: "
<<
optarg
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
if
(
table_size
<
0
||
table_size
>
pow
(
2
,
31
))
{
std
::
cerr
<<
"[ERROR] Invalid integer: "
<<
optarg
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
break
;
}
case
'r'
:
{
char
*
endptr
=
nullptr
;
sifting_repetitions
=
std
::
strtol
(
optarg
,
&
endptr
,
10
);
if
(
*
endptr
!=
'\0'
)
{
std
::
cerr
<<
"[ERROR] Invalid integer for option -r: "
<<
optarg
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
break
;
}
default
:
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" [-v] [-r ordering_output_file] <blif-file>"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
}
if
(
optind
>=
argc
)
{
std
::
cout
<<
"[ERROR] input file in blif format is missing
\n
"
;
std
::
cerr
<<
"[INFO] Usage: "
<<
argv
[
0
]
<<
" [-v] <blif-file>"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
std
::
string
benchmark
(
argv
[
optind
]);
if
(
!
std
::
filesystem
::
exists
(
benchmark
))
{
std
::
cout
<<
"[ERROR] File does not exist
\n
"
;
return
EXIT_FAILURE
;
}
std
::
filesystem
::
path
path
(
benchmark
);
std
::
string
base_name
=
path
.
stem
().
string
();
mockturtle
::
cover_network
cover
;
if
(
lorina
::
read_blif
(
benchmark
,
mockturtle
::
blif_reader
(
cover
))
!=
lorina
::
return_code
::
success
)
{
std
::
cout
<<
"[ERROR] While Lorina tried to read in file
\n
"
;
return
EXIT_FAILURE
;
}
std
::
vector
<
node_index_t
>
cvo_input_v
;
if
(
use_order_input
)
{
std
::
string
line
;
std
::
cout
<<
"Enter variable ordering separated by spaces (leave empty for "
"default ordering): "
;
std
::
getline
(
std
::
cin
,
line
);
std
::
stringstream
str_s
(
line
);
int
num
;
while
(
str_s
>>
num
)
{
cvo_input_v
.
push_back
(
num
);
}
if
(
cover
.
_storage
->
inputs
.
size
()
!=
cvo_input_v
.
size
()
&&
!
cvo_input_v
.
empty
())
{
std
::
cerr
<<
"[ERROR] Number of variables in ordering does not match "
"number of inputs
\n
"
;
return
EXIT_FAILURE
;
}
}
use_order_input
=
true
;
cvo_input_v
=
{};
printf
(
"[INFO] cover with %zu nodes
\n
"
,
cover
.
_storage
->
nodes
.
size
());
Unique_table
table
;
table
.
init_table
(
table_size
,
cover
.
get_module_name
());
if
(
use_order_input
&&
!
cvo_input_v
.
empty
())
{
table
.
init_cvo
(
cover
.
_storage
->
inputs
,
cvo_input
,
cvo_input_v
);
}
else
{
table
.
init_cvo
(
cover
.
_storage
->
inputs
,
cvo_none
);
}
std
::
filesystem
::
path
order_output_dir_path
;
std
::
filesystem
::
path
base_name_path
;
std
::
filesystem
::
path
order_file_path
;
std
::
ofstream
order_file
;
if
(
use_order_input
)
{
order_output_dir_path
=
order_output_dir
;
base_name_path
=
base_name
;
base_name_path
.
replace_extension
(
".csv"
);
order_file_path
=
order_output_dir_path
/
base_name_path
;
bool
order_file_exitsts
=
std
::
filesystem
::
exists
(
order_file_path
);
order_file
.
open
(
order_file_path
,
std
::
ios
::
app
);
if
(
!
order_file_exitsts
)
{
order_file
<<
"order_in;order_pos;height;nodes
\n
"
;
}
}
cover_to_bbdd
(
&
table
,
cover
,
use_height
,
sifting_repetitions
);
std
::
cout
<<
"[INFO] BBDD created
\n
"
;
if
(
vis
)
{
std
::
cout
<<
"[INFO] dumping result into .dot file
\n
"
;
table
.
dump_table
();
table
.
dump_dot
(
"temp/"
+
base_name
+
".dot"
,
cover
.
signal_map
);
system
(
(
"dot -Tpng temp/"
+
base_name
+
".dot -o temp/"
+
base_name
+
".png"
)
.
c_str
());
}
#ifdef CACHE_STATS
table
.
print_cache_stats
();
table
.
dump_cache_stats
(
"temp/"
+
base_name
+
"_cache_stats.csv"
);
#endif
if
(
use_order_input
)
{
std
::
cout
<<
"[INFO] Writing ordering, total height, total number of nodes to "
<<
order_file_path
<<
"
\n
"
;
dump_ordering
(
table
.
cvo
,
order_file
);
order_file
<<
";"
<<
table
.
get_total_height
()
<<
";"
<<
table
.
get_total_number_nodes
()
<<
"
\n
"
;
order_file
.
close
();
}
std
::
cout
<<
"[INFO] Writing bbdd into blif file
\n
"
;
table
.
write_blif
(
"temp/"
+
base_name
+
"_bbdd"
+
(
use_height
?
"_height"
:
""
)
+
".blif"
,
cover
.
get_module_name
(),
cover
.
signal_map
,
cover
.
_storage
->
inputs
.
size
());
table
.
free_table
();
return
EXIT_SUCCESS
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Oct 19, 1:42 PM (11 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
199296
Default Alt Text
convert_bbdd.cpp (5 KB)
Attached To
Mode
R272 SoC_NEM_Synthesis
Attached
Detach File
Event Timeline
Log In to Comment