Added a bunch of filters to the assembly output

refactor
Matt Godbolt 11 years ago
parent 1f690d749f
commit 854ec646e6

@ -47,3 +47,35 @@ CodeMirror.defineMode("asm", function() {
});
CodeMirror.defineMIME("text/x-asm", "asm");
function filterAsm(asm, filters) {
var result = [];
var asmLines = asm.split("\n");
var labelsUsed = {};
var labelFind = /\.[a-zA-Z0-9$_.]+/g;
$.each(asmLines, function(_, line) {
if (line == "" || line[0] == ".") return;
var match = line.match(labelFind);
if (match) $.each(match, function(_, label) { labelsUsed[label] = true; });
});
var directive = /^\s*\..*$/;
var labelDefinition = /^(\.[a-zA-Z0-9$_.]+):/;
var commentOnly = /^\s*#.*/;
$.each(asmLines, function(_, line) {
if (line.trim() == "") return;
if (filters.commentOnly && line.match(commentOnly)) return;
var match = line.match(labelDefinition);
if (match && labelsUsed[match[1]] == undefined) {
if (filters.labels) return;
}
if (!match && filters.directives) {
// Check for directives only if it wasn't a label; the regexp would
// otherwise misinterpret labels as directives.
match = line.match(directive);
if (match) return;
}
result.push(line);
});
return result.join("\n");
}

@ -26,6 +26,7 @@ var pendingTimeout = null;
var asmCodeMirror = null;
var cppEditor = null;
var lastRequest = null;
var currentAssembly = null;
function parseLines(lines, callback) {
var re = /^\<stdin\>:([0-9]+):([0-9]+):\s+(.*)/;
@ -68,7 +69,13 @@ function onCompileResponse(data) {
elem.text(msg);
}
});
asmCodeMirror.setValue(data.asm || "[no output]");
currentAssembly = data.asm || "[no output]";
updateAsm();
}
function updateAsm() {
if (!currentAssembly) return;
asmCodeMirror.setValue(filterAsm(currentAssembly, getAsmFilters()));
}
function onChange() {
@ -91,6 +98,8 @@ function onChange() {
success: onCompileResponse});
}, 750);
window.localStorage['code'] = cppEditor.getValue();
window.localStorage['filter'] = JSON.stringify(getAsmFilters());
updateAsm();
$('a.permalink').attr('href', '#' + serialiseState());
}
@ -191,10 +200,11 @@ function saveFileAs() {
function serialiseState() {
var state = {
version: 1,
version: 2,
source: cppEditor.getValue(),
compiler: $('.compiler').val(),
options: $('.compiler_options').val()
options: $('.compiler_options').val(),
filterAsm: getAsmFilters()
};
return encodeURIComponent(JSON.stringify(state));
}
@ -202,11 +212,13 @@ function serialiseState() {
function deserialiseState(state) {
try {
var state = $.parseJSON(decodeURIComponent(state));
if (state.version != 1) return false;
if (state.version == 1) { state.filterAsm = true; }
else if (state.version != 2) return false;
} catch (ignored) { return false; }
cppEditor.setValue(state.source);
$('.compiler').val(state.compiler);
$('.compiler_options').val(state.options);
setFilterUi(state.filterAsm);
return true;
}
@ -261,6 +273,11 @@ function initialise() {
return false;
});
$('.filter button.btn').click(function(e) {
$(e.target).toggleClass('active');
onChange();
});
$(window).bind('hashchange', function() {
deserialiseState(window.location.hash.substr(1));
});
@ -270,6 +287,21 @@ function initialise() {
}
if (window.localStorage['code']) cppEditor.setValue(window.localStorage['code']);
if (window.localStorage['compilerOptions']) $('.compiler_options').val(window.localStorage['compilerOptions']);
setFilterUi($.parseJSON(window.localStorage['filter'] || "{}"));
}
function getAsmFilters() {
var asmFilters = {};
$('.filter button.btn.active').each(function() {
asmFilters[$(this).val()] = true;
});
return asmFilters;
}
function setFilterUi(asmFilters) {
$('.filter button.btn').each(function() {
$(this).toggleClass('active', !!asmFilters[$(this).val()]);
});
}
$(initialise);

@ -12,7 +12,6 @@
<script src="gcc.js"></script>
<script src="ext/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-55180-6']);
_gaq.push(['_trackPageview']);
@ -22,7 +21,6 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
(function() {
@ -72,6 +70,14 @@
<form class="well form-inline">
<label>Compiler: <select class="compiler"></select></label>
<label>Compiler options: <input class="compiler_options" style="width: 30em;" type="text" value="-O2 -std=c++0x -march=native"></label>
<table><tbody><tr><td>Filter:&nbsp;</td>
<td>
<div class="btn-group filter">
<button class="btn" value="labels">Unused labels</button>
<button class="btn" value="directives">Directives</button>
<button class="btn" value="commentOnly">Comment-only lines</button>
</div>
</td></table>
</form>
</div>
</div>

Loading…
Cancel
Save