mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
Assembly documentation tooltips always display Intel syntax information,
but when the actual assembly output is in AT&T syntax, this can be
confusing due to the reversed operand order (AT&T uses source, dest
while Intel uses dest, source).
This change adds a warning to the tooltip when the assembly output is
NOT in Intel syntax, informing users that the documentation pertains to
Intel syntax.
The warning appears when:
- The user has not enabled the Intel syntax filter (filters.intel is
false)
- The assembly output is therefore in AT&T syntax
The detection uses filters.isSet('intel') rather than compiler.intelAsm,
ensuring we check the actual output syntax (what the user selected)
rather than just whether the compiler supports Intel syntax.
Fixes #4311
refactor: move assembly-syntax type to frontend, remove from device-view
Move types/assembly-syntax.ts to static/assembly-syntax.ts since it's
only used by frontend code (compiler.ts and device-view.ts), not
backend.
Per CONTRIBUTING.md, types/ directory is for shared types used by both
frontend (static/) and backend (lib/). Since AssemblySyntax is
frontend-only, it belongs in static/.
Also removed syntax tracking from device-view entirely:
- Device assembly (CUDA PTX, GPU, etc.) doesn't have Intel/AT&T variants
- device-view was storing syntax as immutable state that never updated
- This would cause incorrect tooltips if user toggled syntax after
opening
- Reverted device-view to match main branch (no syntax support)
Changes:
- Moved types/assembly-syntax.ts -> static/assembly-syntax.ts
- Updated import paths in compiler.ts
- Removed syntax field and imports from device-view.ts/.interfaces.ts
This means no unit tests are required per CONTRIBUTING.md guidelines
(tests only required for server-side components in lib/).
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->
This commit is contained in:
@@ -170,4 +170,5 @@ From oldest to newest contributor, we would like to thank:
|
||||
- [LJ](https://github.com/elle-j)
|
||||
- [Frank Leon Rose](https://github.com/frankleonrose)
|
||||
- [Oguz Ulgen](https://github.com/oulgen)
|
||||
- [Josh Brice] (https://github.com/jjb0123)
|
||||
- [Josh Brice](https://github.com/jjb0123)
|
||||
- [Sean Garwood](https://github.com/sean-garwood)
|
||||
|
||||
27
static/assembly-syntax.ts
Normal file
27
static/assembly-syntax.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2025, 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 const AssemblySyntaxesList = ['att', 'intel'] as const;
|
||||
|
||||
export type AssemblySyntax = (typeof AssemblySyntaxesList)[number];
|
||||
@@ -82,6 +82,7 @@ import {InstructionSet} from '../../types/instructionsets.js';
|
||||
import {LanguageKey} from '../../types/languages.interfaces.js';
|
||||
import {Tool} from '../../types/tool.interfaces.js';
|
||||
import {ArtifactHandler} from '../artifact-handler.js';
|
||||
import {AssemblySyntax} from '../assembly-syntax.js';
|
||||
import {ICompilerShared} from '../compiler-shared.interfaces.js';
|
||||
import {CompilerShared} from '../compiler-shared.js';
|
||||
import {SourceAndFiles} from '../download-service.js';
|
||||
@@ -145,6 +146,8 @@ const COMPILING_PLACEHOLDER = '<Compiling...>';
|
||||
|
||||
// Disable max line count only for the constructor. Turns out, it needs to do quite a lot of things
|
||||
|
||||
const attSyntaxWarning = '***WARNING: The information shown pertains to Intel syntax.***';
|
||||
|
||||
export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, CompilerState> {
|
||||
private compilerService: CompilerService;
|
||||
private readonly id: number;
|
||||
@@ -2817,6 +2820,12 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
);
|
||||
}
|
||||
|
||||
asmSyntax(): AssemblySyntax {
|
||||
return this.compiler?.supportsIntel && this.filters.isSet('intel') && this.compiler.intelAsm.includes('intel')
|
||||
? 'intel'
|
||||
: 'att';
|
||||
}
|
||||
|
||||
handlePopularArgumentsResult(result: Record<string, {description: string}> | null): void {
|
||||
const popularArgumentsMenu = $(this.domRoot.find('div.populararguments div.dropdown-menu'));
|
||||
|
||||
@@ -3472,11 +3481,28 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
public static async getAsmInfo(
|
||||
opcode: string,
|
||||
instructionSet: InstructionSet,
|
||||
syntax: AssemblySyntax = 'intel',
|
||||
): Promise<AssemblyInstructionInfo | undefined> {
|
||||
const cacheName = `asm/${instructionSet}/${opcode}`;
|
||||
const cached = OpcodeCache.get(cacheName);
|
||||
|
||||
// Helper to add AT&T syntax warning to opcode data without mutating cache
|
||||
const addAttWarningIfNeeded = (data: AssemblyInstructionInfo): AssemblyInstructionInfo => {
|
||||
if (syntax === 'att') {
|
||||
return {
|
||||
...data,
|
||||
tooltip: attSyntaxWarning + '\n\n' + data.tooltip,
|
||||
html: attSyntaxWarning + '<br><br>' + data.html,
|
||||
};
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
if (cached) {
|
||||
if (cached.found) return cached.data as AssemblyInstructionInfo;
|
||||
if (cached.found) {
|
||||
const cachedData = cached.data as AssemblyInstructionInfo;
|
||||
return addAttWarningIfNeeded(cachedData);
|
||||
}
|
||||
throw new Error(cached.data as string);
|
||||
}
|
||||
|
||||
@@ -3484,7 +3510,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
const body = await response.json();
|
||||
if (response.status === 200) {
|
||||
OpcodeCache.set(cacheName, {found: true, data: body});
|
||||
return body;
|
||||
return addAttWarningIfNeeded(body);
|
||||
}
|
||||
const error = (body as any).error;
|
||||
OpcodeCache.set(cacheName, {found: false, data: error});
|
||||
@@ -3593,6 +3619,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
const response = await Compiler.getAsmInfo(
|
||||
currentWord.word,
|
||||
unwrap(this.recentInstructionSet || this.compiler.instructionSet),
|
||||
this.asmSyntax(),
|
||||
);
|
||||
if (!response) return;
|
||||
this.decorations.asmToolTip = [
|
||||
@@ -3649,12 +3676,13 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
);
|
||||
}
|
||||
|
||||
function appendInfo(url: string): string {
|
||||
function appendInfo(url: string, syntax: AssemblySyntax): string {
|
||||
return (
|
||||
'<br><br>For more information, visit <a href="' +
|
||||
url +
|
||||
'" target="_blank" rel="noopener noreferrer">the ' +
|
||||
opcode +
|
||||
(syntax === 'att' ? syntaxWarning() : '') +
|
||||
' documentation <sup><small class="fas fa-external-link-alt opens-new-window"' +
|
||||
' title="Opens in a new window"></small></sup></a>.' +
|
||||
'<br>If the documentation for this opcode is wrong or broken in some way, ' +
|
||||
@@ -3666,14 +3694,20 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
|
||||
);
|
||||
}
|
||||
|
||||
function syntaxWarning(): string {
|
||||
return `<br><br><b>${attSyntaxWarning}</b>`;
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.compiler?.supportsAsmDocs) {
|
||||
const asmSyntax = this.asmSyntax();
|
||||
const asmHelp = await Compiler.getAsmInfo(
|
||||
word.word,
|
||||
unwrap(this.recentInstructionSet || this.compiler.instructionSet),
|
||||
asmSyntax,
|
||||
);
|
||||
if (asmHelp) {
|
||||
this.alertSystem.alert(opcode + ' help', asmHelp.html + appendInfo(asmHelp.url), {
|
||||
this.alertSystem.alert(opcode + ' help', asmHelp.html + appendInfo(asmHelp.url, asmSyntax), {
|
||||
onClose: () => {
|
||||
ed.focus();
|
||||
ed.setPosition(pos);
|
||||
|
||||
Reference in New Issue
Block a user