Skip to content

Commit

Permalink
Add a passthrough example
Browse files Browse the repository at this point in the history
This commit adds a simple proc that forwards the received
information from an input channel to an output channel.

Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
  • Loading branch information
rw1nkler committed May 23, 2024
1 parent 3b61ec9 commit 907a62b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
26 changes: 26 additions & 0 deletions xls/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,29 @@ filegroup(
srcs = glob(["*.x"]),
visibility = ["//xls:xls_internal"],
)

xls_dslx_library(
name = "passthrough_dslx",
srcs = [
"passthrough.x",
],
)

xls_dslx_test(
name = "passthrough_dslx_test",
srcs = ["passthrough.x"],
deps = [":passthrough_dslx"],
)

xls_dslx_verilog(
name = "passthrough_verilog",
codegen_args = {
"module_name": "passthrough",
"delay_model": "unit",
"pipeline_stages": "1",
"reset": "rst",
},
dslx_top = "Passthrough",
library = "passthrough_dslx",
verilog_file = "passthrough.sv",
)
58 changes: 58 additions & 0 deletions xls/examples/passthrough.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// A simple proc that forwards the received information from
// an input channel to an output channel.

import std;

proc Passthrough {
data_r: chan<u32> in;
data_s: chan<u32> out;

config(data_r: chan<u32> in, data_s: chan<u32> out) { (data_r, data_s) }

init { () }

next(tok: token, state: ()) {
let (tok, data) = recv(tok, data_r);
let tok = send(tok, data_s, data);
}
}

#[test_proc]
proc PassthroughTest {
terminator: chan<bool> out;
data_s: chan<u32> out;
data_r: chan<u32> in;

config(terminator: chan<bool> out) {
let (data_s, data_r) = chan<u32>("data");
spawn Passthrough(data_r, data_s);
(terminator, data_s, data_r)
}

init { u32:10 }

next(tok: token, count: u32) {
let data_to_send = count * count;
let tok = send(tok, data_s, data_to_send);
let (tok, received_data) = recv(tok, data_r);

assert_eq(data_to_send, received_data);
send_if(tok, terminator, count == u32:0, true);

count - u32:1
}
}

0 comments on commit 907a62b

Please sign in to comment.