-
Notifications
You must be signed in to change notification settings - Fork 43
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
Constant propagation #324
Comments
Hi Manu!
This is planned but not yet implemented for LAL. It would be basically the equivalent of ASIS' data decomposition annex. Note that for ASIS, it will soon be implemented on top of gnat's -gnatr4js switch, and that's basically what will be used by Libadalang too (eg. we don't plan to reimplement that in LAL). Note that if you really need it, you can definitely emit and read the corresponding JSON files yourself! With help from Libadalang you should be able to map types and data representation info quite easily (hint: using LAL's
I'm not sure that's exactly what you're looking for, but Libadalang as a static expression evaluator, that might help you, and that is currently accessible via the Using it, you can eval constants. Note that:
Here is an example to get first and last values for a set of types, including one example where it will fail because the value is not statically known: procedure Test_Static_Eval is
type A is range 1 .. 1248;
High : constant := 583989 * 34;
type B is range A'First .. High;
High_2 : constant Positive := 28359;
type C is range 1 .. High_2;
procedure NonStatic (B : Integer) is
type D is range 1 .. B;
begin
null;
end NonStatic;
begin
null;
end Test_Static_Eval; And then using the playground on it: def eval_range(rc):
rng = rc.f_range.f_range
return rng.f_left.p_eval_as_int, rng.f_right.p_eval_as_int
for rc in u.root.findall(lal.SignedIntTypeDef):
try:
print(eval_range(rc))
except lal.PropertyError as p:
print("Cannot eval range for {}".format(rc.entity_repr))
print( "Exception:", p.message) |
Hi Raphael, |
I am working on a tool to automatically generate input/output from types declared in an Ada package. This includes binary output, for which we want to output the minimum number of bytes to contain all possible values of the type.
Is there any planned support in libadalang for either:
computing
'Size
for a type (not sure whether this might sometimes require backend knowledge, for instance when fields are reordered in a record -- I personally only care for scalar types but this feature would have to be more general in libadalang I guess)propagating constants, so that I can use the
range
information from the type declaration. Of course, the range might be the result of some computation, in particular involving constants from other parts of the code or even (sigh) from formal parameters.I also want to generate python versions of these input/output routines, so I cannot simply do the computation in the generated Ada code, but need some static value to pass to python.
Both of these seem far-fetched for libadalang, but I might as well ask :-)
The text was updated successfully, but these errors were encountered: