public IProject MakeProject(IProject Project, ProjectPath Path, ICompilerLog Log)
 {
     var newPath = Path.Path.Parent.Combine(Project.Name).ChangeExtension("ecsproj");
     var dsp = DSProject.FromProject(Project, newPath.AbsolutePath.Path);
     dsp.WriteTo(newPath.Path);
     return dsp;
 }
Beispiel #2
0
 public IProject MakeProject(IProject Project, ProjectPath Path, ICompilerLog Log)
 {
     Log.LogWarning(new LogEntry(
                        "ignored '-make-project'",
                        "the '-make-project' option was ignored because cin does not support any C project formats yet."));
     return(Project);
 }
 public AzureFunctionsCompiler(ICompilerLog compilerLog)
 {
     _compilerLog      = compilerLog;
     _jsonCompiler     = new JsonCompiler();
     _openApiCompiler  = new OpenApiCompiler();
     _assemblyCompiler = new AzureFunctionsAssemblyCompiler(compilerLog, new TemplateProvider(CompileTargetEnum.AzureFunctions));
 }
Beispiel #4
0
        /// <summary>
        /// Creates a GC description from the given binder and log.
        /// </summary>
        /// <param name="Binder">The binder to find types with.</param>
        /// <param name="Log">The log to use when an error is to be reported.</param>
        public ExternalGCDescription(IBinder Binder, ICompilerLog Log)
        {
            var methodFinder = new ExternalGCMethodFinder(Binder, Log);

            this.allocMethod             = methodFinder.AllocateMethod;
            this.registerFinalizerMethod = methodFinder.RegisterFinalizerMethod;
        }
Beispiel #5
0
 /// <summary>
 /// Creates a GC method finder from the given binder and log.
 /// </summary>
 /// <param name="Binder">The binder to find types with.</param>
 /// <param name="Log">The log to use when an error is to be reported.</param>
 public ExternalGCMethodFinder(IBinder Binder, ICompilerLog Log)
 {
     this.Binder                  = Binder;
     this.Log                     = Log;
     this.GCType                  = new Lazy <IType>(GetGCType);
     this.AllocateMethod          = new Lazy <IMethod>(GetAllocateMethod);
     this.RegisterFinalizerMethod = new Lazy <IMethod>(GetRegisterFinalizerMethod);
 }
 public IProject Parse(ProjectPath Path, ICompilerLog Log)
 {
     if (Path.HasExtension("ecs") || Path.HasExtension("cs") || Path.HasExtension("les"))
     {
         return new SingleFileProject(Path, Log.Options.GetTargetPlatform());
     }
     else
     {
         return DSProject.ReadProject(Path.Path.Path);
     }
 }
Beispiel #7
0
        public Compiler(Assembly configurationSourceAssembly,
                        string outputBinaryFolder,
                        ICompilerLog compilerLog)
        {
            _configurationSourceAssembly = configurationSourceAssembly;
            _outputBinaryFolder          = outputBinaryFolder;
            _compilerLog       = compilerLog;
            _serviceCollection = new ServiceCollection();
            CommandingDependencyResolverAdapter adapter = new CommandingDependencyResolverAdapter(
                (fromType, toInstance) => _serviceCollection.AddSingleton(fromType, toInstance),
                (fromType, toType) => _serviceCollection.AddTransient(fromType, toType),
                (resolveType) => null // we never resolve during compilation
                );

            _commandRegistry          = adapter.AddCommanding();
            _triggerReferenceProvider = new TriggerReferenceProvider();
        }
Beispiel #8
0
        public PassPreferences GetPassPreferences(ICompilerLog Log)
        {
            return(new PassPreferences(new PassCondition[]
            {
                new PassCondition(
                    PassExtensions.EliminateDeadCodePassName,
                    optInfo => optInfo.OptimizeMinimal || optInfo.OptimizeDebug),
                new PassCondition(
                    InfiniteRecursionPass.InfiniteRecursionPassName,
                    optInfo => InfiniteRecursionPass.IsUseful(optInfo.Log))
            },
                                       new PassInfo <Tuple <IStatement, IMethod, ICompilerLog>, IStatement>[]
            {
                new PassInfo <Tuple <IStatement, IMethod, ICompilerLog>, IStatement>(
                    VerifyingDeadCodePass.Instance,
                    PassExtensions.EliminateDeadCodePassName),

                new PassInfo <Tuple <IStatement, IMethod, ICompilerLog>, IStatement>(
                    InfiniteRecursionPass.Instance,
                    InfiniteRecursionPass.InfiniteRecursionPassName)
            }));
        }
