private Ast.Argument KernelArgument(Type type, string name) { Ast.Argument result; if (type.IsSubclassOf(typeof(KernelArg))) { var typeDef = type.GetGenericTypeDefinition(); var elemType = type.GetGenericArguments()[0]; result = typeDef == typeof(Value <>) ? ClcAst.KArg(elemType, name, ClcAst.KernelArgumentKind.Value) : typeDef == typeof(Buffer <>) ? ClcAst.KArg(elemType, name, ClcAst.KernelArgumentKind.Buffer, ClcAst.KernelArgumentMemory.Global) : null; if (result == null) { throw new ParseException("Argument groups are only valid as kernel arguments."); } } else { result = Ast.Arg(type, name); } _currentScope.AddLocal(name, result); return(result); }
private string CompileAndOutput(CLKernel[] kernels) { foreach (var kernel in kernels) { var body = Ast.Blk(); BeginScope(body); _function = ClcAst.Kern(kernel.Name, KernelArguments(kernel._expr.Parameters), body); OutputKernel(kernel._expr); _program.Functions.Add(Macro.InstantiateAllMacros(_function)); } return(_program.Output(this)); }
private void DeclareConstant(Type constType, string name, Expression value) { Ast.Constant con; if (constType.IsArray) { var nai = value.Expect <NewArrayExpression> (ExpressionType.NewArrayInit); con = Ast.Const(constType.GetElementType(), name, nai.Expressions.Count, Expr(value)); } else { con = Ast.Const(constType, name, Expr(value)); } AddGlobal(ClcAst.DeclConst(con)); _constants.Add(name, con); }
private void DefineStruct(Type structType, bool isUnion) { if (!DefineType(structType)) { return; } var name = StructTypeName(structType); var fields = from field in structType.GetCLFields() let fi = GetArrayLen(field, field.FieldType) select Ast.Fld(fi.Item1, field.Name, fi.Item2); AddGlobal(isUnion ? ClcAst.Union(name, fields) : ClcAst.Struct(name, fields)); }
protected override Ast.InitStruct InitStructure(Type type, IEnumerable <Tuple <Ast.VariableRef, Ast.Expression> > initFields) { return(ClcAst.InitS(type, initFields)); }
protected override Ast.NewArray ArrayConstant(Type type, int count, IEnumerable <Ast.Expression> items) { return(ClcAst.Arr(type, count, items)); }