-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Currently, copilot-bluespec has a fair bit of code that is copy-pasted from copilot-c99:
-
Almost all of the code in
Copilot.Compile.Bluespec.Externalis taken directly fromCopilot.Compile.C99.External. -
This code in
Copilot.Compile.Bluespec.Name:copilot-bluespec/src/Copilot/Compile/Bluespec/Name.hs
Lines 69 to 95 in 9d83645
-- | Turn a stream id into a suitable Bluespec variable name. streamName :: Id -> String streamName sId = "s" ++ show sId -- | Turn a stream id into the global varname for indices. indexName :: Id -> String indexName sId = streamName sId ++ "_idx" -- | Turn a stream id into the name of its accessor function streamAccessorName :: Id -> String streamAccessorName sId = streamName sId ++ "_get" -- | Turn stream id into name of its generator function. generatorName :: Id -> String generatorName sId = streamName sId ++ "_gen" -- | Turn the name of a trigger into a guard generator. guardName :: String -> String guardName name = lowercaseName name ++ "_guard" -- | Turn a trigger name into a an trigger argument name. argName :: String -> Int -> String argName name n = lowercaseName name ++ "_arg" ++ show n -- | Enumerate all argument names based on trigger name. argNames :: String -> [String] argNames base = map (argName base) [0..] Is taken from
Copilot.Compile.C99.Name. -
This code in
Copilot.Compile.Bluespec.Compile:copilot-bluespec/src/Copilot/Compile/Bluespec/Compile.hs
Lines 262 to 294 in 9d83645
-- ** Obtain information from Copilot Core Exprs and Types. -- | List all types of an expression, returns items uniquely. exprTypes :: Typeable a => Expr a -> [UType] exprTypes e = case e of Const ty _ -> typeTypes ty Local ty1 ty2 _ e1 e2 -> typeTypes ty1 `union` typeTypes ty2 `union` exprTypes e1 `union` exprTypes e2 Var ty _ -> typeTypes ty Drop ty _ _ -> typeTypes ty ExternVar ty _ _ -> typeTypes ty Op1 _ e1 -> exprTypes e1 Op2 _ e1 e2 -> exprTypes e1 `union` exprTypes e2 Op3 _ e1 e2 e3 -> exprTypes e1 `union` exprTypes e2 `union` exprTypes e3 Label ty _ _ -> typeTypes ty -- | List all types of a type, returns items uniquely. typeTypes :: Typeable a => Type a -> [UType] typeTypes ty = case ty of Array ty' -> typeTypes ty' `union` [UType ty] Struct x -> concatMap (\(Value ty' _) -> typeTypes ty') (toValues x) `union` [UType ty] _ -> [UType ty] -- | Collect all expression of a list of streams and triggers and wrap them -- into an UEXpr. gatherExprs :: [Stream] -> [Trigger] -> [UExpr] gatherExprs streams triggers = map streamUExpr streams ++ concatMap triggerUExpr triggers where streamUExpr (Stream _ _ expr ty) = UExpr ty expr triggerUExpr (Trigger _ guard args) = UExpr Bool guard : args Is taken from
Copilot.Compile.C99.Compile. -
Much of the infrastructure in the unit tests in each package.
Ideally, we could find some way to share this code in between the two libraries to avoid code duplication. One complication is that most of this code lives in modules that aren't exported. Perhaps it would make sense to create a new copilot-backend library that factors out the code shared in common?