-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The instructionCounter slot in instruction facts is used to define the order. Rules that inline instructions can insert instructions into methods by creating new counters using addition (instructionCounter+1 etc). To facilitate this, extracted facts use a fixed offset of 100. I.e. an instruction with a counter value of 300 is followed by an instruction with a counter value of 400 etc. This is hardcoded in some rules (example: to remove duplicated checkcast:
REMOVED_INSTRUCTION(..,methodid,instructioncounter) :-
CHECKCAST(factid1,methodid,instructioncounter,desc),
CHECKCAST(factid2,methodid,instructioncounter-100,desc).
It is also hardcoded in the Java code building the EDB from ASM nodes. It would be better to have this configurable, e.g. when long methods (> 100 instructions) are to be inlined.
A dedicated predicate INSTRUCTION_COUNTER_OFFSET(offset) could be defined for this purpose, with a single fact INSTRUCTION_COUNTER_OFFSET(100). This fact would be generated with the EDB from a constant defined in DALEQ. This value could even be set with a CLI argument.
Rules would then look like this:
REMOVED_INSTRUCTION(..,methodid,instructioncounter) :-
CHECKCAST(factid1,methodid,instructioncounter,desc),
CHECKCAST(factid2,methodid,instructioncounter-offset,desc),
INSTRUCTION_COUNTER_OFFSET(offset).