copilot-c99 3.1.1 → 3.1.2
raw patch · 3 files changed
+50/−32 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG +7/−2
- copilot-c99.cabal +6/−6
- src/Copilot/Compile/C99/CodeGen.hs +37/−24
CHANGELOG view
@@ -1,8 +1,13 @@-2019-12-23 Frank Dedden <dev@dedden.net>+2020-03-30+ * Version bump (3.1.2)+ * Fixed bug where stream buffers are updated too soon. (#21)+ * Updated description of cabal package. (#17)++2019-12-23 * Version bump (3.1.1). * Fixed bug with constant structs and arrays.(#13). -2019-11-22 Ivan Perez <ivan.perez@nianet.org>+2019-11-22 * Version bump (3.1). * Remove ExternFun (#6). * Fix bug in code generation for local expression (#15).
copilot-c99.cabal view
@@ -1,22 +1,22 @@ cabal-version : >= 1.10 name : copilot-c99-version : 3.1.1+version : 3.1.2 synopsis : A compiler for Copilot targeting C99. description : This package is a back-end from Copilot to C. . Copilot is a stream (i.e., infinite lists) domain-specific language (DSL) in Haskell that compiles into embedded C. Copilot contains an interpreter,- multiple back-end compilers, and other verification tools. A tutorial, bug- reports, and todos are available at- <https://github.com/Copilot-Language/copilot-discussion>.+ multiple back-end compilers, and other verification tools. .- Examples are available at- <https://github.com/Copilot-Language/Copilot/tree/master/Examples>.+ A tutorial, examples, and other information are available at+ <https://copilot-language.github.io>. license : BSD3 license-file : LICENSE maintainer : Frank Dedden <dev@dedden.net>+homepage : https://copilot-language.github.io+bug-reports : https://github.com/Copilot-Language/copilot-c99/issues stability : Experimental category : Language, Embedded build-type : Simple
src/Copilot/Compile/C99/CodeGen.hs view
@@ -4,7 +4,7 @@ module Copilot.Compile.C99.CodeGen where import Control.Monad.State (runState)-import Data.List (union)+import Data.List (union, unzip4) import Data.Typeable (Typeable) import qualified Language.C99.Simple as C@@ -56,12 +56,45 @@ mkstep :: [Stream] -> [Trigger] -> [External] -> C.FunDef mkstep streams triggers exts = C.FunDef void "step" [] declns stmts where void = C.TypeSpec C.Void- declns = [] stmts = map mkexcopy exts ++ map mktriggercheck triggers- ++ map mkupdatebuffer streams- ++ map mkupdateindex streams+ ++ tmpassigns+ ++ bufferupdates+ ++ indexupdates+ (declns, tmpassigns, bufferupdates, indexupdates) =+ unzip4 $ map mkupdateglobals streams + -- Write code to update global stream buffers and index.+ mkupdateglobals :: Stream -> (C.Decln, C.Stmt, C.Stmt, C.Stmt)+ mkupdateglobals (Stream sid buff expr ty) =+ (tmpdecln, tmpassign, bufferupdate, indexupdate)+ where+ tmpdecln = C.VarDecln Nothing cty tmp_var Nothing++ tmpassign = case ty of+ Array _ -> C.Expr $ memcpy (C.Ident tmp_var) val size+ where+ size = C.LitInt $ fromIntegral $ tysize ty+ _ -> C.Expr $ C.Ident tmp_var C..= val++ bufferupdate = case ty of+ Array _ -> C.Expr $ memcpy dest (C.Ident tmp_var) size+ where+ dest = C.Index buff_var index_var+ size = C.LitInt $ fromIntegral $ tysize ty+ _ -> C.Expr $ C.Index buff_var index_var C..= (C.Ident tmp_var)++ indexupdate = C.Expr $ index_var C..= (incindex C..% bufflength)+ where+ bufflength = C.LitInt $ fromIntegral $ length buff+ incindex = (C..++) index_var++ tmp_var = streamname sid ++ "_tmp"+ buff_var = C.Ident $ streamname sid+ index_var = C.Ident $ indexname sid+ val = C.Funcall (C.Ident $ generatorname sid) []+ cty = transtype ty+ -- Make code that copies an external variable to its local one. mkexcopy :: External -> C.Stmt mkexcopy (External name cpyname ty) = C.Expr $ case ty of@@ -78,26 +111,6 @@ firetrigger = [C.Expr $ C.Funcall (C.Ident name) args'] where args' = take (length args) (map argcall (argnames name)) argcall name = C.Funcall (C.Ident name) []-- -- Code to update the global buffer.- mkupdatebuffer :: Stream -> C.Stmt- mkupdatebuffer (Stream sid buff expr ty) = case ty of- Array _ -> C.Expr $ memcpy dest src size where- dest = C.Index (C.Ident $ streamname sid) (C.Ident $ indexname sid)- src = C.Funcall (C.Ident $ generatorname sid) []- size = C.LitInt $ fromIntegral $ tysize ty- _ -> C.Expr $ C.Index var index C..= val where- var = C.Ident $ streamname sid- index = C.Ident $ indexname sid- val = C.Funcall (C.Ident $ generatorname sid) []-- -- Code to update the index.- mkupdateindex :: Stream -> C.Stmt- mkupdateindex (Stream sid buff expr ty) = C.Expr $ globvar C..= val where- globvar = C.Ident $ indexname sid- index = (C..++) (C.Ident $ indexname sid)- val = index C..% (C.LitInt $ fromIntegral len)- len = length buff -- Write a call to the memcpy function. memcpy :: C.Expr -> C.Expr -> C.Expr -> C.Expr