Skip to content

Commit

Permalink
refactor: renames the CompilerFilters type (#4346)
Browse files Browse the repository at this point in the history
The type which probably started as a real enum of possible post filtering
options now also includes options used for compilers' invocations.

The type was already split, but the naming was not reflecting this in the other
part of the code.

This changes tries to apply a simple renaming to the type only (corresponding
variables are left as 'filters').

While doing so, some typing error were discovered around the GccDump feature.
A fix for this will follow in a different PR.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
  • Loading branch information
dkm committed Nov 28, 2022
1 parent 90e6e4e commit 2fa2bbb
Show file tree
Hide file tree
Showing 35 changed files with 171 additions and 104 deletions.
47 changes: 31 additions & 16 deletions lib/base-compiler.ts
Expand Up @@ -48,7 +48,7 @@ import {
ExecutableExecutionOptions,
UnprocessedExecResult,
} from '../types/execution/execution.interfaces';
import {CompilerFilters, ParseFilters} from '../types/features/filters.interfaces';
import {CompilerOutputOptions, ParseFiltersAndOutputOptions} from '../types/features/filters.interfaces';
import {Language} from '../types/languages.interfaces';
import {Library, LibraryVersion, SelectedLibraryVersion} from '../types/libraries/libraries.interfaces';
import {ResultLine} from '../types/resultline/resultline.interfaces';
Expand Down Expand Up @@ -392,7 +392,14 @@ export class BaseCompiler {
return output;
}

async objdump(outputFilename, result: any, maxSize: number, intelAsm, demangle, filters: ParseFilters) {
async objdump(
outputFilename,
result: any,
maxSize: number,
intelAsm,
demangle,
filters: ParseFiltersAndOutputOptions,
) {
outputFilename = this.getObjdumpOutputFilename(outputFilename);

if (!(await utils.fileExists(outputFilename))) {
Expand Down Expand Up @@ -585,7 +592,11 @@ export class BaseCompiler {
return addOpts;
}

protected optionsForFilter(filters: ParseFilters, outputFilename: string, userOptions?: string[]): string[] {
protected optionsForFilter(
filters: ParseFiltersAndOutputOptions,
outputFilename: string,
userOptions?: string[],
): string[] {
let options = ['-g', '-o', this.filename(outputFilename)];
if (this.compiler.intelAsm && filters.intel && !filters.binary) {
options = options.concat(this.compiler.intelAsm.split(' '));
Expand Down Expand Up @@ -844,7 +855,7 @@ export class BaseCompiler {

prepareArguments(
userOptions: string[],
filters: ParseFilters,
filters: ParseFiltersAndOutputOptions,
backendOptions: Record<string, any>,
inputFilename: string,
outputFilename: string,
Expand Down Expand Up @@ -1009,7 +1020,7 @@ export class BaseCompiler {
}
}

async generateIR(inputFilename: string, options: string[], filters: ParseFilters) {
async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) {
// These options make Clang produce an IR
const newOptions = options.filter(option => option !== '-fcolor-diagnostics').concat(this.compiler.irArg);

Expand All @@ -1025,7 +1036,7 @@ export class BaseCompiler {
return ir.asm;
}

async processIrOutput(output, filters: ParseFilters) {
async processIrOutput(output, filters: ParseFiltersAndOutputOptions) {
const irPath = this.getIrOutputFilename(output.inputFilename, filters);
if (await fs.pathExists(irPath)) {
const output = await fs.readFile(irPath, 'utf-8');
Expand All @@ -1041,7 +1052,7 @@ export class BaseCompiler {
async generateLLVMOptPipeline(
inputFilename: string,
options: string[],
filters: ParseFilters,
filters: ParseFiltersAndOutputOptions,
llvmOptPipelineOptions: LLVMOptPipelineBackendOptions,
): Promise<LLVMOptPipelineOutput | undefined> {
// These options make Clang produce the pass dumps
Expand Down Expand Up @@ -1102,7 +1113,11 @@ export class BaseCompiler {
}
}

async processLLVMOptPipeline(output, filters: ParseFilters, llvmOptPipelineOptions: LLVMOptPipelineBackendOptions) {
async processLLVMOptPipeline(
output,
filters: ParseFiltersAndOutputOptions,
llvmOptPipelineOptions: LLVMOptPipelineBackendOptions,
) {
return this.llvmPassDumpParser.process(output.stderr, filters, llvmOptPipelineOptions);
}

Expand Down Expand Up @@ -1198,7 +1213,7 @@ export class BaseCompiler {
return [{text: 'Internal error; unable to open output path'}];
}

getIrOutputFilename(inputFilename: string, filters: ParseFilters): string {
getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string {
return inputFilename.replace(path.extname(inputFilename), '.ll');
}

Expand Down Expand Up @@ -1316,7 +1331,7 @@ export class BaseCompiler {
else return null;
}

async checkOutputFileAndDoPostProcess(asmResult, outputFilename, filters: ParseFilters) {
async checkOutputFileAndDoPostProcess(asmResult, outputFilename, filters: ParseFiltersAndOutputOptions) {
try {
const stat = await fs.stat(outputFilename);
asmResult.asmSize = stat.size;
Expand Down Expand Up @@ -1386,7 +1401,7 @@ export class BaseCompiler {
return Promise.all(filesToWrite);
}

protected async writeAllFiles(dirPath, source, files, filters: ParseFilters) {
protected async writeAllFiles(dirPath, source, files, filters: ParseFiltersAndOutputOptions) {
if (!source) throw new Error(`File ${this.compileFilename} has no content or file is missing`);

const inputFilename = path.join(dirPath, this.compileFilename);
Expand All @@ -1401,7 +1416,7 @@ export class BaseCompiler {
};
}

protected async writeAllFilesCMake(dirPath, source, files, filters: ParseFilters) {
protected async writeAllFilesCMake(dirPath, source, files, filters: ParseFiltersAndOutputOptions) {
if (!source) throw new Error('File CMakeLists.txt has no content or file is missing');

const inputFilename = path.join(dirPath, 'CMakeLists.txt');
Expand All @@ -1424,7 +1439,7 @@ export class BaseCompiler {

const outputFilename = this.getExecutableFilename(dirPath, this.outputFilebase, key);

const buildFilters: ParseFilters = Object.assign({}, key.filters);
const buildFilters: ParseFiltersAndOutputOptions = Object.assign({}, key.filters);
buildFilters.binary = true;
buildFilters.execute = true;

Expand Down Expand Up @@ -2307,7 +2322,7 @@ export class BaseCompiler {
return this.asm.process(result.asm, filters);
}

async postProcessAsm(result, filters?: ParseFilters) {
async postProcessAsm(result, filters?: ParseFiltersAndOutputOptions) {
if (!result.okToCache || !this.demanglerClass || !result.asm) return result;
const demangler = new this.demanglerClass(this.compiler.demangler, this);

Expand Down Expand Up @@ -2478,14 +2493,14 @@ but nothing was dumped. Possible causes are:
return this.handlePostProcessResult(result, await this.exec('bash', ['-c', postCommand], {maxOutput: maxSize}));
}

preProcess(source: string, filters: CompilerFilters): string {
preProcess(source: string, filters: CompilerOutputOptions): string {
if (filters.binary && !this.stubRe.test(source)) {
source += `\n${this.stubText}\n`;
}
return source;
}

async postProcess(result, outputFilename: string, filters: ParseFilters) {
async postProcess(result, outputFilename: string, filters: ParseFiltersAndOutputOptions) {
const postProcess = _.compact(this.compiler.postProcess);
const maxSize = this.env.ceProps('max-asm-size', 64 * 1024 * 1024);
const optPromise = result.hasOptOutput ? this.processOptOutput(result.optPath) : '';
Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/assembly.ts
Expand Up @@ -28,7 +28,7 @@ import path from 'path';
import _ from 'underscore';

import {BuildResult} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
import {AsmRaw} from '../parsers/asm-raw';
import {fileExists} from '../utils';
Expand Down Expand Up @@ -138,7 +138,7 @@ export class AssemblyCompiler extends BaseCompiler {

const outputFilename = this.getExecutableFilename(dirPath);

const buildFilters: ParseFilters = Object.assign({}, key.filters);
const buildFilters: ParseFiltersAndOutputOptions = Object.assign({}, key.filters);
buildFilters.binary = true;
buildFilters.execute = false;

Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/cc65.ts
Expand Up @@ -28,7 +28,7 @@ import fs from 'fs-extra';
import _ from 'underscore';

import {CompilationResult} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
import {CC65AsmParser} from '../parsers/asm-parser-cc65';
import * as utils from '../utils';
Expand Down Expand Up @@ -98,7 +98,7 @@ export class Cc65Compiler extends BaseCompiler {
maxSize: number,
intelAsm,
demangle,
filters: ParseFilters,
filters: ParseFiltersAndOutputOptions,
) {
const res = await super.objdump(outputFilename, result, maxSize, intelAsm, demangle, filters);

Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/circt.ts
Expand Up @@ -24,7 +24,7 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

import {BaseParser} from './argument-parsers';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class CIRCTCompiler extends BaseCompiler {
return BaseParser;
}

override optionsForFilter(filters: ParseFilters, outputFilename, userOptions?): any[] {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename, userOptions?): any[] {
return [];
}
}
4 changes: 2 additions & 2 deletions lib/compilers/cppfront.ts
Expand Up @@ -24,7 +24,7 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
import {AsmParserCpp} from '../parsers/asm-parser-cpp';

Expand All @@ -44,7 +44,7 @@ export class CppFrontCompiler extends BaseCompiler {
return 'cppp';
}

override optionsForFilter(filters: ParseFilters, outputFilename: any) {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: any) {
return [];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/dotnet.ts
Expand Up @@ -37,7 +37,7 @@ import {
import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces';
import {BaseCompiler} from '../base-compiler';
import {DotNetAsmParser} from '../parsers/asm-parser-dotnet';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';

class DotNetCompiler extends BaseCompiler {
private targetFramework: string;
Expand Down Expand Up @@ -204,7 +204,7 @@ class DotNetCompiler extends BaseCompiler {
return compilerResult;
}

override optionsForFilter(filters: ParseFilters) {
override optionsForFilter(filters: ParseFiltersAndOutputOptions) {
if (filters.binary) {
this.compileToBinary = true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/erlang.ts
Expand Up @@ -24,7 +24,7 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

import {ErlangParser} from './argument-parsers';
Expand All @@ -34,7 +34,7 @@ export class ErlangCompiler extends BaseCompiler {
return 'erlang';
}

override optionsForFilter(filters: ParseFilters, outputFilename: string): string[] {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string): string[] {
return [
'-noshell',
'-eval',
Expand Down
8 changes: 6 additions & 2 deletions lib/compilers/hlsl.ts
Expand Up @@ -24,7 +24,7 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

export class HLSLCompiler extends BaseCompiler {
Expand All @@ -39,7 +39,11 @@ export class HLSLCompiler extends BaseCompiler {
}

/* eslint-disable no-unused-vars */
override optionsForFilter(filters: ParseFilters, outputFilename: string, userOptions?: string[]): string[] {
override optionsForFilter(
filters: ParseFiltersAndOutputOptions,
outputFilename: string,
userOptions?: string[],
): string[] {
return [
'-Zi', // Embed debug information to get DXIL line associations
'-Qembed_debug', // Silences the warning associated with embedded debug information
Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/hook.ts
Expand Up @@ -25,15 +25,15 @@
import path from 'path';

import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

export class HookCompiler extends BaseCompiler {
static get key(): string {
return 'hook';
}

override optionsForFilter(filters: ParseFilters): string[] {
override optionsForFilter(filters: ParseFiltersAndOutputOptions): string[] {
return ['--dump'];
}

Expand Down
13 changes: 10 additions & 3 deletions lib/compilers/jakt.ts
Expand Up @@ -25,7 +25,7 @@
import path from 'path';

import {ExecutionOptions} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

export class JaktCompiler extends BaseCompiler {
Expand All @@ -43,13 +43,20 @@ export class JaktCompiler extends BaseCompiler {
return 'cppp';
}

override async objdump(outputFilename, result: any, maxSize: number, intelAsm, demangle, filters: ParseFilters) {
override async objdump(
outputFilename,
result: any,
maxSize: number,
intelAsm,
demangle,
filters: ParseFiltersAndOutputOptions,
) {
const objdumpResult = await super.objdump(outputFilename, result, maxSize, intelAsm, demangle, filters);
objdumpResult.languageId = 'asm';
return objdumpResult;
}

override optionsForFilter(filters: ParseFilters, outputFilename: any) {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: any) {
return ['--binary-dir', path.dirname(outputFilename)];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/llvm-mos.ts
Expand Up @@ -28,7 +28,7 @@ import fs from 'fs-extra';
import _ from 'underscore';

import {CompilationResult} from '../../types/compilation/compilation.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import * as utils from '../utils';

import {ClangCompiler} from './clang';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class LLVMMOSCompiler extends ClangCompiler {
maxSize: number,
intelAsm,
demangle,
filters: ParseFilters,
filters: ParseFiltersAndOutputOptions,
) {
if (!outputFilename.endsWith('.elf') && (await utils.fileExists(outputFilename + '.elf'))) {
outputFilename = outputFilename + '.elf';
Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/mlir.ts
Expand Up @@ -24,7 +24,7 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';

import {BaseParser} from './argument-parsers';
Expand Down Expand Up @@ -67,7 +67,7 @@ export class MLIRCompiler extends BaseCompiler {
return BaseParser;
}

override optionsForFilter(filters: ParseFilters, outputFilename, userOptions?): any[] {
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename, userOptions?): any[] {
return [];
}
}
4 changes: 2 additions & 2 deletions lib/compilers/nvcc.js
Expand Up @@ -51,7 +51,7 @@ export class NvccCompiler extends BaseCompiler {

/**
*
* @param {import('../../types/features/filters.interfaces').ParseFilters} filters
* @param {import('../../types/features/filters.interfaces').ParseFiltersAndOutputOptions} filters
* @param {string} outputFilename
* @param {string[]?} userOptions
* @returns {string[]}
Expand Down Expand Up @@ -107,7 +107,7 @@ export class NvccCompiler extends BaseCompiler {
*
* @param {*} result
* @param {string} outputFilename
* @param {import('../../types/features/filters.interfaces').ParseFilters} filters
* @param {import('../../types/features/filters.interfaces').ParseFiltersAndOutputOptions} filters
*/
async postProcess(result, outputFilename, filters) {
const maxSize = this.env.ceProps('max-asm-size', 64 * 1024 * 1024);
Expand Down

0 comments on commit 2fa2bbb

Please sign in to comment.