Skip to content

Commit

Permalink
first bits of compiler interface (#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
partouf committed Dec 2, 2022
1 parent 1af4cc7 commit ae0fee1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/base-compiler.ts
Expand Up @@ -42,7 +42,7 @@ import {
LLVMOptPipelineBackendOptions,
LLVMOptPipelineOutput,
} from '../types/compilation/llvm-opt-pipeline-output.interfaces';
import {CompilerInfo} from '../types/compiler.interfaces';
import {CompilerInfo, ICompiler} from '../types/compiler.interfaces';
import {
BasicExecutionResult,
ExecutableExecutionOptions,
Expand Down Expand Up @@ -79,8 +79,8 @@ import {getToolchainPath} from './toolchain-utils';
import {Tool, ToolResult, ToolTypeKey} from './tooling/base-tool.interface';
import * as utils from './utils';

export class BaseCompiler {
public compiler: CompilerInfo & Record<string, any>; // TODO: Some missing types still present in Compiler type
export class BaseCompiler implements ICompiler {
protected compiler: CompilerInfo & Record<string, any>; // TODO: Some missing types still present in Compiler type
public lang: Language;
protected compileFilename: string;
protected env: any;
Expand Down
23 changes: 17 additions & 6 deletions lib/compilers/fake-for-test.js → lib/compilers/fake-for-test.ts
Expand Up @@ -24,7 +24,16 @@

import _ from 'underscore';

export class FakeCompiler {
import {ICompiler} from '../../types/compiler.interfaces';
import {Language} from '../../types/languages.interfaces';
import {CompilerArguments} from '../compiler-arguments';

export class FakeCompiler implements ICompiler {
public possibleArguments: CompilerArguments;
public lang: any;
private compiler: any;
private info: any;

static get key() {
return 'fake-for-test';
}
Expand All @@ -40,10 +49,15 @@ export class FakeCompiler {
);
this.lang = {id: this.compiler.lang, name: `Language ${this.compiler.lang}`};
this.info = info;
this.possibleArguments = new CompilerArguments();
}

initialise(mtime: Date, clientOptions: any, isPrediscovered: boolean) {
throw new Error('Method not implemented.');
}

getInfo() {
return null;
return this.compiler;
}

getDefaultFilters() {
Expand All @@ -61,6 +75,7 @@ export class FakeCompiler {
options: options,
backendOptions: backendOptions,
filters: filters,
files: undefined,
},
};

Expand All @@ -79,8 +94,4 @@ export class FakeCompiler {
}),
);
}

initalize() {
return null;
}
}
9 changes: 5 additions & 4 deletions lib/handlers/compile.ts
Expand Up @@ -33,6 +33,7 @@ import temp from 'temp';
import _ from 'underscore';
import which from 'which';

import {ICompiler} from '../../types/compiler.interfaces';
import {BaseCompiler} from '../base-compiler';
import {CompilationEnvironment} from '../compilation-env';
import {getCompilerTypeByKey} from '../compilers';
Expand Down Expand Up @@ -156,7 +157,7 @@ export class CompileHandler {
});
}

async create(compiler): Promise<BaseCompiler | null> {
async create(compiler): Promise<ICompiler | null> {
const isPrediscovered = !!compiler.version;

const type = compiler.compilerType || 'default';
Expand Down Expand Up @@ -208,7 +209,7 @@ export class CompileHandler {
}
}

async setCompilers(compilers: BaseCompiler[], clientOptions: Record<string, any>) {
async setCompilers(compilers: ICompiler[], clientOptions: Record<string, any>) {
// Be careful not to update this.compilersById until we can replace it entirely.
const compilersById = {};
try {
Expand All @@ -217,9 +218,9 @@ export class CompileHandler {
let compilersCreated = 0;
const createdCompilers = _.compact(await Promise.all(_.map(compilers, this.create, this)));
for (const compiler of createdCompilers) {
const langId = compiler.compiler.lang;
const langId = compiler.getInfo().lang;
if (!compilersById[langId]) compilersById[langId] = {};
compilersById[langId][compiler.compiler.id] = compiler;
compilersById[langId][compiler.getInfo().id] = compiler;
compilersCreated++;
}
logger.info('Compilers created: ' + compilersCreated);
Expand Down
12 changes: 11 additions & 1 deletion types/compiler.interfaces.ts
Expand Up @@ -22,9 +22,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

// Minimal Compiler properties until a better one can be sync'ed with the backend
import {CompilerArguments} from '../lib/compiler-arguments';
import {Tool, ToolInfo} from '../lib/tooling/base-tool.interface';

import {Language} from './languages.interfaces';
import {Library} from './libraries/libraries.interfaces';

export type CompilerInfo = {
Expand Down Expand Up @@ -85,3 +86,12 @@ export type CompilerInfo = {
preamble?: string;
};
};

export interface ICompiler {
possibleArguments: CompilerArguments;
lang: Language;
compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries, files);
cmake(files, key);
initialise(mtime: Date, clientOptions, isPrediscovered: boolean);
getInfo();
}

0 comments on commit ae0fee1

Please sign in to comment.