[cfe-dev] Adding new data type
Olaf Krzikalla
Olaf.Krzikalla at tu-dresden.de
Fri Apr 30 00:48:38 PDT 2010
Hi,
kalyan ponnala schrieb:
> Thanks for the replies. I am trying to add support to a new
> architecture called Line Associative Registers. It has vector
> registers in it. I would like to add a vector data type such as int[4]
> which could access a register with a width of 4 integers in it (max).
> Since it has to be mentioned in the source as
>
> int[4] = {1, 2, 3, 4}
>
> I am not sure about how to proceed. This form looks like an array with
> 4 elements but I want it to be a datatype.
I had a similiar problem when I wanted to add SSE data types. First I
tried adding a new type to the type system too, but this was clearly the
wrong way. I recommend adding just a typedef, which then can act like a
built-in type. See my source code below (vecType should be int, float,
double or the like).
QualType StmtCollector::getSimdType(const QualType& vecType, unsigned
NumElts)
{
// Ctx is a ASTContext
BuiltinType *baseType =
dyn_cast<BuiltinType>(Ctx.getCanonicalType(vecType).getTypePtr());
assert(baseType != 0 && "getVectorType(): Expecting a built-in type");
TypedefDecl*& simdTypedef =
m_SimdTypedefDecl[tSimdTypedefDeclKey(baseType, NumElts)];
if (simdTypedef == 0)
{
const char* pTypeName;
if (baseType == Ctx.FloatTy.getTypePtr() && NumElts == 4)
{
pTypeName = "__m128";
}
else if (baseType == Ctx.DoubleTy.getTypePtr() && NumElts == 2)
{
pTypeName = "__m128d";
}
else
{
assert(0 && "simd type unsupported");
}
simdTypedef = TypedefDecl::Create(Ctx,
Ctx.getTranslationUnitDecl(),
SourceLocation(),
&Ctx.Idents.get(pTypeName),
Ctx.CreateTypeSourceInfo(Ctx.getVectorType(vecType, NumElts,
false, false)));
}
return Ctx.getTypedefType(simdTypedef);
}
Hth
Olaf Krzikalla
More information about the cfe-dev
mailing list