diff options
author | Jason Ekstrand <jason@jlekstrand.net> | 2019-04-24 04:58:14 -0500 |
---|---|---|
committer | Jason Ekstrand <jason@jlekstrand.net> | 2019-04-25 19:25:39 +0000 |
commit | 3eccb6ecb1267c518e80e2fb428d495c071edcd3 (patch) | |
tree | d38fad564866b49ba7a05f04eca7f323e780dce2 /misc | |
parent | 9762d37b874591abb5951ba2035567048bc355f7 (diff) |
glsl_scraper: Allow for __LINE__ to be the first line of the macro
When I originally wrote the scraper, I did some testing with GCC and
found that it consistently used the last line occupied by a macro for
the value of __LINE__ within the evaluation of that macro. However,
with GCC 9, it now uses the first line. This commit updates the
glsl_scraper macro to allow for both behaviors. It's rather aweful that
we rely on such details of the C preprocessor but it makes for really
nice syntax inside tests so.... Oh, well?
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/glsl_scraper.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/misc/glsl_scraper.py b/misc/glsl_scraper.py index 5bc3f50..0621579 100644 --- a/misc/glsl_scraper.py +++ b/misc/glsl_scraper.py @@ -28,7 +28,7 @@ class Shader: def add_text(self, s): self.stream.write(s) - def finish_text(self, line): + def finish_text(self, start_line, end_line): self.glsl = self.stream.getvalue() self.stream = None @@ -40,7 +40,8 @@ class Shader: self.target_env = m.group(1) self.glsl = self.glsl.replace('QO_TARGET_ENV', '// --target-env') - self.line = line + self.start_line = start_line + self.end_line = end_line def __run_glslang(self, extra_args=[]): if self.stage == 'VERTEX': @@ -131,7 +132,7 @@ class Shader: def dump_c_code(self, f, glsl_only = False): f.write('\n\n') - var_prefix = '__qonos_shader{0}'.format(self.line) + var_prefix = '__qonos_shader{0}'.format(self.end_line) self._dump_glsl_code(f, var_prefix + '_glsl_src') @@ -152,7 +153,10 @@ class Shader: f.write(" .stage = VK_SHADER_STAGE_{0}_BIT,\n".format(self.stage)) - f.write('};') + f.write('};\n') + + f.write('#define __qonos_shader{0}_info __qonos_shader{1}_info\n'\ + .format(self.start_line, self.end_line)) token_exp = re.compile(r'(qoShaderModuleCreateInfoGLSL|qoCreateShaderModuleGLSL|\(|\)|,)') @@ -208,6 +212,8 @@ class Parser: t = next(self.token_iter) assert t == '(' + start_line = self.line_number + if macro == 'qoCreateShaderModuleGLSL': # Throw away the device parameter t = next(self.token_iter) @@ -221,7 +227,7 @@ class Parser: self.current_shader = Shader(stage) self.handle_shader_src() - self.current_shader.finish_text(self.line_number) + self.current_shader.finish_text(start_line, self.line_number) self.shaders.append(self.current_shader) self.current_shader = None |