diff --git a/.eslintrc.yml b/.eslintrc.yml index dd0bcff9a03b34814571e4c75d3174fdd5f778ee..051465483ded4af1bdbe30ef838de80745f63eaf 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -70,7 +70,7 @@ rules: no-useless-call: error no-useless-computed-key: error no-useless-concat: error - no-useless-constructor: error + '@typescript-eslint/no-useless-constructor': error no-useless-escape: error no-useless-rename: error no-useless-return: error diff --git a/lib/objdumper/_all.js b/lib/objdumper/_all.ts similarity index 96% rename from lib/objdumper/_all.js rename to lib/objdumper/_all.ts index e8e0d62078209869ca4c918d92b2c5c5be1ad60f..17784a71f082eec781dea4bc6fbe3fdb6e38fe88 100644 --- a/lib/objdumper/_all.js +++ b/lib/objdumper/_all.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/lib/objdumper/base.js b/lib/objdumper/base.ts similarity index 71% rename from lib/objdumper/base.js rename to lib/objdumper/base.ts index 77cc7ee8683ebfa15a33a5058f8f6244212a1271..6d45596791aea433961724b591edac8c7438b4f9 100644 --- a/lib/objdumper/base.js +++ b/lib/objdumper/base.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -22,13 +22,10 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -export class BaseObjdumper { - constructor() { - this.intelAsmOptions = null; - this.widthOptions = null; - } +export abstract class BaseObjdumper { + constructor(protected readonly intelAsmOptions: string[], protected readonly widthOptions: string[]) {} - getDefaultArgs(outputFilename, demangle, intelAsm) { + getDefaultArgs(outputFilename: string, demangle?: boolean, intelAsm?: boolean) { const args = ['-d', outputFilename, '-l', ...this.widthOptions]; if (demangle) args.push('-C'); @@ -36,4 +33,10 @@ export class BaseObjdumper { return args; } + + // There's no way in TS to do an abstract static members and interfaces don't allow "static" at all. + // There's apparently a hack with InstanceType but I couldn't get it working. I think this is the best solution. + static get key(): string { + throw new Error('Objdumper must provide a `static get key()` implementation'); + } } diff --git a/lib/objdumper/binutils.js b/lib/objdumper/binutils.ts similarity index 88% rename from lib/objdumper/binutils.js rename to lib/objdumper/binutils.ts index da85d979782bc662016799fa9dbfab7eb6221e7b..99f33ae96a55313c58008300730aecb095f09b31 100644 --- a/lib/objdumper/binutils.js +++ b/lib/objdumper/binutils.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -25,14 +25,11 @@ import {BaseObjdumper} from './base'; export class BinutilsObjdumper extends BaseObjdumper { - static get key() { - return 'binutils'; - } - constructor() { - super(); + super(['-M', 'intel'], ['--insn-width=16']); + } - this.intelAsmOptions = ['-M', 'intel']; - this.widthOptions = ['--insn-width=16']; + static override get key() { + return 'binutils'; } } diff --git a/lib/objdumper/da65.js b/lib/objdumper/da65.ts similarity index 91% rename from lib/objdumper/da65.js rename to lib/objdumper/da65.ts index 5cf7a7acf93edd4976d73eaacd4af8b77f7f2ac4..b48bfc631dc9a3dee6b29d166c6c2f42891943d1 100644 --- a/lib/objdumper/da65.js +++ b/lib/objdumper/da65.ts @@ -25,18 +25,15 @@ import {BaseObjdumper} from './base'; export class Da65Objdumper extends BaseObjdumper { - static get key() { - return 'da65'; - } - constructor() { - super(); - - this.intelAsmOptions = []; - this.widthOptions = []; + super([], []); } - getDefaultArgs(outputFilename) { + override getDefaultArgs(outputFilename: string) { return [outputFilename]; } + + static override get key() { + return 'da65'; + } } diff --git a/lib/objdumper/default.js b/lib/objdumper/default.ts similarity index 94% rename from lib/objdumper/default.js rename to lib/objdumper/default.ts index c89ca48d8599316cea5d6471dec9c4353ff855f3..886d2d429bd85f00898d2860a8d41f9c1926215c 100644 --- a/lib/objdumper/default.js +++ b/lib/objdumper/default.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -25,7 +25,7 @@ import {BinutilsObjdumper} from './binutils'; export class DefaultObjdumper extends BinutilsObjdumper { - static get key() { + static override get key() { return 'default'; } } diff --git a/lib/objdumper/elftoolchain.js b/lib/objdumper/elftoolchain.ts similarity index 89% rename from lib/objdumper/elftoolchain.js rename to lib/objdumper/elftoolchain.ts index d6d5221b697a247ca469f99eaca8bebb768de676..408aa2b3a6945f8a60cf286ff5a8ef5db3c61719 100644 --- a/lib/objdumper/elftoolchain.js +++ b/lib/objdumper/elftoolchain.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -25,14 +25,11 @@ import {BaseObjdumper} from './base'; export class ElfToolChainObjdumper extends BaseObjdumper { - static get key() { - return 'elftoolchain'; - } - constructor() { - super(); + super(['-M', 'intel'], []); + } - this.intelAsmOptions = ['-M', 'intel']; - this.widthOptions = []; + static override get key() { + return 'elftoolchain'; } } diff --git a/lib/objdumper/index.js b/lib/objdumper/index.ts similarity index 96% rename from lib/objdumper/index.js rename to lib/objdumper/index.ts index 791d8a500ecbe8a3ad828fe9cdbe0550d9297c5d..716db51c134857d4af8d9474e766ad593d78544f 100644 --- a/lib/objdumper/index.js +++ b/lib/objdumper/index.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/lib/objdumper/llvm.js b/lib/objdumper/llvm.ts similarity index 89% rename from lib/objdumper/llvm.js rename to lib/objdumper/llvm.ts index 93e73bc4a8b0e2bd4c318b6361717d1af80b36c3..217ba1073707ada6da6fb6912a68a1d23b746acd 100644 --- a/lib/objdumper/llvm.js +++ b/lib/objdumper/llvm.ts @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Compiler Explorer Authors +// Copyright (c) 2022, Compiler Explorer Authors // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -25,14 +25,11 @@ import {BaseObjdumper} from './base'; export class LlvmObjdumper extends BaseObjdumper { - static get key() { - return 'llvm'; - } - constructor() { - super(); + super(['--x86-asm-syntax=intel'], []); + } - this.intelAsmOptions = ['--x86-asm-syntax=intel']; - this.widthOptions = []; + static override get key() { + return 'llvm'; } }