Beispiel #9
0
 public IProject Parse(ProjectPath Path, ICompilerLog Log)
 {
     return(new SingleFileProject(Path, Log.Options.GetTargetPlatform()));
 }
Beispiel #10
0
 public AspNetCoreAssemblyCompiler(ICompilerLog compilerLog, ITemplateProvider templateProvider = null) : base(compilerLog, templateProvider)
 {
 }
Beispiel #11
0
        /// <inheritdoc/>
        protected override Tuple <IAssembly, IEnumerable <IAssembly> > RewriteAssemblies(
            Tuple <IAssembly, IEnumerable <IAssembly> > MainAndOtherAssemblies,
            IBinder Binder,
            ICompilerLog Log)
        {
            // In addition to emitting LLVM IR from managed code, flame-llvm must also
            // set up an environment in which managed code can run. Part of this
            // environment is the 'main' function: managed code expects an entry point
            // to look like this: `void|int Main(|string[])`, whereas a C 'main' function
            // must have the following signature: `int main(int, byte**)`.
            //
            // To bridge this divide, we'll generate a 'main' function and use that to
            // call the entry point.

            var originalAsm        = MainAndOtherAssemblies.Item1;
            var originalEntryPoint = originalAsm.GetEntryPoint();

            if (originalEntryPoint == null)
            {
                // We can't rewrite the entry point of an assembly that doesn't
                // have an entry point.
                return(MainAndOtherAssemblies);
            }

            // Generate the following class:
            //
            // public static class __entry_point
            // {
            //     [#builtin_abi("C")]
            //     [#builtin_llvm_linkage(external)]
            //     public static int main(int argc, byte** argv)
            //     {
            //         try
            //         {
            //             var parsedArgs = Environment.Initialize(argc, argv);
            //             return actual_entry_point(...);
            //             // --or--
            //             actual_entry_point(...);
            //             return 0;
            //         }
            //         catch (Exception ex)
            //         {
            //             Environment.HandleFatalException(ex);
            //             return 1;
            //         }
            //     }
            // }

            var mainAsm = new DescribedAssembly(
                originalAsm.Name,
                originalAsm.AssemblyVersion,
                Binder.Environment);

            var epType = new DescribedType(new SimpleName("__entry_point"), mainAsm);

            epType.AddAttribute(PrimitiveAttributes.Instance.StaticTypeAttribute);
            var mainThunk = new DescribedBodyMethod(
                new SimpleName("main"), epType, PrimitiveTypes.Int32, true);

            mainThunk.AddAttribute(new LLVMLinkageAttribute(LLVMLinkage.LLVMExternalLinkage));
            mainThunk.AddAttribute(LLVMAttributes.CreateAbiAttribute("C"));
            mainThunk.AddParameter(new DescribedParameter("argc", PrimitiveTypes.Int32));
            mainThunk.AddParameter(
                new DescribedParameter(
                    "argv",
                    PrimitiveTypes.UInt8
                    .MakePointerType(PointerKind.TransientPointer)
                    .MakePointerType(PointerKind.TransientPointer)));

            if (originalEntryPoint.HasSameSignature(mainThunk))
            {
                // We don't have to rewrite the entry point if the existing entry point
                // already has the expected form.
                return(MainAndOtherAssemblies);
            }

            var epCall = CreateEntryPointCall(originalEntryPoint, mainThunk, Binder);

            mainThunk.Body = epCall.Type.GetIsInteger()
                ? (IStatement) new ReturnStatement(
                new StaticCastExpression(epCall, PrimitiveTypes.Int32).Simplify())
                : new BlockStatement(new IStatement[]
            {
                new ExpressionStatement(epCall),
                new ReturnStatement(new IntegerExpression(0))
            });

            var handleExceptionMethod = BindEnvironmentHandleFatalExceptionMethod(Binder);

            if (handleExceptionMethod != null)
            {
                var exceptionParam = handleExceptionMethod.Parameters.Single <IParameter>();
                var catchClause    = new CatchClause(
                    new DescribedVariableMember(
                        exceptionParam.Name,
                        exceptionParam.ParameterType));

                catchClause.Body = new BlockStatement(new IStatement[]
                {
                    new ExpressionStatement(
                        new InvocationExpression(
                            handleExceptionMethod,
                            null,
                            new IExpression[]
                    {
                        catchClause.ExceptionVariable.CreateGetExpression()
                    })),

                    new ReturnStatement(new IntegerExpression(1))
                });

                mainThunk.Body = new TryStatement(
                    mainThunk.Body,
                    new CatchClause[] { catchClause });
            }

            epType.AddMethod(mainThunk);
            mainAsm.AddType(epType);
            mainAsm.EntryPoint = mainThunk;

            return(new Tuple <IAssembly, IEnumerable <IAssembly> >(
                       mainAsm,
                       new IAssembly[] { originalAsm }.Concat <IAssembly>(MainAndOtherAssemblies.Item2)));
        }
Beispiel #12
0
 public LazySourceDocument(string Identifier, ICompilerLog Log)
 {
     this.Identifier = Identifier;
     this.Log        = Log;
 }
Beispiel #13
0
 public string GetRuntimeIdentifier(string Identifier, ICompilerLog Log)
 {
     return(LLVMIdentifier);
 }
Beispiel #14
0
 public AspNetCoreCompiler(ICompilerLog compilerLog)
 {
     _compilerLog      = compilerLog;
     _assemblyCompiler = new AspNetCoreAssemblyCompiler(compilerLog, new TemplateProvider(CompileTargetEnum.AspNetCore));
     _openApiCompiler  = new OpenApiCompiler();
 }
        public PassPreferences GetPassPreferences(ICompilerLog Log)
        {
            return new PassPreferences(new PassCondition[] 
            {
                new PassCondition("check-nodes", _ => true),
                new PassCondition(AutoInitializationPass.AutoInitializationPassName, _ => true),
                new PassCondition(ValueTypeDelegateVisitor.ValueTypeDelegatePassName, 
                    optInfo => ValueTypeDelegateVisitor.ValueTypeDelegateWarning.UseWarning(optInfo.Log.Options)),
                new PassCondition(Flame.Front.Target.PassExtensions.EliminateDeadCodePassName,
                    optInfo => optInfo.OptimizeMinimal || optInfo.OptimizeDebug),
                new PassCondition(InfiniteRecursionPass.InfiniteRecursionPassName,
                    optInfo => InfiniteRecursionPass.IsUseful(optInfo.Log)),
            },
            new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>[] 
            { 
                new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>(
                    LogPass.Instance, 
                    "check-nodes"),

                new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>(
                    AnalysisPasses.ValueTypeDelegatePass,
                    ValueTypeDelegateVisitor.ValueTypeDelegatePassName),

                new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>(
                    VerifyingDeadCodePass.Instance,
                    Flame.Front.Target.PassExtensions.EliminateDeadCodePassName),

                new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>(
                    AutoInitializationPass.Instance,
                    AutoInitializationPass.AutoInitializationPassName),

                new PassInfo<Tuple<IStatement, IMethod, ICompilerLog>, IStatement>(
                    InfiniteRecursionPass.Instance,
                    InfiniteRecursionPass.InfiniteRecursionPassName)
            });
        }
Beispiel #16
0
 protected AssemblyCompilerBase(ICompilerLog compilerLog, ITemplateProvider templateProvider)
 {
     CompilerLog      = compilerLog;
     TemplateProvider = templateProvider;
 }
Beispiel #17
0
 public AzureFunctionsAssemblyCompiler(ICompilerLog compilerLog, ITemplateProvider templateProvider) : base(compilerLog, templateProvider)
 {
 }
Beispiel #18
0
 public AssemblyCompiler(ICompilerLog compilerLog, ITemplateProvider templateProvider = null)
 {
     _compilerLog      = compilerLog;
     _templateProvider = templateProvider ?? new TemplateProvider();
 }
Beispiel #19
0
 private static IEnvironment CreateLLVMEnvironment(ICompilerLog Log)
 {
     return(new StandaloneEnvironment("llvm"));
 }