Skip to content

Commit 7f32798

Browse files
Merge pull request #3519 from dotty-staging/dotp-tasty
Add -print-tasty setting
2 parents c48f7b0 + 07720f1 commit 7f32798

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ScalaSettings extends Settings.SettingGroup {
4343
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
4444
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
4545
val fromTasty = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")
46+
val printTasty = BooleanSetting("-print-tasty", "Prints the raw tasty when decompiling.")
4647

4748
/** -X "Advanced" settings
4849
*/

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
2929
def printContents(): Unit = {
3030
println("Names:")
3131
printNames()
32+
println()
3233
println("Trees:")
3334
unpickle(new TreeSectionUnpickler)
3435
unpickle(new PositionSectionUnpickler)
@@ -111,7 +112,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
111112
val positions = new PositionUnpickler(reader).positions
112113
println(s" position bytes:")
113114
val sorted = positions.toSeq.sortBy(_._1.index)
114-
for ((addr, pos) <- sorted) println(s"${addr.index}: ${offsetToInt(pos.start)} .. ${pos.end}")
115+
for ((addr, pos) <- sorted) println(s" ${addr.index}: ${offsetToInt(pos.start)} .. ${pos.end}")
115116
}
116117
}
117118
}

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package decompiler
33

44
import dotty.tools.dotc.core.Contexts._
55
import dotty.tools.dotc.core.Phases.Phase
6+
import dotty.tools.dotc.core.tasty.TastyPrinter
67

78
/** Phase that prints the trees in all loaded compilation units.
89
*
@@ -26,5 +27,10 @@ class DecompilationPrinter extends Phase {
2627

2728
println(unit.tpdTree.show)
2829
println(line)
30+
31+
if (ctx.settings.printTasty.value) {
32+
new TastyPrinter(unit.pickled.head._2).printContents()
33+
println(line)
34+
}
2935
}
3036
}

0 commit comments

Comments
 (0)