Refactor code generator.
Add support for buffers and memory spaces.
Hoist map declarations.