1

in my verification environment I have different registers' types with almost the same name that differs only by index, e.g.: timer_load_0, timer_load_1 etc.. I try to create a macro that gets 2 parameters: string (the 'name' of the register without its index) and uint (the register's index) and returns a variable of "concatenated" register type. For example I would like that the command:

my_idx : uint = 0;
create_reg "timer_load" my_idx;

will return the variable timer_load_0.

My macro code:

define <var_by_idx'action> "create_reg <name'any> <idx'exp>" as computed {
    var idx : uint = <idx'exp>.as_a(uint);
    result = appendf("%s_%d",<name'any>, idx);  
};

The compilation error I get:

Error: Looking for a number but found 'my_idx'
                at line 45 in @macros
    var idx : uint = <idx'exp>.as_a(uint);
                during execution of a define-as-computed macro:
                at line 380 in @timer_monitor
            create_reg "timer_load" my_idx;

The macro does not recognize my_idx as uint variable but as string.. Thank you for any help.

Halona
  • 1,475
  • 1
  • 15
  • 26
  • 1
    It's not clear what exactly you're trying to achieve by this macro. In general, a DAC macro is executed during parsing (not at run time), and it should usually return some string, which contains some legal e code, and which is further parsed. In this example, I don't see the macro returns any string. Could you please clarify what exactly are you trying to do here? What is expected to happen at run time? – Yuri Tsoglin Sep 22 '14 at 09:28
  • 1
    Hi Yuri, I've edited my question with fixes according to your notes – Halona Sep 23 '14 at 06:36
  • 1
    I think I kind of get what you want to do here from the questions you've been previously asking. You probably have the same field defined in both sub-types and you just need to cast to be able to access it. You could use reflection in this case, but it's going to be costlier in terms of run-time performance, I think. – Tudor Timi Sep 23 '14 at 09:33
  • If that's the case, then maybe you could post another question with some more context. – Tudor Timi Sep 23 '14 at 09:40

1 Answers1

2

A macro that does what you want can only be passed a constant value, so you would need to change back to <idx'num>.

As Yuri mentioned, define as computed macros are expanded at compile time. This means your macro needs to get a constant value for idx to know what type of variable to allocate for your created_reg. The value of the idx variable you would want to pass to the macro is only set at run-time, which is just too late.

Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • 1
    Hi Tudor, I've edited the question and i've fixed the code with as_a(uint), but I still has compilation error.. – Halona Sep 23 '14 at 06:37
  • 1
    @Halona I just realized that what you want is impossible, because you need to know at compile time what sub-type you want (TIMER_LOAD_0 or TIMER_LOAD_1). You can't use a variable for this. – Tudor Timi Sep 23 '14 at 09:20
  • Even if the macro was used with a constant (such as 'create_reg "timer_load" 1'), it's still not clear what's the expected outcome. The macro is declared to be , but 'timer_load_1' is not an action. So, what should it actually do? Declare a field? Declare a local variable? Anything else? – Yuri Tsoglin Sep 23 '14 at 11:33
  • @YuriTsoglin I think he wants to get a certain register instance from a reg file and then cast it to a certain sub-type and store it in a variable of that type. – Tudor Timi Sep 23 '14 at 13:43