From a9d2910c52ca44d5b8f19f802444190140a5baa5 Mon Sep 17 00:00:00 2001 From: Sean Garwood Date: Mon, 22 Dec 2025 20:23:59 -0500 Subject: [PATCH] Warn when assembly output is in AT&T syntax (#4311) (#8272) 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/). --- CONTRIBUTORS.md | 3 ++- static/assembly-syntax.ts | 27 +++++++++++++++++++++++++ static/panes/compiler.ts | 42 +++++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 static/assembly-syntax.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ede8587e6..92e6eb584 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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) diff --git a/static/assembly-syntax.ts b/static/assembly-syntax.ts new file mode 100644 index 000000000..7892d9462 --- /dev/null +++ b/static/assembly-syntax.ts @@ -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]; diff --git a/static/panes/compiler.ts b/static/panes/compiler.ts index d44d991fd..2a7395ff3 100644 --- a/static/panes/compiler.ts +++ b/static/panes/compiler.ts @@ -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 = ''; // 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 { private compilerService: CompilerService; private readonly id: number; @@ -2817,6 +2820,12 @@ export class Compiler extends MonacoPane | null): void { const popularArgumentsMenu = $(this.domRoot.find('div.populararguments div.dropdown-menu')); @@ -3472,11 +3481,28 @@ export class Compiler extends MonacoPane { 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 + '

' + 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
For more information, visit the ' + opcode + + (syntax === 'att' ? syntaxWarning() : '') + ' documentation .' + '
If the documentation for this opcode is wrong or broken in some way, ' + @@ -3666,14 +3694,20 @@ export class Compiler extends MonacoPane
${attSyntaxWarning}`; + } + 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);