Hello All,
I am trying to add a method that expands a macro to the preprocessor, however I am facing some issues.
So, let's call this new method: ExpandMacro, it is used whenever a macro is called.Now, what ExpandMacro doing is:
- Search for the macro definition in 'preprocess_data_.macro_definitions'
- Feed the found 'PP_define_body' token to the lexer (VerilogLexer)
- Append the new lexed tokens to 'preprocess_data_.preprocessed_token_stream' token stream, instead of the 'PP_define_body'
The test case:`define FIRST a`define SECOND bmodule m;wire `FIRST;wire `SECOND;endmoduleResult:Both macros are expanded to b.If we remove 'wire `SECOND;' line, then `FIRST is expanded to a.The problem:Filling a TokenStreamView ( 'preprocess_data_.preprocessed_token_stream' in this case) with const::iterators of 2 different TokenSequence objects, the original text corresponds to the SV code, and the new TokenSequence created from the new lexed tokens in ExpandMacro
It seems that for different calls of ExpandMacro, it creates new lexed TokenInfo with the same reference, so it overrides the values that are pointed to by the previous iterators of the previous call.I am not sure, if that's the correct problem cause, can you help me on this a bit?Thanks,
Karim
--
You received this message because you are subscribed to the Google Groups "Verible Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to verible-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/verible-dev/1ddf7147-2728-4585-b8ec-bee54b38ea79n%40googlegroups.com.
Now I don't actually know why the token sequence points to iterators of tokens and does not contain TokenInfo directly; it sounds like an unnecessary indirection, but maybe David (CC'ed) can shed light on that.
--It seems that for different calls of ExpandMacro, it creates new lexed TokenInfo with the same reference, so it overrides the values that are pointed to by the previous iterators of the previous call.I am not sure, if that's the correct problem cause, can you help me on this a bit?Thanks,
Karim--
You received this message because you are subscribed to the Google Groups "Verible Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to verible-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/verible-dev/1ddf7147-2728-4585-b8ec-bee54b38ea79n%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Verible Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to verible-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/verible-dev/b734cf48-3fcc-4111-a381-edc373fe457dn%40googlegroups.com.
No, what does it mean to have its memory backed? Sorry
I thought i might need to save it in the MacroDefiniton itself, it will be more efficient in case there are many macro calls.
To view this discussion on the web visit https://groups.google.com/d/msgid/verible-dev/322f2555-445c-4a63-b849-ec13df692561n%40googlegroups.com.
On Wed, 6 Apr 2022 at 17:08, Karim Tera <karim...@gmail.com> wrote:No, what does it mean to have its memory backed? Sorry
I thought i might need to save it in the MacroDefiniton itself, it will be more efficient in case there are many macro calls.Yes, storing it in the MacroDefinition sounds good. With 'memory backed' I just mean that the iterators you hand out need to point to something that is still there when someone is dereferencing them.So keeping it in the MacroDefinition is the right approach. One thing to be aware of is that if you insert more MacroDefinitions, the map might re-alloc memory, which might copy the values around - so you need to make sure that the memory your iterators are pointing to is still the same. Typically, the values are std::move'ed so this might be fine but being aware what is happening in that case is good.