Add support for pointers to the language.

Pointers can be either uniform or varying, and behave correspondingly.
e.g.: "uniform float * varying" is a varying pointer to uniform float
data in memory, and "float * uniform" is a uniform pointer to varying
data in memory.  Like other types, pointers are varying by default.

Pointer-based expressions, & and *, sizeof, ->, pointer arithmetic,
and the array/pointer duality all bahave as in C.  Array arguments
to functions are converted to pointers, also like C.

There is a built-in NULL for a null pointer value; conversion from
compile-time constant 0 values to NULL still needs to be implemented.

Other changes:
- Syntax for references has been updated to be C++ style; a useful
  warning is now issued if the "reference" keyword is used.
- It is now illegal to pass a varying lvalue as a reference parameter
  to a function; references are essentially uniform pointers.
  This case had previously been handled via special case call by value
  return code.  That path has been removed, now that varying pointers
  are available to handle this use case (and much more).
- Some stdlib routines have been updated to take pointers as
  arguments where appropriate (e.g. prefetch and the atomics).
  A number of others still need attention.
- All of the examples have been updated
- Many new tests

TODO: documentation
This commit is contained in:
Matt Pharr
2011-11-21 09:16:29 -08:00
parent 15a7d353ab
commit 975db80ef6
191 changed files with 4746 additions and 3225 deletions

View File

@@ -0,0 +1,6 @@
// Can only pre/post increment numeric and pointer types
void foo() {
float a[5] = { 1,2,3,4,5};
++a;
}

View File

@@ -0,0 +1,6 @@
// ffofoof
void foo(float *x) {
float a[5] = { 1,2,3,4,5};
a = x;
}

View File

@@ -0,0 +1,10 @@
// ffofoof
struct Foo {
const int a;
};
void foo(Foo f) {
Foo a;
a = f;
}

View File

@@ -1,4 +1,4 @@
// Can't pre-increment
// Can't assign to type "const int32" on left-hand
int func() {
const int x = 2;

View File

@@ -0,0 +1,7 @@
// Can't assign to type "const int32" on left-hand side
const int x = 0;
void foo() {
++x;
}

View File

@@ -0,0 +1,5 @@
// operator "." can't be used with expression of "int32" type
int func(int *a) {
a.x = 0;
}

View File

@@ -0,0 +1,7 @@
// operator "." can't be applied to pointer type
struct Foo { int x; };
int func(Foo *a) {
a.x = 0;
}

View File

@@ -0,0 +1,7 @@
// Dereference operator "->" can't be applied to non-pointer type "uniform struct Foo"
struct Foo { int x; };
int func(Foo a) {
a->x = 0;
}

5
tests_errors/deref.ispc Normal file
View File

@@ -0,0 +1,5 @@
// Member operator "->" can't be used with expression of "int32" type
int func(int *a) {
a->x = 0;
}

View File

@@ -0,0 +1,7 @@
// Unable to find matching overload for call to function
void foo(int x);
void bar(int x) {
foo();
}

View File

@@ -0,0 +1,7 @@
// Unable to find matching overload for call to function
void foo(int x);
void bar(int x) {
foo(x, x);
}

View File

@@ -0,0 +1,7 @@
// Unable to find matching overload for call to function
void foo();
void bar(int x) {
foo(x);
}

View File

@@ -1,3 +1,3 @@
// Initializer list for array "int32[2][4]" must have 2 elements (has 3).
// Initializer list for array "int32[4]" must have 4 elements (has 3)
int a[2][4] = { { 1, 2, 3 }, { 1, 2, 3, 4 }, 1 };

View File

@@ -1,4 +1,4 @@
// Inconsistent expression list lengths found in initializer list
// Inconsistent initializer expression list lengths make it impossible to size unsized array dimensions
void foo() {
int a[2][] = { { 1, 2, 3 }, { 1, 2, 3, 4 } };

View File

@@ -0,0 +1,4 @@
// Inconsistent initializer expression list lengths make it impossible
int a[2][] = { { 1, 2, 3 }, { 1, 2, 3, 4 } };

5
tests_errors/ptr-1.ispc Normal file
View File

@@ -0,0 +1,5 @@
// Can't convert between incompatible pointer types
int *foo(void *p) {
return p;
}

5
tests_errors/ptr-2.ispc Normal file
View File

@@ -0,0 +1,5 @@
// Illegal to pre/post increment
void *foo(void *p) {
++p;
}

6
tests_errors/ptr-3.ispc Normal file
View File

@@ -0,0 +1,6 @@
// Illegal to perform pointer arithmetic
void *foo(void *p) {
p = p-2;
return p;
}

6
tests_errors/ptr-4.ispc Normal file
View File

@@ -0,0 +1,6 @@
// Illegal to perform pointer arithmetic
void *foo(void *p) {
p += 1;
return p;
}

View File

@@ -0,0 +1,5 @@
// Can't assign to type "const int32 * const"
void foo(const int * const p) {
++p;
}

View File

@@ -0,0 +1,5 @@
// Can't assign to type "const int32" on left-hand side
void foo(const int * p) {
*p = 0;
}

View File

@@ -0,0 +1,12 @@
// Conversion between incompatible pointer types
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
uniform int8 * varying pa = (uniform int8 *)aFOO;
RET[programIndex] = aFOO - pa;
}
export void result(uniform float RET[]) {
RET[programIndex] = 40;
}

6
tests_errors/ref-1.ispc Normal file
View File

@@ -0,0 +1,6 @@
// Syntax error--token "&" unexpected
int foo(int & & bar) {
bar = 0;
return bar;
}

6
tests_errors/ref-2.ispc Normal file
View File

@@ -0,0 +1,6 @@
// Must provide initializer for reference-type variable
void func(int a) {
int &b;
b = 0;
}

5
tests_errors/ref-3.ispc Normal file
View File

@@ -0,0 +1,5 @@
// Syntax error--token "*" unexpected
void foo(int & * x) {
*x = NULL;
}

View File

@@ -0,0 +1,7 @@
// Can't assign to type "const int32" on left-hand side of expression
const int x[20];
void foo() {
++x[5];
}

View File

@@ -0,0 +1,9 @@
// Can't assign to type "const int32" on left-hand side of expression
struct Foo {
int x;
};
void f(const Foo &f) {
f.x += 2;
}

View File

@@ -0,0 +1,9 @@
// Can't assign to type "const int32" on left-hand side of expression
struct Foo {
int x;
};
void f(const Foo &f) {
++f.x;
}

View File

@@ -0,0 +1,5 @@
// Can't assign to type "const uniform int32" on left-hand side of expression
void foo(const uniform int &x) {
x = 0;
}

View File

@@ -0,0 +1,9 @@
// fff
void foo(float &x) {
++x;
}
void bar(uniform float a[], int i) {
foo(a[i]);
}

View File

@@ -0,0 +1,13 @@
// Unsized arrays aren't allowed in struct definitions
struct Foo {
float a[];
float b[10];
};
Foo f;
void Func() {
Foo f;
}

View File

@@ -0,0 +1,5 @@
// ffofoof
struct Foo {
int a, a;
};

View File

@@ -0,0 +1,7 @@
// ffofoof
void inc(float &x) { ++x; }
void foo(uniform float a[], int index) {
inc(a[index]);
}