Commit Graph

735 Commits

Author SHA1 Message Date
Lei Zhang
2b4ebbb1e1 Update scanner in TParseContext when changing the input stream.
After parsing a #include directive, we push a TokenizableString
which contains the content of the included file into the input
stack. Henceforth, tokens will be read from the newly pushed
TokenizableString. However, the scanner in TParseContext still
points to the previous input stream. We need to update the scanner
to point to the new input stream inside TokenizableString. Thus,
the setCurrent{String|Line|..} method in TParseContext updates
the status of the correct input stream. After finishing the newly
pushed TokenizableString, we need to restore the scanner to the
previous input stream.
2015-07-31 19:41:19 -04:00
Lei Zhang
9c1280b225 Use extension framework to enable #include directive.
This patch introduces a new extension, GL_GOOGLE_include_directive,
to enable support #include directives. It depends on the extension
GL_GOOGLE_cpp_style_line_directive.
2015-07-31 19:41:19 -04:00
Dejan Mircevski
7be4b8282d Add #include processing to glslang (though turned off by default).
When an include directive is recognized by the preprocessor, it
executes a callback on the filepath argument to obtain the file
contents.  That way the compilation client can deal with the file
system, include paths, etc.

Currently only accepts quoted filepaths -- no angle brackets yet.
2015-07-31 19:41:18 -04:00
John Kessenich
1363fcd60b Merge pull request #45 from google/source-string-name
Add mechanism for specifying names for source strings.
2015-07-31 17:38:27 -06:00
Lei Zhang
1719fb207a Add mechanism for specifying names for source strings.
Expose a new method setStringsWithLengthsAndNames() in the interface
which allows the caller to set descriptive names for source strings.
These names can be used in error messages.
2015-07-29 09:59:04 -04:00
John Kessenich
b9e5424792 Non-functional: Slight change to the Google #include implementation to separate it from AEP. 2015-07-28 19:01:16 -06:00
John Kessenich
d9b89d3e9a Merge pull request #43 from google/cpp-style-line-directive
Extend the syntax of #line and __FILE__ to support filename strings.

The implementation is done via introducing a new extension 
GL_GOOGLE_cpp_style_line_directive using the extension framework.

The purpose is to support cpp-style #line directives, which is
required by #include.
2015-07-28 18:55:44 -06:00
Lei Zhang
54e47cc275 Use const reference for TSourceLoc in interfaces. 2015-07-28 12:45:41 -04:00
Lei Zhang
780a2f4426 Use requireExtensions() to check extension and turn on more tests.
Use requireExtensions() to check GL_GOOGLE_cpp_style_line_directive
is turned on. Add register more tests for running.
2015-07-28 12:21:00 -04:00
Lei Zhang
5011fbebc3 Extend the syntax of #line and __FILE__ to support filename strings.
According to the GLSL spec, the second parameter to #line should be
an integer source string number and __FILE__ will be substituted
with the integer source string number currently processed. This
patch extends the syntax of #line and __FILE__. Now #line accepts
as the second parameter a filename string quoted by double quotation
marks. And if such a #line is set, __FILE__ will be substituted with
the currently set filename string. The implementation is done via
introducing a new extension GL_GOOGLE_cpp_style_line_directive using
the extension framework.

The purpose is to support cpp-style #line directives, which is
required by #include.
2015-07-27 13:07:52 -04:00
John Kessenich
c777fc2c4c Scanning: 1) rationalize end-of-input everywhere, 2) prevent infinite loop at end-of-input, 3) use positive chars.
Fixes issue #25. (char 255 aliased to -1 and missing tests for end of input).

1) All layers of input scanning now share a single EndOfInput value.
This avoids translation of it across layers of encapsulation.

2) Some places looking for end of line were not stopping on EndOfInput.

