/// <summary cref="IBackendCodeGenerator.GenerateCode(AddressSpaceCast)"/> public void GenerateCode(AddressSpaceCast value) { var targetType = value.TargetType as AddressSpaceType; var source = Load(value.Value); var target = Allocate(value); bool isOperation = CLInstructions.TryGetAddressSpaceCast( value.TargetAddressSpace, out string operation); void GeneratePointerCast(StatementEmitter statement) { if (isOperation) { // There is a specific cast operation statement.AppendCommand(operation); statement.BeginArguments(); statement.Append(source); } else { statement.AppendPointerCast(TypeGenerator[targetType.ElementType]); } statement.Append(source); } using (var statement = BeginStatement(target)) { GeneratePointerCast(statement); if (isOperation) { statement.EndArguments(); } } }
/// <summary cref="IValueVisitor.Visit(AddressSpaceCast)"/> public void Visit(AddressSpaceCast value) { var targetType = value.TargetType as AddressSpaceType; var target = AllocatePointerType(targetType.ElementType, value.TargetAddressSpace); PointerVariable address; if (value.IsPointerCast) { address = LoadAs <PointerVariable>(value.Value); Bind(value, target); } else { var viewSource = LoadAs <ViewVariable>(value.Value); address = viewSource.Pointer; var viewTarget = new ViewVariable( value.Type as ViewType, target, viewSource.Length); Bind(value, viewTarget); } if (CLInstructions.TryGetAddressSpaceCast( value.TargetAddressSpace, out string operation)) { // There is a specific cast operation using (var statement = BeginStatement(target)) { statement.AppendCommand(operation); statement.BeginArguments(); statement.AppendArgument(address); statement.EndArguments(); } } else { // Use an unspecific generic pointer cast using (var statement = BeginStatement(target)) { statement.AppendCast( TypeGenerator[targetType.ElementType] + CLInstructions.DereferenceOperation); statement.Append(address); } } }
/// <summary cref="IValueVisitor.Visit(AddressSpaceCast)"/> public void Visit(AddressSpaceCast value) { var targetType = value.TargetType as AddressSpaceType; var source = Load(value.Value); var target = Allocate(value); bool isOperation = CLInstructions.TryGetAddressSpaceCast( value.TargetAddressSpace, out string operation); void GeneratePointerCast(StatementEmitter statement) { if (isOperation) { // There is a specific cast operation statement.AppendCommand(operation); statement.BeginArguments(); statement.Append(source); } else { statement.AppendPointerCast(TypeGenerator[targetType.ElementType]); } statement.Append(source); } if (value.IsPointerCast) { using (var statement = BeginStatement(target)) { GeneratePointerCast(statement); if (isOperation) { statement.EndArguments(); } } } else { var targetView = target as ViewImplementationVariable; Declare(target); // Assign pointer using (var statement = BeginStatement(target, targetView.PointerFieldIndex)) { GeneratePointerCast(statement); statement.AppendField(targetView.PointerFieldIndex); if (isOperation) { statement.EndArguments(); } } // Assign length using (var statement = BeginStatement(target, targetView.LengthFieldIndex)) { statement.Append(source); statement.AppendField(targetView.LengthFieldIndex); } } }