summaryrefslogtreecommitdiff
path: root/Source/GPUVerify/GPUVerifier.cs
diff options
context:
space:
mode:
authorGravatar paulthomson <unknown>2012-02-09 23:05:50 +0000
committerGravatar paulthomson <unknown>2012-02-09 23:05:50 +0000
commitd4df20f16944dbb4181d9fdd2820be919296afaf (patch)
tree8eeb451e86e6fc5b25d9f88d5a97e821295be108 /Source/GPUVerify/GPUVerifier.cs
parent30231b61979a4c2639f9a48c89a7b4ea81876e6b (diff)
Fix: Check for duplicate special constants (with attributes).
Diffstat (limited to 'Source/GPUVerify/GPUVerifier.cs')
-rw-r--r--Source/GPUVerify/GPUVerifier.cs113
1 files changed, 51 insertions, 62 deletions
diff --git a/Source/GPUVerify/GPUVerifier.cs b/Source/GPUVerify/GPUVerifier.cs
index dd2a5227..2f9be79b 100644
--- a/Source/GPUVerify/GPUVerifier.cs
+++ b/Source/GPUVerify/GPUVerifier.cs
@@ -155,8 +155,35 @@ namespace GPUVerify
}
}
- private void FindNonLocalVariables(Program program)
+
+ private void ReportMultipleAttributeError(string attribute, IToken first, IToken second)
+ {
+ Error(
+ second,
+ "Can only have one {0} attribute, but previously saw this attribute at ({1}, {2})",
+ attribute,
+ first.filename,
+ first.line, first.col - 1);
+ }
+
+ private bool setConstAttributeField(Constant constInProgram, string attr, ref Constant constFieldRef)
+ {
+ if (QKeyValue.FindBoolAttribute(constInProgram.Attributes, attr))
+ {
+ if (constFieldRef != null)
+ {
+ ReportMultipleAttributeError(attr, constFieldRef.tok, constInProgram.tok);
+ return false;
+ }
+ CheckSpecialConstantType(constInProgram);
+ constFieldRef = constInProgram;
+ }
+ return true;
+ }
+
+ private bool FindNonLocalVariables(Program program)
{
+ bool success = true;
foreach (Declaration D in program.TopLevelDeclarations)
{
if (D is Variable && (D as Variable).IsMutable)
@@ -176,69 +203,28 @@ namespace GPUVerify
else if (D is Constant)
{
Constant C = D as Constant;
- if(QKeyValue.FindBoolAttribute(C.Attributes, LOCAL_ID_X_STRING))
- {
- CheckSpecialConstantType(C);
- _X = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, LOCAL_ID_Y_STRING))
- {
- CheckSpecialConstantType(C);
- _Y = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, LOCAL_ID_Z_STRING))
- {
- CheckSpecialConstantType(C);
- _Z = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_SIZE_X_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_SIZE_X = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_SIZE_Y_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_SIZE_Y = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_SIZE_Z_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_SIZE_Z = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_ID_X_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_X = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_ID_Y_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_Y = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, GROUP_ID_Z_STRING))
- {
- CheckSpecialConstantType(C);
- _GROUP_Z = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, NUM_GROUPS_X_STRING))
- {
- CheckSpecialConstantType(C);
- _NUM_GROUPS_X = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, NUM_GROUPS_Y_STRING))
- {
- CheckSpecialConstantType(C);
- _NUM_GROUPS_Y = C;
- }
- if (QKeyValue.FindBoolAttribute(C.Attributes, NUM_GROUPS_Z_STRING))
- {
- CheckSpecialConstantType(C);
- _NUM_GROUPS_Z = C;
- }
+
+ success &= setConstAttributeField(C, LOCAL_ID_X_STRING, ref _X);
+ success &= setConstAttributeField(C, LOCAL_ID_Y_STRING, ref _Y);
+ success &= setConstAttributeField(C, LOCAL_ID_Z_STRING, ref _Z);
+
+ success &= setConstAttributeField(C, GROUP_SIZE_X_STRING, ref _GROUP_SIZE_X);
+ success &= setConstAttributeField(C, GROUP_SIZE_Y_STRING, ref _GROUP_SIZE_Y);
+ success &= setConstAttributeField(C, GROUP_SIZE_Z_STRING, ref _GROUP_SIZE_Z);
+
+ success &= setConstAttributeField(C, GROUP_ID_X_STRING, ref _GROUP_X);
+ success &= setConstAttributeField(C, GROUP_ID_Y_STRING, ref _GROUP_Y);
+ success &= setConstAttributeField(C, GROUP_ID_Z_STRING, ref _GROUP_Z);
+
+ success &= setConstAttributeField(C, NUM_GROUPS_X_STRING, ref _NUM_GROUPS_X);
+ success &= setConstAttributeField(C, NUM_GROUPS_Y_STRING, ref _NUM_GROUPS_Y);
+ success &= setConstAttributeField(C, NUM_GROUPS_Z_STRING, ref _NUM_GROUPS_Z);
+
}
}
+
+ return success;
}
private void CheckSpecialConstantType(Constant C)
@@ -2209,7 +2195,10 @@ namespace GPUVerify
Error(BarrierProcedure, "Barrier procedure must not return any results");
}
- FindNonLocalVariables(Program);
+ if (!FindNonLocalVariables(Program))
+ {
+ return ErrorCount;
+ }
CheckKernelImplementation();