Initial support for Modula-2 language (#4747)

With the upcoming gcc 13 release and its shiny Modula-2 frontend, we
are introducing Modula-2 support in Compiler Explorer :)

Currently, only the gcc-snapshot build supports modula-2.

fixes #4688

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
This commit is contained in:
Marc Poulhiès
2023-02-23 20:43:56 +01:00
committed by GitHub
parent ed5216a3ad
commit 73f7d0787f
10 changed files with 221 additions and 0 deletions

4
.github/labeler.yml vendored
View File

@@ -117,6 +117,10 @@ lang-llvm:
- lib/tooling/llvm-mca-tool.js
- etc/config/llvm.*.properties
- static/modes/llvm-ir-mode.ts
lang-modula2:
- lib/compilers/gm2.js
- etc/config/modula2.*.properties
- static/modes/modula2-mode.ts
lang-nim:
- lib/compilers/nim.js
- etc/config/nim.*.properties

View File

@@ -0,0 +1,24 @@
# Default settings for modula2
compilers=&gm2
defaultCompiler=gm2snapshot
demangler=/opt/compiler-explorer/gcc-snapshot/bin/c++filt
objdumper=/opt/compiler-explorer/gcc-snapshot/bin/objdump
postProcess=
supportsBinary=true
supportsBinaryObject=true
supportsExecute=true
binaryHideFuncRe=^(__.*|_(init|start|fini)|(de)?register_tm_clones|call_gmon_start|frame_dummy|\.plt.*)$
supportsLibraryCodeFilter=true
needsMulti=false
externalparser=CEAsmParser
externalparser.exe=/usr/local/bin/asm-parser
group.gm2.compilers=gm2snapshot
group.gm2.instructionSet=amd64
group.gm2.isSemVer=true
group.gm2.baseName=x86-64 gcc gm2
compiler.gm2snapshot.exe=/opt/compiler-explorer/gcc-snapshot/bin/gm2
compiler.gm2snapshot.semver=(snapshot)

View File

@@ -0,0 +1,15 @@
# Default settings for modula2
compilers=:&gcc
defaultCompiler=gdefault
demangler=c++filt
objdumper=objdump
postProcess=
supportsBinary=true
supportsBinaryObject=true
binaryHideFuncRe=^(__.*|_(init|start|fini)|(de)?register_tm_clones|call_gmon_start|frame_dummy|\.plt.*)$
supportsLibraryCodeFilter=true
group.gcc.compilers=cgdefault
compiler.cgdefault.exe=/usr/bin/gm2
compiler.cgdefault.name=gcc default

View File

@@ -0,0 +1,10 @@
MODULE PrintHelloWorld;
(*This program prints "Hello world!" on the standard output device*)
FROM InOut IMPORT WriteString, WriteLn;
BEGIN
WriteString('Hello world!');
WriteLn;
END PrintHelloWorld.

View File

@@ -71,6 +71,7 @@ export {LLCCompiler} from './llc';
export {LLVMmcaTool} from './llvm-mca';
export {LLVMMOSCompiler} from './llvm-mos';
export {MLIRCompiler} from './mlir';
export {GM2Compiler} from './gm2';
export {MrustcCompiler} from './mrustc';
export {NasmCompiler} from './nasm';
export {NimCompiler} from './nim';

31
lib/compilers/gm2.ts Normal file
View File

@@ -0,0 +1,31 @@
// 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 {GCCCompiler} from './gcc';
export class GM2Compiler extends GCCCompiler {
static override get key() {
return 'gm2';
}
}

View File

@@ -418,6 +418,17 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
previewFilter: null,
monacoDisassembly: null,
},
modula2: {
name: 'modula2',
monaco: 'modula2',
extensions: ['.mod'],
alias: [],
logoUrl: null,
logoUrlDark: null,
formatter: null,
previewFilter: null,
monacoDisassembly: null,
},
nim: {
name: 'Nim',
monaco: 'nim',

View File

@@ -48,6 +48,7 @@ import './ispc-mode';
import './jakt-mode';
import './llvm-ir-mode';
import './mlir-mode';
import './modula2-mode';
import './nc-mode';
import './nim-mode';
import './ocaml-mode';

View File

@@ -0,0 +1,123 @@
// Copyright (c) 2018, Eugen Bulavin
// 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 * as monaco from 'monaco-editor';
function definition(): monaco.languages.IMonarchLanguage {
return {
keywords: [
'AND',
'ARRAY',
'BEGIN',
'BY',
'CASE',
'CONST',
'DEFINITION',
'DIV',
'DO',
'ELSE',
'ELSIF',
'END',
'EXCEPT',
'EXIT',
'EXPORT',
'FINALLY',
'FOR',
'FROM',
'IF',
'IMPLEMENTATION',
'IMPORT',
'IN',
'LOOP',
'MOD',
'MODULE',
'NOT',
'OF',
'OR',
'PACKEDSET',
'POINTER',
'PROCEDURE',
'QUALIFIED',
'UNQUALIFIED',
'RECORD',
'REM',
'REPEAT',
'RETRY',
'RETURN',
'SET',
'THEN',
'TO',
'TYPE',
'UNTIL',
'VAR',
'WHILE',
'WITH',
'ASM',
'VOLATILE',
],
typeKeywords: ['integer number', 'real number', 'identifier', 'string'],
numbers: /-?[0-9.]/,
tokenizer: {
root: [
// identifiers and keywords
[
/[A-Za-z_$][\w$]*/,
{
cases: {
'@typeKeywords': 'keyword',
'@keywords': 'keyword',
'@default': 'identifier',
},
},
],
{include: '@whitespace'},
[/@numbers/, 'number'],
[/[+\-*/=<>$@]/, 'operators'],
[/(")(.*)(")/, ['string', 'string', 'string']],
],
comment: [
[/[^(*]+/, 'comment'],
[/\*\)/, 'comment', '@pop'],
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\(\*/, 'comment', '@comment'],
],
},
};
}
monaco.languages.register({id: 'modula2'});
monaco.languages.setMonarchTokensProvider('modula2', definition());
export {};

View File

@@ -57,6 +57,7 @@ export type LanguageKey =
| 'kotlin'
| 'llvm'
| 'mlir'
| 'modula2'
| 'nim'
| 'ocaml'
| 'objc'