Skip to content

Commit

Permalink
separate llvmmos targets and nes emu (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
partouf committed Nov 18, 2022
1 parent 5ccd9d2 commit c206b3c
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 29 deletions.
52 changes: 39 additions & 13 deletions etc/config/c++.amazon.properties
@@ -1,4 +1,4 @@
compilers=&gcc86:&icc:&icx:&clang:&clangx86trunk:&clang-rocm:&mosclang:&rvclang:&wasmclang:&cl:&cross:&ellcc:&zapcc:&djggp:www.godbolt.ms@443:&armclang32:&armclang64:&zigcxx:&cxx6502:&nvcxx_x86_cxx:&nvcxx_arm_cxx
compilers=&gcc86:&icc:&icx:&clang:&clangx86trunk:&clang-rocm:&mosclang-trunk:&rvclang:&wasmclang:&cl:&cross:&ellcc:&zapcc:&djggp:www.godbolt.ms@443:&armclang32:&armclang64:&zigcxx:&cxx6502:&nvcxx_x86_cxx:&nvcxx_arm_cxx
defaultCompiler=g122
demangler=/opt/compiler-explorer/gcc-12.2.0/bin/c++filt
objdumper=/opt/compiler-explorer/gcc-12.2.0/bin/objdump
Expand Down Expand Up @@ -550,18 +550,44 @@ compiler.armv8-full-clang-trunk.alias=armv8.5-clang-trunk

################################
# LLVM-MOS (6502 Clang)
group.mosclang.compilers=mosclang-trunk
group.mosclang.baseName=llvm-mos (6502) clang
group.mosclang.groupName=llvm-mos (6502) clang
group.mosclang.options=-mllvm -zp-avail=224
group.mosclang.instructionSet=6502
group.mosclang.supportsBinary=false
group.mosclang.supportsExecute=false
group.mosclang.compilerType=clang
group.mosclang.isSemVer=true

compiler.mosclang-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/clang
compiler.mosclang-trunk.semver=(trunk)
group.mosclang-trunk.compilers=mos-nes-cnrom-trunk:mos-nes-mmc1-trunk:mos-nes-mmc3-trunk:mos-nes-nrom-trunk:mos-atari8-trunk:mos-cx16-trunk:mos-c64-trunk:mos-mega65-trunk:mos-osi-c1p-trunk
group.mosclang-trunk.baseName=llvm-mos
group.mosclang-trunk.groupName=llvm-mos (6502) clang
group.mosclang-trunk.options=--target=mos
group.mosclang-trunk.instructionSet=6502
group.mosclang-trunk.supportsBinary=true
group.mosclang-trunk.supportsExecute=false
group.mosclang-trunk.compilerType=llvmmos
group.mosclang-trunk.isSemVer=true
group.mosclang-trunk.objdumper=/opt/compiler-explorer/llvm-mos-trunk/bin/llvm-objdump
group.mosclang-trunk.objdumperType=llvm

compiler.mos-nes-cnrom-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-cnrom-clang
compiler.mos-nes-cnrom-trunk.semver=nes-cnrom

compiler.mos-nes-mmc1-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-mmc1-clang
compiler.mos-nes-mmc1-trunk.semver=nes-mmc1

compiler.mos-nes-mmc3-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-mmc3-clang
compiler.mos-nes-mmc3-trunk.semver=nes-mmc3

compiler.mos-nes-nrom-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-nrom-clang
compiler.mos-nes-nrom-trunk.semver=nes-nrom

compiler.mos-atari8-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-atari8-clang
compiler.mos-atari8-trunk.semver=atari 8-bit

compiler.mos-cx16-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-cx16-clang
compiler.mos-cx16-trunk.semver=commander X16

compiler.mos-c64-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-c64-clang
compiler.mos-c64-trunk.semver=commodore 64

compiler.mos-mega65-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-mega65-clang
compiler.mos-mega65-trunk.semver=mega65

compiler.mos-osi-c1p-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-osi-c1p-clang
compiler.mos-osi-c1p-trunk.semver=osi-c1p

################################
# Clang for RISC-V
Expand Down
51 changes: 40 additions & 11 deletions etc/config/c.amazon.properties
@@ -1,4 +1,4 @@
compilers=&cgcc86:&cclang:&armcclang32:&armcclang64:mosclang:&rvcclang:&wasmcclang:&ppci:&cicc:&cicx:&ccl:&ccross:&cgcc-classic:&cc65:&sdcc:&ctendra:&tinycc:&zigcc:&cproc86:&chibicc:&z88dk:www.godbolt.ms@443
compilers=&cgcc86:&cclang:&armcclang32:&armcclang64:&cmosclang-trunk:&rvcclang:&wasmcclang:&ppci:&cicc:&cicx:&ccl:&ccross:&cgcc-classic:&cc65:&sdcc:&ctendra:&tinycc:&zigcc:&cproc86:&chibicc:&z88dk:www.godbolt.ms@443
defaultCompiler=cg122
demangler=/opt/compiler-explorer/gcc-12.2.0/bin/c++filt
objdumper=/opt/compiler-explorer/gcc-12.2.0/bin/objdump
Expand Down Expand Up @@ -499,16 +499,45 @@ compiler.armv8-full-cclang-trunk.options=-target aarch64-none-linux-gnu --gcc-to
compiler.armv8-full-cclang-trunk.alias=armv8.5-cclang-trunk

################################
# LLVM-MOS (6502 Clang
compiler.mosclang.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/clang
compiler.mosclang.name=llvm-mos (6502) clang trunk
compiler.mosclang.options=-mllvm -zp-avail=224
compiler.mosclang.instructionSet=6502
compiler.mosclang.supportsBinary=false
compiler.mosclang.supportsExecute=false
compiler.mosclang.compilerType=clang
compiler.mosclang.isSemVer=true
compiler.mosclang.semver=(trunk)
# LLVM-MOS (6502 Clang)
group.cmosclang-trunk.compilers=cmos-nes-cnrom-trunk:cmos-nes-mmc1-trunk:cmos-nes-mmc3-trunk:cmos-nes-nrom-trunk:cmos-atari8-trunk:cmos-cx16-trunk:cmos-c64-trunk:cmos-mega65-trunk:cmos-osi-c1p-trunk
group.cmosclang-trunk.baseName=llvm-mos
group.cmosclang-trunk.groupName=llvm-mos (6502) clang
group.cmosclang-trunk.options=--target=mos
group.cmosclang-trunk.instructionSet=6502
group.cmosclang-trunk.supportsBinary=true
group.cmosclang-trunk.supportsExecute=false
group.cmosclang-trunk.compilerType=llvmmos
group.cmosclang-trunk.isSemVer=true
group.cmosclang-trunk.objdumper=/opt/compiler-explorer/llvm-mos-trunk/bin/llvm-objdump
group.cmosclang-trunk.objdumperType=llvm

compiler.cmos-nes-cnrom-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-cnrom-clang++
compiler.cmos-nes-cnrom-trunk.semver=nes-cnrom

compiler.cmos-nes-mmc1-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-mmc1-clang++
compiler.cmos-nes-mmc1-trunk.semver=nes-mmc1

compiler.cmos-nes-mmc3-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-mmc3-clang++
compiler.cmos-nes-mmc3-trunk.semver=nes-mmc3

compiler.cmos-nes-nrom-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-nes-nrom-clang++
compiler.cmos-nes-nrom-trunk.semver=nes-nrom

compiler.cmos-atari8-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-atari8-clang++
compiler.cmos-atari8-trunk.semver=atari 8-bit

compiler.cmos-cx16-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-cx16-clang++
compiler.cmos-cx16-trunk.semver=commander X16

compiler.cmos-c64-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-c64-clang++
compiler.cmos-c64-trunk.semver=commodore 64

compiler.cmos-mega65-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-mega65-clang++
compiler.cmos-mega65-trunk.semver=mega65

compiler.cmos-osi-c1p-trunk.exe=/opt/compiler-explorer/llvm-mos-trunk/bin/mos-osi-c1p-clang++
compiler.cmos-osi-c1p-trunk.semver=osi-c1p

################################
# Clang for RISC-V
Expand Down
19 changes: 14 additions & 5 deletions lib/base-compiler.ts
Expand Up @@ -1916,6 +1916,18 @@ export class BaseCompiler {
return libsAndOptions;
}

getExtraCMakeArgs(key): string[] {
return [];
}

getCMakeExtToolchainParam(): string {
if (this.toolchainPath) {
return `-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=${this.toolchainPath}`;
}

return '';
}

async cmake(files, key) {
// key = {source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries};

Expand Down Expand Up @@ -1976,13 +1988,10 @@ export class BaseCompiler {

fullResult.downloads = await this.setupBuildEnvironment(cacheKey, dirPath, true);

let toolchainparam = '';
if (this.toolchainPath) {
toolchainparam = `-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=${this.toolchainPath}`;
}
const toolchainparam = this.getCMakeExtToolchainParam();

const cmakeArgs = utils.splitArguments(key.backendOptions.cmakeArgs);
const fullArgs = [toolchainparam, ...cmakeArgs, '..'];
const fullArgs = [toolchainparam, ...this.getExtraCMakeArgs(key), ...cmakeArgs, '..'];

const cmakeStepResult = await this.doBuildstepAndAddToResult(
fullResult,
Expand Down
1 change: 1 addition & 0 deletions lib/compilers/_all.js
Expand Up @@ -66,6 +66,7 @@ export {KotlinCompiler} from './kotlin';
export {LDCCompiler} from './ldc';
export {LLCCompiler} from './llc';
export {LLVMmcaTool} from './llvm-mca';
export {LLVMMOSCompiler} from './llvm-mos';
export {MLIRCompiler} from './mlir';
export {MrustcCompiler} from './mrustc';
export {NasmCompiler} from './nasm';
Expand Down
89 changes: 89 additions & 0 deletions lib/compilers/llvm-mos.ts
@@ -0,0 +1,89 @@
// Copyright (c) 2022, 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-extra';
import _ from 'underscore';

import {CompilationResult} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import * as utils from '../utils';

import {ClangCompiler} from './clang';

export class LLVMMOSCompiler extends ClangCompiler {
static override get key() {
return 'llvmmos';
}

constructor(compilerInfo, env) {
super(compilerInfo, env);
this.externalparser = null;
this.toolchainPath = path.normalize(path.join(path.dirname(this.compiler.exe), '..'));
}

override getExtraCMakeArgs(key): string[] {
return [`-DCMAKE_PREFIX_PATH=${this.toolchainPath}`];
}

override fixFiltersBeforeCacheKey(filters, options, files) {
filters.binary = false;
}

override getCMakeExtToolchainParam(): string {
return '';
}

override async objdump(
outputFilename,
result: CompilationResult,
maxSize: number,
intelAsm,
demangle,
filters: ParseFilters,
) {
if (!outputFilename.endsWith('.elf') && (await utils.fileExists(outputFilename + '.elf'))) {
outputFilename = outputFilename + '.elf';
}

intelAsm = false;
const res = await super.objdump(outputFilename, result, maxSize, intelAsm, demangle, filters);

if (this.compiler.exe.includes('nes')) {
let nesFile = outputFilename;
if (outputFilename.endsWith('.elf')) {
nesFile = outputFilename.substr(0, outputFilename.length - 4);
}

if (await utils.fileExists(nesFile)) {
const file_buffer = await fs.readFile(nesFile);
const binary_base64 = file_buffer.toString('base64');
result.jsnesrom = binary_base64;
}
}

return res;
}
}

0 comments on commit c206b3c

Please sign in to comment.