I'm using LLVM and Clang to generate assembly listing from .c file. Instructions are printed correctly, but in the beginning and in the end LLVM-Clang inserts default directives incompatible with my architecture. I overrode AsmPrinter class to get own directives, but I succeeded only in adding new directives not in replacing them. For instance:
MyAsmPrinter.c:
class MyAsmPrinter : public AsmPrinter {
...
void EmitStartOfAsmFile(Module &M) override;
void EmitEndOfAsmFile(Module &M) override;
...
}
void MyAsmPrinter::EmitStartOfAsmFile(Module &M) {
<--- insert something (A)
}
void MyAsmPrinter::EmitEndOfAsmFile(Module &M) {
<--- insert something (B)
}
clangtest.c:
int main()
{
int a, b;
b = 3;
a = b*b;
return a;
}
I type:
./bin/clang -target mytarget -S clangtest.c -o test.s
And get
.text
<--- (A goes here)
.file "clangtest.c"
.globl main
.type main,@function
main:
(correct asm code here)
.Ltmp0:
.size main, .Ltmp0-main
.ident "clang version 3.6.0 ..."
.section ".note.GNU-stack","",@progbits
<--- (B goes here)
But I want to get rid of ".text", ".file" and ".ident" at all. Where they get inserted anyway? I tried googling it, greping source code for other targets and LLVM source code, but found nothing. So, could anyone give me a hint how to do this?