Skip to content

Commit

Permalink
Ts-ify objdumpers (#4385)
Browse files Browse the repository at this point in the history
* Ts conversion for objdumpers

* Updated copyright years
  • Loading branch information
jeremy-rifkin authored and mattgodbolt committed Jan 24, 2023
1 parent 1270599 commit c1ddb47
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/objdumper/_all.js → 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
Expand Down
17 changes: 10 additions & 7 deletions lib/objdumper/base.js → 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
Expand All @@ -22,18 +22,21 @@
// 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');
if (intelAsm) args.push(...this.intelAsmOptions);

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');
}
}
13 changes: 5 additions & 8 deletions lib/objdumper/binutils.js → 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
Expand All @@ -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';
}
}
15 changes: 6 additions & 9 deletions lib/objdumper/da65.js → lib/objdumper/da65.ts
Expand Up @@ -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';
}
}
4 changes: 2 additions & 2 deletions lib/objdumper/default.js → 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
Expand All @@ -25,7 +25,7 @@
import {BinutilsObjdumper} from './binutils';

export class DefaultObjdumper extends BinutilsObjdumper {
static get key() {
static override get key() {
return 'default';
}
}
13 changes: 5 additions & 8 deletions lib/objdumper/elftoolchain.js → 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
Expand All @@ -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';
}
}
2 changes: 1 addition & 1 deletion lib/objdumper/index.js → 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
Expand Down
13 changes: 5 additions & 8 deletions lib/objdumper/llvm.js → 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
Expand All @@ -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';
}
}

0 comments on commit c1ddb47

Please sign in to comment.