Specman Secrets – Inline Text Expansion
Even though ‘e’ language documentation is quite well written, there are still some stuff either not described in the specifications, or described in just a few words. That’s a pity since, over time, I found out a lot of useful undocumented features of ‘e’ language.
The first one that I want to share with you is described with just a couple of words as “Inline Text Expansion”.
It allows you to write a string on multiple lines without any backslash (\) and it allows you to insert values in the string directly.
Here is an example:
1 2 3 4 5 6 | var my_number : uint = 10; var my_strings : list of string = << #: this is the first line my number is <(my_number)> end #; print my_strings; |
The output for this code is this:
1 2 | this is the first line my number is 10 |
Pretty cool, right?
You are probably thinking: where in the hell will I make use of this?
Well, the only place I found this very useful is when I had to build macros “as computed”. It makes the macro definition much more readable:
1 2 3 4 5 6 7 8 9 | define <evc_data_width'statement> "set_data_width in <evc'any> to <width'any>" as computed { return str_join(<< #: { extend <(str_upper(<evc'any>))>_DEFAULT cfs_<(str_lower(<evc'any>))>_agent_config { keep data_width == <(<width'any>)>; }; }; end #, ""); }; |
Calling the macro will look like this:
1 2 | set_data_width in APB to 16; set_data_width in AXI to 32; |
The resulting code will be:
1 2 3 4 5 6 7 | extend APB_DEFAULT cfs_apb_agent_config { keep data_width == 16; }; extend AXI_DEFAULT cfs_axi_agent_config { keep data_width == 32; }; |
Hope you found this useful!
