Codegen: Cleanups

Clean up the code in preparation for supporting multiple definitions.

Signed-off-by: Pekka Enberg <penberg@iki.fi>