Re-commit r152202 hopefully fixing the MSVC linker error.

Original commit message:
Use uint16_t to store InstrNameIndices in MCInstrInfo. Add asserts to protect all 16-bit string table offsets. Also make sure the string to offset table string is not larger than 65536 characters since larger string literals aren't portable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152296 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp
index cdcc496..4afee21 100644
--- a/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2023,7 +2023,7 @@
   // Emit the static custom operand parsing table;
   OS << "namespace {\n";
   OS << "  struct OperandMatchEntry {\n";
-  OS << "    static const char *MnemonicTable;\n";
+  OS << "    static const char *const MnemonicTable;\n";
   OS << "    unsigned OperandMask;\n";
   OS << "    uint16_t Mnemonic;\n";
   OS << "    " << getMinimalTypeForRange(Info.Classes.size())
@@ -2079,8 +2079,9 @@
 
     // Store a pascal-style length byte in the mnemonic.
     std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
-    OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false)
-       << " /* " << II.Mnemonic << " */";
+    unsigned Idx = StringTable.GetOrAddStringOffset(LenMnemonic, false);
+    assert(Idx <= 0xffff && "String offset too large to fit in table");
+    OS << ", " << Idx << " /* " << II.Mnemonic << " */";
 
     OS << ", " << OMI.CI->Name
        << ", ";
@@ -2097,7 +2098,7 @@
   }
   OS << "};\n\n";
 
-  OS << "const char *OperandMatchEntry::MnemonicTable =\n";
+  OS << "const char *const OperandMatchEntry::MnemonicTable =\n";
   StringTable.EmitString(OS);
   OS << ";\n\n";
 
@@ -2320,7 +2321,7 @@
   // following the mnemonic.
   OS << "namespace {\n";
   OS << "  struct MatchEntry {\n";
-  OS << "    static const char *MnemonicTable;\n";
+  OS << "    static const char *const MnemonicTable;\n";
   OS << "    uint16_t Opcode;\n";
   OS << "    uint16_t Mnemonic;\n";
   OS << "    " << getMinimalTypeForRange(Info.Matchables.size())
@@ -2363,10 +2364,11 @@
 
     // Store a pascal-style length byte in the mnemonic.
     std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
+    unsigned Idx = StringTable.GetOrAddStringOffset(LenMnemonic, false);
+    assert(Idx <= 0xffff && "String offset too large to fit in table");
     OS << "  { " << Target.getName() << "::"
        << II.getResultInst()->TheDef->getName() << ", "
-       << StringTable.GetOrAddStringOffset(LenMnemonic, false)
-       << " /* " << II.Mnemonic << " */"
+       << Idx << " /* " << II.Mnemonic << " */"
        << ", " << II.ConversionFnKind << ", { ";
     for (unsigned i = 0, e = II.AsmOperands.size(); i != e; ++i) {
       MatchableInfo::AsmOperand &Op = II.AsmOperands[i];
@@ -2390,7 +2392,7 @@
 
   OS << "};\n\n";
 
-  OS << "const char *MatchEntry::MnemonicTable =\n";
+  OS << "const char *const MatchEntry::MnemonicTable =\n";
   StringTable.EmitString(OS);
   OS << ";\n\n";