2

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.

ggiakoum
  • 23
  • 2

2 Answers2

1

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;
}
Erik Carstensen
  • 634
  • 4
  • 14
  • What I was actually missing was the separate declaration, as well as the instantiation of the register template by the equivalent of register_with_signal. – ggiakoum Jan 17 '23 at 16:07
  • Actually the 'is register' part is not needed, you only need it if you want to access the standard register members from the foreach body. For instance, if all you need in the loop is `reg.set` and `reg.get`, then you can say `is (get, set)` instead, this consumes a bit less memory. – Erik Carstensen Jan 18 '23 at 15:18
  • I need to access the offset member which is part of the register template, so in my case the instantiation of the register template is required. – ggiakoum Jan 19 '23 at 11:28
0

I also faced with this issue. Here is solution that i found:

foreach reg in (this._each_register) {
    if (reg.offset == unmapped_offset) { // constant unmapped_offset = 0xffff_ffff_ffff_ffff;
        <some actions for UNMAPPED regs>
    }
}
odenysex
  • 25
  • 2