<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">This is a cool idea and AFAIK there isn’t any project that has done similar thing.<div class=""><br class=""></div><div class="">However IMO a potential problem is: In this story, LLVM only eases the efforts of writing a disassembler from scratch <span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">(and parsing object file formats for you)</span>. But we already can use the implementation of MCDisassembler provided by each target as a normal library to perform disassembly. Same for parsing object file formats.</div><div class="">In other words, it’s already easy to use LLVM’s disassembler in an emulator project.</div><div class=""><br class=""></div><div class="">It is, however, an attractive option to _directly_ generate part of the emulator code. We can even provide handler code for each instruction in the TG description as you have suggested. It would be a cool out-of-tree project for sure, but I see little chance to go upstream because it’s pretty far away from LLVM’s original goal.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">-Min</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 17, 2021, at 2:58 PM, John Byrd via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Howdy llvm-dev,<div class=""><br class=""></div><div class="">Low priority question.  This doesn't really meet the requirements for an RFC, because it's probably merely a half-baked idea at this point.<div class=""><br class=""></div><div class="">As I was working with some tablegen internals on an 8-bit processor backend, it struck me that I would need at some point to write an emulator for that processor.</div><div class=""><br class=""></div><div class="">And I realized that, although I could write an emulator in the traditional manner, tablegen already has most of the information it needs to automatically generate the guts of an emulator.</div><div class=""><br class=""></div><div class="">Tablegen's already generating a disassembler (-gen-disassembler). </div><div class=""><br class=""></div><div class="">At the least, tablegen could be given an additional backend that says, "given this instruction, do this emulation step."  Such a step could be pure code copied from the .td files, or it could be compositionally constructed based on the classes that an object is composed from.</div><div class=""><br class=""></div><div class="">You'd have to write your own code to deal with emulated machine state, but hey, instruction parsing would be an item off the to-do list.</div><div class=""><br class=""></div><div class="">I would have a hard time believing that this concept is novel.  Has anyone else taken a crack at this?</div><div class=""><br class=""></div><div class="">Sincerely,</div><div class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">---<br class=""><br class="">John Byrd<br class="">Gigantic Software<br class="">2321 E 4th Street<br class="">Suite C #429<br class="">Santa Ana, CA  92705-3862<br class=""><a href="http://www.giganticsoftware.com/" target="_blank" class="">http://www.giganticsoftware.com</a><br class="">T: (949) 892-3526 F: (206) 309-0850</div></div></div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>