diff options
author | David Hewitt <davidmhewitt@users.noreply.github.com> | 2023-04-11 03:47:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 22:47:49 -0500 |
commit | a7da7e83c41e31b3be4ba4adfedf05cd1c6480e2 (patch) | |
tree | ba11a76f2a4d91b288edd90fdc14cd4fb49c7534 /lib/compilers | |
parent | 471d49ee8e831fb2a5b6c9ce137cbf73e28f7c28 (diff) | |
download | compiler-explorer-a7da7e83c41e31b3be4ba4adfedf05cd1c6480e2.tar.gz compiler-explorer-a7da7e83c41e31b3be4ba4adfedf05cd1c6480e2.zip |
Add the Vala programming language (#4955)gh-7078
See https://gitlab.gnome.org/GNOME/vala/ for the language repository.
> Vala is a programming language that aims to bring modern programming
language features to GNOME developers without imposing any additional
runtime requirements and without using a different ABI compared to
applications and libraries written in C.
>
> `valac`, the Vala compiler, is a self-hosting compiler that translates
Vala source code into C source and header files. It uses the GObject
type system to create classes and interfaces declared in the Vala source
code.
>
> The syntax of Vala is similar to C#, modified to better fit the
GObject type system.
I've also created https://github.com/davidmhewitt/vala-builder based on
https://github.com/compiler-explorer/python-builder and tested that it
can build tarballs of arbitrary versions of Vala. I'd be happy to
transfer the ownership of this repository, or feel free to clone it into
the `compiler-explorer` org.
However, I'm a little unsure of how to join up the pieces and get this
Docker builder integrated with the `infra` repository. Let me know where
to go next and I'd be happy to open the relevant PRs.
Diffstat (limited to 'lib/compilers')
-rw-r--r-- | lib/compilers/_all.ts | 1 | ||||
-rw-r--r-- | lib/compilers/vala.ts | 102 |
2 files changed, 103 insertions, 0 deletions
diff --git a/lib/compilers/_all.ts b/lib/compilers/_all.ts index 4819d442b..01059592a 100644 --- a/lib/compilers/_all.ts +++ b/lib/compilers/_all.ts @@ -104,6 +104,7 @@ export {TinyCCompiler} from './tinyc.js'; export {ToitCompiler} from './toit.js'; export {TurboCCompiler} from './turboc.js'; export {TypeScriptNativeCompiler} from './typescript-native.js'; +export {ValaCompiler} from './vala.js'; export {VBCompiler} from './dotnet.js'; export {V8Compiler} from './v8.js'; export {Win32Compiler} from './win32.js'; diff --git a/lib/compilers/vala.ts b/lib/compilers/vala.ts new file mode 100644 index 000000000..0935b4f75 --- /dev/null +++ b/lib/compilers/vala.ts @@ -0,0 +1,102 @@ +// Copyright (c) 2023, 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 {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {BaseCompiler} from '../base-compiler.js'; + +export class ValaCompiler extends BaseCompiler { + static get key() { + return 'vala'; + } + + ccPath: string; + + constructor(compiler: PreliminaryCompilerInfo, env) { + super(compiler, env); + this.ccPath = this.compilerProps<string>(`compiler.${this.compiler.id}.cc`); + } + + override getCompilerResultLanguageId() { + return 'c'; + } + + override getDefaultExecOptions() { + const execOptions = super.getDefaultExecOptions(); + if (this.ccPath) { + execOptions.env.CC = this.ccPath; + } + return execOptions; + } + + override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: any) { + const options = ['-g']; + if (!filters.binary) { + options.push('-C'); // Save transpiled C code + } else { + options.push('-o', this.filename(outputFilename)); + } + + return options; + } + + override async objdump( + outputFilename, + result: any, + maxSize: number, + intelAsm, + demangle, + staticReloc: boolean, + dynamicReloc: boolean, + filters: ParseFiltersAndOutputOptions, + ) { + const objdumpResult = await super.objdump( + outputFilename, + result, + maxSize, + intelAsm, + demangle, + staticReloc, + dynamicReloc, + filters, + ); + + objdumpResult.languageId = 'asm'; + return objdumpResult; + } + + override getSharedLibraryPathsAsArguments(libraries, libDownloadPath) { + return []; + } + + override getSharedLibraryLinks(libraries: any[]): string[] { + return []; + } + + override getOutputFilename(dirPath: string, outputFilebase: string, key?: any): string { + return path.join(dirPath, 'example.c'); + } +} |