From 891564adb90f090e0c635a30fb947baa0291703c Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 19 Jan 2016 18:44:44 -0800 Subject: nir/spirv: Handle OpLine and OpNoLine in foreach_instruction This way we don't have to explicitly handle them everywhere. --- src/glsl/nir/spirv/spirv_to_nir.c | 38 ++++++++++++++++++++++++-------------- src/glsl/nir/spirv/vtn_private.h | 6 ++++++ 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src/glsl') diff --git a/src/glsl/nir/spirv/spirv_to_nir.c b/src/glsl/nir/spirv/spirv_to_nir.c index 1fcdb1aa14a..a117175341e 100644 --- a/src/glsl/nir/spirv/spirv_to_nir.c +++ b/src/glsl/nir/spirv/spirv_to_nir.c @@ -192,19 +192,37 @@ const uint32_t * vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start, const uint32_t *end, vtn_instruction_handler handler) { + b->file = NULL; + b->line = -1; + b->col = -1; + const uint32_t *w = start; while (w < end) { SpvOp opcode = w[0] & SpvOpCodeMask; unsigned count = w[0] >> SpvWordCountShift; assert(count >= 1 && w + count <= end); - if (opcode == SpvOpNop) { - w++; - continue; - } + switch (opcode) { + case SpvOpNop: + break; /* Do nothing */ - if (!handler(b, opcode, w, count)) - return w; + case SpvOpLine: + b->file = vtn_value(b, w[1], vtn_value_type_string)->str; + b->line = w[2]; + b->col = w[3]; + break; + + case SpvOpNoLine: + b->file = NULL; + b->line = -1; + b->col = -1; + break; + + default: + if (!handler(b, opcode, w, count)) + return w; + break; + } w += count; } @@ -3498,10 +3516,6 @@ vtn_handle_variable_or_type_instruction(struct vtn_builder *b, SpvOp opcode, assert(!"Invalid opcode types and variables section"); break; - case SpvOpLine: - case SpvOpNoLine: - break; /* Ignored for now */ - case SpvOpTypeVoid: case SpvOpTypeBool: case SpvOpTypeInt: @@ -3555,10 +3569,6 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count) { switch (opcode) { - case SpvOpLine: - case SpvOpNoLine: - break; /* Ignored for now */ - case SpvOpLabel: break; diff --git a/src/glsl/nir/spirv/vtn_private.h b/src/glsl/nir/spirv/vtn_private.h index cf75bc92a7a..a0cf1b9fd42 100644 --- a/src/glsl/nir/spirv/vtn_private.h +++ b/src/glsl/nir/spirv/vtn_private.h @@ -299,6 +299,12 @@ struct vtn_builder { nir_function_impl *impl; struct vtn_block *block; + /* Current file, line, and column. Useful for debugging. Set + * automatically by vtn_foreach_instruction. + */ + char *file; + int line, col; + /* * In SPIR-V, constants are global, whereas in NIR, the load_const * instruction we use is per-function. So while we parse each function, we -- cgit v1.2.3