Пример #1
0
        private static async Task <DfirRoot> GenerateDfirAsync(
            ICompositionHost host,
            Envoy documentEnvoy,
            ProgressToken progressToken,
            CompileCancellationToken compileCancellationToken)
        {
            ExtendedQualifiedName topLevelDocumentName = documentEnvoy.CreateExtendedQualifiedName();
            TargetCompiler        targetCompiler       = documentEnvoy.QueryInheritedService <ITargetCompilerServices>().First().Compiler;
            AnyMocCompiler        compiler             = host.GetSharedExportedValue <AnyMocCompiler>();
            IReadOnlySymbolTable  symbolTable          = documentEnvoy.ComputeSymbolTable();

            // A specAndQName is used by the compiler to identify the document for which we're asking for DFIR.
            var specAndQName = new SpecAndQName(targetCompiler.CreateDefaultBuildSpec(topLevelDocumentName, symbolTable), topLevelDocumentName);

            try
            {
                DfirRoot sourceDfirRoot = await compiler.GetTargetDfirAsync(specAndQName, compileCancellationToken, progressToken);

                if (sourceDfirRoot == null)
                {
                    await ShowErrorMessageBoxAsync(host, WaitForCompileErrorMessageBoxText);
                }

                return(sourceDfirRoot);
            }
            catch
            {
                await ShowErrorMessageBoxAsync(host, DfirGenerationErrorMessageBoxText);

                return(null);
            }
        }
        /// <inheritdoc />
        public override async Task <Tuple <CompileCacheEntry, CompileSignature> > BackEndCompileAsyncCore(
            SpecAndQName specAndQName,
            DfirRoot targetDfir,
            CompileCancellationToken cancellationToken,
            ProgressToken progressToken,
            CompileThreadState compileThreadState)
        {
            CompileSignature topSignature = new CompileSignature(
                targetDfir.Name,
                Enumerable.Empty <CompileSignatureParameter>(), // GenerateParameters(targetDfir),
                targetDfir.GetDeclaringType(),
                targetDfir.Reentrancy,
                true,
                true,
                ThreadAffinity.Standard,
                false,
                true,
                ExecutionPriority.Normal,
                CallingConvention.StdCall);
            BuildSpec htmlVIBuildSpec = specAndQName.BuildSpec;

            foreach (var dependency in targetDfir.Dependencies.OfType <CompileInvalidationDfirDependency>().ToList())
            {
                var compileSignature = await Compiler.GetCompileSignatureAsync(dependency.SpecAndQName, cancellationToken, progressToken, compileThreadState);

                if (compileSignature != null)
                {
                    targetDfir.AddDependency(
                        targetDfir,
                        new CompileSignatureDependency(dependency.SpecAndQName, compileSignature));
                }
            }

            IBuiltPackage builtPackage = null;

            if (!RebarFeatureToggles.IsLLVMCompilerEnabled)
            {
                Function compiledFunction = CompileFunctionForBytecodeInterpreter(targetDfir, cancellationToken);
                builtPackage = new FunctionBuiltPackage(specAndQName, Compiler.TargetName, compiledFunction);
            }
            else
            {
                Module compiledFunctionModule = CompileFunctionForLLVM(targetDfir, cancellationToken);
                builtPackage = new LLVM.FunctionBuiltPackage(specAndQName, Compiler.TargetName, compiledFunctionModule);
            }

            BuiltPackageToken token = Compiler.AddToBuiltPackagesCache(builtPackage);
            CompileCacheEntry entry = await Compiler.CreateStandardCompileCacheEntryFromDfirRootAsync(
                CompileState.Complete,
                targetDfir,
                new Dictionary <ExtendedQualifiedName, CompileSignature>(),
                token,
                cancellationToken,
                progressToken,
                compileThreadState,
                false);

            return(new Tuple <CompileCacheEntry, CompileSignature>(entry, topSignature));
        }
 public FunctionBuiltPackage(
     SpecAndQName identity,
     QualifiedName targetIdentity,
     Module module)
 {
     RuntimeEntityIdentity = identity;
     TargetIdentity        = targetIdentity;
     Module = module;
 }
