I'm trying to find a way to set the assembly syntax that LLVM outputs (for x86 in particular). Following the Compiling to Object Code section of the Kaleidoscope tutorial, I'm outputting assembly files with
TargetMachine->addPassesToEmitFile(pass, dest, nullptr, llvm::CGFT_AssemblyFile))
But there's no option to set the output syntax.
llc has the command line option --x86-asm-syntax with which you can set the output assembly syntax (for x86), so I'm sure there must be a way to do it.
So is there a way this can be done through LLVM's C++ API?
Here's a few things I found out by reading the LLVM source:
AssemblyDialectmember inllvm::MCAsmInfo. For x86 the derived classes ofllvm::MCAsmInfocan be found inX86MCAsmInfo.handX86MCAsmInfo.cpp.AssemblyDialectis initialized to the value ofAsmWriterFlavor, which is set by the command line optionx86-asm-syntax.As far as I could tell
AssemblyDialectisn't referenced anywhere else in the code base, so the only way to set it is by thex86-asm-syntaxflag. For that you can usellvm::cl::ParseCommandLineOptions. Minimal example for setting the assembly syntax to intel: