diff --git a/etc/config/cuda.amazon.properties b/etc/config/cuda.amazon.properties index d1370fb56..2a79eb26d 100644 --- a/etc/config/cuda.amazon.properties +++ b/etc/config/cuda.amazon.properties @@ -122,24 +122,31 @@ group.cuclang.objdumper=/opt/compiler-explorer/cuda/11.3.1/bin/nvdisasm # old. It can be overriden by the user via --no-offload-arch=none # --offload-arch=sm_XY. compiler.cuclang700.exe=/opt/compiler-explorer/clang-7.0.0/bin/clang++ -compiler.cuclang700.semver=7.0.0 sm_70 CUDA-9.1 +compiler.cuclang700.semver=7.0.0 +compiler.cuclang700.name=clang 7.0.0 sm_70 CUDA-9.1 compiler.cuclang700.options=--gcc-toolchain=/opt/compiler-explorer/gcc-8.2.0 --cuda-path=/opt/compiler-explorer/cuda/9.1.85 --cuda-gpu-arch=sm_70 --cuda-device-only compiler.cuclang800.exe=/opt/compiler-explorer/clang-8.0.0/bin/clang++ -compiler.cuclang800.semver=8.0.0 sm_75 CUDA-10.0 +compiler.cuclang800.semver=8.0.0 +compiler.cuclang800.name=clang 8.0.0 sm_75 CUDA-10.0 compiler.cuclang800.options=--gcc-toolchain=/opt/compiler-explorer/gcc-8.3.0 --cuda-path=/opt/compiler-explorer/cuda/10.0.130 --cuda-gpu-arch=sm_75 --cuda-device-only compiler.cuclang900.exe=/opt/compiler-explorer/clang-9.0.0/bin/clang++ -compiler.cuclang900.semver=9.0.0 sm_75 CUDA-10.1 +compiler.cuclang900.semver=9.0.0 +compiler.cuclang900.name=clang 9.0.0 sm_75 CUDA-10.1 compiler.cuclang900.options=--gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 --cuda-path=/opt/compiler-explorer/cuda/10.1.168 --cuda-gpu-arch=sm_75 --cuda-device-only compiler.cuclang1000.exe=/opt/compiler-explorer/clang-10.0.0/bin/clang++ -compiler.cuclang1000.semver=10.0.0 sm_75 CUDA-10.2 +compiler.cuclang1000.semver=10.0.0 +compiler.cuclang1000.name=10.0.0 sm_75 CUDA-10.2 compiler.cuclang1000.options=--gcc-toolchain=/opt/compiler-explorer/gcc-9.3.0 --cuda-path=/opt/compiler-explorer/cuda/10.2.89 --cuda-gpu-arch=sm_75 --cuda-device-only compiler.cuclang1001.exe=/opt/compiler-explorer/clang-10.0.1/bin/clang++ -compiler.cuclang1001.semver=10.0.1 sm_75 CUDA-10.2 +compiler.cuclang1001.semver=10.0.1 +compiler.cuclang1001.name=10.0.1 sm_75 CUDA-10.2 compiler.cuclang1001.options=--gcc-toolchain=/opt/compiler-explorer/gcc-9.3.0 --cuda-path=/opt/compiler-explorer/cuda/10.2.89 --cuda-gpu-arch=sm_75 --cuda-device-only compiler.cuclang1100.exe=/opt/compiler-explorer/clang-11.0.0/bin/clang++ -compiler.cuclang1100.semver=11.0.0 sm_75 CUDA-10.2 +compiler.cuclang1100.semver=11.0.0 +compiler.cuclang1100.name=11.0.0 sm_75 CUDA-10.2 compiler.cuclang1100.options=--gcc-toolchain=/opt/compiler-explorer/gcc-10.2.0 --cuda-path=/opt/compiler-explorer/cuda/10.2.89 --cuda-gpu-arch=sm_75 --cuda-device-only -compiler.cltrunk.semver=trunk sm_86 CUDA-11.3 +compiler.cltrunk.semver=trunk +compiler.cltrunk.name=trunk sm_86 CUDA-11.3 compiler.cltrunk.exe=/opt/compiler-explorer/clang-trunk/bin/clang++ compiler.cltrunk.demangler=/opt/compiler-explorer/gcc-snapshot/bin/c++filt compiler.cltrunk.options=--gcc-toolchain=/opt/compiler-explorer/gcc-snapshot --cuda-path=/opt/compiler-explorer/cuda/11.3.1 --cuda-gpu-arch=sm_86 --cuda-device-only -Wno-unknown-cuda-version @@ -158,19 +165,23 @@ compiler.hiptrunk.hidden=true # the clang-hip compiler type adds --gpu-bundle-output which didn't exist in ROCm 4.5 compiler.hipclang-rocm-40502.compilerType=clang compiler.hipclang-rocm-40502.exe=/opt/compiler-explorer/clang-rocm-4.5.2/bin/clang++ -compiler.hipclang-rocm-40502.semver=rocm-4.5.2 +compiler.hipclang-rocm-40502.semver=4.5.2 +compiler.hipclang-rocm-40502.name=clang rocm-4.5.2 compiler.hipclang-rocm-40502.objdumper=/opt/compiler-explorer/clang-rocm-40502/bin/llvm-objdump compiler.hipclang-rocm-40502.options=-x hip --cuda-device-only -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false -O3 -D__HIP_PLATFORM_AMD__=1 -D__HIP_PLATFORM_HCC__=1 --rocm-path=/opt/compiler-explorer/libs/rocm/4.5.2 --rocm-device-lib-path=/opt/compiler-explorer/clang-rocm-4.5.2/amdgcn/bitcode -include hip/hip_runtime.h compiler.hipclang-rocm-50002.exe=/opt/compiler-explorer/clang-rocm-5.0.2/bin/clang++ -compiler.hipclang-rocm-50002.semver=rocm-5.0.2 +compiler.hipclang-rocm-50002.semver=5.0.2 +compiler.hipclang-rocm-50002.name=clang rocm-5.0.2 compiler.hipclang-rocm-50002.objdumper=/opt/compiler-explorer/clang-rocm-50002/bin/llvm-objdump compiler.hipclang-rocm-50002.options=-x hip --cuda-device-only -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false -O3 -D__HIP_PLATFORM_AMD__=1 -D__HIP_PLATFORM_HCC__=1 -isystem /opt/compiler-explorer/libs/rocm/5.0.2/include --rocm-path=/opt/compiler-explorer/libs/rocm/5.0.2 --rocm-device-lib-path=/opt/compiler-explorer/clang-rocm-5.0.2/amdgcn/bitcode -include hip/hip_runtime.h compiler.hipclang-rocm-50103.exe=/opt/compiler-explorer/clang-rocm-5.1.3/bin/clang++ -compiler.hipclang-rocm-50103.semver=rocm-5.1.3 +compiler.hipclang-rocm-50103.semver=5.1.3 +compiler.hipclang-rocm-50103.name=clang rocm-5.1.3 compiler.hipclang-rocm-50103.objdumper=/opt/compiler-explorer/clang-rocm-50103/bin/llvm-objdump compiler.hipclang-rocm-50103.options=-x hip --cuda-device-only -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false -O3 -D__HIP_PLATFORM_AMD__=1 -D__HIP_PLATFORM_HCC__=1 -isystem /opt/compiler-explorer/libs/rocm/5.1.3/include --rocm-path=/opt/compiler-explorer/libs/rocm/5.1.3 --rocm-device-lib-path=/opt/compiler-explorer/clang-rocm-5.1.3/amdgcn/bitcode -include hip/hip_runtime.h compiler.hipclang-rocm-50203.exe=/opt/compiler-explorer/clang-rocm-5.2.3/bin/clang++ -compiler.hipclang-rocm-50203.semver=rocm-5.2.3 +compiler.hipclang-rocm-50203.semver=5.2.3 +compiler.hipclang-rocm-50203.name=clang rocm-5.2.3 compiler.hipclang-rocm-50203.objdumper=/opt/compiler-explorer/clang-rocm-50203/bin/llvm-objdump compiler.hipclang-rocm-50203.options=-x hip --cuda-device-only -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false -O3 -D__HIP_PLATFORM_AMD__=1 -D__HIP_PLATFORM_HCC__=1 -isystem /opt/compiler-explorer/libs/rocm/5.2.3/include --rocm-path=/opt/compiler-explorer/libs/rocm/5.2.3 --rocm-device-lib-path=/opt/compiler-explorer/clang-rocm-5.2.3/amdgcn/bitcode -include hip/hip_runtime.h diff --git a/etc/config/sponsors.yaml b/etc/config/sponsors.yaml index 2cffd3fa8..9d94dea3e 100644 --- a/etc/config/sponsors.yaml +++ b/etc/config/sponsors.yaml @@ -21,11 +21,11 @@ levels: sideBySide: true statsId: intel - name: Backtrace - description: We compress error debugging time by automating capture and providing essential context and insight about impact, all on one platform. Get started for free. + description: Deliver uninterrupted experiences by automating your response to player-impacting errors. Get started for free. icon: https://static.ce-cdn.net/bt/Black-BT-Logo-A.svg icon_dark: https://static.ce-cdn.net/bt/White-BT-Logo-A.svg img: https://static.ce-cdn.net/bt/BT-logo (1).png - url: https://hubs.la/Q013D7rx0 + url: https://backtrace.io/sign-up?utm_source=website&utm_medium=paiddisplay&utm_campaign=00O8Y000008JiuiUAC&utm_content=godboltbannerad priority: 500 topIcon: true sideBySide: true diff --git a/lib/compilers/cc65.ts b/lib/compilers/cc65.ts index aa7c30b19..e0afe4d88 100644 --- a/lib/compilers/cc65.ts +++ b/lib/compilers/cc65.ts @@ -27,6 +27,7 @@ import path from 'path'; import fs from 'fs-extra'; import _ from 'underscore'; +import {CompilationResult} from '../../types/compilation/compilation.interfaces'; import {ParseFilters} from '../../types/features/filters.interfaces'; import {BaseCompiler} from '../base-compiler'; import {CC65AsmParser} from '../parsers/asm-parser-cc65'; @@ -91,7 +92,14 @@ export class Cc65Compiler extends BaseCompiler { return env; } - override async objdump(outputFilename, result: any, maxSize: number, intelAsm, demangle, filters: ParseFilters) { + override async objdump( + outputFilename, + result: CompilationResult, + maxSize: number, + intelAsm, + demangle, + filters: ParseFilters, + ) { const res = await super.objdump(outputFilename, result, maxSize, intelAsm, demangle, filters); const dirPath = path.dirname(outputFilename); @@ -105,7 +113,7 @@ export class Cc65Compiler extends BaseCompiler { return res; } - override async doBuildstepAndAddToResult(result, name, command, args, execParams) { + override async doBuildstepAndAddToResult(result: CompilationResult, name, command, args, execParams) { const stepResult = await super.doBuildstepAndAddToResult(result, name, command, args, execParams); if (name === 'make') { const mapFile = path.join(execParams.customCwd, '../map.txt'); diff --git a/lib/parsers/llvm-pass-dump-parser.ts b/lib/parsers/llvm-pass-dump-parser.ts index c4221a781..5e1704e84 100644 --- a/lib/parsers/llvm-pass-dump-parser.ts +++ b/lib/parsers/llvm-pass-dump-parser.ts @@ -453,16 +453,6 @@ export class LlvmPassDumpParser { } } - // findLastIndex is currently unavailable in node, replacement essentially taken from - // https://stackoverflow.com/a/53187807/89706 - findLastIndex(array: Array, predicate: (value: T) => boolean): number { - let l = array.length; - while (l--) { - if (predicate(array[l])) return l; - } - return 0; // if not found slice entire array. -1 would slice only the *last* element - } - applyIrFilters(ir: ResultLine[], llvmOptPipelineOptions: LLVMOptPipelineBackendOptions) { // Additional filters conditionally enabled by `filterDebugInfo` let filters = this.filters; @@ -472,35 +462,36 @@ export class LlvmPassDumpParser { lineFilters = lineFilters.concat(this.debugInfoLineFilters); } - // Filter junk - // prettier-ignore - const idxAfterHeaders = this.findLastIndex( - ir, - line => (line.text.match(this.irDumpHeader) || line.text.match(this.machineCodeDumpHeader)) !== null); - - return ir - .slice(idxAfterHeaders) - .filter(line => filters.every(re => line.text.match(re) === null)) // apply filters - .map(_line => { - let line = _line.text; - // eslint-disable-next-line no-constant-condition - while (true) { - let newLine = line; - for (const re of lineFilters) { - newLine = newLine.replace(re, ''); + return ( + ir + // whole-line filters + .filter(line => filters.every(re => line.text.match(re) === null)) + // intra-line filters + .map(_line => { + let line = _line.text; + // eslint-disable-next-line no-constant-condition + while (true) { + let newLine = line; + for (const re of lineFilters) { + newLine = newLine.replace(re, ''); + } + if (newLine === line) { + break; + } else { + line = newLine; + } } - if (newLine === line) { - break; - } else { - line = newLine; - } - } - _line.text = line; - return _line; - }); + _line.text = line; + return _line; + }) + ); } - process(ir: ResultLine[], _: ParseFilters, llvmOptPipelineOptions: LLVMOptPipelineBackendOptions) { + process(output: ResultLine[], _: ParseFilters, llvmOptPipelineOptions: LLVMOptPipelineBackendOptions) { + // Crop out any junk before the pass dumps (e.g. warnings) + const ir = output.slice( + output.findIndex(line => line.text.match(this.irDumpHeader) || line.text.match(this.machineCodeDumpHeader)), + ); const preprocessed_lines = this.applyIrFilters(ir, llvmOptPipelineOptions); return this.breakdownOutput(preprocessed_lines, llvmOptPipelineOptions); } diff --git a/static/compiler-service.interfaces.ts b/static/compiler-service.interfaces.ts new file mode 100644 index 000000000..000218e28 --- /dev/null +++ b/static/compiler-service.interfaces.ts @@ -0,0 +1,36 @@ +// Copyright (c) 2022, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +export enum CompilationStatusCode { + NONE = 0, + OK = 1, + WITH_WARNINGS = 2, + WITH_ERRORS = 3, + COMPILING = 4, +} + +export interface CompilationStatus { + code: CompilationStatusCode; + compilerOut: number; +} diff --git a/static/compiler-service.ts b/static/compiler-service.ts index 79ae4d414..ed0be2482 100644 --- a/static/compiler-service.ts +++ b/static/compiler-service.ts @@ -36,18 +36,14 @@ import jqXHR = JQuery.jqXHR; import ErrorTextStatus = JQuery.Ajax.ErrorTextStatus; import {CompilerInfo} from '../types/compiler.interfaces'; import {CompilationResult} from '../types/compilation/compilation.interfaces'; - -type CompilationStatus = { - code: 0 | 1 | 2 | 3 | 4; - compilerOut: number; -}; +import {CompilationStatus} from './compiler-service.interfaces'; const ASCII_COLORS_RE = new RegExp(/\x1B\[[\d;]*m(.\[K)?/g); export class CompilerService { private readonly base = window.httpRoot; private allowStoreCodeDebug: boolean; - private cache: LRU; + cache: LRU; private readonly compilersByLang: Record>; constructor(eventHub: EventEmitter) { @@ -148,7 +144,7 @@ export class CompilerService { .value(); } - private getCompilersForLang(langId: string): Record { + getCompilersForLang(langId: string): Record { return langId in this.compilersByLang ? this.compilersByLang[langId] : {}; } diff --git a/static/motd.interfaces.ts b/static/motd.interfaces.ts index c8d9e18f3..ab84df778 100644 --- a/static/motd.interfaces.ts +++ b/static/motd.interfaces.ts @@ -24,7 +24,7 @@ import {editor} from 'monaco-editor/'; -type Decoration = { +export type Decoration = { decoration: editor.IModelDecorationOptions; filter: string[]; name: string; diff --git a/static/multifile-service.ts b/static/multifile-service.ts index 8c5fc75c3..5b6261b70 100644 --- a/static/multifile-service.ts +++ b/static/multifile-service.ts @@ -237,7 +237,7 @@ export class MultifileService { if (file.isOpen) { const editor = this.hub.getEditorById(file.editorId); - return editor.getSource(); + return editor?.getSource() ?? ''; } else { return file.content; } diff --git a/static/panes/compiler.interfaces.ts b/static/panes/compiler.interfaces.ts new file mode 100644 index 000000000..5f86016be --- /dev/null +++ b/static/panes/compiler.interfaces.ts @@ -0,0 +1,35 @@ +// Copyright (c) 2022, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import {WidgetState} from '../widgets/libs-widget.interfaces'; + +export type CompilerState = WidgetState & { + tree?: number; + source?: number; + compiler: string; + options?: string; + flagsViewOpen?: boolean; + wantOptInfo?: boolean; + lang?: string; +}; diff --git a/static/panes/compiler.js b/static/panes/compiler.js deleted file mode 100644 index 38c498609..000000000 --- a/static/panes/compiler.js +++ /dev/null @@ -1,3294 +0,0 @@ -// Copyright (c) 2012, Compiler Explorer Authors -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -'use strict'; -var $ = require('jquery'); -var _ = require('underscore'); -var ga = require('../analytics').ga; -var colour = require('../colour'); -var Toggles = require('../widgets/toggles').Toggles; -var FontScale = require('../widgets/fontscale').FontScale; -var Promise = require('es6-promise').Promise; -var Components = require('../components'); -var LruCache = require('lru-cache'); -var options = require('../options').options; -var monaco = require('monaco-editor'); -var Alert = require('../alert').Alert; -var bigInt = require('big-integer'); -var LibsWidget = require('../widgets/libs-widget').LibsWidget; -var codeLensHandler = require('../codelens-handler'); -var monacoConfig = require('../monaco-config'); -var TimingWidget = require('../widgets/timing-info-widget'); -var CompilerPicker = require('../compiler-picker').CompilerPicker; -var CompilerService = require('../compiler-service').CompilerService; -var Settings = require('../settings').Settings; -var utils = require('../utils'); -var LibUtils = require('../lib-utils'); -var getAssemblyDocumentation = require('../api/api').getAssemblyDocumentation; -var PaneRenaming = require('../widgets/pane-renaming').PaneRenaming; -var toolIcons = require.context('../../views/resources/logos', false, /\.(png|svg)$/); - -var OpcodeCache = new LruCache({ - max: 64 * 1024, - length: function (n) { - return JSON.stringify(n).length; - }, -}); - -function patchOldFilters(filters) { - if (filters === undefined) return undefined; - // Filters are of the form {filter: true|false¸ ...}. In older versions, we used - // to suppress the {filter:false} form. This means we can't distinguish between - // "filter not on" and "filter not present". In the latter case we want to default - // the filter. In the former case we want the filter off. Filters now don't suppress - // but there are plenty of permalinks out there with no filters set at all. Here - // we manually set any missing filters to 'false' to recover the old behaviour of - // "if it's not here, it's off". - _.each(['binary', 'labels', 'directives', 'commentOnly', 'trim', 'intel'], function (oldFilter) { - if (filters[oldFilter] === undefined) filters[oldFilter] = false; - }); - return filters; -} - -var languages = options.languages; - -// Disable max line count only for the constructor. Turns out, it needs to do quite a lot of things -// eslint-disable-next-line max-statements -function Compiler(hub, container, state) { - this.container = container; - this.hub = hub; - this.eventHub = hub.createEventHub(); - this.compilerService = hub.compilerService; - this.domRoot = container.getElement(); - this.domRoot.html($('#compiler').html()); - this.id = state.id || hub.nextCompilerId(); - this.sourceTreeId = state.tree ? state.tree : false; - if (this.sourceTreeId) { - this.sourceEditorId = false; - } else { - this.sourceEditorId = state.source || 1; - } - this.settings = Settings.getStoredSettings(); - this.originalCompilerId = state.compiler; - this.initLangAndCompiler(state); - this.infoByLang = {}; - this.deferCompiles = hub.deferred; - this.needsCompile = false; - this.deviceViewOpen = false; - this.options = state.options || options.compileOptions[this.currentLangId]; - this.source = ''; - this.assembly = []; - this.colours = []; - this.lastResult = {}; - this.lastTimeTaken = 0; - this.pendingRequestSentAt = 0; - this.pendingCMakeRequestSentAt = 0; - this.nextRequest = null; - this.nextCMakeRequest = null; - this.optViewOpen = false; - this.flagsViewOpen = state.flagsViewOpen || false; - this.cfgViewOpen = false; - this.wantOptInfo = state.wantOptInfo; - this.decorations = {}; - this.prevDecorations = []; - this.labelDefinitions = {}; - this.alertSystem = new Alert(); - this.alertSystem.prefixMessage = 'Compiler #' + this.id; - - this.awaitingInitialResults = false; - this.selection = state.selection; - - this.linkedFadeTimeoutId = -1; - this.toolsMenu = null; - - this.revealJumpStack = []; - - this.paneRenaming = new PaneRenaming(this, state); - - this.initButtons(state); - - this.outputEditor = monaco.editor.create( - this.monacoPlaceholder[0], - monacoConfig.extendConfig( - { - readOnly: true, - language: 'asm', - glyphMargin: !options.embedded, - guides: false, - vimInUse: false, - }, - this.settings - ) - ); - - this.fontScale = new FontScale(this.domRoot, state, this.outputEditor); - this.compilerPicker = new CompilerPicker( - this.domRoot, - this.hub, - this.currentLangId, - this.compiler ? this.compiler.id : null, - _.bind(this.onCompilerChange, this) - ); - - this.initLibraries(state); - - this.initEditorActions(); - this.initEditorCommands(); - - this.initCallbacks(); - // Handle initial settings - this.onSettingsChange(this.settings); - this.sendCompiler(); - this.updateCompilerInfo(); - this.updateButtons(); - this.saveState(); - ga.proxy('send', { - hitType: 'event', - eventCategory: 'OpenViewPane', - eventAction: 'Compiler', - }); - - if (this.sourceTreeId) { - this.compile(); - } -} - -Compiler.prototype.getEditorIdBySourcefile = function (sourcefile) { - if (this.sourceTreeId) { - var tree = this.hub.getTreeById(this.sourceTreeId); - if (tree) { - return tree.multifileService.getEditorIdByFilename(sourcefile.file); - } - } else { - if (sourcefile !== null && (sourcefile.file === null || sourcefile.mainsource)) { - return this.sourceEditorId; - } - } - - return false; -}; - -Compiler.prototype.initLangAndCompiler = function (state) { - var langId = state.lang; - var compilerId = state.compiler; - var result = this.compilerService.processFromLangAndCompiler(langId, compilerId); - this.compiler = result.compiler; - this.currentLangId = result.langId; - this.updateLibraries(); -}; - -Compiler.prototype.close = function () { - codeLensHandler.unregister(this.id); - this.eventHub.unsubscribe(); - this.eventHub.emit('compilerClose', this.id, this.sourceTreeId); - this.outputEditor.dispose(); -}; - -// eslint-disable-next-line max-statements -Compiler.prototype.initPanerButtons = function () { - var outputConfig = _.bind(function () { - return Components.getOutput(this.id, this.sourceEditorId, this.sourceTreeId); - }, this); - - this.container.layoutManager.createDragSource(this.outputBtn, outputConfig); - this.outputBtn.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(outputConfig); - }, this) - ); - - var cloneComponent = _.bind(function () { - var currentState = this.currentState(); - // Delete the saved id to force a new one - delete currentState.id; - return { - type: 'component', - componentName: 'compiler', - componentState: currentState, - }; - }, this); - var createOptView = _.bind(function () { - return Components.getOptViewWith( - this.id, - this.source, - this.lastResult.optOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createFlagsView = _.bind(function () { - return Components.getFlagsViewWith(this.id, this.getCompilerName(), this.optionsField.val()); - }, this); - - if (this.flagsViewOpen) { - createFlagsView(); - } - - var createPpView = _.bind(function () { - return Components.getPpViewWith( - this.id, - this.source, - this.lastResult.ppOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createAstView = _.bind(function () { - return Components.getAstViewWith( - this.id, - this.source, - this.lastResult.astOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createIrView = _.bind(function () { - return Components.getIrViewWith( - this.id, - this.source, - this.lastResult.irOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createLLVMOptPipelineView = _.bind(function () { - return Components.getLLVMOptPipelineViewWith( - this.id, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createDeviceView = _.bind(function () { - return Components.getDeviceViewWith( - this.id, - this.source, - this.lastResult.devices, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createRustMirView = _.bind(function () { - return Components.getRustMirViewWith( - this.id, - this.source, - this.lastResult.rustMirOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createRustMacroExpView = _.bind(function () { - return Components.getRustMacroExpViewWith( - this.id, - this.source, - this.lastResult.rustMacroExpOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createRustHirView = _.bind(function () { - return Components.getRustHirViewWith( - this.id, - this.source, - this.lastResult.rustHirOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createHaskellCoreView = _.bind(function () { - return Components.getHaskellCoreViewWith( - this.id, - this.source, - this.lastResult.haskellCoreOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createHaskellStgView = _.bind(function () { - return Components.getHaskellStgViewWith( - this.id, - this.source, - this.lastResult.haskellStgOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createHaskellCmmView = _.bind(function () { - return Components.getHaskellCmmViewWith( - this.id, - this.source, - this.lastResult.haskellCmmOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createGccDumpView = _.bind(function () { - return Components.getGccDumpViewWith( - this.id, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId, - this.lastResult.gccDumpOutput - ); - }, this); - - var createGnatDebugTreeView = _.bind(function () { - return Components.getGnatDebugTreeViewWith( - this.id, - this.source, - this.lastResult.gnatDebugTreeOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createGnatDebugView = _.bind(function () { - return Components.getGnatDebugViewWith( - this.id, - this.source, - this.lastResult.gnatDebugOutput, - this.getCompilerName(), - this.sourceEditorId, - this.sourceTreeId - ); - }, this); - - var createCfgView = _.bind(function () { - return Components.getCfgViewWith(this.id, this.sourceEditorId, this.sourceTreeId); - }, this); - - var createExecutor = _.bind(function () { - var currentState = this.currentState(); - var editorId = currentState.source; - var treeId = currentState.tree; - var langId = currentState.lang; - var compilerId = currentState.compiler; - var libs = []; - _.each(this.libsWidget.getLibsInUse(), function (item) { - libs.push({ - name: item.libId, - ver: item.versionId, - }); - }); - return Components.getExecutorWith(editorId, langId, compilerId, libs, currentState.options, treeId); - }, this); - - var newPaneDropdown = this.domRoot.find('.new-pane-dropdown'); - var togglePannerAdder = function () { - newPaneDropdown.dropdown('toggle'); - }; - - // Note that the .d.ts file lies. createDragSource returns the newly created DragSource - this.container.layoutManager - .createDragSource(this.domRoot.find('.btn.add-compiler'), cloneComponent) - ._dragListener.on('dragStart', togglePannerAdder); - - this.domRoot.find('.btn.add-compiler').click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(cloneComponent); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.optButton, createOptView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.optButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createOptView); - }, this) - ); - - var popularArgumentsMenu = this.domRoot.find('div.populararguments div.dropdown-menu'); - this.container.layoutManager - .createDragSource(this.flagsButton, createFlagsView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.flagsButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createFlagsView); - }, this) - ); - - popularArgumentsMenu.append(this.flagsButton); - - this.container.layoutManager - .createDragSource(this.ppButton, createPpView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.ppButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createPpView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.astButton, createAstView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.astButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createAstView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.irButton, createIrView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.irButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createIrView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.llvmOptPipelineButton, createLLVMOptPipelineView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.llvmOptPipelineButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createLLVMOptPipelineView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.deviceButton, createDeviceView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.deviceButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createDeviceView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.rustMirButton, createRustMirView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.rustMirButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createRustMirView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.haskellCoreButton, createHaskellCoreView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.haskellCoreButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createHaskellCoreView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.haskellStgButton, createHaskellStgView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.haskellStgButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createHaskellStgView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.haskellCmmButton, createHaskellCmmView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.haskellCmmButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createHaskellCmmView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.rustMacroExpButton, createRustMacroExpView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.rustMacroExpButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createRustMacroExpView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.rustHirButton, createRustHirView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.rustHirButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createRustHirView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.gccDumpButton, createGccDumpView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.gccDumpButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createGccDumpView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.gnatDebugTreeButton, createGnatDebugTreeView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.gnatDebugTreeButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createGnatDebugTreeView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.gnatDebugButton, createGnatDebugView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.gnatDebugButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createGnatDebugView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.cfgButton, createCfgView) - ._dragListener.on('dragStart', togglePannerAdder); - - this.cfgButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createCfgView); - }, this) - ); - - this.container.layoutManager - .createDragSource(this.executorButton, createExecutor) - ._dragListener.on('dragStart', togglePannerAdder); - - this.executorButton.click( - _.bind(function () { - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createExecutor); - }, this) - ); - - this.initToolButtons(); -}; - -Compiler.prototype.undefer = function () { - this.deferCompiles = false; - if (this.needsCompile) { - this.compile(); - } -}; - -Compiler.prototype.resize = function () { - _.defer(function (self) { - var topBarHeight = utils.updateAndCalcTopBarHeight(self.domRoot, self.topBar, self.hideable); - var bottomBarHeight = self.bottomBar.outerHeight(true); - self.outputEditor.layout({ - width: self.domRoot.width(), - height: self.domRoot.height() - topBarHeight - bottomBarHeight, - }); - }, this); -}; - -// Returns a label name if it can be found in the given position, otherwise -// returns null. -Compiler.prototype.getLabelAtPosition = function (position) { - var asmLine = this.assembly[position.lineNumber - 1]; - // Outdated position.lineNumber can happen (Between compilations?) - Check for those and skip - if (asmLine) { - var column = position.column; - var labels = asmLine.labels || []; - - for (var i = 0; i < labels.length; ++i) { - if (column >= labels[i].range.startCol && column < labels[i].range.endCol) { - return labels[i]; - } - } - } - return null; -}; - -// Jumps to a label definition related to a label which was found in the -// given position and highlights the given range. If no label can be found in -// the given positon it do nothing. -Compiler.prototype.jumpToLabel = function (position) { - var label = this.getLabelAtPosition(position); - - if (!label) { - return; - } - - var labelDefLineNum = this.labelDefinitions[label.name]; - if (!labelDefLineNum) { - return; - } - - // Highlight the new range. - var endLineContent = this.outputEditor.getModel().getLineContent(labelDefLineNum); - - this.pushRevealJump(); - - this.outputEditor.setSelection( - new monaco.Selection(labelDefLineNum, 0, labelDefLineNum, endLineContent.length + 1) - ); - - // Jump to the given line. - this.outputEditor.revealLineInCenter(labelDefLineNum); -}; - -Compiler.prototype.pushRevealJump = function () { - this.revealJumpStack.push(this.outputEditor.saveViewState()); - this.revealJumpStackHasElementsCtxKey.set(true); -}; - -Compiler.prototype.popAndRevealJump = function () { - if (this.revealJumpStack.length > 0) { - this.outputEditor.restoreViewState(this.revealJumpStack.pop()); - this.revealJumpStackHasElementsCtxKey.set(this.revealJumpStack.length > 0); - } -}; - -Compiler.prototype.initEditorActions = function () { - this.isLabelCtxKey = this.outputEditor.createContextKey('isLabel', true); - this.revealJumpStackHasElementsCtxKey = this.outputEditor.createContextKey('hasRevealJumpStackElements', false); - this.isAsmKeywordCtxKey = this.outputEditor.createContextKey('isAsmKeyword', true); - - this.outputEditor.addAction({ - id: 'jumptolabel', - label: 'Jump to label', - keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter], - precondition: 'isLabel', - contextMenuGroupId: 'navigation', - contextMenuOrder: 1.5, - run: _.bind(function (ed) { - var position = ed.getPosition(); - if (position != null) { - this.jumpToLabel(position); - } - }, this), - }); - - // Hiding the 'Jump to label' context menu option if no label can be found - // in the clicked position. - var contextmenu = this.outputEditor.getContribution('editor.contrib.contextmenu'); - var realMethod = contextmenu._onContextMenu; - contextmenu._onContextMenu = _.bind(function (e) { - if (e && e.target && e.target.position) { - if (this.isLabelCtxKey) { - var label = this.getLabelAtPosition(e.target.position); - this.isLabelCtxKey.set(label !== null); - } - - if (this.isAsmKeywordCtxKey) { - if (!this.compiler.supportsAsmDocs) { - // No need to show the "Show asm documentation" if it's just going to fail. - // This is useful for things like xtensa which define an instructionSet but have no docs associated - this.isAsmKeywordCtxKey.set(false); - } else { - var currentWord = this.outputEditor.getModel().getWordAtPosition(e.target.position); - if (currentWord) { - currentWord.range = new monaco.Range( - e.target.position.lineNumber, - Math.max(currentWord.startColumn, 1), - e.target.position.lineNumber, - currentWord.endColumn - ); - if (currentWord.word) { - this.isAsmKeywordCtxKey.set(this.isWordAsmKeyword(currentWord)); - } - } - } - } - } - realMethod.apply(contextmenu, arguments); - }, this); - - this.outputEditor.addAction({ - id: 'returnfromreveal', - label: 'Return from reveal jump', - keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.Enter], - contextMenuGroupId: 'navigation', - contextMenuOrder: 1.4, - precondition: 'hasRevealJumpStackElements', - run: _.bind(function () { - this.popAndRevealJump(); - }, this), - }); - - this.outputEditor.addAction({ - id: 'viewsource', - label: 'Scroll to source', - keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10], - keybindingContext: null, - contextMenuGroupId: 'navigation', - contextMenuOrder: 1.5, - run: _.bind(function (ed) { - var position = ed.getPosition(); - if (position != null) { - var desiredLine = position.lineNumber - 1; - var source = this.assembly[desiredLine].source; - if (source && source.line > 0) { - var editorId = this.getEditorIdBySourcefile(source); - if (editorId) { - // a null file means it was the user's source - this.eventHub.emit('editorLinkLine', editorId, source.line, -1, -1, true); - } - } - } - }, this), - }); - - this.outputEditor.addAction({ - id: 'viewasmdoc', - label: 'View assembly documentation', - keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F8], - keybindingContext: null, - precondition: 'isAsmKeyword', - contextMenuGroupId: 'help', - contextMenuOrder: 1.5, - run: _.bind(this.onAsmToolTip, this), - }); - - this.outputEditor.addAction({ - id: 'toggleColourisation', - label: 'Toggle colourisation', - keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.F1], - keybindingContext: null, - run: _.bind(function () { - this.eventHub.emit('modifySettings', { - colouriseAsm: !this.settings.colouriseAsm, - }); - }, this), - }); -}; - -Compiler.prototype.initEditorCommands = function () { - this.outputEditor.addAction({ - id: 'dumpAsm', - label: 'Developer: Dump asm', - run: _.bind(function () { - // eslint-disable-next-line no-console - console.log(this.assembly); - }, this), - }); -}; - -// Gets the filters that will actually be used (accounting for issues with binary -// mode etc). -Compiler.prototype.getEffectiveFilters = function () { - if (!this.compiler) return {}; - var filters = this.filters.get(); - if (filters.binary && !this.compiler.supportsBinary) { - delete filters.binary; - } - 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]; - } - }); - return filters; -}; - -Compiler.prototype.findTools = function (content, tools) { - if (content.componentName === 'tool') { - if (content.componentState.compiler === this.id) { - tools.push({ - id: content.componentState.toolId, - args: content.componentState.args, - stdin: content.componentState.stdin, - }); - } - } else if (content.content) { - _.each( - content.content, - function (subcontent) { - tools = this.findTools(subcontent, tools); - }, - this - ); - } - - return tools; -}; - -Compiler.prototype.getActiveTools = function (newToolSettings) { - if (!this.compiler) return {}; - - var tools = []; - if (newToolSettings) { - tools.push({ - id: newToolSettings.toolId, - args: newToolSettings.args, - stdin: newToolSettings.stdin, - }); - } - - if (this.container.layoutManager.isInitialised) { - var config = this.container.layoutManager.toConfig(); - return this.findTools(config, tools); - } else { - return tools; - } -}; - -Compiler.prototype.isToolActive = function (activetools, toolId) { - return _.find(activetools, function (tool) { - return tool.id === toolId; - }); -}; - -Compiler.prototype.compile = function (bypassCache, newTools) { - if (this.deferCompiles) { - this.needsCompile = true; - return; - } - this.needsCompile = false; - this.compileInfoLabel.text(' - Compiling...'); - var options = { - userArguments: this.options, - compilerOptions: { - producePp: this.ppViewOpen ? this.ppOptions : false, - produceAst: this.astViewOpen, - produceGccDump: { - opened: this.gccDumpViewOpen, - pass: this.gccDumpPassSelected, - treeDump: this.treeDumpEnabled, - rtlDump: this.rtlDumpEnabled, - ipaDump: this.ipaDumpEnabled, - dumpFlags: this.dumpFlags, - }, - produceOptInfo: this.wantOptInfo, - produceCfg: this.cfgViewOpen, - produceGnatDebugTree: this.gnatDebugTreeViewOpen, - produceGnatDebug: this.gnatDebugViewOpen, - produceIr: this.irViewOpen, - produceLLVMOptPipeline: this.llvmOptPipelineViewOpen ? this.llvmOptPipelineOptions : false, - produceDevice: this.deviceViewOpen, - produceRustMir: this.rustMirViewOpen, - produceRustMacroExp: this.rustMacroExpViewOpen, - produceRustHir: this.rustHirViewOpen, - produceHaskellCore: this.haskellCoreViewOpen, - produceHaskellStg: this.haskellStgViewOpen, - produceHaskellCmm: this.haskellCmmViewOpen, - }, - filters: this.getEffectiveFilters(), - tools: this.getActiveTools(newTools), - libraries: [], - }; - - _.each(this.libsWidget.getLibsInUse(), function (item) { - options.libraries.push({ - id: item.libId, - version: item.versionId, - }); - }); - - if (this.sourceTreeId) { - this.compileFromTree(options, bypassCache); - } else { - this.compileFromEditorSource(options, bypassCache); - } -}; - -Compiler.prototype.compileFromTree = function (options, bypassCache) { - var tree = this.hub.getTreeById(this.sourceTreeId); - if (!tree) { - this.sourceTreeId = false; - this.compileFromEditorSource(options, bypassCache); - return; - } - - var request = { - source: tree.multifileService.getMainSource(), - compiler: this.compiler ? this.compiler.id : '', - options: options, - lang: this.currentLangId, - files: tree.multifileService.getFiles(), - }; - - var fetches = []; - fetches.push( - this.compilerService.expand(request.source).then(function (contents) { - request.source = contents; - }) - ); - - for (var i = 0; i < request.files.length; i++) { - var file = request.files[i]; - fetches.push( - this.compilerService.expand(file.contents).then(function (contents) { - file.contents = contents; - }) - ); - } - - var self = this; - Promise.all(fetches).then(function () { - var treeState = tree.currentState(); - var cmakeProject = tree.multifileService.isACMakeProject(); - - if (bypassCache) request.bypassCache = true; - if (!self.compiler) { - self.onCompileResponse(request, errorResult(''), false); - } else if (cmakeProject && request.source === '') { - self.onCompileResponse(request, errorResult(''), false); - } else { - if (cmakeProject) { - request.options.compilerOptions.cmakeArgs = treeState.cmakeArgs; - request.options.compilerOptions.customOutputFilename = treeState.customOutputFilename; - self.sendCMakeCompile(request); - } else { - self.sendCompile(request); - } - } - }); -}; - -Compiler.prototype.compileFromEditorSource = function (options, bypassCache) { - this.compilerService.expand(this.source).then( - _.bind(function (expanded) { - var request = { - source: expanded || '', - compiler: this.compiler ? this.compiler.id : '', - options: options, - lang: this.currentLangId, - files: [], - }; - if (bypassCache) request.bypassCache = true; - if (!this.compiler) { - this.onCompileResponse(request, errorResult(''), false); - } else { - this.sendCompile(request); - } - }, this) - ); -}; - -Compiler.prototype.sendCMakeCompile = function (request) { - var onCompilerResponse = _.bind(this.onCMakeResponse, this); - - if (this.pendingCMakeRequestSentAt) { - // If we have a request pending, then just store this request to do once the - // previous request completes. - this.nextCMakeRequest = request; - return; - } - this.eventHub.emit('compiling', this.id, this.compiler); - // Display the spinner - this.handleCompilationStatus({code: 4}); - this.pendingCMakeRequestSentAt = Date.now(); - // After a short delay, give the user some indication that we're working on their - // compilation. - var progress = setTimeout( - _.bind(function () { - this.setAssembly({asm: fakeAsm('')}, 0); - }, this), - 500 - ); - this.compilerService - .submitCMake(request) - .then(function (x) { - clearTimeout(progress); - onCompilerResponse(request, x.result, x.localCacheHit); - }) - .catch(function (x) { - clearTimeout(progress); - var message = 'Unknown error'; - if (_.isString(x)) { - message = x; - } else if (x) { - message = x.error || x.code || message; - } - onCompilerResponse(request, errorResult(''), false); - }); -}; - -Compiler.prototype.sendCompile = function (request) { - var onCompilerResponse = _.bind(this.onCompileResponse, this); - - if (this.pendingRequestSentAt) { - // If we have a request pending, then just store this request to do once the - // previous request completes. - this.nextRequest = request; - return; - } - this.eventHub.emit('compiling', this.id, this.compiler); - // Display the spinner - this.handleCompilationStatus({code: 4}); - this.pendingRequestSentAt = Date.now(); - // After a short delay, give the user some indication that we're working on their - // compilation. - var progress = setTimeout( - _.bind(function () { - this.setAssembly({asm: fakeAsm('')}, 0); - }, this), - 500 - ); - this.compilerService - .submit(request) - .then(function (x) { - clearTimeout(progress); - onCompilerResponse(request, x.result, x.localCacheHit); - }) - .catch(function (e) { - clearTimeout(progress); - var message = 'Unknown error'; - if (_.isString(e)) { - message = e; - } else if (e) { - message = e.error || e.code || e.message; - if (e.stack) { - // eslint-disable-next-line no-console - console.log(e); - } - } - onCompilerResponse(request, errorResult(''), false); - }); -}; - -Compiler.prototype.setNormalMargin = function () { - this.outputEditor.updateOptions({ - lineNumbers: true, - lineNumbersMinChars: 1, - }); -}; - -Compiler.prototype.setBinaryMargin = function () { - this.outputEditor.updateOptions({ - lineNumbersMinChars: 6, - lineNumbers: _.bind(this.getBinaryForLine, this), - }); -}; - -Compiler.prototype.getBinaryForLine = function (line) { - var obj = this.assembly[line - 1]; - if (obj) { - return obj.address ? obj.address.toString(16) : ''; - } else { - return '???'; - } -}; - -Compiler.prototype.setAssembly = function (result, filteredCount) { - var asm = result.asm || fakeAsm(''); - this.assembly = asm; - if (!this.outputEditor || !this.outputEditor.getModel()) return; - var editorModel = this.outputEditor.getModel(); - if (result.languageId) { - monaco.editor.setModelLanguage(editorModel, result.languageId); - } else { - var monacoDisassembly = - (languages[this.currentLangId] ? languages[this.currentLangId].monacoDisassembly : null) || 'asm'; - monaco.editor.setModelLanguage(editorModel, monacoDisassembly); - } - var msg = ''; - if (asm.length) { - msg = _.pluck(asm, 'text').join('\n'); - } else if (filteredCount > 0) { - msg = ''; - } - - if (asm.length === 1 && result.code !== 0 && (result.stderr || result.stdout)) { - msg += '\n\n# For more information see the output window'; - if (!this.isOutputOpened) { - msg += '\n# To open the output window, click or drag the "Output" icon at the bottom of this window'; - } - } - - editorModel.setValue(msg); - - if (!this.awaitingInitialResults) { - if (this.selection) { - this.outputEditor.setSelection(this.selection); - this.outputEditor.revealLinesInCenter(this.selection.startLineNumber, this.selection.endLineNumber); - } - this.awaitingInitialResults = true; - } else { - var visibleRanges = this.outputEditor.getVisibleRanges(); - var currentTopLine = visibleRanges.length > 0 ? visibleRanges[0].startLineNumber : 1; - this.outputEditor.revealLine(currentTopLine); - } - - this.decorations.labelUsages = []; - _.each( - this.assembly, - _.bind(function (obj, line) { - if (!obj.labels || !obj.labels.length) return; - - obj.labels.forEach(function (label) { - this.decorations.labelUsages.push({ - range: new monaco.Range(line + 1, label.range.startCol, line + 1, label.range.endCol), - options: { - inlineClassName: 'asm-label-link', - hoverMessage: [ - { - value: 'Ctrl + Left click to follow the label', - }, - ], - }, - }); - }, this); - }, this) - ); - this.updateDecorations(); - - var codeLenses = []; - if (this.getEffectiveFilters().binary || result.forceBinaryView) { - this.setBinaryMargin(); - _.each( - this.assembly, - _.bind(function (obj, line) { - if (obj.opcodes) { - var address = obj.address ? obj.address.toString(16) : ''; - codeLenses.push({ - range: { - startLineNumber: line + 1, - startColumn: 1, - endLineNumber: line + 2, - endColumn: 1, - }, - id: address, - command: { - title: obj.opcodes.join(' '), - }, - }); - } - }, this) - ); - } else { - this.setNormalMargin(); - } - - if (this.settings.enableCodeLens) { - codeLensHandler.registerLensesForCompiler(this.id, editorModel, codeLenses); - - var currentAsmLang = editorModel.getLanguageId(); - codeLensHandler.registerProviderForLanguage(currentAsmLang); - } else { - // Make sure the codelens is disabled - codeLensHandler.unregister(this.id); - } -}; - -function errorResult(text) { - return {asm: fakeAsm(text), code: -1, stdout: '', stderr: ''}; -} - -function fakeAsm(text) { - return [{text: text, source: null, fake: true}]; -} - -Compiler.prototype.doNextCompileRequest = function () { - if (this.nextRequest) { - var next = this.nextRequest; - this.nextRequest = null; - this.sendCompile(next); - } -}; - -Compiler.prototype.doNextCMakeRequest = function () { - if (this.nextCMakeRequest) { - var next = this.nextCMakeRequest; - this.nextCMakeRequest = null; - this.sendCMakeCompile(next); - } -}; - -Compiler.prototype.onCMakeResponse = function (request, result, cached) { - result.source = this.source; - this.lastResult = result; - var timeTaken = Math.max(0, Date.now() - this.pendingCMakeRequestSentAt); - this.lastTimeTaken = timeTaken; - var wasRealReply = this.pendingCMakeRequestSentAt > 0; - this.pendingCMakeRequestSentAt = 0; - - this.handleCompileRequestAndResult(request, result, cached, wasRealReply, timeTaken); - - this.doNextCMakeRequest(); -}; - -Compiler.prototype.handleCompileRequestAndResult = function (request, result, cached, wasRealReply, timeTaken) { - ga.proxy('send', { - hitType: 'event', - eventCategory: 'Compile', - eventAction: request.compiler, - eventLabel: request.options.userArguments, - eventValue: cached ? 1 : 0, - }); - ga.proxy('send', { - hitType: 'timing', - timingCategory: 'Compile', - timingVar: request.compiler, - timingValue: timeTaken, - }); - - // Delete trailing empty lines - if (Array.isArray(result.asm)) { - var indexToDiscard = _.findLastIndex(result.asm, function (line) { - return !_.isEmpty(line.text); - }); - result.asm.splice(indexToDiscard + 1, result.asm.length - indexToDiscard); - } - - this.labelDefinitions = result.labelDefinitions || {}; - if (result.asm) { - this.setAssembly(result, result.filteredCount || 0); - } else if (result.result && result.result.asm) { - this.setAssembly(result.result, result.result.filteredCount || 0); - } else { - result.asm = fakeAsm(''); - this.setAssembly(result, 0); - } - - var stdout = result.stdout || []; - var stderr = result.stderr || []; - var failed = result.code ? result.code !== 0 : false; - - if (result.buildsteps) { - _.each(result.buildsteps, function (step) { - stdout = stdout.concat(step.stdout || []); - stderr = stderr.concat(step.stderr || []); - failed = failed | (step.code !== 0); - }); - } - - this.handleCompilationStatus(CompilerService.calculateStatusIcon(result)); - this.outputTextCount.text(stdout.length); - this.outputErrorCount.text(stderr.length); - if (this.isOutputOpened || (stdout.length === 0 && stderr.length === 0)) { - this.outputBtn.prop('title', ''); - } else { - CompilerService.handleOutputButtonTitle(this.outputBtn, result); - } - var infoLabelText = ''; - if (cached) { - infoLabelText = ' - cached'; - } else if (wasRealReply) { - infoLabelText = ' - ' + timeTaken + 'ms'; - } - - if (result.asmSize) { - infoLabelText += ' (' + result.asmSize + 'B)'; - } - - if (result.filteredCount && result.filteredCount > 0) { - infoLabelText += ' ~' + result.filteredCount + (result.filteredCount === 1 ? ' line' : ' lines') + ' filtered'; - } - - this.compileInfoLabel.text(infoLabelText); - - if (result.result) { - var wasCmake = - result.buildsteps && - _.any(result.buildsteps, function (step) { - return step.step === 'cmake'; - }); - this.postCompilationResult(request, result.result, wasCmake); - } else { - this.postCompilationResult(request, result); - } - - this.eventHub.emit('compileResult', this.id, this.compiler, result, languages[this.currentLangId]); -}; - -Compiler.prototype.onCompileResponse = function (request, result, cached) { - // Save which source produced this change. It should probably be saved earlier though - result.source = this.source; - this.lastResult = result; - var timeTaken = Math.max(0, Date.now() - this.pendingRequestSentAt); - this.lastTimeTaken = timeTaken; - var wasRealReply = this.pendingRequestSentAt > 0; - this.pendingRequestSentAt = 0; - - this.handleCompileRequestAndResult(request, result, cached, wasRealReply, timeTaken); - - this.doNextCompileRequest(); -}; - -Compiler.prototype.postCompilationResult = function (request, result, wasCmake) { - if (result.popularArguments) { - this.handlePopularArgumentsResult(result.popularArguments); - } else if (this.compiler) { - this.compilerService.requestPopularArguments(this.compiler.id, request.options.userArguments).then( - _.bind(function (result) { - if (result && result.result) { - this.handlePopularArgumentsResult(result.result); - } - }, this) - ); - } - - this.updateButtons(); - - this.checkForUnwiseArguments(result.compilationOptions, wasCmake); - this.setCompilationOptionsPopover(result.compilationOptions ? result.compilationOptions.join(' ') : ''); - - this.checkForHints(result); - - if (result.bbcdiskimage) { - this.emulateBbcDisk(result.bbcdiskimage); - } else if (result.speccytape) { - this.emulateSpeccyTape(result.speccytape); - } else if (result.miraclesms) { - this.emulateMiracleSMS(result.miraclesms); - } else if (result.jsnesrom) { - this.emulateNESROM(result.jsnesrom); - } -}; - -Compiler.prototype.emulateMiracleSMS = function (image) { - var dialog = $('#miracleemu'); - - this.alertSystem.notify( - 'Click ' + - 'here' + - ' to emulate', - { - group: 'emulation', - collapseSimilar: true, - dismissTime: 10000, - onBeforeShow: function (elem) { - elem.find('#miracle_emulink').on('click', function () { - dialog.modal(); - - var emuwindow = dialog.find('#miracleemuframe')[0].contentWindow; - var tmstr = Date.now(); - emuwindow.location = 'https://xania.org/miracle/miracle.html?' + tmstr + '#b64sms=' + image; - }); - }, - } - ); -}; - -Compiler.prototype.emulateSpeccyTape = function (image) { - var dialog = $('#jsspeccyemu'); - - this.alertSystem.notify( - 'Click ' + - 'here' + - ' to emulate', - { - group: 'emulation', - collapseSimilar: true, - dismissTime: 10000, - onBeforeShow: function (elem) { - elem.find('#jsspeccy_emulink').on('click', function () { - dialog.modal(); - - var emuwindow = dialog.find('#speccyemuframe')[0].contentWindow; - var tmstr = Date.now(); - emuwindow.location = 'https://static.ce-cdn.net/jsspeccy/index.html?' + tmstr + '#b64tape=' + image; - }); - }, - } - ); -}; - -Compiler.prototype.emulateBbcDisk = function (bbcdiskimage) { - var dialog = $('#jsbeebemu'); - - this.alertSystem.notify( - 'Click here to emulate', - { - group: 'emulation', - collapseSimilar: true, - dismissTime: 10000, - onBeforeShow: function (elem) { - elem.find('#emulink').on('click', function () { - dialog.modal(); - - var emuwindow = dialog.find('#jsbeebemuframe')[0].contentWindow; - var tmstr = Date.now(); - emuwindow.location = - 'https://bbc.godbolt.org/?' + tmstr + '#embed&autoboot&disc1=b64data:' + bbcdiskimage; - }); - }, - } - ); -}; - -Compiler.prototype.emulateNESROM = function (nesrom) { - var dialog = $('#jsnesemu'); - - this.alertSystem.notify( - 'Click here to emulate', - { - group: 'emulation', - collapseSimilar: true, - dismissTime: 10000, - onBeforeShow: function (elem) { - elem.find('#emulink').on('click', function () { - dialog.modal(); - - var emuwindow = dialog.find('#jsnesemuframe')[0].contentWindow; - var tmstr = Date.now(); - emuwindow.location = - 'https://static.ce-cdn.net/jsnes-ceweb/index.html?' + tmstr + '#b64nes=' + nesrom; - }); - }, - } - ); -}; - -Compiler.prototype.onEditorChange = function (editor, source, langId, compilerId) { - if (this.sourceTreeId) { - var tree = this.hub.getTreeById(this.sourceTreeId); - if (tree) { - if (tree.multifileService.isEditorPartOfProject(editor)) { - if (this.settings.compileOnChange) { - this.compile(); - - return; - } - } - } - } - - if ( - editor === this.sourceEditorId && - langId === this.currentLangId && - (compilerId === undefined || compilerId === this.id) - ) { - this.source = source; - if (this.settings.compileOnChange) { - this.compile(); - } - } -}; - -Compiler.prototype.onCompilerFlagsChange = function (compilerId, compilerFlags) { - if (compilerId === this.id) { - this.onOptionsChange(compilerFlags); - } -}; - -Compiler.prototype.onToolOpened = function (compilerId, toolSettings) { - if (this.id === compilerId) { - var toolId = toolSettings.toolId; - - var buttons = this.toolsMenu.find('button'); - $(buttons).each( - _.bind(function (idx, button) { - var toolButton = $(button); - var toolName = toolButton.data('toolname'); - if (toolId === toolName) { - toolButton.prop('disabled', true); - } - }, this) - ); - - this.compile(false, toolSettings); - } -}; - -Compiler.prototype.onToolClosed = function (compilerId, toolSettings) { - if (this.id === compilerId) { - var toolId = toolSettings.toolId; - - var buttons = this.toolsMenu.find('button'); - $(buttons).each( - _.bind(function (idx, button) { - var toolButton = $(button); - var toolName = toolButton.data('toolname'); - if (toolId === toolName) { - toolButton.prop('disabled', !this.supportsTool(toolId)); - } - }, this) - ); - } -}; - -Compiler.prototype.onOutputOpened = function (compilerId) { - if (this.id === compilerId) { - this.isOutputOpened = true; - this.outputBtn.prop('disabled', true); - this.resendResult(); - } -}; - -Compiler.prototype.onOutputClosed = function (compilerId) { - if (this.id === compilerId) { - this.isOutputOpened = false; - this.outputBtn.prop('disabled', false); - } -}; - -Compiler.prototype.onOptViewClosed = function (id) { - if (this.id === id) { - this.wantOptInfo = false; - this.optViewOpen = false; - this.optButton.prop('disabled', this.optViewOpen); - } -}; - -Compiler.prototype.onFlagsViewClosed = function (id, compilerFlags) { - if (this.id === id) { - this.flagsViewOpen = false; - this.optionsField.val(compilerFlags); - this.optionsField.prop('disabled', this.flagsViewOpen); - this.optionsField.prop('placeholder', this.initialOptionsFieldPlacehoder); - this.flagsButton.prop('disabled', this.flagsViewOpen); - - this.compilerService.requestPopularArguments(this.compiler.id, compilerFlags).then( - _.bind(function (result) { - if (result && result.result) { - this.handlePopularArgumentsResult(result.result); - } - }, this) - ); - - this.saveState(); - } -}; - -Compiler.prototype.onToolSettingsChange = function (id) { - if (this.id === id) { - this.compile(); - } -}; - -Compiler.prototype.onPpViewOpened = function (id) { - if (this.id === id) { - this.ppButton.prop('disabled', true); - this.ppViewOpen = true; - // the pp view will request compilation once it populates its options so this.compile() is not called here - } -}; - -Compiler.prototype.onPpViewClosed = function (id) { - if (this.id === id) { - this.ppButton.prop('disabled', false); - this.ppViewOpen = false; - } -}; - -Compiler.prototype.onPpViewOptionsUpdated = function (id, options, reqCompile) { - if (this.id === id) { - this.ppOptions = options; - if (reqCompile) { - this.compile(); - } - } -}; - -Compiler.prototype.onAstViewOpened = function (id) { - if (this.id === id) { - this.astButton.prop('disabled', true); - this.astViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onAstViewClosed = function (id) { - if (this.id === id) { - this.astButton.prop('disabled', false); - this.astViewOpen = false; - } -}; - -Compiler.prototype.onIrViewOpened = function (id) { - if (this.id === id) { - this.irButton.prop('disabled', true); - this.irViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onIrViewClosed = function (id) { - if (this.id === id) { - this.irButton.prop('disabled', false); - this.irViewOpen = false; - } -}; - -Compiler.prototype.onLLVMOptPipelineViewOpened = function (id) { - if (this.id === id) { - this.llvmOptPipelineButton.prop('disabled', true); - this.llvmOptPipelineViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onLLVMOptPipelineViewClosed = function (id) { - if (this.id === id) { - this.llvmOptPipelineButton.prop('disabled', false); - this.llvmOptPipelineViewOpen = false; - } -}; - -Compiler.prototype.onLLVMOptPipelineViewOptionsUpdated = function (id, options, recompile) { - if (this.id === id) { - this.llvmOptPipelineOptions = options; - if (recompile) { - this.compile(); - } - } -}; - -Compiler.prototype.onDeviceViewOpened = function (id) { - if (this.id === id) { - this.deviceButton.prop('disabled', true); - this.deviceViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onDeviceViewClosed = function (id) { - if (this.id === id) { - this.deviceButton.prop('disabled', false); - this.deviceViewOpen = false; - } -}; - -Compiler.prototype.onRustMirViewOpened = function (id) { - if (this.id === id) { - this.rustMirButton.prop('disabled', true); - this.rustMirViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onRustMirViewClosed = function (id) { - if (this.id === id) { - this.rustMirButton.prop('disabled', false); - this.rustMirViewOpen = false; - } -}; - -Compiler.prototype.onHaskellCoreViewOpened = function (id) { - if (this.id === id) { - this.haskellCoreButton.prop('disabled', true); - this.haskellCoreViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onHaskellCoreViewClosed = function (id) { - if (this.id === id) { - this.haskellCoreButton.prop('disabled', false); - this.haskellCoreViewOpen = false; - } -}; - -Compiler.prototype.onHaskellStgViewOpened = function (id) { - if (this.id === id) { - this.haskellStgButton.prop('disabled', true); - this.haskellStgViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onHaskellStgViewClosed = function (id) { - if (this.id === id) { - this.haskellStgButton.prop('disabled', false); - this.haskellStgViewOpen = false; - } -}; - -Compiler.prototype.onHaskellCmmViewOpened = function (id) { - if (this.id === id) { - this.haskellCmmButton.prop('disabled', true); - this.haskellCmmViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onHaskellCmmViewClosed = function (id) { - if (this.id === id) { - this.haskellCmmButton.prop('disabled', false); - this.haskellCmmViewOpen = false; - } -}; - -Compiler.prototype.onGnatDebugTreeViewOpened = function (id) { - if (this.id === id) { - this.gnatDebugTreeButton.prop('disabled', true); - this.gnatDebugTreeViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onGnatDebugTreeViewClosed = function (id) { - if (this.id === id) { - this.gnatDebugTreeButton.prop('disabled', false); - this.gnatDebugTreeViewOpen = false; - } -}; - -Compiler.prototype.onGnatDebugViewOpened = function (id) { - if (this.id === id) { - this.gnatDebugButton.prop('disabled', true); - this.gnatDebugViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onGnatDebugViewClosed = function (id) { - if (this.id === id) { - this.gnatDebugButton.prop('disabled', false); - this.gnatDebugViewOpen = false; - } -}; - -Compiler.prototype.onRustMacroExpViewOpened = function (id) { - if (this.id === id) { - this.rustMacroExpButton.prop('disabled', true); - this.rustMacroExpViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onRustMacroExpViewClosed = function (id) { - if (this.id === id) { - this.rustMacroExpButton.prop('disabled', false); - this.rustMacroExpViewOpen = false; - } -}; - -Compiler.prototype.onRustHirViewOpened = function (id) { - if (this.id === id) { - this.rustHirButton.prop('disabled', true); - this.rustHirViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onRustHirViewClosed = function (id) { - if (this.id === id) { - this.rustHirButton.prop('disabled', false); - this.rustHirViewOpen = false; - } -}; - -Compiler.prototype.onGccDumpUIInit = function (id) { - if (this.id === id) { - this.compile(); - } -}; - -Compiler.prototype.onGccDumpFiltersChanged = function (id, filters, reqCompile) { - if (this.id === id) { - this.treeDumpEnabled = filters.treeDump !== false; - this.rtlDumpEnabled = filters.rtlDump !== false; - this.ipaDumpEnabled = filters.ipaDump !== false; - this.dumpFlags = { - address: filters.addressOption !== false, - slim: filters.slimOption !== false, - raw: filters.rawOption !== false, - details: filters.detailsOption !== false, - stats: filters.statsOption !== false, - blocks: filters.blocksOption !== false, - vops: filters.vopsOption !== false, - lineno: filters.linenoOption !== false, - uid: filters.uidOption !== false, - all: filters.allOption !== false, - }; - - if (reqCompile) { - this.compile(); - } - } -}; - -Compiler.prototype.onGccDumpPassSelected = function (id, passObject, reqCompile) { - if (this.id === id) { - this.gccDumpPassSelected = passObject; - - if (reqCompile && passObject !== null) { - this.compile(); - } - } -}; - -Compiler.prototype.onGccDumpViewOpened = function (id) { - if (this.id === id) { - this.gccDumpButton.prop('disabled', true); - this.gccDumpViewOpen = true; - } -}; - -Compiler.prototype.onGccDumpViewClosed = function (id) { - if (this.id === id) { - this.gccDumpButton.prop('disabled', !this.compiler.supportsGccDump); - this.gccDumpViewOpen = false; - - delete this.gccDumpPassSelected; - delete this.treeDumpEnabled; - delete this.rtlDumpEnabled; - delete this.ipaDumpEnabled; - delete this.dumpFlags; - } -}; - -Compiler.prototype.onOptViewOpened = function (id) { - if (this.id === id) { - this.optViewOpen = true; - this.wantOptInfo = true; - this.optButton.prop('disabled', this.optViewOpen); - this.compile(); - } -}; - -Compiler.prototype.onFlagsViewOpened = function (id) { - if (this.id === id) { - this.flagsViewOpen = true; - this.handlePopularArgumentsResult(false); - this.optionsField.prop('disabled', this.flagsViewOpen); - this.optionsField.val(''); - this.optionsField.prop('placeholder', 'see detailed flags window'); - this.flagsButton.prop('disabled', this.flagsViewOpen); - this.compile(); - this.saveState(); - } -}; - -Compiler.prototype.onCfgViewOpened = function (id) { - if (this.id === id) { - this.cfgButton.prop('disabled', true); - this.cfgViewOpen = true; - this.compile(); - } -}; - -Compiler.prototype.onCfgViewClosed = function (id) { - if (this.id === id) { - this.cfgViewOpen = false; - this.cfgButton.prop('disabled', this.getEffectiveFilters().binary); - } -}; - -Compiler.prototype.initFilterButtons = function () { - this.filterBinaryButton = this.domRoot.find("[data-bind='binary']"); - this.filterBinaryTitle = this.filterBinaryButton.prop('title'); - - this.filterExecuteButton = this.domRoot.find("[data-bind='execute']"); - this.filterExecuteTitle = this.filterExecuteButton.prop('title'); - - this.filterLabelsButton = this.domRoot.find("[data-bind='labels']"); - this.filterLabelsTitle = this.filterLabelsButton.prop('title'); - - 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'); - - this.filterTrimButton = this.domRoot.find("[data-bind='trim']"); - this.filterTrimTitle = this.filterTrimButton.prop('title'); - - this.filterIntelButton = this.domRoot.find("[data-bind='intel']"); - this.filterIntelTitle = this.filterIntelButton.prop('title'); - - this.filterDemangleButton = this.domRoot.find("[data-bind='demangle']"); - this.filterDemangleTitle = this.filterDemangleButton.prop('title'); - - this.noBinaryFiltersButtons = this.domRoot.find('.nonbinary'); -}; - -Compiler.prototype.initButtons = function (state) { - this.filters = new Toggles(this.domRoot.find('.filters'), patchOldFilters(state.filters)); - - this.optButton = this.domRoot.find('.btn.view-optimization'); - this.flagsButton = this.domRoot.find('div.populararguments div.dropdown-menu button'); - this.ppButton = this.domRoot.find('.btn.view-pp'); - this.astButton = this.domRoot.find('.btn.view-ast'); - this.irButton = this.domRoot.find('.btn.view-ir'); - this.llvmOptPipelineButton = this.domRoot.find('.btn.view-llvm-opt-pipeline'); - this.deviceButton = this.domRoot.find('.btn.view-device'); - this.gnatDebugTreeButton = this.domRoot.find('.btn.view-gnatdebugtree'); - this.gnatDebugButton = this.domRoot.find('.btn.view-gnatdebug'); - this.rustMirButton = this.domRoot.find('.btn.view-rustmir'); - this.rustMacroExpButton = this.domRoot.find('.btn.view-rustmacroexp'); - this.rustHirButton = this.domRoot.find('.btn.view-rusthir'); - this.haskellCoreButton = this.domRoot.find('.btn.view-haskellCore'); - this.haskellStgButton = this.domRoot.find('.btn.view-haskellStg'); - this.haskellCmmButton = this.domRoot.find('.btn.view-haskellCmm'); - this.gccDumpButton = this.domRoot.find('.btn.view-gccdump'); - this.cfgButton = this.domRoot.find('.btn.view-cfg'); - this.executorButton = this.domRoot.find('.create-executor'); - this.libsButton = this.domRoot.find('.btn.show-libs'); - - this.compileInfoLabel = this.domRoot.find('.compile-info'); - this.compileClearCache = this.domRoot.find('.clear-cache'); - - this.outputBtn = this.domRoot.find('.output-btn'); - this.outputTextCount = this.domRoot.find('span.text-count'); - this.outputErrorCount = this.domRoot.find('span.err-count'); - - this.optionsField = this.domRoot.find('.options'); - this.initialOptionsFieldPlacehoder = this.optionsField.prop('placeholder'); - this.prependOptions = this.domRoot.find('.prepend-options'); - this.fullCompilerName = this.domRoot.find('.full-compiler-name'); - this.fullTimingInfo = this.domRoot.find('.full-timing-info'); - this.compilerLicenseButton = this.domRoot.find('.compiler-license'); - this.setCompilationOptionsPopover(this.compiler ? this.compiler.options : null); - // Dismiss on any click that isn't either in the opening element, inside - // the popover or on any alert - $(document).on( - 'mouseup', - _.bind(function (e) { - var target = $(e.target); - if ( - !target.is(this.prependOptions) && - this.prependOptions.has(target).length === 0 && - target.closest('.popover').length === 0 - ) - this.prependOptions.popover('hide'); - - if ( - !target.is(this.fullCompilerName) && - this.fullCompilerName.has(target).length === 0 && - target.closest('.popover').length === 0 - ) - this.fullCompilerName.popover('hide'); - }, this) - ); - - this.initFilterButtons(state); - - this.filterExecuteButton.toggle(options.supportsExecute); - this.filterLibraryCodeButton.toggle(options.supportsLibraryCodeFilter); - - this.optionsField.val(this.options); - - this.shortCompilerName = this.domRoot.find('.short-compiler-name'); - this.compilerPicker = this.domRoot.find('.compiler-picker'); - this.setCompilerVersionPopover({version: '', fullVersion: ''}, ''); - - this.topBar = this.domRoot.find('.top-bar'); - this.bottomBar = this.domRoot.find('.bottom-bar'); - this.statusLabel = this.domRoot.find('.status-text'); - - this.hideable = this.domRoot.find('.hideable'); - this.statusIcon = this.domRoot.find('.status-icon'); - - this.monacoPlaceholder = this.domRoot.find('.monaco-placeholder'); - - this.initPanerButtons(); -}; - -Compiler.prototype.onLibsChanged = function () { - this.saveState(); - this.compile(); -}; - -Compiler.prototype.initLibraries = function (state) { - this.libsWidget = new LibsWidget( - this.currentLangId, - this.compiler, - this.libsButton, - state, - _.bind(this.onLibsChanged, this), - LibUtils.getSupportedLibraries( - this.compiler ? this.compiler.libsArr : [], - this.currentLangId, - this.compiler ? this.compiler.remote : null - ) - ); -}; - -Compiler.prototype.updateLibraries = function () { - if (this.libsWidget) { - var filteredLibraries = {}; - if (this.compiler) { - filteredLibraries = LibUtils.getSupportedLibraries( - this.compiler.libsArr, - this.currentLangId, - this.compiler ? this.compiler.remote : null - ); - } - - this.libsWidget.setNewLangId(this.currentLangId, this.compiler ? this.compiler.id : false, filteredLibraries); - } -}; - -Compiler.prototype.isSupportedTool = function (tool) { - if (this.sourceTreeId) { - return tool.tool.type === 'postcompilation'; - } else { - return true; - } -}; - -Compiler.prototype.supportsTool = function (toolId) { - if (!this.compiler) return; - - return _.find( - this.compiler.tools, - _.bind(function (tool) { - return tool.tool.id === toolId && this.isSupportedTool(tool); - }, this) - ); -}; - -Compiler.prototype.initToolButton = function (togglePannerAdder, button, toolId) { - var createToolView = _.bind(function () { - var args = ''; - var monacoStdin = false; - var langTools = options.tools[this.currentLangId]; - if (langTools && langTools[toolId] && langTools[toolId].tool) { - if (langTools[toolId].tool.args !== undefined) { - args = langTools[toolId].tool.args; - } - if (langTools[toolId].tool.monacoStdin !== undefined) { - monacoStdin = langTools[toolId].tool.monacoStdin; - } - } - return Components.getToolViewWith(this.id, this.sourceEditorId, toolId, args, monacoStdin, this.sourceTreeId); - }, this); - - this.container.layoutManager - .createDragSource(button, createToolView) - ._dragListener.on('dragStart', togglePannerAdder); - - button.click( - _.bind(function () { - button.prop('disabled', true); - var insertPoint = - this.hub.findParentRowOrColumn(this.container) || this.container.layoutManager.root.contentItems[0]; - insertPoint.addChild(createToolView); - }, this) - ); -}; - -Compiler.prototype.initToolButtons = function () { - this.toolsMenu = this.domRoot.find('.new-tool-dropdown'); - var toggleToolDropdown = _.bind(function () { - this.toolsMenu.dropdown('toggle'); - }, this); - this.toolsMenu.empty(); - - if (!this.compiler) return; - - var addTool = _.bind(function (toolName, title, toolIcon, toolIconDark) { - var btn = $("