MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / MojoCompiler

Class MojoCompiler

lib/compilers/mojo.ts:33–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31import {MojoParser} from './argument-parsers.js';
32
33export class MojoCompiler extends BaseCompiler {
34 static get key() {
35 return 'mojo';
36 }
37
38 constructor(info, env) {
39 super(info, env);
40 this.delayCleanupTemp = true;
41 this.compiler.supportsOptOutput = true;
42 this.compiler.supportsIrView = true;
43 this.compiler.irArg = ['--emit', 'llvm'];
44 this.compiler.minIrArgs = ['--emit=llvm'];
45 }
46
47 override getOutputFilename(dirPath: string, inputFileBase: string) {
48 // This method tells CE where to find the assembly output
49 const outputPath = path.join(dirPath, inputFileBase + '.s');
50 return outputPath;
51 }
52
53 override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions: string[]) {
54 if (filters.binary) return ['build'];
55 return ['build', '--emit=asm', '-o', outputFilename];
56 }
57
58 override getSharedLibraryPathsAsArguments() {
59 return [];
60 }
61
62 override getExecutableFilename(dirPath: string, outputFilebase: string) {
63 const executablePath = path.join(dirPath, 'example');
64 return executablePath;
65 }
66
67 override getIrOutputFilename(inputFilename: string): string {
68 return inputFilename.replace(/\.mojo$/, '.ll');
69 }
70
71 override async generateIR(
72 inputFilename: string,
73 options: string[],
74 irOptions: any,
75 produceCfg: boolean,
76 filters: any,
77 ) {
78 // Remove -o/--emit and their values from options
79 const filteredOptions: string[] = options.filter(
80 (opt, idx, arr) =>
81 opt !== '-o' &&
82 opt !== '--emit' &&
83 !opt.startsWith('--emit=') &&
84 arr[idx - 1] !== '-o' &&
85 arr[idx - 1] !== '--emit',
86 );
87 // Compute the .ll output path
88 const llPath = changeExtension(inputFilename, '.ll');
89 const newOptions = [...filteredOptions, '--emit=llvm', '-o', llPath];
90 const execOptions = this.getDefaultExecOptions();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected