X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=Translator.hs;h=3b0886086b055d3b34aaa8b8c368d0ce2d70bf39;hb=4fb701e41729143a897d43cd8a9c0217b8b3f68a;hp=e1c3325d0e2c753ef0948e7d0f0b8fe5152ddd32;hpb=a5334443f2d490ae6ada3f332eb04b508ff81648;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/Translator.hs b/Translator.hs index e1c3325..3b08860 100644 --- a/Translator.hs +++ b/Translator.hs @@ -33,8 +33,10 @@ import qualified ForSyDe.Backend.Ppr import Text.PrettyPrint.HughesPJ (render) import TranslatorTypes +import HsValueMap import Pretty import Flatten +import FlattenTypes import qualified VHDL main = @@ -65,7 +67,7 @@ main = -- Add the builtin functions mapM addBuiltIn builtin_funcs -- Create entities and architectures for them - mapM flattenBind binds + mapM processBind binds return $ AST.DesignFile [] [] @@ -80,24 +82,33 @@ findBind binds lookfor = NonRec var _ -> lookfor == (occNameString $ nameOccName $ getName var) ) binds --- | Flattens the given bind and adds it to the session. Then (recursively) --- finds any functions it uses and does the same with them. -flattenBind :: - CoreBind -- The binder to flatten +-- | Processes the given bind as a top level bind. +processBind :: + CoreBind -- The bind to process -> VHDLState () -flattenBind (Rec _) = error "Recursive binders not supported" - -flattenBind bind@(NonRec var expr) = do +processBind (Rec _) = error "Recursive binders not supported" +processBind bind@(NonRec var expr) = do -- Create the function signature let ty = CoreUtils.exprType expr let hsfunc = mkHsFunction var ty - --hwfunc <- mkHWFunction bind hsfunc - -- Add it to the session - --addFunc hsfunc hwfunc + flattenBind hsfunc bind + +-- | Flattens the given bind into the given signature and adds it to the +-- session. Then (recursively) finds any functions it uses and does the same +-- with them. +flattenBind :: + HsFunction -- The signature to flatten into + -> CoreBind -- The bind to flatten + -> VHDLState () + +flattenBind _ (Rec _) = error "Recursive binders not supported" + +flattenBind hsfunc bind@(NonRec var expr) = do + -- Flatten the function let flatfunc = flattenFunction hsfunc bind addFunc hsfunc - setFlatFunc hsfunc flatfunc + setFlatFunc hsfunc (Left flatfunc) let used_hsfuncs = map appFunc (apps flatfunc) State.mapM resolvFunc used_hsfuncs return () @@ -123,7 +134,7 @@ resolvFunc hsfunc = do let bind = findBind (cm_binds core) name case bind of Nothing -> error $ "Couldn't find function " ++ name ++ " in current module." - Just b -> flattenBind b + Just b -> flattenBind hsfunc b where name = hsFuncName hsfunc @@ -185,7 +196,10 @@ addBuiltIn (BuiltIn name args res) = do builtin_funcs = [ - BuiltIn "hwxor" [(Single ("a", VHDL.bit_ty)), (Single ("b", VHDL.bit_ty))] (Single ("o", VHDL.bit_ty)) + BuiltIn "hwxor" [(Single ("a", VHDL.bit_ty)), (Single ("b", VHDL.bit_ty))] (Single ("o", VHDL.bit_ty)), + BuiltIn "hwand" [(Single ("a", VHDL.bit_ty)), (Single ("b", VHDL.bit_ty))] (Single ("o", VHDL.bit_ty)), + BuiltIn "hwor" [(Single ("a", VHDL.bit_ty)), (Single ("b", VHDL.bit_ty))] (Single ("o", VHDL.bit_ty)), + BuiltIn "hwnot" [(Single ("a", VHDL.bit_ty))] (Single ("o", VHDL.bit_ty)) ] -- vim: set ts=8 sw=2 sts=2 expandtab: