Skip to content

Commit

Permalink
Merge pull request #315 from Duhemm/wip/empty-pass
Browse files Browse the repository at this point in the history
Add EmptyPass, options in Ctx
  • Loading branch information
densh committed Oct 5, 2016
2 parents 27a5d37 + b7dd94f commit 2cc7638
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
19 changes: 9 additions & 10 deletions tools/src/main/scala/scala/scalanative/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ final class Compiler(opts: Opts) {
Global.Member(Global.Top(opts.entry), "main_class.ssnr.ObjectArray_unit")

private lazy val passCompanions: Seq[PassCompanion] = Seq(
Seq(
pass.LocalBoxingElimination,
pass.DeadCodeElimination
),
maybeInjectMain,
Seq(pass.ExternHoisting,
Seq(pass.LocalBoxingElimination,
pass.DeadCodeElimination,
pass.MainInjection,
pass.ExternHoisting,
pass.ModuleLowering,
pass.RuntimeTypeInfoInjection,
pass.AsLowering,
Expand All @@ -34,9 +32,6 @@ final class Compiler(opts: Opts) {
pass.StackallocHoisting,
pass.CopyPropagation)).flatten

private def maybeInjectMain: Seq[PassCompanion] =
if (!opts.sharedLibrary) Seq(pass.MainInjection) else Seq.empty

private lazy val (links, assembly): (Seq[Attr.Link], Seq[Defn]) = {
val deps = passCompanions.flatMap(_.depends).distinct
val injects = passCompanions.flatMap(_.injects).distinct
Expand All @@ -49,7 +44,8 @@ final class Compiler(opts: Opts) {
private lazy val passes = {
val ctx = Ctx(fresh = Fresh("tx"),
entry = entry,
top = analysis.ClassHierarchy(assembly))
top = analysis.ClassHierarchy(assembly),
options = opts)

passCompanions.map(_.apply(ctx))
}
Expand All @@ -73,6 +69,9 @@ final class Compiler(opts: Opts) {
case Seq() =>
assembly

case (pass.EmptyPass, _) +: rest =>
loop(assembly, rest)

case (pass, id) +: rest =>
val nassembly = pass(assembly)
val n = id + 1
Expand Down
3 changes: 2 additions & 1 deletion tools/src/main/scala/scala/scalanative/compiler/Ctx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package compiler
/** Context that pass companion can uses to instantiate passes. */
final case class Ctx(fresh: nir.Fresh,
entry: nir.Global,
top: analysis.ClassHierarchy.Top)
top: analysis.ClassHierarchy.Top,
options: Opts)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scala.scalanative
package compiler
package pass

/**
* A pass that does nothing.
*/
object EmptyPass extends Pass
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class MainInjection(entry: Global)(implicit fresh: Fresh) extends Pass {
}

object MainInjection extends PassCompanion {
def apply(ctx: Ctx) = new MainInjection(ctx.entry)(ctx.fresh)
def apply(ctx: Ctx) =
if (!ctx.options.sharedLibrary) new MainInjection(ctx.entry)(ctx.fresh)
else EmptyPass

val ObjectArray =
Type.Class(Global.Top("scala.scalanative.runtime.ObjectArray"))
Expand Down

0 comments on commit 2cc7638

Please sign in to comment.