Exemplo n.º 1
0
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Save the Compiler
            _compiler = compiler;
            // The compilation target Architecture
            _architecture = compiler.Architecture;
            // The type system
            _typeSystem = RuntimeBase.Instance.TypeLoader;

            // Enumerate all types and do an appropriate type layout
            ReadOnlyRuntimeTypeListView types = _typeSystem.GetTypesFromModule (compiler.Assembly);
            foreach (RuntimeType type in types)
            {
                switch (type.Attributes & TypeAttributes.LayoutMask) {
                case TypeAttributes.AutoLayout:
                    goto case TypeAttributes.SequentialLayout;

                case TypeAttributes.SequentialLayout:
                    CreateSequentialLayout (type);
                    break;

                case TypeAttributes.ExplicitLayout:
                    CreateExplicitLayout (type);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Save the Compiler
            _compiler = compiler;
            // The compilation target Architecture
            _architecture = compiler.Architecture;
            // The type system
            _typeSystem = RuntimeBase.Instance.TypeLoader;

            // Enumerate all types and do an appropriate type layout
            ReadOnlyRuntimeTypeListView types = _typeSystem.GetTypesFromModule(compiler.Assembly);

            foreach (RuntimeType type in types)
            {
                switch (type.Attributes & TypeAttributes.LayoutMask)
                {
                case TypeAttributes.AutoLayout:
                    goto case TypeAttributes.SequentialLayout;

                case TypeAttributes.SequentialLayout:
                    CreateSequentialLayout(type);
                    break;

                case TypeAttributes.ExplicitLayout:
                    CreateExplicitLayout(type);
                    break;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
        /// </summary>
        /// <param name="architecture">The architecture of the calling convention.</param>
        /// <param name="typeLayout">The type layout.</param>
        public DefaultCallingConvention(IArchitecture architecture)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.architecture = architecture;
        }
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture  = compiler.Architecture;
     typeSystem    = compiler.TypeSystem;
     typeLayout    = compiler.TypeLayout;
 }
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture = compiler.Architecture;
     typeSystem = compiler.TypeSystem;
     typeLayout = compiler.TypeLayout;
 }
Exemplo n.º 6
0
 public TestCaseMethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method) :
     base(linker, architecture, module, type, method)
 {
     // Populate the pipeline
     this.Pipeline.AddRange(new IMethodCompilerStage[] {
         new DecodingStage(),
         new BasicBlockBuilderStage(),
         new OperandDeterminationStage(),
         new InstructionLogger(typeof(OperandDeterminationStage)),
         //new ConstantFoldingStage(),
         new CILTransformationStage(),
         //new InstructionLogger(typeof(CILTransformationStage)),
         //InstructionStatisticsStage.Instance,
         //new DominanceCalculationStage(),
         //new EnterSSA(),
         //new ConstantPropagationStage(),
         //new ConstantFoldingStage(),
         //new LeaveSSA(),
         new StackLayoutStage(),
         new InstructionLogger(typeof(StackLayoutStage)),
         //new BlockReductionStage(),
         new LoopAwareBlockOrderStage(),
         //new SimpleTraceBlockOrderStage(),
         //new ReverseBlockOrderStage(),  // reverse all the basic blocks and see if it breaks anything
         //new BasicBlockOrderStage()
         new CodeGenerationStage(),
         //new InstructionLogger(typeof(CodeGenerationStage)),
         // new InstructionLogger(typeof(CodeGenerationStage)),
     });
 }
