MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / runCompiler

Method runCompiler

lib/compilers/sway.ts:118–235  ·  view source on GitHub ↗
(
        compiler: string,
        options: string[],
        inputFilename: string,
        execOptions: ExecutionOptionsWithEnv,
        filters?: Partial<ParseFiltersAndOutputOptions>,
    )

Source from the content-addressed store, hash-verified

116 }
117
118 override async runCompiler(
119 compiler: string,
120 options: string[],
121 inputFilename: string,
122 execOptions: ExecutionOptionsWithEnv,
123 filters?: Partial<ParseFiltersAndOutputOptions>,
124 ): Promise<CompilationResult> {
125 // Make a temp directory for a forc project
126 const projectDir = await this.newTempDir();
127
128 const {symbolsPath} = await setupForcProject(projectDir, inputFilename, this.std);
129
130 // Run `forc build`
131 // "compiler" is the path to the forc binary from .properties
132 const buildOptions = ['build', '-g', symbolsPath, ...options.filter(arg => arg !== inputFilename)];
133 const buildResult = await this.exec(compiler, buildOptions, {
134 ...execOptions,
135 customCwd: projectDir,
136 });
137
138 // If build succeeded, parse the bytecode
139 let asm: ResultLine[] = [];
140 if (buildResult.code === 0) {
141 const artifactPath = path.join(projectDir, 'out', 'debug', 'compiler-explorer.bin');
142
143 if (filters?.intel) {
144 const asmResult = await this.exec(compiler, ['build', '--asm', 'all'], {
145 ...execOptions,
146 customCwd: projectDir,
147 });
148 const lines = splitLines(asmResult.stdout);
149 const startIndex = lines.findIndex(line => line.includes(';; ASM: Virtual abstract program'));
150 const endIndex = lines.findIndex(line => line.includes('[1;32mFinished'));
151 if (startIndex === -1 || endIndex === -1 || startIndex >= endIndex) {
152 asm = [{text: '<Error extracting ASM output>'}];
153 } else {
154 asm = lines
155 .slice(startIndex, endIndex)
156 .filter(line => line.trim() !== '')
157 .map(line => ({text: line}));
158 }
159 } else {
160 const parseResult = await this.exec(compiler, ['parse-bytecode', artifactPath], {
161 ...execOptions,
162 customCwd: projectDir,
163 });
164 const symbols: SymbolMap | undefined = await utils.tryReadJsonFile(symbolsPath);
165
166 // Map the bytecode lines
167 const contentLines = splitLines(parseResult.stdout)
168 .filter(line => line.trim() !== '')
169 .map(line => {
170 const match = line.match(/^\s*(\d+)\s+(\d+)\s+/);
171 if (match && symbols) {
172 const opcodeIndex = match[1];
173 const symbolInfo = symbols.map[opcodeIndex];
174 if (symbolInfo && symbolInfo.path === 1) {
175 return {

Callers 1

generateIRMethod · 0.95

Calls 6

setupForcProjectFunction · 0.85
newTempDirMethod · 0.80
matchMethod · 0.80
pushMethod · 0.80
splitLinesFunction · 0.70
execMethod · 0.45

Tested by

no test coverage detected