Can I instantiate modules inside an if loop? Basically I want to instantiate some modules only if some condition holds true. If I can't do it, what is the workaround? Thanks.
the answer to your question is "no". That wouldn't make sense. instances of modules describe hardware. If you have a module, the best you can do is to have some logic that interacts with the inputs/outputs of the module.
That said, you can use "generates" to instantiate modules based on constants/generics/parameters. Keep in mind that _constant_ means "does not change during operation".