Turn on SpecConstantOpMode based on node qualifier

Move SpecConstantOpModeGuard from makeSpvConstantFromConstSubTree() to
visitbinary() and visitunary(). Checking if the visiting node is a spec
constants, if so, turn on the SpecConstantOpMode, otherwise, stay in the
normal mode.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 63c3d40..147a4bd 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -72,12 +72,14 @@
     SpecConstantOpModeGuard(spv::Builder* builder)
         : builder_(builder) {
         previous_flag_ = builder->isInSpecConstCodeGenMode();
-        builder->setToSpecConstCodeGenMode();
     }
     ~SpecConstantOpModeGuard() {
         previous_flag_ ? builder_->setToSpecConstCodeGenMode()
                        : builder_->setToNormalCodeGenMode();
     }
+    void turnOnSpecConstantOpMode() {
+        builder_->setToSpecConstCodeGenMode();
+    }
 
 private:
     spv::Builder* builder_;
@@ -813,6 +815,10 @@
 
 bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node)
 {
+    SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
+    if (node->getType().getQualifier().isSpecConstant())
+        spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
+
     // First, handle special cases
     switch (node->getOp()) {
     case glslang::EOpAssign:
@@ -985,6 +991,10 @@
 
 bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node)
 {
+    SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
+    if (node->getType().getQualifier().isSpecConstant())
+        spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
+
     spv::Id result = spv::NoResult;
 
     // try texturing first
@@ -1946,7 +1956,7 @@
     glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
     if (specNode != nullptr) {
         builder.clearAccessChain();
-        SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
+        // SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
         specNode->traverse(this);
         return accessChainLoad(specNode->getAsTyped()->getType());
     }
@@ -3920,22 +3930,12 @@
     } else if (glslang::TIntermBinary* bn = subTree->getAsBinaryNode()) {
         // Binary operation node, we should generate OpSpecConstantOp <binary op>
         // This case should only happen when Specialization Constants are involved.
-
-        // Spec constants defined with binary operations and other constants requires
-        // OpSpecConstantOp instruction.
-        SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
-
         bn->traverse(this);
         return accessChainLoad(bn->getType());
 
     } else if (glslang::TIntermUnary* un = subTree->getAsUnaryNode()) {
         // Unary operation node, similar to binary operation node, should only
         // happen when specialization constants are involved.
-
-        // Spec constants defined with unary operations and other constants requires
-        // OpSpecConstantOp instruction.
-        SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
-
         un->traverse(this);
         return accessChainLoad(un->getType());