summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd/gen/Codegen.scala
blob: c3aa527ef2abca62faa98c0e991f6a29423bd9cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* NEST (New Scala Test)
 * Copyright 2007-2013 LAMP/EPFL
 * @author  Paul Phillips
 */

package scala.tools.cmd
package gen

class Codegen(args: List[String]) extends {
  val parsed = CodegenSpec(args: _*)
} with CodegenSpec with Instance

object Codegen {
  def echo(msg: String) = Console println msg

  def main(args0: Array[String]): Unit = {
    val runner = new Codegen(args0.toList)
    import runner._

    if (args0.isEmpty)
      return println (CodegenSpec.helpMsg)

    val out = outDir getOrElse { return println("--out is required.") }
    val all = genall || !anyvals

    echo("Generating sources into " + out)

    if (anyvals || all) {
      val av = new AnyVals { }

      av.make() foreach { case (name, code ) =>
        val file = (out / (name + ".scala")).toFile
        echo("Writing: " + file)
        file writeAll code
      }
    }
  }
}