Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple files in DefaultMode #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/main/scala/gvc/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ case class Config(
onlyCompile: Boolean = false,
onlyBenchmark: Boolean = false,
onlyErrors: Boolean = false,
sourceFile: Option[String] = None,
sourceFiles: List[String] = List.empty,
linkedLibraries: List[String] = List.empty,
includeDirectories: List[String] = List.empty,
versionString: Option[String] = None,
Expand All @@ -52,15 +52,25 @@ case class Config(
Some("Cannot combine --output and --only-verify")
else if (exec && onlyVerify)
Some("Cannot combine --exec and --only-verify")
else if (sourceFile.isEmpty && (mode == DefaultMode || mode == Describe || mode == CaseStudyMode))
else if (sourceFiles.isEmpty && (mode == DefaultMode || mode == Describe || mode == CaseStudyMode))
Some("No source file specified")
else if (sourceFile.nonEmpty && !Files.exists(Paths.get(sourceFile.get)))
Some(s"Source file '${sourceFile.get}' does not exist")
else if (sourceFiles.nonEmpty)
sourceFiles.collectFirst {
case sourceFile if !Files.exists(Paths.get(sourceFile)) =>
s"Source file '${sourceFile}' does not exist"
}
else if (versionString.nonEmpty && versionString.get.trim.isEmpty) {
Some(s"Invalid version string.")
} else None
).foreach(Config.error)
}

def getSingleSourceFile(): String = {
if (sourceFiles.size > 1) {
Config.error("Cannot specify multiple input files")
}
sourceFiles.head
}
}

object Config {
Expand Down Expand Up @@ -359,14 +369,10 @@ object Config {
case other :: _ if other.startsWith("-") =>
error(s"Unrecognized command line argument: $other")
case sourceFile :: tail =>
current.sourceFile match {
case Some(_) => error("Cannot specify multiple input files")
case None =>
fromCommandLineArgs(
tail,
current.copy(sourceFile = Some(sourceFile))
)
}
fromCommandLineArgs(
tail,
current.copy(sourceFiles = sourceFile :: current.sourceFiles)
)
case Nil => current
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/gvc/benchmarking/BenchmarkExternalConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ object BenchmarkExternalConfig {
p.getName.endsWith(".c0")
})
.map(_.toPath)
val fileCollection = rootConfig.sourceFile match {
case Some(value) => c0SourceFiles ++ List(Paths.get(value))
case None => c0SourceFiles
val fileCollection = rootConfig.sourceFiles match {
case List(value) => c0SourceFiles ++ List(Paths.get(value))
case List() => c0SourceFiles
case _ => Config.error("Cannot specify multiple input files")
}

val outputDir = benchmarkRoot \ "output-dir"
Expand Down
32 changes: 16 additions & 16 deletions src/main/scala/gvc/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ object Main extends App {
BenchmarkMonitor.monitor(benchConfig)
case Config.DynamicVerification | Config.FramingVerification =>
Output.printTiming(() => {
val fileNames = getOutputCollection(config.sourceFile.get)
val inputSource = readFile(config.sourceFile.get)
val fileNames = getOutputCollection(config.getSingleSourceFile())
val inputSource = readFile(config.getSingleSourceFile())
val onlyFraming = config.mode == Config.FramingVerification
val ir = generateIR(inputSource, linkedLibraries)
BaselineChecker.check(ir, onlyFraming)
Expand Down Expand Up @@ -159,38 +159,40 @@ object Main extends App {
BenchmarkExternalConfig.parsePopulator(config)
BenchmarkPopulator.populate(benchConfig, linkedLibraries)
case Config.Describe =>
val inputSource = readFile(config.sourceFile.get)
val inputSource = readFile(config.getSingleSourceFile())
val sourceIR = Main.generateIR(inputSource, linkedLibraries)
val visitor = new LabelVisitor()
val labelOutput = visitor.visit(sourceIR)
visitor.printCounts(labelOutput.labels)
case Config.DefaultMode =>
val fileNames = getOutputCollection(config.sourceFile.get)
val inputSource = readFile(config.sourceFile.get)
Output.printTiming(() => {
val verifiedOutput = verify(inputSource, fileNames, cmdConfig)
execute(verifiedOutput.c0Source, fileNames)
})
for (sourceFile <- config.sourceFiles.reverse) {
val fileNames = getOutputCollection(sourceFile)
val inputSource = readFile(sourceFile)
Output.printTiming(() => {
val verifiedOutput = verify(inputSource, fileNames, cmdConfig)
execute(verifiedOutput.c0Source, fileNames)
})
}
case Config.CaseStudyMode => {
val fileNames = getOutputCollection(config.sourceFile.get)
val inputSource = readFile(config.sourceFile.get)
val fileNames = getOutputCollection(config.getSingleSourceFile())
val inputSource = readFile(config.getSingleSourceFile())
val caseName = fileNames.baseName.split("/").last

// create new dir for collected data and files
val localTime = java.time.LocalDateTime.now()
val outputDir = Paths.get("").toAbsolutePath.toString + "/" + caseName + "-" + localTime + "/"
val newSourceFile = outputDir + config.sourceFile.get.split("/").last
val newSourceFile = outputDir + config.getSingleSourceFile().split("/").last
val fileNames2 = getOutputCollection(newSourceFile)

val caseConfig = new Config(
mode = Config.CaseStudyMode,
saveFiles = true,
exec = true,
sourceFile = config.sourceFile,
sourceFiles = config.sourceFiles,
linkedLibraries = config.linkedLibraries,
includeDirectories = config.includeDirectories,
)
println(Output.purple("Verifying '" + config.sourceFile.get + "' and gathering data."))
println(Output.purple("Verifying '" + config.getSingleSourceFile() + "' and gathering data."))
println(Output.purple("Outputting collected data to " + outputDir))
writeDir(outputDir)
writeFile(newSourceFile, inputSource)
Expand Down Expand Up @@ -464,8 +466,6 @@ object Main extends App {
if (cmdConfig.exec) {
val outputCommand = Paths.get(outputExe).toAbsolutePath.toString
sys.exit(Seq(outputCommand) !)
} else {
sys.exit(0)
}
}
}
Expand Down