Closed crackleeeessyp closed 3 months ago
ExpandMacros Make changes OptimizeMacros
No. This will require a full iteration of the entire method body.
AsmResolver has this expansion and optimization of macros built in via the ExpandMacros
and OptimizeMacros
methods. A typical workflow for editing method bodies is as follows:
MethodDefinition method = ...;
var instructions = method.CilMethodBody.Instructions;
// Expand all instructions (including branches) in a method body to their long forms.
instructions.ExpandMacros();
/* ... Make your changes ... */
// Optimize all instructions (including branches) to their short forms where possible.
instructions.OptimizeMacros();
Thanks all for your help, will have a try~
@crackleeeessyp can I consider this issue solved?
How easy would it be for AsmResolver to switch the op code when writing instead of throwing an exception? Is that a solution you would be comfortable with?
@ds5678 I am not a fan of it as it introduces an asymmetry. It would mean short branches would be promoted automatically, but long branches definitely should not be (i.e., it is perfectly valid to have "short long branches" so AsmResolver should be able to write them as well). Besides, I don't think it would be contributing to the comprehensibility/predictability of how the library behaves (i.e., I predict questions such as "why are my instructions/method bodies updating without me explicitly stating so?")
All good 👍
@crackleeeessyp can I consider this issue solved?
Thanks, I think so, use ExpandMacros solved the problem!
Description
When adding instructions within a method, I encounter an error stating:
Branch target at IL_00xx is too far away for a ShortInlineBr instruction.
Is there a more efficient solution to address this issue, rather than iterating through all the instructions in the body and replacing each short 'br' branch instruction with a long one?