-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter as variable #58
Comments
Currently, all parameters get evaluated into constants and finalized at compile-time. Currently there is no way to "float" a parameter to the output. That said, I have considered adding this feature and do have some notes on how I would do it. If I have time, I may end up doing this. |
How difficult would this be to implement or how long would it take? If you give some pointers and if it's not too difficult I might be able to jump in and help 😛 |
I'm personally quite interested in this feature as well. I've spent the past couple of evenings working through some of the details in my personal logbook, and I think I have a plan for how to implement. Here's a quick summary of what I was thinking: Conceptually it would be pretty straightforward - Rather than providing a parameter value, the user would assign a placeholder object during top-level elaboration. This would "poison" the parameter and mark it as deferred. For example: rdlc.compile_file("abcd.rdl")
root = rdlc.elaborate(
parameters= {
"OTHER_PARAM": 1234,
"BASE_ADDR_C": SomeMagicObject(), # <-- Deferred Parameter
}
) When the user queries a component property, or other value that involves this parameter, the API would instead return an AST (Abstract Syntax Tree) object that represents the expression which defines the value. From your initial example, the "value" for
I would then provide a mechanism for "rendering" this AST back to text into a few common languages (Verilog, VHDL, SystemRDL, or a user-defined renderer) This approach has the advantage of making it possible for any parameter to become variable. I noticed the proprietary tool made by Agnysis accomplishes this by having the user mark such parameters in RDL using a Implementation of this is relatively straightforward since the compiler's existing expression mechanics will propagate this "poison" object naturally throughout the compiled design. The one major gotchya is that it touches/breaks a lot of existing things in elaboration & validation. A lot of the changes will simply involve adding bypasses, throwing error messages, to some more exotic scenarios. For example:
None of this is impossible. I just want to make sure I do it right :-). Let me know what you think! |
Sorry for the late response, I was pretty busy working on some other things last week. While your suggestion seems feasible, I don't think it will scale that well, and it does introduce a lot of edge cases.... Quite frankly I have been using your compiler as an export tool, and I haven't looked too deeply into the nook and crank of your implementation yet. However, when users use parameter passes down from parent to children, ex addrmap to reg and reg to field, your compiler seems to interpret the values correctly. Instead of intepreting the value into constant, Wouldn't there be a way to keep them as variable as a middle step before translating them into constant? |
Translating the resulting expression to an AST is exactly that - it is an intermediate representation that defers the elaboration of a value into a constant. Perhaps I am not understanding your comment. Could you provide more details on what you were thinking? |
Yes what I mean is the intermediate representation that defers the elaboration of a value into a constant, maybe I misunderstand your earlier comment a bit.
For example, if we use the compiler as an automation tool to read in input files and we don't know what parameters or how many parameters there are in the inputs, then this approach won't work. Is there a way that we can translate the resulting expresion to intermediate AST representation without asking users to specify parameters during top-level elaborate phase? Hope it makes sense... Again, I have not read into too much details on your implementation yet. Most of what I understand about your code is AFTER the input is already compiled 😛 |
I think I understand - you're saying that there should be a way to defer all top level parameters automatically. I can see how that is useful in some situations. Basically:
I'll think of a clean way to accomplish that (using the wildcard method above, or something else...) |
Or even more simply:
|
I'm thinking something along this way, not sure how to implement it though 😄, take the example below:
Right now, after compiled, mem1 object still have ROWS as parameter info, which is great. I think the parameter name is still reserved in the object it is declared. This information is lost when it goes down to data[ROWS], in order word it becomes data[34]. Again I do not know exactly where this information get resolved into constant, but if we can pass it down to
Then we can maintain the parameter as variable and still calculate the array size correctly. I have only encountered cases where Parameters pass down the hierarchy and use as array size in the children, so there prob are more cases where Parameters Variable can be used |
Yep! I think we're basically saying the same thing. |
Yup. I do need this feature eventually, might be soon 😓. If you decide to work on it, feel free to make a branch and add me as contributor. Once you have started, I should have an idea and can jump in to help you out. |
Initially I was going to ask about parameters, than I noticed there are several discussions already, so I joined this one. Since I can't really provide any suggestions, I will just list use cases I considered. I find the most practical use case would be generators for languages with parameterized types:
Most use cases would probably focus on handling integer values, but SystemRDL built in and user defined enumerations and structures are also useful. One example I would like to provide, is a parameter specifying whether a regfile contains configuration or status registers, actually more like TX versus RX:
The current compiler was handling this code well. Looking back, maybe not the best example for passing parameters into generated code, since this parameter would switch between inputs and outputs, which can't be parameterized in any of the above languages. |
Hello,
I want to ask if the compiler has the ability to extract the parameter name instead of turning them into constant after compiler. For the below example:
For the test1 address, is there a way to extract and know that this address is derived from BASE_ADDR_C + 8? as far as I understand, the compiler seems to resolve this into constant 8.
Thanks
The text was updated successfully, but these errors were encountered: