passing parameters for a analysis pass

Hi,

I want to pass parameter to a analysis pass. My pass need to use some result from some other tools. I can hard code a file name into my pass, and let my pass read input there, but what if I do not want the file name to be hard coded?

Is it possible to do that? If yes, where can I find some documentation about it?

Thanks,
Guoliang

You can use llvm::sys::Path::GetTemporaryDirectory() and put the
inputs and outputs there.

Reid

If you think a commandline option is the way to go, LLVM makes it
pretty easy to do so, see the documentation here:
http://llvm.org/docs/CommandLine.html .

Mostly you can just add an appropriate "cl::opt<string>" option (for
your filename, for example) and you're on your way.

~Will

The getAnalysis function returns a reference to a pass. Once you have the reference you can call the pass's member functions or access its member variables to send/receive information.

http://llvm.org/docs/WritingAnLLVMPass.html#getAnalysis

Trevor

As a follow up question, I am having problems when specifying cl::opt with
strings. I have seen the LoopUnrollPass, which uses cl::opt with unsigned.

I have tried exactly the same option:
cl::opt<string> with the parameter name as "fileName".
The code:
static cl::opt<std::string>metaFile("fileName", cl::desc("The llvm metadata
file to this pass"),cl::value_desc("llvmfile"));
  
When running opt, I use the pass argument : -fileName=file_metadata.
opt -load ~/llvm-2.9/Release/lib/LLVMInject.so -analysisInject
-fileName=file_metadata < input_ll_file.ll

However, the filename does not change to "file_metadata".

Any pointers on what could be wrong?

Thanks,
Anna

Will Dietz wrote: