Using MCAsmParser to generate MCInst

Is there some interface in MCAsmParser that will give me back a list of MCInst? It seems like the only interfaces available write out asm or object code to a file/buffer.

The ultimate goal is to be able to pass an inline asm string and get back a list of MCInst (usually of size one). I suspect this might be tricky because the point I want to do this is before register allocation and the inline asm might have placeholder references like $0, which should somehow become a “virtual” register in the MCInst. I’ll bet the parser doesn’t understand how to interpret those but maybe the target AsmBackend could somehow handle parsing them. It seems like a flexible enough framework to at least make it plausible.

I could manually parse it but handling all the different instruction types is going to be extremely tedious and there’s a whole framework that knows how to parse instructions right there.

Thanks for any help!

David

I never tried before but a custom MCStreamer might work. More specifically, overriding the MCStreamer::emitInstruction to receive the MCInst stream.

Not sure how to deal with the placeholder (register) issue though.

That’s a good thought about a custom streamer, thanks!

All I really need to do is check where the placeholder appears in the instruction and map it to the corresponding virtual register passed to the inline asm. This is a read-only operation, I don’t need to modify the inline asm or anything so I think a pretty simplistic custom operand parsing should work.

David