-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
dslx.scroll
63 lines (51 loc) · 2.17 KB
/
dslx.scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import ../code/conceptPage.scroll
id dslx
name dslx
appeared 2020
tags pl
conceptDescription DSLX is a domain specific, functional language to build hardware that can also run effectively as host software. The DSL targets the XLS compiler (by conversion to XLS IR) to enable flows for FPGAs and ASICs (note that other frontends will become available in the future). DSLX mimics Rust, while being an immutable expression-based dataflow DSL with hardware-oriented features; e.g. arbitrary bitwidths, entirely fixed size objects, fully analyzeable call graph, etc. To avoid arbitrary new syntax/semantics choices the DSL mimics Rust where it is reasonably possible; for example, integer conversions all follow the same semantics as Rust.
country United States
originCommunity Google
reference https://google.github.io/xls/dslx_reference/
example
fn cast_to_array(x: u6) -> u2[3] {
x as u2[3]
}
fn cast_from_array(a: u2[3]) -> u6 {
a as u6
}
fn concat_arrays(a: u2[3], b: u2[3]) -> u2[6] {
a ++ b
}
test cast_to_array {
let a_value: u6 = u6:0b011011;
let a: u2[3] = cast_to_array(a_value);
let a_array = u2[3]:[1, 2, 3];
let _ = assert_eq(a, a_array);
// Note: converting back from array to bits gives the original value.
let _ = assert_eq(a_value, cast_from_array(a));
let b_value: u6 = u6:0b111001;
let b_array: u2[3] = u2[3]:[3, 2, 1];
let b: u2[3] = cast_to_array(b_value);
let _ = assert_eq(b, b_array);
let _ = assert_eq(b_value, cast_from_array(b));
// Concatenation of bits is analogous to concatenation of their converted
// arrays. That is:
//
// convert(concat(a, b)) == concat(convert(a), convert(b))
let concat_value: u12 = a_value ++ b_value;
let concat_array: u2[6] = concat_value as u2[6];
let _ = assert_eq(concat_array, concat_arrays(a_array, b_array));
// Show a few classic "endianness" example using 8-bit array values.
let x = u32:0xdeadbeef;
let _ = assert_eq(x as u8[4], u8[4]:[0xde, 0xad, 0xbe, 0xef]);
let y = u16:0xbeef;
let _ = assert_eq(y as u8[2], u8[2]:[0xbe, 0xef]);
()
}
lineCommentToken //
hasLineComments true
// A comment
hasComments true
// A comment
hasSemanticIndentation false