diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-11 07:47:57 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-11 07:47:57 +0800 |
commit | 583e690b7a028c85809a8be2c7afe3b65264adbe (patch) | |
tree | bc7ba2fe96833633455daaebf44d7382d0e20b7d /packages/sol-tracing-utils/src/instructions.ts | |
parent | a516b00a0397a567fd233bd955206d46321cc178 (diff) | |
parent | a5b7a351609a5e6689bb97990216153f64302462 (diff) | |
download | dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.gz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.bz2 dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.lz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.xz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.zst dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.zip |
Merge branch 'development' into fix/dev-tools-pages/finalTouches
* development: (49 commits)
upgrade to ddex api v3 (#1507)
Add new deployment related instructions to pipeline README (#1499)
feature: implement logging and friendly wallet name for Opera
Fix prettier
Add missing dependencies
Remove second yarn call
Add .gitkeep
Rename sol-trace-based-tools-common to sol-tracing-utils
Update packages/sol-trace/README.md
Update packages/sol-trace/CHANGELOG.json
Update packages/sol-trace-based-tools-common/src/source_maps.ts
Update packages/sol-trace-based-tools-common/CHANGELOG.json
Update packages/sol-profiler/CHANGELOG.json
Update packages/sol-coverage/CHANGELOG.json
Update packages/monorepo-scripts/src/test_installation.ts
chore: changelog update
fix: account for undefined errors in promisify, not only null
Clean up docs before publish
In README's, don't mention non-existent tests (#1497)
fix: use getBackendBaseUrl instead of hardcoded string
...
Diffstat (limited to 'packages/sol-tracing-utils/src/instructions.ts')
-rw-r--r-- | packages/sol-tracing-utils/src/instructions.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/sol-tracing-utils/src/instructions.ts b/packages/sol-tracing-utils/src/instructions.ts new file mode 100644 index 000000000..40987dbe5 --- /dev/null +++ b/packages/sol-tracing-utils/src/instructions.ts @@ -0,0 +1,23 @@ +import { constants } from './constants'; + +const isPush = (inst: number) => inst >= constants.PUSH1 && inst <= constants.PUSH32; + +const pushDataLength = (inst: number) => inst - constants.PUSH1 + 1; + +const instructionLength = (inst: number) => (isPush(inst) ? pushDataLength(inst) + 1 : 1); + +export const getPcToInstructionIndexMapping = (bytecode: Uint8Array) => { + const result: { + [programCounter: number]: number; + } = {}; + let byteIndex = 0; + let instructionIndex = 0; + while (byteIndex < bytecode.length) { + const instruction = bytecode[byteIndex]; + const length = instructionLength(instruction); + result[byteIndex] = instructionIndex; + byteIndex += length; + instructionIndex += 1; + } + return result; +}; |