Skip to content

Commit bb49b1f

Browse files
authored
Merge pull request #8 from LeeKaiXuan/main
Support bit-selects
2 parents 7201d01 + 50e2a52 commit bb49b1f

21 files changed

+420
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include ${PSS_HOME}/samples/Make.vars
2+
3+
gentarget:
4+
$(PSSGEN) test.pss -o test.s -root pss_top::root_a || true
5+
6+
clean:
7+
rm -f test.s result.log
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*!
2+
@weakgroup test
3+
@{
4+
@file
5+
@author Luther Lee
6+
@data 2023/08/15
7+
@brief Test <i>bit-select</i> primary expressions.
8+
@version
9+
Portable Test and Stimulus Standard Version 2.0 <br>
10+
> Section 9.6 : Primary expressions <br>
11+
> Section 9.6.1 : Bit-selects and part-selects <br>
12+
13+
14+
---------------------------------------------------------------------------------------------------
15+
16+
### Test Command
17+
@code{.unparsed}
18+
make gentarget
19+
@endcode
20+
*/
21+
component pss_top {
22+
action root_a {
23+
bit [8] byte_0 = 8 'b0011_0011;
24+
bit [8] byte_1 = 8 'b0110_0110;
25+
bit [8] byte_2 = 8 'b1100_1100;
26+
bit [8] byte_3 = 8 'b1001_1001;
27+
bit [8] byte_4 = 8 'b0010_0010;
28+
29+
exec post_solve {
30+
byte_0[1] = 0;
31+
byte_1[3] = 2'b10;
32+
byte_2[1] = byte_2[2];
33+
byte_3[2] |= byte_3[3];
34+
byte_4 |= byte_4[1];
35+
}
36+
37+
exec body ASM =
38+
"""
39+
byte_0 = {{byte_0}} = {{byte_0[7]}}{{byte_0[6]}}{{byte_0[5]}}{{byte_0[4]}}{{byte_0[3]}}{{byte_0[2]}}{{byte_0[1]}}{{byte_0[0]}}
40+
byte_1 = {{byte_1}} = {{byte_1[7]}}{{byte_1[6]}}{{byte_1[5]}}{{byte_1[4]}}{{byte_1[3]}}{{byte_1[2]}}{{byte_1[1]}}{{byte_1[0]}}
41+
byte_2 = {{byte_2}} = {{byte_2[7]}}{{byte_2[6]}}{{byte_2[5]}}{{byte_2[4]}}{{byte_2[3]}}{{byte_2[2]}}{{byte_2[1]}}{{byte_2[0]}}
42+
byte_3 = {{byte_3}} = {{byte_3[7]}}{{byte_3[6]}}{{byte_3[5]}}{{byte_3[4]}}{{byte_3[3]}}{{byte_3[2]}}{{byte_3[1]}}{{byte_3[0]}}
43+
byte_4 = {{byte_4}} = {{byte_4[7]}}{{byte_4[6]}}{{byte_4[5]}}{{byte_4[4]}}{{byte_4[3]}}{{byte_4[2]}}{{byte_4[1]}}{{byte_4[0]}}
44+
""";
45+
}
46+
}
47+
48+
/**@}*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
byte_0 = 49 = 00110001
3+
byte_1 = 110 = 01101110
4+
byte_2 = 206 = 11001110
5+
byte_3 = 157 = 10011101
6+
byte_4 = 35 = 00100011
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include ${PSS_HOME}/samples/Make.vars
2+
3+
gentarget:
4+
$(PSSGEN) test.pss -o test.s -root pss_top::root_a || true
5+
6+
clean:
7+
rm -f test.s result.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*!
2+
@weakgroup test
3+
@{
4+
@file
5+
@author Luther Lee
6+
@data 2023/08/23
7+
@brief Test <i>index operator</i> `[]` applied to array.
8+
@version
9+
Portable Test and Stimulus Standard Version 2.0 <br>
10+
> Section 8.8 : Collections <br>
11+
> Section 8.8.2 : Arrays <br>
12+
> Section 8.8.2.1 : Array operators <br>
13+
> Section 9.6 : Primary expressions <br>
14+
> Section 9.6.2 : Selecting an element from a collection (indexing) <br>
15+
16+
17+
---------------------------------------------------------------------------------------------------
18+
19+
### Test Command
20+
@code{.unparsed}
21+
make gentarget
22+
@endcode
23+
*/
24+
component pss_top {
25+
action root_a {
26+
bit [4] nibbleArray_0 [3] = {4'b1100, 4'b0110, 4'b0011};
27+
array<bit [4], 3> nibbleArray_1 = {4'b1100, 4'b0110, 4'b0011};
28+
bit [4] nibble_0_0 = 4'b0001;
29+
bit [4] nibble_0_1 = 4'b0010;
30+
bit [4] nibble_0_2 = 4'b0100;
31+
bit [4] nibble_1_0 = 4'b0001;
32+
bit [4] nibble_1_1 = 4'b0010;
33+
bit [4] nibble_1_2 = 4'b0100;
34+
35+
exec post_solve {
36+
nibbleArray_0[0] = 4'b0110;
37+
nibbleArray_0[1] = nibbleArray_0[2];
38+
nibbleArray_0[2] |= nibbleArray_0[0];
39+
40+
nibbleArray_1[0] = 4'b0110;
41+
nibbleArray_1[1] = nibbleArray_1[2];
42+
nibbleArray_1[2] |= nibbleArray_1[0];
43+
44+
nibble_0_0 = nibbleArray_0[0];
45+
nibble_0_1 = nibbleArray_0[1];
46+
nibble_0_2 = nibbleArray_0[2];
47+
48+
nibble_1_0 = nibbleArray_1[0];
49+
nibble_1_1 = nibbleArray_1[1];
50+
nibble_1_2 = nibbleArray_1[2];
51+
}
52+
53+
exec body ASM =
54+
"""
55+
nibble_0_0 = {{nibble_0_0}} = {{nibble_0_0[3]}}{{nibble_0_0[2]}}{{nibble_0_0[1]}}{{nibble_0_0[0]}}
56+
nibble_0_1 = {{nibble_0_1}} = {{nibble_0_1[3]}}{{nibble_0_1[2]}}{{nibble_0_1[1]}}{{nibble_0_1[0]}}
57+
nibble_0_2 = {{nibble_0_2}} = {{nibble_0_2[3]}}{{nibble_0_2[2]}}{{nibble_0_2[1]}}{{nibble_0_2[0]}}
58+
nibble_1_0 = {{nibble_1_0}} = {{nibble_1_0[3]}}{{nibble_1_0[2]}}{{nibble_1_0[1]}}{{nibble_1_0[0]}}
59+
nibble_1_1 = {{nibble_1_1}} = {{nibble_1_1[3]}}{{nibble_1_1[2]}}{{nibble_1_1[1]}}{{nibble_1_1[0]}}
60+
nibble_1_2 = {{nibble_1_2}} = {{nibble_1_2[3]}}{{nibble_1_2[2]}}{{nibble_1_2[1]}}{{nibble_1_2[0]}}
61+
""";
62+
}
63+
}
64+
65+
/**@}*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
nibble_0_0 = 6 = 0110
3+
nibble_0_1 = 3 = 0011
4+
nibble_0_2 = 7 = 0111
5+
nibble_1_0 = 6 = 0110
6+
nibble_1_1 = 3 = 0011
7+
nibble_1_2 = 7 = 0111
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include ${PSS_HOME}/samples/Make.vars
2+
3+
gentarget:
4+
$(PSSGEN) test.pss -o test.s -root pss_top::root_a || true
5+
6+
clean:
7+
rm -f test.s result.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*!
2+
@weakgroup test
3+
@{
4+
@file
5+
@author Luther Lee
6+
@data 2023/08/23
7+
@brief Test <i>index operator</i> `[]` applied to list.
8+
@version
9+
Portable Test and Stimulus Standard Version 2.0 <br>
10+
> Section 8.8 : Collections <br>
11+
> Section 8.8.3 : Lists <br>
12+
> Section 8.8.3.1 : List operators <br>
13+
> Section 9.6 : Primary expressions <br>
14+
> Section 9.6.2 : Selecting an element from a collection (indexing) <br>
15+
16+
17+
---------------------------------------------------------------------------------------------------
18+
19+
### Test Command
20+
@code{.unparsed}
21+
make gentarget
22+
@endcode
23+
*/
24+
component pss_top {
25+
action root_a {
26+
list<bit [4]> nibbleList_0 = {4'b1100, 4'b0110, 4'b0011};
27+
bit [4] nibble_0_0 = 4'b0001;
28+
bit [4] nibble_0_1 = 4'b0010;
29+
bit [4] nibble_0_2 = 4'b0100;
30+
31+
exec post_solve {
32+
nibbleList_0[0] = 4'b0110;
33+
nibbleList_0[1] = nibbleList_0[2];
34+
nibbleList_0[2] |= nibbleList_0[0];
35+
36+
nibble_0_0 = nibbleList_0[0];
37+
nibble_0_1 = nibbleList_0[1];
38+
nibble_0_2 = nibbleList_0[2];
39+
}
40+
41+
exec body ASM =
42+
"""
43+
nibble_0_0 = {{nibble_0_0}} = {{nibble_0_0[3]}}{{nibble_0_0[2]}}{{nibble_0_0[1]}}{{nibble_0_0[0]}}
44+
nibble_0_1 = {{nibble_0_1}} = {{nibble_0_1[3]}}{{nibble_0_1[2]}}{{nibble_0_1[1]}}{{nibble_0_1[0]}}
45+
nibble_0_2 = {{nibble_0_2}} = {{nibble_0_2[3]}}{{nibble_0_2[2]}}{{nibble_0_2[1]}}{{nibble_0_2[0]}}
46+
""";
47+
}
48+
}
49+
50+
/**@}*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
nibble_0_0 = 6 = 0110
3+
nibble_0_1 = 3 = 0011
4+
nibble_0_2 = 7 = 0111
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include ${PSS_HOME}/samples/Make.vars
2+
3+
gentarget:
4+
$(PSSGEN) test.pss -o test.s -root pss_top::root_a || true
5+
6+
clean:
7+
rm -f test.s result.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*!
2+
@weakgroup test
3+
@{
4+
@file
5+
@author Luther Lee
6+
@data 2023/08/23
7+
@brief Test <i>index operator</i> `[]` applied to map.
8+
@version
9+
Portable Test and Stimulus Standard Version 2.0 <br>
10+
> Section 8.8 : Collections <br>
11+
> Section 8.8.4 : Maps <br>
12+
> Section 8.8.4.1 : Map operators <br>
13+
> Section 9.6 : Primary expressions <br>
14+
> Section 9.6.2 : Selecting an element from a collection (indexing) <br>
15+
16+
17+
---------------------------------------------------------------------------------------------------
18+
19+
### Test Command
20+
@code{.unparsed}
21+
make gentarget
22+
@endcode
23+
*/
24+
component pss_top {
25+
action root_a {
26+
map<string, bit [4]> nibbleMap_0 = {"ONE": 4'b1100, "TWO": 4'b0110};
27+
bit [4] nibble_0_0 = 4'b0010;
28+
bit [4] nibble_0_1 = 4'b0100;
29+
bit [4] nibble_0_2 = 4'b1000;
30+
31+
exec post_solve {
32+
nibbleMap_0["ONE"] = 4'b0001;
33+
nibbleMap_0["TWO"] |= nibbleMap_0["ONE"];
34+
nibbleMap_0["THREE"] = nibbleMap_0["ONE"] + nibbleMap_0["ONE"] + nibbleMap_0["ONE"];
35+
36+
nibble_0_0 = nibbleMap_0["ONE"];
37+
nibble_0_1 = nibbleMap_0["TWO"];
38+
nibble_0_2 = nibbleMap_0["THREE"];
39+
}
40+
41+
exec body ASM =
42+
"""
43+
nibble_0_0 = {{nibble_0_0}} = {{nibble_0_0[3]}}{{nibble_0_0[2]}}{{nibble_0_0[1]}}{{nibble_0_0[0]}}
44+
nibble_0_1 = {{nibble_0_1}} = {{nibble_0_1[3]}}{{nibble_0_1[2]}}{{nibble_0_1[1]}}{{nibble_0_1[0]}}
45+
nibble_0_2 = {{nibble_0_2}} = {{nibble_0_2[3]}}{{nibble_0_2[2]}}{{nibble_0_2[1]}}{{nibble_0_2[0]}}
46+
""";
47+
}
48+
}
49+
50+
/**@}*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
nibble_0_0 = 1 = 0001
3+
nibble_0_1 = 7 = 0111
4+
nibble_0_2 = 3 = 0011
5+

Diff for: samples/Make.vars

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ ANTLR4_JAR_PATH = ${PSS_HOME}/antlr4/antlr-4.9.3-complete.jar
33
PSSGEN_JAR_PATH = ${PSS_HOME}/src/pssgen.jar
44
PSSGEN = java -classpath $(PSSGEN_JAR_PATH):$(ANTLR4_JAR_PATH) PSSGenMain -info
55

6-
6+
.SILENT: test
77
test: gentarget
88
diff test.s test.s.golden; \
99
diff=$$?; \
1010
if [ $$diff -eq 0 ]; then \
11+
echo "Test Result: PASS"; \
1112
echo PASS >| result.log; \
1213
else \
14+
echo "Test Result: FAIL"; \
1315
echo FAIL >| result.log; \
14-
fi
16+
fi
1517

1618
clean:
1719
rm -f test.s result.log

Diff for: src/PSSActionModel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public void evalPreSolve(PSSInst inst) {
9898
}
9999

100100
public void evalPostSolve(PSSInst inst) {
101-
for (int i=0; i<m_exec_list.size(); i++) {
101+
PSSMessage.Info("evalPostSolve");
102+
for (int i = 0; i < m_exec_list.size(); i++) {
102103
PSSExecBlock block = m_exec_list.get(i);
103104
if (block.getKind().equals(PSSExecKind.post_solve)) {
104105
block.eval(inst);

Diff for: src/PSSArrayInst.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public PSSIntInst size() {
165165
public PSSIntInst sum() {
166166
if (!(m_elem_type_model instanceof PSSIntModel))
167167
PSSMessage.Error("ArrayInst",
168-
"Array.sum() is only used on Int type.");
168+
"Array.sum() is only used on `int` or `bit` type.");
169169

170170
int sum = 0;
171171
for (PSSVal e : toVal().getValList())

0 commit comments

Comments
 (0)