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; } } }
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 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)), }); }
/// <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; }
/// <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; }
/// <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(), }); }
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; }
/// <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 }
/// <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 }
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); }
/// <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; }
/// <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; }
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; }
/// <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; }
/// <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(); }
/// <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; }
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; }
public override void RemoveLinkedArchitecture() { if (_currentArchitecture != null) { IArchitecture oldArchitecture = _currentArchitecture; _currentArchitecture.UnregisterArchitecture(); _currentArchitecture = null; OnArchitectureChanged(oldArchitecture, null); } }
/// <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); } ); }
public Hooker() { if (IntPtr.Size == 8) { arch = new ArchitectureX64(); } else { arch = new ArchitectureX86(); } }
/// <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(); }
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); }
/// <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); }
/// <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; }
/// <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; }
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; }
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) }); }
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) }); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
//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); }
/// <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; }
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; }
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); }
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); }
/// <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); }
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); } }
/// <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; }
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); }
/// <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); }
/// <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; } } }
/// <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); }
/// <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; }
/// <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); }