[haskell-llvm] enforce block structure of functions
lemming at henning-thielemann.de
Sun Oct 10 14:21:51 EDT 2010
In LLVM.Core.Instructions I read:
-- Use Terminate to ensure bb termination (how?)
To answer this question: I would introduce a Block monad. LLVM assembly
instructions become actions of the Block monad and a block must be
terminated with a terminator directive like 'br' or 'ret'. This rule is
ensured by a function that lifts a Block to a CodeGenFunction:
embedBlock :: Block r Terminate -> CodeGenFunction r ()
Since we recently started to use the monadic result () for instructions
without a result like 'store', we can no longer use the type synonym
Terminate = (). But we could add a new type (data Terminate = Terminate)
or just (data Terminate).
This change would break most of the code that uses the llvm package, but
it would document and force the overall structure of a piece of LLVM
assembly code written in Haskell.
As a light proposal for now, I would just like to define a new type
Terminate, that is distinct from ().
More information about the Haskell-llvm