Skip to content

Commit

Permalink
copilot-c99: Write uniquely numbered triggers to .c output. Refs Copi…
Browse files Browse the repository at this point in the history
…lot-Language#296.

Generate the trigger guard and argument functions using the unique
names.
  • Loading branch information
fdedden committed Dec 20, 2024
1 parent 5934349 commit 92932bb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions copilot-c99/src/Copilot/Compile/C99/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Copilot.Compile.C99.Settings ( CSettings, cSettingsOutputDirectory,
cSettingsStepFunctionName,
mkDefaultCSettings )
import Copilot.Compile.C99.Type ( transType )
import Copilot.Compile.C99.Representation ( UniqueTrigger (..), mkUniqueTriggers )

-- | Compile a specification to a .h and a .c file.
--
Expand Down Expand Up @@ -90,11 +91,12 @@ compileC cSettings spec = C.TransUnit declns funs
declns = mkExts exts
++ mkGlobals streams

funs = mkGenFuns streams triggers
++ [mkStep cSettings streams triggers exts]
funs = mkGenFuns streams uniqueTriggers
++ [mkStep cSettings streams uniqueTriggers exts]

streams = specStreams spec
triggers = specTriggers spec
uniqueTriggers = mkUniqueTriggers triggers
exts = gatherExts streams triggers

-- Make declarations for copies of external variables.
Expand All @@ -110,7 +112,7 @@ compileC cSettings spec = C.TransUnit declns funs
indexDecln (Stream sId _ _ _ ) = mkIndexDecln sId

-- Make generator functions, including trigger arguments.
mkGenFuns :: [Stream] -> [Trigger] -> [C.FunDef]
mkGenFuns :: [Stream] -> [UniqueTrigger] -> [C.FunDef]
mkGenFuns streamList triggerList = map accessDecln streamList
++ map streamGen streamList
++ concatMap triggerGen triggerList
Expand All @@ -122,11 +124,11 @@ compileC cSettings spec = C.TransUnit declns funs
streamGen (Stream sId _ expr ty) =
exprGen (generatorName sId) (generatorOutputArgName sId) expr ty

triggerGen :: Trigger -> [C.FunDef]
triggerGen (Trigger name guard args) = guardDef : argDefs
triggerGen :: UniqueTrigger -> [C.FunDef]
triggerGen (UniqueTrigger uniqueName (Trigger _name guard args)) = guardDef : argDefs
where
guardDef = mkGenFun (guardName name) guard Bool
argDefs = zipWith argGen (argNames name) args
guardDef = mkGenFun (guardName uniqueName) guard Bool
argDefs = zipWith argGen (argNames uniqueName) args

argGen :: String -> UExpr -> C.FunDef
argGen argName (UExpr ty expr) =
Expand Down

0 comments on commit 92932bb

Please sign in to comment.