From 051b52653dc726b469b0c93eeedc6e45c322ae02 Mon Sep 17 00:00:00 2001 From: Adam Procter Date: Thu, 19 May 2016 13:21:04 -0500 Subject: [PATCH] Bump version number to 0.1.0.2; fix name mangling in ToVHDL; tweak Fibonacci example to remove "module" header (should me Main, not Fibonacci) --- ReWire.cabal | 5 +++-- ReWire/PreHDL/ToVHDL.hs | 26 +++++++++++++++----------- examples/Fibonacci/Fibonacci.hs | 2 -- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ReWire.cabal b/ReWire.cabal index 3f1040f..c16e9eb 100644 --- a/ReWire.cabal +++ b/ReWire.cabal @@ -10,7 +10,7 @@ name: ReWire -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.1 +version: 0.1.0.2 -- A short (one-line) description of the package. synopsis: A Haskell-to-VHDL compiler @@ -54,7 +54,8 @@ data-files: lib/*.hs cabal-version: >=1.10 library - build-depends: base >=4.6 && <5 + build-depends: ghc >=7.6.3 + , base >=4.6 && <5 , bytestring >= 0.10 , containers >= 0.5 , deepseq >= 1.3.0 diff --git a/ReWire/PreHDL/ToVHDL.hs b/ReWire/PreHDL/ToVHDL.hs index 4219416..fee85d0 100644 --- a/ReWire/PreHDL/ToVHDL.hs +++ b/ReWire/PreHDL/ToVHDL.hs @@ -5,6 +5,10 @@ module ReWire.PreHDL.ToVHDL where import ReWire.PreHDL.Syntax import Data.List (intercalate) +import Encoding (zEncodeString) -- this is from the ghc package + +mangle :: String -> String +mangle = zEncodeString vTy :: Ty -> String vTy (TyBits n) = "std_logic_vector(0 to " ++ show (n-1) ++ ")" @@ -34,8 +38,8 @@ vRHS :: RHS -> String vRHS (BoolRHS b) = vBool b vRHS (LocRHS "input") = "input_tmp" -- FIXME: kludge vRHS (LocRHS l) = l -vRHS (FunCallRHS s []) = s -vRHS (FunCallRHS s ls) = s ++ "(" ++ intercalate "," ls ++ ")" +vRHS (FunCallRHS s []) = mangle s +vRHS (FunCallRHS s ls) = mangle s ++ "(" ++ intercalate "," ls ++ ")" vRHS (ConstRHS bs) = "\"" ++ concatMap show bs ++ "\"" vRHS (SliceRHS lo hi r) = r ++ "(" ++ show lo ++ " to " ++ show hi ++ ")" vRHS (ConcatRHS ls) = "(" ++ intercalate " & " ls ++ ")" @@ -75,23 +79,23 @@ vCmd (CaseIf bs) = let (b1,c1) = head bs vFunDefnProto :: FunDefn -> String -vFunDefnProto fd = "function " ++ funDefnName fd ++ (if null params - then "" - else "(" ++ intercalate " ; " (map ((++" : std_logic_vector") . regDeclName) params) ++ ")") - ++ " return std_logic_vector;" +vFunDefnProto fd = "function " ++ mangle (funDefnName fd) ++ (if null params + then "" + else "(" ++ intercalate " ; " (map ((++" : std_logic_vector") . regDeclName) params) ++ ")") + ++ " return std_logic_vector;" where params = funDefnParams fd vFunDefn :: FunDefn -> String -vFunDefn fd = "function " ++ funDefnName fd ++ (if null params - then "" - else "(" ++ intercalate " ; " (map ((++" : std_logic_vector") . regDeclName) params) ++ ")") - ++ " return std_logic_vector\n" +vFunDefn fd = "function " ++ mangle (funDefnName fd) ++ (if null params + then "" + else "(" ++ intercalate " ; " (map ((++" : std_logic_vector") . regDeclName) params) ++ ")") + ++ " return std_logic_vector\n" ++ "is\n" ++ indent (concatMap ((++"\n") . vRegDecl) (funDefnRegDecls fd)) ++ "begin\n" ++ indent (vCmd (funDefnBody fd) ++ "\n") ++ indent ("return " ++ funDefnResultReg fd ++ ";\n") - ++ "end " ++ funDefnName fd ++ ";" + ++ "end " ++ mangle (funDefnName fd) ++ ";" where params = funDefnParams fd flopName, flopNextName :: String -> String diff --git a/examples/Fibonacci/Fibonacci.hs b/examples/Fibonacci/Fibonacci.hs index a06cefc..e373677 100644 --- a/examples/Fibonacci/Fibonacci.hs +++ b/examples/Fibonacci/Fibonacci.hs @@ -1,5 +1,3 @@ -module Fibonacci where - -- -- The compiler doesn't yet support a "prelude" so we will have to define a -- few things ourselves!