83 Error(pos,
"Type \"%s\" cannot be qualified with both uniform and varying.", type->
GetString().c_str());
86 if ((typeQualifiers & TYPEQUAL_UNIFORM) != 0) {
88 Error(pos,
"\"uniform\" qualifier is illegal with \"void\" type.");
91 }
else if ((typeQualifiers & TYPEQUAL_VARYING) != 0) {
93 Error(pos,
"\"varying\" qualifier is illegal with \"void\" type.");
103 Error(pos,
"Illegal to apply both \"signed\" and \"unsigned\" " 107 if (unsignedType != NULL)
111 Error(pos,
"\"unsigned\" qualifier is illegal with \"%s\" type.", resolvedType->
GetString().c_str());
118 "\"signed\" qualifier is illegal with non-integer type " 150 if (retType == NULL) {
151 Warning(pos,
"No type specified in declaration. Assuming int32.");
156 const AtomicType *atomicType = CastType<AtomicType>(retType);
157 if (atomicType == NULL) {
158 Error(pos,
"Only atomic types (int, float, ...) are legal for vector " 168 const StructType *st = CastType<StructType>(retType);
172 "Illegal to provide soa<%d> qualifier with non-struct " 178 "soa<%d> width illegal. Value must be positive power " 186 "\"uniform\" qualifier and \"soa<%d>\" qualifier can't " 187 "both be used in a type declaration.",
192 "\"varying\" qualifier and \"soa<%d>\" qualifier can't " 193 "both be used in a type declaration.",
199 if (soaWidth < g->target->getVectorWidth())
201 "soa<%d> width smaller than gang size %d " 202 "currently leads to inefficient code to access " 211 switch (storageClass) {
217 return "extern \"C\"";
223 FATAL(
"Unhandled storage class in lGetStorageClassName");
267 "__declspec specifiers for non-function type \"%s\" are " 274 printf(
"%*cdeclarator: [", indent,
' ');
280 printf(
"%s",
name.c_str());
304 FATAL(
"Unhandled declarator kind");
315 printf(
"\n%*cfunc param %d:\n", indent,
' ', i);
334 if (hasUniformQual && hasVaryingQual) {
335 Error(
pos,
"Can't provide both \"uniform\" and \"varying\" qualifiers.");
339 Error(
pos,
"\"task\" qualifier illegal in variable declaration.");
343 Error(
pos,
"\"unmasked\" qualifier illegal in variable declaration.");
347 Error(
pos,
"\"export\" qualifier illegal in variable declaration.");
354 else if (hasVaryingQual)
375 if (hasUniformQual) {
376 Error(
pos,
"\"uniform\" qualifier is illegal to apply to references.");
379 if (hasVaryingQual) {
380 Error(
pos,
"\"varying\" qualifier is illegal to apply to references.");
384 Error(
pos,
"\"const\" qualifier is to illegal apply to references.");
388 if (CastType<ReferenceType>(baseType) != NULL) {
389 Error(
pos,
"References to references are illegal.");
402 Error(
pos,
"Arrays of \"void\" type are illegal.");
405 if (CastType<ReferenceType>(baseType)) {
406 Error(
pos,
"Arrays of references (type \"%s\") are illegal.", baseType->
GetString().c_str());
419 llvm::SmallVector<const Type *, 8> args;
420 llvm::SmallVector<std::string, 8> argNames;
421 llvm::SmallVector<Expr *, 8> argDefaults;
422 llvm::SmallVector<SourcePos, 8> argPos;
443 if (decl == NULL || decl->type == NULL) {
448 if (decl->name ==
"") {
451 snprintf(buf,
sizeof(buf),
"__anon_parameter_%d", i);
458 "Storage class \"%s\" is illegal in " 459 "function parameter declaration for parameter \"%s\".",
461 if (decl->type->IsVoidType()) {
462 Error(decl->pos,
"Parameter with type \"void\" illegal in function " 467 const ArrayType *at = CastType<ArrayType>(decl->type);
478 if (targetType == NULL) {
487 at = CastType<ArrayType>(targetType);
489 if (at->GetElementCount() == 0)
490 Error(decl->pos,
"Arrays with unsized dimensions in " 491 "dimensions after the first one are illegal in " 492 "function parameter lists.");
493 at = CastType<ArrayType>(at->GetElementType());
497 args.push_back(decl->type);
498 argNames.push_back(decl->name);
499 argPos.push_back(decl->pos);
503 while (decl != NULL) {
504 if (decl->initExpr != NULL) {
505 decl->initExpr =
TypeCheck(decl->initExpr);
506 decl->initExpr =
Optimize(decl->initExpr);
507 if (decl->initExpr != NULL) {
508 init = llvm::dyn_cast<
ConstExpr>(decl->initExpr);
512 Error(decl->initExpr->pos,
513 "Default value for parameter " 514 "\"%s\" must be a compile-time constant.",
521 argDefaults.push_back(init);
524 const Type *returnType = baseType;
525 if (returnType == NULL) {
526 Error(
pos,
"No return type provided in function declaration.");
530 if (CastType<FunctionType>(returnType) != NULL) {
531 Error(
pos,
"Illegal to return function type from function.");
542 if (isExported && isTask) {
543 Error(
pos,
"Function can't have both \"task\" and \"export\" " 547 if (isExternC && isTask) {
548 Error(
pos,
"Function can't have both \"extern \"C\"\" and \"task\" " 552 if (isExternC && isExported) {
553 Error(
pos,
"Function can't have both \"extern \"C\"\" and \"export\" " 557 if (isUnmasked && isExported)
558 Warning(
pos,
"\"unmasked\" qualifier is redundant for exported " 567 isExported, isExternC, isUnmasked);
571 for (
int i = 0; i < (int)ds->
declSpecList.size(); ++i) {
576 (
const_cast<FunctionType *
>(functionType))->isSafe =
true;
577 else if (!strncmp(str.c_str(),
"cost", 4)) {
578 int cost = atoi(str.c_str() + 4);
580 Error(ds_spec_pos,
"Negative function cost %d is illegal.", cost);
581 (
const_cast<FunctionType *
>(functionType))->costOverride = cost;
583 Error(ds_spec_pos,
"__declspec parameter \"%s\" unknown.", str.c_str());
599 declarators = *dlist;
600 for (
unsigned int i = 0; i < declarators.size(); ++i)
601 if (declarators[i] != NULL)
602 declarators[i]->InitFromDeclSpecs(declSpecs);
609 declarators.push_back(d);
615 std::vector<VariableDeclaration> vars;
617 for (
unsigned int i = 0; i < declarators.size(); ++i) {
619 if (decl == NULL || decl->
type == NULL) {
626 Error(decl->
pos,
"\"void\" type variable illegal in declaration.");
627 else if (CastType<FunctionType>(decl->
type) == NULL) {
641 for (
unsigned int i = 0; i < declarators.size(); ++i) {
643 if (decl == NULL || decl->
type == NULL) {
660 printf(
"%*cDeclaration: specs [", indent,
' ');
662 printf(
"], declarators:\n");
663 for (
unsigned int i = 0; i < declarators.size(); ++i)
664 declarators[i]->
Print(indent + 4);
670 llvm::SmallVector<const Type *, 8> *elementTypes,
671 llvm::SmallVector<std::string, 8> *elementNames,
672 llvm::SmallVector<SourcePos, 8> *elementPositions) {
673 std::set<std::string> seenNames;
674 for (
unsigned int i = 0; i < sd.size(); ++i) {
692 for (
unsigned int j = 0; j < sd[i]->declarators->size(); ++j) {
697 Error(d->
pos,
"\"void\" type illegal for struct member.");
699 elementTypes->push_back(d->
type);
701 if (seenNames.find(d->
name) != seenNames.end())
703 "Struct member \"%s\" has same name as a " 704 "previously-declared member.",
707 seenNames.insert(d->
name);
709 elementNames->push_back(d->
name);
710 elementPositions->push_back(d->
pos);
714 for (
int i = 0; i < (int)elementTypes->size() - 1; ++i) {
715 const ArrayType *arrayType = CastType<ArrayType>((*elementTypes)[i]);
718 Error((*elementPositions)[i],
"Unsized arrays aren't allowed except " 719 "for the last member in a struct definition.");
virtual bool IsIntType() const =0
virtual const Type * GetAsVaryingType() const =0
bool IsUniformType() const
void InitFromType(const Type *base, DeclSpecs *ds)
void Print(int indent) const
#define TYPEQUAL_NOINLINE
virtual const Type * GetAsUnsignedType() const
virtual const Type * ResolveUnboundVariability(Variability v) const =0
std::vector< VariableDeclaration > GetVariableDeclarations() const
bool IsVaryingType() const
bool ContainsType(const Type *type) const
std::vector< std::pair< std::string, SourcePos > > declSpecList
#define AssertPos(pos, expr)
An expression that represents a NULL pointer.
Declaration(DeclSpecs *ds, std::vector< Declarator *> *dlist=NULL)
#define TYPEQUAL_UNSIGNED
ASTNode * TypeCheck(ASTNode *root)
const AtomicType * GetAsUnboundVariabilityType() const
bool AddVariable(Symbol *symbol)
Expression representing a compile-time constant value.
void InitFromDeclSpecs(DeclSpecs *ds)
const Type * GetElementType() const
void AddFunctionDeclaration(const std::string &name, const FunctionType *ftype, StorageClass sc, bool isInline, bool isNoInline, SourcePos pos)
StorageClass storageClass
const Type * GetBaseType(SourcePos pos) const
Declarator(DeclaratorKind dk, SourcePos p)
Type implementation for pointers to other types.
virtual void Print() const =0
static PointerType * GetUniform(const Type *t, bool isSlice=false)
header file with declarations for symbol and symbol table classes.
const StructType * GetAsSOAType(int width) const
Type representing a reference to another (non-reference) type.
File with declarations for classes related to statements in the language.
void PerformanceWarning(SourcePos p, const char *fmt,...)
static const Type * lApplyTypeQualifiers(int typeQualifiers, const Type *type, SourcePos pos)
DeclSpecs(const Type *t=NULL, StorageClass sc=SC_NONE, int tq=TYPEQUAL_NONE)
Representation of a structure holding a number of members.
std::vector< Declaration * > functionParams
AtomicType represents basic types like floats, ints, etc.
#define TYPEQUAL_UNMASKED
Representation of a range of positions in a source file.
virtual std::string GetString() const =0
StorageClass storageClass
Representation of a full declaration of one or more variables, including the shared DeclSpecs as well...
Declarations related to type declarations; the parser basically creates instances of these classes...
void Error(SourcePos p, const char *fmt,...)
int getVectorWidth() const
A (short) vector of atomic types.
virtual const Type * GetAsUniformType() const =0
Representation of the declaration of a single variable.
std::vector< Declarator * > declarators
const DeclaratorKind kind
static const AtomicType * UniformInt32
Type representing a function (return type + argument types)
Representation of a program symbol.
Interface class that defines the type abstraction.
Expr abstract base class and expression implementations.
virtual const Type * GetAsConstType() const =0
int GetElementCount() const
Expr is the abstract base class that defines the interface that all expression types must implement...
void GetStructTypesNamesPositions(const std::vector< StructDeclaration *> &sd, llvm::SmallVector< const Type *, 8 > *elementTypes, llvm::SmallVector< std::string, 8 > *elementNames, llvm::SmallVector< SourcePos, 8 > *elementPositions)
ASTNode * Optimize(ASTNode *root)
static const char * lGetStorageClassName(StorageClass storageClass)
void Print(int indent) const
Declaration of the Module class, which is the ispc-side representation of the results of compiling a ...
virtual const Type * GetAsUnboundVariabilityType() const =0
void Warning(SourcePos p, const char *fmt,...)
static void lPrintTypeQualifiers(int typeQualifiers)
SymbolTable * symbolTable
File with declarations for classes related to type representation.
Representation of the declaration specifiers in a declaration.
One-dimensional array type.