/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="compilerTrace">The compiler trace.</param> /// <param name="compilerOptions">The compiler options.</param> /// <param name="architecture">The architecture.</param> /// <param name="simAdapter">The sim adapter.</param> /// <param name="linker">The linker.</param> /// <returns></returns> public static SimCompiler Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, CompilerTrace compilerTrace, CompilerOptions compilerOptions, BaseArchitecture architecture, ISimAdapter simAdapter, BaseLinker linker) { var compiler = new SimCompiler(architecture, typeSystem, typeLayout, linker, compilerOptions, compilerTrace, simAdapter); compiler.Compile(); return compiler; }
/// <summary> /// Initializes a new instance of the <see cref="MosaTypeLayout" /> class. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="nativePointerSize">Size of the native pointer.</param> /// <param name="nativePointerAlignment">The native pointer alignment.</param> public MosaTypeLayout(TypeSystem typeSystem, int nativePointerSize, int nativePointerAlignment) { Debug.Assert(nativePointerSize == 4 || nativePointerSize == 8); NativePointerAlignment = nativePointerAlignment; NativePointerSize = nativePointerSize; TypeSystem = typeSystem; ResolveLayouts(); }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param> /// <param name="architecture">The architecture.</param> /// <param name="simAdapter">The sim adapter.</param> /// <param name="linker">The linker.</param> /// <returns></returns> public static SimCompiler Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, bool enabledSSA, BaseArchitecture architecture, ISimAdapter simAdapter, ILinker linker) { CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = enabledSSA; compilerOptions.EnableSSAOptimizations = enabledSSA; SimCompiler compiler = new SimCompiler(architecture, typeSystem, typeLayout, linker, compilerOptions, internalTrace, simAdapter); compiler.Compile(); return compiler; }
public CompilationScheduler(TypeSystem typeSystem, bool compileAllMethods) { this.typeSystem = typeSystem; this.compileAllMethods = compileAllMethods; if (compileAllMethods) { // forces all types to get compiled foreach (MosaType type in typeSystem.AllTypes) { CompileType(type); } } }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="compilerTrace">The compiler trace.</param> /// <param name="platform">The platform.</param> /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param> /// <param name="enableOptimizations">if set to <c>true</c> [enable ssa optimizations].</param> /// <param name="emitBinary">if set to <c>true</c> [emit binary].</param> public static void Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, CompilerTrace compilerTrace, string platform, CompilerOptions compilerOptions, bool emitBinary) { BaseArchitecture architecture; switch (platform.ToLower()) { case "x86": architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; case "armv6": architecture = Mosa.Platform.ARMv6.Architecture.CreateArchitecture(Mosa.Platform.ARMv6.ArchitectureFeatureFlags.AutoDetect); break; //case "avr32": architecture = Mosa.Platform.AVR32.Architecture.CreateArchitecture(Mosa.Platform.AVR32.ArchitectureFeatureFlags.AutoDetect); break; default: architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; } var compiler = new ExplorerCompiler(architecture, typeSystem, typeLayout, compilerTrace, compilerOptions, emitBinary); compiler.Compile(); }
/// <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="compilerTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> public ExplorerCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, CompilerTrace compilerTrace, CompilerOptions compilerOptions, bool emitBinary) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), compilerTrace, new ExplorerLinker(), compilerOptions) { this.emitBinary = emitBinary; // Build the assembly compiler pipeline Pipeline.Add(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeInitializerSchedulerStage(), new MethodLookupTableStage(), new MethodExceptionLookupTableStage(), new MetadataStage(), }); architecture.ExtendCompilerPipeline(Pipeline); }
/// <summary> /// Prevents a default instance of the <see cref="SimCompiler" /> 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="linker">The linker.</param> /// <param name="compilerOptions">The compiler options.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="simAdapter">The sim adapter.</param> public SimCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ILinker linker, CompilerOptions compilerOptions, IInternalTrace internalTrace, ISimAdapter simAdapter) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, linker, compilerOptions) { this.simAdapter = simAdapter; // Build the assembly compiler pipeline Pipeline.Add(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeInitializerSchedulerStage(), new SimPowerUpStage(), new TypeLayoutStage(), new MetadataStage(), new LinkerFinalizationStage(), }); architecture.ExtendCompilerPipeline(Pipeline); }
/// <summary> /// Initializes a new compiler instance. /// </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="compilationScheduler">The compilation scheduler.</param> /// <param name="compilerTrace">The compiler trace.</param> /// <param name="linker">The linker.</param> /// <param name="compilerOptions">The compiler options.</param> /// <exception cref="System.ArgumentNullException">@Architecture</exception> protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, CompilerTrace compilerTrace, BaseLinker linker, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"Architecture"); Pipeline = new CompilerPipeline(); Architecture = architecture; TypeSystem = typeSystem; TypeLayout = typeLayout; CompilerTrace = compilerTrace; CompilerOptions = compilerOptions; Counters = new Counters(); CompilationScheduler = compilationScheduler; PlugSystem = new PlugSystem(); Linker = linker; if (Linker == null) { Linker = compilerOptions.LinkerFactory(); Linker.Initialize(compilerOptions.BaseAddress, architecture.Endianness, architecture.ElfMachineType); } // Create new dictionary IntrinsicTypes = new Dictionary<string, Type>(); // Get all the classes that implement the IIntrinsicInternalMethod interface IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(IIntrinsicInternalMethod).IsAssignableFrom(p) && p.IsClass); // Iterate through all the found types foreach (var t in types) { // Now get all the ReplacementTarget attributes var attributes = (ReplacementTargetAttribute[])t.GetCustomAttributes(typeof(ReplacementTargetAttribute), true); for (int i = 0; i < attributes.Length; i++) { // Finally add the dictionary entry mapping the target string and the type IntrinsicTypes.Add(attributes[i].Target, t); } } PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="platform">The platform.</param> /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param> /// <param name="emitBinary">if set to <c>true</c> [emit binary].</param> public static void Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, string platform, bool enabledSSA, bool emitBinary) { BaseArchitecture architecture; switch (platform.ToLower()) { case "x86": architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; case "armv6": architecture = Mosa.Platform.ARMv6.Architecture.CreateArchitecture(Mosa.Platform.ARMv6.ArchitectureFeatureFlags.AutoDetect); break; //case "avr32": architecture = Mosa.Platform.AVR32.Architecture.CreateArchitecture(Mosa.Platform.AVR32.ArchitectureFeatureFlags.AutoDetect); break; default: architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; } CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = enabledSSA; compilerOptions.EnableSSAOptimizations = enabledSSA && enabledSSA; ExplorerCompiler compiler = new ExplorerCompiler(architecture, typeSystem, typeLayout, internalTrace, compilerOptions, emitBinary); compiler.Compile(); }
/// <summary> /// Initializes a new compiler instance. /// </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="compilationScheduler">The compilation scheduler.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, ILinker linker, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"Architecture"); Pipeline = new CompilerPipeline(); Architecture = architecture; TypeSystem = typeSystem; TypeLayout = typeLayout; InternalTrace = internalTrace; CompilerOptions = compilerOptions; Counters = new Counters(); CompilationScheduler = compilationScheduler; PlugSystem = new PlugSystem(); Linker = linker; if (Linker == null) { Linker = compilerOptions.LinkerFactory(); Linker.Initialize(compilerOptions.OutputFile, architecture.Endianness, architecture.ElfMachineType); } }
private static void AddArrayMethods(TypeSystem typeSystem, MosaType arrayType, MosaType.Mutator type, MosaArrayInfo info) { // Remove all methods & fields --> Since BaseType = System.Array, they're automatically inherited. type.Methods.Clear(); type.Fields.Clear(); // Add three array accessors as defined in standard (Get, Set, Address) // Also, constructor. uint rank = info.Rank; MosaMethod methodGet = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodGet)) { method.DeclaringType = arrayType; method.Name = "Get"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; List<MosaParameter> parameters = new List<MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodGet; } parameters.Add(indexParam); } method.Signature = new MosaMethodSignature(arrayType.ElementType, parameters); } type.Methods.Add(methodGet); MosaMethod methodSet = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodSet)) { method.DeclaringType = arrayType; method.Name = "Set"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; List<MosaParameter> parameters = new List<MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodSet; } parameters.Add(indexParam); } var valueParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(valueParam)) { mosaParameter.Name = "value"; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = arrayType.ElementType; mosaParameter.DeclaringMethod = methodSet; } parameters.Add(valueParam); method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters); } type.Methods.Add(methodSet); MosaMethod methodAdrOf = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodAdrOf)) { method.DeclaringType = arrayType; method.Name = "AddressOr"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; List<MosaParameter> parameters = new List<MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodAdrOf; } parameters.Add(indexParam); } method.Signature = new MosaMethodSignature(arrayType.ElementType.ToManagedPointer(), parameters); } type.Methods.Add(methodAdrOf); MosaMethod methodCtor = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodCtor)) { method.DeclaringType = arrayType; method.Name = ".ctor"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; List<MosaParameter> parameters = new List<MosaParameter>(); for (uint i = 0; i < rank; i++) { var lengthParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(lengthParam)) { mosaParameter.Name = "length" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodCtor; } parameters.Add(lengthParam); } method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters); } type.Methods.Add(methodCtor); }
/// <summary> /// Initializes a new instance of the <see cref="AotCompiler" /> class. /// </summary> /// <param name="architecture">The 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 AotCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, null, compilerOptions) { }
/// <summary> /// Creates the low 32 bit portion of a 64-bit <see cref="Operand"/>. /// </summary> /// <param name="longOperand">The long operand.</param> /// <param name="offset">The offset.</param> /// <param name="index">The index.</param> /// <returns></returns> public static Operand CreateLowSplitForLong(TypeSystem typeSystem, Operand longOperand, int offset, int index) { Debug.Assert(longOperand.IsLong); Debug.Assert(longOperand.SplitParent == null); Debug.Assert(longOperand.Low == null); Operand operand; if (longOperand.IsConstant) { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsConstant = true; operand.ConstantUnsignedLongInteger = longOperand.ConstantUnsignedLongInteger & uint.MaxValue; } else if (longOperand.IsField) { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsMemoryAddress = true; operand.IsField = true; operand.Field = longOperand.Field; operand.Type = longOperand.Type; operand.OffsetBase = longOperand.OffsetBase; operand.Displacement = longOperand.Displacement + offset; operand.Register = longOperand.Register; } else if (longOperand.IsMemoryAddress) { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsMemoryAddress = true; operand.OffsetBase = longOperand.OffsetBase; operand.Displacement = longOperand.Displacement + offset; operand.Register = longOperand.Register; } else { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsVirtualRegister = true; } operand.SplitParent = longOperand; Debug.Assert(longOperand.Low == null); longOperand.Low = operand; operand.Index = index; //operand.sequence = index; return operand; }
/// <summary> /// Creates a new constant <see cref="Operand" /> for the given integral value. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="value">The value to create the constant operand for.</param> /// <returns> /// A new operand representing the value <paramref name="value" />. /// </returns> public static Operand CreateConstant(TypeSystem typeSystem, long value) { var operand = new Operand(typeSystem.BuiltIn.I8); operand.IsConstant = true; operand.ConstantSignedLongInteger = value; return operand; }
/// <summary> /// Creates the symbol. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="name">The name.</param> /// <returns></returns> public static Operand CreateUnmanagedSymbolPointer(TypeSystem typeSystem, string name) { var operand = new Operand(typeSystem.BuiltIn.Pointer); operand.IsSymbol = true; operand.Name = name; return operand; }
/// <summary> /// Creates the string symbol with data. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="name">The name.</param> /// <param name="data">The string data.</param> /// <returns></returns> public static Operand CreateStringSymbol(TypeSystem typeSystem, string name, string data) { Debug.Assert(data != null); var operand = new Operand(typeSystem.BuiltIn.String); operand.IsSymbol = true; operand.Name = name; operand.StringData = data; return operand; }
public void Compile() { HasCompileError = true; Log.Clear(); Counters.Clear(); var compiler = new MosaCompiler(); try { CompileStartTime = DateTime.Now; CompiledFile = Path.Combine(Options.DestinationDirectory, Path.GetFileNameWithoutExtension(Options.SourceFile) + ".bin"); compiler.CompilerFactory = delegate { return new AotCompiler(); }; compiler.CompilerOptions.EnableSSA = Options.EnableSSA; compiler.CompilerOptions.EnableOptimizations = Options.EnableIROptimizations; compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = Options.EnableSparseConditionalConstantPropagation; compiler.CompilerOptions.EnableInlinedMethods = Options.EnableInlinedMethods; compiler.CompilerOptions.InlinedIRMaximum = Options.InlinedIRMaximum; compiler.CompilerOptions.EnableVariablePromotion = Options.EnableVariablePromotion; compiler.CompilerOptions.OutputFile = CompiledFile; compiler.CompilerOptions.Architecture = SelectArchitecture(Options.PlatformType); compiler.CompilerOptions.LinkerFormatType = Options.LinkerFormatType; compiler.CompilerOptions.BootStageFactory = GetBootStageFactory(Options.BootFormat); compiler.CompilerOptions.SetCustomOption("multiboot.video", Options.VBEVideo ? "true" : "false"); compiler.CompilerOptions.SetCustomOption("multiboot.width", Options.Width.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.height", Options.Height.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.depth", Options.Depth.ToString()); compiler.CompilerOptions.BaseAddress = Options.BaseAddress; compiler.CompilerOptions.EmitSymbols = Options.EmitSymbols; compiler.CompilerOptions.EmitRelocations = Options.EmitRelocations; compiler.CompilerOptions.SetCustomOption("x86.irq-methods", Options.Emitx86IRQMethods ? "true" : "false"); if (Options.GenerateMapFile) { compiler.CompilerOptions.MapFile = Path.Combine(Options.DestinationDirectory, Path.GetFileNameWithoutExtension(Options.SourceFile) + ".map"); } if (!Directory.Exists(Options.DestinationDirectory)) { Directory.CreateDirectory(Options.DestinationDirectory); } compiler.CompilerTrace.TraceListener = traceListener; if (string.IsNullOrEmpty(Options.SourceFile)) { AddOutput("Please select a source file"); return; } else if (!File.Exists(Options.SourceFile)) { AddOutput(string.Format("File {0} does not exists", Options.SourceFile)); return; } var inputFiles = new List<FileInfo>(); inputFiles.Add(new FileInfo(Options.SourceFile)); compiler.Load(inputFiles); var threads = Options.UseMultipleThreadCompiler ? Environment.ProcessorCount : 1; compiler.Execute(threads); Linker = compiler.Linker; TypeSystem = compiler.TypeSystem; if (Options.ImageFormat == ImageFormat.ISO) { if (Options.BootLoader == BootLoader.Grub_0_97 || Options.BootLoader == BootLoader.Grub_2_00) { CreateISOImageWithGrub(CompiledFile); } else // assuming syslinux { CreateISOImageWithSyslinux(CompiledFile); } } else { CreateDiskImage(CompiledFile); if (Options.ImageFormat == ImageFormat.VMDK) { CreateVMDK(ImageFile); } } HasCompileError = false; if (Options.GenerateASMFile) { LaunchNDISASM(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { compiler.Dispose(); compiler = null; } }
/// <summary> /// Initializes a new instance of <see cref="BaseCodeEmitter" />. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="linker">The linker.</param> /// <param name="codeStream">The stream the machine code is written to.</param> /// <param name="typeSystem">The type system.</param> public void Initialize(string methodName, BaseLinker linker, Stream codeStream, TypeSystem typeSystem) { Debug.Assert(codeStream != null); Debug.Assert(linker != null); this.MethodName = methodName; this.linker = linker; this.codeStream = codeStream; this.TypeSystem = typeSystem; }
private static void AddArrayMethods(TypeSystem typeSystem, MosaType arrayType, MosaType.Mutator type, MosaArrayInfo info) { // Remove all methods & fields --> Since BaseType = System.Array, they're automatically inherited. type.Methods.Clear(); type.Fields.Clear(); // Add three array accessors as defined in standard (Get, Set, Address) // Also, constructor. uint rank = info.Rank; var methodGet = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodGet)) { method.DeclaringType = arrayType; method.Name = "Get"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; var parameters = new List <MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodGet; } parameters.Add(indexParam); } method.Signature = new MosaMethodSignature(arrayType.ElementType, parameters); } type.Methods.Add(methodGet); var methodSet = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodSet)) { method.DeclaringType = arrayType; method.Name = "Set"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; var parameters = new List <MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodSet; } parameters.Add(indexParam); } var valueParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(valueParam)) { mosaParameter.Name = "value"; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = arrayType.ElementType; mosaParameter.DeclaringMethod = methodSet; } parameters.Add(valueParam); method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters); } type.Methods.Add(methodSet); var methodAdrOf = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodAdrOf)) { method.DeclaringType = arrayType; method.Name = "AddressOr"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; var parameters = new List <MosaParameter>(); for (uint i = 0; i < rank; i++) { var indexParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam)) { mosaParameter.Name = "index" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodAdrOf; } parameters.Add(indexParam); } method.Signature = new MosaMethodSignature(arrayType.ElementType.ToManagedPointer(), parameters); } type.Methods.Add(methodAdrOf); var methodCtor = typeSystem.Controller.CreateMethod(); using (var method = typeSystem.Controller.MutateMethod(methodCtor)) { method.DeclaringType = arrayType; method.Name = ".ctor"; method.IsInternalCall = true; method.IsRTSpecialName = method.IsSpecialName = true; method.IsFinal = true; method.HasThis = true; var parameters = new List <MosaParameter>(); for (uint i = 0; i < rank; i++) { var lengthParam = typeSystem.Controller.CreateParameter(); using (var mosaParameter = typeSystem.Controller.MutateParameter(lengthParam)) { mosaParameter.Name = "length" + i; mosaParameter.ParameterAttributes = MosaParameterAttributes.In; mosaParameter.ParameterType = typeSystem.BuiltIn.I4; mosaParameter.DeclaringMethod = methodCtor; } parameters.Add(lengthParam); } method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters); } type.Methods.Add(methodCtor); }
public TypeSystemController(TypeSystem typeSystem) { this.typeSystem = typeSystem; }
/// <summary> /// Setups the specified compiler. /// </summary> /// <param name="compiler">The compiler.</param> void IMethodCompilerStage.Initialize(BaseMethodCompiler compiler) { MethodCompiler = compiler; BasicBlocks = compiler.BasicBlocks; Architecture = compiler.Architecture; TypeSystem = compiler.TypeSystem; TypeLayout = compiler.TypeLayout; CallingConvention = Architecture.CallingConvention; NativePointerSize = Architecture.NativePointerSize; NativeAlignment = Architecture.NativeAlignment; NativeInstructionSize = Architecture.NativeInstructionSize; MethodData = MethodCompiler.MethodData; traceLogs = new List<TraceLog>(); Setup(); }
/// <summary> /// Reserves the stack size for call. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="context">The context.</param> /// <param name="stackSize">Size of the stack.</param> /// <param name="scratch">The scratch.</param> private void ReserveStackSizeForCall(TypeSystem typeSystem, Context context, int stackSize, Operand scratch) { if (stackSize == 0) return; Operand stackPointer = Operand.CreateCPURegister(typeSystem.BuiltIn.Pointer, architecture.StackPointerRegister); architecture.InsertSubInstruction(context, stackPointer, stackPointer, Operand.CreateConstant(typeSystem.BuiltIn.I4, stackSize)); architecture.InsertMoveInstruction(context, scratch, stackPointer); }
public void Initialize(MosaCompiler compiler) { if (compiler == null) throw new ArgumentNullException(@"compiler"); Compiler = compiler; Architecture = Compiler.CompilerOptions.Architecture; TypeSystem = Compiler.TypeSystem; TypeLayout = Compiler.TypeLayout; CompilerTrace = Compiler.CompilerTrace; CompilerOptions = Compiler.CompilerOptions; CompilationScheduler = Compiler.CompilationScheduler; Linker = compiler.Linker; PreCompilePipeline = new CompilerPipeline(); PostCompilePipeline = new CompilerPipeline(); GlobalCounters = new Counters(); PlugSystem = new PlugSystem(); CompilerData = new CompilerData(); // Create new dictionary IntrinsicTypes = new Dictionary<string, Type>(); foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (type.IsClass && typeof(IIntrinsicInternalMethod).IsAssignableFrom(type)) { // Now get all the ReplacementTarget attributes var attributes = (ReplacementTargetAttribute[])type.GetCustomAttributes(typeof(ReplacementTargetAttribute), true); for (int i = 0; i < attributes.Length; i++) { // Finally add the dictionary entry mapping the target string and the type IntrinsicTypes.Add(attributes[i].Target, type); } } } PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); InternalRuntimeType = GeInternalRuntimeType(); // Extended Setup ExtendCompilerSetup(); // Build the default pre-compiler pipeline Architecture.ExtendPreCompilerPipeline(PreCompilePipeline); // Build the default post-compiler pipeline Architecture.ExtendPostCompilerPipeline(PostCompilePipeline); }
public void Load(TypeSystem typeSystem) { TypeSystem = typeSystem; TypeLayout = new MosaTypeLayout(typeSystem, CompilerOptions.Architecture.NativePointerSize, CompilerOptions.Architecture.NativeAlignment); CompilationScheduler = new CompilationScheduler(); }
/// <summary> /// Creates a new symbol <see cref="Operand" /> for the given symbol name. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="method">The method.</param> /// <returns></returns> public static Operand CreateSymbolFromMethod(TypeSystem typeSystem, MosaMethod method) { var operand = CreateUnmanagedSymbolPointer(typeSystem, method.FullName); operand.Method = method; return operand; }
public void LoadAssembly(string filename) { MosaModuleLoader moduleLoader = new MosaModuleLoader(); moduleLoader.AddPrivatePath(System.IO.Path.GetDirectoryName(filename)); moduleLoader.LoadModuleFromFile(filename); TypeSystem = TypeSystem.Load(moduleLoader.CreateMetadata()); TypeLayout = new MosaTypeLayout(TypeSystem, 4, 4); assembliesView.UpdateTree(); }
/// <summary> /// Gets the null constant <see cref="Operand"/>. /// </summary> /// <returns></returns> public static Operand GetNull(TypeSystem typeSystem) { var operand = new Operand(typeSystem.BuiltIn.Object); operand.IsNull = true; operand.IsConstant = true; return operand; }
/// <summary> /// Creates a new constant <see cref="Operand"/> for the given integral value. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="value">The value to create the constant operand for.</param> /// <returns> /// A new operand representing the value <paramref name="value"/>. /// </returns> public static Operand CreateConstant(TypeSystem typeSystem, float value) { var operand = new Operand(typeSystem.BuiltIn.R4); operand.IsConstant = true; operand.ConstantSingleFloatingPoint = value; operand.IsResolved = true; return operand; }
/// <summary> /// Creates a new constant <see cref="Operand"/> for the given integral value. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="value">The value to create the constant operand for.</param> /// <returns> /// A new operand representing the value <paramref name="value"/>. /// </returns> public static Operand CreateConstant(TypeSystem typeSystem, double value) { var operand = new Operand(typeSystem.BuiltIn.R8); operand.IsConstant = true; operand.ConstantDoubleFloatingPoint = value; return operand; }
/// <summary> /// Creates the low 32 bit portion of a 64-bit <see cref="Operand" />. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="longOperand">The long operand.</param> /// <param name="index">The index.</param> /// <returns></returns> public static Operand CreateLowSplitForLong(TypeSystem typeSystem, Operand longOperand, int index) { Debug.Assert(longOperand.IsLong); Debug.Assert(longOperand.SplitParent == null); Debug.Assert(longOperand.Low == null); Operand operand = null; if (longOperand.IsResolvedConstant) { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsConstant = true; operand.IsResolved = true; operand.ConstantUnsignedLongInteger = longOperand.ConstantUnsignedLongInteger & uint.MaxValue; } else if (longOperand.IsVirtualRegister) { operand = new Operand(typeSystem.BuiltIn.U4); operand.IsVirtualRegister = true; } else if (longOperand.IsStackLocal) { operand = longOperand; } Debug.Assert(operand != null); operand.SplitParent = longOperand; operand.Index = index; longOperand.Low = operand; return operand; }
public void ScheduleAll(TypeSystem typeSystem) { foreach (var type in typeSystem.AllTypes) { Schedule(type); } }
public void Initialize(MosaCompiler compiler) { if (compiler == null) throw new ArgumentNullException(@"compiler"); Compiler = compiler; Architecture = Compiler.CompilerOptions.Architecture; TypeSystem = Compiler.TypeSystem; TypeLayout = Compiler.TypeLayout; CompilerTrace = Compiler.CompilerTrace; CompilerOptions = Compiler.CompilerOptions; CompilationScheduler = Compiler.CompilationScheduler; Linker = compiler.Linker; PreCompilePipeline = new CompilerPipeline(); PostCompilePipeline = new CompilerPipeline(); Counters = new Counters(); PlugSystem = new PlugSystem(); CompilerData = new CompilerData(this); // Create new dictionary IntrinsicTypes = new Dictionary<string, Type>(); // Get all the classes that implement the IIntrinsicInternalMethod interface IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(IIntrinsicInternalMethod).IsAssignableFrom(p) && p.IsClass); // Iterate through all the found types foreach (var t in types) { // Now get all the ReplacementTarget attributes var attributes = (ReplacementTargetAttribute[])t.GetCustomAttributes(typeof(ReplacementTargetAttribute), true); for (int i = 0; i < attributes.Length; i++) { // Finally add the dictionary entry mapping the target string and the type IntrinsicTypes.Add(attributes[i].Target, t); } } PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); // Extended Setup ExtendCompilerSetup(); // Build the default pre-compiler pipeline Architecture.ExtendPreCompilerPipeline(this.PreCompilePipeline); // Build the default post-compiler pipeline Architecture.ExtendPostCompilerPipeline(this.PostCompilePipeline); }