<div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>[InstVisitor](<a href="http://llvm.org/doxygen/classllvm_1_1InstVisitor.html">http://llvm.org/doxygen/classllvm_1_1InstVisitor.html</a>) will give you that switch. Derive from that and you get to handle the different instruction types appropriately.<br></div><div><br></div><div>Cheers,</div><div>Philip</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 6, 2018 at 3:41 PM Gleb Popov via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Hello.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Any ideas how to do that easier way? How much of existing LLVM code can I reuse?<br></div><div><br></div><div>Thanks in advance.<br></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>