aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Moores <info@tmoor.es>2021-11-21 13:22:04 +0000
committerGitHub <noreply@github.com>2021-11-21 14:22:04 +0100
commit82772f4bbbbfbc0462cf4f29ec80b0036c41d9e6 (patch)
treeb126322eb0a3ad3dd2b624ec335ee419933da34a
parent177fee0739be0765ff89ee5d3f1d135e62906883 (diff)
downloadcompiler-explorer-82772f4bbbbfbc0462cf4f29ec80b0036c41d9e6.tar.gz
compiler-explorer-82772f4bbbbfbc0462cf4f29ec80b0036c41d9e6.zip
add support for erlang to beam bytecode (#3094)gh-1286
* add support for erlang to beam bytecode * changed call by 'this' to overridden functions * Update base-compiler.js Co-authored-by: Patrick Quist <partouf@gmail.com>
-rw-r--r--etc/config/erlang.defaults.properties20
-rw-r--r--examples/erlang/default.erl4
-rw-r--r--lib/compilers/_all.js1
-rw-r--r--lib/compilers/argument-parsers.js7
-rw-r--r--lib/compilers/erlang.js96
-rw-r--r--lib/languages.js6
6 files changed, 134 insertions, 0 deletions
diff --git a/etc/config/erlang.defaults.properties b/etc/config/erlang.defaults.properties
new file mode 100644
index 000000000..b6fb121ad
--- /dev/null
+++ b/etc/config/erlang.defaults.properties
@@ -0,0 +1,20 @@
+# Default settings for Erlang
+compilers=&erlang
+compilerType=erlang
+versionFlag=
+objdumper=
+instructionSet=beam
+
+group.erlang.compilers=erlcdefault
+compiler.erlcdefault.exe=/usr/bin/erl
+compiler.erlcdefault.runtime=/usr/bin/erl
+compiler.erlcdefault.name=erl default
+
+defaultCompiler=erlcdefault
+demangler=
+postProcess=
+options=-S
+supportsBinary=false
+needsMulti=false
+supportsExecute=false
+interpreted=true
diff --git a/examples/erlang/default.erl b/examples/erlang/default.erl
new file mode 100644
index 000000000..163980025
--- /dev/null
+++ b/examples/erlang/default.erl
@@ -0,0 +1,4 @@
+-module(square).
+-export([square/1]).
+
+square(A) -> A*A.
diff --git a/lib/compilers/_all.js b/lib/compilers/_all.js
index 1e2139374..bc99138c8 100644
--- a/lib/compilers/_all.js
+++ b/lib/compilers/_all.js
@@ -37,6 +37,7 @@ export { CrystalCompiler } from './crystal';
export { DefaultCompiler } from './default';
export { DMDCompiler } from './dmd';
export { EllccCompiler } from './ellcc';
+export { ErlangCompiler } from './erlang';
export { EWARMCompiler } from './ewarm';
export { EWAVRCompiler } from './ewavr';
export { FakeCompiler } from './fake-for-test';
diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js
index 1944711a1..aeed08a50 100644
--- a/lib/compilers/argument-parsers.js
+++ b/lib/compilers/argument-parsers.js
@@ -157,6 +157,13 @@ export class ClangParser extends BaseParser {
}
}
+export class ErlangParser extends BaseParser {
+ static async parse(compiler) {
+ await ErlangParser.getOptions(compiler, '-help');
+ return compiler;
+ }
+}
+
export class PascalParser extends BaseParser {
static async parse(compiler) {
await PascalParser.getOptions(compiler, '-help');
diff --git a/lib/compilers/erlang.js b/lib/compilers/erlang.js
new file mode 100644
index 000000000..b844b822b
--- /dev/null
+++ b/lib/compilers/erlang.js
@@ -0,0 +1,96 @@
+// Copyright (c) 2021, 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 { BaseCompiler } from '../base-compiler';
+import { logger } from '../logger';
+
+import { ErlangParser } from './argument-parsers';
+
+export class ErlangCompiler extends BaseCompiler {
+ static get key() { return 'erlang'; }
+
+ /* eslint-disable no-unused-vars */
+ optionsForFilter(filters, outputFilename) {
+ return [
+ '-noshell',
+ '-eval',
+ '{ok, Input} = init:get_argument(input),' +
+ '{ok, _, Output} = compile:file(Input, [\'S\', binary, no_line_info, report]),' +
+ 'Binary = io_lib:format("~p", [Output]),' +
+ `file:write_file("${outputFilename}", list_to_binary(Binary)),` +
+ 'halt().',
+ ];
+ }
+ /* eslint-enable no-unused-vars */
+
+ async runCompiler(compiler, options, inputFilename, execOptions) {
+ if (!execOptions) {
+ execOptions = this.getDefaultExecOptions();
+ }
+
+ if (!execOptions.customCwd) {
+ execOptions.customCwd = path.dirname(inputFilename);
+ }
+
+ const result = await this.exec(compiler, options.concat(['-input', inputFilename]), execOptions);
+ result.inputFilename = inputFilename;
+ const transformedInput = result.filenameTransform(inputFilename);
+ this.parseCompilationOutput(result, transformedInput);
+ return result;
+ }
+
+
+ getVersion() {
+ logger.info(`Gathering ${this.compiler.id} version information on ${this.compiler.exe}...`);
+ if (this.compiler.explicitVersion) {
+ logger.debug(`${this.compiler.id} has forced version output: ${this.compiler.explicitVersion}`);
+ return {stdout: [this.compiler.explicitVersion], stderr: [], code: 0};
+ }
+ const execOptions = this.getDefaultExecOptions();
+ const versionCmd = this.compilerProps(`compiler.${this.compiler.id}.runtime`);
+ execOptions.timeoutMs = 0; // No timeout for --version. A sort of workaround for slow EFS/NFS on the prod site
+ execOptions.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths([]);
+
+ try {
+ return this.execCompilerCached(
+ versionCmd,
+ ['-noshell', '-eval', 'io:fwrite("~s~n", [erlang:system_info(otp_release)]), halt().'],
+ execOptions,
+ );
+ } catch (err) {
+ logger.error(`Unable to get version for compiler '${this.compiler.exe}' - ${err}`);
+ return null;
+ }
+ }
+
+ getOutputFilename(dirPath, outputFilebase) {
+ return path.join(dirPath, `${outputFilebase}.S`);
+ }
+
+ getArgumentParser() {
+ return ErlangParser;
+ }
+}
diff --git a/lib/languages.js b/lib/languages.js
index ddd22c4cf..cc54de978 100644
--- a/lib/languages.js
+++ b/lib/languages.js
@@ -116,6 +116,12 @@ export const languages = {
extensions: ['.d'],
alias: [],
},
+ erlang: {
+ name: 'Erlang',
+ monaco: 'erlang',
+ extensions: ['.erl', '.hrl'],
+ alias: [],
+ },
go: {
name: 'Go',
monaco: 'go',