public FormalParameter(Type type, StateSpaces stsp = StateSpaces.REG, PassingStyles style = PassingStyles.VAL) : base(type, stsp) { PassingStyle = style; }
public Argument(Type type, PassingStyles style = PassingStyles.VAL) : base(type, StateSpaces.REG, style) { }
public static Subprogram BuildIR(this MethodInfo method, IList <SpecialRegister> srpool, IDictionary <MethodInfo, Subprogram> spmap, bool anonymousKernel = false) { if (!method.IsStatic) { throw new ArgumentException("Only static methods are supported", "method"); } bool kernel = anonymousKernel || Attribute.GetCustomAttribute(method, typeof(KernelAttribute)) != null; bool result = method.ReturnType != typeof(void); if (kernel && result) { throw new ArgumentException("Kernels can not have return parameter", "method"); } List <FormalParameter> formalParameters = new List <FormalParameter>(method.GetParameters().Select(pi => { PassingStyles ps = pi.ParameterType.IsByRef ? pi.IsOut ? PassingStyles.OUT : PassingStyles.REF : PassingStyles.VAL; Type pt = pi.ParameterType.IsByRef ? pi.ParameterType.GetElementType() : pi.ParameterType; FormalParameter fp = pt.IsArray ? new FormalParameter(pt.GetElementType(), anonymousKernel ? StateSpaces.GLOBAL : (Attribute.GetCustomAttribute(pi, typeof(StateSpaceAttribute)) as StateSpaceAttribute).StateSpace, ps) : new Argument(pt, ps); fp.Name = pi.Name; return(fp); })); if (result) { FormalParameter returnParameter = method.ReturnType.IsArray ? new FormalParameter(method.ReturnType.GetElementType(), (Attribute.GetCustomAttribute(method.ReturnParameter, typeof(StateSpaceAttribute)) as StateSpaceAttribute).StateSpace, PassingStyles.OUT) : new Argument(method.ReturnType, PassingStyles.OUT); returnParameter.Name = method.Name; formalParameters.Add(returnParameter); } IList <FormalParameter> formalParametersRO = formalParameters.AsReadOnly(); IList <VirtualRegister> localVariablesRO = new List <VirtualRegister>(method.GetMethodBody().LocalVariables.Select(lvi => new VirtualRegister(InstructionSelector.UpconvertMapping[lvi.LocalType.IsArray ? typeof(int) : lvi.LocalType]))).AsReadOnly(); Subprogram subprogram = kernel ? new Kernel(formalParametersRO) : new Subprogram(formalParametersRO); subprogram.Name = method.Name; spmap.Add(method, subprogram); Func <Type, StateSpaces, InstructionSelector.DynamicRegister> regalloc = IRBuildOptions.WasteRegisters ? (Func <Type, StateSpaces, InstructionSelector.DynamicRegister>)RegisterAllocator.Waste : new RegisterAllocator().Allocate; subprogram.CFGRoot = BuildIRCFG(BuildCILCFG(method.GetInstructions().First()), new Stack <Tuple <Tuple <GenericOperand, bool>, InstructionSelector> >(), new Dictionary <CILBB, List <CILBBImplementation> >(), formalParametersRO, localVariablesRO, result, srpool, spmap, regalloc).AsBasicBlock; if (regalloc.Target != null && !(regalloc.Target as RegisterAllocator).FinishTest()) { throw new Exception("There is a bug in instruction selecting phase: we have live registers"); } return(subprogram); }
public FormalParameter(Type type, StateSpaces stsp = StateSpaces.REG, PassingStyles style = PassingStyles.VAL) : base(type, stsp) { PassingStyle = style; }