Move the validation code into the val:: namespace (#1682)

This CL moves the validation code to the val:: namespace. This makes it
clearer which instance of the Instruction and other classes are being
referred too.
diff --git a/source/comp/markv_codec.cpp b/source/comp/markv_codec.cpp
index 1b9b869..5e3ddab 100644
--- a/source/comp/markv_codec.cpp
+++ b/source/comp/markv_codec.cpp
@@ -17,7 +17,7 @@
 //   - MARK-V to SPIR-V decoder
 //
 // MARK-V is a compression format for SPIR-V binaries. It strips away
-// non-essential information (such as result ids which can be regenerated) and
+// non-essential information (such as result IDs which can be regenerated) and
 // uses various bit reduction techiniques to reduce the size of the binary.
 
 #include <algorithm>
@@ -388,7 +388,7 @@
 
   // Returns instruction which created |id| or nullptr if such instruction was
   // not registered.
-  const Instruction* FindDef(uint32_t id) const {
+  const val::Instruction* FindDef(uint32_t id) const {
     const auto it = id_to_def_instruction_.find(id);
     if (it == id_to_def_instruction_.end()) return nullptr;
     return it->second;
@@ -396,7 +396,7 @@
 
   // Returns type id of vector type component.
   uint32_t GetVectorComponentType(uint32_t vector_type_id) const {
-    const Instruction* type_inst = FindDef(vector_type_id);
+    const val::Instruction* type_inst = FindDef(vector_type_id);
     assert(type_inst);
     assert(type_inst->opcode() == SpvOpTypeVector);
 
@@ -546,7 +546,7 @@
   std::vector<uint32_t> ids_local_to_cur_function_;
 
   // List of instructions in the order they are given in the module.
-  std::vector<std::unique_ptr<const Instruction>> instructions_;
+  std::vector<std::unique_ptr<const val::Instruction>> instructions_;
 
   // Container/computer for long (32-bit) id descriptors.
   IdDescriptorCollection long_id_descriptors_;
@@ -575,7 +575,7 @@
 
  private:
   // Maps result id to the instruction which defined it.
-  std::unordered_map<uint32_t, const Instruction*> id_to_def_instruction_;
+  std::unordered_map<uint32_t, const val::Instruction*> id_to_def_instruction_;
 
   uint32_t id_bound_ = 1;
 };
@@ -859,7 +859,7 @@
 };
 
 void MarkvCodecBase::ProcessCurInstruction() {
-  instructions_.emplace_back(new Instruction(&inst_));
+  instructions_.emplace_back(new val::Instruction(&inst_));
 
   const SpvOp opcode = SpvOp(inst_.opcode);
 
@@ -883,7 +883,7 @@
 
       // Store function parameter types in a queue, so that we know which types
       // to expect in the following OpFunctionParameter instructions.
-      const Instruction* def_inst = FindDef(inst_.words[4]);
+      const val::Instruction* def_inst = FindDef(inst_.words[4]);
       assert(def_inst);
       assert(def_inst->opcode() == SpvOpTypeFunction);
       for (uint32_t i = 3; i < def_inst->words().size(); ++i) {
@@ -982,7 +982,7 @@
     }
 
     if (inst_.type_id) {
-      const Instruction* type_inst = FindDef(inst_.type_id);
+      const val::Instruction* type_inst = FindDef(inst_.type_id);
       assert(type_inst);
 
       multi_mtf_.Insert(kMtfObject, inst_.result_id);
@@ -1225,7 +1225,7 @@
       if (operand_index_ == 1) {
         const uint32_t pointer_id = GetInstWords()[1];
         const uint32_t pointer_type = id_to_type_id_.at(pointer_id);
-        const Instruction* pointer_inst = FindDef(pointer_type);
+        const val::Instruction* pointer_inst = FindDef(pointer_type);
         assert(pointer_inst);
         assert(pointer_inst->opcode() == SpvOpTypePointer);
         const uint32_t data_type =
@@ -1272,7 +1272,7 @@
     case SpvOpConstantComposite: {
       if (operand_index_ == 0) return kMtfTypeComposite;
       if (operand_index_ >= 2) {
-        const Instruction* composite_type_inst = FindDef(inst_.type_id);
+        const val::Instruction* composite_type_inst = FindDef(inst_.type_id);
         assert(composite_type_inst);
         if (composite_type_inst->opcode() == SpvOpTypeVector) {
           return GetMtfIdOfType(composite_type_inst->word(2));
@@ -1406,13 +1406,13 @@
 
       if (operand_index_ >= 3) {
         const uint32_t function_id = GetInstWords()[3];
-        const Instruction* function_inst = FindDef(function_id);
+        const val::Instruction* function_inst = FindDef(function_id);
         if (!function_inst) return kMtfObject;
 
         assert(function_inst->opcode() == SpvOpFunction);
 
         const uint32_t function_type_id = function_inst->word(4);
-        const Instruction* function_type_inst = FindDef(function_type_id);
+        const val::Instruction* function_type_inst = FindDef(function_type_id);
         assert(function_type_inst);
         assert(function_type_inst->opcode() == SpvOpTypeFunction);
 
diff --git a/source/spirv_stats.cpp b/source/spirv_stats.cpp
index 8ba35e0..9251ef1 100644
--- a/source/spirv_stats.cpp
+++ b/source/spirv_stats.cpp
@@ -47,8 +47,8 @@
   StatsAggregator(SpirvStats* in_out_stats, const spv_const_context context,
                   const uint32_t* words, size_t num_words) {
     stats_ = in_out_stats;
-    vstate_.reset(
-        new ValidationState_t(context, &validator_options_, words, num_words));
+    vstate_.reset(new val::ValidationState_t(context, &validator_options_,
+                                             words, num_words));
   }
 
   // Collects header statistics and sets correct id_bound.
@@ -83,7 +83,7 @@
 
   // Collects statistics of descriptors generated by IdDescriptorCollection.
   void ProcessIdDescriptors() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     const uint32_t new_descriptor =
         id_descriptors_.ProcessInstruction(inst.c_inst());
 
@@ -114,7 +114,7 @@
 
   // Collects statistics of enum words for operands of specific types.
   void ProcessEnums() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     for (const auto& operand : inst.operands()) {
       switch (operand.type) {
         case SPV_OPERAND_TYPE_SOURCE_LANGUAGE:
@@ -150,7 +150,7 @@
 
   // Collects statistics of literal strings used by opcodes.
   void ProcessLiteralStrings() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     for (const auto& operand : inst.operands()) {
       if (operand.type == SPV_OPERAND_TYPE_LITERAL_STRING) {
         const std::string str =
@@ -162,7 +162,7 @@
 
   // Collects statistics of all single word non-id operand slots.
   void ProcessNonIdWords() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     uint32_t index = 0;
     for (const auto& operand : inst.operands()) {
       if (operand.num_words == 1 && !spvIsIdType(operand.type)) {
@@ -175,7 +175,7 @@
 
   // Collects OpCapability statistics.
   void ProcessCapability() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     if (inst.opcode() != SpvOpCapability) return;
     const uint32_t capability = inst.word(inst.operands()[0].offset);
     ++stats_->capability_hist[capability];
@@ -183,7 +183,7 @@
 
   // Collects OpExtension statistics.
   void ProcessExtension() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     if (inst.opcode() != SpvOpExtension) return;
     const std::string extension = GetExtensionString(&inst.c_inst());
     ++stats_->extension_hist[extension];
@@ -218,12 +218,12 @@
 
   // Collects OpConstant statistics.
   void ProcessConstant() {
-    const Instruction& inst = GetCurrentInstruction();
+    const val::Instruction& inst = GetCurrentInstruction();
     if (inst.opcode() != SpvOpConstant) return;
     const uint32_t type_id = inst.GetOperandAs<uint32_t>(0);
     const auto type_decl_it = vstate_->all_definitions().find(type_id);
     assert(type_decl_it != vstate_->all_definitions().end());
-    const Instruction& type_decl_inst = *type_decl_it->second;
+    const val::Instruction& type_decl_inst = *type_decl_it->second;
     const SpvOp type_op = type_decl_inst.opcode();
     if (type_op == SpvOpTypeInt) {
       const uint32_t bit_width = type_decl_inst.GetOperandAs<uint32_t>(1);
@@ -263,13 +263,13 @@
 
  private:
   // Returns the current instruction (the one last processed by the validator).
-  const Instruction& GetCurrentInstruction() const {
+  const val::Instruction& GetCurrentInstruction() const {
     return vstate_->ordered_instructions().back();
   }
 
   SpirvStats* stats_;
   spv_validator_options_t validator_options_;
-  std::unique_ptr<ValidationState_t> vstate_;
+  std::unique_ptr<val::ValidationState_t> vstate_;
   IdDescriptorCollection id_descriptors_;
 };
 
diff --git a/source/val/basic_block.cpp b/source/val/basic_block.cpp
index 409af77..d70a3f0 100644
--- a/source/val/basic_block.cpp
+++ b/source/val/basic_block.cpp
@@ -21,6 +21,7 @@
 using std::vector;
 
 namespace spvtools {
+namespace val {
 
 BasicBlock::BasicBlock(uint32_t label_id)
     : id_(label_id),
@@ -144,4 +145,6 @@
 const BasicBlock*& BasicBlock::DominatorIterator::operator*() {
   return current_;
 }
+
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/val/basic_block.h b/source/val/basic_block.h
index b3641e5..8c7312f 100644
--- a/source/val/basic_block.h
+++ b/source/val/basic_block.h
@@ -25,6 +25,7 @@
 #include <vector>
 
 namespace spvtools {
+namespace val {
 
 enum BlockType : uint32_t {
   kBlockTypeUndefined,
@@ -241,6 +242,7 @@
 bool operator!=(const BasicBlock::DominatorIterator& lhs,
                 const BasicBlock::DominatorIterator& rhs);
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  /// LIBSPIRV_VAL_BASICBLOCK_H_
diff --git a/source/val/construct.cpp b/source/val/construct.cpp
index c07cc56..6a70ab2 100644
--- a/source/val/construct.cpp
+++ b/source/val/construct.cpp
@@ -20,6 +20,7 @@
 #include <unordered_set>
 
 namespace spvtools {
+namespace val {
 
 Construct::Construct(ConstructType construct_type, BasicBlock* entry,
                      BasicBlock* exit, std::vector<Construct*> constructs)
@@ -122,4 +123,5 @@
   return construct_blocks;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/val/construct.h b/source/val/construct.h
index 7cec18d..0de63f6 100644
--- a/source/val/construct.h
+++ b/source/val/construct.h
@@ -22,6 +22,7 @@
 #include <vector>
 
 namespace spvtools {
+namespace val {
 
 /// Functor for ordering BasicBlocks. BasicBlock pointers must not be null.
 struct less_than_id {
@@ -144,6 +145,7 @@
   BasicBlock* exit_block_;
 };
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  /// LIBSPIRV_VAL_CONSTRUCT_H_
diff --git a/source/val/decoration.h b/source/val/decoration.h
index 6e48ad2..1c5a57a 100644
--- a/source/val/decoration.h
+++ b/source/val/decoration.h
@@ -22,6 +22,7 @@
 #include "latest_version_spirv_header.h"
 
 namespace spvtools {
+namespace val {
 
 // An object of this class represents a specific decoration including its
 // parameters (if any). Decorations are used by OpDecorate and OpMemberDecorate,
@@ -82,6 +83,7 @@
   int struct_member_index_;
 };
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  /// LIBSPIRV_VAL_DECORATION_H_
diff --git a/source/val/function.cpp b/source/val/function.cpp
index 51ee7e4..9f02a48 100644
--- a/source/val/function.cpp
+++ b/source/val/function.cpp
@@ -35,6 +35,7 @@
 using std::vector;
 
 namespace spvtools {
+namespace val {
 
 // Universal Limit of ResultID + 1
 static const uint32_t kInvalidId = 0x400000;
@@ -386,4 +387,5 @@
   return return_value;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/val/function.h b/source/val/function.h
index 2c567ff..61f9888 100644
--- a/source/val/function.h
+++ b/source/val/function.h
@@ -29,6 +29,7 @@
 #include "val/construct.h"
 
 namespace spvtools {
+namespace val {
 
 struct bb_constr_type_pair_hash {
   std::size_t operator()(
@@ -351,6 +352,7 @@
   std::set<uint32_t> function_call_targets_;
 };
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  /// LIBSPIRV_VAL_FUNCTION_H_
diff --git a/source/val/instruction.cpp b/source/val/instruction.cpp
index f0e6e3b..1e2bb76 100644
--- a/source/val/instruction.cpp
+++ b/source/val/instruction.cpp
@@ -19,6 +19,7 @@
 using std::make_pair;
 
 namespace spvtools {
+namespace val {
 
 #define OPERATOR(OP)                                                 \
   bool operator OP(const Instruction& lhs, const Instruction& rhs) { \
@@ -49,4 +50,5 @@
   uses_.push_back(make_pair(inst, index));
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/val/instruction.h b/source/val/instruction.h
index 6636ae9..c47e6ba 100644
--- a/source/val/instruction.h
+++ b/source/val/instruction.h
@@ -25,6 +25,7 @@
 #include "table.h"
 
 namespace spvtools {
+namespace val {
 
 class BasicBlock;
 class Function;
@@ -113,18 +114,20 @@
 OPERATOR(==);
 #undef OPERATOR
 
+}  // namespace val
 }  // namespace spvtools
 
 // custom specialization of std::hash for Instruction
 namespace std {
 template <>
-struct hash<spvtools::Instruction> {
-  typedef spvtools::Instruction argument_type;
+struct hash<spvtools::val::Instruction> {
+  typedef spvtools::val::Instruction argument_type;
   typedef std::size_t result_type;
   result_type operator()(const argument_type& inst) const {
     return hash<uint32_t>()(inst.id());
   }
 };
+
 }  // namespace std
 
 #endif  // LIBSPIRV_VAL_INSTRUCTION_H_
diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp
index 3186593..afcc786 100644
--- a/source/val/validation_state.cpp
+++ b/source/val/validation_state.cpp
@@ -30,8 +30,9 @@
 using std::vector;
 
 namespace spvtools {
-
+namespace val {
 namespace {
+
 bool IsInstructionInLayoutSection(ModuleLayoutSection layout, SpvOp op) {
   // See Section 2.4
   bool out = false;
@@ -139,7 +140,7 @@
   return out;
 }
 
-}  // anonymous namespace
+}  // namespace
 
 ValidationState_t::ValidationState_t(const spv_const_context ctx,
                                      const spv_const_validator_options opt,
@@ -878,4 +879,5 @@
                                     words_, num_words_, disassembly_options);
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/val/validation_state.h b/source/val/validation_state.h
index cb378ba..463cb23 100644
--- a/source/val/validation_state.h
+++ b/source/val/validation_state.h
@@ -35,6 +35,7 @@
 #include "val/instruction.h"
 
 namespace spvtools {
+namespace val {
 
 /// This enum represents the sections of a SPIRV module. See section 2.4
 /// of the SPIRV spec for additional details of the order. The enumerant values
@@ -597,6 +598,7 @@
   const std::vector<uint32_t> empty_ids_;
 };
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  /// LIBSPIRV_VAL_VALIDATIONSTATE_H_
diff --git a/source/validate.cpp b/source/validate.cpp
index e010b7b..76a81df 100644
--- a/source/validate.cpp
+++ b/source/validate.cpp
@@ -50,15 +50,9 @@
 using std::vector;
 using std::placeholders::_1;
 
-using spvtools::CfgPass;
-using spvtools::DataRulesPass;
-using spvtools::Extension;
-using spvtools::IdPass;
-using spvtools::Instruction;
-using spvtools::InstructionPass;
-using spvtools::LiteralsPass;
-using spvtools::ModuleLayoutPass;
-using spvtools::ValidationState_t;
+namespace spvtools {
+namespace val {
+namespace {
 
 spv_result_t spvValidateIDs(const spv_instruction_t* pInsts,
                             const uint64_t count,
@@ -70,8 +64,6 @@
   return SPV_SUCCESS;
 }
 
-namespace {
-
 // TODO(umar): Validate header
 // TODO(umar): The binary parser validates the magic word, and the length of the
 // header, but nothing else.
@@ -204,7 +196,7 @@
   return SPV_SUCCESS;
 }
 
-void printDot(const ValidationState_t& _, const spvtools::BasicBlock& other) {
+void printDot(const ValidationState_t& _, const BasicBlock& other) {
   string block_string;
   if (other.successors()->empty()) {
     block_string += "end ";
@@ -217,7 +209,7 @@
          block_string.c_str());
 }
 
-void PrintBlocks(ValidationState_t& _, spvtools::Function func) {
+void PrintBlocks(ValidationState_t& _, Function func) {
   assert(func.first_block());
 
   printf("%10s -> %s\n", _.getIdOrName(func.id()).c_str(),
@@ -237,7 +229,7 @@
 #define UNUSED(func) func
 #endif
 
-UNUSED(void PrintDotGraph(ValidationState_t& _, spvtools::Function func)) {
+UNUSED(void PrintDotGraph(ValidationState_t& _, Function func)) {
   if (func.first_block()) {
     string func_name(_.getIdOrName(func.id()));
     printf("digraph %s {\n", func_name.c_str());
@@ -255,21 +247,21 @@
   spv_endianness_t endian;
   spv_position_t position = {};
   if (spvBinaryEndianness(binary.get(), &endian)) {
-    return spvtools::DiagnosticStream(position, context.consumer, "",
-                                      SPV_ERROR_INVALID_BINARY)
+    return DiagnosticStream(position, context.consumer, "",
+                            SPV_ERROR_INVALID_BINARY)
            << "Invalid SPIR-V magic number.";
   }
 
   spv_header_t header;
   if (spvBinaryHeaderGet(binary.get(), endian, &header)) {
-    return spvtools::DiagnosticStream(position, context.consumer, "",
-                                      SPV_ERROR_INVALID_BINARY)
+    return DiagnosticStream(position, context.consumer, "",
+                            SPV_ERROR_INVALID_BINARY)
            << "Invalid SPIR-V header.";
   }
 
   if (header.version > spvVersionForTargetEnv(context.target_env)) {
-    return spvtools::DiagnosticStream(position, context.consumer, "",
-                                      SPV_ERROR_WRONG_VERSION)
+    return DiagnosticStream(position, context.consumer, "",
+                            SPV_ERROR_WRONG_VERSION)
            << "Invalid SPIR-V binary version "
            << SPV_SPIRV_VERSION_MAJOR_PART(header.version) << "."
            << SPV_SPIRV_VERSION_MINOR_PART(header.version)
@@ -374,7 +366,33 @@
 
   return SPV_SUCCESS;
 }
-}  // anonymous namespace
+
+}  // namespace
+
+spv_result_t ValidateBinaryAndKeepValidationState(
+    const spv_const_context context, spv_const_validator_options options,
+    const uint32_t* words, const size_t num_words, spv_diagnostic* pDiagnostic,
+    std::unique_ptr<ValidationState_t>* vstate) {
+  spv_context_t hijack_context = *context;
+  if (pDiagnostic) {
+    *pDiagnostic = nullptr;
+    UseDiagnosticAsMessageConsumer(&hijack_context, pDiagnostic);
+  }
+
+  vstate->reset(
+      new ValidationState_t(&hijack_context, options, words, num_words));
+
+  return ValidateBinaryUsingContextAndValidationState(
+      hijack_context, words, num_words, pDiagnostic, vstate->get());
+}
+
+spv_result_t ValidateInstructionAndUpdateValidationState(
+    ValidationState_t* vstate, const spv_parsed_instruction_t* inst) {
+  return ProcessInstruction(vstate, inst);
+}
+
+}  // namespace val
+}  // namespace spvtools
 
 spv_result_t spvValidate(const spv_const_context context,
                          const spv_const_binary binary,
@@ -396,10 +414,12 @@
   spv_validator_options default_options = spvValidatorOptionsCreate();
 
   // Create the ValidationState using the context and default options.
-  ValidationState_t vstate(&hijack_context, default_options, words, num_words);
+  spvtools::val::ValidationState_t vstate(&hijack_context, default_options,
+                                          words, num_words);
 
-  spv_result_t result = ValidateBinaryUsingContextAndValidationState(
-      hijack_context, words, num_words, pDiagnostic, &vstate);
+  spv_result_t result =
+      spvtools::val::ValidateBinaryUsingContextAndValidationState(
+          hijack_context, words, num_words, pDiagnostic, &vstate);
 
   spvValidatorOptionsDestroy(default_options);
   return result;
@@ -416,35 +436,9 @@
   }
 
   // Create the ValidationState using the context.
-  ValidationState_t vstate(&hijack_context, options, binary->code,
-                           binary->wordCount);
+  spvtools::val::ValidationState_t vstate(&hijack_context, options,
+                                          binary->code, binary->wordCount);
 
-  return ValidateBinaryUsingContextAndValidationState(
+  return spvtools::val::ValidateBinaryUsingContextAndValidationState(
       hijack_context, binary->code, binary->wordCount, pDiagnostic, &vstate);
 }
-
-namespace spvtools {
-
-spv_result_t ValidateBinaryAndKeepValidationState(
-    const spv_const_context context, spv_const_validator_options options,
-    const uint32_t* words, const size_t num_words, spv_diagnostic* pDiagnostic,
-    std::unique_ptr<ValidationState_t>* vstate) {
-  spv_context_t hijack_context = *context;
-  if (pDiagnostic) {
-    *pDiagnostic = nullptr;
-    spvtools::UseDiagnosticAsMessageConsumer(&hijack_context, pDiagnostic);
-  }
-
-  vstate->reset(
-      new ValidationState_t(&hijack_context, options, words, num_words));
-
-  return ValidateBinaryUsingContextAndValidationState(
-      hijack_context, words, num_words, pDiagnostic, vstate->get());
-}
-
-spv_result_t ValidateInstructionAndUpdateValidationState(
-    ValidationState_t* vstate, const spv_parsed_instruction_t* inst) {
-  return ProcessInstruction(vstate, inst);
-}
-
-}  // namespace spvtools
diff --git a/source/validate.h b/source/validate.h
index ff5cfc7..5d84629 100644
--- a/source/validate.h
+++ b/source/validate.h
@@ -25,6 +25,7 @@
 #include "table.h"
 
 namespace spvtools {
+namespace val {
 
 class ValidationState_t;
 class BasicBlock;
@@ -193,8 +194,6 @@
 spv_result_t PrimitivesPass(ValidationState_t& _,
                             const spv_parsed_instruction_t* inst);
 
-}  // namespace spvtools
-
 /// @brief Validate the ID usage of the instruction stream
 ///
 /// @param[in] pInsts stream of instructions
@@ -205,7 +204,7 @@
 /// @return result code
 spv_result_t spvValidateInstructionIDs(const spv_instruction_t* pInsts,
                                        const uint64_t instCount,
-                                       const spvtools::ValidationState_t& state,
+                                       const ValidationState_t& state,
                                        spv_position position);
 
 /// @brief Validate the ID's within a SPIR-V binary
@@ -220,9 +219,8 @@
 spv_result_t spvValidateIDs(const spv_instruction_t* pInstructions,
                             const uint64_t count, const uint32_t bound,
                             spv_position position,
-                            const spvtools::MessageConsumer& consumer);
+                            const MessageConsumer& consumer);
 
-namespace spvtools {
 // Performs validation for the SPIRV-V module binary.
 // The main difference between this API and spvValidateBinary is that the
 // "Validation State" is not destroyed upon function return; it lives on and is
@@ -230,13 +228,14 @@
 spv_result_t ValidateBinaryAndKeepValidationState(
     const spv_const_context context, spv_const_validator_options options,
     const uint32_t* words, const size_t num_words, spv_diagnostic* pDiagnostic,
-    std::unique_ptr<spvtools::ValidationState_t>* vstate);
+    std::unique_ptr<ValidationState_t>* vstate);
 
 // Performs validation for a single instruction and updates given validation
 // state.
 spv_result_t ValidateInstructionAndUpdateValidationState(
-    spvtools::ValidationState_t* vstate, const spv_parsed_instruction_t* inst);
+    ValidationState_t* vstate, const spv_parsed_instruction_t* inst);
 
+}  // namespace val
 }  // namespace spvtools
 
 #endif  // LIBSPIRV_VALIDATE_H_
diff --git a/source/validate_adjacency.cpp b/source/validate_adjacency.cpp
index 4999d5c..da79685 100644
--- a/source/validate_adjacency.cpp
+++ b/source/validate_adjacency.cpp
@@ -25,6 +25,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 spv_result_t ValidateAdjacency(ValidationState_t& _) {
   const auto& instructions = _.ordered_instructions();
@@ -81,4 +82,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_arithmetics.cpp b/source/validate_arithmetics.cpp
index 328c54e..3460cde 100644
--- a/source/validate_arithmetics.cpp
+++ b/source/validate_arithmetics.cpp
@@ -22,7 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
-
+namespace val {
 namespace {
 
 // Returns operand word for given instruction and operand index.
@@ -42,6 +42,7 @@
                                  size_t operand_index) {
   return _.GetTypeId(GetOperandWord(inst, operand_index));
 }
+
 }  // namespace
 
 // Validates correctness of arithmetic instructions.
@@ -468,4 +469,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_atomics.cpp b/source/validate_atomics.cpp
index 82b0d71..b4a196c 100644
--- a/source/validate_atomics.cpp
+++ b/source/validate_atomics.cpp
@@ -24,6 +24,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 // Validates Memory Scope operand.
 spv_result_t ValidateMemoryScope(ValidationState_t& _,
@@ -318,4 +319,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_barriers.cpp b/source/validate_barriers.cpp
index 8cb1c28..8985ada 100644
--- a/source/validate_barriers.cpp
+++ b/source/validate_barriers.cpp
@@ -25,6 +25,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Validates Execution Scope operand.
@@ -189,7 +190,7 @@
   return SPV_SUCCESS;
 }
 
-}  // anonymous namespace
+}  // namespace
 
 // Validates correctness of barrier instructions.
 spv_result_t BarriersPass(ValidationState_t& _,
@@ -295,4 +296,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_bitwise.cpp b/source/validate_bitwise.cpp
index 63e7d0d..cd00cd6 100644
--- a/source/validate_bitwise.cpp
+++ b/source/validate_bitwise.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns operand word for given instruction and operand index.
@@ -41,6 +42,7 @@
                                  size_t operand_index) {
   return _.GetTypeId(GetOperandWord(inst, operand_index));
 }
+
 }  // namespace
 
 // Validates correctness of bitwise instructions.
@@ -235,4 +237,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_builtins.cpp b/source/validate_builtins.cpp
index 6221912..eca4d89 100644
--- a/source/validate_builtins.cpp
+++ b/source/validate_builtins.cpp
@@ -33,6 +33,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns a short textual description of the id defined by the given
@@ -2535,7 +2536,7 @@
   return SPV_SUCCESS;
 }
 
-}  // anonymous namespace
+}  // namespace
 
 // Validates correctness of built-in variables.
 spv_result_t ValidateBuiltIns(const ValidationState_t& _) {
@@ -2554,4 +2555,5 @@
   return validator.Run();
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_capability.cpp b/source/validate_capability.cpp
index c26ec8e..11e3506 100644
--- a/source/validate_capability.cpp
+++ b/source/validate_capability.cpp
@@ -25,6 +25,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 bool IsSupportGuaranteedVulkan_1_0(uint32_t capability) {
@@ -305,4 +306,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_cfg.cpp b/source/validate_cfg.cpp
index 5f8b923..e09063a 100644
--- a/source/validate_cfg.cpp
+++ b/source/validate_cfg.cpp
@@ -50,13 +50,7 @@
 using std::vector;
 
 namespace spvtools {
-namespace {
-
-using bb_ptr = BasicBlock*;
-using cbb_ptr = const BasicBlock*;
-using bb_iter = vector<BasicBlock*>::const_iterator;
-
-}  // namespace
+namespace val {
 
 void printDominatorList(const BasicBlock& b) {
   std::cout << b.id() << " is dominated by: ";
@@ -476,13 +470,13 @@
     vector<const BasicBlock*> postorder;
     vector<const BasicBlock*> postdom_postorder;
     vector<pair<uint32_t, uint32_t>> back_edges;
-    auto ignore_block = [](cbb_ptr) {};
-    auto ignore_edge = [](cbb_ptr, cbb_ptr) {};
+    auto ignore_block = [](const BasicBlock*) {};
+    auto ignore_edge = [](const BasicBlock*, const BasicBlock*) {};
     if (!function.ordered_blocks().empty()) {
       /// calculate dominators
       CFA<BasicBlock>::DepthFirstTraversal(
           function.first_block(), function.AugmentedCFGSuccessorsFunction(),
-          ignore_block, [&](cbb_ptr b) { postorder.push_back(b); },
+          ignore_block, [&](const BasicBlock* b) { postorder.push_back(b); },
           ignore_edge);
       auto edges = CFA<BasicBlock>::CalculateDominators(
           postorder, function.AugmentedCFGPredecessorsFunction());
@@ -494,7 +488,8 @@
       CFA<BasicBlock>::DepthFirstTraversal(
           function.pseudo_exit_block(),
           function.AugmentedCFGPredecessorsFunction(), ignore_block,
-          [&](cbb_ptr b) { postdom_postorder.push_back(b); }, ignore_edge);
+          [&](const BasicBlock* b) { postdom_postorder.push_back(b); },
+          ignore_edge);
       auto postdom_edges = CFA<BasicBlock>::CalculateDominators(
           postdom_postorder, function.AugmentedCFGSuccessorsFunction());
       for (auto edge : postdom_edges) {
@@ -505,7 +500,8 @@
           function.pseudo_entry_block(),
           function
               .AugmentedCFGSuccessorsFunctionIncludingHeaderToContinueEdge(),
-          ignore_block, ignore_block, [&](cbb_ptr from, cbb_ptr to) {
+          ignore_block, ignore_block,
+          [&](const BasicBlock* from, const BasicBlock* to) {
             back_edges.emplace_back(from->id(), to->id());
           });
     }
@@ -630,4 +626,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_composites.cpp b/source/validate_composites.cpp
index a2f9c3b..f4ba74e 100644
--- a/source/validate_composites.cpp
+++ b/source/validate_composites.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns the type of the value accessed by OpCompositeExtract or
@@ -477,4 +478,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_conversion.cpp b/source/validate_conversion.cpp
index 8442d6d..a4e75ed 100644
--- a/source/validate_conversion.cpp
+++ b/source/validate_conversion.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 // Validates correctness of conversion instructions.
 spv_result_t ConversionPass(ValidationState_t& _,
@@ -409,4 +410,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_datarules.cpp b/source/validate_datarules.cpp
index debc62b..59dba8b 100644
--- a/source/validate_datarules.cpp
+++ b/source/validate_datarules.cpp
@@ -27,6 +27,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Validates that the number of components in the vector is valid.
@@ -266,4 +267,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_decorations.cpp b/source/validate_decorations.cpp
index 02b320c..9b320a0 100644
--- a/source/validate_decorations.cpp
+++ b/source/validate_decorations.cpp
@@ -27,6 +27,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 using std::make_pair;
@@ -814,4 +815,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_derivatives.cpp b/source/validate_derivatives.cpp
index 6b55f81..5a794f3 100644
--- a/source/validate_derivatives.cpp
+++ b/source/validate_derivatives.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 // Validates correctness of derivative instructions.
 spv_result_t DerivativesPass(ValidationState_t& _,
@@ -66,4 +67,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_ext_inst.cpp b/source/validate_ext_inst.cpp
index f1b48f4..85e9dcf 100644
--- a/source/validate_ext_inst.cpp
+++ b/source/validate_ext_inst.cpp
@@ -27,6 +27,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 uint32_t GetSizeTBitWidth(const ValidationState_t& _) {
@@ -1984,4 +1985,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_id.cpp b/source/validate_id.cpp
index 5238cd3..25d5f80 100644
--- a/source/validate_id.cpp
+++ b/source/validate_id.cpp
@@ -42,6 +42,7 @@
 using std::vector;
 
 namespace spvtools {
+namespace val {
 namespace {
 
 class idUsage {
@@ -2796,18 +2797,18 @@
   return SPV_SUCCESS;
 }
 
-}  // namespace spvtools
-
 spv_result_t spvValidateInstructionIDs(const spv_instruction_t* pInsts,
                                        const uint64_t instCount,
-                                       const spvtools::ValidationState_t& state,
+                                       const ValidationState_t& state,
                                        spv_position position) {
-  spvtools::idUsage idUsage(state.context(), pInsts, instCount,
-                            state.memory_model(), state.addressing_model(),
-                            state, state.entry_points(), position,
-                            state.context()->consumer);
+  idUsage idUsage(state.context(), pInsts, instCount, state.memory_model(),
+                  state.addressing_model(), state, state.entry_points(),
+                  position, state.context()->consumer);
   for (uint64_t instIndex = 0; instIndex < instCount; ++instIndex) {
     if (!idUsage.isValid(&pInsts[instIndex])) return SPV_ERROR_INVALID_ID;
   }
   return SPV_SUCCESS;
 }
+
+}  // namespace val
+}  // namespace spvtools
diff --git a/source/validate_image.cpp b/source/validate_image.cpp
index 6822f3a..e4dbe76 100644
--- a/source/validate_image.cpp
+++ b/source/validate_image.cpp
@@ -24,6 +24,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Performs compile time check that all SpvImageOperandsXXX cases are handled in
@@ -1666,4 +1667,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_instruction.cpp b/source/validate_instruction.cpp
index 6e28f8c..605ae3c 100644
--- a/source/validate_instruction.cpp
+++ b/source/validate_instruction.cpp
@@ -38,6 +38,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 std::string ToString(const CapabilitySet& capabilities,
@@ -604,4 +605,6 @@
   // All instruction checks have passed.
   return SPV_SUCCESS;
 }
+
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_interfaces.cpp b/source/validate_interfaces.cpp
index 230d594..3f821b5 100644
--- a/source/validate_interfaces.cpp
+++ b/source/validate_interfaces.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns true if \c inst is an input or output variable.
@@ -108,4 +109,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_layout.cpp b/source/validate_layout.cpp
index e1b422e..287a49e 100644
--- a/source/validate_layout.cpp
+++ b/source/validate_layout.cpp
@@ -26,6 +26,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Module scoped instructions are processed by determining if the opcode
@@ -200,4 +201,6 @@
   }
   return SPV_SUCCESS;
 }
+
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_literals.cpp b/source/validate_literals.cpp
index 3e4083c..3f8e55e 100644
--- a/source/validate_literals.cpp
+++ b/source/validate_literals.cpp
@@ -24,6 +24,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns true if the operand holds a literal number
@@ -95,4 +96,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_logicals.cpp b/source/validate_logicals.cpp
index 051aad7..a893d3f 100644
--- a/source/validate_logicals.cpp
+++ b/source/validate_logicals.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 // Returns operand word for given instruction and operand index.
@@ -280,4 +281,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_non_uniform.cpp b/source/validate_non_uniform.cpp
index 3d5d832..de42dea 100644
--- a/source/validate_non_uniform.cpp
+++ b/source/validate_non_uniform.cpp
@@ -25,6 +25,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 spv_result_t ValidateExecutionScope(ValidationState_t& _,
@@ -80,4 +81,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_primitives.cpp b/source/validate_primitives.cpp
index 564c0dc..4705496 100644
--- a/source/validate_primitives.cpp
+++ b/source/validate_primitives.cpp
@@ -24,6 +24,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 // Validates correctness of primitive instructions.
 spv_result_t PrimitivesPass(ValidationState_t& _,
@@ -70,4 +71,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/source/validate_type_unique.cpp b/source/validate_type_unique.cpp
index ea7c3b2..c251f6c 100644
--- a/source/validate_type_unique.cpp
+++ b/source/validate_type_unique.cpp
@@ -22,6 +22,7 @@
 #include "val/validation_state.h"
 
 namespace spvtools {
+namespace val {
 
 // Validates that type declarations are unique, unless multiple declarations
 // of the same data type are allowed by the specification.
@@ -53,4 +54,5 @@
   return SPV_SUCCESS;
 }
 
+}  // namespace val
 }  // namespace spvtools
diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp
index e819d19..9dc1e8d 100644
--- a/test/val/val_decoration_test.cpp
+++ b/test/val/val_decoration_test.cpp
@@ -20,6 +20,7 @@
 #include "val_fixtures.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 using std::string;
@@ -2664,4 +2665,5 @@
 }
 
 }  // namespace
+}  // namespace val
 }  // namespace spvtools
diff --git a/test/val/val_fixtures.h b/test/val/val_fixtures.h
index 1615bbe..21762e8 100644
--- a/test/val/val_fixtures.h
+++ b/test/val/val_fixtures.h
@@ -60,7 +60,7 @@
   spv_binary binary_;
   spv_diagnostic diagnostic_;
   spv_validator_options options_;
-  std::unique_ptr<spvtools::ValidationState_t> vstate_;
+  std::unique_ptr<spvtools::val::ValidationState_t> vstate_;
 };
 
 template <typename T>
@@ -114,7 +114,7 @@
 template <typename T>
 spv_result_t ValidateBase<T>::ValidateAndRetrieveValidationState(
     spv_target_env env) {
-  return spvtools::ValidateBinaryAndKeepValidationState(
+  return spvtools::val::ValidateBinaryAndKeepValidationState(
       ScopedContext(env).context, options_, get_const_binary()->code,
       get_const_binary()->wordCount, &diagnostic_, &vstate_);
 }
diff --git a/test/val/val_state_test.cpp b/test/val/val_state_test.cpp
index d9d7a07..76c2ed4 100644
--- a/test/val/val_state_test.cpp
+++ b/test/val/val_state_test.cpp
@@ -29,6 +29,7 @@
 #include "validate.h"
 
 namespace spvtools {
+namespace val {
 namespace {
 
 using std::vector;
@@ -136,4 +137,5 @@
 }
 
 }  // namespace
+}  // namespace val
 }  // namespace spvtools
diff --git a/test/val/val_storage_test.cpp b/test/val/val_storage_test.cpp
index 02ef6f5..3df19ce 100644
--- a/test/val/val_storage_test.cpp
+++ b/test/val/val_storage_test.cpp
@@ -21,11 +21,14 @@
 #include "gmock/gmock.h"
 #include "val_fixtures.h"
 
+namespace spvtools {
+namespace val {
+namespace {
+
 using ::testing::HasSubstr;
 
 using ValidateStorage = spvtest::ValidateBase<std::string>;
 
-namespace {
 
 TEST_F(ValidateStorage, FunctionStorageInsideFunction) {
   char str[] = R"(
@@ -175,4 +178,7 @@
   EXPECT_THAT(getDiagnosticString(),
               HasSubstr("OpVariable storage class cannot be Generic"));
 }
+
 }  // namespace
+}  // namespace val
+}  // namespace spvtools