From 02fc5cc91fd10732873b21df57f536ae1e9eb628 Mon Sep 17 00:00:00 2001 From: "fabiomfv@google.com" Date: Wed, 5 Oct 2011 20:40:38 +0000 Subject: [PATCH] add debugging compiler flags: --human-readable-output : generates readable source code in optimized output. --disable-type-optimizations : disables type optimizations. Review URL: https://chromereviews.googleplex.com/3513020 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@70 260f80e4-7a28-3924-810f-c04153c831b5 --- .../google/dart/compiler/CommandLineOptions.java | 16 ++++++++++++++++ .../dart/compiler/CompilerConfiguration.java | 7 +++++++ .../compiler/DefaultCompilerConfiguration.java | 7 ++++++- .../DelegatingCompilerConfiguration.java | 6 ++++++ .../compiler/backend/js/AbstractJsBackend.java | 11 ++++++++--- .../compiler/backend/js/ClosureJsBackend.java | 13 ++++++++++++- .../testing/TestCompilerConfiguration.java | 6 ++++++ 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/compiler/java/com/google/dart/compiler/CommandLineOptions.java b/compiler/java/com/google/dart/compiler/CommandLineOptions.java index 91cc50c05ae..ea18b66652c 100644 --- a/compiler/java/com/google/dart/compiler/CommandLineOptions.java +++ b/compiler/java/com/google/dart/compiler/CommandLineOptions.java @@ -38,6 +38,10 @@ public class CommandLineOptions { usage = "do not generate output, only analyze") private boolean checkOnly = false; + @Option(name = "--disable-type-optimizations", + usage = "Debugging: disable type optimizations") + private boolean disableTypeOptimizations = false; + @Option(name = "-documentation-lib", usage = "only generate documentation for the given library") private String documentationLibrary = null; @@ -53,6 +57,10 @@ public class CommandLineOptions { usage = "classes to generate stubs for, comma-separated") private String generateIsolateStubs = null; + @Option(name = "--human-readable-output", + usage = "Debugging: generates human readable javascript output") + private boolean generateHumanReadableOutput = false; + @Option(name = "--ignore-unrecognized-flags", usage = "ignore unrecognized command line flags") private boolean ignoreUnrecognizedFlags = false; @@ -180,6 +188,14 @@ public class CommandLineOptions { return batch; } + public boolean disableTypeOptimizations() { + return disableTypeOptimizations; + } + + public boolean generateHumanReadableOutput() { + return generateHumanReadableOutput; + } + /** * Enables optimization of the generated JavaScript. */ diff --git a/compiler/java/com/google/dart/compiler/CompilerConfiguration.java b/compiler/java/com/google/dart/compiler/CompilerConfiguration.java index 7d28f2b4ded..bdc957adede 100644 --- a/compiler/java/com/google/dart/compiler/CompilerConfiguration.java +++ b/compiler/java/com/google/dart/compiler/CompilerConfiguration.java @@ -4,6 +4,7 @@ package com.google.dart.compiler; +import com.google.dart.compiler.CommandLineOptions.CompilerOptions; import com.google.dart.compiler.metrics.CompilerMetrics; import java.io.File; @@ -87,4 +88,10 @@ public interface CompilerConfiguration { * Return the system library corresponding to the specified "dart:" spec. */ LibrarySource getSystemLibraryFor(String importSpec); + + /** + * Return {@link CompilerOptions} instance. + * @return command line options passed to the compiler. + */ + CompilerOptions getCompilerOptions(); } diff --git a/compiler/java/com/google/dart/compiler/DefaultCompilerConfiguration.java b/compiler/java/com/google/dart/compiler/DefaultCompilerConfiguration.java index 8ff32c113a4..ecb305ad97a 100644 --- a/compiler/java/com/google/dart/compiler/DefaultCompilerConfiguration.java +++ b/compiler/java/com/google/dart/compiler/DefaultCompilerConfiguration.java @@ -53,7 +53,7 @@ public class DefaultCompilerConfiguration implements CompilerConfiguration { return new DartIsolateStubGenerator(compilerOptions.getIsolateStubClasses(), compilerOptions.getIsolateStubOutputFile()); } else if (compilerOptions.shouldOptimize()) { - return new ClosureJsBackend(); + return new ClosureJsBackend(compilerOptions.generateHumanReadableOutput()); } else { return new JavascriptBackend(); } @@ -205,4 +205,9 @@ public class DefaultCompilerConfiguration implements CompilerConfiguration { } return new UrlLibrarySource(systemUri, this.systemLibraryManager); } + + @Override + public CompilerOptions getCompilerOptions() { + return compilerOptions; + } } \ No newline at end of file diff --git a/compiler/java/com/google/dart/compiler/DelegatingCompilerConfiguration.java b/compiler/java/com/google/dart/compiler/DelegatingCompilerConfiguration.java index df528a90485..0768cc34ea3 100644 --- a/compiler/java/com/google/dart/compiler/DelegatingCompilerConfiguration.java +++ b/compiler/java/com/google/dart/compiler/DelegatingCompilerConfiguration.java @@ -4,6 +4,7 @@ package com.google.dart.compiler; +import com.google.dart.compiler.CommandLineOptions.CompilerOptions; import com.google.dart.compiler.metrics.CompilerMetrics; import java.io.File; @@ -100,4 +101,9 @@ public class DelegatingCompilerConfiguration implements CompilerConfiguration { public LibrarySource getSystemLibraryFor(String importSpec) { return delegate.getSystemLibraryFor(importSpec); } + + @Override + public CompilerOptions getCompilerOptions() { + return delegate.getCompilerOptions(); + } } diff --git a/compiler/java/com/google/dart/compiler/backend/js/AbstractJsBackend.java b/compiler/java/com/google/dart/compiler/backend/js/AbstractJsBackend.java index af213a9dc2e..6a7ad8e21d4 100644 --- a/compiler/java/com/google/dart/compiler/backend/js/AbstractJsBackend.java +++ b/compiler/java/com/google/dart/compiler/backend/js/AbstractJsBackend.java @@ -12,6 +12,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.Multiset; +import com.google.dart.compiler.CommandLineOptions.CompilerOptions; import com.google.dart.compiler.DartCompilerContext; import com.google.dart.compiler.DartSource; import com.google.dart.compiler.ast.DartClass; @@ -308,9 +309,13 @@ public abstract class AbstractJsBackend extends AbstractBackend { Tracer.canTrace() ? Tracer.start(DartEventType.TRANSLATE_TO_JS, "unit", unit.getSourceName()) : null; - OptimizationStrategy optimizationStrategy = shouldOptimize() ? - new BasicOptimizationStrategy(unit, typeProvider) : - new NoOptimizationStrategy(unit, typeProvider); + CompilerOptions options = context.getCompilerConfiguration().getCompilerOptions(); + OptimizationStrategy optimizationStrategy; + if (shouldOptimize() && !options.disableTypeOptimizations()) { + optimizationStrategy = new BasicOptimizationStrategy(unit, typeProvider); + } else { + optimizationStrategy = new NoOptimizationStrategy(unit, typeProvider); + } try { TraceEvent normalizeEvent = diff --git a/compiler/java/com/google/dart/compiler/backend/js/ClosureJsBackend.java b/compiler/java/com/google/dart/compiler/backend/js/ClosureJsBackend.java index 241822fda54..35681b6113f 100644 --- a/compiler/java/com/google/dart/compiler/backend/js/ClosureJsBackend.java +++ b/compiler/java/com/google/dart/compiler/backend/js/ClosureJsBackend.java @@ -66,7 +66,18 @@ public class ClosureJsBackend extends AbstractJsBackend { private long totalJsOutputCharCount; // Generate "readable" output for debugging - private boolean generateHumanReadableOutput = false; + private final boolean generateHumanReadableOutput; + + public ClosureJsBackend() { + this.generateHumanReadableOutput = false; + } + + /** + * @param generateHumanReadableOutput - generates human readable javascript output. + */ + public ClosureJsBackend(boolean generateHumanReadableOutput) { + this.generateHumanReadableOutput = generateHumanReadableOutput; + } @Override public boolean isOutOfDate(DartSource src, DartCompilerContext context) { diff --git a/compiler/java/com/google/dart/compiler/testing/TestCompilerConfiguration.java b/compiler/java/com/google/dart/compiler/testing/TestCompilerConfiguration.java index 055b452bd05..63eeee7b2ce 100644 --- a/compiler/java/com/google/dart/compiler/testing/TestCompilerConfiguration.java +++ b/compiler/java/com/google/dart/compiler/testing/TestCompilerConfiguration.java @@ -5,6 +5,7 @@ package com.google.dart.compiler.testing; import com.google.dart.compiler.Backend; +import com.google.dart.compiler.CommandLineOptions.CompilerOptions; import com.google.dart.compiler.CompilerConfiguration; import com.google.dart.compiler.DartCompilationPhase; import com.google.dart.compiler.LibrarySource; @@ -109,4 +110,9 @@ public class TestCompilerConfiguration implements CompilerConfiguration { } return new UrlLibrarySource(systemUri, this.systemLibraryManager); } + + @Override + public CompilerOptions getCompilerOptions() { + throw new AssertionError(); + } }