Search code examples
simicsdml-lang

How to iterate over the unmapped registers of a bank in DML 1.4?


I am trying to migrate some modules to DML 1.4 and I face some problems during bank content iteration. Specifically, I originally have the snippet below:

select reg in ($signals.unmapped_registers) where (reg.signal_number == signal) {
    // some statements here
} else {
    log "unimplemented", 1: "Power/Board: Signal %d is unimplemented", signal;
    return;
}

However, unmapped_registers is not valid in DML 1.4, thus leading to an unknown identifier compiler error.

How am I supposed to iterate over all the unmapped registers of a specific bank in DML 1.4 and select the one I want based on some specific criteria (i.e. the signal_number parameter)?

I've already tried swapping the select statement with foreach without success.

I've also tried to iterate over all bank registers that instantiate a specific template, but still without success.


Solution

  • You need to foreach over a template that has signal_number as type member.

    When you iterate using foreach, the iteration variable is a run-time template reference, which means that not all declarations of the template can be accessed: Only parameters with a declared explicit type belong to the template type (together with all method declarations annotated with shared, and most session and saved declarations). So in your case, your problem is likely that signal_number does not have a declared type.

    If you add a parameter type like this:

    template register_with_signal is register {
      param signal_number : int;
      // default assignment must be a separate declaration
      param signal_number default -1;
      ...
    }
    

    then you can implement your loop like this:

    method handle_signal(int signal) {
        foreach reg in (each register_with_signal in (this)) {
            if (reg.signal_number == signal) {
                // some statements here
                return;
            }
        }
        log unimpl: "signal %d is unimplemented", signal;
    }