[llvm-dev] Serializing LLVM IR in custom fashion

Philip Pfaffe via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 6 06:46:57 PDT 2018


Hi,

[InstVisitor](http://llvm.org/doxygen/classllvm_1_1InstVisitor.html) will
give you that switch. Derive from that and you get to handle the different
instruction types appropriately.

Cheers,
Philip

On Thu, Sep 6, 2018 at 3:41 PM Gleb Popov via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello.
>
> I need to write a pass that converts a whole LLVM module into a bytecode
> for some other VM. VM's instructions resemble LLVM ones pretty much, so it
> is almost 1-to-1 translation. Basically, I need to do what BitWriterPass
> does, but using different format for the resulting bytecode.
>
> The obvious solution is just to iterate over all Instructions and
> serialize them using giant switch(i->getOpcode()), however this involves
> writing much boilerplate code. And I would eventually need to write a
> deserializer too, so that doubles the boilerplate work.
>
> Any ideas how to do that easier way? How much of existing LLVM code can I
> reuse?
>
> Thanks in advance.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180906/9875b33d/attachment.html>


More information about the llvm-dev mailing list