ast2firm: Factorise code to convert a value to its storage type.