Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added period args
  • Loading branch information
Tom committed May 26, 2010
1 parent 9d19ac8 commit 4762123
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/Code.hs
Expand Up @@ -6,14 +6,14 @@ import Text.Printf

import Model

genCode :: String -> [String] -> [Class] -> IO ()
genCode name includes classes = writeFile (name ++ ".c") $ "// Generated by statechart.\n"
genCode :: String -> Int -> [String] -> [Class] -> IO ()
genCode name period includes classes = writeFile (name ++ ".c") $ "// Generated by statechart.\n"
++ "#include <stdbool.h>\n"
++ "#include <stdint.h>\n\n"
++ concat [ "#include \"" ++ inc ++ "\"\n" | inc <- includes ]
++ "\n"
++ "void " ++ name ++ "() {\n"
++ indent ("static uint64_t stateChartGlobalClock = 0;\n\n" ++ concatMap codeStateChart (concat [ s | Class _ s <- classes ]) ++ "stateChartGlobalClock++;\n")
++ indent ("static uint64_t stateChartGlobalClock = 0;\n\n" ++ concatMap (codeStateChart period) (concat [ s | Class _ s <- classes ]) ++ "stateChartGlobalClock++;\n")
++ "}\n\n"

formatId :: String -> String -> String
Expand All @@ -30,11 +30,11 @@ indent = unlines . map (" " ++) . lines
block :: String -> String
block a = "{\n" ++ indent a ++ "}\n"

codeStateChart :: StateChart -> String
codeStateChart (StateChart name states transitions) = seq defaultState $ "// " ++ name ++ "\n" ++ block (unlines
codeStateChart :: Int -> StateChart -> String
codeStateChart period (StateChart name states transitions) = seq defaultState $ "// " ++ name ++ "\n" ++ block (unlines
[ unlines [ printf "static bool %s = false;" (sId $ stateId state) | state <- states ]
, unlines [ printf "static uint64_t %s_entryTime = 0;" (sId $ stateId state) | state <- states ]
, concatMap (codeTransition states) transitions
, concatMap (codeTransition period states) transitions
]) ++ "\n"
where
root = head [ state | state <- states, stateParent state == Nothing ]
Expand All @@ -46,17 +46,17 @@ codeStateChart (StateChart name states transitions) = seq defaultState $ "// " +
then error "default state not specified (2)"
else head [ state | state <- states, stateId state == transitionTarget defaultTransition ]

codeTransition :: [State] -> Transition -> String
codeTransition states t = case transitionSource t of
codeTransition :: Int -> [State] -> Transition -> String
codeTransition period states t = case transitionSource t of
Nothing -> "// -> " ++ stateName (idState states target) ++ "\n"
++ "if (period20() && !" ++ sId (head b) ++ ") {\n"
++ "if (period" ++ show period ++ "() && !" ++ sId (head b) ++ ") {\n"
++ indent (transAction (transitionAction t) ++ concatMap (stateEntry . idState states) b)
++ "}\n\n"
where
b = hierarchy states target

Just source -> "// " ++ stateName (idState states source) ++ " -> " ++ stateName (idState states target) ++ "\n"
++ "if (period20() && " ++ predicate ++ ") {\n"
++ "if (period" ++ show period ++ "() && " ++ predicate ++ ") {\n"
++ indent (concatMap (stateExit . idState states) a ++ transAction (transitionAction t) ++ concatMap (stateEntry . idState states) b)
++ "}\n\n"
where
Expand Down
4 changes: 2 additions & 2 deletions src/Statechart.hs
Expand Up @@ -10,7 +10,7 @@ main :: IO ()
main = do
args <- getArgs
case args of
name : args@(_:_) -> readFile (last args) >>= genCode name (init args) . parseModel . parseRhapsody
name : period : args@(_:_) -> readFile (last args) >>= genCode name (read period) (init args) . parseModel . parseRhapsody
_ -> help

help :: IO ()
Expand All @@ -20,7 +20,7 @@ help = putStrLn $ unlines
, " statechart - statechart code generation"
, ""
, "SYNOPSIS"
, " statechart <name> { <include-files> } <rhapsody-file>"
, " statechart <name> <period>{ <include-files> } <rhapsody-file>"
, ""
, "DESCRIPTION"
, " Compiles a statechart to <name>.c"
Expand Down

0 comments on commit 4762123

Please sign in to comment.