diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-09 11:34:21 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-09 13:44:59 -0700 |
| commit | fcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch) | |
| tree | 41047c94883b86ec085a81597391ce3ef557cd43 /tests/front-end | |
| parent | 52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff) | |
Initial import of code.
Diffstat (limited to 'tests/front-end')
| -rw-r--r-- | tests/front-end/lexer-comments.spire | 13 | ||||
| -rw-r--r-- | tests/front-end/parser-decls.spire | 60 | ||||
| -rw-r--r-- | tests/front-end/parser-empty.spire | 1 | ||||
| -rw-r--r-- | tests/front-end/parser-error-unclosed-curly.spire | 3 | ||||
| -rw-r--r-- | tests/front-end/parser-error-unclosed-curly.spire.expected | 6 | ||||
| -rw-r--r-- | tests/front-end/parser-using-file-a.spireh | 3 | ||||
| -rw-r--r-- | tests/front-end/parser-using-file.spire.disabled | 6 | ||||
| -rw-r--r-- | tests/front-end/pipeline-simple.spireh | 41 | ||||
| -rw-r--r-- | tests/front-end/struct.spire | 49 | ||||
| -rw-r--r-- | tests/front-end/typedef.spire | 15 |
10 files changed, 197 insertions, 0 deletions
diff --git a/tests/front-end/lexer-comments.spire b/tests/front-end/lexer-comments.spire new file mode 100644 index 000000000..d8c06ca76 --- /dev/null +++ b/tests/front-end/lexer-comments.spire @@ -0,0 +1,13 @@ +//TEST:SIMPLE: +// confirming that the lexer handles comments correctly + +// line comment + +/* block comment +*/ + +/* block comments don't nest + /* +*/ + +float f(float f) { return f; }
\ No newline at end of file diff --git a/tests/front-end/parser-decls.spire b/tests/front-end/parser-decls.spire new file mode 100644 index 000000000..bc5a2b13b --- /dev/null +++ b/tests/front-end/parser-decls.spire @@ -0,0 +1,60 @@ +//TEST:SIMPLE: +// test that we can parse all the expected kinds of declarations + +// global-scope `using` is another test + +/* Note(tfoley): disabled during syntax transition +// pipeline +pipeline P +{ + +} +*/ + +// empty declaration +; + +// struct type +struct Pair +{ + int head; + float tail; + +// Note(tfoley): semicolon is expected/required +// here for compatibility with HLSL (C-style +// declarators). +// +// TODO: this could be removed if we treat +// HLSL as a "compatibility mode" +}; + +// function at global scope +float tail(Pair p) { return p.tail; } + +/* Note(tfoley): disabled during syntax transition + +// module +module M +{ + // component declarations + + // using declarations + +} + +// a module can "inherit" from a pipeline +module M2 + targets P +{ +} + +// shader +shader S +{ + // component declarations + + // using declarations + +} + +*/
\ No newline at end of file diff --git a/tests/front-end/parser-empty.spire b/tests/front-end/parser-empty.spire new file mode 100644 index 000000000..bfd66f05b --- /dev/null +++ b/tests/front-end/parser-empty.spire @@ -0,0 +1 @@ +//TEST:SIMPLE: diff --git a/tests/front-end/parser-error-unclosed-curly.spire b/tests/front-end/parser-error-unclosed-curly.spire new file mode 100644 index 000000000..6cfcca456 --- /dev/null +++ b/tests/front-end/parser-error-unclosed-curly.spire @@ -0,0 +1,3 @@ +//TEST:SIMPLE: +void foo() { +// Note: no closing curly brace diff --git a/tests/front-end/parser-error-unclosed-curly.spire.expected b/tests/front-end/parser-error-unclosed-curly.spire.expected new file mode 100644 index 000000000..437b6eab0 --- /dev/null +++ b/tests/front-end/parser-error-unclosed-curly.spire.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +Tests/FrontEnd/parser-error-unclosed-curly.spire(4): error 20001: unexpected end of file, expected '}' +} +standard output = { +} diff --git a/tests/front-end/parser-using-file-a.spireh b/tests/front-end/parser-using-file-a.spireh new file mode 100644 index 000000000..62e6acd06 --- /dev/null +++ b/tests/front-end/parser-using-file-a.spireh @@ -0,0 +1,3 @@ +// this file exists to be included by "parser-using-file.spire" + +float a(float x) { return x * x; } diff --git a/tests/front-end/parser-using-file.spire.disabled b/tests/front-end/parser-using-file.spire.disabled new file mode 100644 index 000000000..f93fb576c --- /dev/null +++ b/tests/front-end/parser-using-file.spire.disabled @@ -0,0 +1,6 @@ +//TEST:SIMPLE: +// test that we can include a file via `using` + +using "parser-using-file-a.spireh"; + +float base( float x ) { return a(x); }
\ No newline at end of file diff --git a/tests/front-end/pipeline-simple.spireh b/tests/front-end/pipeline-simple.spireh new file mode 100644 index 000000000..55afd693c --- /dev/null +++ b/tests/front-end/pipeline-simple.spireh @@ -0,0 +1,41 @@ +// pipeline-simple.spireh + + +// TODO(tfoley): strip this down to a minimal pipeline + +pipeline StandardPipeline +{ + [Pinned] + input world MeshVertex; + + world CoarseVertex;// : "glsl(vertex:projCoord)" using projCoord export standardExport; + world Fragment;// : "glsl" export fragmentExport; + + require @CoarseVertex vec4 projCoord; + + [VertexInput] + extern @CoarseVertex MeshVertex vertAttribIn; + import(MeshVertex->CoarseVertex) vertexImport() + { + return project(vertAttribIn); + } + + extern @Fragment CoarseVertex CoarseVertexIn; + import(CoarseVertex->Fragment) standardImport() +// TODO(tfoley): this trait doesn't seem to be implemented on `vec3` +// require trait IsTriviallyPassable(CoarseVertex) + { + return project(CoarseVertexIn); + } + + stage vs : VertexShader + { + World: CoarseVertex; + Position: projCoord; + } + + stage fs : FragmentShader + { + World: Fragment; + } +}
\ No newline at end of file diff --git a/tests/front-end/struct.spire b/tests/front-end/struct.spire new file mode 100644 index 000000000..8347f8d58 --- /dev/null +++ b/tests/front-end/struct.spire @@ -0,0 +1,49 @@ +//TEST:SIMPLE: +// test that `struct` decls work + +// Note(tfoley): disabled during syntax transition +// #include "pipeline-simple.spireh" + +// struct declaration +struct Foo +{ + float3 a; + float3 b; +}; + +// function on a struct +Foo makeFoo(float x, float y) +{ + // local of struct type + Foo foo; + foo.a = float3(x); + foo.b = float3(y); + return foo; +} + +/* Note(tfoley): disabled during syntax transition + +template shader Test() +// targets StandardPipeline +{ + // Uniform of struct type + param Foo foo1; + + @MeshVertex float3 position; + @MeshVertex float3 color; + + param mat4 modelViewProjection; + + public vec4 projCoord = modelViewProjection * vec4(position, 1.0); + + // Component of struct type + // Note(tfoley): use of `public` here required to work around parser limitations + public Foo foo2 = makeFoo(color.x, color.y); + + // + float3 result = foo1.a + foo2.b; + + out @Fragment vec4 colorTarget = vec4(result,1); +} + +*/
\ No newline at end of file diff --git a/tests/front-end/typedef.spire b/tests/front-end/typedef.spire new file mode 100644 index 000000000..7e96bead0 --- /dev/null +++ b/tests/front-end/typedef.spire @@ -0,0 +1,15 @@ +//TEST:SIMPLE: +// test that we can `typedef` a type + +typedef float F32; + +F32 foo() +{ + float x = 123.0; + return x; +} + +float bar() +{ + return foo(); +} |