Пример #4
0
 public FunctionBuiltPackage(
     SpecAndQName identity,
     QualifiedName targetIdentity,
     Function function)
 {
     RuntimeEntityIdentity = identity;
     TargetIdentity        = targetIdentity;
     Function = function;
 }
Пример #5
0
        /// <summary>
        /// Returns a dictionary that maps subVI names of method calls in the source <see cref="DfirRoot"/> to
        /// the corresponding <see cref="DfirRoot"/> objects.
        /// </summary>
        /// <param name="sourceDfirRoot">The parent document that does the method call</param>
        /// <param name="nameDictionary">The dictionary to fill out with names to dfir maps.</param>
        /// <param name="compileCancellationToken">The cancellation token</param>
        /// <param name="progressToken">The progress token</param>
        /// <param name="host">The composition host</param>
        /// <returns>The task to wait on</returns>
        private static async Task GetSubDfirRootsAsync(
            DfirRoot sourceDfirRoot,
            IDictionary <ExtendedQualifiedName, DfirRoot> nameDictionary,
            CompileCancellationToken compileCancellationToken,
            ProgressToken progressToken,
            ICompositionHost host)
        {
            if (sourceDfirRoot == null)
            {
                return;
            }

            // Maintain a queue of VIs to visit, and visit each one.
            var rootsToProcess = new Queue <DfirRoot>();

            // Add the top-level VI to the queue so it is visited first.
            rootsToProcess.Enqueue(sourceDfirRoot);
            while (rootsToProcess.Count > 0)
            {
                DfirRoot root = rootsToProcess.Dequeue();
                foreach (MethodCall node in root.BlockDiagram.GetAllNodes().OfType <MethodCall>())
                {
                    var      specAndQName = new SpecAndQName(node.TargetBuildSpec, node.TargetName);
                    var      compiler     = host.GetSharedExportedValue <AnyMocCompiler>();
                    DfirRoot subDfirRoot;
                    try
                    {
                        subDfirRoot = await compiler.GetTargetDfirAsync(specAndQName, compileCancellationToken, progressToken);

                        RemoveDebugPoints(subDfirRoot, compileCancellationToken);
                    }
                    catch
                    {
                        await ShowErrorMessageBoxAsync(host, DfirGenerationErrorMessageBoxText);

                        return;
                    }
                    if (subDfirRoot == null)
                    {
                        continue;
                    }

                    if (nameDictionary.ContainsKey(node.TargetName))
                    {
                        // If the subVI has already been visited, then don't enqueue it to be visited again.
                        continue;
                    }

                    // The subVI has not been visited. Add the subVI to the queue of VIs to visit.
                    nameDictionary[node.TargetName] = subDfirRoot;
                    rootsToProcess.Enqueue(subDfirRoot);
                }
            }
        }
Пример #6
0
 public FunctionMocReflector(
     IReflectableModel source,
     ReflectionCancellationToken reflectionCancellationToken,
     IScheduledActivityManager scheduledActivityManager,
     IMessageDescriptorTranslator additionalErrorTexts,
     Envoy buildSpecSource,
     SpecAndQName specAndQName,
     DfirModelMap map) :
     base(source, reflectionCancellationToken, scheduledActivityManager, additionalErrorTexts, buildSpecSource, specAndQName)
 {
     _map = map;
 }
