Code Generation in the Flex Protocol