diff --git a/.github/labeler.yml b/.github/labeler.yml index 16def5cf2..ededc63c0 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -40,6 +40,9 @@ lang-clean: - lib/compilers/clean.js - etc/config/clean.*.properties - static/modes/clean-mode.ts +lang-cobol: + - lib/compilers/cobol.js + - etc/config/cobol.*.properties lang-cppx: - etc/config/cppx?(_blue|_gold).*.properties - static/modes/cppx-blue-mode.ts diff --git a/etc/config/cobol.amazon.properties b/etc/config/cobol.amazon.properties new file mode 100644 index 000000000..33804a024 --- /dev/null +++ b/etc/config/cobol.amazon.properties @@ -0,0 +1,10 @@ +compilers=&cobol +defaultCompiler=cobol + +group.cobol.groupName=COBOL +group.cobol.compilers=cobol +group.cobol.isSemVer=true +group.cobol.baseName=COBOL +group.cobol.licenseName=GPLv3 +group.cobol.licenseLink=https://sourceforge.net/p/gnucobol/code/HEAD/tree/trunk/COPYING +compiler.cobol.exe=/opt/compiler-explorer/gnucobol/bin/cobc diff --git a/etc/config/cobol.defaults.properties b/etc/config/cobol.defaults.properties new file mode 100644 index 000000000..556e85f56 --- /dev/null +++ b/etc/config/cobol.defaults.properties @@ -0,0 +1,14 @@ +# Default settings for COBOL +compilers=cobol +compilerType=cobol + +versionFlag=--version + +objdumper=objdump +supportsBinary=true +supportsBinaryObject=true +binaryHideFuncRe=^(__.*|_(init|start|fini)|(de)?register_tm_clones|call_gmon_start|frame_dummy|\.plt.*|_dl_relocate_static_pie)$ +supportsLibraryCodeFilter=true + +compiler.cobol.name=GNU COBOL +compiler.cobol.exe=/usr/local/bin/cobc diff --git a/examples/cobol/Max_array.cob b/examples/cobol/Max_array.cob new file mode 100644 index 000000000..006139e6e --- /dev/null +++ b/examples/cobol/Max_array.cob @@ -0,0 +1,15 @@ + identification division. + program-id. Max_array. + data division. + working-storage section. + 01 ws-array-1 pic s9(8) occurs 65535 times. + 01 ws-array-2 pic s9(8) occurs 65535 times. + 01 i pic s9(8) comp. + procedure division. + move 0 to i. + perform varying i from 1 by 1 until i > 65535 + if ws-array-1(i) > ws-array-2(i) + move ws-array-1(i) to ws-array-2(i) + end-if + end-perform. + stop run. diff --git a/examples/cobol/default.cob b/examples/cobol/default.cob new file mode 100644 index 000000000..99c6e06a6 --- /dev/null +++ b/examples/cobol/default.cob @@ -0,0 +1,5 @@ + identification division. + program-id. hello. + procedure division. + display "Hello World!". + stop run. diff --git a/lib/compilers/_all.ts b/lib/compilers/_all.ts index 39fd3ba0f..f1790ccbb 100644 --- a/lib/compilers/_all.ts +++ b/lib/compilers/_all.ts @@ -38,6 +38,7 @@ export {ClangCudaCompiler} from './clang.js'; export {ClangHipCompiler} from './clang.js'; export {ClangIntelCompiler} from './clang.js'; export {CleanCompiler} from './clean.js'; +export {CobolCompiler} from './cobol.js'; export {CppFrontCompiler} from './cppfront.js'; export {CprocCompiler} from './cproc.js'; export {CLSPVCompiler} from './clspv.js'; diff --git a/lib/compilers/cobol.ts b/lib/compilers/cobol.ts new file mode 100644 index 000000000..3acf0a319 --- /dev/null +++ b/lib/compilers/cobol.ts @@ -0,0 +1,86 @@ +// 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 _ from 'underscore'; + +import path from 'path'; + +import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {BaseCompiler} from '../base-compiler.js'; +import * as utils from '../utils.js'; + +export class CobolCompiler extends BaseCompiler { + static get key() { + return 'cobol'; + } + + override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) { + let options = ['-o', this.filename(outputFilename)]; + if (!filters.binary) options = options.concat('-S'); + else options = options.concat('-x'); + return options; + } + + override getCompilerResultLanguageId() { + return 'asm'; + } + + 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 getExecutableFilename(dirPath: string, outputFilebase: string) { + return path.join(dirPath, outputFilebase); + } + + override getSharedLibraryPathsAsArguments(libraries, libDownloadPath) { + return []; + } + + override getSharedLibraryLinks(libraries: any[]): string[] { + return []; + } +} diff --git a/lib/languages.ts b/lib/languages.ts index f9d6404b6..76d02a5dc 100644 --- a/lib/languages.ts +++ b/lib/languages.ts @@ -165,6 +165,17 @@ const definitions: Record = { previewFilter: null, monacoDisassembly: null, }, + cobol: { + name: 'COBOL', + monaco: 'cobol', + extensions: ['.cob', '.cbl', '.cobol'], + alias: [], + logoUrl: null, // TODO: Find a better alternative + formatter: null, + logoUrlDark: null, + previewFilter: null, + monacoDisassembly: null, + }, cpp_for_opencl: { name: 'C++ for OpenCL', monaco: 'cpp-for-opencl', diff --git a/types/languages.interfaces.ts b/types/languages.interfaces.ts index 8900fc4b6..8881df4b6 100644 --- a/types/languages.interfaces.ts +++ b/types/languages.interfaces.ts @@ -33,6 +33,7 @@ export type LanguageKey = | 'circt' | 'clean' | 'cmake' + | 'cobol' | 'cpp_for_opencl' | 'cppx' | 'cppx_blue'