Lawu
Lawu copied to clipboard
More downstream stuff
This gets entries for all of the various table attributes out of the AST.
For BootstrapMethods
, it unrolls the MethodHandle
constant. Admittedly I don't understand this recommendation 100%, but I don't have a good reason not to do it either. Constants are still rolled into all other attributes though, so let me know if I should be unrolling constants across the board. If that's the case we might want to look into a more universal to_attr
method or something.
A TableAttribute
base class is added
ReferenceKind
is now an IntEnum
Second commit does exactly what it says on the tin, which is very useful for searching methods for various instructions
for ins in code.find(f=lambda x: x.name in ('ldc', 'ldc_w'))
vs
for ins in code.find(name=('ldc','ldc_w'))
Wait, I'm dumb, this checks node names not name names. Reverting. I think this needs a better solution because this operation is super common and using a lambda feels clunky.
dmittedly I don't understand this recommendation 100%, but I don't have a good reason not to do it either.
The lawu.constants
types are tightly tied to their binary representation, and will be the first thing moved into C/Cython (parsing constants takes the 2nd most time after simple zipfile IO). The AST can come from anywhere, such as Jasmin [which we already have a lexer for and used to have a parser for], as well as Soot's 3 intermediate representations.
I'll probably re-organize the files a bit, such as moving lawu.constants
into lawu.cf.constants
to make it clear it's for writing/parsing binary ClassFiles.
The reason why I'm trying to keep all the constants unpacked in the AST is to make transformation easier. Constants are a pain, because you can't just edit what you're on, such as an ldc
instruction, but also have to clone the constant, or ensure all other references to that constant are okay with the change as well. Some sources like Jasmin don't have a concept of a pool until assembled.
Keep in mind all of this is "alpha" stage, so if you have better suggestions feel free to bring them up :)
That makes perfect sense, I'll have the other attributes unroll constants as well