How can I specify instruction pattern simplifications? #5227
-
|
Compilers often use a series of instructions to accomplish high-level operations, which often called instruction idioms or patterns. PowerPC for example, has an entire guide for compiler writers on how to implement common operations on their architecture https://cr.yp.to/2005-590/powerpc-cwg.pdf I notice that ghidra often has a hard time understanding these instruction patterns. For example I would want the pattern (Figure 3-52) (and ideally any equivalent data flow) to create a single INT2FLOAT pcode that converts I am new to ghidra, so what would be an appropriate way to implement this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
What you would need to do is lie down, try not to cry and then cry a lot. The only way to do this is to add a decompiler rule specifically for it. This requires modification of the decompiler native code and since the decompiler is not extendable at runtime in any way, there is no way for you to provide the changes to others without providing ghidra in its entirety. You could open a pull request and wait forever (decompiler changes are almost never even reviewed). Something very processor specifically would be unlikely to be accepted either. I know this is definitely what nobody wants to hear but I'm just calling it how I see it. |
Beta Was this translation helpful? Give feedback.
-
|
First of all, sorry for the late response. While working with Ghidra's decompiler output, I also noticed that it's often quite unclear how a function's decompiled representation came to be. Additionally, writing the simplification rules used by the decompiler is quite verbose, which also makes it harder to understand what a rule is doing. To alleviate this, I started work on 2 tools that I have already found quite helpful. I'm linking them here, hoping they might assist you in understanding and improving the behaviour of Ghidra's decompiler.
While I've already used both tools, and they have been of help to me, they are still in development. As such, don't hesitate to create issues on their repo's if you are using the programs and you find any bugs / anything that could be improved. |
Beta Was this translation helpful? Give feedback.

What you would need to do is lie down, try not to cry and then cry a lot. The only way to do this is to add a decompiler rule specifically for it. This requires modification of the decompiler native code and since the decompiler is not extendable at runtime in any way, there is no way for you to provide the changes to others without providing ghidra in its entirety. You could open a pull request and wait forever (decompiler changes are almost never even reviewed). Something very processor specifically would be unlikely to be accepted either.
I know this is definitely what nobody wants to hear but I'm just calling it how I see it.