예제 #1
0
        public CodeGenerator(DynamicRuntimeState globalState, TargetMachine machine, bool disableOptimization = false)
            : base(null)
        {
            globalState.ValidateNotNull(nameof(globalState));
            machine.ValidateNotNull(nameof(machine));

            if (globalState.LanguageLevel > LanguageLevel.MutableVariables)
            {
                throw new ArgumentException("Language features not supported by this generator", nameof(globalState));
            }

            RuntimeState         = globalState;
            Context              = new Context( );
            TargetMachine        = machine;
            DisableOptimizations = disableOptimization;
            InstructionBuilder   = new InstructionBuilder(Context);
            Module = Context.CreateBitcodeModule( );
            Module.TargetTriple = machine.Triple;
            Module.Layout       = TargetMachine.TargetData;
            FunctionPassManager = new FunctionPassManager(Module);
            FunctionPassManager.AddPromoteMemoryToRegisterPass( );

            if (!DisableOptimizations)
            {
                FunctionPassManager.AddInstructionCombiningPass( )
                .AddReassociatePass( )
                .AddGVNPass( )
                .AddCFGSimplificationPass( );
            }

            FunctionPassManager.Initialize( );
        }
예제 #2
0
 private void InitializeModuleAndPassManager( )
 {
     Module = new BitcodeModule(Context, "Kaleidoscope");
     FunctionPassManager = new FunctionPassManager(Module);
     FunctionPassManager.AddPromoteMemoryToRegisterPass()
     .AddInstructionCombiningPass( )
     .AddReassociatePass( )
     .AddGVNPass( )
     .AddCFGSimplificationPass( )
     .Initialize( );
 }
예제 #3
0
        private void InitializeModuleAndPassManager( )
        {
            Module              = Context.CreateBitcodeModule( );
            Module.Layout       = JIT.TargetMachine.TargetData;
            FunctionPassManager = new FunctionPassManager(Module);
            FunctionPassManager.AddPromoteMemoryToRegisterPass( );

            if (!DisableOptimizations)
            {
                FunctionPassManager.AddInstructionCombiningPass( )
                .AddReassociatePass( )
                .AddGVNPass( )
                .AddCFGSimplificationPass( );
            }

            FunctionPassManager.Initialize( );
        }
예제 #4
0
        private void InitializeModuleAndPassManager(string sourcePath)
        {
            Module = Context.CreateBitcodeModule(Path.GetFileName(sourcePath), SourceLanguage.C, sourcePath, "Kaleidoscope Compiler");
            Module.TargetTriple = TargetMachine.Triple;
            Module.Layout       = TargetMachine.TargetData;
            DoubleType          = new DebugBasicType(Context.DoubleType, Module, "double", DiTypeKind.Float);

            FunctionPassManager = new FunctionPassManager(Module);
            FunctionPassManager.AddPromoteMemoryToRegisterPass( );

            if (!DisableOptimizations)
            {
                FunctionPassManager.AddInstructionCombiningPass( )
                .AddReassociatePass( )
                .AddGVNPass( )
                .AddCFGSimplificationPass( );
            }

            FunctionPassManager.Initialize( );
        }
예제 #5
0
        public CodeGenerator(DynamicRuntimeState globalState, TargetMachine machine, string sourcePath, bool disableOptimization = false)
            : base(null)
        {
            globalState.ValidateNotNull(nameof(globalState));
            machine.ValidateNotNull(nameof(machine));
            if (globalState.LanguageLevel > LanguageLevel.MutableVariables)
            {
                throw new ArgumentException("Language features not supported by this generator", nameof(globalState));
            }

            RuntimeState         = globalState;
            Context              = new Context( );
            TargetMachine        = machine;
            DisableOptimizations = disableOptimization;
            InstructionBuilder   = new InstructionBuilder(Context);

            #region InitializeModuleAndPassManager
            Module = Context.CreateBitcodeModule(Path.GetFileName(sourcePath), SourceLanguage.C, sourcePath, "Kaleidoscope Compiler");
            Debug.Assert(Module.DICompileUnit != null, "Expected non null compile unit");
            Debug.Assert(Module.DICompileUnit.File != null, "Expected non-null file for compile unit");

            Module.TargetTriple = machine.Triple;
            Module.Layout       = TargetMachine.TargetData;
            DoubleType          = new DebugBasicType(Context.DoubleType, Module, "double", DiTypeKind.Float);

            FunctionPassManager = new FunctionPassManager(Module);
            FunctionPassManager.AddPromoteMemoryToRegisterPass( );

            if (!DisableOptimizations)
            {
                FunctionPassManager.AddInstructionCombiningPass( )
                .AddReassociatePass( )
                .AddGVNPass( )
                .AddCFGSimplificationPass( );
            }

            FunctionPassManager.Initialize( );
            #endregion
        }