Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add d8 for disassembling javascript #4721

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll get this one installed too.

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=

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some extra whitespace here (I can remove it though)


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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file is misnamed: elsewhere you declare the suffix as .js (hence the check failure)

Copy link
Contributor Author

@gautam1168 gautam1168 Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I have named this file a .mjs is to get around the linter. The linter has an ignore pattern for files in the examples folder. However, it also throws a warning when it ignores that javascript file. Then since the max warnings is set to 0 I can not commit the file if its named as js. I get this error:
image

You can see that it wants to ignore all the files in examples but also doesn't want to tolerate the warning that comes as a result of a javascript file being present in that folder which is skipped.

Javascript files can be named with the extension .mjs : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

I thought this is an acceptable workaround to this dilemma. However if you want me to fix this in another way, please suggest how I should go about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the configuration in the language files to use the .mjs extension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any failing checks now. Please tell me if I am missing something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks : I understand what happened here. This workaround works for me!

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.