質問

I'm using LLVM to perform static analysis using opt (i.e. an LLVM Pass). To perform this analysis, the user provides me with a text file that lists a few metrics and some stats about them. I'll need the user to also map each of these metrics to a set of LLVM instructions. Hence, the following could an example input file:

<name 1>.attribute_a = 12  
<name 2>.attribute_a = 11 
<name 3>.attribute_a = 0.6  

<name 1>.instructions = Alloca,Load,Fence  
<name 2>.instructions = ZExt,SExt  
<name 3>.instructions = Shl,Xor,Add,FAdd,Invoke  

And so on. Parsing the attributes has already been taken care of and I have a map that points from the name of each metric to a struct of the data that pertains to it. What I'd like to do now is to parse the instructions and add the set of instructions to that struct of data.

I think it's most convenient for both the user and myself to have the instructions in the input file be represented as opcodes, so instead of the above we could have something like:

<name 1>.attribute_a = 12   

<name 1>.instructions = 26,27,30 

But I'm not totally sure. What's the best way to represent the input data in a text file and what's the best way to actually parse the data once that's been done? I think I'll end up using something like std::set<unsigned> to represent the data.

役に立ちましたか?

解決

I don't think it matters much as long as you have a 1-to-1 mapping between entities in your text file and actual LLVM IR instructions. The instruction names may be more readable, so you can parse into a std::set<std::string>. Note that llvm::Instruction has the method getOpcodeName which you can compare to a textual name read from a file.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top