Add TINT_SYMBOL_STORE_DEBUG_NAME option to help debugging the AST
If TINT_SYMBOL_STORE_DEBUG_NAME is 1, Symbol instances store a `debug_name_` member initialized with the name of the identifier they represent. This member is not exposed, but is useful for debugging purposes. Bug: tint:1331 Change-Id: Ia98e266aefc1ca26bbf30c6ece73d9eac8afdbd7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/71780 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
cf3880201b
commit
b2bbb14bd4
|
@ -95,6 +95,8 @@ option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF)
|
|||
|
||||
option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
|
||||
|
||||
option_if_not_defined(TINT_SYMBOL_STORE_DEBUG_NAME "Enable storing of name in tint::ast::Symbol to help debugging the AST" OFF)
|
||||
|
||||
message(STATUS "Tint build samples: ${TINT_BUILD_SAMPLES}")
|
||||
message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
|
||||
message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}")
|
||||
|
|
|
@ -559,6 +559,9 @@ tint_default_compile_options(libtint)
|
|||
if (${COMPILER_IS_LIKE_GNU})
|
||||
target_compile_options(libtint PRIVATE -fvisibility=hidden)
|
||||
endif()
|
||||
if (${TINT_SYMBOL_STORE_DEBUG_NAME})
|
||||
target_compile_definitions(libtint PUBLIC "TINT_SYMBOL_STORE_DEBUG_NAME=1")
|
||||
endif()
|
||||
set_target_properties(libtint PROPERTIES OUTPUT_NAME "tint")
|
||||
|
||||
if (${TINT_BUILD_FUZZERS})
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "src/symbol.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace tint {
|
||||
|
||||
Symbol::Symbol() = default;
|
||||
|
@ -21,6 +23,11 @@ Symbol::Symbol() = default;
|
|||
Symbol::Symbol(uint32_t val, tint::ProgramID program_id)
|
||||
: val_(val), program_id_(program_id) {}
|
||||
|
||||
#if TINT_SYMBOL_STORE_DEBUG_NAME
|
||||
Symbol::Symbol(uint32_t val, tint::ProgramID program_id, std::string debug_name)
|
||||
: val_(val), program_id_(program_id), debug_name_(std::move(debug_name)) {}
|
||||
#endif
|
||||
|
||||
Symbol::Symbol(const Symbol& o) = default;
|
||||
|
||||
Symbol::Symbol(Symbol&& o) = default;
|
||||
|
|
17
src/symbol.h
17
src/symbol.h
|
@ -15,6 +15,13 @@
|
|||
#ifndef SRC_SYMBOL_H_
|
||||
#define SRC_SYMBOL_H_
|
||||
|
||||
// If TINT_SYMBOL_STORE_DEBUG_NAME is 1, Symbol instances store a `debug_name_`
|
||||
// member initialized with the name of the identifier they represent. This
|
||||
// member is not exposed, but is useful for debugging purposes.
|
||||
#ifndef TINT_SYMBOL_STORE_DEBUG_NAME
|
||||
#define TINT_SYMBOL_STORE_DEBUG_NAME 0
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/program_id.h"
|
||||
|
@ -31,6 +38,13 @@ class Symbol {
|
|||
/// @param val the symbol value
|
||||
/// @param program_id the identifier of the program that owns this Symbol
|
||||
Symbol(uint32_t val, tint::ProgramID program_id);
|
||||
#if TINT_SYMBOL_STORE_DEBUG_NAME
|
||||
/// Constructor
|
||||
/// @param val the symbol value
|
||||
/// @param program_id the identifier of the program that owns this Symbol
|
||||
/// @param debug_name name of symbols used only for debugging
|
||||
Symbol(uint32_t val, tint::ProgramID program_id, std::string debug_name);
|
||||
#endif
|
||||
/// Copy constructor
|
||||
/// @param o the symbol to copy
|
||||
Symbol(const Symbol& o);
|
||||
|
@ -75,6 +89,9 @@ class Symbol {
|
|||
private:
|
||||
uint32_t val_ = static_cast<uint32_t>(-1);
|
||||
tint::ProgramID program_id_;
|
||||
#if TINT_SYMBOL_STORE_DEBUG_NAME
|
||||
std::string debug_name_;
|
||||
#endif
|
||||
};
|
||||
|
||||
/// @param sym the Symbol
|
||||
|
|
|
@ -38,7 +38,11 @@ Symbol SymbolTable::Register(const std::string& name) {
|
|||
if (it != name_to_symbol_.end())
|
||||
return it->second;
|
||||
|
||||
#if TINT_SYMBOL_STORE_DEBUG_NAME
|
||||
Symbol sym(next_symbol_, program_id_, name);
|
||||
#else
|
||||
Symbol sym(next_symbol_, program_id_);
|
||||
#endif
|
||||
++next_symbol_;
|
||||
|
||||
name_to_symbol_[name] = sym;
|
||||
|
|
Loading…
Reference in New Issue