protected void MergeInto(Configuration result) { if (ApplyDefaults.HasValue) result.ApplyDefaults = ApplyDefaults; if (IncludeDependencies.HasValue) result.IncludeDependencies = IncludeDependencies; if (UseSymbols.HasValue) result.UseSymbols = UseSymbols; if (UseThreads.HasValue) result.UseThreads = UseThreads; if (UseDefaultProxies.HasValue) result.UseDefaultProxies = UseDefaultProxies; if (FrameworkVersion.HasValue) result.FrameworkVersion = FrameworkVersion; if (GenerateSkeletonsForStubbedAssemblies.HasValue) result.GenerateSkeletonsForStubbedAssemblies = GenerateSkeletonsForStubbedAssemblies; if (GenerateContentManifest.HasValue) result.GenerateContentManifest = GenerateContentManifest; if (RunBugChecks.HasValue) result.RunBugChecks = RunBugChecks; Assemblies.MergeInto(result.Assemblies); Optimizer.MergeInto(result.Optimizer); }
internal TranslationResult ( Configuration configuration, string assemblyPath, AssemblyManifest assemblyManifest ) { Configuration = configuration; AssemblyPath = assemblyPath; AssemblyManifest = assemblyManifest; }
public virtual void MergeInto(Configuration result) { if (ApplyDefaults.HasValue) result.ApplyDefaults = ApplyDefaults; if (IncludeDependencies.HasValue) result.IncludeDependencies = IncludeDependencies; if (UseSymbols.HasValue) result.UseSymbols = UseSymbols; if (UseThreads.HasValue) result.UseThreads = UseThreads; if (UseDefaultProxies.HasValue) result.UseDefaultProxies = UseDefaultProxies; if (FrameworkVersion.HasValue) result.FrameworkVersion = FrameworkVersion; if (GenerateSkeletonsForStubbedAssemblies.HasValue) result.GenerateSkeletonsForStubbedAssemblies = GenerateSkeletonsForStubbedAssemblies; if (GenerateContentManifest.HasValue) result.GenerateContentManifest = GenerateContentManifest; if (RunBugChecks.HasValue) result.RunBugChecks = RunBugChecks; if (FilenameEscapeRegex != null) result.FilenameEscapeRegex = FilenameEscapeRegex; if (AssemblyCollectionName != null) result.AssemblyCollectionName = AssemblyCollectionName; Assemblies.MergeInto(result.Assemblies); CodeGenerator.MergeInto(result.CodeGenerator); }
public UnsafeCodeTransforms ( Configuration configuration, TypeSystem typeSystem, MethodTypeFactory methodTypes ) { Configuration = configuration; TypeSystem = typeSystem; MethodTypes = methodTypes; }
public UnsafeCodeTransforms ( Configuration configuration, TypeSystem typeSystem, MethodTypeFactory methodTypes, IFunctionSource functionSource ) { Configuration = configuration; TypeSystem = typeSystem; MethodTypes = methodTypes; FunctionSource = functionSource; }
public void SetupFixture() { Console.WriteLine("// SimpleTestCasesForStubbedBcl.SetupFixture() {"); Func<Configuration> makeConfiguration = () => { var c = new Configuration { ApplyDefaults = false, FrameworkVersion = 4.0 }; c.Assemblies.Stubbed.Add("mscorlib,"); c.Assemblies.Stubbed.Add("^System,"); c.Assemblies.Stubbed.Add("^System\\.(.+),"); c.Assemblies.Stubbed.Add("^Microsoft\\.(.+),"); c.Assemblies.Stubbed.Add("FSharp.Core,"); c.Assemblies.Ignored.Add("Microsoft\\.VisualC,"); c.Assemblies.Ignored.Add("Accessibility,"); c.Assemblies.Ignored.Add("SMDiagnostics,"); c.Assemblies.Ignored.Add("System\\.EnterpriseServices,"); c.Assemblies.Ignored.Add("System\\.Security,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.Serialization\\.Formatters\\.Soap,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.DurableInstancing,"); c.Assemblies.Ignored.Add("System\\.Data\\.SqlXml,"); c.Assemblies.Ignored.Add("^Mono\\."); c.Assemblies.Ignored.Add("JSIL\\.Meta,"); c.Assemblies.Proxies.Add(Path.Combine(ComparisonTest.JSILFolder, "JSIL.Proxies.Bcl.dll")); return c; }; Action<AssemblyTranslator> initializeTranslator = (at) => { // Suppress stdout spew at.IgnoredMethod += (_, _2) => { }; }; RunSingleComparisonTestCase( BootstrapArguments(), makeConfiguration, new JSEvaluationConfig { ThrowOnUnimplementedExternals = false }, initializeTranslator: initializeTranslator, shouldRunJs: false, testFolderNameOverride: GetType().Name ); Console.WriteLine("// SimpleTestCasesForStubbedBcl.SetupFixture() }"); }
protected void MergeInto(Configuration result) { if (ApplyDefaults.HasValue) result.ApplyDefaults = ApplyDefaults; if (IncludeDependencies.HasValue) result.IncludeDependencies = IncludeDependencies; if (UseSymbols.HasValue) result.UseSymbols = UseSymbols; if (UseThreads.HasValue) result.UseThreads = UseThreads; if (FrameworkVersion.HasValue) result.FrameworkVersion = FrameworkVersion; Assemblies.MergeInto(result.Assemblies); Optimizer.MergeInto(result.Optimizer); }
public void ExpressionTestCasesForTranslatedBcl(object[] parameters) { Func<Configuration> makeConfiguration = () => { var c = new Configuration { ApplyDefaults = false, }; c.Assemblies.Stubbed.Add("^System,"); c.Assemblies.Stubbed.Add("^System\\.(?!Core)(.+),"); c.Assemblies.Stubbed.Add("^Microsoft\\.(.+),"); c.Assemblies.Stubbed.Add("FSharp.Core,"); c.Assemblies.Ignored.Add("Microsoft\\.VisualC,"); c.Assemblies.Ignored.Add("Accessibility,"); c.Assemblies.Ignored.Add("SMDiagnostics,"); c.Assemblies.Ignored.Add("System\\.EnterpriseServices,"); c.Assemblies.Ignored.Add("System\\.Security,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.Serialization\\.Formatters\\.Soap,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.DurableInstancing,"); c.Assemblies.Ignored.Add("System\\.Data\\.SqlXml,"); c.Assemblies.Ignored.Add("JSIL\\.Meta,"); c.Assemblies.TranslateAdditional.Add("JSIL.ExpressionInterpreter.dll"); c.Assemblies.Proxies.Add(Path.Combine(ComparisonTest.JSILFolder, "JSIL.Proxies.Bcl.dll")); return c; }; Action<AssemblyTranslator> initializeTranslator = (at) => { // Suppress stdout spew at.IgnoredMethod += (_, _2) => { }; }; RunSingleComparisonTestCase( parameters, makeConfiguration, new JSEvaluationConfig { ThrowOnUnimplementedExternals = false, AdditionalFilesToLoad = new[] { Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "..", "Libraries", "JSIL.ExpressionInterpreter.js")) } }, initializeTranslator: initializeTranslator ); }
public void SimpleTestCasesForTranslatedBcl(object[] parameters) { Func<Configuration> makeConfiguration = () => { var c = new Configuration { ApplyDefaults = false, }; c.Assemblies.Stubbed.Add("^System,"); c.Assemblies.Stubbed.Add("^System\\.(?!Core)(.+),"); c.Assemblies.Stubbed.Add("^Microsoft\\.(.+),"); c.Assemblies.Stubbed.Add("FSharp.Core,"); c.Assemblies.Ignored.Add("Microsoft\\.VisualC,"); c.Assemblies.Ignored.Add("Accessibility,"); c.Assemblies.Ignored.Add("SMDiagnostics,"); c.Assemblies.Ignored.Add("System\\.EnterpriseServices,"); c.Assemblies.Ignored.Add("System\\.Security,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.Serialization\\.Formatters\\.Soap,"); c.Assemblies.Ignored.Add("System\\.Runtime\\.DurableInstancing,"); c.Assemblies.Ignored.Add("System\\.Data\\.SqlXml,"); c.Assemblies.Ignored.Add("JSIL\\.Meta,"); c.Assemblies.Proxies.Add("JSIL.Proxies.Bcl.dll"); return c; }; Action<AssemblyTranslator> initializeTranslator = (at) => { // Suppress stdout spew at.IgnoredMethod += (_, _2) => { }; }; RunSingleComparisonTestCase( parameters, makeConfiguration, false, initializeTranslator: initializeTranslator ); }
public virtual void MergeInto (Configuration result) { if (ApplyDefaults.HasValue) result.ApplyDefaults = ApplyDefaults; if (IncludeDependencies.HasValue) result.IncludeDependencies = IncludeDependencies; if (UseSymbols.HasValue) result.UseSymbols = UseSymbols; if (UseThreads.HasValue) result.UseThreads = UseThreads; if (UseDefaultProxies.HasValue) result.UseDefaultProxies = UseDefaultProxies; if (FrameworkVersion.HasValue) result.FrameworkVersion = FrameworkVersion; if (GenerateSkeletonsForStubbedAssemblies.HasValue) result.GenerateSkeletonsForStubbedAssemblies = GenerateSkeletonsForStubbedAssemblies; if (GenerateContentManifest.HasValue) result.GenerateContentManifest = GenerateContentManifest; if (SkipManifestCreation.HasValue) result.SkipManifestCreation = SkipManifestCreation; if (RunBugChecks.HasValue) result.RunBugChecks = RunBugChecks; if (TuneGarbageCollection.HasValue) result.TuneGarbageCollection = TuneGarbageCollection; if (FilenameEscapeRegex != null) result.FilenameEscapeRegex = FilenameEscapeRegex; if (AssemblyCollectionName != null) result.AssemblyCollectionName = AssemblyCollectionName; if (BuildSourceMap != null) result.BuildSourceMap = BuildSourceMap; if (InlineAssemblyReferences != null) result.InlineAssemblyReferences = InlineAssemblyReferences; foreach (var kvp in FilenameReplaceRegexes) result.FilenameReplaceRegexes[kvp.Key] = kvp.Value; foreach (var emitterFactory in EmitterFactories) { result.EmitterFactories.Add(emitterFactory); } Assemblies.MergeInto(result.Assemblies); CodeGenerator.MergeInto(result.CodeGenerator); }
public IAstEmitter MakeAstEmitter ( JSILIdentifier jsil, TypeSystem typeSystem, TypeInfoProvider typeInfoProvider, Configuration configuration ) { return new JavascriptAstEmitter( Formatter, jsil, typeSystem, typeInfoProvider, configuration ); }
/// <summary> /// Compiles the provided C# and then translates it into JavaScript. /// On success, returns the JS. On failure, throws. /// </summary> public static CompiledSnippet Compile(string csharp, bool deleteTempFiles) { var result = new CompiledSnippet { OriginalSource = csharp }; int tempDirId = Interlocked.Increment(ref NextTempDirId); var tempPath = Path.Combine(Path.GetTempPath(), "JSIL.Try", tempDirId.ToString()); if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath); try { string resultPath, entryPointName, compilerOutput, resultFullName; long compileStarted = DateTime.UtcNow.Ticks; CompileAssembly( tempPath, csharp, out compilerOutput, out resultPath, out resultFullName, out entryPointName ); result.CompileElapsed = TimeSpan.FromTicks(DateTime.UtcNow.Ticks - compileStarted).TotalSeconds; if ((resultPath == null) || !File.Exists(resultPath)) { if (String.IsNullOrWhiteSpace(compilerOutput)) throw new Exception("Compile failed with unknown error."); else throw new Exception(compilerOutput); } var translatorConfiguration = new Configuration { ApplyDefaults = false, Assemblies = { Stubbed = { "mscorlib,", "System.*", "Microsoft.*" }, Ignored = { "Microsoft.VisualC,", "Accessibility,", "SMDiagnostics,", "System.EnterpriseServices,", "JSIL.Meta," } }, FrameworkVersion = 4.0, GenerateSkeletonsForStubbedAssemblies = false, GenerateContentManifest = false, IncludeDependencies = false, UseSymbols = true, UseThreads = false }; var translatorOutput = new StringBuilder(); var typeInfo = CachedTypeInfo.Value; // Don't use a cached type provider if this snippet contains a proxy. bool disableCaching = csharp.Contains("JSProxy"); using (var translator = new AssemblyTranslator( translatorConfiguration, // Reuse the cached type info provider, if one exists. disableCaching ? null : typeInfo, // Can't reuse a manifest meaningfully here. null, // Reuse the assembly cache so that mscorlib doesn't get loaded every time. AssemblyCache )) { translator.CouldNotDecompileMethod += (s, exception) => { lock (translatorOutput) translatorOutput.AppendFormat( "Could not decompile method '{0}': {1}{2}", s, exception.Message, Environment.NewLine ); }; translator.CouldNotResolveAssembly += (s, exception) => { lock (translatorOutput) translatorOutput.AppendFormat( "Could not resolve assembly '{0}': {1}{2}", s, exception.Message, Environment.NewLine ); }; translator.Warning += (s) => { lock (translatorOutput) translatorOutput.AppendLine(s); }; var translateStarted = DateTime.UtcNow.Ticks; var translationResult = translator.Translate(resultPath, true); AssemblyTranslator.GenerateManifest( translator.Manifest, Path.GetDirectoryName(resultPath), translationResult ); result.EntryPoint = String.Format( "{0}.{1}", translator.Manifest.GetPrivateToken(resultFullName).IDString, entryPointName ); result.Warnings = translatorOutput.ToString().Trim(); result.TranslateElapsed = TimeSpan.FromTicks(DateTime.UtcNow.Ticks - translateStarted).TotalSeconds; result.JavaScript = translationResult.WriteToString(); if (typeInfo != null) { // Remove the temporary assembly from the type info provider. typeInfo.Remove(translationResult.Assemblies.ToArray()); } else if (!disableCaching) { // We didn't have a type info provider to reuse, so store the translator's. CachedTypeInfo.Value = typeInfo = translator.GetTypeInfoProvider(); } /* result.Warnings += String.Format( "{1} assemblies loaded{0}", Environment.NewLine, AppDomain.CurrentDomain.GetAssemblies().Length ); */ /* result.Warnings += String.Format( "TypeInfo.Count = {1}{0}AssemblyCache.Count = {2}{0}", Environment.NewLine, TypeInfo.Count, AssemblyCache.Count ); */ } /* GC.Collect(); result.Warnings += String.Format( "{1} byte(s) GC heap {0}", Environment.NewLine, GC.GetTotalMemory(true) ); */ return result; } finally { try { if (deleteTempFiles) Directory.Delete(tempPath, true); } catch (Exception exc) { Console.WriteLine("Failed to empty temporary directory: {0}", exc.Message); } } }
public virtual Configuration Clone () { var result = new Configuration(); MergeInto(result); return result; }
internal TranslationResult(Configuration configuration) { Configuration = configuration; }
public AssemblyTranslator MakeTranslator (Configuration configuration) { return new AssemblyTranslator(configuration); }
public IAstEmitter MakeAstEmitter(JSILIdentifier jsil, TypeSystem typeSystem, TypeInfoProvider typeInfoProvider, Configuration configuration) { return new AstEmitter(this, Formatter, jsil, typeSystem, typeInfoProvider, configuration, isTopLevel: false); }
public IAstEmitter MakeAstEmitter(JSILIdentifier jsil, TypeSystem typeSystem, TypeInfoProvider typeInfoProvider, Configuration configuration) { return new NullAstEmitter(typeSystem); }