Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2k
Warn when assembly output is in AT&T syntax (#4311)#8272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; | ||
| @@ -143,7 +144,10 @@ type Assembly = { | ||
| const COMPILING_PLACEHOLDER = '<Compiling...>'; | ||
| // Disable max line count only for the constructor. Turns out, it needs to do | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. was there a reason to reformat this line? | ||
| // 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; | ||
| @@ -2809,6 +2813,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')); | ||
| @@ -3464,19 +3474,37 @@ 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 | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nice solution to this. | ||
| 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) { | ||
| const cachedData = cached.data as AssemblyInstructionInfo; | ||
| // Return a copy with warnings added based on current syntax mode | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not sure this comment adds anything - the function name is very descriptive. Just | ||
| return addAttWarningIfNeeded(cachedData); | ||
| } | ||
| throw new Error(cached.data as string); | ||
| } | ||
| const response = await getAssemblyDocumentation({opcode, instructionSet}); | ||
| const body = await response.json(); | ||
| if (response.status === 200) { | ||
| OpcodeCache.set(cacheName, {found: true, data: body}); | ||
| returnaddAttWarningIfNeeded(body); | ||
| } | ||
| const error = (body as any).error; | ||
| OpcodeCache.set(cacheName, {found: false, data: error}); | ||
| @@ -3585,6 +3613,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 = [ | ||
| @@ -3641,12 +3670,13 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co | ||
| ); | ||
| } | ||
| 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, ' + | ||
| @@ -3658,14 +3688,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, asmSyntax), { | ||
| onClose: () => { | ||
| ed.focus(); | ||
| ed.setPosition(pos); | ||
Uh oh!
There was an error while loading.Please reload this page.