Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
330e53fb
Unverified
Commit
330e53fb
authored
May 16, 2022
by
s7v7nislands
Committed by
GitHub
May 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/asm: use strings.Builder and fix godoc issues (#24861)
parent
fcbc05cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
asm.go
core/asm/asm.go
+9
-9
compiler.go
core/asm/compiler.go
+5
-5
lexer.go
core/asm/lexer.go
+1
-1
No files found.
core/asm/asm.go
View file @
330e53fb
...
...
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Provides support for dealing with EVM assembly instructions (e.g., disassembling them).
// P
ackage asm p
rovides support for dealing with EVM assembly instructions (e.g., disassembling them).
package
asm
import
(
...
...
@@ -34,14 +34,14 @@ type instructionIterator struct {
started
bool
}
//
C
reate a new instruction iterator.
//
NewInstructionIterator c
reate a new instruction iterator.
func
NewInstructionIterator
(
code
[]
byte
)
*
instructionIterator
{
it
:=
new
(
instructionIterator
)
it
.
code
=
code
return
it
}
//
R
eturns true if there is a next instruction and moves on.
//
Next r
eturns true if there is a next instruction and moves on.
func
(
it
*
instructionIterator
)
Next
()
bool
{
if
it
.
error
!=
nil
||
uint64
(
len
(
it
.
code
))
<=
it
.
pc
{
// We previously reached an error or the end.
...
...
@@ -79,27 +79,27 @@ func (it *instructionIterator) Next() bool {
return
true
}
//
R
eturns any error that may have been encountered.
//
Error r
eturns any error that may have been encountered.
func
(
it
*
instructionIterator
)
Error
()
error
{
return
it
.
error
}
//
R
eturns the PC of the current instruction.
//
PC r
eturns the PC of the current instruction.
func
(
it
*
instructionIterator
)
PC
()
uint64
{
return
it
.
pc
}
//
R
eturns the opcode of the current instruction.
//
Op r
eturns the opcode of the current instruction.
func
(
it
*
instructionIterator
)
Op
()
vm
.
OpCode
{
return
it
.
op
}
//
R
eturns the argument of the current instruction.
//
Arg r
eturns the argument of the current instruction.
func
(
it
*
instructionIterator
)
Arg
()
[]
byte
{
return
it
.
arg
}
// Pretty-print all disassembled EVM instructions to stdout.
// Pr
intDisassembled pr
etty-print all disassembled EVM instructions to stdout.
func
PrintDisassembled
(
code
string
)
error
{
script
,
err
:=
hex
.
DecodeString
(
code
)
if
err
!=
nil
{
...
...
@@ -117,7 +117,7 @@ func PrintDisassembled(code string) error {
return
it
.
Error
()
}
//
Return
all disassembled EVM instructions in human-readable format.
//
Disassemble returns
all disassembled EVM instructions in human-readable format.
func
Disassemble
(
script
[]
byte
)
([]
string
,
error
)
{
instrs
:=
make
([]
string
,
0
)
...
...
core/asm/compiler.go
View file @
330e53fb
...
...
@@ -39,7 +39,7 @@ type Compiler struct {
debug
bool
}
//
n
ewCompiler returns a new allocated compiler.
//
N
ewCompiler returns a new allocated compiler.
func
NewCompiler
(
debug
bool
)
*
Compiler
{
return
&
Compiler
{
labels
:
make
(
map
[
string
]
int
),
...
...
@@ -105,16 +105,16 @@ func (c *Compiler) Compile() (string, []error) {
}
// turn the binary to hex
var
bin
string
var
bin
string
s
.
Builder
for
_
,
v
:=
range
c
.
binary
{
switch
v
:=
v
.
(
type
)
{
case
vm
.
OpCode
:
bin
+=
fmt
.
Sprintf
(
"%x"
,
[]
byte
{
byte
(
v
)}
)
bin
.
WriteString
(
fmt
.
Sprintf
(
"%x"
,
[]
byte
{
byte
(
v
)})
)
case
[]
byte
:
bin
+=
fmt
.
Sprintf
(
"%x"
,
v
)
bin
.
WriteString
(
fmt
.
Sprintf
(
"%x"
,
v
)
)
}
}
return
bin
,
errors
return
bin
.
String
()
,
errors
}
// next returns the next token and increments the
...
...
core/asm/lexer.go
View file @
330e53fb
...
...
@@ -93,7 +93,7 @@ type lexer struct {
debug
bool
// flag for triggering debug output
}
//
l
ex lexes the program by name with the given source. It returns a
//
L
ex lexes the program by name with the given source. It returns a
// channel on which the tokens are delivered.
func
Lex
(
source
[]
byte
,
debug
bool
)
<-
chan
token
{
ch
:=
make
(
chan
token
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment