Skip to content

Commit dead2aa

Browse files
committed
sdc: add -keep_hierarchy test
1 parent e341bbb commit dead2aa

File tree

8 files changed

+157
-5
lines changed

8 files changed

+157
-5
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ MK_TEST_DIRS += tests/arch/xilinx
890890
MK_TEST_DIRS += tests/bugpoint
891891
MK_TEST_DIRS += tests/opt
892892
MK_TEST_DIRS += tests/sat
893+
MK_TEST_DIRS += tests/sdc
893894
MK_TEST_DIRS += tests/sim
894895
MK_TEST_DIRS += tests/svtypes
895896
MK_TEST_DIRS += tests/techmap

tests/sdc/alu_sub.sdc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
###############################################################################
2+
# Created by write_sdc
3+
# Fri Oct 3 11:26:00 2025
4+
###############################################################################
5+
current_design wrapper
6+
###############################################################################
7+
# Timing Constraints
8+
###############################################################################
9+
create_clock -name this_clk -period 1.0000 [get_ports {clk}]
10+
create_clock -name that_clk -period 2.0000
11+
create_clock -name another_clk -period 2.0000 \
12+
[list [get_ports {A[0]}]\
13+
[get_ports {A[1]}]\
14+
[get_ports {A[2]}]\
15+
[get_ports {A[3]}]\
16+
[get_ports {A[4]}]\
17+
[get_ports {A[5]}]\
18+
[get_ports {A[6]}]\
19+
[get_ports {A[7]}]\
20+
[get_ports {B[0]}]\
21+
[get_ports {B[1]}]\
22+
[get_ports {B[2]}]\
23+
[get_ports {B[3]}]\
24+
[get_ports {B[4]}]\
25+
[get_ports {B[5]}]\
26+
[get_ports {B[6]}]\
27+
[get_ports {B[7]}]]
28+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[0]}]
29+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[0]}]
30+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[1]}]
31+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[1]}]
32+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[2]}]
33+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[2]}]
34+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[3]}]
35+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[3]}]
36+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[4]}]
37+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[4]}]
38+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[5]}]
39+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[5]}]
40+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[6]}]
41+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[6]}]
42+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {A[7]}]
43+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {A[7]}]
44+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[0]}]
45+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[0]}]
46+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[1]}]
47+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[1]}]
48+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[2]}]
49+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[2]}]
50+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[3]}]
51+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[3]}]
52+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[4]}]
53+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[4]}]
54+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[5]}]
55+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[5]}]
56+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[6]}]
57+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[6]}]
58+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -rise -min -add_delay [get_ports {B[7]}]
59+
set_input_delay 1.0000 -clock [get_clocks {this_clk}] -fall -min -add_delay [get_ports {B[7]}]
60+
group_path -name operation_group\
61+
-through [list [get_nets {alu/operation[0]}]\
62+
[get_nets {alu/operation[1]}]\
63+
[get_nets {alu/operation[2]}]\
64+
[get_nets {alu/operation[3]}]]
65+
###############################################################################
66+
# Environment
67+
###############################################################################
68+
###############################################################################
69+
# Design Rules
70+
###############################################################################

tests/sdc/alu_sub.v

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
module adder(
2+
input [7:0] a, input [7:0] b, output [7:0] y
3+
);
4+
assign y = a + b;
5+
endmodule
6+
7+
module wrapper(
8+
input clk,
9+
input [7:0] A,
10+
input [7:0] B,
11+
input [3:0] op,
12+
output reg [7:0] result
13+
);
14+
wire CF, ZF, SF;
15+
alu alu(
16+
.clk(clk),
17+
.A(A),
18+
.B(B),
19+
.operation(op),
20+
.result(result),
21+
.CF(CF),
22+
.ZF(ZF),
23+
.SF(SF)
24+
);
25+
endmodule
26+
27+
module alu(
28+
input clk,
29+
input [7:0] A,
30+
input [7:0] B,
31+
input [3:0] operation,
32+
output reg [7:0] result,
33+
output reg CF,
34+
output reg ZF,
35+
output reg SF
36+
);
37+
38+
localparam ALU_OP_ADD /* verilator public_flat */ = 4'b0000;
39+
localparam ALU_OP_SUB /* verilator public_flat */ = 4'b0001;
40+
41+
reg [8:0] tmp;
42+
reg [7:0] added;
43+
44+
adder adder(.a(A), .b(B), .y(added));
45+
46+
always @(posedge clk)
47+
begin
48+
case (operation)
49+
ALU_OP_ADD :
50+
tmp = added;
51+
ALU_OP_SUB :
52+
tmp = A - B;
53+
endcase
54+
55+
CF <= tmp[8];
56+
ZF <= tmp[7:0] == 0;
57+
SF <= tmp[7];
58+
59+
result <= tmp[7:0];
60+
end
61+
endmodule
62+

tests/sdc/alu_sub.ys

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
read_verilog alu_sub.v
2+
proc
3+
hierarchy -auto-top
4+
5+
select -assert-mod-count 1 adder
6+
select -assert-mod-count 1 wrapper
7+
select -assert-mod-count 1 alu
8+
9+
sdc -keep_hierarchy alu_sub.sdc
10+
flatten
11+
12+
select -assert-mod-count 0 adder
13+
select -assert-mod-count 1 wrapper
14+
select -assert-mod-count 1 alu

tests/sdc/run-test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
source ../gen-tests-makefile.sh
4+
generate_mk --yosys-scripts --bash

tests/sdc/side-effects.sdc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
puts "This should print something:"
2+
puts [get_ports {A[0]}]

tests/sdc/side-effects.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
../../yosys -p 'read_verilog alu_sub.v; proc; hierarchy -auto-top; sdc side-effects.sdc' | grep 'This should print something:
4+
YOSYS_SDC_MAGIC_NODE_0'

tests/various/sdc.sdc

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)