Exemplo n.º 7
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (_pipeline == null)
            {
                throw new ObjectDisposedException("MethodCompilerBase");
            }

            foreach (IMethodCompilerStage mcs in _pipeline)
            {
                IDisposable d = mcs as IDisposable;
                if (null != d)
                {
                    d.Dispose();
                }
            }

            _pipeline.Clear();
            _pipeline = null;

            _architecture   = null;
            _linker         = null;
            _method         = null;
            _module         = null;
            _type           = null;
            _instructionSet = null;
            _basicBlocks    = null;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
        /// </summary>
        /// <param name="architecture">The architecture of the calling convention.</param>
        public DefaultCallingConvention(IArchitecture architecture)
        {
            if (null == architecture)
                throw new ArgumentNullException ("architecture");

            _architecture = architecture;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (pipeline == null)
            {
                throw new ObjectDisposedException(@"MethodCompilerBase");
            }

            foreach (IMethodCompilerStage mcs in pipeline)
            {
                IDisposable d = mcs as IDisposable;
                if (null != d)
                {
                    d.Dispose();
                }
            }

            pipeline.Clear();
            pipeline = null;

            architecture   = null;
            linker         = null;
            method         = null;
            type           = null;
            instructionSet = null;
            basicBlocks    = null;
        }
 public TestCaseMethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method)
     : base(linker, architecture, module, type, method)
 {
     // Populate the pipeline
     this.Pipeline.AddRange(new IMethodCompilerStage[] {
         new DecodingStage(),
         new BasicBlockBuilderStage(),
         new OperandDeterminationStage(),
         new InstructionLogger(),
         //new ConstantFoldingStage(),
         new CILTransformationStage(),
         //new InstructionLogger(),
         //InstructionStatisticsStage.Instance,
         //new DominanceCalculationStage(),
         //new EnterSSA(),
         //new ConstantPropagationStage(),
         //new ConstantFoldingStage(),
         //new LeaveSSA(),
         new StackLayoutStage(),
         new PlatformStubStage(),
         new InstructionLogger(),
         //new BlockReductionStage(),
         new LoopAwareBlockOrderStage(),
         //new SimpleTraceBlockOrderStage(),
         //new ReverseBlockOrderStage(),  // reverse all the basic blocks and see if it breaks anything
         //new BasicBlockOrderStage()
         new CodeGenerationStage(),
         //new InstructionLogger(),
     });
 }