3) Use of "char" for the input made char values > 127 be negative numbers.
This allowed for aliasing of 255 to -1, etc.  This is fixed by using
unsigned char.
2015-07-27 09:37:55 -06:00
John Kessenich
91b977e172 Issue #39: Prevent problem of inserting a zero-length symbol after cascading errors. 2015-07-25 18:14:09 -06:00
John Kessenich
aead93aafd Preprocessor: Allow '\' as a token, which gets actual use in #error, but should have no other use.
This is just for '\' that's not before a new line.
Note the specification says it has no use other than as line continuation,
but #error is a grey area. (There are no escape sequences.)
2015-07-25 17:34:32 -06:00
John Kessenich
f330f08129 Consolidate all token length limits (1024), including one bad one (80) hardcoded on the stack (issue #40, issue #41). 2015-07-25 14:02:53 -06:00
John Kessenich
1070e629a9 Merge pull request #44 from fkaa/osx-const-key-fix
Fix missing const qualifier on TUnorderedMap template type
2015-07-25 12:51:02 -06:00
Felix Kaaman
09d16c3ec1 Fix missing const qualifier on TUnorderedMap template type 2015-07-25 16:31:50 +02:00
John Kessenich
2b3442ada1 Portability: Make previous merge work with MSVS 2012. 2015-07-24 15:15:55 -06:00
John Kessenich
b159bd5821 Merge pull request #38 from google/preprocessing-line-number
Preprocessing line number handling
2015-07-24 15:05:17 -06:00
Lei Zhang
79f6451b53 DoPreprocessing() should consider source string change.
Everytime we switch to a new source string, the line are reset.
We need to reset lastLine and also output newlines appropriately.
2015-07-23 12:29:19 -04:00
Lei Zhang
d67e15e9b4 Create a new class to keep track of line number in preprocessor.
SourceLineSynchronizer is added for keeping track of the last
line number and output newlines appropriately if we switch to
a new line in the preprocessor.
2015-07-23 12:29:19 -04:00
John Kessenich
62aa5bdfca AST -> SPV testing: Update test for using new TbdFunctionality() that is non-fatal and uniquifies printed TBDs. 2015-07-23 10:25:20 -06:00
John Kessenich
426394d0c8 AST -> SPV: Add basic atomic_uint and atomic*() built-in function functionality. 2015-07-23 10:22:48 -06:00
John Kessenich
917ec4ac8c Front-end atomics: Finish adding atomic built-in functions (non-image) into the AST. 2015-07-22 19:58:15 -06:00
John Kessenich
d1a6846ba2 Todo.txt: Added key, including notation for who's working on something. 2015-07-22 16:39:12 -06:00
John Kessenich
7ed16efaf6 Update Todo.txt. 2015-07-22 16:36:38 -06:00
John Kessenich
c040e76c58 Portability: Remove unneeded "= default" to work with older compilers. 2015-07-22 15:25:59 -06:00
John Kessenich
96d8042a64 Merge pull request #31 from google/explicit-extension-directive
Only output explicit extension directives in preprocessing.
2015-07-22 15:20:54 -06:00
John Kessenich
12a383379c Issue 32: Guard against constructors consuming unsized arrays. 2015-07-22 11:44:59 -06:00
John Kessenich
f498400945 Merge pull request #33 from google/spv-builder-loop-ctor-inits-all-members
spv::Builder::Loop constructor inits all members.
2015-07-22 11:39:29 -06:00
David Neto
3e6a33cedf spv::Builder::Loop constructor inits all members.
After construction, the Loop is effectively const.

This perturbs the IDs in SPIR-V tests because the body block
is created before generating any of the loop code, rather than
only when the body is first referenced.
2015-07-22 12:24:21 -04:00
John Kessenich
8ba301c7c2 Issue #28: Correctly handle a single input argument conversion when the input argument is an aggregate. 2015-07-21 16:00:34 -06:00
Lei Zhang
1d2996db68 Only output explicit extension directives in preprocessing.
Preprocessing output shouldn't contain extensions enabled as
dependencies.
2015-07-21 17:47:47 -04:00
John Kessenich
efb8461722 Issue #26: Detect empty array constructors, require at least on operand. 2015-07-21 14:35:39 -06:00
John Kessenich
222457054e g++: Fix compilation issue with templates in g++. 2015-07-21 00:07:52 -06:00
John Kessenich
1056110c30 Perf: Put in a portable std::hash that works with the pool. This turns on the 10-15% perf gain. 2015-07-20 23:59:32 -06:00
John Kessenich
96f4911351 SPV: Make previous commit compile with MSVC 2012. 2015-07-20 22:34:49 -06:00
John Kessenich
37e8337958 Merge pull request #22 from google/structured-do-while
Generate correctly structured do-while loops.
2015-07-20 22:14:38 -06:00
John Kessenich
d2762564dc Preprocessor: Prevent (and give an error on) expression division by 0. 2015-07-20 12:29:41 -06:00
John Kessenich
e9022e1ffe Tests: Increase testing around incorrect use of block names and instances. 2015-07-20 12:03:04 -06:00
John Kessenich
78a5a0d7d8 Front end: Prevent use of a block name, which has no other use in a shader. 2015-07-20 11:35:51 -06:00
John Kessenich
68965c0fa9 Fix g++ build break (portibility problems with stl hash). This partly turns off the stl improvements.
It also removes some old code that ancient compilers used to need.
However, the main issue is getting access to hash functions for
unordered_map in portable way.
2015-07-20 02:06:22 -06:00
John Kessenich
6ab3d582d6 Preprocessor: 1) Rationalize the "fixed atom" scheme, 2) remove redundant lookups when the text is already available.
This simplification is a prelude to eliminating what I appear unnecessary
symbol inserts into tables when tokenizing in the preprecessor, which
show up as taking notable time. (Performance issue.)  It also simply makes
the preprocessor easier to understand, which it is badly in need of.
2015-07-19 22:59:24 -06:00
John Kessenich
2f273369e4 Performance: Simple upgrade/cleanup of stl c++11 containers (10% perf. increase). 2015-07-19 12:03:51 -06:00
John Kessenich
f4673162b7 Building: Fix a couple of new warnings. 2015-07-18 11:25:54 -06:00
John Kessenich
2b4b9bd65b Front-end: Add error-recovery code for a switch statement that ends with a case/default that has no statements. 2015-07-18 11:13:14 -06:00
David Neto
c22f37cfb4 Generate correctly structured do-while loops.
The loop test is always emitted before the loop body.

For do-while loops, use a phi node to track whether we're
on the first loop iteration, and only check the loop test
on the second and subsequent iterations.

For do-while loops, the loop test branch no longer occurs
at the top of the loop, so it must get its own selection
merge instruction.

A block can't be the target of more than one merge instruction.
So when the loop test executes after the body (as in do-while in GLSL)
we need to introduce a dummy block to be the target of the selection
merge just before the loop test conditional branch.

The other arm of the branch exits the loop and hence is the
"break block" exception in the structured control flow rules.
2015-07-17 17:51:51 -04:00
John Kessenich
51b31b5785 Merge pull request #21 from google/allow_non_null_strings
Added a setStringsWithLengths() method to TShader.
2015-07-17 11:51:56 -06:00
John Kessenich
72becbe5a2 Merge pull request #20 from google/remove_exception
Removed the single usage of exceptions in all of glslang.
2015-07-17 11:45:31 -06:00
Andrew Woloszyn
6a6aaeffd3 Added a setStringsWithLengths() method to TShader.
This allows us to pass through non null-terminated strings.
2015-07-17 13:37:02 -04:00
Andrew Woloszyn
e837f99afb Removed the single usage of exceptions in all of glslang. 2015-07-17 13:31:25 -04:00