From c206b3cc9ba1fe4689ac02dd4744622b560f3f1a Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Fri, 18 Nov 2022 19:08:37 +0100 Subject: [PATCH] separate llvmmos targets and nes emu (#4299) --- etc/config/c++.amazon.properties | 52 ++++++++++++++----- etc/config/c.amazon.properties | 51 ++++++++++++++---- lib/base-compiler.ts | 19 +++++-- lib/compilers/_all.js | 1 + lib/compilers/llvm-mos.ts | 89 ++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 29 deletions(-) create mode 100644 lib/compilers/llvm-mos.ts diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 16f68b14d35..bddc105cda3 100644 --- a/etc/config/c++.amazon.properties +++ b/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 @@ -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 diff --git a/etc/config/c.amazon.properties b/etc/config/c.amazon.properties index 52541b4e708..a32407d4149 100644 --- a/etc/config/c.amazon.properties +++ b/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 @@ -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 diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 2b10ab2dde4..487038b8ed7 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -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}; @@ -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, diff --git a/lib/compilers/_all.js b/lib/compilers/_all.js index fcd31fddac6..0b5075dc6a0 100644 --- a/lib/compilers/_all.js +++ b/lib/compilers/_all.js @@ -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'; diff --git a/lib/compilers/llvm-mos.ts b/lib/compilers/llvm-mos.ts new file mode 100644 index 00000000000..668686a3d32 --- /dev/null +++ b/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; + } +}