aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
authorPatrick Quist <partouf@gmail.com>2022-08-25 22:44:48 +0200
committerGitHub <noreply@github.com>2022-08-25 22:44:48 +0200
commit3f6004b20036f6c8c52f577215a1940d7ecca4b4 (patch)
tree24e75abc43393fe3690926262f5a68f4eda7afa4 /lib/compilers
parent16dca9d307220229b80327ea0998c4cecec9137b (diff)
downloadcompiler-explorer-3f6004b20036f6c8c52f577215a1940d7ecca4b4.tar.gz
compiler-explorer-3f6004b20036f6c8c52f577215a1940d7ecca4b4.zip
Add z88dk (#3812)gh-4027
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/_all.js1
-rw-r--r--lib/compilers/z88dk.ts140
2 files changed, 141 insertions, 0 deletions
diff --git a/lib/compilers/_all.js b/lib/compilers/_all.js
index ca902a933..3224acc03 100644
--- a/lib/compilers/_all.js
+++ b/lib/compilers/_all.js
@@ -98,3 +98,4 @@ export {WslVcCompiler} from './wsl-vc';
export {ZigCC} from './zigcc';
export {ZigCompiler} from './zig';
export {ZigCXX} from './zigcxx';
+export {z88dkCompiler} from './z88dk';
diff --git a/lib/compilers/z88dk.ts b/lib/compilers/z88dk.ts
new file mode 100644
index 000000000..1c5e39f3d
--- /dev/null
+++ b/lib/compilers/z88dk.ts
@@ -0,0 +1,140 @@
+// Copyright (c) 2022, 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 {ExecutionOptions} from '../../types/compilation/compilation.interfaces';
+import {ParseFilters} from '../../types/features/filters.interfaces';
+import {BaseCompiler} from '../base-compiler';
+import {logger} from '../logger';
+import {AsmParserZ88dk} from '../parsers/asm-parser-z88dk';
+import * as utils from '../utils';
+
+export class z88dkCompiler extends BaseCompiler {
+ static get key() {
+ return 'z88dk';
+ }
+
+ constructor(compilerInfo, env) {
+ super(compilerInfo, env);
+ this.outputFilebase = 'example';
+ this.asm = new AsmParserZ88dk(this.compilerProps);
+ }
+
+ public override getOutputFilename(dirPath: string, outputFilebase: string, key?: any): string {
+ let filename;
+ if (key && key.backendOptions && key.backendOptions.customOutputFilename) {
+ filename = key.backendOptions.customOutputFilename;
+ } else if (key && key.filters.binary) {
+ filename = `${outputFilebase}`;
+ } else {
+ filename = `${outputFilebase}.c.asm`;
+ }
+
+ if (dirPath) {
+ return path.join(dirPath, filename);
+ } else {
+ return filename;
+ }
+ }
+
+ public override orderArguments(
+ options,
+ inputFilename,
+ libIncludes,
+ libOptions,
+ libPaths,
+ libLinks,
+ userOptions,
+ staticLibLinks,
+ ) {
+ return userOptions.concat(
+ options,
+ [this.filename(inputFilename)],
+ libIncludes,
+ libOptions,
+ libPaths,
+ libLinks,
+ staticLibLinks,
+ );
+ }
+
+ protected override optionsForFilter(filters: ParseFilters, outputFilename: string): string[] {
+ if (!filters.binary) {
+ return ['-S'];
+ } else {
+ // note: the .tmp is somehow empty, but this argument is still required to generate "example.bin"
+ return ['-o', outputFilename + '.tmp', '-create-app'];
+ }
+ }
+
+ override getDefaultExecOptions(): ExecutionOptions {
+ const opts = super.getDefaultExecOptions();
+ opts.env.ZCCCFG = path.join(path.dirname(this.compiler.exe), '../share/z88dk/lib/config');
+ opts.env.PATH = process.env.PATH + path.delimiter + path.dirname(this.compiler.exe);
+
+ return opts;
+ }
+
+ override getObjdumpOutputFilename(defaultOutputFilename) {
+ return defaultOutputFilename + '.bin';
+ }
+
+ override async objdump(outputFilename, result: any, maxSize: number, intelAsm, demangle, filters: ParseFilters) {
+ outputFilename = this.getObjdumpOutputFilename(outputFilename);
+
+ if (!(await utils.fileExists(outputFilename))) {
+ result.asm = '<No output file ' + outputFilename + '>';
+ return result;
+ }
+
+ const args = [outputFilename];
+
+ if (this.externalparser) {
+ const objResult = await this.externalparser.objdumpAndParseAssembly(result.dirPath, args, filters);
+ if (objResult.parsingTime !== undefined) {
+ objResult.objdumpTime = parseInt(result.execTime) - parseInt(result.parsingTime);
+ delete objResult.execTime;
+ }
+
+ result = {...result, ...objResult};
+ } else {
+ const execOptions: ExecutionOptions = {
+ maxOutput: maxSize,
+ customCwd: (result.dirPath as string) || path.dirname(outputFilename),
+ };
+ const objResult = await this.exec(this.compiler.objdumper, args, execOptions);
+
+ if (objResult.code !== 0) {
+ logger.error(`Error executing objdump ${this.compiler.objdumper}`, objResult);
+ result.asm = `<No output: objdump returned ${objResult.code}>`;
+ } else {
+ result.objdumpTime = objResult.execTime;
+ result.asm = this.postProcessObjdumpOutput(objResult.stdout);
+ }
+ }
+
+ return result;
+ }
+}