then it's fairly obvious that the second branch is actually branch-always. The same would seem to apply to a situation like:
label0 lda #$00
beq label1
However, because of self-modifying code (i.e. a write to label0+1), that's not necessarily the case. The opposite may also be true:
label0 lda #$00
bne label1
The BNE appears to be branch-never, but might not be. In some cases we actually want a branch-always, but SourceGen can't figure it out:
lda mem_addr
bne label1
If we know that the address in question never holds a zero value, then we know that the branch is branch-always.
The way to handle these issues in SourceGen is to override the appropriate status flag on the branch statement, changing it so that the value correctly reflects the program's behavior. In the above examples, the 'Z' flag would be altered. To make the change, the user needs to know which flag needs to be adjusted, and to which value the flag should be set.
We could make this a little easier by adding "make branch indeterminate" and "make branch branch-always" actions, but this situation isn't usually common enough to warrant a menu item, much less multiple items. We could instead add button to the status flag override dialog that would mark the appropriate flag.
Each flag can have one of four values: default, zero, one, or indeterminate. We already have "Reset to Default", which resets all flags to "default" (which means the value is set by the code analyzer). We could have additional buttons that are only enabled for branch instructions:
Mark Branch as Branch-Always
Mark Branch as Indeterminate
I don't think we need a button for branch-never, but we could add it for completeness. Clicking the button would update the flag and immediately close the dialog to save an extra click, or could just adjust the radio buttons to make it clear what effect the button has. The buttons could be hidden for non-branch instructions, or greyed out (probably the latter).
Another option would be simply highlighting the flag column, but that doesn't help figure out what e.g. setting it to zero means. We could present the four options (default, always, never, indeterminate) in a pop-up menu, which would be more compact than individual buttons, but slower to work with.
It might be helpful to display what the current behavior is, e.g. "branch always" or "branch sometimes".
If you have a situation like:
then it's fairly obvious that the second branch is actually branch-always. The same would seem to apply to a situation like:
However, because of self-modifying code (i.e. a write to
label0+1
), that's not necessarily the case. The opposite may also be true:The
BNE
appears to be branch-never, but might not be. In some cases we actually want a branch-always, but SourceGen can't figure it out:If we know that the address in question never holds a zero value, then we know that the branch is branch-always.
The way to handle these issues in SourceGen is to override the appropriate status flag on the branch statement, changing it so that the value correctly reflects the program's behavior. In the above examples, the 'Z' flag would be altered. To make the change, the user needs to know which flag needs to be adjusted, and to which value the flag should be set.
We could make this a little easier by adding "make branch indeterminate" and "make branch branch-always" actions, but this situation isn't usually common enough to warrant a menu item, much less multiple items. We could instead add button to the status flag override dialog that would mark the appropriate flag.
Each flag can have one of four values: default, zero, one, or indeterminate. We already have "Reset to Default", which resets all flags to "default" (which means the value is set by the code analyzer). We could have additional buttons that are only enabled for branch instructions:
I don't think we need a button for branch-never, but we could add it for completeness. Clicking the button would update the flag and immediately close the dialog to save an extra click, or could just adjust the radio buttons to make it clear what effect the button has. The buttons could be hidden for non-branch instructions, or greyed out (probably the latter).
Another option would be simply highlighting the flag column, but that doesn't help figure out what e.g. setting it to zero means. We could present the four options (default, always, never, indeterminate) in a pop-up menu, which would be more compact than individual buttons, but slower to work with.
It might be helpful to display what the current behavior is, e.g. "branch always" or "branch sometimes".