Added memory-like support and new opcodes to asm.
This commit is contained in:
parent
83db8a6bd1
commit
6fd3bb62d1
@ -591,11 +591,16 @@ export class ScopeNode extends LabelledNode {
|
|||||||
export type Operation = {
|
export type Operation = {
|
||||||
opcode: Opcode;
|
opcode: Opcode;
|
||||||
offset: number;
|
offset: number;
|
||||||
|
length: number;
|
||||||
pushValue?: string;
|
pushValue?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Bytecode extends Array<Operation> {
|
export interface Bytecode extends Array<Operation> {
|
||||||
getOperation(offset: number): Operation;
|
getOperation(offset: number): Operation;
|
||||||
|
getByte(offset: number): number;
|
||||||
|
getBytes(offset: number, length: number): Uint8Array;
|
||||||
|
byteLength: number;
|
||||||
|
operationCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function disassemble(bytecode: string): Bytecode {
|
export function disassemble(bytecode: string): Bytecode {
|
||||||
@ -616,7 +621,8 @@ export function disassemble(bytecode: string): Bytecode {
|
|||||||
|
|
||||||
const op: Operation = {
|
const op: Operation = {
|
||||||
opcode: opcode,
|
opcode: opcode,
|
||||||
offset: i
|
offset: i,
|
||||||
|
length: 1
|
||||||
};
|
};
|
||||||
offsets[i] = op;
|
offsets[i] = op;
|
||||||
ops.push(op);
|
ops.push(op);
|
||||||
@ -628,6 +634,7 @@ export function disassemble(bytecode: string): Bytecode {
|
|||||||
const data = ethers.utils.hexlify(bytes.slice(i, i + push));
|
const data = ethers.utils.hexlify(bytes.slice(i, i + push));
|
||||||
if (ethers.utils.hexDataLength(data) === push) {
|
if (ethers.utils.hexDataLength(data) === push) {
|
||||||
op.pushValue = data;
|
op.pushValue = data;
|
||||||
|
op.length += push;
|
||||||
i += push;
|
i += push;
|
||||||
} else {
|
} else {
|
||||||
oob = true;
|
oob = true;
|
||||||
@ -636,9 +643,34 @@ export function disassemble(bytecode: string): Bytecode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(<Bytecode>ops).getOperation = function(offset: number): Operation {
|
(<Bytecode>ops).getOperation = function(offset: number): Operation {
|
||||||
|
if (offset >= bytes.length) {
|
||||||
|
return {
|
||||||
|
opcode: Opcode.from("STOP"),
|
||||||
|
offset: offset,
|
||||||
|
length: 1
|
||||||
|
};
|
||||||
|
}
|
||||||
return (offsets[offset] || null);
|
return (offsets[offset] || null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(<Bytecode>ops).getByte = function(offset: number): number {
|
||||||
|
if (offset >= bytes.length) {
|
||||||
|
return 0x00;
|
||||||
|
}
|
||||||
|
return bytes[offset];
|
||||||
|
};
|
||||||
|
|
||||||
|
(<Bytecode>ops).getBytes = function(offset: number, length: number): Uint8Array {
|
||||||
|
const result = new Uint8Array(length);
|
||||||
|
result.fill(0);
|
||||||
|
if (offset < bytes.length) {
|
||||||
|
result.set(bytes.slice(offset));
|
||||||
|
}
|
||||||
|
return ethers.utils.arrayify(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
(<Bytecode>ops).byteLength = bytes.length;
|
||||||
|
|
||||||
return (<Bytecode>ops);
|
return (<Bytecode>ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +145,8 @@ const _Opcodes: { [ name: string ]: _Opcode } = {
|
|||||||
number: { value: 0x43, delta: 0, alpha: 1, doc: "blockNumber = number" },
|
number: { value: 0x43, delta: 0, alpha: 1, doc: "blockNumber = number" },
|
||||||
difficulty: { value: 0x44, delta: 0, alpha: 1, doc: "diff = difficulty" },
|
difficulty: { value: 0x44, delta: 0, alpha: 1, doc: "diff = difficulty" },
|
||||||
gaslimit: { value: 0x45, delta: 0, alpha: 1, doc: "gas = gaslimit" },
|
gaslimit: { value: 0x45, delta: 0, alpha: 1, doc: "gas = gaslimit" },
|
||||||
|
chainid: { value: 0x46, delta: 0, alpha: 1, doc: "chainid = chainid" },
|
||||||
|
selfbalance: { value: 0x47, delta: 0, alpha: 1, doc: "bal = selfbalance" },
|
||||||
|
|
||||||
// Stack, Memory, Storage and Flow Operations
|
// Stack, Memory, Storage and Flow Operations
|
||||||
pop: { value: 0x50, delta: 1, alpha: 0, doc: "stackTopValue = pop" },
|
pop: { value: 0x50, delta: 1, alpha: 0, doc: "stackTopValue = pop" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user