Skip to content

Commit

Permalink
Merge pull request compiler-explorer#1035 from mattgodbolt/hide-heade…
Browse files Browse the repository at this point in the history
…r-code

add option for hiding header code
  • Loading branch information
partouf authored Dec 19, 2018
2 parents 240b29f + f7ff883 commit b8983f9
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 8 deletions.
1 change: 1 addition & 0 deletions etc/config/c++.defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ binaryHideFuncRe=^(__.*|_(init|start|fini)|(de)?register_tm_clones|call_gmon_sta
needsMulti=false
stubRe=\bmain\b
stubText=int main(void){return 0;/*stub provided by Compiler Explorer*/}
supportsLibraryCodeFilter=true

#################################
#################################
Expand Down
2 changes: 2 additions & 0 deletions etc/config/compiler-explorer.defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ textBanner=Compilation provided by Compiler Explorer at https://godbolt.org/
# privacy policy, and then to enable both these below.
cookiePolicyEnabled=false
privacyPolicyEnabled=false

supportsLibraryCodeFilter=false
8 changes: 5 additions & 3 deletions lib/asm-parser-vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ class AsmParser extends AsmParserBase {
}

for (const func of obj.functions) {
pushLine({text: "", source: null});
for (const line of func.lines) {
pushLine(line);
if (!filters.libraryCode || func.file === null) {
pushLine({text: "", source: null});
for (const line of func.lines) {
pushLine(line);
}
}
}

Expand Down
43 changes: 38 additions & 5 deletions lib/asm-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class AsmParser extends AsmRegex {
const stdInLooking = /<stdin>|^-$|example\.[^/]+$|<source>/;
const endBlock = /\.(cfi_endproc|data|text|section)/;
let source = null;
let mayRemovePreviousLabel = true;

let inNvccDef = false;
let inNvccCode = false;

let inCustomAssembly = 0;
asmLines.forEach(line => {
Expand Down Expand Up @@ -260,11 +264,24 @@ class AsmParser extends AsmRegex {
break;
}
}
if (line.match(endBlock)) {
if (line.match(endBlock) || (inNvccCode && line.match(/}/))) {
source = null;
prevLabel = null;
}

if (filters.libraryCode && source && source.file !== null) {
if (mayRemovePreviousLabel && result.length > 0) {
const lastLine = result[result.length - 1];
if (lastLine.text && lastLine.text.match(this.labelDef)) {
result.pop();
}
mayRemovePreviousLabel = false;
}
return;
} else {
mayRemovePreviousLabel = true;
}

if (filters.commentOnly && line.match(commentOnly)) return;

if (inCustomAssembly > 0)
Expand All @@ -274,8 +291,10 @@ class AsmParser extends AsmRegex {
if (!match) match = line.match(this.assignmentDef);
if (!match) {
match = line.match(this.cudaBeginDef);
if (match)
this.inNvccDef = true;
if (match) {
inNvccDef = true;
inNvccCode = true;
}
}
if (match) {
// It's a label definition.
Expand All @@ -287,9 +306,9 @@ class AsmParser extends AsmRegex {
prevLabel = match;
}
}
if (this.inNvccDef) {
if (inNvccDef) {
if (line.match(this.cudaEndDef))
this.inNvccDef = false;
inNvccDef = false;
} else if (!match && filters.directives) {
// Check for directives only if it wasn't a label; the regexp would
// otherwise misinterpret labels as directives.
Expand Down Expand Up @@ -326,6 +345,7 @@ class AsmParser extends AsmRegex {
let asmLines = asm.split("\n");
let source = null;
let func = null;
let mayRemovePreviousLabel = true;

// Handle "error" documents.
if (asmLines.length === 1 && asmLines[0][0] === '<') {
Expand Down Expand Up @@ -360,6 +380,19 @@ class AsmParser extends AsmRegex {

if (!func || !this.isUserFunction(func)) return;

if (filters.libraryCode && source && source.file !== null) {
if (mayRemovePreviousLabel && result.length > 0) {
const lastLine = result[result.length - 1];
if (lastLine.text && lastLine.text.match(this.labelDef)) {
result.pop();
}
mayRemovePreviousLabel = false;
}
return;
} else {
mayRemovePreviousLabel = true;
}

match = line.match(this.asmOpcodeRe);
if (match) {
const address = parseInt(match[1], 16);
Expand Down
2 changes: 2 additions & 0 deletions lib/compiler-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class CompilerFinder {

const supportsBinary = !!props("supportsBinary", true);
const supportsExecute = supportsBinary && !!props("supportsExecute", true);
const supportsLibraryCodeFilter = !!props("supportsLibraryCodeFilter", true);
const group = props("group", "");
const demangler = props("demangler", "");
const isSemVer = props("isSemVer", false);
Expand Down Expand Up @@ -184,6 +185,7 @@ class CompilerFinder {
supportsDemangle: !!demangler,
supportsBinary: supportsBinary,
supportsExecute: supportsExecute,
supportsLibraryCodeFilter: supportsLibraryCodeFilter,
postProcess: props("postProcess", "").split("|"),
lang: langId,
group: group,
Expand Down
5 changes: 5 additions & 0 deletions lib/options-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class ClientOptionsHandler {
return this.supportsBinary[lang.id] && !!res;
});
this.supportsExecute = Object.values(this.supportsExecutePerLanguage).some(value => value);

this.supportsLibraryCodeFilterPerLanguage = this.compilerProps(languages, 'supportsLibraryCodeFilter', false);
this.supportsLibraryCodeFilter = Object.values(this.supportsLibraryCodeFilterPerLanguage).some(value => value);

const libs = this.parseLibraries(this.compilerProps(languages, 'libs'));
const tools = this.parseTools(this.compilerProps(languages, 'tools'));

Expand All @@ -85,6 +89,7 @@ class ClientOptionsHandler {
compileOptions: this.compilerProps(languages, 'defaultOptions', ''),
supportsBinary: this.supportsBinary,
supportsExecute: this.supportsExecute,
supportsLibraryCodeFilter: this.supportsLibraryCodeFilter,
languages: languages,
sources: sources,
sentryDsn: ceProps('sentryDsn', ''),
Expand Down
10 changes: 10 additions & 0 deletions static/panes/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ Compiler.prototype.getEffectiveFilters = function () {
if (filters.execute && !this.compiler.supportsExecute) {
delete filters.execute;
}
if (filters.libraryCode && !this.compiler.supportsLibraryCodeFilter) {
delete filters.libraryCode;
}
_.each(this.compiler.disabledFilters, function (filter) {
if (filters[filter]) {
delete filters[filter];
Expand Down Expand Up @@ -868,6 +871,9 @@ Compiler.prototype.initButtons = function (state) {
this.filterDirectivesButton = this.domRoot.find("[data-bind='directives']");
this.filterDirectivesTitle = this.filterDirectivesButton.prop('title');

this.filterLibraryCodeButton = this.domRoot.find("[data-bind='libraryCode']");
this.filterLibraryCodeTitle = this.filterLibraryCodeButton.prop('title');

this.filterCommentsButton = this.domRoot.find("[data-bind='commentOnly']");
this.filterCommentsTitle = this.filterCommentsButton.prop('title');

Expand All @@ -882,6 +888,7 @@ Compiler.prototype.initButtons = function (state) {

this.noBinaryFiltersButtons = this.domRoot.find('.nonbinary');
this.filterExecuteButton.toggle(options.supportsExecute);
this.filterLibraryCodeButton.toggle(options.supportsLibraryCodeFilter);
this.optionsField.val(this.options);

this.shortCompilerName = this.domRoot.find('.short-compiler-name');
Expand Down Expand Up @@ -968,6 +975,9 @@ Compiler.prototype.updateButtons = function () {
var noBinaryFiltersDisabled = !!filters.binary && !this.compiler.supportsFiltersInBinary;
this.noBinaryFiltersButtons.prop('disabled', noBinaryFiltersDisabled);

this.filterLibraryCodeButton.prop('disabled', !this.compiler.supportsLibraryCodeFilter);
formatFilterTitle(this.filterLibraryCodeButton, this.filterLibraryCodeTitle);

this.filterLabelsButton.prop('disabled', this.compiler.disabledFilters.indexOf('labels') !== -1);
formatFilterTitle(this.filterLabelsButton, this.filterLabelsTitle);
this.filterDirectivesButton.prop('disabled', this.compiler.disabledFilters.indexOf('directives') !== -1);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/filter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ describe('Filter test cases', function () {
{directives: true, commentOnly: true});
});
});
describe('Directives and library code', function () {
cases.forEach(function (x) {
testFilter(x, ".directives.library",
{directives: true, libraryCode: true});
});
});
describe('Directives, labels, comments and library code', function () {
cases.forEach(function (x) {
testFilter(x, ".directives.labels.comments.library",
{directives: true, labels: true, commentOnly: true, libraryCode: true});
});
});
});
4 changes: 4 additions & 0 deletions views/templates.pug
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
button.btn.btn-light.btn-sm.active.nonbinary(type="button" title="Filter unused labels from the output" data-bind="labels" aria-pressed="true")
span .LX0:
input.d-none(type="checkbox" checked=true)
.button-checkbox
button.btn.btn-light.btn-sm.active.nonbinary(title="Filter functions from other libraries from the output" data-bind="libraryCode" aria-pressed="true")
span lib.f:
input.d-none(type="checkbox")
.button-checkbox
button.btn.btn-light.btn-sm.active.nonbinary(type="button" title="Filter all assembler directives from the output" data-bind="directives" aria-pressed="true")
span .text
Expand Down

0 comments on commit b8983f9

Please sign in to comment.