I am now developing a management unit that controls several IPs through corresponding control-fsm. These IPs are grouped in several group, and each group are controlled by one control-fsm. Thus I have a control_fsm_template and a ip_template, and in each control_fsm there is a parameter ip_list to record all IPs controlled by this FSM:
template control_fsm_template {
param ip_list : sequence (ip_template);
param ip_list default undefined;
method gm1() {
foreach ip in ip_list {
if (ip.p1) ip.m1();
}
}
}
template ip_template {
param p1;
param p2;
connect c1;
port c2;
method m1() {}
method m2() {}
}
group ip_1 is (ip_template);
group ip_2 is (ip_template);
group control_fsm1 is (control_fsm_template) {
param ip_list = [ip_1, ip_2];
}
group ip_3 is (ip_template);
group ip_4 is (ip_template);
group control_fsm2 is (control_fsm_template) {
param ip_list = [ip_3, ip_4];
}
DMLC reports error: error: not a value: [ip_1, ip_2]
And then I changed the code to:
template ip_group1_template is (ip_template);
template ip_group2_template is (ip_template);
group ip_1 is (ip_group1_tempalte);
group ip_2 is (ip_group1_template);
group control_fsm1 is (control_fsm_template) {
param ip_list = each ip_group1_template in (dev);
}
group ip_3 is (ip_group2_tempalte);
group ip_4 is (ip_group2_template);
group control_fsm2 is (control_fsm_template) {
param ip_list = each ip_group2_template in (dev);
}
Then DMLC reports error: error: wrong type in assignment got: list of trait ip_group1_template expect: list of trait ip_template
The problem in your first attempt is that
[]
lists are not true values; they are purely compile-time entities that only support three operations:#foreach
,#select
, and direct indexing with a constant; therefore you cannot assign them to a typed parameter. The only way to construct values of typesequence(X)
is currentlyeach .. in ..
expressions, as you correctly realized in your second attempt. The problem there is instead that DML doesn't offer a way to convert asequence(X)
into asequence(Y)
, even iftemplate Y is X
. This would be a valid feature request.The simplest solution is to use nested groups, so you can say collect all instances within a subhierarchy instead of
dev
: