Skip to content

Commit

Permalink
Add d8 for disassembling javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam1168 committed Mar 30, 2023
1 parent 2f6902a commit 987b6be
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
22 changes: 22 additions & 0 deletions etc/config/javascript.amazon.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
compilers=&v8
defaultCompiler=v8trunk

group.v8.compilers=v8trunk:v8113
group.v8.isSemver=false
group.v8.baseName=v8

compiler.v8trunk.exe=/opt/compiler-explorer/d8-trunk/d8
compiler.v8trunk.options=--print-opt-code --redirect-code-traces --allow-natives-syntax

compiler.v8113.exe=/opt/compiler-explorer/d8-11.3/d8
compiler.v8113.options=--print-opt-code --redirect-code-traces --allow-natives-syntax

supportsBinary=false
interpreted=true
compilerType=v8
objdumper=
demangler=
postProcess=
options=
supportsExecute=false
stubText=
26 changes: 26 additions & 0 deletions etc/config/javascript.defaults.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Default settings for v8

compilers=&v8
defaultCompiler=v8trunk

group.v8.compilers=v8trunk:v8113
group.v8.isSemver=false
group.v8.baseName=v8

compiler.v8trunk.exe=d8
compiler.v8trunk.options=--print-opt-code --redirect-code-traces --allow-natives-syntax

compiler.v8113.exe=d8
compiler.v8113.options=--print-opt-code --redirect-code-traces --allow-natives-syntax

supportsBinary=false
interpreted=true
compilerType=v8
objdumper=
demangler=
postProcess=
options=
supportsExecute=false
stubText=


13 changes: 13 additions & 0 deletions examples/javascript/default.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function square(a) {
let result = a * a;
return result;
}

// Call function once to fill type information
square(23);

// Call function again to go from uninitialized -> pre-monomorphic -> monomorphic
square(13);
%OptimizeFunctionOnNextCall(square);
square(71);

1 change: 1 addition & 0 deletions lib/compilers/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export {ToitCompiler} from './toit.js';
export {TurboCCompiler} from './turboc.js';
export {TypeScriptNativeCompiler} from './typescript-native.js';
export {VBCompiler} from './dotnet.js';
export {V8Compiler} from './v8.js';
export {Win32Compiler} from './win32.js';
export {Win32Vc6Compiler} from './win32-vc6.js';
export {Win32VcCompiler} from './win32-vc.js';
Expand Down
63 changes: 63 additions & 0 deletions lib/compilers/v8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2023, 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.

import path from 'path';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';

export class V8Compiler extends BaseCompiler {
static get key() {
return 'v8';
}

constructor(compilerInfo: PreliminaryCompilerInfo, env) {
super(compilerInfo, env);
this.compiler.demangler = '';
this.demanglerClass = null;
}

override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string {
return this.filename(path.dirname(inputFilename) + '/code.asm');
}

public override getOutputFilename(dirPath: string, outputFilebase: string, key?: any) {
let filename;
if (key && key.backendOptions && key.backendOptions.customOutputFilename) {
filename = key.backendOptions.customOutputFilename;
} else {
filename = 'code.asm';
}

if (dirPath) {
return path.join(dirPath, filename);
} else {
return filename;
}
}

override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) {
return [];
}
}
11 changes: 11 additions & 0 deletions lib/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,17 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
previewFilter: null,
monacoDisassembly: null,
},
javascript: {
name: 'Javascript',
monaco: 'typescript',
extensions: ['.mjs'],
alias: [],
logoUrl: 'js.svg',
logoUrlDark: null,
formatter: null,
previewFilter: null,
monacoDisassembly: null,
},
};

export const languages: Record<LanguageKey, Language> = _.mapObject(definitions, (lang, key) => {
Expand Down
1 change: 1 addition & 0 deletions types/languages.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type LanguageKey =
| 'jakt'
| 'java'
| 'julia'
| 'javascript'
| 'kotlin'
| 'llvm'
| 'llvm_mir'
Expand Down
31 changes: 31 additions & 0 deletions views/resources/logos/js.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 987b6be

Please sign in to comment.