The Art of SquirrelFish's Bytecode Generation
Saturday, January 10, 2009 I have to say, after my summer at Adobe, my C skills have definitely improved. Thanks Edwin Smith, Tom Reilly, and Dan Smith! Going through SquirrelFish seems way easier than going through Tamarin. On that note, let's take a look at how SquirrelFish generates bytecodes. SquirrelFish does something pretty nifty. It parses the JavaScript source code into an Abstract Syntax Tree (AST). This AST is passed into a byte code generator that walks the tree, generating bytecode and assigning registers to specific values as it goes along. For some reason, I expected bytecode to be generated during the initial parsing. SquirrelFish heavily uses polymorphism so that each AST node generates the bytecode that itself represents.
Nodes.cpp
RegisterID* NumberNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst)
{
if (dst == generator.ignoredResult())
return 0;
return generator.emitLoad(dst, m_double);
}
6 m_instructions; 72 bytes at 00BAD510; 1 parameter(s); 14 callee register(s)[ 0] enter
[ 1] mov r3, r0
[ 4] resolve_func r4, r3, print(@id0)
[ 8] mov r5, r1
[ 11] call r3, r3, 2, 14
[ 16] end r3
Identifiers:
id0 = print
Constants:
r0 = undefined
r1 = "hello world"
hello world
End: undefined
All of the bytecode definitions can be found on the Webkit website. Next up, register allocation!

Reader Comments (3)
nice one. Very informative.
Very useful. Much appreciated.
Very useful information. I was looking for in-depth posts about squirrelfish like yours.
May I know how I can see my bytecodes which the squirrelfish generates based on my java script code?
Could you give me a direction?
I succeeded to make a sample code and compile it with the squirrelfish.