Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!binary) {
return [];
}
let numInstructions;
if (sourceMap) {
numInstructions = sourceMap.split(";").length;
} else {
//HACK
numInstructions = (binary.length - 2) / 2;
//this is actually an overestimate, but that's OK
}
//because we might be dealing with a constructor with arguments, we do
//*not* remove metadata manually
let instructions = CodeUtils.parseCode(binary, numInstructions);
if (!sourceMap) {
// HACK
// Let's create a source map to use since none exists. This source
// map maps just as many ranges as there are instructions (or
// possibly more), and marks them all as being Solidity-internal and
// not jumps.
sourceMap =
binary !== "0x"
? "0:0:-1:-".concat(";".repeat(instructions.length - 1))
: "";
}
var lineAndColumnMappings = Object.assign(
{},
...Object.entries(sources).map(([id, { source }]) => ({
return done(
new TruffleError(
'Cannot find compiled contract with name "' + contractName + '"'
)
);
}
var bytecode = Contract.deployedBytecode;
var numInstructions = Contract.deployedSourceMap.split(";").length;
if (options.creation) {
bytecode = Contract.bytecode;
numInstructions = Contract.sourceMap.split(";").length;
}
var opcodes = CodeUtils.parseCode(bytecode, numInstructions);
var indexLength = (opcodes.length + "").length;
opcodes.forEach(function(opcode, index) {
var strIndex = index + ":";
while (strIndex.length < indexLength + 1) {
strIndex += " ";
}
console.log(
strIndex + " " + opcode.name + " " + (opcode.pushData || "")
);
});
});
}
export function readInstructions(
bytecode: string,
sourceMap: string | undefined
):
DataModel.IInstruction[]
{
const instructions = parseCode(bytecode);
const sourceRanges = (sourceMap) ? readSourceMapRanges(sourceMap) : null;
return instructions.map(
(op: Instruction, index: number) => Object.assign(
{
programCounter: op.pc,
opcode: op.name,
meta: {
cost: op.fee,
pops: op.in,
pushes: op.out,
dynamic: op.dynamic
}
},