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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webassembly language #6429

Merged
merged 5 commits into from
Jun 11, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@
- 'etc/config/vala.*.properties'
- 'static/modes/vala-mode.ts'

'lang-wasm':
- changed-files:
- any-glob-to-any-file:
- 'lib/compilers/wasmtime.ts'
- 'etc/config/wasm.*.properties'
- 'static/modes/wat-mode.ts'

'lang-zig':
- changed-files:
- any-glob-to-any-file:
Expand Down
21 changes: 21 additions & 0 deletions etc/config/wasm.amazon.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
compilers=&wasmtime
objdumper=llvm-objdump
objdumperType=llvm
binaryHideFuncRe=^.*::(:?native_to_wasm_trampoline|wasm_to_native_trampoline|array_to_wasm_trampoline).*$

group.wasmtime.compilers=wasmtime2001
group.wasmtime.compilerType=wasmtime
group.wasmtime.options=-Ddebug-info=y -Ccache=n
group.wasmtime.supportsBinary=true
group.wasmtime.supportsBinaryObject=true
group.wasmtime.versionFlag=--version
group.wasmtime.isSemVer=true
group.wasmtime.baseName=Wasmtime

compiler.wasmtime2001.exe=/opt/compiler-explorer/wasmtime-20.0.1/wasmtime
Copy link
Member

Choose a reason for hiding this comment

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

Confirmed this path 馃憤

Jun/11 02:22 admin-node~ 172.4m $ /opt/compiler-explorer/wasmtime-20.0.1/wasmtime
error: the following required arguments were not provided:
  <WASM>...

Usage: wasmtime <WASM>...

For more information, try '--help'.

compiler.wasmtime2001.semver=20.0.1

#################################
#################################
# Installed libs (See c++.amazon.properties for a scheme of libs group)
libs=
20 changes: 20 additions & 0 deletions etc/config/wasm.defaults.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Default settings for Wasm
compilers=&wasmtimelocal
objdumper=llvm-objdump
objdumperType=llvm
Comment on lines +3 to +4
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 used llvm-objdump here because wasmtime supports a --target=<triple> parameter that cross-compiles WASM modules for other architectures. The problem is that when using objdump it then can't disassemble the resulting file. I'm not sure if there is a better solution to handle these cases

Copy link
Member

Choose a reason for hiding this comment

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

Let's start with this and work on it later if needed.

binaryHideFuncRe=^.*::(:?native_to_wasm_trampoline|wasm_to_native_trampoline|array_to_wasm_trampoline).*$

group.wasmtimelocal.compilers=wasmtimedefault
group.wasmtimelocal.compilerType=wasmtime
group.wasmtimelocal.options=-Ddebug-info=y -Ccache=n
group.wasmtimelocal.supportsBinary=true
group.wasmtimelocal.supportsBinaryObject=true
group.wasmtimelocal.versionFlag=--version

compiler.wasmtimedefault.exe=/opt/compiler-explorer/wasmtime-20.0.1/wasmtime
compiler.wasmtimedefault.name=Wasmtime default

#################################
#################################
# Installed libs (See c++.amazon.properties for a scheme of libs group)
libs=
7 changes: 7 additions & 0 deletions examples/wasm/default.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(module
(func $square (param i32) (result i32)
local.get 0
local.get 0
i32.mul
)
)
1 change: 1 addition & 0 deletions lib/compilers/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export {Win32MingWClang} from './win32-mingw-clang.js';
export {WineVcCompiler} from './wine-vc.js';
export {WslVcCompiler} from './wsl-vc.js';
export {WyrmCompiler} from './wyrm.js';
export {WasmtimeCompiler} from './wasmtime.js';
export {ZigCC} from './zigcc.js';
export {ZigCompiler} from './zig.js';
export {ZigCXX} from './zigcxx.js';
Expand Down
7 changes: 7 additions & 0 deletions lib/compilers/argument-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,13 @@ export class Z88dkParser extends BaseParser {
}
}

export class WasmtimeParser extends BaseParser {
static override async parse(compiler) {
await this.getOptions(compiler, '--help');
return compiler;
}
}

export class ZigCxxParser extends ClangParser {
static override getMainHelpOptions(): string[] {
return ['c++', '--help'];
Expand Down
70 changes: 70 additions & 0 deletions lib/compilers/wasmtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2024, 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 {BaseCompiler} from '../base-compiler.js';

import {WasmtimeParser} from './argument-parsers.js';

export class WasmtimeCompiler extends BaseCompiler {
static get key() {
return 'wasmtime';
}

override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions?: string[]) {
filters.binary = true;
return ['-o', this.filename(outputFilename)];
}

override orderArguments(
options: string[],
inputFilename: string,
libIncludes: string[],
libOptions: string[],
libPaths: string[],
libLinks: string[],
userOptions: string[],
staticLibLinks: string[],
): string[] {
return ['compile', inputFilename]
.concat(options)
.concat(libIncludes, libOptions, libPaths, libLinks, userOptions, staticLibLinks);
}

override getOutputFilename(dirPath: string, outputFilebase: string): string {
return path.join(dirPath, `${outputFilebase}.cwasm`);
}

override getArgumentParser() {
return WasmtimeParser;
}

override getSharedLibraryPathsAsArguments() {
// Wasmtime does not have an equivalent to -Wl,-rpath in its driver, return
// an empty list.
return [];
}
}
11 changes: 11 additions & 0 deletions lib/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,17 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
previewFilter: null,
monacoDisassembly: null,
},
wasm: {
name: 'WASM',
monaco: 'wat',
RubenRBS marked this conversation as resolved.
Show resolved Hide resolved
extensions: ['.wat'],
alias: [],
logoUrl: 'wasm.svg',
logoUrlDark: null,
formatter: null,
previewFilter: null,
monacoDisassembly: null,
},
zig: {
name: 'Zig',
monaco: 'zig',
Expand Down
1 change: 1 addition & 0 deletions static/modes/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ import './spirv-mode';
import './tablegen-mode';
import './v-mode';
import './vala-mode';
import './wat-mode';
import './zig-mode';