Macros 使用宏约束列表

Macros 使用宏约束列表,macros,specman,Macros,Specman,我试图将列表项约束为在特定条件下等于特定值。 为此,我设计了一个define as computed宏 define <num_prob_constraints'struct_member> "CHECK_and_SET_CONSTRAINTS <lst'exp>" as computed { //var cur : list of uint = <lst'exp>.as_a(list of uint); var t : uint = &l

我试图将列表项约束为在特定条件下等于特定值。 为此,我设计了一个define as computed宏

define <num_prob_constraints'struct_member> "CHECK_and_SET_CONSTRAINTS <lst'exp>" as computed {

    //var cur : list of uint = <lst'exp>.as_a(list of uint);
    var t : uint =  <lst'exp>.as_a(list of uint).size(); 
    print t;
    for i from 1 to 4 {
        result = append(result,"keep ",<lst'exp>,"[",i,"]==",i,"=> ",<lst'exp>,"[",i,"]==389; \n");
    };
};
但这是行不通的。首先,它打印一些随机大小(来自宏),而不是列表的实际大小。 其次,我得到了这类错误:

*** Error: '1' is of type 'int', while expecting type 'list of int'.
                      in code generated by macro defined at line 3 in
        sports_sched_macro.e

    keep sched_w[1]==1=> sched_w[1]==389;
             expanded at line 8 in sports_sched.e
CHECK_and_SET_CONSTRAINTS sched_w;

对这里的错误有什么看法吗?

宏只是代码替代。它们的功能只是在解析阶段用另一个字符串(计算或不计算)替换某些字符串。 这意味着宏将部署在生成阶段之前的解析阶段中使用它的位置。因此,事实上,该列表还不存在,您无法访问它的大小和项目。 更具体地说,宏的部署方式如下:

struct schedule {
    n : uint;
    sched_w : list of list of int;
    keep sched_w[1]==2=> sched_w[1]==389;
    keep sched_w[2]==2=> sched_w[2]==389;   
    ...
    ...
};
收到的错误消息告诉您无法显式访问特定列表项(因为列表大小和项的值尚未确定)。 如果要将列表保留为大小4,并且如果值为2,则要将其替换为389,则可能需要使用post_generate()方法,因为您正在尝试访问已分配给列表项的值:

keep sched_w.size()==4;
post_generate() is also{
    for each in sched_w  {
        if (it==2) {it=389};    
    };
}; 

是否确实要约束二维列表?这看起来有点不同。例如,对于阵列计划[4][1]:

schedule: list of list of int;
keep schedule.size() == 4;
keep for each (sublist) in schedule {
   sublist.size() == 1;
   for each (elem) in sublist { 
      ...
   };
};
schedule: list of list of int;
keep schedule.size() == 4;
keep for each (sublist) in schedule {
   sublist.size() == 1;
   for each (elem) in sublist { 
      ...
   };
};