Permalink
Browse files

GenASM activated via -target:jvm-1.6 or -target:jvm-1.5-asm

  • Loading branch information...
magarciaEPFL committed May 8, 2012
1 parent f994343 commit 454c2a0c775c92be7f2a741bb6ab17b55f1eddb1
@@ -76,13 +76,34 @@ trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable =>
*/
case class ScalaSigBytes(bytes: Array[Byte]) extends ClassfileAnnotArg {
override def toString = (bytes map { byte => (byte & 0xff).toHexString }).mkString("[ ", " ", " ]")
lazy val encodedBytes = ByteCodecs.encode(bytes)
def isLong: Boolean = (encodedBytes.length > 65535)
lazy val encodedBytes = ByteCodecs.encode(bytes) // TODO remove after migration to ASM-based GenJVM complete
def isLong: Boolean = (encodedBytes.length > 65535) // TODO remove after migration to ASM-based GenJVM complete
lazy val sevenBitsMayBeZero: Array[Byte] = {
mapToNextModSevenBits(scala.reflect.internal.pickling.ByteCodecs.encode8to7(bytes))
}
def fitsInOneString: Boolean = {
val numZeros = (sevenBitsMayBeZero count { b => b == 0 })
val res = (sevenBitsMayBeZero.length + numZeros) <= 65535
assert(this.isLong == !res, "As things stand, can't just swap in `fitsInOneString()` for `isLong()`")
res
}
def sigAnnot: Type =
if (this.isLong)
definitions.ScalaLongSignatureAnnotation.tpe
else
definitions.ScalaSignatureAnnotation.tpe
private def mapToNextModSevenBits(src: Array[Byte]): Array[Byte] = {
var i = 0
val srclen = src.length
while (i < srclen) {
val in = src(i)
src(i) = (if (in == 0x7f) 0.toByte else (in + 1).toByte)
i += 1
}
src
}
}
/** Represents a nested classfile annotation */
@@ -1153,7 +1153,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
*/
private def getModuleOrClass(path: Name): Symbol = getModuleOrClass(path, path.length)
private def getClassByName(fullname: Name): Symbol = {
def getClassByName(fullname: Name): Symbol = {
var result = getModuleOrClass(fullname.toTypeName)
while (result.isAliasType) result = result.info.typeSymbol
result
@@ -25,7 +25,7 @@ import typechecker._
import transform._
import backend.icode.{ ICodes, GenICode, ICodeCheckers }
import backend.{ ScalaPrimitives, Platform, MSILPlatform, JavaPlatform }
import backend.jvm.GenJVM
import backend.jvm.{GenJVM, GenASM}
import backend.opt.{ Inliners, InlineExceptionHandlers, ClosureElimination, DeadCodeElimination }
import backend.icode.analysis._
import language.postfixOps
@@ -617,13 +617,20 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
val runsRightAfter = None
} with DeadCodeElimination
// phaseName = "jvm"
// phaseName = "jvm", FJBG-based version
object genJVM extends {
val global: Global.this.type = Global.this
val runsAfter = List("dce")
val runsRightAfter = None
} with GenJVM
// phaseName = "jvm", ASM-based version
object genASM extends {
val global: Global.this.type = Global.this
val runsAfter = List("dce")
val runsRightAfter = None
} with GenASM
// This phase is optional: only added if settings.make option is given.
// phaseName = "dependencyAnalysis"
object dependencyAnalysis extends {
@@ -33,9 +33,13 @@ trait JavaPlatform extends Platform {
if (settings.make.isDefault) Nil
else List(dependencyAnalysis)
private def classEmitPhase =
if (settings.target.value == "jvm-1.5") genJVM
else genASM
def platformPhases = List(
flatten, // get rid of inner classes
genJVM // generate .class files
flatten, // get rid of inner classes
classEmitPhase // generate .class files
) ++ depAnalysisPhase
lazy val externalEquals = getDecl(BoxesRunTimeClass, nme.equals_)
@@ -435,6 +435,8 @@ trait Opcodes { self: ICodes =>
override def consumed = 1
override def produced = 0
def flatTagsCount: Int = { var acc = 0; var rest = tags; while(rest.nonEmpty) { acc += rest.head.length; rest = rest.tail }; acc } // a one-liner
}
/** This class represents a JUMP instruction
@@ -127,42 +127,61 @@ trait Primitives { self: ICodes =>
/** Returns a string representation of this operation. */
override def toString(): String
/** used only from GenASM */
def opcodeIF(): Int
/** used only from GenASM */
def opcodeIFICMP(): Int
}
/** An equality test */
case object EQ extends TestOp {
def negate() = NE
override def toString() = "EQ"
override def opcodeIF() = scala.tools.asm.Opcodes.IFEQ
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPEQ
}
/** A non-equality test */
case object NE extends TestOp {
def negate() = EQ
override def toString() = "NE"
override def opcodeIF() = scala.tools.asm.Opcodes.IFNE
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPNE
}
/** A less-than test */
case object LT extends TestOp {
def negate() = GE
override def toString() = "LT"
override def opcodeIF() = scala.tools.asm.Opcodes.IFLT
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPLT
}
/** A greater-than-or-equal test */
case object GE extends TestOp {
def negate() = LT
override def toString() = "GE"
override def opcodeIF() = scala.tools.asm.Opcodes.IFGE
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPGE
}
/** A less-than-or-equal test */
case object LE extends TestOp {
def negate() = GT
override def toString() = "LE"
override def opcodeIF() = scala.tools.asm.Opcodes.IFLE
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPLE
}
/** A greater-than test */
case object GT extends TestOp {
def negate() = LE
override def toString() = "GT"
override def opcodeIF() = scala.tools.asm.Opcodes.IFGT
override def opcodeIFICMP() = scala.tools.asm.Opcodes.IF_ICMPGT
}
/** This class represents an arithmetic operation. */
Oops, something went wrong.

0 comments on commit 454c2a0

Please sign in to comment.