xls
xls copied to clipboard
[enhancement] Add proc-scoped constants
What's hard to do? (limit 100 words)
Currently, the only way to create a constant available in the entire proc's scope is by using a parameter with a default value. However, this exposes the parameter to user modification, which can lead to unintended behavior. It would be useful to define immutable constants that are accessible across the entire proc without risking alteration. The proc-scoped constants would be particularly useful when used for defining channels.
There are many cases in the examples when something that should be defined as a constant is defined as a parameter. Here is the DelayInternal
proc from the delay.x file:
proc DelayInternal<DATA_WIDTH:u32, DELAY:u32, INIT_DATA:u32={u32:0},
ADDR_WIDTH:u32={addr_width(half_floor(DELAY))},
DOUBLE_DATA_WIDTH:u32={double(DATA_WIDTH)},
HALF_FLOOR_DELAY:u32={half_floor(DELAY)}> {
data_in: chan<bits[DATA_WIDTH]> in;
data_out: chan<bits[DATA_WIDTH]> out;
ram_req: chan<RamReq<ADDR_WIDTH, DOUBLE_DATA_WIDTH, 0>> out;
ram_resp: chan<RamResp<DOUBLE_DATA_WIDTH>> in;
ram_wr_comp: chan<()> in;
In this case at least DOUBLE_DATA_WIDTH
and HALF_FLOOR_DELAY
should be defined as constants:
proc DelayInternal<DATA_WIDTH:u32, DELAY:u32, INIT_DATA:u32={u32:0},
ADDR_WIDTH:u32={addr_width(half_floor(DELAY))}> {
const DOUBLE_DATA_WIDTH = double(DATA_WIDTH);
const HALF_FLOOR_DELAY = half_floor(DELAY);
data_in: chan<bits[DATA_WIDTH]> in;
data_out: chan<bits[DATA_WIDTH]> out;
ram_req: chan<RamReq<ADDR_WIDTH, DOUBLE_DATA_WIDTH, 0>> out;
ram_resp: chan<RamResp<DOUBLE_DATA_WIDTH>> in;
ram_wr_comp: chan<()> in;
Current best alternative workaround (limit 100 words)
The desired behavior can be achieved by defining the same constant using the const
keyword in the init
, next
, and config
functions
Your view of the "best case XLS enhancement" (limit 100 words)
Allow proc-scoped const
declarations, similar to how proc-scoped type aliases are handled now