Following a forking code path in a Harmony transpiler

Started by sparr, December 01, 2018, 07:59:00 PM

Previous topic - Next topic

sparr

In the implementation of a transpiler I am looking at a particular CodeInstruction. From that point, I want to follow the code forward through every possible code path until I reach a return, and process instructions found along the way. I do not want to proceed to code that can't be reached during execution from my starting point. I think this means I need to handle every possible type of branching opcode, such as Br*, Ble* Blt*, Bge*, Bgt*, etc, as well as more complex things like Switch. This is a wheel I would particularly dislike to reinvent, if someone else has written a helper for it. Is there something like this?

LWM

It's entirely possible that approaching this from a slightly different angle might be useful...  Can you give a better idea of what you mean by "want to follow the code forward?"

--LWM

sparr

I want to find every `return X` that could be reached during execution starting at a specific point, and modify X.

LWM

Harmony Postfix()?

Alternately, if you only want to change the value after a certain point in the code:
Look for the branching target labels.  Before your cutoff, leave them alone.  After your cutoff, set them all to a new branch point.  Then when the code reaches the original branch label (presumably "return"), put that instruction aside, output your branch label and instructions, and then give the return branch label back.  Would that work?

--LWM