Skip to content
Snippets Groups Projects
Commit dc91b649 authored by Emmanouil (Manos) Koukoutos's avatar Emmanouil (Manos) Koukoutos
Browse files

File output, and noop option to do only that

parent 45b38fcb
Branches
Tags
No related merge requests found
...@@ -10,6 +10,7 @@ object Main { ...@@ -10,6 +10,7 @@ object Main {
List( List(
frontends.scalac.ExtractionPhase, frontends.scalac.ExtractionPhase,
utils.TypingPhase, utils.TypingPhase,
FileOutputPhase,
xlang.ArrayTransformation, xlang.ArrayTransformation,
xlang.EpsilonElimination, xlang.EpsilonElimination,
xlang.ImperativeCodeElimination, xlang.ImperativeCodeElimination,
...@@ -32,6 +33,7 @@ object Main { ...@@ -32,6 +33,7 @@ object Main {
LeonFlagOptionDef ("xlang", "--xlang", "Support for extra program constructs (imperative,...)"), LeonFlagOptionDef ("xlang", "--xlang", "Support for extra program constructs (imperative,...)"),
LeonFlagOptionDef ("library", "--library", "Inject Leon standard library"), LeonFlagOptionDef ("library", "--library", "Inject Leon standard library"),
LeonValueOptionDef("debug", "--debug=<sections..>", "Enables specific messages"), LeonValueOptionDef("debug", "--debug=<sections..>", "Enables specific messages"),
LeonFlagOptionDef ("noop", "--noop", "No operation performed, just output program"),
LeonFlagOptionDef ("help", "--help", "Show help") LeonFlagOptionDef ("help", "--help", "Show help")
) )
...@@ -156,6 +158,8 @@ object Main { ...@@ -156,6 +158,8 @@ object Main {
} }
} }
settings = settings.copy(debugSections = debugSections.toSet) settings = settings.copy(debugSections = debugSections.toSet)
case LeonFlagOption("noop", true) =>
settings = settings.copy(verify = false)
case LeonFlagOption("help", true) => case LeonFlagOption("help", true) =>
displayHelp(initReporter) displayHelp(initReporter)
case _ => case _ =>
...@@ -207,7 +211,7 @@ object Main { ...@@ -207,7 +211,7 @@ object Main {
} else if (settings.verify) { } else if (settings.verify) {
AnalysisPhase AnalysisPhase
} else { } else {
NoopPhase() utils.FileOutputPhase
} }
} }
......
...@@ -58,6 +58,15 @@ object Definitions { ...@@ -58,6 +58,15 @@ object Definitions {
case d => d case d => d
}))) })))
} }
def writeScalaFile(filename: String) {
import java.io.FileWriter
import java.io.BufferedWriter
val fstream = new FileWriter(filename)
val out = new BufferedWriter(fstream)
out.write(ScalaPrinter(this))
out.close
}
} }
object Program { object Program {
......
package leon.utils
import leon._
import purescala.Definitions.Program
import java.io.File
object FileOutputPhase extends UnitPhase[Program] {
val name = "File output"
val description = "Output parsed/generated program into a file (default: memo.out.scala)"
override val definedOptions : Set[LeonOptionDef] = Set(
LeonValueOptionDef("o", "--o=<file>", "Output file")
)
def apply(ctx:LeonContext, p : Program) {
// Get the output file name from command line, or use default
val outputFile = ( for (LeonValueOption("o", file) <- ctx.options) yield file ).lastOption.getOrElse("memo.out.scala")
try {
p.writeScalaFile(outputFile)
} catch {
case _ : java.io.IOException => ctx.reporter.fatalError("Could not write on " + outputFile)
}
ctx.reporter.info("Output written on " + outputFile)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment