문제

Now we are implementing a analysis pass for llvm, following this tutorial. and need to pass an additional argument to the plugin such as below:

opt -load /path/to/myplugin.so -mypass -mypass_option input.bc

However I did not find any manual telling me how to do. So I'm wondering whether it is possible in practice.

Thanks in advance.

도움이 되었습니까?

해결책

You should use the CommandLine library which comes built-in with LLVM. Basically, you just put at the top of the .cpp file of the pass:

#include "llvm/Support/CommandLine.h"

static cl::opt<string> InputFilename("mypass_option", cl::desc("Specify input filename for mypass"), cl::value_desc("filename"));

But I recommend you check the above link, it has full reference + convenient quickstart section.

For an example, take a look at the built-in loop unrolling pass - it defines two unsigned and two boolean options, right at the top of the source file, by using cl::opt<unsigned> and cl::opt<bool>.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top