Skip to content

Commit

Permalink
Add Wyrm transpiler (#6028)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin authored Jan 21, 2024
1 parent e5fb8e1 commit 8c1c3ea
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
18 changes: 17 additions & 1 deletion etc/config/gimple.amazon.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
compilers=&gimplegcc86:&gimplecross
compilers=&gimplegcc86:&gimplecross:&wyrm
defaultCompiler=gimpleg132
demangler=/opt/compiler-explorer/gcc-13.1.0/bin/c++filt
objdumper=/opt/compiler-explorer/gcc-13.1.0/bin/objdump
Expand Down Expand Up @@ -1108,6 +1108,22 @@ compiler.rv32-gimplegcctrunk.isNightly=true
compiler.rv32-gimplegcctrunk.objdumper=/opt/compiler-explorer/riscv32/gcc-trunk/riscv32-unknown-linux-gnu/bin/riscv32-unknown-linux-gnu-objdump
compiler.rv32-gimplegcctrunk.demangler=/opt/compiler-explorer/riscv32/gcc-trunk/riscv32-unknown-linux-gnu/bin/riscv32-unknown-linux-gnu-c++filt

###############################
# Wyrm GIMPLE to LLVM transpiler
group.wyrm.compilers=wyrmtrunk
group.wyrm.groupName=Wyrm
group.wyrm.instructionSet=llvm
group.wyrm.isSemVer=true
group.wyrm.baseName=Wyrm GIMPLE to LLVM Transpiler
group.wyrm.licenseLink=https://github.com/jeremy-rifkin/wyrm/blob/main/LICENSE
group.wyrm.licenseName=MIT
group.wyrm.licensePreamble=Copyright (c) 2023-2024 Jeremy Rifkin
group.wyrm.gccId=cg121

compiler.wyrmtrunk.exe=/opt/compiler-explorer/wyrm-trunk/libplugin.so
compiler.wyrmtrunk.semver=(trunk)


#################################
#################################
# Libraries
Expand Down
1 change: 1 addition & 0 deletions lib/compilers/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export {Win32MingWGcc} from './win32-mingw-gcc.js';
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 {ZigCC} from './zigcc.js';
export {ZigCompiler} from './zig.js';
export {ZigCXX} from './zigcxx.js';
Expand Down
85 changes: 85 additions & 0 deletions lib/compilers/wyrm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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 fs from 'fs/promises';

import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {CompilationEnvironment} from '../compilation-env.js';
import {unwrap} from '../assert.js';

export class WyrmCompiler extends BaseCompiler {
static get key() {
return 'wyrm';
}

gcc: BaseCompiler | undefined;
gccId: string;

constructor(compilerInfo: PreliminaryCompilerInfo & {disabledFilters?: string[]}, env: CompilationEnvironment) {
super(compilerInfo, env);

this.gccId = this.compilerProps<string>(`group.${this.compiler.group}.gccId`);
}

getGcc(): BaseCompiler {
if (!this.gcc) {
this.gcc = unwrap(global.handler_config.compileHandler.findCompiler('c', this.gccId));
}
return unwrap(this.gcc);
}

override async runCompiler(
compiler: string,
options: string[],
inputFilename: string,
execOptions: ExecutionOptions & {env: Record<string, string>},
) {
const gcc = this.getGcc();
const result = await gcc.runCompiler(
gcc.getInfo().exe,
options.concat(`-fplugin=${compiler}`, '-fgimple'),
inputFilename,
execOptions,
);
const oPath = options[options.indexOf('-o') + 1];
await fs.rename(`${path.dirname(oPath)}/x.ll`, oPath);
return {
...result,
languageId: this.getCompilerResultLanguageId(),
};
}

override async getVersion() {
return {
stdout: ['trunk'],
stderr: [],
};
}

override getCompilerResultLanguageId() {
return 'llvm-ir';
}
}

0 comments on commit 8c1c3ea

Please sign in to comment.