This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE DuplicateRecordFields, NoFieldSelectors #-}
|
||||
{-|
|
||||
Module : Language.QBE
|
||||
Description : Types and Pretty instances for the QBE IL
|
||||
@@ -278,7 +279,15 @@ instance Pretty Field where
|
||||
|
||||
-- TODO use record syntax on long types like this one
|
||||
-- | Function definition. The 'Maybe (Ident \'Temporary)' is the environment
|
||||
data FuncDef = FuncDef [Linkage] (Maybe AbiTy) (Ident 'Global) (Maybe (Ident 'Temporary)) [Param] Variadic (NonEmpty Block)
|
||||
data FuncDef = FuncDef
|
||||
{ linkage :: [Linkage]
|
||||
, returnType :: Maybe AbiTy
|
||||
, name :: Ident 'Global
|
||||
, env :: Maybe (Ident 'Temporary)
|
||||
, params :: [Param]
|
||||
, variadic :: Variadic
|
||||
, code :: NonEmpty Block
|
||||
}
|
||||
deriving (Show, Eq, Data)
|
||||
|
||||
instance Pretty FuncDef where
|
||||
@@ -333,7 +342,12 @@ instance Pretty Val where
|
||||
pretty (ValGlobal ident) = pretty ident
|
||||
|
||||
-- | Block of instructions beginning with a label and ending with a jump
|
||||
data Block = Block (Ident 'Label) [Phi] [Inst] Jump
|
||||
data Block = Block
|
||||
{ label :: Ident 'Label
|
||||
, phis :: [Phi]
|
||||
, insts :: [Inst]
|
||||
, jump :: Jump
|
||||
}
|
||||
deriving (Show, Eq, Data)
|
||||
|
||||
instance Pretty Block where
|
||||
|
||||
@@ -50,12 +50,12 @@ goldenTests = testGroup "golden tests"
|
||||
, t "function" $ FuncDef [Export] (Just $ AbiAggregateTy "t") "f"
|
||||
(Just "env") [Param (AbiBaseTy Word) "a", Param (AbiBaseTy Double) "b"] Variadic $
|
||||
Block "l" [] [] (Ret Nothing) :| []
|
||||
, t "val" [valInt 0, ValTemporary "temporary", ValGlobal "global"]
|
||||
, t "val" [valInt 0, ValTemporary "temporary", ValConst (CGlobal "global")]
|
||||
, t "jmp" $ Jmp "target"
|
||||
, t "jnz" $ Jnz (valInt 0) "target1" "target2"
|
||||
, t "ret" $ Ret $ Just $ ValTemporary "x"
|
||||
, t "phi" $ Phi (Assignment "a" Word) [PhiArg "b" $ valInt 1, PhiArg "c" $ valInt 2]
|
||||
, t "call" $ Call (Just ("r", AbiBaseTy Word)) (ValGlobal "f") (Just $ valInt 1)
|
||||
, t "call" $ Call (Just ("r", AbiBaseTy Word)) (ValConst (CGlobal "f")) (Just $ valInt 1)
|
||||
[Arg (AbiBaseTy Word) $ valInt 2, Arg (AbiAggregateTy "t") $ ValTemporary "a"]
|
||||
[Arg (AbiBaseTy Word) $ valInt 3, Arg (AbiAggregateTy "t1") $ ValTemporary "b"]
|
||||
, t "inst" $ Block "l" []
|
||||
@@ -112,9 +112,9 @@ helloWorld = Program [] [helloString] [helloMain]
|
||||
Nothing [] NoVariadic $
|
||||
Block "start"
|
||||
[]
|
||||
[ Call (Just ("r", AbiBaseTy Word)) (ValGlobal "puts")
|
||||
[ Call (Just ("r", AbiBaseTy Word)) (ValConst (CGlobal "puts"))
|
||||
Nothing
|
||||
[Arg (AbiBaseTy Long) $ ValGlobal "str"]
|
||||
[Arg (AbiBaseTy Long) $ ValConst (CGlobal "str")]
|
||||
[]
|
||||
]
|
||||
(Ret $ Just $ ValConst $ CInt 0)
|
||||
|
||||
Reference in New Issue
Block a user