/// <summary> /// This function is called on every recompilation to discard all previous results /// </summary> private void Reset() { compilerResults = null; outputSettings = null; qil = null; command = null; }
private void CompileIlFromQil(XsltSettings settings) { command = new XmlILGenerator().Generate(qil, settings.AssemblyName); // Set outputSettings only if compilation was successful outputSettings = qil.DefaultWriterSettings; qil = null; }
/// <summary> /// This function is called on every recompilation to discard all previous results /// </summary> private void Reset() { this.compilerResults = null; this.outputSettings = null; this.qil = null; this.command = null; }
/// <summary> /// This function is called on every recompilation to discard all previous results /// </summary> private void Reset() { _compilerErrorColl = null; _outputSettings = null; _qil = null; _command = null; }
/// <summary> /// This function is called on every recompilation to discard all previous results /// </summary> private void Reset() { _compilerResults = null; _outputSettings = null; _qil = null; _command = null; }
public CompilerResults Compile(object stylesheet, XmlResolver xmlResolver, out QilExpression qil) { Debug.Assert(stylesheet != null); Debug.Assert(PrincipalStylesheet == null, "Compiler cannot be reused"); new XsltLoader().Load(this, stylesheet, xmlResolver); qil = QilGenerator.CompileStylesheet(this); return(CompilerResults); }
/// <summary> /// This function is called on every recompilation to discard all previous results /// </summary> private void Reset() { _compilerErrorColl = null; _outputSettings = null; _qil = null; #if FEATURE_COMPILED_XSL _command = null; #endif }
/// <summary> /// Serialize rewritten Qil tree to writer "w". /// </summary> private static void WriteQilRewrite(QilExpression qil, XmlWriter w, string?rewriteName) { w.WriteStartElement("Diff"); if (rewriteName != null) { w.WriteAttributeString("rewrite", rewriteName); } WriteQil(qil, w); w.WriteEndElement(); }
private void CompileQilToMsil(XsltSettings settings) { #if FEATURE_COMPILED_XSL _command = new XmlILGenerator().Generate(_qil, /*typeBuilder:*/ null); _outputSettings = _command.StaticData.DefaultWriterSettings; _qil = null; #else throw new PlatformNotSupportedException(SR.Xslt_NotSupported); #endif }
/// <summary> /// Trace ILGen optimizations and log them to "fileName". /// </summary> public static void TraceOptimizations(QilExpression qil, string fileName) { if (!IsEnabled) { return; } XmlWriter w = XmlWriter.Create(s_dirName + "\\" + fileName); w.WriteStartDocument(); w.WriteProcessingInstruction("xml-stylesheet", "href='qilo.xslt' type='text/xsl'"); w.WriteStartElement("QilOptimizer"); w.WriteAttributeString("timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture)); WriteQilRewrite(qil, w, null); try { // Then, rewrite the graph until "done" or some max value is reached. for (int i = 1; i < MAX_REWRITES; i++) { QilExpression qilTemp = (QilExpression)(new QilCloneVisitor(qil.Factory).Clone(qil)); XmlILOptimizerVisitor visitor = new XmlILOptimizerVisitor(qilTemp, !qilTemp.IsDebug); visitor.Threshold = i; qilTemp = visitor.Optimize(); // In debug code, ensure that QIL after N steps is correct QilValidationVisitor.Validate(qilTemp); // Trace the rewrite WriteQilRewrite(qilTemp, w, OptimizationToString(visitor.LastReplacement)); if (visitor.ReplacementCount < i) { break; } } } catch (Exception e) { if (!XmlException.IsCatchableException(e)) { throw; } w.WriteElementString("Exception", null, e.ToString()); throw; } finally { w.WriteEndElement(); w.WriteEndDocument(); w.Flush(); w.Close(); } }
/// <summary> /// Perform tail-call analysis on the functions in the specified QilExpression. /// </summary> public static void Analyze(QilExpression qil) { foreach (QilFunction ndFunc in qil.FunctionList) { // Only analyze functions which are pushed to the writer, since otherwise code // is generated after the call instruction in order to process cached results if (XmlILConstructInfo.Read(ndFunc).ConstructMethod == XmlILConstructMethod.Writer) { AnalyzeDefinition(ndFunc.Definition); } } }
/// <summary> /// Constructor. /// </summary> public XmlILCommand(ExecuteDelegate delExec, QilExpression qil, StaticDataManager staticData) { Debug.Assert(qil != null); this.delExec = delExec; this.defaultWriterSettings = qil.DefaultWriterSettings; this.wsRules = qil.WhitespaceRules; this.names = staticData.Names; this.prefixMappingsList = staticData.PrefixMappingsList; this.filters = staticData.NameFilters; this.types = staticData.XmlTypes; this.collations = staticData.Collations; this.globalNames = staticData.GlobalNames; this.earlyInfo = staticData.EarlyBound; }
public static void WriteQil(QilExpression qil, string fileName) { if (!IsEnabled) { return; } XmlWriter w = XmlWriter.Create(dirName + "\\" + fileName); try { WriteQil(qil, w); } finally { w.Close(); } }
internal static void PrintQil(object qil, XmlWriter xw, bool printComments, bool printTypes, bool printLineInfo) { QilExpression node = (QilExpression)qil; QilXmlWriter.Options none = QilXmlWriter.Options.None; if (printComments) { none |= QilXmlWriter.Options.Annotations; } if (printTypes) { none |= QilXmlWriter.Options.TypeInfo; } if (printLineInfo) { none |= QilXmlWriter.Options.LineInfo; } new QilXmlWriter(xw, none).ToXml(node); xw.Flush(); }
internal static void PrintQil(object qil, XmlWriter xw, bool printComments, bool printTypes, bool printLineInfo) { QilExpression qilExpr = (QilExpression)qil; QilXmlWriter.Options options = QilXmlWriter.Options.None; QilValidationVisitor.Validate(qilExpr); if (printComments) { options |= QilXmlWriter.Options.Annotations; } if (printTypes) { options |= QilXmlWriter.Options.TypeInfo; } if (printLineInfo) { options |= QilXmlWriter.Options.LineInfo; } QilXmlWriter qw = new QilXmlWriter(xw, options); qw.ToXml(qilExpr); xw.Flush(); }
/// <summary> /// Serialize Qil tree to writer "w". /// </summary> private static void WriteQil(QilExpression qil, XmlWriter w) { QilXmlWriter qw = new QilXmlWriter(w); qw.ToXml(qil); }
/// <summary> /// Given the logical query plan (QilExpression) generate a physical query plan (MSIL) that can be executed. /// </summary> // SxS Note: The way the trace file names are created (hardcoded) is NOT SxS safe. However the files are // created only for internal tracing purposes. In addition XmlILTrace class is not compiled into retail // builds. As a result it is fine to suppress the FxCop SxS warning. // TODO-NULLABLE: missing [return: NotNullIfNull("typeBldr")] public XmlILCommand?Generate(QilExpression query, TypeBuilder?typeBldr) { _qil = query; bool useLRE = ( !_qil.IsDebug && (typeBldr == null) #if DEBUG && !XmlILTrace.IsEnabled // Dump assembly to disk; can't do this when using LRE #endif ); bool emitSymbols = _qil.IsDebug; // In debug code, ensure that input QIL is correct QilValidationVisitor.Validate(_qil); #if DEBUG // Trace Qil before optimization XmlILTrace.WriteQil(_qil, "qilbefore.xml"); // Trace optimizations XmlILTrace.TraceOptimizations(_qil, "qilopt.xml"); #endif // Optimize and annotate the Qil graph _optVisitor = new XmlILOptimizerVisitor(_qil, !_qil.IsDebug); _qil = _optVisitor.Optimize(); // In debug code, ensure that output QIL is correct QilValidationVisitor.Validate(_qil); #if DEBUG // Trace Qil after optimization XmlILTrace.WriteQil(_qil, "qilafter.xml"); #endif // Create module in which methods will be generated if (typeBldr != null) { _module = new XmlILModule(typeBldr); } else { _module = new XmlILModule(useLRE, emitSymbols); } // Create a code generation helper for the module; enable optimizations if IsDebug is false _helper = new GenerateHelper(_module, _qil.IsDebug); // Create helper methods CreateHelperFunctions(); // Create metadata for the Execute function, which is the entry point to the query // public static void Execute(XmlQueryRuntime); MethodInfo methExec = _module.DefineMethod("Execute", typeof(void), Array.Empty <Type>(), Array.Empty <string>(), XmlILMethodAttributes.NonUser); // Create metadata for the root expression // public void Root() Debug.Assert(_qil.Root != null); XmlILMethodAttributes methAttrs = (_qil.Root.SourceLine == null) ? XmlILMethodAttributes.NonUser : XmlILMethodAttributes.None; MethodInfo methRoot = _module.DefineMethod("Root", typeof(void), Array.Empty <Type>(), Array.Empty <string>(), methAttrs); // Declare all early bound function objects foreach (EarlyBoundInfo info in _qil.EarlyBoundTypes) { _helper.StaticData.DeclareEarlyBound(info.NamespaceUri, info.EarlyBoundType); } // Create metadata for each QilExpression function that has at least one caller CreateFunctionMetadata(_qil.FunctionList); // Create metadata for each QilExpression global variable and parameter CreateGlobalValueMetadata(_qil.GlobalVariableList); CreateGlobalValueMetadata(_qil.GlobalParameterList); // Generate Execute method GenerateExecuteFunction(methExec, methRoot); // Visit the QilExpression graph _xmlIlVisitor = new XmlILVisitor(); _xmlIlVisitor.Visit(_qil, _helper, methRoot); // Collect all static information required by the runtime XmlQueryStaticData staticData = new XmlQueryStaticData( _qil.DefaultWriterSettings, _qil.WhitespaceRules, _helper.StaticData ); // Create static constructor that initializes XmlQueryStaticData instance at runtime if (typeBldr != null) { CreateTypeInitializer(staticData); // Finish up creation of the type _module.BakeMethods(); return(null); } else { // Finish up creation of the type _module.BakeMethods(); // Create delegate over "Execute" method ExecuteDelegate delExec = (ExecuteDelegate)_module.CreateDelegate("Execute", typeof(ExecuteDelegate)); return(new XmlILCommand(delExec, staticData)); } }
public CompilerErrorCollection Compile(object stylesheet, XmlResolver xmlResolver, out QilExpression qil) { Debug.Assert(stylesheet != null); Debug.Assert(Root == null, "Compiler cannot be reused"); new XsltLoader().Load(this, stylesheet, xmlResolver); qil = QilGenerator.CompileStylesheet(this); SortErrors(); return(CompilerErrorColl); }
private void CompileQilToMsil(XsltSettings settings) { _command = new XmlILGenerator().Generate(_qil, /*typeBuilder:*/ null); _outputSettings = _command.StaticData.DefaultWriterSettings; _qil = null; }
/// <summary> /// Given the logical query plan (QilExpression) generate a physical query plan (MSIL) that can be executed. /// </summary> public XmlCommand Generate(QilExpression query, AssemblyName asmName) { MethodInfo methRoot, methExec; bool useLRE, emitSymbols; ExecuteDelegate delExec; XmlILMethodAttributes methAttrs; this.qil = query; useLRE = !this.qil.IsDebug && (asmName == null); emitSymbols = this.qil.IsDebug; // In debug code, ensure that input QIL is correct QilValidationVisitor.Validate(this.qil); // Trace Qil before optimization XmlILTrace.WriteQil(this.qil, "qilbefore.xml"); // Trace optimizations XmlILTrace.TraceOptimizations(this.qil, "qilopt.xml"); if (XmlILTrace.IsEnabled) { // Dump assembly to disk; can't do this when using LRE useLRE = false; } // Optimize and annotate the Qil graph this.optVisitor = new XmlILOptimizerVisitor(this.qil, !this.qil.IsDebug); this.qil = this.optVisitor.Optimize(); // In debug code, ensure that output QIL is correct QilValidationVisitor.Validate(this.qil); // Trace Qil after optimization XmlILTrace.WriteQil(this.qil, "qilafter.xml"); // Create module in which methods will be generated this.module = new XmlILModule(useLRE, emitSymbols, asmName); // Create a code generation helper for the module; enable optimizations if IsDebug is false this.helper = new GenerateHelper(this.module, this.qil.IsDebug); // Create helper methods CreateHelperFunctions(); // Create metadata for the root expression // public void Root() Debug.Assert(this.qil.Root != null); methAttrs = (this.qil.Root.SourceLine == null) ? XmlILMethodAttributes.NonUser : XmlILMethodAttributes.None; methRoot = this.module.DefineMethod("Root", typeof(void), new Type[] {}, new string[] {}, methAttrs); // Create metadata for each QilExpression function that has at least one caller CreateFunctionMetadata(this.qil.FunctionList); // Create metadata for each QilExpression global variable and parameter CreateGlobalValueMetadata(this.qil.GlobalVariableList); CreateGlobalValueMetadata(this.qil.GlobalParameterList); // Create Execute method methExec = CreateExecuteFunction(methRoot); // Visit the QilExpression graph this.xmlIlVisitor = new XmlILVisitor(); this.xmlIlVisitor.Visit(this.qil, this.helper, methRoot); this.module.BakeMethods(); // Create delegate over "Execute" method delExec = (ExecuteDelegate)this.module.CreateDelegate("Execute", typeof(ExecuteDelegate)); return(new XmlILCommand(delExec, this.qil, this.helper.StaticData)); }
private void CompileQilToMsil(XsltSettings settings) { this.command = new XmlILGenerator().Generate(this.qil, null); this.outputSettings = this.command.StaticData.DefaultWriterSettings; this.qil = null; }