aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/pythran.ts
blob: dff1c20163db859ea0817e790bf0e14cf8214b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from 'path';

import {CompileChildLibraries} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';

export class PythranCompiler extends BaseCompiler {
    static get key() {
        return 'pythran';
    }

    cpp_compiler_root: string;

    constructor(info: PreliminaryCompilerInfo, env) {
        super(info, env);
        this.cpp_compiler_root = this.compilerProps<string>(`compiler.${this.compiler.id}.cpp_compiler_root`);
    }

    override getSharedLibraryPaths(libraries: CompileChildLibraries[], dirPath?: string): string[] {
        let ldpath = super.getSharedLibraryPaths(libraries, dirPath);
        if (this.cpp_compiler_root) {
            ldpath = ldpath.concat(
                path.join(this.cpp_compiler_root, 'lib'),
                path.join(this.cpp_compiler_root, 'lib64'),
            );
        }
        return ldpath;
    }

    override getDefaultExecOptions() {
        const execOptions = super.getDefaultExecOptions();

        if (this.cpp_compiler_root) {
            execOptions.env.PATH = execOptions.env.PATH + ':' + path.join(this.cpp_compiler_root, 'bin');
        }

        return execOptions;
    }

    override optionsForFilter(
        filters: ParseFiltersAndOutputOptions,
        outputFilename: string,
        userOptions?: string[],
    ): string[] {
        let options = ['-o', this.filename(outputFilename)];
        if (!filters.binary && !filters.binaryObject) options = options.concat('-E');
        return options;
    }

    override getCompilerResultLanguageId(filters?: ParseFiltersAndOutputOptions): string | undefined {
        if (filters !== undefined && filters.binary) return 'asm';
        else return 'cppp';
    }
}