abergmeier
abergmeier

Reputation: 14042

How to generate bitcode from dragonegg

Back when dragonegg was in llvm-gcc one could issue -emit-llvm and it did generate llvm bitcode. Now when I use dragonegg as a plugin (gcc -fplugin=dragonegg.so) I cannot find any such option anymore. The only thing I found was generating LLVM IR - which is not what I want. How is it still possible to generate bitcode?

GCC is 4.6, LLVM and Dragonegg are current SVN. And using clang is not an option since its C++11 support is feeble.

Upvotes: 0

Views: 1470

Answers (2)

abergmeier
abergmeier

Reputation: 14042

Since outputting LLVM bitcode doesn't seem to be possible anymore I wrote a python script which then feeds the IR to llvm-as which then gives me bitcode. Performance-wise this is a catastrophe, but at least it works.

#/usr/bin/env python

import sys, subprocess

args = list(sys.argv)
del args[0] # Remove our exec name
compiler = args[0] 
del args[0] # Remove the compile name

compileArguments = [compiler]
outputFile = ''

foundFile = False

for arg in args:
if arg.startswith('-o'):
    foundFile = True
elif foundFile:
    outputFile = arg
    foundFile = False
    arg = "/dev/stdout"

compileArguments.append(arg)

compileProcess = subprocess.Popen(compileArguments, stdout=subprocess.PIPE)
asbin = 'llvm-as'

ir2bcProcess = subprocess.Popen([asbin, '-f', '-o=' + outputFile], stdin=compileProcess.stdout)

stdout, stderr = ir2bcProcess.communicate()

compileProcess.wait()
ir2bcProcess.wait()

Upvotes: 1

ephemient
ephemient

Reputation: 204668

From the README:

-fplugin-arg-dragonegg-emit-ir
-flto
  Output LLVM IR rather than target assembler.  You need to use -S with this,
  since otherwise GCC will pass the output to the system assembler (these don't
  usually understand LLVM IR).  It would be nice to fix this and have the option
  work with -c too but it's not clear how.  If you plan to read the IR then you
  probably want to use the -fverbose-asm flag as well (see below).

Upvotes: 0

Related Questions