Add basic COBOL support

This commit is contained in:
wxwisiasdf
2023-03-01 06:17:26 +08:00
parent b2dd3fd663
commit a3edc64993
9 changed files with 146 additions and 0 deletions

3
.github/labeler.yml vendored
View File

@@ -40,6 +40,9 @@ lang-clean:
- lib/compilers/clean.js - lib/compilers/clean.js
- etc/config/clean.*.properties - etc/config/clean.*.properties
- static/modes/clean-mode.ts - static/modes/clean-mode.ts
lang-cobol:
- lib/compilers/cobol.js
- etc/config/cobol.*.properties
lang-cppx: lang-cppx:
- etc/config/cppx?(_blue|_gold).*.properties - etc/config/cppx?(_blue|_gold).*.properties
- static/modes/cppx-blue-mode.ts - static/modes/cppx-blue-mode.ts

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -0,0 +1,5 @@
identification division.
program-id. hello.
procedure division.
display "Hello World!".
stop run.

View File

@@ -38,6 +38,7 @@ export {ClangCudaCompiler} from './clang.js';
export {ClangHipCompiler} from './clang.js'; export {ClangHipCompiler} from './clang.js';
export {ClangIntelCompiler} from './clang.js'; export {ClangIntelCompiler} from './clang.js';
export {CleanCompiler} from './clean.js'; export {CleanCompiler} from './clean.js';
export {CobolCompiler} from './cobol.js';
export {CppFrontCompiler} from './cppfront.js'; export {CppFrontCompiler} from './cppfront.js';
export {CprocCompiler} from './cproc.js'; export {CprocCompiler} from './cproc.js';
export {CLSPVCompiler} from './clspv.js'; export {CLSPVCompiler} from './clspv.js';

86
lib/compilers/cobol.ts Normal file
View File

@@ -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 [];
}
}

View File

@@ -165,6 +165,17 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
previewFilter: null, previewFilter: null,
monacoDisassembly: 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: { cpp_for_opencl: {
name: 'C++ for OpenCL', name: 'C++ for OpenCL',
monaco: 'cpp-for-opencl', monaco: 'cpp-for-opencl',

View File

@@ -33,6 +33,7 @@ export type LanguageKey =
| 'circt' | 'circt'
| 'clean' | 'clean'
| 'cmake' | 'cmake'
| 'cobol'
| 'cpp_for_opencl' | 'cpp_for_opencl'
| 'cppx' | 'cppx'
| 'cppx_blue' | 'cppx_blue'