jnc100 wrote:The main difficulty with parsing AML where potential forward references come in is that in order to correctly parse method calls you need to know how many parameters the method has, and this is not defined at the call site but rather the declaration site which may be much further along the byte stream.
3a) If a method definition is encountered then store a method definition in the hash table, along with the start and end offsets of the code and the number of parameters, but do not try and do anything else with the methods code (e.g. tokenize it before it is called), simply skip over it and continue
3b) Similarly for if-else statements, skip over the bits which aren't called.
So i've followed your suggestions, i'm removing my tree type structure and going with a flat table + hash, i can see the simplicity of it which is great.
I'm going a similar route with method declaration.. but..
i'm still not 100% sure on how to handle these IF type blocks..
Code: Select all
Name(SS0,0)
Method(BOB)
{
Store(SS0,Arg0)
}
Bob(10)
If(SS1 < 10)
{
Name(SS2,0)
}
Else
{
Name(SS2,1)
}
Name(SS1,15)
Given the above, assuming a single pass.. we get to the If SS1 code.. SS1 isn't defined yet, so we have no way of knowing if it's less than 10.. it would be wrong to assume it is 0 because then we're going to create an entry for SS2=0 and the If block will execute and the Else will be skipped. Then we declare SS1 but it's too late now to evaluate the If.
option 1) If the expression evaluation finds any undefined/unresolved symbol in the predicate.. simply skip the ENTIRE IF/ELSE block.. mark that we need another pass.. and repeat.. the problem with that is that certain code is likely to be executed twice .. like the Method call to Bob.. which may or may not be a problem, but it's not right to call it twice.. alternative
2) do the same as 1 but ONLY allocate entries in the symbol table on the initial passes don't actually execute anything at all until ALL symbols are defined/resolved... but even that is a bit suspect because the execution of the code may be absolutely required to define symbols.
this would all have been so much easier if IASL simply generated a proper bytecode instead of AML.. a virtual set of registers,stack,flags and a bunch of opcodes.. which you just execute.. all data(address relative to AML start) or whatever compiled down into a .data or .bss type section in the bytecode..