Charles Ying
2009-Jan-04 17:29 UTC
[LLVMdev] Avoiding jump (branch) instructions in a LLVM JavaScript backend
Hello llvm-dev, I've been hacking on a JavaScript backend to LLVM, starting with the CBackend as base. Sadly, JavaScript does not support a "goto" style of jump instruction, making it "tricky" to code generate a jump instruction. What might you recommend for avoiding jump instructions? Is there a transformation for something like this or any other ideas? The only solution I see at the moment is to write a small VM execution loop in JavaScript, but I was hoping that there might be other solutions. Thanks! Charles -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090104/d9e91a3a/attachment.html>
me22
2009-Jan-04 19:10 UTC
[LLVMdev] Avoiding jump (branch) instructions in a LLVM JavaScript backend
On Sun, Jan 4, 2009 at 12:29, Charles Ying <charles.ying at gmail.com> wrote:> Sadly, JavaScript does not support a "goto" style of jump instruction, > making it "tricky" to code generate a jump instruction. > > What might you recommend for avoiding jump instructions? Is there a > transformation for something like this or any other ideas? The only solution > I see at the moment is to write a small VM execution loop in JavaScript, but > I was hoping that there might be other solutions. >What about splitting each block into a javascript function and calling it with setTimeout( function() {...}, 0)? Or, similarly, having a while (1) { continuation(); } loop, where goto becomes continuation function() {...};.
John Criswell
2009-Jan-04 19:10 UTC
[LLVMdev] Avoiding jump (branch) instructions in a LLVM JavaScript backend
Charles Ying wrote:> Hello llvm-dev, > > I've been hacking on a JavaScript backend to LLVM, starting with the > CBackend as base. > > Sadly, JavaScript does not support a "goto" style of jump instruction, > making it "tricky" to code generate a jump instruction.One possible solution for code that is well structured is to map the branching behavior back into higher level constructs. For example, the LoopInfo pass can identify loops; you can probably translate those into JavaScript loops. You might be able to write a similar analysis pass that finds if/then/else constructs. Of course, this won't work in the general case (since LLVM bitcode can express arbitrary, unstructured branching behavior), but it might offer better code generation for programs that were written using structured programming constructs. -- John T.> > What might you recommend for avoiding jump instructions? Is there a > transformation for something like this or any other ideas? The only > solution I see at the moment is to write a small VM execution loop in > JavaScript, but I was hoping that there might be other solutions. > > Thanks! > Charles >
Filipe Cabecinhas
2009-Jan-05 16:12 UTC
[LLVMdev] Avoiding jump (branch) instructions in a LLVM JavaScript backend
Hi, Some time ago a friend of mine made a conversion script from AGI (an early virtual machine) to Javascript, including rudimentary goto support. He says it's not the best code in the world but you can take a look around: http://web.ist.utl.pt/~antonio.afonso/agi/logic.phps. There's an AGI emulator that plays Leisure Suite Larry a directory above ;-) You could also convert the LLVM's IR (SSA) to CPS and then you could just directly emit the javascript code :-P Regards, F On 4 Jan, 2009, at 17:29, Charles Ying wrote:> Hello llvm-dev, > > I've been hacking on a JavaScript backend to LLVM, starting with the > CBackend as base. > > Sadly, JavaScript does not support a "goto" style of jump > instruction, making it "tricky" to code generate a jump instruction. > > What might you recommend for avoiding jump instructions? Is there a > transformation for something like this or any other ideas? The only > solution I see at the moment is to write a small VM execution loop > in JavaScript, but I was hoping that there might be other solutions. > > Thanks! > Charles > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090105/cb04fb21/attachment.html>