-
Notifications
You must be signed in to change notification settings - Fork 1.1k
rewiring-dependencies on settings in the bytecode emitter #19
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
303d69f
accessing settings
magarciaEPFL 64c62ef
some BytecodeWriter need a Context, except ClassBytecodeWriter
magarciaEPFL cefc22f
address feedback: ctx.settings
magarciaEPFL e559fe5
address feedback: BytecodeWriter extends HasContext
magarciaEPFL 698c51c
context for ClassBytecodeWriter
lrytz 8374903
Merge pull request #1 from lrytz/backendWip
magarciaEPFL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, | |
import java.util.jar.Attributes.Name | ||
|
||
import dotty.tools.io._ | ||
import core.Contexts.Context | ||
|
||
/** Can't output a file due to the state of the file system. */ | ||
class FileConflictException(msg: String, val file: AbstractFile) extends IOException(msg) | ||
|
@@ -22,8 +23,8 @@ class FileConflictException(msg: String, val file: AbstractFile) extends IOExcep | |
*/ | ||
trait BytecodeWriters { | ||
|
||
def outputDirectory(sym: Symbol): AbstractFile = | ||
settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile) | ||
def outputDirectory(sym: Symbol)(implicit ctx: Context): AbstractFile = | ||
ctx.base.settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile) | ||
|
||
/** | ||
* @param clsName cls.getName | ||
|
@@ -40,14 +41,14 @@ trait BytecodeWriters { | |
def getFile(sym: Symbol, clsName: String, suffix: String): AbstractFile = | ||
getFile(outputDirectory(sym), clsName, suffix) | ||
|
||
def factoryNonJarBytecodeWriter(): BytecodeWriter = { | ||
val emitAsmp = settings.Ygenasmp.isSetByUser | ||
val doDump = settings.Ydumpclasses.isSetByUser | ||
def factoryNonJarBytecodeWriter(implicit ctx0: Context): BytecodeWriter = { | ||
val emitAsmp = ctx0.base.settings.Ygenasmp.isSetByUser | ||
val doDump = ctx0.base.settings.Ydumpclasses.isSetByUser | ||
(emitAsmp, doDump) match { | ||
case (false, false) => new ClassBytecodeWriter { } | ||
case (false, true ) => new ClassBytecodeWriter with DumpBytecodeWriter { } | ||
case (true, false) => new ClassBytecodeWriter with AsmpBytecodeWriter | ||
case (true, true ) => new ClassBytecodeWriter with AsmpBytecodeWriter with DumpBytecodeWriter { } | ||
case (false, true ) => new ClassBytecodeWriter with DumpBytecodeWriter { val ctx = ctx0 } | ||
case (true, false) => new ClassBytecodeWriter with AsmpBytecodeWriter { val ctx = ctx0 } | ||
case (true, true ) => new ClassBytecodeWriter with AsmpBytecodeWriter with DumpBytecodeWriter { val ctx = ctx0 } | ||
} | ||
} | ||
|
||
|
@@ -56,10 +57,12 @@ trait BytecodeWriters { | |
def close(): Unit = () | ||
} | ||
|
||
class DirectToJarfileWriter(jfile: JFile) extends BytecodeWriter { | ||
class DirectToJarfileWriter(jfile: JFile)(implicit protected val ctx: Context) | ||
extends BytecodeWriter | ||
with HasContext { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about changing |
||
val jarMainAttrs = ( | ||
if (settings.mainClass.isDefault) Nil | ||
else List(Name.MAIN_CLASS -> settings.mainClass.value) | ||
if (ctx.base.settings.mainClass.isDefault) Nil | ||
else List(Name.MAIN_CLASS -> ctx.base.settings.mainClass.value) | ||
) | ||
val writer = new Jar(jfile).jarWriter(jarMainAttrs: _*) | ||
|
||
|
@@ -85,10 +88,10 @@ trait BytecodeWriters { | |
* their expansion by ASM is more readable. | ||
* | ||
* */ | ||
trait AsmpBytecodeWriter extends BytecodeWriter { | ||
trait AsmpBytecodeWriter extends BytecodeWriter with HasContext { | ||
import dotty.tools.asm | ||
|
||
private val baseDir = Directory(settings.Ygenasmp.value).createDirectory() | ||
private val baseDir = Directory(ctx.base.settings.Ygenasmp.value).createDirectory() | ||
|
||
private def emitAsmp(jclassBytes: Array[Byte], asmpFile: io.File): Unit = { | ||
val pw = asmpFile.printWriter() | ||
|
@@ -126,8 +129,8 @@ trait BytecodeWriters { | |
} | ||
} | ||
|
||
trait DumpBytecodeWriter extends BytecodeWriter { | ||
val baseDir = Directory(settings.Ydumpclasses.value).createDirectory() | ||
trait DumpBytecodeWriter extends BytecodeWriter with HasContext { | ||
val baseDir = Directory(ctx.base.settings.Ydumpclasses.value).createDirectory() | ||
|
||
abstract override def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit = { | ||
super.writeClass(label, jclassName, jclassBytes, outfile) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* NSC -- new Scala compiler | ||
* Copyright 2005-2012 LAMP/EPFL | ||
* @author Martin Odersky | ||
*/ | ||
|
||
package dotty.tools.dotc | ||
package backend.jvm | ||
|
||
import core.Contexts.Context | ||
|
||
/** | ||
* All components (e.g. BCPickles, BCInnerClassGen) of the builder classes | ||
* extend this trait to have access to the context. | ||
* | ||
* The context is provided by the three leaf classes (PlainClassBuilder, | ||
* JMirrorBuilder and JBeanInfoBuilder) as class parameter. | ||
* | ||
* Same goes for BytecodeWriter | ||
*/ | ||
trait HasContext { | ||
implicit protected val ctx: Context | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.base
should not be necessary, there's animplicit def toBase(ctx: Context): ContextBase
in the companion objectContext