Skip to content

Commit b9824f3

Browse files
committed
Add listing opcodes. Resolves #3
1 parent 2803e73 commit b9824f3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

evmasm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@ def main():
1111
parser.add_argument('-d', '--disassemble', action='store_true', help='Disassemble EVM to opcodes')
1212
parser.add_argument('-i', '--input', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='Input file, default=stdin')
1313
parser.add_argument('-o', '--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout, help='Output file, default=stdout')
14+
parser.add_argument('-t', '--print-opcode-table', action='store_true', help='List supported EVM opcodes')
1415

1516
args = parser.parse_args(sys.argv[1:])
17+
18+
if args.print_opcode_table:
19+
table = EVMAsm._get_reverse_table()
20+
for mnemonic in table.keys():
21+
# This relies on the internal format
22+
(opcode, name, immediate_operand_size, pops, pushes, gas, description) = table[mnemonic]
23+
print("%02x: %-16s %s" % (opcode, mnemonic, description))
24+
25+
sys.exit(0)
26+
1627
if args.assemble and args.disassemble:
1728
print("You cannot both assemble and disassemble at the same time.")
1829
sys.exit(1)
@@ -23,9 +34,6 @@ def main():
2334
if args.assemble:
2435
asm = args.input.read().strip().rstrip()
2536
args.output.write(EVMAsm.assemble_hex(asm) + "\n")
26-
#insns = list(EVMAsm.assemble_all(asm))
27-
#for i in insns:
28-
# args.output.write(i)
2937

3038
if args.disassemble:
3139
buf = args.input.read().strip().rstrip()

0 commit comments

Comments
 (0)