Example #1
0
        static void EmitMain(string programName, Assembly[] assemblies, Tracer tracer, IReadOnlyList <ImmutableRootSyntaxNode> rootNodes)
        {
            var createdAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(programName), AssemblyBuilderAccess.RunAndSave);
            var createdModule   = createdAssembly.DefineDynamicModule(programName, programName + ".exe");

            var emitModuleBuilder = new EmitModuleBuilder(createdModule, assemblies);

            var codeGenerator = new NewCodeGenerator(emitModuleBuilder, tracer);

            var entryPoint = codeGenerator.GenerateAssembly(rootNodes);

            //            System.Console.Out.WriteLine("Hello World from Out!");


            if (entryPoint == null)
            {
                throw new InvalidOperationException("Entry point must be null");
            }

            createdAssembly.SetEntryPoint(((EmitMethodInfo)entryPoint).MethodInfo);

            createdAssembly.Save(programName + ".exe");

            tracer.AddEpoch("Code Generation");
        }
Example #2
0
        static void IlAsmMain(string programName, Assembly[] assemblies, Tracer tracer, IReadOnlyList <ImmutableRootSyntaxNode> rootNode)
        {
            var emitModuleBuilder = new AsmModuleBuilder(programName, assemblies);

            var codeGenerator = new NewCodeGenerator(emitModuleBuilder, tracer);

            var entryPoint = codeGenerator.GenerateAssembly(rootNode);


            if (entryPoint == null)
            {
                throw new InvalidOperationException("Entry point must be null");
            }

            var asm = emitModuleBuilder.Emitter.Finalize();

            File.WriteAllLines($"{programName}.il", asm);

            tracer.AddEpoch("Code Generation");
        }