Skip to content

Commit 206e1c5

Browse files
authored
Merge pull request hdl#322 from abrisco/exectools
Add `data` attribute to `verilog_library`
2 parents 925fe7c + 6626455 commit 206e1c5

File tree

8 files changed

+51
-33
lines changed

8 files changed

+51
-33
lines changed

synthesis/build_defs.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def _create_flist(ctx, flist_tag, files, short_path = False):
6464
def _synthesize_design_impl(ctx):
6565
transitive_srcs = _transitive_srcs([dep for dep in ctx.attr.deps if VerilogInfo in dep])
6666
verilog_srcs = [verilog_info_struct.srcs for verilog_info_struct in transitive_srcs.to_list()]
67-
verilog_files = [src for sub_tuple in verilog_srcs for src in sub_tuple]
67+
verilog_data = [verilog_info_struct.data for verilog_info_struct in transitive_srcs.to_list()]
68+
verilog_files = [src for sub_tuple in (verilog_srcs + verilog_data) for src in sub_tuple]
6869
verilog_hdrs = [verilog_info_struct.hdrs for verilog_info_struct in transitive_srcs.to_list()]
6970
verilog_hdr_files = [hdr for sub_tuple in verilog_hdrs for hdr in sub_tuple]
7071

verilator/defs.bzl

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ def cc_compile_and_link_static_library(ctx, srcs, hdrs, deps, runfiles, includes
7474
output_files.append(linking_output.library_to_link.dynamic_library)
7575

7676
return [
77-
DefaultInfo(files = depset(output_files), runfiles = ctx.runfiles(files = runfiles)),
77+
DefaultInfo(
78+
files = depset(output_files),
79+
runfiles = ctx.runfiles(files = runfiles),
80+
),
7881
CcInfo(
7982
compilation_context = compilation_context,
8083
linking_context = linking_context,
@@ -100,7 +103,8 @@ def _only_hpp(f):
100103
def _verilator_cc_library(ctx):
101104
transitive_srcs = depset([], transitive = [ctx.attr.module[VerilogInfo].dag])
102105
all_srcs = [verilog_info_struct.srcs for verilog_info_struct in transitive_srcs.to_list()]
103-
all_files = [src for sub_tuple in all_srcs for src in sub_tuple]
106+
all_data = [verilog_info_struct.data for verilog_info_struct in transitive_srcs.to_list()]
107+
all_files = [src for sub_tuple in (all_srcs + all_data) for src in sub_tuple]
104108

105109
# Filter out .dat files.
106110
runfiles = []

verilator/tests/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ verilog_library(
4747
name = "load_and_count",
4848
srcs = [
4949
"load_and_count.sv",
50+
],
51+
data = [
5052
"test_data.dat",
5153
],
5254
)

verilog/providers.bzl

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ VerilogInfo = provider(
2424
},
2525
)
2626

27-
def make_dag_entry(srcs, hdrs, deps, label):
27+
def make_dag_entry(srcs, hdrs, data, deps, label):
2828
"""Create a new DAG entry for use in VerilogInfo.
2929
3030
As VerilogInfo should be created via 'merge_verilog_info' (rather than directly),
@@ -39,6 +39,7 @@ def make_dag_entry(srcs, hdrs, deps, label):
3939
Args:
4040
srcs: A list of File that are 'srcs'.
4141
hdrs: A list of File that are 'hdrs'.
42+
data: A list of File that are `data`.
4243
deps: A list of Label that are deps of this entry.
4344
label: A Label to use as the name for this entry.
4445
Returns:
@@ -47,6 +48,7 @@ def make_dag_entry(srcs, hdrs, deps, label):
4748
return struct(
4849
srcs = tuple(srcs),
4950
hdrs = tuple(hdrs),
51+
data = tuple(data),
5052
deps = tuple(deps),
5153
label = label,
5254
)
@@ -69,7 +71,7 @@ def make_verilog_info(
6971
# dpis: Verilog DPI files.
7072
Returns:
7173
VerilogInfo that combines all the DAGs together.
72-
"""
74+
"""
7375
return VerilogInfo(
7476
dag = depset(
7577
direct = new_entries,
@@ -91,6 +93,7 @@ def _verilog_library_impl(ctx):
9193
verilog_info = make_verilog_info(
9294
new_entries = [make_dag_entry(
9395
srcs = ctx.files.srcs,
96+
data = ctx.files.data,
9497
hdrs = ctx.files.hdrs,
9598
deps = ctx.attr.deps,
9699
label = ctx.label,
@@ -106,6 +109,10 @@ verilog_library = rule(
106109
doc = "Define a Verilog module.",
107110
implementation = _verilog_library_impl,
108111
attrs = {
112+
"data": attr.label_list(
113+
doc = "Compile data ready by sources.",
114+
allow_files = True,
115+
),
109116
"deps": attr.label_list(
110117
doc = "The list of other libraries to be linked.",
111118
providers = [
@@ -114,11 +121,11 @@ verilog_library = rule(
114121
),
115122
"hdrs": attr.label_list(
116123
doc = "Verilog or SystemVerilog headers.",
117-
allow_files = True,
124+
allow_files = [".vh", ".svh"],
118125
),
119126
"srcs": attr.label_list(
120127
doc = "Verilog or SystemVerilog sources.",
121-
allow_files = True,
128+
allow_files = [".v", ".sv"],
122129
),
123130
},
124131
)

vivado/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Vivado rules
22

3+
Bazel rules for the [Vivado Design Suite](https://www.xilinx.com/developer/products/vivado.html).
4+
35
The following are defined in `//vivado:defs.bzl`:
46

57
* `vivado_create_project`

vivado/defs.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def generate_file_load_tcl(module):
9898
"""
9999
transitive_srcs = depset([], transitive = [module[VerilogInfo].dag])
100100
all_srcs = [verilog_info_struct.srcs for verilog_info_struct in transitive_srcs.to_list()]
101-
all_files = [src for sub_tuple in all_srcs for src in sub_tuple]
101+
all_data = [verilog_info_struct.data for verilog_info_struct in transitive_srcs.to_list()]
102+
all_files = [src for sub_tuple in (all_srcs + all_data) for src in sub_tuple]
102103

103104
hdl_source_content, constraints_content, tcl_content = get_content_from_files(all_files)
104105

vivado/tests/BUILD

+26-13
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
1516
load("@rules_cc//cc:defs.bzl", "cc_test")
16-
load("@rules_python//python:defs.bzl", "py_binary")
1717
load("//verilator:defs.bzl", "verilator_cc_library")
1818
load("//verilog:defs.bzl", "verilog_library")
1919
load(
@@ -33,6 +33,8 @@ verilog_library(
3333
name = "johnson_counter",
3434
srcs = [
3535
"johnson_counter.sv",
36+
],
37+
data = [
3638
"test.mem",
3739
],
3840
)
@@ -70,8 +72,10 @@ xsim_test(
7072
verilog_library(
7173
name = "johnson_counter_top",
7274
srcs = [
73-
"io_constraints.xdc",
7475
"johnson_counter_top.sv",
76+
],
77+
data = [
78+
"io_constraints.xdc",
7579
"zcu111_gpio.tcl",
7680
],
7781
deps = [
@@ -88,24 +92,31 @@ vivado_flow(
8892
xilinx_env = ":xilinx_env.sh",
8993
)
9094

91-
py_binary(
92-
name = "gen_values",
93-
srcs = ["gen_values.py"],
94-
)
95-
96-
genrule(
95+
write_file(
9796
name = "test_mem",
98-
outs = ["test.mem"],
99-
cmd = "$(location :gen_values) > $(OUTS)",
100-
tools = [":gen_values"],
97+
out = "test.mem",
98+
content = [
99+
"00",
100+
"05",
101+
"0A",
102+
"0F",
103+
"14",
104+
"19",
105+
"1E",
106+
"28",
107+
"",
108+
],
109+
newline = "unix",
101110
)
102111

103112
verilog_library(
104113
name = "weights_replay",
105114
srcs = [
106-
"test.mem",
107115
"weights_replay.sv",
108116
],
117+
data = [
118+
"test.mem",
119+
],
109120
)
110121

111122
verilator_cc_library(
@@ -131,6 +142,8 @@ verilog_library(
131142
name = "weights_replay_top",
132143
srcs = [
133144
"weights_replay_top.sv",
145+
],
146+
data = [
134147
"zcu111_weights.tcl",
135148
],
136149
)
@@ -194,7 +207,7 @@ vivado_create_ip(
194207

195208
verilog_library(
196209
name = "weights_replay_and_save_bd",
197-
srcs = [
210+
data = [
198211
"weights_replay_and_save_bd.tcl",
199212
],
200213
)

vivado/tests/gen_values.py

-12
This file was deleted.

0 commit comments

Comments
 (0)