Add support for Swift LLVM IR (#8180)

This adds support for the LLVM IR view for Swift, based on what other
LLVM based compilers do.

I tested it on my machine and it seems to work well, including with the
demangler. I'm not sure what `minIrArgs` is though, I added it because
it was there for other languages.

Co-authored-by: Nathan SALAUN <nathan.salaun@sofia.dev>
This commit is contained in:
Nathan S.
2025-10-13 21:20:25 +02:00
committed by GitHub
parent 685f68450a
commit 822292e4ea
2 changed files with 10 additions and 1 deletions

View File

@@ -165,4 +165,4 @@ From oldest to newest contributor, we would like to thank:
- [Florian Freitag](https://github.com/flofriday)
- [Trevor Gross](https://github.com/tgross35)
- [Alex Trotta](https://github.com/Ahajha)
- [natinusala](https://github.com/natinusala)

View File

@@ -22,6 +22,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import path from 'node:path';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {CompilationEnvironment} from '../compilation-env.js';
@@ -35,6 +37,9 @@ export class SwiftCompiler extends BaseCompiler {
constructor(info: PreliminaryCompilerInfo, env: CompilationEnvironment) {
super(info, env);
this.compiler.supportsIrView = true;
this.compiler.irArg = ['-emit-ir'];
this.compiler.minIrArgs = ['-emit-ir'];
this.compiler.optPipeline = {
arg: ['-Xllvm', '-print-after-all', '-Xllvm', '-print-before-all'],
moduleScopeArg: ['-Xllvm', '-print-module-scope'],
@@ -53,4 +58,8 @@ export class SwiftCompiler extends BaseCompiler {
override isCfgCompiler() {
return true;
}
override getIrOutputFilename(inputFilename: string): string {
return this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase).replace('.o', '.ll');
}
}