diff --git a/.eslintrc.yml b/.eslintrc.yml index dd0bcff9a03..051465483de 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 e8e0d620782..17784a71f08 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 77cc7ee8683..6d45596791a 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 da85d979782..99f33ae96a5 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 5cf7a7acf93..b48bfc631dc 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 c89ca48d859..886d2d429bd 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 d6d5221b697..408aa2b3a69 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 791d8a500ec..716db51c134 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 93e73bc4a8b..217ba107370 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'; } }