Пример #7
0
        public override MocTransformManager GenerateMocTransformManager(SpecAndQName specAndQName, DfirRoot sourceDfir,
                                                                        CompileCancellationToken cancellationToken)
        {
            TerminalTypeUnificationResults unificationResults          = new TerminalTypeUnificationResults();
            LifetimeVariableAssociation    lifetimeVariableAssociation = new LifetimeVariableAssociation();
            List <IDfirTransformBase>      semanticAnalysisTransforms  = new List <IDfirTransformBase>()
            {
                new CreateNodeFacadesTransform(),
                new MergeVariablesAcrossWiresTransform(lifetimeVariableAssociation, unificationResults),
                new FinalizeAutoBorrowsTransform(),
                new MarkConsumedVariablesTransform(lifetimeVariableAssociation),
                new ValidateVariableUsagesTransform(unificationResults),
                new ReflectVariablesToTerminalsTransform(),
            };

            if (RebarFeatureToggles.IsRebarTargetEnabled)
            {
                semanticAnalysisTransforms.Add(new RebarSupportedTargetTransform());
            }
            semanticAnalysisTransforms.Add(new StandardTypeReflectionTransform());
            ReflectErrorsTransform.AddErrorReflection(semanticAnalysisTransforms, CompilePhase.SemanticAnalysis);
            if (!RebarFeatureToggles.IsRebarTargetEnabled)
            {
                semanticAnalysisTransforms.Add(new EmptyTargetDfirTransform());
            }

            List <IDfirTransformBase> toTargetDfirTransforms = new List <IDfirTransformBase>()
            {
                new AutoBorrowTransform(lifetimeVariableAssociation),
                new InsertTerminateLifetimeTransform(lifetimeVariableAssociation),
                new InsertDropTransform(lifetimeVariableAssociation),
            };

            return(new StandardMocTransformManager(
                       specAndQName,
                       sourceDfir,
                       semanticAnalysisTransforms,
                       toTargetDfirTransforms,
                       _host.GetSharedExportedValue <ScheduledActivityManager>()));
        }
Пример #8
0
 /// <summary>
 /// Base constructor of <see cref="ApplicationComponentMocReflector"/>
 /// </summary>
 /// <param name="source">An interface allowing the reflector to talk to the source model</param>
 /// <param name="reflectionCancellationToken">A token to poll for whether to do reflection or not</param>
 /// <param name="scheduledActivityManager">The activity used to flip over into the UI thread as needed to do reflections</param>
 /// <param name="additionalErrorTexts">Supplies third-party message descriptions for this MoC</param>
 /// <param name="buildSpecSource">Source of the BuildSpec for which to reflect messages</param>
 /// <param name="specAndQName">The <see cref="SpecAndQName"/> for which to reflect messages</param>
 internal ApplicationComponentMocReflector(IReflectableModel source, ReflectionCancellationToken reflectionCancellationToken, IScheduledActivityManager scheduledActivityManager, IMessageDescriptorTranslator additionalErrorTexts, Envoy buildSpecSource, SpecAndQName specAndQName)
     : base(source, reflectionCancellationToken, scheduledActivityManager, additionalErrorTexts, buildSpecSource, specAndQName)
 {
 }
Пример #9
0
 public override MocReflector CreateMocReflector(ICompilableModel source, ReflectionCancellationToken reflectionCancellationToken, Envoy buildSpecSource, SpecAndQName specAndQName)
 {
     return(new ApplicationComponentMocReflector(
                source,
                reflectionCancellationToken,
                ScheduledActivityManager,
                AdditionalErrorTexts,
                buildSpecSource,
                specAndQName));
 }
Пример #10
0
 /// <inheritdoc />
 public Task <CompileInformation> GetCompileInformation(SpecAndQName itemSpecAndQName, CompileCancellationToken cancellationToken,
                                                        ProgressToken progressToken, CompileThreadState compileThreadState)
 {
     return(Compiler.CompileAsTopLevel(itemSpecAndQName, cancellationToken, progressToken, compileThreadState));
 }
Пример #11
0
 /// <inheritdoc />
 protected override IBuiltPackage CreateExecutionBuiltPackage(SpecAndQName specAndQName, string absoluteDirectoryForComponent,
                                                              IEnumerable <IFileBuilder> builders, ComponentBuildResult componentBuildResult)
 {
     throw new NotImplementedException();
 }