algorand / algorand/go-algorand

Make disassembler dead code aware

Open
#4,486 1 comment 0 reactions 0 assignees View on GitHub
Team Scytale
Dominant language
Go
Stars
1.4k
Forks
537
Avg merge
1d 7h
Merged PRs (30d)
18

Description

## 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 https://github.com/algorand/go-algorand/pull/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.