Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make disassembler dead code aware #4486

Open
michaeldiamant opened this issue Aug 30, 2022 · 1 comment
Open

Make disassembler dead code aware #4486

michaeldiamant opened this issue Aug 30, 2022 · 1 comment

Comments

@michaeldiamant
Copy link
Contributor

Problem

The disassembler makes a best-effort attempt to annotate intc references with the associated literal value to improve human readability.

Since the disassembler is not dead code aware, it leads to annotated comments that are obviously wrong. Consider the following snippet:

	ops = testProg(t, `
target:
int 1
b skip
intcblock 10
retsub
callsub target
int 1
int 1
+
skip:
int 10 
int 1
+
`, AssemblerMaxVersion)
	text, err = Disassemble(ops.Program)
	require.NoError(t, err)
	fmt.Printf("%v\n", text)

As of #4442, the output incorrectly shows intc_0 // 10 instead of intc_0 // 1:

#pragma version 8
intcblock 1
label2:
intc_0 // 1
b label1
intcblock 10
retsub
callsub label2
intc_0 // 10
intc_0 // 10
+
label1:
pushint 10
intc_0 // 10
+

A direct response to the problem at-hand is to extend the disassembler to account for dead code, which fixes the example's comments.

Additionally, it may make sense to consider if there are more general rules / changes to consider for disassembly.

Solution

Dependencies

Urgency

@michaeldiamant michaeldiamant changed the title Make diassembler dead code aware Make disassembler dead code aware Aug 30, 2022
@jannotti
Copy link
Contributor

This deserves fixing, but another problem probably can't be fixed - In the face of arbitrary conditional code, and the presence of multiple non-deadcode cblocks, the disassembler should know that it might be confused and probably stop spitting out the comments at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants