Add --dumpcases option

Output goes in the same directory as the generated code (so
build/exec/<appname>_app for the Chez back end)
This commit is contained in:
Edwin Brady 2020-04-02 16:06:00 +01:00
parent 8029241458
commit 59503712f3
6 changed files with 51 additions and 18 deletions

View File

@ -10,6 +10,7 @@ Christian Rasmussen
David Smith David Smith
Edwin Brady Edwin Brady
GhiOm GhiOm
Guillaume Allais
Ilya Rezvov Ilya Rezvov
Jan de Muijnck-Hughes Jan de Muijnck-Hughes
Kamil Shakirov Kamil Shakirov

View File

@ -18,7 +18,7 @@ rsync -avm --include-from='srcfiles' -f 'hide,! */' dist idris2-$1
# Copy run time support for Idris 2 # Copy run time support for Idris 2
cp -r support idris2-$1/support cp -r support idris2-$1/support
# Copy top level files and docs # Copy top level files and docs
cp *.md CONTRIBUTORS Makefile LICENSE idris2.ipkg idris2-$1 cp *.md CONTRIBUTORS Makefile LICENSE *.ipkg idris2-$1
tar zcvf idris2-$1.tgz idris2-$1 tar zcvf idris2-$1.tgz idris2-$1
shasum -a 256 idris2-$1.tgz > idris2-$1.tgz.sha256 shasum -a 256 idris2-$1.tgz > idris2-$1.tgz.sha256

View File

@ -87,13 +87,47 @@ natHackNames
NS ["Prelude"] (UN "natToInteger"), NS ["Prelude"] (UN "natToInteger"),
NS ["Prelude"] (UN "integerToNat")] NS ["Prelude"] (UN "integerToNat")]
export
fastAppend : List String -> String
fastAppend xs
= let len = cast (foldr (+) 0 (map length xs)) in
unsafePerformIO $
do b <- newStringBuffer (len+1)
build b xs
getStringFromBuffer b
where
build : StringBuffer -> List String -> IO ()
build b [] = pure ()
build b (x :: xs) = do addToStringBuffer b x
build b xs
dumpCases : {auto c : Ref Ctxt Defs} ->
String -> List Name ->
Core ()
dumpCases fn cns
= do defs <- get Ctxt
cstrs <- traverse (dumpCase defs) cns
Right () <- coreLift $ writeFile fn (fastAppend cstrs)
| Left err => throw (FileErr fn err)
pure ()
where
dumpCase : Defs -> Name -> Core String
dumpCase defs n
= case !(lookupCtxtExact n (gamma defs)) of
Nothing => pure ""
Just d =>
case compexpr d of
Nothing => pure ""
Just def => pure (show n ++ " = " ++ show def ++ "\n")
-- Find all the names which need compiling, from a given expression, and compile -- Find all the names which need compiling, from a given expression, and compile
-- them to CExp form (and update that in the Defs) -- them to CExp form (and update that in the Defs)
export export
findUsedNames : {auto c : Ref Ctxt Defs} -> Term vars -> findUsedNames : {auto c : Ref Ctxt Defs} ->
Core (List Name, NameTags) Term vars -> Core (List Name, NameTags)
findUsedNames tm findUsedNames tm
= do defs <- get Ctxt = do defs <- get Ctxt
sopts <- getSession
let ns = getRefs (Resolved (-1)) tm let ns = getRefs (Resolved (-1)) tm
natHackNames' <- traverse toResolvedNames natHackNames natHackNames' <- traverse toResolvedNames natHackNames
-- make an array of Bools to hold which names we've found (quicker -- make an array of Bools to hold which names we've found (quicker
@ -116,6 +150,10 @@ findUsedNames tm
logTime ("Compile defs " ++ show (length cns) ++ "/" ++ show asize) $ logTime ("Compile defs " ++ show (length cns) ++ "/" ++ show asize) $
traverse_ (compileDef tycontags) cns traverse_ (compileDef tycontags) cns
logTime "Inline" $ traverse_ inlineDef cns logTime "Inline" $ traverse_ inlineDef cns
maybe (pure ())
(\f => do coreLift $ putStrLn $ "Dumping case trees to " ++ f
dumpCases f cns)
(dumpcases sopts)
pure (cns, tycontags) pure (cns, tycontags)
where where
primTags : Int -> NameTags -> List Constant -> NameTags primTags : Int -> NameTags -> List Constant -> NameTags
@ -212,17 +250,3 @@ copyLib (lib, fullname)
Right _ <- coreLift $ writeToFile lib bin Right _ <- coreLift $ writeToFile lib bin
| Left err => throw (FileErr lib err) | Left err => throw (FileErr lib err)
pure () pure ()
export
fastAppend : List String -> String
fastAppend xs
= let len = cast (foldr (+) 0 (map length xs)) in
unsafePerformIO $
do b <- newStringBuffer (len+1)
build b xs
getStringFromBuffer b
where
build : StringBuffer -> List String -> IO ()
build b [] = pure ()
build b (x :: xs) = do addToStringBuffer b x
build b xs

View File

@ -98,6 +98,7 @@ record Session where
logLevel : Nat logLevel : Nat
logTimings : Bool logTimings : Bool
debugElabCheck : Bool -- do conversion check to verify results of elaborator debugElabCheck : Bool -- do conversion check to verify results of elaborator
dumpcases : Maybe String -- file to output compiled case trees
public export public export
record PPrinter where record PPrinter where
@ -142,7 +143,7 @@ defaultPPrint : PPrinter
defaultPPrint = MkPPOpts False True False defaultPPrint = MkPPOpts False True False
defaultSession : Session defaultSession : Session
defaultSession = MkSessionOpts False False False Chez 0 False False defaultSession = MkSessionOpts False False False Chez 0 False False Nothing
defaultElab : ElabDirectives defaultElab : ElabDirectives
defaultElab = MkElabDirectives True True PartialOK 3 defaultElab = MkElabDirectives True True PartialOK 3

View File

@ -69,6 +69,8 @@ data CLOpt
Yaffle String | Yaffle String |
||| Dump metadata from a .ttm file ||| Dump metadata from a .ttm file
Metadata String | Metadata String |
||| Dump cases before compiling
DumpCases String |
||| Run a REPL command then exit immediately ||| Run a REPL command then exit immediately
RunREPL String | RunREPL String |
FindIPKG | FindIPKG |
@ -143,6 +145,8 @@ options = [MkOpt ["--check", "-c"] [] [CheckOnly]
Nothing, -- run ttimp REPL rather than full Idris Nothing, -- run ttimp REPL rather than full Idris
MkOpt ["--ttm" ] ["ttimp file"] (\f => [Metadata f]) MkOpt ["--ttm" ] ["ttimp file"] (\f => [Metadata f])
Nothing, -- dump metadata information from the given ttm file Nothing, -- dump metadata information from the given ttm file
MkOpt ["--dumpcases"] ["output file"] (\f => [DumpCases f])
Nothing, -- dump case trees to the given file
MkOpt ["--debug-elab-check"] [] [DebugElabCheck] MkOpt ["--debug-elab-check"] [] [DebugElabCheck]
Nothing -- do more elaborator checks (currently conversion in LinearCheck) Nothing -- do more elaborator checks (currently conversion in LinearCheck)
] ]

View File

@ -86,6 +86,9 @@ preOptions (RunREPL _ :: opts)
preOptions (FindIPKG :: opts) preOptions (FindIPKG :: opts)
= do setSession (record { findipkg = True } !getSession) = do setSession (record { findipkg = True } !getSession)
preOptions opts preOptions opts
preOptions (DumpCases f :: opts)
= do setSession (record { dumpcases = Just f } !getSession)
preOptions opts
preOptions (_ :: opts) = preOptions opts preOptions (_ :: opts) = preOptions opts
-- Options to be processed after type checking. Returns whether execution -- Options to be processed after type checking. Returns whether execution