Skip to content

Commit 59aff3c

Browse files
committed
Add legacy assembly JSON formatter
Imported from browser-solidity (src/app/contract/contractParser.js)
1 parent 24431b8 commit 59aff3c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

translate.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,41 @@ function translateJsonCompilerOutput (output) {
148148
return ret;
149149
}
150150

151+
function formatAssemblyText (asm, prefix, source) {
152+
if (typeof asm === typeof '' || asm === null || asm === undefined) {
153+
return prefix + asm + '\n';
154+
}
155+
var text = prefix + '.code\n';
156+
asm['.code'].forEach(function (item, i) {
157+
var v = item.value === undefined ? '' : item.value;
158+
var src = '';
159+
if (source !== undefined && item.begin !== undefined && item.end !== undefined) {
160+
src = source.slice(item.begin, item.end).replace('\n', '\\n', 'g');
161+
}
162+
if (src.length > 30) {
163+
src = src.slice(0, 30) + '...';
164+
}
165+
if (item.name !== 'tag') {
166+
text += ' ';
167+
}
168+
text += prefix + item.name + ' ' + v + '\t\t\t' + src + '\n';
169+
});
170+
text += prefix + '.data\n';
171+
var asmData = asm['.data'] || [];
172+
for (var i in asmData) {
173+
var item = asmData[i];
174+
text += ' ' + prefix + '' + i + ':\n';
175+
text += formatAssemblyText(item, prefix + ' ', source);
176+
}
177+
return text;
178+
}
179+
180+
function prettyPrintLegacyAssemblyJSON (assembly, source) {
181+
return formatAssemblyText(assembly, '', source);
182+
}
183+
151184
module.exports = {
152185
versionToSemver: versionToSemver,
153-
translateJsonCompilerOutput: translateJsonCompilerOutput
186+
translateJsonCompilerOutput: translateJsonCompilerOutput,
187+
prettyPrintLegacyAssemblyJSON: prettyPrintLegacyAssemblyJSON
154188
};

0 commit comments

Comments
 (0)