-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
compiler.ts
3568 lines (3157 loc) · 137 KB
/
compiler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
import _ from 'underscore';
import $ from 'jquery';
import {ga} from '../analytics';
import * as colour from '../colour';
import {Toggles} from '../widgets/toggles';
import * as Components from '../components';
import LruCache from 'lru-cache';
import {options} from '../options';
import * as monaco from 'monaco-editor';
import {Alert} from '../widgets/alert';
import bigInt from 'big-integer';
import {LibsWidget} from '../widgets/libs-widget';
import * as codeLensHandler from '../codelens-handler';
import * as monacoConfig from '../monaco-config';
import * as TimingWidget from '../widgets/timing-info-widget';
import {CompilerPicker} from '../widgets/compiler-picker';
import {CompilerService} from '../compiler-service';
import {SiteSettings} from '../settings';
import * as LibUtils from '../lib-utils';
import {getAssemblyDocumentation} from '../api/api';
import {MonacoPane} from './pane';
import {CompilerInfo} from '../../types/compiler.interfaces';
import {MonacoPaneState} from './pane.interfaces';
import {Hub} from '../hub';
import {Container} from 'golden-layout';
import {CompilerState} from './compiler.interfaces';
import {ComponentConfig, ToolViewState} from '../components.interfaces';
import {FiledataPair} from '../multifile-service';
import {LanguageLibs} from '../options.interfaces';
import {GccDumpFiltersState, GccDumpViewSelectedPass} from './gccdump-view.interfaces';
import {Tool} from '../../lib/tooling/base-tool.interface';
import {AssemblyInstructionInfo} from '../../lib/asm-docs/base';
import {PPOptions} from './pp-view.interfaces';
import {CompilationStatus} from '../compiler-service.interfaces';
import {WidgetState} from '../widgets/libs-widget.interfaces';
import {LLVMOptPipelineBackendOptions} from '../../types/compilation/llvm-opt-pipeline-output.interfaces';
import {CompilationResult} from '../../types/compilation/compilation.interfaces';
import {ResultLine} from '../../types/resultline/resultline.interfaces';
import * as utils from '../utils';
import * as Sentry from '@sentry/browser';
import {editor} from 'monaco-editor';
import IEditorMouseEvent = editor.IEditorMouseEvent;
const toolIcons = require.context('../../views/resources/logos', false, /\.(png|svg)$/);
const 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".
['binary', 'labels', 'directives', 'commentOnly', 'trim', 'intel'].forEach(oldFilter => {
if (filters[oldFilter] === undefined) filters[oldFilter] = false;
});
return filters;
}
const languages = options.languages;
type CompilerCurrentState = CompilerState &
MonacoPaneState & {
filters: Record<string, boolean>;
};
type ActiveTools = {
id: number;
args: string[];
stdin: string;
};
type NewToolSettings = {
toolId: number;
args: string[];
stdin: string;
};
type LinkedCode = {
range: monaco.Range;
options: {
isWholeLine: boolean;
linesDecorationsClassName?: string;
className?: string;
inlineClassName?: string;
};
};
type Decorations = Record<string, monaco.editor.IModelDeltaDecoration[] | monaco.editor.IModelDeltaDecoration>;
type CompileRequestOptions = {
userArguments: string;
compilerOptions: {
producePp: PPOptions | null;
produceAst: boolean;
produceGccDump: {
opened: boolean;
pass?: GccDumpViewSelectedPass;
treeDump?: boolean;
rtlDump?: boolean;
ipaDump?: boolean;
dumpFlags: any;
};
produceOptInfo: boolean;
produceCfg: boolean;
produceGnatDebugTree: boolean;
produceGnatDebug: boolean;
produceIr: boolean;
produceLLVMOptPipeline: LLVMOptPipelineBackendOptions | null;
produceDevice: boolean;
produceRustMir: boolean;
produceRustMacroExp: boolean;
produceRustHir: boolean;
produceHaskellCore: boolean;
produceHaskellStg: boolean;
produceHaskellCmm: boolean;
cmakeArgs?: string;
customOutputFilename?: string;
};
filters: Record<string, boolean>;
tools: ActiveTools[];
libraries: {
id: string;
version: string;
}[];
};
type CompileRequest = {
source: string;
compiler: string;
options: CompileRequestOptions;
lang: string | null;
files: FiledataPair[];
bypassCache: boolean;
};
type Assembly = {
labels?: any[];
source?: {
line: number;
column?: number;
};
address?: number;
opcodes?: string[];
text?: string;
fake?: boolean;
};
type DumpFlags = {
address: boolean;
slim: boolean;
raw: boolean;
details: boolean;
stats: boolean;
blocks: boolean;
vops: boolean;
lineno: boolean;
uid: boolean;
all: boolean;
};
// 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
export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, CompilerState> {
private compilerService: CompilerService;
private readonly id: number;
private sourceTreeId: number | null;
private sourceEditorId: number | null;
private originalCompilerId: string;
private readonly infoByLang: Record<string, {compiler: string; options: string}>;
private deferCompiles: boolean;
private needsCompile: boolean;
private deviceViewOpen: boolean;
private options: string;
private source: string;
private assembly: Assembly[];
private colours: string[];
private lastResult: CompilationResult | null;
private lastTimeTaken: number;
private pendingRequestSentAt: number;
private pendingCMakeRequestSentAt: number;
private nextRequest: CompileRequest | null;
private nextCMakeRequest: CompileRequest | null;
private flagsViewOpen: boolean;
private optViewOpen: boolean;
private cfgViewOpen: boolean;
private wantOptInfo?: boolean;
private readonly decorations: Decorations;
private prevDecorations: string[];
private labelDefinitions: Record<any, number>;
private alertSystem: Alert;
private awaitingInitialResults: boolean;
private linkedFadeTimeoutId: NodeJS.Timeout | null;
private toolsMenu: JQuery<HTMLElement> | null;
private revealJumpStack: (monaco.editor.ICodeEditorViewState | null)[];
private compilerPicker: CompilerPicker | JQuery<HTMLElement>;
private compiler: CompilerInfo | null;
private currentLangId: string | null;
private filters: Toggles;
private optButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private flagsButton?: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private ppButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private astButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private irButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private llvmOptPipelineButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private deviceButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private gnatDebugTreeButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private gnatDebugButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private rustMirButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private rustMacroExpButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private haskellCoreButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private haskellStgButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private haskellCmmButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private gccDumpButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private cfgButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private executorButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private libsButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private compileInfoLabel: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private compileClearCache: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private outputBtn: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private outputTextCount: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private outputErrorCount: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private optionsField: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private initialOptionsFieldPlacehoder: JQuery<HTMLElement>;
private prependOptions: JQuery<HTMLElement>;
private fullCompilerName: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private fullTimingInfo: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private compilerLicenseButton: JQuery<HTMLElement>;
private filterBinaryButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterBinaryTitle: JQuery<HTMLElement>;
private filterExecuteButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterExecuteTitle: JQuery<HTMLElement>;
private filterLabelsButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterLabelsTitle: JQuery<HTMLElement>;
private filterDirectivesButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterDirectivesTitle: JQuery<HTMLElement>;
private filterLibraryCodeButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterLibraryCodeTitle: JQuery<HTMLElement>;
private filterCommentsButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterCommentsTitle: JQuery<HTMLElement>;
private filterTrimButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterTrimTitle: JQuery<HTMLElement>;
private filterIntelButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterIntelTitle: JQuery<HTMLElement>;
private filterDemangleButton: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private filterDemangleTitle: JQuery<HTMLElement>;
private noBinaryFiltersButtons: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private shortCompilerName: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private bottomBar: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusLabel: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusIcon: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private monacoPlaceholder: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private rustHirButton: JQuery<HTMLElement>;
private libsWidget: LibsWidget | null;
private isLabelCtxKey: monaco.editor.IContextKey<boolean>;
private revealJumpStackHasElementsCtxKey: monaco.editor.IContextKey<boolean>;
private isAsmKeywordCtxKey: monaco.editor.IContextKey<boolean>;
private lineHasLinkedSourceCtxKey: monaco.editor.IContextKey<boolean>;
private ppViewOpen: boolean;
private astViewOpen: boolean;
private irViewOpen: boolean;
private llvmOptPipelineViewOpen: boolean;
private gccDumpViewOpen: boolean;
private gccDumpPassSelected?: GccDumpViewSelectedPass;
private treeDumpEnabled?: boolean;
private rtlDumpEnabled?: boolean;
private ipaDumpEnabled?: boolean;
private dumpFlags?: DumpFlags;
private gnatDebugTreeViewOpen: boolean;
private gnatDebugViewOpen: boolean;
private rustMirViewOpen: boolean;
private rustMacroExpViewOpen: boolean;
private rustHirViewOpen: boolean;
private haskellCoreViewOpen: boolean;
private haskellStgViewOpen: boolean;
private haskellCmmViewOpen: boolean;
private ppOptions: PPOptions;
private llvmOptPipelineOptions: LLVMOptPipelineBackendOptions;
private isOutputOpened: boolean;
private mouseMoveThrottledFunction?: ((e: monaco.editor.IEditorMouseEvent) => void) & _.Cancelable;
private cursorSelectionThrottledFunction?: ((e: monaco.editor.ICursorSelectionChangedEvent) => void) & _.Cancelable;
private mouseUpThrottledFunction?: ((e: monaco.editor.IEditorMouseEvent) => void) & _.Cancelable;
// eslint-disable-next-line max-statements
constructor(hub: Hub, container: Container, state: MonacoPaneState & CompilerState) {
super(hub, container, state);
this.id = state.id || hub.nextCompilerId();
this.infoByLang = {};
this.deferCompiles = hub.deferred;
this.needsCompile = false;
this.initLangAndCompiler(state);
this.source = '';
this.assembly = [];
this.colours = [];
this.lastResult = null;
this.lastTimeTaken = 0;
this.pendingRequestSentAt = 0;
this.pendingCMakeRequestSentAt = 0;
this.nextRequest = null;
this.nextCMakeRequest = null;
this.optViewOpen = false;
this.cfgViewOpen = false;
this.decorations = {
labelUsages: [],
};
this.prevDecorations = [];
this.labelDefinitions = {};
this.alertSystem = new Alert();
this.alertSystem.prefixMessage = 'Compiler #' + this.id;
this.awaitingInitialResults = false;
this.linkedFadeTimeoutId = null;
this.toolsMenu = null;
this.revealJumpStack = [];
// MonacoPane's registerButtons is not called late enough, we still need to init some buttons with new data
this.initPanerButtons();
this.compilerPicker = new CompilerPicker(
this.domRoot,
this.hub,
this.currentLangId ?? '',
this.compiler?.id ?? '',
this.onCompilerChange.bind(this)
);
this.initLibraries(state);
// MonacoPane's registerCallbacks is not called late enough either
this.initCallbacks();
// Handle initial settings
this.onSettingsChange(this.settings);
this.sendCompiler();
this.updateCompilerInfo();
this.updateButtons();
this.updateState();
if (this.sourceTreeId) {
this.compile();
}
}
override initializeStateDependentProperties(state: MonacoPaneState & CompilerState) {
this.compilerService = this.hub.compilerService;
this.sourceTreeId = state.tree ? state.tree : null;
if (this.sourceTreeId) {
this.sourceEditorId = null;
} else {
this.sourceEditorId = state.source || 1;
}
this.options = state.options || (options.compileOptions[this.currentLangId ?? ''] ?? '');
this.deviceViewOpen = !!state.deviceViewOpen;
this.flagsViewOpen = state.flagsViewOpen || false;
this.wantOptInfo = state.wantOptInfo;
this.originalCompilerId = state.compiler;
this.selection = state.selection;
}
override getInitialHTML() {
return $('#compiler').html();
}
override createEditor(editorRoot: HTMLElement) {
return monaco.editor.create(
editorRoot,
monacoConfig.extendConfig(
{
readOnly: true,
language: 'asm',
glyphMargin: !options.embedded,
// guides: false,
vimInUse: false,
},
this.settings as SiteSettings
)
);
}
override registerOpeningAnalyticsEvent(): void {
ga.proxy('send', {
hitType: 'event',
eventCategory: 'OpenViewPane',
eventAction: 'Compiler',
});
}
getEditorIdBySourcefile(sourcefile: Assembly['source']): number | null {
if (this.sourceTreeId) {
const tree = this.hub.getTreeById(this.sourceTreeId);
if (tree) {
return tree.multifileService.getEditorIdByFilename((sourcefile as any)?.file ?? '');
}
} else {
if (sourcefile != null && ((sourcefile as any).file === null || (sourcefile as any).mainsource)) {
return this.sourceEditorId;
}
}
return null;
}
initLangAndCompiler(state: Pick<MonacoPaneState & CompilerState, 'lang' | 'compiler'>): void {
const langId = state.lang;
const compilerId = state.compiler;
const result = this.compilerService.processFromLangAndCompiler(langId ?? null, compilerId);
this.compiler = result?.compiler ?? null;
this.currentLangId = result?.langId ?? null;
this.updateLibraries();
}
override close(): void {
codeLensHandler.unregister(this.id);
this.eventHub.unsubscribe();
this.eventHub.emit('compilerClose', this.id, this.sourceTreeId ?? 0);
this.editor.dispose();
}
onCompiler(compilerId: number, compiler: unknown, options: string, editorId: number, treeId: number): void {}
onCompileResult(compilerId: number, compiler: unknown, result: unknown): void {}
// eslint-disable-next-line max-statements
initPanerButtons(): void {
const outputConfig = Components.getOutput(
this.id as unknown as string,
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
this.container.layoutManager.createDragSource(this.outputBtn, outputConfig);
this.outputBtn.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(outputConfig);
});
const cloneComponent = () => {
const currentState = this.getCurrentState();
// Delete the saved id to force a new one
// @ts-ignore
delete currentState.id;
return {
type: 'component',
componentName: 'compiler',
componentState: currentState,
};
};
const createOptView = () => {
return Components.getOptViewWith(
this.id,
this.source as unknown as number,
this.lastResult?.optOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createFlagsView = () => {
return Components.getFlagsViewWith(this.id, this.getCompilerName(), this.optionsField.val());
};
if (this.flagsViewOpen) {
createFlagsView();
}
const createPpView = () => {
return Components.getPpViewWith(
this.id,
this.source as unknown as number,
this.lastResult?.ppOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createAstView = () => {
return Components.getAstViewWith(
this.id,
this.source as unknown as number,
this.lastResult?.astOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createIrView = () => {
return Components.getIrViewWith(
this.id,
this.source,
this.lastResult?.irOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createLLVMOptPipelineView = () => {
return Components.getLLVMOptPipelineViewWith(
this.id,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createDeviceView = () => {
return Components.getDeviceViewWith(
this.id,
this.source,
this.lastResult?.devices,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createRustMirView = () => {
return Components.getRustMirViewWith(
this.id,
this.source,
this.lastResult?.rustMirOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createRustMacroExpView = () => {
return Components.getRustMacroExpViewWith(
this.id,
this.source,
this.lastResult?.rustMacroExpOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createRustHirView = () => {
return Components.getRustHirViewWith(
this.id,
this.source,
this.lastResult?.rustHirOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createHaskellCoreView = () => {
return Components.getHaskellCoreViewWith(
this.id,
this.source,
this.lastResult?.haskellCoreOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createHaskellStgView = () => {
return Components.getHaskellStgViewWith(
this.id,
this.source,
this.lastResult?.haskellStgOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createHaskellCmmView = () => {
return Components.getHaskellCmmViewWith(
this.id,
this.source,
this.lastResult?.haskellCmmOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createGccDumpView = () => {
return Components.getGccDumpViewWith(
this.id,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0,
this.lastResult?.gccDumpOutput
);
};
const createGnatDebugTreeView = () => {
return Components.getGnatDebugTreeViewWith(
this.id,
this.source,
this.lastResult?.gnatDebugTreeOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createGnatDebugView = () => {
return Components.getGnatDebugViewWith(
this.id,
this.source,
this.lastResult?.gnatDebugOutput,
this.getCompilerName(),
this.sourceEditorId ?? 0,
this.sourceTreeId ?? 0
);
};
const createCfgView = () => {
return Components.getCfgViewWith(this.id, this.sourceEditorId ?? 0, this.sourceTreeId ?? 0);
};
const createExecutor = () => {
const currentState = this.getCurrentState();
const editorId = currentState.source;
const treeId = currentState.tree;
const langId = currentState.lang;
const compilerId = currentState.compiler;
const libs =
this.libsWidget?.getLibsInUse()?.map(item => ({
name: item.libId,
ver: item.versionId,
})) ?? [];
return Components.getExecutorWith(
editorId ?? 0,
langId ?? '',
compilerId,
libs,
currentState.options,
treeId ?? 0
);
};
const newPaneDropdown = this.domRoot.find('.new-pane-dropdown');
const togglePannerAdder = () => {
newPaneDropdown.dropdown('toggle');
};
// Note that the .d.ts file lies in more than 1 way!
// createDragSource returns the newly created DragSource
// the second parameter can be a function that returns the config!
this.container.layoutManager
.createDragSource(this.domRoot.find('.btn.add-compiler'), cloneComponent as any)
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.domRoot.find('.btn.add-compiler').on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(cloneComponent());
});
this.container.layoutManager
.createDragSource(this.optButton, createOptView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.optButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createOptView());
});
const popularArgumentsMenu = this.domRoot.find('div.populararguments div.dropdown-menu');
if (this.flagsButton) {
this.container.layoutManager
.createDragSource(this.flagsButton, createFlagsView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.flagsButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createFlagsView());
});
popularArgumentsMenu.append(this.flagsButton);
}
this.container.layoutManager
.createDragSource(this.ppButton, createPpView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.ppButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createPpView());
});
this.container.layoutManager
.createDragSource(this.astButton, createAstView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.astButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createAstView());
});
this.container.layoutManager
.createDragSource(this.irButton, createIrView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.irButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createIrView());
});
this.container.layoutManager
.createDragSource(this.llvmOptPipelineButton, createLLVMOptPipelineView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.llvmOptPipelineButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createLLVMOptPipelineView());
});
this.container.layoutManager
.createDragSource(this.deviceButton, createDeviceView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.deviceButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createDeviceView());
});
this.container.layoutManager
.createDragSource(this.rustMirButton, createRustMirView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.rustMirButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createRustMirView());
});
this.container.layoutManager
.createDragSource(this.haskellCoreButton, createHaskellCoreView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.haskellCoreButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createHaskellCoreView());
});
this.container.layoutManager
.createDragSource(this.haskellStgButton, createHaskellStgView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.haskellStgButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createHaskellStgView());
});
this.container.layoutManager
.createDragSource(this.haskellCmmButton, createHaskellCmmView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.haskellCmmButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createHaskellCmmView());
});
this.container.layoutManager
.createDragSource(this.rustMacroExpButton, createRustMacroExpView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.rustMacroExpButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createRustMacroExpView());
});
this.container.layoutManager
.createDragSource(this.rustHirButton, createRustHirView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.rustHirButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createRustHirView());
});
this.container.layoutManager
.createDragSource(this.gccDumpButton, createGccDumpView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.gccDumpButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createGccDumpView());
});
this.container.layoutManager
.createDragSource(this.gnatDebugTreeButton, createGnatDebugTreeView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.gnatDebugTreeButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createGnatDebugTreeView());
});
this.container.layoutManager
.createDragSource(this.gnatDebugButton, createGnatDebugView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.gnatDebugButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createGnatDebugView());
});
this.container.layoutManager
.createDragSource(this.cfgButton, createCfgView())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.cfgButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createCfgView());
});
this.container.layoutManager
.createDragSource(this.executorButton, createExecutor())
// @ts-ignore
._dragListener.on('dragStart', togglePannerAdder);
this.executorButton.on('click', () => {
const insertPoint =
this.hub.findParentRowOrColumn(this.container.parent) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(createExecutor());
});
this.initToolButtons();
}
undefer(): void {
this.deferCompiles = false;
if (this.needsCompile) {
this.compile();
}
}
// Returns a label name if it can be found in the given position, otherwise
// returns null.
getLabelAtPosition(position: monaco.Position): any | null {
const asmLine = this.assembly[position.lineNumber - 1];
// Outdated position.lineNumber can happen (Between compilations?) - Check for those and skip
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (asmLine) {
const column = position.column;
const labels = asmLine.labels || [];
for (let 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 position it do nothing.
jumpToLabel(position: monaco.Position): void {
const label = this.getLabelAtPosition(position);
if (!label) {
return;
}
const labelDefLineNum = this.labelDefinitions[label.name];
if (!labelDefLineNum) {
return;
}
// Highlight the new range.
const endLineContent = this.editor.getModel()?.getLineContent(labelDefLineNum);
this.pushRevealJump();
this.editor.setSelection(
new monaco.Selection(labelDefLineNum, 0, labelDefLineNum, (endLineContent?.length ?? 0) + 1)
);
// Jump to the given line.
this.editor.revealLineInCenter(labelDefLineNum);
}
pushRevealJump(): void {
this.revealJumpStack.push(this.editor.saveViewState());
this.revealJumpStackHasElementsCtxKey.set(true);
}
popAndRevealJump(): void {
if (this.revealJumpStack.length > 0) {
this.editor.restoreViewState(this.revealJumpStack.pop() as any);
this.revealJumpStackHasElementsCtxKey.set(this.revealJumpStack.length > 0);
}
}
override registerEditorActions(): void {
this.isLabelCtxKey = this.editor.createContextKey('isLabel', true);
this.revealJumpStackHasElementsCtxKey = this.editor.createContextKey('hasRevealJumpStackElements', false);
this.isAsmKeywordCtxKey = this.editor.createContextKey('isAsmKeyword', true);
this.lineHasLinkedSourceCtxKey = this.editor.createContextKey('lineHasLinkedSource', false);