From 73f7d0787f33bc0f7db44149a3f161421668d72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Thu, 23 Feb 2023 20:43:56 +0100 Subject: [PATCH] Initial support for Modula-2 language (#4747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/labeler.yml | 4 + etc/config/modula2.amazon.properties | 24 +++++ etc/config/modula2.defaults.properties | 15 +++ examples/modula2/default.mod | 10 ++ lib/compilers/_all.ts | 1 + lib/compilers/gm2.ts | 31 +++++++ lib/languages.ts | 11 +++ static/modes/_all.ts | 1 + static/modes/modula2-mode.ts | 123 +++++++++++++++++++++++++ types/languages.interfaces.ts | 1 + 10 files changed, 221 insertions(+) create mode 100644 etc/config/modula2.amazon.properties create mode 100644 etc/config/modula2.defaults.properties create mode 100644 examples/modula2/default.mod create mode 100644 lib/compilers/gm2.ts create mode 100644 static/modes/modula2-mode.ts diff --git a/.github/labeler.yml b/.github/labeler.yml index 16f0d1f3d..16def5cf2 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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 diff --git a/etc/config/modula2.amazon.properties b/etc/config/modula2.amazon.properties new file mode 100644 index 000000000..9689ada45 --- /dev/null +++ b/etc/config/modula2.amazon.properties @@ -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) diff --git a/etc/config/modula2.defaults.properties b/etc/config/modula2.defaults.properties new file mode 100644 index 000000000..f06e83dfb --- /dev/null +++ b/etc/config/modula2.defaults.properties @@ -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 + diff --git a/examples/modula2/default.mod b/examples/modula2/default.mod new file mode 100644 index 000000000..8c2616d1d --- /dev/null +++ b/examples/modula2/default.mod @@ -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. diff --git a/lib/compilers/_all.ts b/lib/compilers/_all.ts index 1f7d7012d..ab67d0871 100644 --- a/lib/compilers/_all.ts +++ b/lib/compilers/_all.ts @@ -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'; diff --git a/lib/compilers/gm2.ts b/lib/compilers/gm2.ts new file mode 100644 index 000000000..6e5d3fe1f --- /dev/null +++ b/lib/compilers/gm2.ts @@ -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'; + } +} diff --git a/lib/languages.ts b/lib/languages.ts index c1b5275bb..b65949316 100644 --- a/lib/languages.ts +++ b/lib/languages.ts @@ -418,6 +418,17 @@ const definitions: Record = { 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', diff --git a/static/modes/_all.ts b/static/modes/_all.ts index 0ea95ef3b..e4d51557f 100644 --- a/static/modes/_all.ts +++ b/static/modes/_all.ts @@ -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'; diff --git a/static/modes/modula2-mode.ts b/static/modes/modula2-mode.ts new file mode 100644 index 000000000..a2911c1c5 --- /dev/null +++ b/static/modes/modula2-mode.ts @@ -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 {}; diff --git a/types/languages.interfaces.ts b/types/languages.interfaces.ts index 01e6ba49b..8c67c0e45 100644 --- a/types/languages.interfaces.ts +++ b/types/languages.interfaces.ts @@ -57,6 +57,7 @@ export type LanguageKey = | 'kotlin' | 'llvm' | 'mlir' + | 'modula2' | 'nim' | 'ocaml' | 'objc'