From 43fbfcd19f4cc87297ec765c7777d4363e7d66cb Mon Sep 17 00:00:00 2001 From: Cr0a3 <127748753+Cr0a3@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:37:40 +0200 Subject: [PATCH] Adding ylc (#6982) Hi dear godbolt team, > Before opening the PR, please make sure that the tests & linter pass their checks, > by running `make check`. With this pr i added support for the ylc compiler. Infra-PR: https://github.com/compiler-explorer/infra/pull/1441 --- etc/config/ylc.amazon.properties | 16 ++++++ etc/config/ylc.defaults.properties | 11 ++++ examples/ylc/default.yl | 5 ++ infra | 1 + lib/compilers/_all.ts | 1 + lib/compilers/ylc.ts | 83 ++++++++++++++++++++++++++++++ lib/languages.ts | 11 ++++ types/languages.interfaces.ts | 3 +- 8 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 etc/config/ylc.amazon.properties create mode 100644 etc/config/ylc.defaults.properties create mode 100644 examples/ylc/default.yl create mode 160000 infra create mode 100644 lib/compilers/ylc.ts diff --git a/etc/config/ylc.amazon.properties b/etc/config/ylc.amazon.properties new file mode 100644 index 000000000..30fbf0fd3 --- /dev/null +++ b/etc/config/ylc.amazon.properties @@ -0,0 +1,16 @@ +compilers=&ylc_compilers +defaultCompiler=ylc_newest +objdumper=/opt/compiler-explorer/clang-18.1.0/bin/llvm-objdump +objdumperType=llvm + +group.ylc_compilers.compilers=ylc_newest +group.ylc_compilers.compilerType=ylc +group.ylc_compilers.options= +group.ylc_compilers.supportsBinary=false +group.ylc_compilers.supportsBinaryObject=false +group.ylc_compilers.versionFlag=--version +group.ylc_compilers.isSemVer=true +group.ylc_compilers.baseName=ylc + +compiler.ylc_newest.exe=/opt/compiler-explorer/ygen/bin/ylc +compiler.ylc_newest.semver=0.0.0 \ No newline at end of file diff --git a/etc/config/ylc.defaults.properties b/etc/config/ylc.defaults.properties new file mode 100644 index 000000000..6f245126e --- /dev/null +++ b/etc/config/ylc.defaults.properties @@ -0,0 +1,11 @@ +compilers=ylc_newest +displayName=ylc + +compiler.ylc_newest.exe=/opt/compiler-explorer/ygen/bin/ylc +compiler.ylc_newest.semver=0.0.0 +compiler.ylc_newest.supportsBinary=false +compiler.ylc_newest.compilerType=ylc +compiler.ylc_newest.objdumper=objdump +compiler.ylc_newest.versionFlag=--version +compiler.ylc_newest.options=-asm +compiler.ylc_newest.displayName=ylc \ No newline at end of file diff --git a/examples/ylc/default.yl b/examples/ylc/default.yl new file mode 100644 index 000000000..9f98c3363 --- /dev/null +++ b/examples/ylc/default.yl @@ -0,0 +1,5 @@ +define i32 @square(i32 %0) { + entry: + %1 = mul i32 %0, %0 + ret i32 %1 +} diff --git a/infra b/infra new file mode 160000 index 000000000..3d4a55bdc --- /dev/null +++ b/infra @@ -0,0 +1 @@ +Subproject commit 3d4a55bdc2dab8089db08839a1b5adabf3e228f7 diff --git a/lib/compilers/_all.ts b/lib/compilers/_all.ts index 15c662099..c8e61adf9 100644 --- a/lib/compilers/_all.ts +++ b/lib/compilers/_all.ts @@ -91,6 +91,7 @@ export {JuliaCompiler} from './julia.js'; export {KotlinCompiler} from './kotlin.js'; export {LDCCompiler} from './ldc.js'; export {LLCCompiler} from './llc.js'; +export {YLCCompiler} from './ylc.js'; export {LLVMmcaTool} from './llvm-mca.js'; export {LLVMMOSCompiler} from './llvm-mos.js'; export {MadPascalCompiler} from './madpascal.js'; diff --git a/lib/compilers/ylc.ts b/lib/compilers/ylc.ts new file mode 100644 index 000000000..477daba6c --- /dev/null +++ b/lib/compilers/ylc.ts @@ -0,0 +1,83 @@ +import path from 'path'; + +import {CompileChildLibraries} from '../../types/compilation/compilation.interfaces.js'; +import {ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js'; +import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {unwrap} from '../assert.js'; +import {BaseCompiler} from '../base-compiler.js'; +import * as utils from '../utils.js'; + +import {BaseParser} from './argument-parsers.js'; + +export class YLCCompiler extends BaseCompiler { + static get key() { + return 'ylc'; + } + + override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions: string[]) { + return ['-o=' + this.filename(outputFilename)]; + } + + override getArgumentParserClass() { + return BaseParser; + } + + override prepareArguments( + userOptions: string[], + filters: ParseFiltersAndOutputOptions, + backendOptions: Record, + inputFilename: string, + outputFilename: string, + libraries: CompileChildLibraries[], + overrides: ConfiguredOverrides, + ) { + let options = this.optionsForFilter(filters, outputFilename, userOptions); + backendOptions = backendOptions || {}; + + options = options.concat(this.optionsForBackend(backendOptions, outputFilename)); + + if (this.compiler.options) { + options = options.concat(utils.splitArguments(this.compiler.options)); + } + + if (this.compiler.supportsOptOutput && backendOptions.produceOptInfo) { + options = options.concat(unwrap(this.compiler.optArg)); + } + if (this.compiler.supportsStackUsageOutput && backendOptions.produceStackUsageInfo) { + options = options.concat(unwrap(this.compiler.stackUsageArg)); + } + + const toolchainPath = this.getDefaultOrOverridenToolchainPath(backendOptions.overrides || []); + + const dirPath = path.dirname(inputFilename); + + const libIncludes = this.getIncludeArguments(libraries, dirPath); + const libOptions = this.getLibraryOptions(libraries); + let libLinks: string[] = []; + let libPaths: string[] = []; + let libPathsAsFlags: string[] = []; + let staticLibLinks: string[] = []; + + if (filters.binary) { + libLinks = (this.getSharedLibraryLinks(libraries).filter(Boolean) as string[]) || []; + libPathsAsFlags = this.getSharedLibraryPathsAsArguments(libraries, undefined, toolchainPath, dirPath); + libPaths = this.getSharedLibraryPaths(libraries, dirPath); + staticLibLinks = (this.getStaticLibraryLinks(libraries, libPaths).filter(Boolean) as string[]) || []; + } + + userOptions = this.filterUserOptions(userOptions) || []; + [options, overrides] = this.fixIncompatibleOptions(options, userOptions, overrides); + options = this.changeOptionsBasedOnOverrides(options, overrides); + + return this.orderArguments( + options, + '-in=' + inputFilename, + libIncludes, + libOptions, + libPathsAsFlags, + libLinks, + userOptions, + staticLibLinks, + ); + } +} diff --git a/lib/languages.ts b/lib/languages.ts index d7d4fe86f..c91794bbe 100644 --- a/lib/languages.ts +++ b/lib/languages.ts @@ -851,6 +851,17 @@ const definitions: Record = { previewFilter: /^\s*#include/, monacoDisassembly: null, }, + ylc: { + name: 'Ygen', + monaco: 'llvm-ir', + extensions: ['.yl'], + alias: [], + logoUrl: null, // ygen does not yet have a logo ping me if it requires one (@Cr0a3) + logoUrlDark: null, + formatter: null, + previewFilter: null, + monacoDisassembly: null, + }, }; export const languages = Object.fromEntries( diff --git a/types/languages.interfaces.ts b/types/languages.interfaces.ts index 6e08ae69f..7b602babb 100644 --- a/types/languages.interfaces.ts +++ b/types/languages.interfaces.ts @@ -93,7 +93,8 @@ export type LanguageKey = | 'vala' | 'vb' | 'wasm' - | 'zig'; + | 'zig' + | 'ylc'; export interface Language { /** Id of language. Added programmatically based on CELanguages key */