mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/asm: address feedback from code review.
This commit is contained in:
parent
223110a558
commit
4eda92569a
3 changed files with 7 additions and 8 deletions
|
|
@ -34,7 +34,7 @@ func main() {
|
|||
}
|
||||
code := strings.TrimSpace(string(in[:]))
|
||||
fmt.Printf("%v\n", code)
|
||||
err = asm.PrettyPrintDisassembledInstructions(code)
|
||||
err = asm.PrintDisassembled(code)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2014, 2017 The go-ethereum Authors
|
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
|
|
@ -28,8 +28,7 @@ import (
|
|||
func ForEachDisassembledInstruction(script []byte, fun func(uint64, vm.OpCode, []byte)) error {
|
||||
for pc := uint64(0); pc < uint64(len(script)); pc++ {
|
||||
op := vm.OpCode(script[pc])
|
||||
switch op {
|
||||
case vm.PUSH1, vm.PUSH2, vm.PUSH3, vm.PUSH4, vm.PUSH5, vm.PUSH6, vm.PUSH7, vm.PUSH8, vm.PUSH9, vm.PUSH10, vm.PUSH11, vm.PUSH12, vm.PUSH13, vm.PUSH14, vm.PUSH15, vm.PUSH16, vm.PUSH17, vm.PUSH18, vm.PUSH19, vm.PUSH20, vm.PUSH21, vm.PUSH22, vm.PUSH23, vm.PUSH24, vm.PUSH25, vm.PUSH26, vm.PUSH27, vm.PUSH28, vm.PUSH29, vm.PUSH30, vm.PUSH31, vm.PUSH32:
|
||||
if op.IsPush() {
|
||||
a := uint64(op) - uint64(vm.PUSH1) + 1
|
||||
u := pc + 1 + a
|
||||
if uint64(len(script)) <= pc || uint64(len(script)) < u {
|
||||
|
|
@ -37,7 +36,7 @@ func ForEachDisassembledInstruction(script []byte, fun func(uint64, vm.OpCode, [
|
|||
}
|
||||
fun(pc, op, script[pc+1:u])
|
||||
pc += a
|
||||
default:
|
||||
} else {
|
||||
fun(pc, op, make([]byte, 0))
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +44,7 @@ func ForEachDisassembledInstruction(script []byte, fun func(uint64, vm.OpCode, [
|
|||
}
|
||||
|
||||
// Pretty-print all disassembled EVM instructions to stdout.
|
||||
func PrettyPrintDisassembledInstructions(code string) error {
|
||||
func PrintDisassembled(code string) error {
|
||||
script, err := hex.DecodeString(code)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -61,7 +60,7 @@ func PrettyPrintDisassembledInstructions(code string) error {
|
|||
}
|
||||
|
||||
// Return all disassembled EVM instructions in human-readable format.
|
||||
func PrettyPrintedDisassembledInstructions(script []byte) ([]string, error) {
|
||||
func Disassemble(script []byte) ([]string, error) {
|
||||
instrs := make([]string, 0)
|
||||
err := ForEachDisassembledInstruction(script, func(pc uint64, op vm.OpCode, args []byte) {
|
||||
if args != nil && 0 < len(args) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2016 The go-ethereum Authors
|
||||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
|
|
|
|||
Loading…
Reference in a new issue