llvm-pretty 0.3.0.0 → 0.3.1.0
raw patch · 2 files changed
+32/−2 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Text.LLVM: assign :: IsValue a => Ident -> BB (Typed a) -> BB (Typed Value)
- Text.LLVM: (:>) :: a -> b -> :> a b
+ Text.LLVM: (:>) :: a -> b -> (:>) a b
Files
- llvm-pretty.cabal +1/−1
- src/Text/LLVM.hs +31/−1
llvm-pretty.cabal view
@@ -1,5 +1,5 @@ Name: llvm-pretty-Version: 0.3.0.0+Version: 0.3.1.0 License: BSD3 License-file: LICENSE Author: Trevor Elliott
src/Text/LLVM.hs view
@@ -44,6 +44,7 @@ , freshLabel , label , comment+ , assign -- * Terminator Instructions , ret@@ -109,13 +110,21 @@ import Data.Maybe (maybeToList) import Data.String (IsString(..)) import MonadLib hiding (jump,Label)-import qualified Data.Map as Map+import qualified Data.Map.Strict as Map -- Fresh Names ----------------------------------------------------------------- type Names = Map.Map String Int +-- | Avoid generating the provided name. When the name already exists, return+-- Nothing.+avoid :: String -> Names -> Maybe Names+avoid name ns =+ case Map.lookup name ns of+ Nothing -> Just (Map.insert name 0 ns)+ Just _ -> Nothing+ nextName :: String -> Names -> (String,Names) nextName pfx ns = case Map.lookup pfx ns of@@ -274,6 +283,13 @@ { unBB :: WriterT [BasicBlock] (StateT RW Id) a } deriving (Functor,Applicative,Monad,MonadFix) +avoidName :: String -> BB ()+avoidName name = BB $ do+ rw <- get+ case avoid name (rwNames rw) of+ Just ns' -> set rw { rwNames = ns' }+ Nothing -> fail ("avoidName: " ++ name ++ " already registered")+ freshNameBB :: String -> BB String freshNameBB pfx = BB $ do rw <- get@@ -438,6 +454,20 @@ comment :: String -> BB () comment str = effect (Comment str)++-- | Emit an assignment that uses the given identifier to name the result of the+-- BB operation.+--+-- WARNING: this can throw errors.+assign :: IsValue a => Ident -> BB (Typed a) -> BB (Typed Value)+assign r@(Ident name) body = do+ avoidName name+ tv <- body+ rw <- BB get+ case rwStmts rw of+ Result _ i m : stmts -> do BB (set rw { rwStmts = Result r i m : stmts })+ return (const (ValIdent r) `fmap` tv)+ _ -> fail "assign: invalid argument" -- | Emit the ``ret'' instruction and terminate the current basic block. ret :: IsValue a => Typed a -> BB ()