Permalink
Browse files

have ocram optionally dump p-code

  • Loading branch information...
1 parent 159140d commit 8d104672c375656b9795dc73f210a38d25c9f5af Alexander Bernauer committed Oct 26, 2012
View
1 applications/simulation_os/collect-and-forward/.gitignore
@@ -1,4 +1,5 @@
ec.c
pal.c
+pc.c
*.elf
*.pped.*
View
2 applications/simulation_os/collect-and-forward/Makefile
@@ -41,4 +41,4 @@ native.elf: native.o $(OS_ROOT)/os/libos.a
$(CC) $(CFLAGS) -o $@ $^
ec.c pal.c debug.json: tc.c $(OCRAM) $(PALGEN) $(OCRAM_PAL_TEMPLATE)
- $(OCRAM) -p pal.c -i $< -o ec.c -g $(PALGEN) -d debug.json -c "$(CC) $(CFLAGS) -DOCRAM_MODE -E -o -" || (rm -f ec.c pal.c; exit 1)
+ $(OCRAM) -k pc.c -p pal.c -i $< -o ec.c -g $(PALGEN) -d debug.json -c "$(CC) $(CFLAGS) -DOCRAM_MODE -E -o -" || (rm -f ec.c pal.c; exit 1)
View
7 ocram/src/Ocram/IO.hs
@@ -3,7 +3,7 @@ module Ocram.IO
-- export {{{1
(
parse
- , dump_ecode
+ , dump_ecode, dump_pcode
, dump_debug_info
, generate_pal
) where
@@ -39,6 +39,11 @@ parse opt = do
Left e -> (IoOcramError . return . Left) [new_error 1 ("parsing failed\n" ++ show e) Nothing]
Right x -> return x
+dump_pcode :: Options -> BS.ByteString -> IO (Either [OcramError] ()) -- {{{1
+dump_pcode options pcode =
+ case optPcode options of
+ Nothing -> return (Right ())
+ Just pfile -> write pfile pcode
dump_ecode :: Options -> BS.ByteString -> IO (Either [OcramError] ()) -- {{{1
dump_ecode options ecode =
View
3 ocram/src/Ocram/Main.hs
@@ -6,7 +6,7 @@ import Ocram.Backend (tcode_2_ecode)
import Ocram.Debug (create_debug_info)
import Ocram.Intermediate (ast_2_ir)
import Ocram.Options (options)
-import Ocram.IO (parse, generate_pal, dump_ecode, dump_debug_info)
+import Ocram.IO (parse, generate_pal, dump_ecode, dump_debug_info, dump_pcode)
import Ocram.Print (render_with_log')
import Ocram.Ruab (encode_debug_info)
import Ocram.Text (OcramError, show_errors)
@@ -40,6 +40,7 @@ runCompiler argv = do
exitOnError "output" =<< generate_pal opt (footprint (anaCallgraph ana)) pal
exitOnError "output" =<< dump_ecode opt ecode
exitOnError "output" =<< dump_debug_info opt di
+ exitOnError "output" =<< dump_pcode opt pcode
return ()
View
38 ocram/src/Ocram/Options.hs
@@ -15,16 +15,16 @@ import System.Console.GetOpt
import System.Path (absNormPath)
data Options = Options { -- {{{1
- optInput :: FilePath
- , optOutput :: FilePath
+ optInput :: FilePath
+ , optOutput :: FilePath
+ , optPcode :: Maybe FilePath
, optPreprocessor :: FilePath
, optPalGenerator :: Maybe FilePath
- , optPalFile :: Maybe FilePath
- , optDebugFile :: Maybe FilePath
- , optHelp :: Bool
+ , optPalFile :: Maybe FilePath
+ , optDebugFile :: Maybe FilePath
+ , optHelp :: Bool
}
-
options :: String -> FilePath -> [String] -> Either [OcramError] Options -- {{{1
options prg cwd argv =
let use = usage prg in
@@ -41,19 +41,20 @@ options prg cwd argv =
(_,n,[]) -> Left [new_error 3 (err use ("unknown options '" ++ unwords n ++ "'")) Nothing]
(_,_,es) -> Left [new_error 4 (err use $ intercalate "\n" es) Nothing]
-help :: String -> String
+help :: String -> String -- {{{2
help use = "Printing usage:\n" ++ use
-err :: String -> String -> String
+err :: String -> String -> String -- {{{2
err use msg = "Error in command line options\n" ++ msg ++ "\n" ++ use
-usage :: String -> String
+usage :: String -> String -- {{{2
usage prg = usageInfo ("Usage: " ++ prg ++ " OPTIONS") (availableOptions "")
-availableOptions :: FilePath -> [OptDescr (Options -> Options)]
+availableOptions :: FilePath -> [OptDescr (Options -> Options)] -- {{{1
availableOptions cwd = [
- Option "i" ["input"] (ReqArg (\x opts -> opts {optInput = abs x}) "input") "input tc file (required)"
- , Option "o" ["output"] (ReqArg (\x opts -> opts {optOutput = abs x}) "output") "output ec file (required)"
+ Option "i" ["input"] (ReqArg (\x opts -> opts {optInput = abs x}) "input") "input t-code file (required)"
+ , Option "o" ["output"] (ReqArg (\x opts -> opts {optOutput = abs x}) "output") "output e-code file (required)"
+ , Option "k" ["p-code"] (ReqArg (\x opts -> opts {optPcode = Just (abs x)}) "p-code") "output p-code file (optional)"
, Option "c" ["preprocessor"] (ReqArg (\x opts -> opts {optPreprocessor = x}) "preprocessor") "external program which performs the pre-processing of the input C file (required)"
, Option "g" ["generator"] (ReqArg (\x opts -> opts {optPalGenerator = Just x}) "generator") "external program which generates the PAL implementation (optional)"
, Option "p" ["pal"] (ReqArg (\x opts -> opts {optPalFile = Just (abs x)}) "pal") "file path for the PAL generator program (mandatory if generator is specified)"
@@ -62,15 +63,16 @@ availableOptions cwd = [
]
where abs = $fromJust_s . absNormPath cwd
-defaultOptions :: Options
+defaultOptions :: Options -- {{{1
defaultOptions = Options {
- optInput = ""
- , optOutput = ""
+ optInput = ""
+ , optOutput = ""
+ , optPcode = Nothing
, optPreprocessor = ""
, optPalGenerator = Nothing
- , optPalFile = Nothing
- , optDebugFile = Nothing
- , optHelp = False
+ , optPalFile = Nothing
+ , optDebugFile = Nothing
+ , optHelp = False
}
checkOptions :: Options -> Bool

0 comments on commit 8d10467

Please sign in to comment.