Skip to content

Commit 6effd3e

Browse files
authored
Merge pull request #259 from abs-tudelft/static-vhdl
Add fletchgen option to output static VHDL support files as well
2 parents 501b920 + c8a252b commit 6effd3e

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

codegen/cpp/fletchgen/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ if(NOT TARGET fletcher::c)
4242
add_subdirectory(../../../common/c common-c)
4343
endif()
4444

45+
46+
FetchContent_Declare(cmakerc
47+
GIT_REPOSITORY https://github.com/vector-of-bool/cmrc.git
48+
GIT_TAG master
49+
)
50+
FetchContent_MakeAvailable(cmakerc)
51+
52+
file(
53+
GLOB_RECURSE RESOURCE_FILES
54+
LIST_DIRECTORIES false
55+
"${CMAKE_CURRENT_SOURCE_DIR}/../../../hardware/**/*"
56+
)
57+
cmrc_add_resource_library(
58+
fletchgen-resources
59+
ALIAS fletchgen::resources
60+
NAMESPACE fletchgen
61+
WHENCE "${CMAKE_CURRENT_SOURCE_DIR}/../../.."
62+
${RESOURCE_FILES}
63+
)
64+
set_property(
65+
TARGET fletchgen-resources
66+
PROPERTY POSITION_INDEPENDENT_CODE ON
67+
)
68+
4569
add_compile_unit(
4670
OPT
4771
NAME fletchgen::obj
@@ -66,6 +90,7 @@ add_compile_unit(
6690
src/fletchgen/profiler.cc
6791
src/fletchgen/axi4_lite.cc
6892
src/fletchgen/external.cc
93+
src/fletchgen/static_vhdl.cc
6994

7095
src/fletchgen/srec/recordbatch.cc
7196
src/fletchgen/srec/srec.cc
@@ -92,6 +117,7 @@ add_compile_unit(
92117
fletcher::c
93118
CLI11::CLI11
94119
Threads::Threads
120+
fletchgen::resources
95121
)
96122

97123
add_compile_unit(

codegen/cpp/fletchgen/src/fletchgen/fletchgen.cc

+7
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
#include "fletchgen/srec/recordbatch.h"
2929
#include "fletchgen/top/sim.h"
3030
#include "fletchgen/top/axi.h"
31+
#include "fletchgen/static_vhdl.h"
3132

3233
namespace fletchgen {
3334

3435
int fletchgen(int argc, char **argv) {
36+
3537
// Start logging
3638
std::string program_name = fletchgen::GetProgramName(argv[0]);
3739
fletcher::StartLogging(program_name, FLETCHER_LOG_DEBUG, program_name + ".log");
@@ -161,6 +163,11 @@ int fletchgen(int argc, char **argv) {
161163
*/
162164
}
163165

166+
// Write static VHDL support files for Fletcher.
167+
if (options->static_vhdl) {
168+
write_static_vhdl("vhdl/support");
169+
}
170+
164171
// Wait for vhdmmio.
165172
if (!vhdmmio.joinable()) {
166173
FLETCHER_LOG(INFO, "Waiting for vhdmmio to complete...");

codegen/cpp/fletchgen/src/fletchgen/options.cc

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ bool Options::Parse(Options *options, int argc, char **argv) {
9393
app.add_flag("--vivado_hls", options->vivado_hls,
9494
"Generate a Vivado HLS kernel template.");
9595

96+
app.add_flag("--static-vhdl", options->static_vhdl, "Write static VHDL support files.");
97+
9698
// Other options:
9799
app.add_flag("-v,--version", options->version,
98100
"Show version.");

codegen/cpp/fletchgen/src/fletchgen/options.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct Options {
5959
bool axi_top = false;
6060
/// Whether to simulate an AXI top level.
6161
bool sim_top = false;
62+
/// Whether to generate static VHDL files (copied from hardware directory, embedded as resources).
63+
bool static_vhdl = false;
6264
/// Whether to backup any existing generated files.
6365
bool backup = false;
6466

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2018-2019 Delft University of Technology
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "fletchgen/static_vhdl.h"
16+
17+
#include <cmrc/cmrc.hpp>
18+
#include <fstream>
19+
#include <algorithm>
20+
#include <sys/stat.h>
21+
#include <sys/types.h>
22+
23+
CMRC_DECLARE(fletchgen);
24+
25+
namespace fletchgen {
26+
27+
void write_static_vhdl(const std::string &real_dir, const std::string &emb_dir) {
28+
mkdir(real_dir.c_str(), 0777);
29+
for (const auto &dirent : cmrc::fletchgen::get_filesystem().iterate_directory(emb_dir)) {
30+
if (dirent.is_file()) {
31+
std::ofstream real_file;
32+
real_file.open(real_dir + "/" + dirent.filename());
33+
std::ostream_iterator<char> out_it{real_file};
34+
auto emb_file = cmrc::fletchgen::get_filesystem().open(emb_dir + "/" + dirent.filename());
35+
std::copy(emb_file.cbegin(), emb_file.cend(), out_it);
36+
real_file.close();
37+
} else {
38+
write_static_vhdl(real_dir + "/" + dirent.filename(), emb_dir + "/" + dirent.filename());
39+
}
40+
}
41+
}
42+
43+
} // namespace fletchgen
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018-2019 Delft University of Technology
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <string>
18+
19+
namespace fletchgen {
20+
21+
/**
22+
* @brief Writes Fletcher's static VHDL files to the given directory.
23+
* @param real_dir The real directory to write to.
24+
* @param emb_dir The embedded filesystem directory to read from, defaulting
25+
* to the toplevel resource directory ("hardware").
26+
*/
27+
void write_static_vhdl(const std::string &real_dir, const std::string &emb_dir = "hardware");
28+
29+
} // namespace fletchgen

0 commit comments

Comments
 (0)