diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..4349842 --- /dev/null +++ b/cabal.project @@ -0,0 +1,7 @@ +packages: . + +-- TODO RGS: Remove this +source-repository-package + type: git + location: https://github.com/GaloisInc/language-bluespec + tag: 7f2daed111f6029953a63804500bd17ca6b5c4aa diff --git a/src/Copilot/Compile/Bluespec/CodeGen.hs b/src/Copilot/Compile/Bluespec/CodeGen.hs index 6d9fde0..ee9c296 100644 --- a/src/Copilot/Compile/Bluespec/CodeGen.hs +++ b/src/Copilot/Compile/Bluespec/CodeGen.hs @@ -119,13 +119,13 @@ mkAccessDecln sId ty xs = nameId = BS.mkId BS.NoPos $ fromString name buffLength = cLit $ BS.LInt $ BS.ilDec $ toInteger $ length xs argId = BS.mkId BS.NoPos "x" - index = BS.CApply (BS.CVar (BS.idPercentAt BS.NoPos)) - [ BS.CApply (BS.CVar BS.idPlus) - [ BS.CVar (BS.mkId BS.NoPos (fromString (indexName sId))) - , BS.CVar argId - ] - , buffLength - ] + index = BS.CBinOp + (BS.CBinOp + (BS.CVar (BS.mkId BS.NoPos (fromString (indexName sId)))) + BS.idPlus + (BS.CVar argId)) + (BS.idPercentAt BS.NoPos) + buffLength indexExpr = cIndexVector (BS.CVar (BS.mkId BS.NoPos (fromString (streamName sId)))) index @@ -198,24 +198,26 @@ mkStepRule streams where bufferUpdate = BS.CSExpr Nothing $ - BS.Cwrite - BS.NoPos + BS.CBinOp (cIndexVector (BS.CVar buffId) (BS.CVar indexId)) + BS.idAssign (BS.CVar genId) indexUpdate = BS.CSExpr Nothing $ - BS.Cwrite - BS.NoPos + BS.CBinOp (BS.CVar indexId) - (BS.CApply (BS.CVar (BS.idPercentAt BS.NoPos)) - [incIndex, buffLength]) + BS.idAssign + (BS.CBinOp + incIndex + (BS.idPercentAt BS.NoPos) + buffLength) where buffLength = cLit $ BS.LInt $ BS.ilDec $ toInteger $ length buff - incIndex = BS.CApply (BS.CVar BS.idPlus) - [ BS.CVar indexId - , cLit $ BS.LInt $ BS.ilDec 1 - ] + incIndex = BS.CBinOp + (BS.CVar indexId) + BS.idPlus + (cLit $ BS.LInt $ BS.ilDec 1) buffId = BS.mkId BS.NoPos $ fromString $ streamName sId genId = BS.mkId BS.NoPos $ fromString $ generatorName sId diff --git a/src/Copilot/Compile/Bluespec/Compile.hs b/src/Copilot/Compile/Bluespec/Compile.hs index c4701ea..cb5eb40 100644 --- a/src/Copilot/Compile/Bluespec/Compile.hs +++ b/src/Copilot/Compile/Bluespec/Compile.hs @@ -16,7 +16,7 @@ import Data.Typeable (Typeable) import qualified Language.Bluespec.Classic.AST as BS import qualified Language.Bluespec.Classic.AST.Builtin.Ids as BS import qualified Language.Bluespec.Classic.AST.Builtin.Types as BS -import Text.PrettyPrint.HughesPJClass (Pretty (..), render) +import qualified Language.Bluespec.SystemVerilog.AST.Pretty as BS import System.Directory (createDirectoryIfMissing) import System.Exit (exitFailure) import System.FilePath (()) @@ -56,17 +56,17 @@ compileWith bsSettings prefix spec exitFailure | otherwise - = do let typesBsFile = render $ pPrint $ compileTypesBS bsSettings prefix spec - ifcBsFile = render $ pPrint $ compileIfcBS bsSettings prefix spec - bsFile = render $ pPrint $ compileBS bsSettings prefix spec + = do let typesBsFile = BS.pvpReadable $ compileTypesBS bsSettings prefix spec + ifcBsFile = BS.pvpReadable $ compileIfcBS bsSettings prefix spec + bsFile = BS.pvpReadable $ compileBS bsSettings prefix spec let dir = bluespecSettingsOutputDirectory bsSettings createDirectoryIfMissing True dir - writeFile (dir specTypesPkgName prefix ++ ".bs") typesBsFile - writeFile (dir specIfcPkgName prefix ++ ".bs") ifcBsFile + writeFile (dir specTypesPkgName prefix ++ ".bsv") typesBsFile + writeFile (dir specIfcPkgName prefix ++ ".bsv") ifcBsFile writeFile (dir "bs_fp.c") copilotBluespecFloatingPointC writeFile (dir "BluespecFP.bsv") copilotBluespecFloatingPointBSV - writeFile (dir prefix ++ ".bs") bsFile + writeFile (dir prefix ++ ".bsv") bsFile where triggers = specTriggers spec diff --git a/src/Copilot/Compile/Bluespec/Expr.hs b/src/Copilot/Compile/Bluespec/Expr.hs index c4978ae..3e25c3c 100644 --- a/src/Copilot/Compile/Bluespec/Expr.hs +++ b/src/Copilot/Compile/Bluespec/Expr.hs @@ -78,9 +78,10 @@ transOp1 op e = -- Bluespec's Arith class does not have a `recip` method corresponding to -- Haskell's `recip` in the `Fractional` class, so we implement it -- ourselves. - Recip ty -> BS.CApply - (BS.CVar (BS.idSlashAt BS.NoPos)) - [constNumTy ty 1, e] + Recip ty -> BS.CBinOp + (constNumTy ty 1) + (BS.idSlashAt BS.NoPos) + e BwNot _ty -> app $ BS.idInvertAt BS.NoPos Cast fromTy toTy -> transCast fromTy toTy e @@ -150,7 +151,7 @@ transOp2 op e1 e2 = Atan2 ty -> appFP ty "atan2" where app :: BS.Id -> BS.CExpr - app i = BS.CApply (BS.CVar i) [e1, e2] + app i = BS.CBinOp e1 i e2 appFP :: forall t. Type t -> String -> BS.CExpr appFP ty funPrefix = app $ fpFunId ty funPrefix @@ -630,7 +631,9 @@ cLit = BS.CLit . BS.CLiteral BS.NoPos -- | Create a Bluespec expression that indexes into a @Vector@. cIndexVector :: BS.CExpr -> BS.CExpr -> BS.CExpr cIndexVector vec idx = - BS.CApply (BS.CVar (BS.mkId BS.NoPos "select")) [vec, idx] + BS.CApply + (BS.CVar (BS.idPrimSelectFn BS.NoPos)) + [BS.CVar BS.idNoPosition, vec, idx] -- | Create a Bluespec expression that updates a @Vector@ element at a -- particular index.