c++ - How to generate LLVM bitcode for a file using a compilation database? -
i want generate llvm bitcode large number of c source files have compilation database . there way invoke clang such reads compilation database , uses appropriate flags?
background
for toy programs, command generate llvm bitcode simple:
clang -emit-llvm -c foo.c -o foo.bc however, source files in large projects require lots of additional compilation flags, including -is , -ds , whatnot.
i want write script iterates on large number of source files , calls clang -emit-llvm ... on each generate llvm bitcode. difficulty each clang -emit-llvm ... command has have flags specific source file. have compilation database these source files, captures flags needed each individual source file. is there way make clang -emit-llvm ... aware of compilation database?
one solution i've thought of parse compilation database myself , find appropriate entry each source file, , modify command entry (a) include -emit-llvm , (b) change -o foo.o -o foo.bc, , run command. might work, seems bit hacky.
instead of parsing compilation database yourself, rely on python binding so. judging test suite of binding, like:
cdb = compilationdatabase.fromdirectory(kinputsdir) cmds = cdb.getallcompilecommands() and update content of cmds.
Comments
Post a Comment