From 7957cefec26cfc41e7b2f8e0dd238a84b5ee3699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 17:18:53 +0200 Subject: [PATCH 1/9] Add minor changes to Cfg views. (CC @cppchedy) --- lib/base-compiler.js | 4 ++-- lib/cfg.js | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index afa63be29..166603805 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -62,7 +62,7 @@ Compile.prototype.readFile = Promise.denodeify(fs.readFile); Compile.prototype.stat = Promise.denodeify(fs.stat); Compile.prototype.optOutputRequested = function (options) { - return options.some((x) => x == "-fsave-optimization-record"); + return options.some((x) => x === "-fsave-optimization-record"); }; Compile.prototype.getRemote = function () { @@ -373,7 +373,7 @@ Compile.prototype.couldSupportASTDump = function (options, version) { }; Compile.prototype.isCfgCompiler = function(compilerVersion) { - return compilerVersion.includes("clang") || compilerVersion.includes("g++"); + return compilerVersion.includes("clang") || compilerVersion.indexOf("g++") === 0; }; Compile.prototype.processAstOutput = function (output) { diff --git a/lib/cfg.js b/lib/cfg.js index dc99ead61..80dac6718 100644 --- a/lib/cfg.js +++ b/lib/cfg.js @@ -104,27 +104,27 @@ function separateCodeFromData_(asmArr) { .value(); } - var clangX86 = { - filterData: separateCodeFromData_, - isFunctionEnd:function(x) { return ((x[0] !== ' ') && (x[0] !== '.') && - (x.indexOf(':') !== -1)) ;}, +var clangX86 = { + filterData: separateCodeFromData_, + isFunctionEnd:function(x) { return ((x[0] !== ' ') && (x[0] !== '.') && + (x.indexOf(':') !== -1)) ;}, - isBasicBlockEnd: function(x) { return x[0] === ".";} , + isBasicBlockEnd: function(inst, prevInst) { return inst[0] === "." || prevInst.includes(" ret");} , - getInstructionType:function(inst) { - if(inst.includes("jmp")) return InstructionType_jmp; - else if(inst.trim()[0] === 'j') return InstructionType_conditionalJmpInst; - else if(!inst.includes(" ret")) return InstructionType_notRetInst; - else return InstructionType_retInst; - }, + getInstructionType:function(inst) { + if(inst.includes("jmp")) return InstructionType_jmp; + else if(inst.trim()[0] === 'j') return InstructionType_conditionalJmpInst; + else if(!inst.includes(" ret")) return InstructionType_notRetInst; + else return InstructionType_retInst; + }, - extractNodeName:function(inst) { - var name = inst.match(/\.LBB\d+_\d+/); - return name + ":"; - }, + extractNodeName:function(inst) { + var name = inst.match(/\.LBB\d+_\d+/); + return name + ":"; + }, - isJmpInstruction: function(x) { var trimed = x.trim(); return ( trimed[0] === 'j');} - }; + isJmpInstruction: function(x) { var trimed = x.trim(); return ( trimed[0] === 'j');} +}; function ControlFlowGraph(compiler){ if(compiler.includes("clang")) From 08314e59b3d87ab84aa477f7718c5ee3a4ed3f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 17:42:46 +0200 Subject: [PATCH 2/9] Add @cppchedy to codeowners If a PR for thhis files comes while he has no push access, I'll let him know --- .clang-format | 0 CODEOWNERS | 4 ++++ 2 files changed, 4 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..e69de29bb diff --git a/CODEOWNERS b/CODEOWNERS index c061334dc..d1e7e7673 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -22,3 +22,7 @@ static/ast-view.js @TartanLlama static/haskell-mode.js @TartanLlama lib/compilers/haskell.js @TartanLlama views/example.hs @TartanLlama + +# cppchedy +static/cfg-view.js @cppchedy +lib/cfg.js @cppchedy From 81419b1cc690837f9f31a8f39cd6f98b8e8f6f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 17:44:02 +0200 Subject: [PATCH 3/9] Add clang-format to our workflow. make format reformats every js file in lib/ & static/ (Plus app.js) Hopefuly your preferred IDE has some kind of integration with c-f --- .clang-format | 8 ++++++++ Makefile | 3 +++ package.json | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index e69de29bb..7826d0de2 100644 --- a/.clang-format +++ b/.clang-format @@ -0,0 +1,8 @@ +--- +Language: JavaScript +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 120 +UseTab: Never +SpaceBeforeParens: Always +--- diff --git a/Makefile b/Makefile index 629611f24..29fd6bab1 100644 --- a/Makefile +++ b/Makefile @@ -106,3 +106,6 @@ dist: prereqs c-preload: $(MAKE) -C c-preload + +format: + $(NODE) ./node_modules/.bin/clang-format -i -style=file static/*.js lib/*.js app.js diff --git a/package.json b/package.json index bed8c8b20..193be0ad6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "mocha": "^3.3.0", "requirejs": "*", "supervisor": "*", - "uglify-js": "*" + "uglify-js": "*", + "clang-format": "1.0.55" }, "scripts": { "test": "mocha && make test" From c77418537d7699652ebf85a1f510f4cb56ce7cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 19:25:10 +0200 Subject: [PATCH 4/9] Delete clang-format SOmehow it ended up pushed --- .clang-format | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 7826d0de2..000000000 --- a/.clang-format +++ /dev/null @@ -1,8 +0,0 @@ ---- -Language: JavaScript -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 120 -UseTab: Never -SpaceBeforeParens: Always ---- From 58c821f23de11c9db681e7a93ac1e21e3fbf69dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 19:27:52 +0200 Subject: [PATCH 5/9] Remove all traces of clang-format It should have never been here in the first place --- Makefile | 3 --- package.json | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 29fd6bab1..629611f24 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,3 @@ dist: prereqs c-preload: $(MAKE) -C c-preload - -format: - $(NODE) ./node_modules/.bin/clang-format -i -style=file static/*.js lib/*.js app.js diff --git a/package.json b/package.json index 193be0ad6..bed8c8b20 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,7 @@ "mocha": "^3.3.0", "requirejs": "*", "supervisor": "*", - "uglify-js": "*", - "clang-format": "1.0.55" + "uglify-js": "*" }, "scripts": { "test": "mocha && make test" From 6c164c1fdc60f6a8a0eefa77fb093fe2adc4971f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 20:48:59 +0200 Subject: [PATCH 6/9] Format cfg-view.js --- static/cfg-view.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/static/cfg-view.js b/static/cfg-view.js index dd47cb261..174c6900d 100644 --- a/static/cfg-view.js +++ b/static/cfg-view.js @@ -23,24 +23,24 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -define(function(require){ - "use strict"; +define(function (require) { + "use strict"; + var $ = require('jquery'); var vis = require('vis'); var _ = require('underscore'); - require('asm-mode'); require('selectize'); - function Cfg(hub, container, state){ + function Cfg(hub, container, state) { this.container = container; this.eventHub = hub.createEventHub(); this.domRoot = container.getElement(); this.domRoot.html($('#cfg').html()); this.functions = state.cfgResult; this.defaultCfgOuput = {nodes: [{id: 0, label: 'No Output'}], edges: []}; - this.fnNames = this.functions? Object.keys(this.functions): []; - this.currentFunc = this.fnNames.length? this.fnNames[0]: ""; + this.fnNames = this.functions ? Object.keys(this.functions) : []; + this.currentFunc = this.fnNames.length ? this.fnNames[0] : ""; this.networkOpts = { autoResize: true, @@ -79,9 +79,9 @@ define(function(require){ }; this.cfgVisualiser = new vis.Network(this.domRoot.find(".graph-placeholder")[0], - this.defaultCfgOuput, this.networkOpts); + this.defaultCfgOuput, this.networkOpts); this.restButton = this.domRoot.find(".show-hide-btn") - .on('click', _.bind(function(){ + .on('click', _.bind(function () { this.networkOpts.interaction.navigationButtons = !this.networkOpts.interaction.navigationButtons; this.cfgVisualiser.setOptions(this.networkOpts); }, this)); @@ -101,11 +101,11 @@ define(function(require){ container.on('resize', this.resize, this); container.on('shown', this.resize, this); - this.adaptStructure = function(names){ + this.adaptStructure = function (names) { var options = []; - for(var i = 0; i < names.length; ++i){ - options.push({name:names[i]}); + for (var i = 0; i < names.length; ++i) { + options.push({name: names[i]}); } return options; }; @@ -115,9 +115,9 @@ define(function(require){ valueField: 'name', labelField: 'name', searchField: ['name'], - options: this.fnNames.length ? this.adaptStructure(this.fnNames) : [{name:"The input does not contain any function"}], + options: this.fnNames.length ? this.adaptStructure(this.fnNames) : [{name: "The input does not contain any function"}], items: this.fnNames.length ? [this.currentFunc] : ["Please select a function"] - }).on('change', _.bind(function(event){ + }).on('change', _.bind(function (event) { this.onFunctionChange(this.functions, event.target.value); }, this)); @@ -129,7 +129,7 @@ define(function(require){ if (result.supportsCfg && !$.isEmptyObject(result.cfg)) { this.functions = result.cfg; this.fnNames = Object.keys(this.functions); - if(this.fnNames.indexOf(this.currentFunc) === -1) + if (this.fnNames.indexOf(this.currentFunc) === -1) this.currentFunc = this.fnNames[0]; this.showCfgResults({ 'nodes': this.functions[this.currentFunc].nodes, @@ -148,8 +148,8 @@ define(function(require){ valueField: 'name', labelField: 'name', searchField: ['name'], - options: this.fnNames.length ? this.adaptStructure(this.fnNames) : [{name:"The input does not contain any function"}], - items: this.fnNames.length ? [this.currentFunc] : ["Please select a function"] + options: this.fnNames.length ? this.adaptStructure(this.fnNames) : [{name: "The input does not contain any function"}], + items: this.fnNames.length ? [this.currentFunc] : ["Please select a function"] }).on('change', _.bind(function (event) { this.onFunctionChange(this.functions, event.target.value); }, this)); @@ -157,15 +157,15 @@ define(function(require){ }; Cfg.prototype.setTitle = function () { - this.container.setTitle(this._compilerName + " Graph Viewer (Editor #" + this._editorid + ", Compiler #" + this._compilerid + ")"); + this.container.setTitle(this._compilerName + " Graph Viewer (Editor #" + this._editorid + ", Compiler #" + this._compilerid + ")"); }; - Cfg.prototype.showCfgResults = function(data) { + Cfg.prototype.showCfgResults = function (data) { this.cfgVisualiser.setData(data); }; Cfg.prototype.onCompiler = function (id, compiler, options, editorid) { - if(id === this._compilerid) { + if (id === this._compilerid) { this._compilerName = compiler.name; this._editorid = editorid; this.setTitle(); From 042d68262a995889ca124bb338d2bf5a1f1d2655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 20:53:30 +0200 Subject: [PATCH 7/9] Delegate compilation handling to view events This fixes #499 #500 --- static/compiler.js | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/static/compiler.js b/static/compiler.js index ac709b26b..64015ed72 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -235,10 +235,10 @@ define(function (require) { this.eventHub.on('findCompilers', this.sendCompiler, this); this.eventHub.on('compilerSetDecorations', this.onCompilerSetDecorations, this); this.eventHub.on('settingsChange', this.onSettingsChange, this); + this.eventHub.on('optViewOpened', this.onOptViewOpened, this); this.eventHub.on('optViewClosed', this.onOptViewClosed, this); this.eventHub.on('astViewOpened', this.onAstViewOpened, this); this.eventHub.on('astViewClosed', this.onAstViewClosed, this); - this.eventHub.on('optViewOpened', this.onOptViewOpened, this); this.eventHub.on('cfgViewOpened', this.onCfgViewOpened, this); this.eventHub.on('cfgViewClosed', this.onCfgViewClosed, this); this.eventHub.on('resize', this.resize, this); @@ -288,46 +288,30 @@ define(function (require) { }, this)); this.container.layoutManager.createDragSource( - this.optButton, function () { - this.wantOptInfo = true; - this.compile(); - return createOptView.apply(this); - }.bind(this)); + this.optButton, createOptView); this.optButton.click(_.bind(function () { - this.wantOptInfo = true; var insertPoint = hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; insertPoint.addChild(createOptView); - this.optButton.prop("disabled", true); - this.compile(); }, this)); this.container.layoutManager.createDragSource( - this.astButton, function () { - this.compile(); - return createAstView.apply(this); - }.bind(this)); + this.astButton, createAstView); this.astButton.click(_.bind(function () { var insertPoint = hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; insertPoint.addChild(createAstView); - this.compile(); }, this)); this.container.layoutManager.createDragSource( - this.cfgButton, function() { - this.compile(); - return createCfgView.apply(this); - }.bind(this)); + this.cfgButton, createCfgView); this.cfgButton.click(_.bind(function () { var insertPoint = hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; insertPoint.addChild(createCfgView); - this.cfgButton.prop("disabled", true); - this.compile(); }, this)); @@ -665,6 +649,7 @@ define(function (require) { if (this.id == id) { this.astButton.prop("disabled", true); this.astViewOpen = true; + this.compile(); } }; @@ -679,6 +664,7 @@ define(function (require) { this.optViewOpen = true; this.wantOptInfo = true; this.optButton.prop("disabled", this.optViewOpen); + this.compile(); } }; @@ -686,6 +672,7 @@ define(function (require) { if (this.id == id) { this.cfgButton.prop("disabled", true); this.cfgViewOpen = true; + this.compile(); } }; From c4a243ebc9b3903a766e5579d17063cbb624f08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= Date: Tue, 26 Sep 2017 23:31:51 +0200 Subject: [PATCH 8/9] Add cctz library Abseil needs it. Not exposing it in the interface. Should I? This fixes #539 --- etc/config/c++.amazon.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 0695fbbc1..c3671d851 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -272,4 +272,4 @@ libs.xtensor.versions.trunk.path=/opt/compiler-explorer/libs/xtensor/include libs.abseil.name=Abseil libs.abseil.versions=trunk libs.abseil.versions.trunk.version=trunk -libs.abseil.versions.trunk.path=/opt/compiler-explorer/libs/abseil +libs.abseil.versions.trunk.path=/opt/compiler-explorer/libs/abseil:/opt/compiler-explorer/libs/cctz/include From fa1487df863c304173b56d504825827e457c210d Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Tue, 26 Sep 2017 15:31:34 -0700 Subject: [PATCH 9/9] Workaround for `vis.js` - directly use the minified version as that seems to prevent the double-anonymous function problem --- static/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/main.js b/static/main.js index 21a53acff..1eb9adacc 100644 --- a/static/main.js +++ b/static/main.js @@ -42,7 +42,7 @@ require.config({ vs: "ext/monaco-editor/min/vs", 'bootstrap-slider': 'ext/seiyria-bootstrap-slider/dist/bootstrap-slider', filesaver: 'ext/file-saver/FileSaver', - vis: 'ext/vis/dist/vis' + vis: 'ext/vis/dist/vis.min' }, shim: { underscore: {exports: '_'},