ROSE 创建模板类变量的一个取巧办法

问题

用ROSE产生cuda代码时,为了性能需要,使用到了纹理存储器。但在纹理存储器变量声明的时候,遇到了点问题:纹理寄存器变量的类型是模板类实例,e.g,texture<DATATYPE,1,cudaReadModeElementType> t_a,但是rose中模板类变量貌似不怎么好声明,尝试了半天都没有成功。

解决方案

使用万金油式的buildOpaqueType直接创建模板类型,然后使用该类型创建纹理存储器变量

1
2
3
4
5
//create a template instance type directly: texture<DATATYPE,1,cudaReadModelElementType>
SgType* textureType=buildOpaqueType("texture<DATATYPE,1,cudaReadModelElementType>",node->get_scope());

//create the texture type variable "texture_a"
SgVariableDeclaration* vdecl=buildVariableDeclaration("texture_a",textureType,node->get_scope());