Esempio n. 1
0
        /// <summary>
        /// Starts the P# compilation process.
        /// </summary>
        public void Start()
        {
            foreach (var target in this.CompilationContext.Configuration.CompilationTargets)
            {
                Output.PrintLine(". Compiling for " + target);

                this.CompilationContext.ActiveCompilationTarget = target;

                // Creates and runs a P# compilation engine.
                CompilationEngine.Create(this.CompilationContext).Run();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts the P# compilation process.
        /// </summary>
        public void Start()
        {
            if (this.CompilationContext.Configuration.CompilationTarget == CompilationTarget.Testing)
            {
                IO.PrintLine($". Compiling ({this.CompilationContext.Configuration.CompilationTarget})");
            }
            else
            {
                IO.PrintLine($". Compiling ({this.CompilationContext.Configuration.CompilationTarget}::" +
                             $"{this.CompilationContext.Configuration.OptimizationTarget})");
            }

            // Creates and runs a P# compilation engine.
            CompilationEngine.Create(this.CompilationContext).Run();
        }
Esempio n. 3
0
        /// <summary>
        /// Starts the P# compilation process.
        /// </summary>
        public void Start()
        {
            if (this.CompilationContext.Configuration.CompilationTarget == CompilationTarget.Testing)
            {
                Output.WriteLine($". Compiling ({this.CompilationContext.Configuration.CompilationTarget})");
            }
            else
            {
                Output.WriteLine($". Compiling ({this.CompilationContext.Configuration.CompilationTarget}::" +
                                 $"{this.CompilationContext.Configuration.OptimizationTarget})");
            }

            // Creates and runs a P# compilation engine.
            CompilationEngine.Create(this.CompilationContext, this.Logger).Run();
        }
Esempio n. 4
0
        /// <summary>
        /// Create a new proxy type.
        /// </summary>
        /// <param name="interfaceType">Type</param>
        /// <param name="actorMachineType">Actor machine type</param>
        /// <param name="assemblyPath">Assembly path</param>
        /// <returns>Type</returns>
        private Type CreateProxyType(Type interfaceType, Type actorMachineType, string assemblyPath)
        {
            if (!interfaceType.IsInterface)
            {
                throw new InvalidOperationException();
            }

            var actorType  = this.GetActorType(interfaceType, assemblyPath);
            var references = new HashSet <MetadataReference>();

            references.Add(MetadataReference.CreateFromFile(actorType.Assembly.Location));
            references.Add(MetadataReference.CreateFromFile(typeof(ActorMachine).Assembly.Location));
            foreach (var referencedAssembly in actorType.Assembly.GetReferencedAssemblies())
            {
                references.Add(MetadataReference.CreateFromFile(Assembly.Load(referencedAssembly).Location));
            }

            SyntaxTree syntaxTree = this.CreateProxySyntaxTree(interfaceType, actorType, actorMachineType);
            //Console.WriteLine(syntaxTree);

            var context     = CompilationContext.Create().LoadSolution(syntaxTree.ToString(), references, "cs");
            var compilation = context.GetSolution().Projects.First().GetCompilationAsync().Result;

            syntaxTree = context.GetSolution().Projects.First().Documents.First().GetSyntaxTreeAsync().Result;

            SemanticModel semanticModel = compilation.GetSemanticModel(syntaxTree);

            var typeSymbol = semanticModel.GetDeclaredSymbol(syntaxTree.GetRoot().DescendantNodes()
                                                             .OfType <ClassDeclarationSyntax>().First());

            compilation = compilation.WithAssemblyName(interfaceType.Name + "_PSharpProxy");
            compilation = compilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            string proxyAssemblyPath = CompilationEngine.Create(context).ToFile(compilation,
                                                                                OutputKind.DynamicallyLinkedLibrary, Assembly.GetExecutingAssembly().Location,
                                                                                false, false);

            Assembly proxyAssembly = Assembly.LoadFrom(proxyAssemblyPath);

            Type proxyType = proxyAssembly.GetType(typeSymbol.ContainingNamespace.ToString() +
                                                   "." + typeSymbol.MetadataName);

            return(proxyType);
        }