This patch moves from using a hard coded number (4)
authorJack Carter <jcarter@mips.com>
Wed, 3 Oct 2012 21:58:54 +0000 (21:58 +0000)
committerJack Carter <jcarter@mips.com>
Wed, 3 Oct 2012 21:58:54 +0000 (21:58 +0000)
for the number of bytes in a particular instruction
to using
   const MCInstrDesc &Desc = MCII.get(TmpInst.getOpcode());
   Desc.getSize()

This is necessary with the advent of 16 bit instructions with
mips16 and micromips. It is also puts Mips in compliance with
the other targets for getting instruction size.

llvm-svn: 165171

llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp

index 06882e1..7fbdae0 100644 (file)
@@ -146,8 +146,10 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS,
   if ((TSFlags & MipsII::FormMask) == MipsII::Pseudo)
     llvm_unreachable("Pseudo opcode found in EncodeInstruction()");
 
-  // For now all instructions are 4 bytes
-  int Size = 4; // FIXME: Have Desc.getSize() return the correct value!
+  // Get byte count of instruction
+  unsigned Size = Desc.getSize();
+  if (!Size)
+    llvm_unreachable("Desc.getSize() returns 0");
 
   EmitInstruction(Binary, Size, OS);
 }