Skip to content

Commit ff8357c

Browse files
committed
sdc: error on unknown getters
1 parent 0aa2a4c commit ff8357c

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

passes/cmds/sdc/graph-stubs.sdc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
proc unknown {args} {
2+
# Check if it's a getter
3+
if {[llength $args] > 0} {
4+
set first_arg [lindex $args 0]
5+
if {[string match "get_*" $first_arg]} {
6+
# It's a getter, has it been redirected from specialized C++ code?
7+
if {[llength $args] > 1} {
8+
set second_arg [lindex $args 1]
9+
if {$second_arg ne "-getter-validated"} {
10+
error "Unknown getter: $first_arg"
11+
}
12+
} else {
13+
error "Unknown getter: $first_arg"
14+
}
15+
}
16+
}
17+
# TODO this safety feature could be optional via a global
18+
219
global sdc_call_index
320
global sdc_calls
421
if {![info exists sdc_call_index]} {
@@ -15,4 +32,11 @@ proc unknown {args} {
1532
}
1633
proc list {args} {
1734
return [unknown "list" {*}$args]
18-
}
35+
}
36+
proc get_clocks {args} {
37+
# get_clocks isn't a design object getter
38+
# because clocks aren't design objects, just aliases
39+
# so the referred to clock pin already are being tracked
40+
# as arguments of uninterpreted create_clock command or similar
41+
return [unknown "get_clocks" "-getter-validated" {*}$args]
42+
}

passes/cmds/sdc/sdc.cc

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,32 @@ static std::pair<bool, BitSelection> matches(std::string name, const std::string
344344
}
345345
}
346346

347-
static int graph_node(TclCall call) {
348-
// TODO is that it?
349-
return redirect_unknown(call);
347+
static int getter_graph_node(TclCall call) {
348+
// Insert -getter-validated as first argument for passing to unknown
349+
// to distinguish resolved and unknown getters.
350+
// For example, if call is ["get_foo", "-bar"]
351+
// then newCall is ["get_foo", "-getter-validated", "-bar"]
352+
Tcl_Obj* validity_tag = Tcl_NewStringObj("-getter-validated", -1);
353+
Tcl_IncrRefCount(validity_tag);
354+
std::vector<Tcl_Obj*> newObjv(call.objc + 1);
355+
log_assert(call.objc > 0);
356+
newObjv[0] = call.objv[0];
357+
newObjv[1] = validity_tag;
358+
for (int i = 1; i < call.objc; ++i) {
359+
newObjv[i + 1] = call.objv[i];
360+
}
361+
// Send the vector to the Tcl land
362+
Tcl_Obj** allocatedObjv = new Tcl_Obj*[call.objc + 1];
363+
for (int i = 0; i < call.objc + 1; ++i) {
364+
allocatedObjv[i] = newObjv[i];
365+
}
366+
TclCall newCall {
367+
.interp = call.interp,
368+
.objc = call.objc + 1,
369+
.objv = allocatedObjv
370+
};
371+
// Finally, redirect to unknown handler
372+
return redirect_unknown(newCall);
350373
}
351374

352375
static int redirect_unknown(TclCall call) {
@@ -610,7 +633,7 @@ static int sdc_get_pins_cmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_O
610633
const auto& pins = objects->design_pins;
611634
resolved = find_matching<SdcObjects::CellPin, decltype(pins)>(pins, config, opts.patterns, "pin");
612635

613-
return graph_node(TclCall{interp, objc, objv});
636+
return getter_graph_node(TclCall{interp, objc, objv});
614637
}
615638

616639
static int sdc_get_ports_cmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj* const objv[])
@@ -631,7 +654,7 @@ static int sdc_get_ports_cmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_
631654
merge_or_init(std::make_pair(name, wire), objects->constrained_ports, matching_bits);
632655
}
633656

634-
return graph_node(TclCall{interp, objc, objv});
657+
return getter_graph_node(TclCall{interp, objc, objv});
635658
}
636659

637660
static int sdc_get_nets_cmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj* const objv[])
@@ -652,7 +675,7 @@ static int sdc_get_nets_cmd(ClientData data, Tcl_Interp *interp, int objc, Tcl_O
652675
merge_or_init(std::make_pair(name, wire), objects->constrained_nets, matching_bits);
653676
}
654677

655-
return graph_node(TclCall{interp, objc, objv});
678+
return getter_graph_node(TclCall{interp, objc, objv});
656679
}
657680

658681
class SDCInterpreter

tests/sdc/get_foo.sdc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
get_foo -bar 1

tests/sdc/unknown-getter.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
not ../../yosys -p 'read_verilog alu_sub.v; proc; hierarchy -auto-top; sdc get_foo.sdc' 2>&1 | grep 'Unknown getter'

0 commit comments

Comments
 (0)