Thanks,
Alex
You might want to check out LLVM <http://www.llvm.org>, which includes
the ability to generate Altivec and SSE code.
It's a pretty amazing beast (it even has the ability to "rewrite" vector
code down to non-vector code so you can target non-vector architectures
"for free"), though still a bit rough around the edges...
Very cool. Thank you for the link. However, I can't find any
information on how to compile a high level language to LLVM bytecode. I
found HLVM, but unfortunately that project doesn't look like it's
gotten very far. Do you know if there any similar (more mature)
projects? Or a tutorial of some sort?
Thanks,
Alex
There's a gcc front end for an LLVM back end, which pretty much meets
the definition of "how to compile a high level language to LLVM" though
it's far from something that you'd want to delve through to figure out
how to do it.
Start with the "stacker" example, which takes a FORTH-like stack-based
RPN language and produces the corresponding LLVM structures (which can
be recorded as bytecodes or directly executed). It's definitely the
most "tutorialish" of the batch.
It's mostly straightforward once you get into it ("so how do I make a
'switch' statement? Ah, there's a 'switch' instruction"), but it is a
bit of a curve to get started. I was able to rewrite a stack based
virtual machine that evaluated expressions into a JIT in a couple of
days, and added various statement control structures over the next
couple of days after that.
You can also use the gcc front end to compile code snippet and look at
the resulting bytecodes (and there's pretty much a one-to-one
correspondence between them and the various classes you instantiate).
You don't even have to downlood the whole gcc-llvm toolchain - there's a
web front end that lets you type in code snippets and compile it, which
is great for the "how do I make a 'for' loop with a 'break' statement"
sort of problems.