{
string first_source;
- bool timestamps;
internal int fatal_errors;
- //
- // Last time we took the time
- //
- Stopwatch stopwatch;
- DateTime first_time;
-
internal readonly CompilerContext ctx;
static readonly char[] argument_value_separator = new char [] { ';', ',' };
Report Report {
get { return ctx.Report; }
}
-
- void ShowTime (string msg)
- {
- if (!timestamps)
- return;
-
- stopwatch.Stop ();
-
- Console.WriteLine ("{0,5}ms {1}", stopwatch.ElapsedMilliseconds, msg);
-
- stopwatch = Stopwatch.StartNew ();
- }
-
- void ShowTotalTime (string msg)
- {
- if (!timestamps)
- return;
-
- DateTime now = DateTime.Now;
- TimeSpan span = now - first_time;
-
- Console.WriteLine (
- "[{0:00}:{1:000}] {2}",
- (int) span.TotalSeconds, span.Milliseconds, msg);
- }
-
+
void tokenize_file (CompilationUnit file, CompilerContext ctx)
{
Stream input;
return true;
case "--timestamp":
- timestamps = true;
+ RootContext.Timestamps = true;
return true;
case "--debug": case "-g":
//
public bool Compile ()
{
+ TimeReporter tr = new TimeReporter (RootContext.Timestamps);
+ ctx.TimeReporter = tr;
+ tr.StartTotal ();
+
var module = new ModuleContainer (ctx);
RootContext.ToplevelTypes = module;
- if (timestamps) {
- stopwatch = Stopwatch.StartNew ();
- first_time = DateTime.Now;
- }
-
+ tr.Start (TimeReporter.TimerType.ParseTotal);
Parse (module);
- ShowTime ("Parsing source files");
+ tr.Stop (TimeReporter.TimerType.ParseTotal);
if (Report.Errors > 0)
return false;
output_file_name = Path.GetFileName (output_file);
}
- //
- // Load assemblies required
- //
- if (timestamps)
- stopwatch = Stopwatch.StartNew ();
-
#if STATIC
var importer = new StaticImporter ();
var references_loader = new StaticLoader (importer, ctx);
+ tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
assembly.Create (references_loader.Domain);
+ tr.Stop (TimeReporter.TimerType.AssemblyBuilderSetup);
// Create compiler types first even before any referenced
// assembly is loaded to allow forward referenced types from
// loaded assembly into compiled builder to be resolved
// correctly
+ tr.Start (TimeReporter.TimerType.CreateTypeTotal);
module.CreateType ();
- ShowTime ("Creating compiled types");
-
importer.AddCompiledAssembly (assembly);
+ tr.Stop (TimeReporter.TimerType.CreateTypeTotal);
+
references_loader.LoadReferences (module);
- ShowTime ("Imporing referenced assemblies");
+ tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
- ShowTime ("Initializing predefined types");
+ tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);
references_loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
- ShowTime ("Imporing referenced assemblies");
-
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
- ShowTime ("Initializing predefined types");
-
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
return false;
+ module.CreateType ();
+
loader.LoadModules (assembly, module.GlobalRootNamespace);
#endif
+ tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
module.Define ();
-
- ShowTime ("Types definition");
+ tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);
if (Report.Errors > 0)
return false;
- if (Report.Errors == 0 &&
- RootContext.Documentation != null &&
+ if (RootContext.Documentation != null &&
!RootContext.Documentation.OutputDocComment (
output_file, Report))
return false;
//
// Verify using aliases now
//
+ tr.Start (TimeReporter.TimerType.UsingVerification);
NamespaceEntry.VerifyAllUsing ();
+ tr.Stop (TimeReporter.TimerType.UsingVerification);
if (Report.Errors > 0){
return false;
if (Report.Errors > 0)
return false;
-
- //
- // The code generator
- //
- if (timestamps)
- stopwatch = Stopwatch.StartNew ();
- assembly.Emit ();
- ShowTime ("Resolving and emitting members blocks");
+ tr.Start (TimeReporter.TimerType.EmitTotal);
+ assembly.Emit ();
+ tr.Stop (TimeReporter.TimerType.EmitTotal);
if (Report.Errors > 0){
return false;
}
+ tr.Start (TimeReporter.TimerType.CloseTypes);
module.CloseType ();
+ tr.Stop (TimeReporter.TimerType.CloseTypes);
- ShowTime ("Closing types");
-
- if (timestamps)
- stopwatch = Stopwatch.StartNew ();
-
+ tr.Start (TimeReporter.TimerType.Resouces);
assembly.EmbedResources ();
- ShowTime ("Embedding resources");
+ tr.Stop (TimeReporter.TimerType.Resouces);
if (Report.Errors > 0)
return false;
- if (timestamps)
- stopwatch = Stopwatch.StartNew ();
-
assembly.Save ();
#if STATIC
references_loader.Dispose ();
#endif
-
- ShowTime ("Saving output assembly");
-
- ShowTotalTime ("Total");
-
- Timer.ShowTimers ();
+ tr.StopTotal ();
+ tr.ShowStats ();
return (Report.Errors == 0);
}