Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
9381d571
Commit
9381d571
authored
Dec 11, 2020
by
aniket-engg
Committed by
Aniket
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codeResolver and codeUtils updated
parent
137b6a7c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
29 deletions
+33
-29
codeResolver.ts
libs/remix-debug/src/code/codeResolver.ts
+21
-16
codeUtils.ts
libs/remix-debug/src/code/codeUtils.ts
+12
-13
No files found.
libs/remix-debug/src/code/codeResolver.ts
View file @
9381d571
'use strict'
const
codeUtils
=
require
(
'./codeUtils'
)
function
CodeResolver
({
getCode
})
{
this
.
getCode
=
getCode
export
class
CodeResolver
{
getCode
bytecodeByAddress
instructionsByAddress
instructionsIndexByBytesOffset
constructor
({
getCode
})
{
this
.
getCode
=
getCode
this
.
bytecodeByAddress
=
{}
// bytes code by contract addesses
this
.
instructionsByAddress
=
{}
// assembly items instructions list by contract addesses
this
.
instructionsIndexByBytesOffset
=
{}
// mapping between bytes offset and instructions index.
}
}
CodeResolver
.
prototype
.
clear
=
function
()
{
clear
()
{
this
.
bytecodeByAddress
=
{}
this
.
instructionsByAddress
=
{}
this
.
instructionsIndexByBytesOffset
=
{}
}
}
CodeResolver
.
prototype
.
resolveCode
=
async
function
(
address
)
{
async
resolveCode
(
address
)
{
const
cache
=
this
.
getExecutingCodeFromCache
(
address
)
if
(
cache
)
{
return
cache
...
...
@@ -23,22 +29,22 @@ CodeResolver.prototype.resolveCode = async function (address) {
const
code
=
await
this
.
getCode
(
address
)
return
this
.
cacheExecutingCode
(
address
,
code
)
}
}
CodeResolver
.
prototype
.
cacheExecutingCode
=
function
(
address
,
hexCode
)
{
cacheExecutingCode
(
address
,
hexCode
)
{
const
codes
=
this
.
formatCode
(
hexCode
)
this
.
bytecodeByAddress
[
address
]
=
hexCode
this
.
instructionsByAddress
[
address
]
=
codes
.
code
this
.
instructionsIndexByBytesOffset
[
address
]
=
codes
.
instructionsIndexByBytesOffset
return
this
.
getExecutingCodeFromCache
(
address
)
}
}
CodeResolver
.
prototype
.
formatCode
=
function
(
hexCode
)
{
formatCode
(
hexCode
)
{
const
[
code
,
instructionsIndexByBytesOffset
]
=
codeUtils
.
nameOpCodes
(
Buffer
.
from
(
hexCode
.
substring
(
2
),
'hex'
))
return
{
code
,
instructionsIndexByBytesOffset
}
}
}
CodeResolver
.
prototype
.
getExecutingCodeFromCache
=
function
(
address
)
{
getExecutingCodeFromCache
(
address
)
{
if
(
!
this
.
instructionsByAddress
[
address
])
{
return
null
}
...
...
@@ -47,10 +53,9 @@ CodeResolver.prototype.getExecutingCodeFromCache = function (address) {
instructionsIndexByBytesOffset
:
this
.
instructionsIndexByBytesOffset
[
address
],
bytecode
:
this
.
bytecodeByAddress
[
address
]
}
}
}
CodeResolver
.
prototype
.
getInstructionIndex
=
function
(
address
,
pc
)
{
getInstructionIndex
(
address
,
pc
)
{
return
this
.
getExecutingCodeFromCache
(
address
).
instructionsIndexByBytesOffset
[
pc
]
}
}
module
.
exports
=
CodeResolver
libs/remix-debug/src/code/codeUtils.ts
View file @
9381d571
'use strict'
const
opcodes
=
require
(
'./opcodes'
)
module
.
exports
=
{
nameOpCodes
:
function
(
raw
)
{
export
function
nameOpCodes
(
raw
)
{
let
pushData
=
''
const
codeMap
=
{}
const
code
=
[]
...
...
@@ -18,19 +17,19 @@ module.exports = {
i
+=
jumpNum
}
const
data
=
pushData
.
toString
(
'hex'
)
!==
''
?
' '
+
pushData
.
toString
(
'hex'
)
:
''
const
data
=
pushData
.
toString
()
!==
''
?
' '
+
pushData
.
toString
(
)
:
''
code
.
push
(
this
.
pad
(
pc
,
this
.
roundLog
(
raw
.
length
,
10
))
+
' '
+
curOpCode
+
data
)
pushData
=
''
}
return
[
code
,
codeMap
]
},
}
/**
/**
* Parses code as a list of integers into a list of objects containing
* information about the opcode.
*/
parseCode
:
function
(
raw
)
{
export
function
parseCode
(
raw
)
{
const
code
=
[]
for
(
let
i
=
0
;
i
<
raw
.
length
;
i
++
)
{
const
opcode
=
opcodes
(
raw
[
i
],
true
)
...
...
@@ -48,19 +47,19 @@ module.exports = {
code
.
push
(
opcode
)
}
return
code
},
}
pad
:
function
(
num
,
size
)
{
export
function
pad
(
num
,
size
)
{
let
s
=
num
+
''
while
(
s
.
length
<
size
)
s
=
'0'
+
s
return
s
},
}
log
:
function
(
num
,
base
)
{
export
function
log
(
num
,
base
)
{
return
Math
.
log
(
num
)
/
Math
.
log
(
base
)
},
}
roundLog
:
function
(
num
,
base
)
{
export
function
roundLog
(
num
,
base
)
{
return
Math
.
ceil
(
this
.
log
(
num
,
base
))
}
}
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