Exemplo n.º 11
0
        public MethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method, Stream codeStream)
            : base(linker, architecture, module, type, method)
        {
            if (null == codeStream)
                throw new ArgumentNullException(@"codeStream");

            _codeStream = codeStream;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
        /// </summary>
        /// <param name="architecture">The architecture of the calling convention.</param>
        /// <param name="typeLayout">The type layout.</param>
        public DefaultCallingConvention(IArchitecture architecture, ITypeLayout typeLayout)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.architecture = architecture;
            this.typeLayout = typeLayout;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinObjectFile"/> class.
 /// </summary>
 /// <param name="format">The object file format.</param>
 /// <param name="architecture">The architecture.</param>
 /// <param name="name">The name of the object file; or <see langword="null"/>.</param>
 internal BinObjectFile(BinObjectFileFormat format, IArchitecture architecture, string name)
     : base(format, architecture, name)
 {
     #region Contract
     Contract.Requires<ArgumentNullException>(format != null);
     Contract.Requires<ArgumentNullException>(architecture != null);
     #endregion
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinObjectFile"/> class.
 /// </summary>
 /// <param name="format">The object file format.</param>
 /// <param name="architecture">The architecture.</param>
 /// <param name="name">The name of the object file; or <see langword="null"/>.</param>
 internal BinObjectFile(BinObjectFileFormat format, IArchitecture architecture, string name)
     : base(format, architecture, name)
 {
     #region Contract
     Contract.Requires <ArgumentNullException>(format != null);
     Contract.Requires <ArgumentNullException>(architecture != null);
     #endregion
 }
Exemplo n.º 15
0
        public override MethodCompilerBase CreateMethodCompiler(RuntimeType type, RuntimeMethod method)
        {
            IArchitecture      arch = this.Architecture;
            MethodCompilerBase mc   = new TestCaseMethodCompiler(this.Pipeline.Find <IAssemblyLinker>(), this.Architecture, this.Assembly, type, method);

            arch.ExtendMethodCompilerPipeline(mc.Pipeline);
            return(mc);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
        /// </summary>
        /// <param name="architecture">The architecture of the calling convention.</param>
        /// <param name="typeLayout">The type layout.</param>
        public DefaultCallingConvention(IArchitecture architecture)
        {
            if (architecture == null)
            {
                throw new ArgumentNullException(@"architecture");
            }

            this.architecture = architecture;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        protected AssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.architecture = architecture;
            this.pipeline = new CompilerPipeline();
            this.typeSystem = typeSystem;
        }
Exemplo n.º 18
0
        public CompilerState(ZinniaBuilder Builder, MessageStrings Strings, IArchitecture Arch, Language Language)
        {
            Messages = new MessageList(Strings);

            this.Builder  = Builder;
            this.Arch     = Arch;
            this.Language = Language;
            this.Strings  = Strings;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultCallingConvention"/>.
        /// </summary>
        /// <param name="architecture">The architecture of the calling convention.</param>
        public DefaultCallingConvention(IArchitecture architecture)
        {
            if (null == architecture)
            {
                throw new ArgumentNullException("architecture");
            }

            _architecture = architecture;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="assembly">The assembly of this compiler.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="architecture"/> or <paramref name="assembly"/> is null.</exception>
        protected AssemblyCompiler(IArchitecture architecture, IMetadataModule assembly)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            _architecture = architecture;
            _assembly = assembly;
            _pipeline = new CompilerPipeline();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Setups the specified compiler.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        public void Setup(IMethodCompiler compiler)
        {
            if (compiler == null)
                throw new ArgumentNullException ("compiler");

            MethodCompiler = compiler;
            InstructionSet = compiler.InstructionSet;
            BasicBlocks = compiler.BasicBlocks;
            Architecture = compiler.Architecture;
        }
Exemplo n.º 22
0
        public MethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method, Stream codeStream) :
            base(linker, architecture, module, type, method)
        {
            if (null == codeStream)
            {
                throw new ArgumentNullException(@"codeStream");
            }

            _codeStream = codeStream;
        }
Exemplo n.º 23
0
 public override void RemoveLinkedArchitecture()
 {
     if (_currentArchitecture != null)
     {
         IArchitecture oldArchitecture = _currentArchitecture;
         _currentArchitecture.UnregisterArchitecture();
         _currentArchitecture = null;
         OnArchitectureChanged(oldArchitecture, null);
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Adds the additional options for the parsing process to the given OptionSet.
 /// </summary>
 /// <param name="optionSet">A given OptionSet to add the options to.</param>
 public void AddOptions(OptionSet optionSet)
 {
     optionSet.Add(
         "a|Architecture=",
         "Select one of the MOSA architectures to compile for [{x86}].",
         delegate(string arch)
     {
         this.implementation = SelectImplementation(arch);
     }
         );
 }
Exemplo n.º 25
0
 public Hooker()
 {
     if (IntPtr.Size == 8)
     {
         arch = new ArchitectureX64();
     }
     else
     {
         arch = new ArchitectureX86();
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="assembly">The assembly of this compiler.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="architecture"/> or <paramref name="assembly"/> is null.</exception>
        protected AssemblyCompiler(IArchitecture architecture, IMetadataModule assembly)
        {
            if (architecture == null)
            {
                throw new ArgumentNullException("architecture");
            }

            _architecture = architecture;
            _assembly     = assembly;
            _pipeline     = new CompilerPipeline();
        }
Exemplo n.º 27
0
 public void Initialize()
 {
     m_Arch = new Architecture("Default", new Dictionary <int, IOperationConverter>
     {
         { 0, new NoOpConverter() }
     },
                               new List <OperationDefinition>
     {
         new OperationDefinition(0, 0)
     });
 }
 private TestCaseAssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem)
     : base(architecture, typeSystem)
 {
     // Build the assembly compiler pipeline
     Pipeline.AddRange(new IAssemblyCompilerStage[] {
         new TypeLayoutStage(),
         new AssemblyMemberCompilationSchedulerStage(),
         new MethodCompilerSchedulerStage(),
         new TestAssemblyLinker(),
     });
     architecture.ExtendAssemblyCompilerPipeline(Pipeline);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Creates a method compiler
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="method">The method to compile.</param>
        /// <returns>
        /// An instance of a MethodCompilerBase for the given type/method pair.
        /// </returns>
        public override MethodCompilerBase CreateMethodCompiler(RuntimeType type, RuntimeMethod method)
        {
            IArchitecture      arch = this.Architecture;
            MethodCompilerBase mc   = new AotMethodCompiler(
                this,
                type,
                method
                );

            arch.ExtendMethodCompilerPipeline(mc.Pipeline);
            return(mc);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        protected AssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout)
        {
            if (architecture == null)
            {
                throw new ArgumentNullException(@"architecture");
            }

            this.architecture = architecture;
            this.pipeline     = new CompilerPipeline();
            this.typeSystem   = typeSystem;
            this.typeLayout   = typeLayout;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Setups the specified compiler.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        public void Setup(IMethodCompiler compiler)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }

            MethodCompiler = compiler;
            InstructionSet = compiler.InstructionSet;
            BasicBlocks    = compiler.BasicBlocks;
            Architecture   = compiler.Architecture;
        }
Exemplo n.º 32
0
        public static void Compile(ITypeSystem typeSystem)
        {
            IArchitecture architecture = x86.Architecture.CreateArchitecture(x86.ArchitectureFeatureFlags.AutoDetect);

            // FIXME: get from architecture
            TypeLayout typeLayout = new TypeLayout(typeSystem, 4, 4);

            CompilerHelper compiler = new CompilerHelper(architecture, typeSystem, typeLayout);

            compiler.Compile();

            //return compiler.linker;
        }
Exemplo n.º 33
0
 public AotAssemblyCompiler(IArchitecture architecture, IMetadataModule assembly, ITypeInitializerSchedulerStage typeInitializerSchedulerStage, IAssemblyLinker linker)
     : base(architecture, assembly)
 {
     this.Pipeline.AddRange(
             new IAssemblyCompilerStage[]
             {
                 new TypeLayoutStage(),
                 new AssemblyMemberCompilationSchedulerStage(),
                 new MethodCompilerSchedulerStage(),
                 new TypeInitializerSchedulerStageProxy(typeInitializerSchedulerStage),
                 new LinkerProxy(linker)
             });
 }
Exemplo n.º 34
0
 public AotAssemblyCompiler(IArchitecture architecture, ITypeInitializerSchedulerStage typeInitializerSchedulerStage, IAssemblyLinker linker, ITypeSystem typeSystem, ITypeLayout typeLayout)
     : base(architecture, typeSystem, typeLayout)
 {
     this.Pipeline.AddRange(
         new IAssemblyCompilerStage[]
     {
         new AssemblyMemberCompilationSchedulerStage(),
         new MethodCompilerSchedulerStage(),
         new TypeInitializerSchedulerStageProxy(typeInitializerSchedulerStage),
         new TypeLayoutStage(),
         new LinkerProxy(linker)
     });
 }
Exemplo n.º 35
0
        public static TestAssemblyLinker Compile(ITypeSystem typeSystem)
        {
            IArchitecture architecture = x86.Architecture.CreateArchitecture(x86.ArchitectureFeatureFlags.AutoDetect);

            // FIXME: get from architecture
            TypeLayout typeLayout = new TypeLayout(typeSystem, 4, 4);

            TestCaseAssemblyCompiler compiler = new TestCaseAssemblyCompiler(architecture, typeSystem, typeLayout);

            compiler.Compile();

            return(compiler.linker);
        }
Exemplo n.º 36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectFile"/> class with the specified name.
        /// </summary>
        /// <param name="format">The format of the object file.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="name">The name of the object file; or <see langword="null"/> to specify no name.</param>
        public ObjectFile(IObjectFileFormat format, IArchitecture architecture, string name)
        {
            #region Contract
            Contract.Requires<ArgumentNullException>(format != null);
            Contract.Requires<ArgumentNullException>(architecture != null);
            Contract.Requires<ArgumentException>(format.IsSupportedArchitecture(architecture));
            #endregion

            this.format = format;
            this.architecture = architecture;
            this.sections = new SectionCollection(this);
            this.AssociatedSymbol = new Symbol(SymbolType.None, name);
        }
Exemplo n.º 37
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        protected AssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.pipeline = new CompilerPipeline();
            this.architecture = architecture;
            this.typeSystem = typeSystem;
            this.typeLayout = typeLayout;
            this.internalTrace = internalTrace;
            this.compilerOptions = compilerOptions;
            this.genericTypePatcher = new GenericTypePatcher(typeSystem);
        }
Exemplo n.º 38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectFile"/> class with the specified name.
        /// </summary>
        /// <param name="format">The format of the object file.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="name">The name of the object file; or <see langword="null"/> to specify no name.</param>
        public ObjectFile(IObjectFileFormat format, IArchitecture architecture, string name)
        {
            #region Contract
            Contract.Requires <ArgumentNullException>(format != null);
            Contract.Requires <ArgumentNullException>(architecture != null);
            Contract.Requires <ArgumentException>(format.IsSupportedArchitecture(architecture));
            #endregion

            this.format           = format;
            this.architecture     = architecture;
            this.sections         = new SectionCollection(this);
            this.AssociatedSymbol = new Symbol(SymbolType.None, name);
        }
 private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module)
     : base(architecture, module)
 {
     // Build the assembly compiler pipeline
     CompilerPipeline pipeline = this.Pipeline;
     pipeline.AddRange(new IAssemblyCompilerStage[] {
         new TypeLayoutStage(),
         new AssemblyMemberCompilationSchedulerStage(),
         new MethodCompilerSchedulerStage(),
         new TestAssemblyLinker(),
     });
     architecture.ExtendAssemblyCompilerPipeline(pipeline);
 }
Exemplo n.º 40
0
        /// <summary>
        /// Prevents a default instance of the <see cref="ExplorerCompiler"/> class from being created.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        public ExplorerCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
            : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, compilerOptions)
        {
            // Build the assembly compiler pipeline
            Pipeline.AddRange(new ICompilerStage[] {
                new PlugStage(),
                new MethodCompilerSchedulerStage(),
                new TypeLayoutStage(),
                (ExplorerLinker)Linker
            });

            architecture.ExtendCompilerPipeline(Pipeline);
        }
Exemplo n.º 41
0
        //private readonly Queue<CCtor> cctorQueue = new Queue<CCtor>();
        //private readonly TestAssemblyLinker linker;
        private CompilerHelper(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout)
            : base(architecture, typeSystem, typeLayout)
        {
            var linker = new LinkerStub();

            // Build the assembly compiler pipeline
            Pipeline.AddRange(new IAssemblyCompilerStage[] {
                new AssemblyMemberCompilationSchedulerStage(),
                new MethodCompilerSchedulerStage(),
                new TypeLayoutStage(),
                linker
            });
            architecture.ExtendAssemblyCompilerPipeline(Pipeline);
        }
Exemplo n.º 42
0
        /// <summary>
        /// Computes the field offset.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="metadataProvider">The metadata provider.</param>
        /// <param name="architecture">The architecture.</param>
        /// <returns></returns>
        public static int ComputeFieldOffset(ISignatureContext context, TokenTypes token, IMetadataProvider metadataProvider, IArchitecture architecture)
        {
            Metadata.Tables.TypeDefRow typeDefinition;
            Metadata.Tables.TypeDefRow followingTypeDefinition;
            metadataProvider.Read(token, out typeDefinition);
            metadataProvider.Read(token + 1, out followingTypeDefinition);

            int result = 0;
            TokenTypes fieldList = typeDefinition.FieldList;
            while (fieldList != token)
                result += FieldSize(context, fieldList++, metadataProvider, architecture);

            return result;
        }
Exemplo n.º 43
0
        public void Reset()
        {
            ObjectFiles = new List <string>();
            Archives    = new List <string>();
            ZinniaFiles = new List <string>();
            Assemblies  = new List <AssemblyPath>();
            IncBins     = new List <IncBinReference>();

            Dir      = ZinniaLib = Entry = OutFile = null;
            Arch     = null;
            Language = null;
            State    = null;
            Format   = AssemblyFormat.Unknown;
        }
Exemplo n.º 44
0
        //private readonly Queue<CCtor> cctorQueue = new Queue<CCtor>();

        //private readonly TestAssemblyLinker linker;

        private CompilerHelper(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout) :
            base(architecture, typeSystem, typeLayout)
        {
            var linker = new LinkerStub();

            // Build the assembly compiler pipeline
            Pipeline.AddRange(new IAssemblyCompilerStage[] {
                new AssemblyMemberCompilationSchedulerStage(),
                new MethodCompilerSchedulerStage(),
                new TypeLayoutStage(),
                linker
            });
            architecture.ExtendAssemblyCompilerPipeline(Pipeline);
        }
        private ExplorerAssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
            : base(architecture, typeSystem, typeLayout, internalTrace, compilerOptions)
        {
            var linker = new ExplorerLinker();

            // Build the assembly compiler pipeline
            Pipeline.AddRange(new IAssemblyCompilerStage[] {
                new AssemblyMemberCompilationSchedulerStage(),
                new MethodCompilerSchedulerStage(),
                new TypeLayoutStage(),
                linker
            });

            architecture.ExtendAssemblyCompilerPipeline(Pipeline);
        }
Exemplo n.º 46
0
 private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module)
     : base(architecture, module)
 {
     // Build the assembly compiler pipeline
     CompilerPipeline pipeline = this.Pipeline;
     pipeline.AddRange(new IAssemblyCompilerStage[] {
         new TypeLayoutStage(),
         new MethodCompilerBuilderStage(),
         new MethodCompilerRunnerStage(),
         // __grover, 01/02/2009: No object files in test!
         // new ObjectFileLayoutStage()
         new TestAssemblyLinker(),
     });
     architecture.ExtendAssemblyCompilerPipeline(pipeline);
 }
Exemplo n.º 47
0
        private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module) :
            base(architecture, module)
        {
            // Build the assembly compiler pipeline
            CompilerPipeline pipeline = this.Pipeline;

            pipeline.AddRange(new IAssemblyCompilerStage[] {
                new TypeLayoutStage(),
                new MethodCompilerBuilderStage(),
                new MethodCompilerRunnerStage(),
                // __grover, 01/02/2009: No object files in test!
                // new ObjectFileLayoutStage()
                new TestAssemblyLinker(),
            });
            architecture.ExtendAssemblyCompilerPipeline(pipeline);
        }
Exemplo n.º 48
0
        /// <inheritdoc />
        public bool IsSupportedArchitecture(IArchitecture architecture)
        {
            var x86arch = architecture as SharpAssembler.Architectures.X86.X86Architecture;

            if (x86arch == null)
            {
                return(false);
            }
            if (x86arch.AddressSize != DataSize.Bit64 &&
                x86arch.AddressSize != DataSize.Bit32 &&
                x86arch.AddressSize != DataSize.Bit16)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 49
0
        private bool LookupAndLinkNewArchitecture()
        {
            ILibrary lib = Service <ILibrary> .Instance;

            if (lib.ContainsArchitecture(this))
            {
                IArchitecture oldArchitecture = _currentArchitecture;
                RemoveLinkedArchitecture();
                _currentArchitecture = lib.LookupArchitecture(this).InstantiateToPort(this);
                OnArchitectureChanged(oldArchitecture, _currentArchitecture);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 50
0
        /// <summary>
        /// Fields the size.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="metadataProvider">The metadata provider.</param>
        /// <param name="architecture">The architecture.</param>
        /// <returns></returns>
        public static int FieldSize(ISignatureContext context, TokenTypes field, IMetadataProvider metadataProvider, IArchitecture architecture)
        {
            Metadata.Tables.FieldRow fieldRow;
            metadataProvider.Read(field, out fieldRow);
            FieldSignature signature = Signature.FromMemberRefSignatureToken(context, metadataProvider, fieldRow.SignatureBlobIdx) as FieldSignature;

            // If the field is another struct, we have to dig down and compute its size too.
            if (signature.Type.Type == CilElementType.ValueType)
            {
                TokenTypes valueTypeSig = ValueTokenTypeFromSignature(metadataProvider, fieldRow.SignatureBlobIdx);
                return ComputeTypeSize(context, valueTypeSig, metadataProvider, architecture);
            }

            int size, alignment;
            architecture.GetTypeRequirements(signature.Type, out size, out alignment);
            return size;
        }
Exemplo n.º 51
0
        private TestCaseAssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
            : base(architecture, typeSystem, typeLayout, internalTrace, compilerOptions)
        {
            linker = new TestAssemblyLinker();

            // Build the assembly compiler pipeline
            Pipeline.AddRange(new IAssemblyCompilerStage[] {
                new DelegateTypePatchStage(),
                new PlugStage(),
                new AssemblyMemberCompilationSchedulerStage(),
                new MethodCompilerSchedulerStage(),
                new TypeLayoutStage(),
                new MetadataStage(),
                linker
            });

            architecture.ExtendAssemblyCompilerPipeline(Pipeline);
        }
Exemplo n.º 52
0
        /// <summary>
        /// Setups the specified compiler.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        public void Setup(IMethodCompiler compiler)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }

            methodCompiler    = compiler;
            InstructionSet    = compiler.InstructionSet;
            basicBlocks       = compiler.BasicBlocks;
            architecture      = compiler.Architecture;
            typeModule        = compiler.Method.Module;
            typeSystem        = compiler.TypeSystem;
            typeLayout        = compiler.TypeLayout;
            callingConvention = architecture.GetCallingConvention();

            architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment);
        }
Exemplo n.º 53
0
        /// <summary>
        /// Prepares the evaluation stack.
        /// </summary>
        /// <param name="architecture">The architecture.</param>
        private void PrepareEvaluationStack(IArchitecture architecture)
        {
            /*
             * This register allocator uses two sets of registers to keep
             * parts of the evaluation stack in memory. The first set is used
             * for integers and the second set for floating point values.
             *
             */
            SigType i  = new SigType(CilElementType.I);
            SigType fp = new SigType(CilElementType.R8);

            Register[] registerSet = architecture.RegisterSet;
            int        iregs = 0, fpregs = 0;

            // Enumerate all registers, until we've found all needed registers
            foreach (Register reg in registerSet)
            {
                if (reg.IsFloatingPoint == false)
                {
                    // A general purpose register. Do we need to allocate a stack register?
                    if (iregs < RegisterStackSize)
                    {
                        this.stackRegistersI[iregs++] = new RegisterOperand(i, reg);
                    }
                }
                else
                {
                    // A floating point register. Do we need to allocate a stack register?
                    if (fpregs < RegisterStackSize)
                    {
                        this.stackRegistersFp[fpregs++] = new RegisterOperand(fp, reg);
                    }
                }

                // If we've allocated all registers, break the loop
                if (iregs == RegisterStackSize && fpregs == RegisterStackSize)
                {
                    break;
                }
            }
        }
Exemplo n.º 54
0
        /// <summary>
        /// Computes the size of the type.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="metadataProvider">The metadata provider.</param>
        /// <param name="architecture">The architecture.</param>
        /// <returns></returns>
        public static int ComputeTypeSize(ISignatureContext context, TokenTypes token, IMetadataProvider metadataProvider, IArchitecture architecture)
        {
            Metadata.Tables.TypeDefRow typeDefinition;
            Metadata.Tables.TypeDefRow followingTypeDefinition = new Mosa.Runtime.Metadata.Tables.TypeDefRow();
            metadataProvider.Read(token, out typeDefinition);
            try
            {
                metadataProvider.Read(token + 1, out followingTypeDefinition);
            }
            catch (System.Exception)
            {
            }

            int result = 0;
            TokenTypes fieldList = typeDefinition.FieldList;
            TokenTypes last = metadataProvider.GetMaxTokenValue(TokenTypes.Field);
            while (fieldList != followingTypeDefinition.FieldList && fieldList != last)
                result += FieldSize(context, fieldList++, metadataProvider, architecture);

            return result;
        }
        public TestCaseMethodCompiler(TestCaseAssemblyCompiler compiler, IArchitecture architecture, ICompilationSchedulerStage compilationScheduler, RuntimeType type, RuntimeMethod method)
            : base(compiler.Pipeline.FindFirst<IAssemblyLinker>(), architecture, compilationScheduler, type, method, compiler.TypeSystem, compiler.Pipeline.FindFirst<ITypeLayout>())
        {
            this.assemblyCompiler = compiler;

            // Populate the pipeline
            this.Pipeline.AddRange(new IMethodCompilerStage[] {
                new DecodingStage(),
                //new InstructionLogger(),
                new BasicBlockBuilderStage(),
                //new InstructionLogger(),
                new OperandDeterminationStage(),
                //new InstructionLogger(),
                new StaticAllocationResolutionStage(),
                //new InstructionLogger(),
                //new ConstantFoldingStage(),
                new CILTransformationStage(),
                //new InstructionLogger(),
                new CILLeakGuardStage() { MustThrowCompilationException = true },
                //new InstructionLogger(),
                //InstructionStatisticsStage.Instance,
                //new DominanceCalculationStage(),
                //new EnterSSA(),
                //new ConstantPropagationStage(),
                //new ConstantFoldingStage(),
                //new LeaveSSA(),
                new StackLayoutStage(),
                new PlatformStubStage(),
                //new InstructionLogger(),
                //new BlockReductionStage(),
                new LoopAwareBlockOrderStage(),
                //new SimpleTraceBlockOrderStage(),
                //new ReverseBlockOrderStage(),  // reverse all the basic blocks and see if it breaks anything
                //new BasicBlockOrderStage()
                new CodeGenerationStage(),
                //new InstructionLogger(),
            });
        }
 /// <inheritdoc />
 public bool IsSupportedArchitecture(IArchitecture architecture)
 {
     var x86arch = architecture as SharpAssembler.Architectures.X86.X86Architecture;
     if (x86arch == null)
         return false;
     if (x86arch.AddressSize != DataSize.Bit64 &&
         x86arch.AddressSize != DataSize.Bit32 &&
         x86arch.AddressSize != DataSize.Bit16)
         return false;
     return true;
 }
 /// <inheritdoc />
 public ObjectFile CreateObjectFile(IArchitecture architecture, string name)
 {
     return new BinObjectFile(this, architecture, name);
 }
 /// <inheritdoc />
 public ObjectFile CreateObjectFile(IArchitecture architecture)
 {
     return CreateObjectFile(architecture, null);
 }
Exemplo n.º 59
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualRegisterLayout"/> class.
 /// </summary>
 /// <param name="architecture">The architecture.</param>
 /// <param name="stackLayout">The stack layout.</param>
 public VirtualRegisterLayout(IArchitecture architecture, StackLayout stackLayout)
 {
     this.architecture = architecture;
     this.stackLayout = stackLayout;
 }
Exemplo n.º 60
0
        /// <summary>
        /// Setups the specified compiler.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        public void Setup(IMethodCompiler compiler)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");

            methodCompiler = compiler;
            instructionSet = compiler.InstructionSet;
            basicBlocks = compiler.BasicBlocks;
            architecture = compiler.Architecture;
            typeModule = compiler.Method.Module;
            typeSystem = compiler.TypeSystem;
            typeLayout = compiler.TypeLayout;
            callingConvention = architecture.GetCallingConvention();

            architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment);
        }