如何从dragonegg生成bitcode

时间:2011-09-24 21:22:28

标签: gcc llvm

dragonegg llvm-gcc 中时,可以发出-emit-llvm并确实生成了llvm bitcode。现在当我使用dragonegg作为插件(gcc -fplugin=dragonegg.so)时,我再也找不到任何这样的选项了。我发现的唯一一件事是生成LLVM IR - 这不是我想要的。 如何生成bitcode仍然可能?

GCC是4.6,LLVM和Dragonegg是当前的SVN。使用clang不是一种选择,因为它的C ++ 11支持很弱。

2 个答案:

答案 0 :(得分:1)

由于输出LLVM bitcode似乎不再可能了,我编写了一个python脚本,然后将IR提供给 llvm-as 然后给我bitcode。在性能方面,这是一场灾难,但至少它是有效的。

#/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()

答案 1 :(得分:0)

来自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).