[llvm-commits] CVS: llvm/lib/Target/TargetAsmInfo.cpp

Dale Johannesen dalej at apple.com
Mon Apr 23 13:00:35 PDT 2007



Changes in directory llvm/lib/Target:

TargetAsmInfo.cpp updated: 1.22 -> 1.23
---
Log message:

Fix generic getInlineAsmLength


---
Diffs of the changes:  (+18 -4)

 TargetAsmInfo.cpp |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/TargetAsmInfo.cpp
diff -u llvm/lib/Target/TargetAsmInfo.cpp:1.22 llvm/lib/Target/TargetAsmInfo.cpp:1.23
--- llvm/lib/Target/TargetAsmInfo.cpp:1.22	Fri Apr 20 16:38:10 2007
+++ llvm/lib/Target/TargetAsmInfo.cpp	Mon Apr 23 15:00:17 2007
@@ -13,6 +13,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Target/TargetAsmInfo.h"
+#include <cctype>
+#include <cstring>
 
 using namespace llvm;
 
@@ -100,15 +102,27 @@
 
 /// Measure the specified inline asm to determine an approximation of its
 /// length.
+/// Comments (which run till the next SeparatorChar or newline) do not
+/// count as an instruction.
+/// Any other non-whitespace text is considered an instruction, with
+/// multiple instructions separated by SeparatorChar or newlines.
+/// Variable-length instructions are not handled here; this function
+/// may be overloaded in the target code to do that.
 unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
   // Count the number of instructions in the asm.
-  unsigned NumInsts = 0;
+  bool atInsnStart = true;
+  unsigned Length = 0;
   for (; *Str; ++Str) {
     if (*Str == '\n' || *Str == SeparatorChar)
-      ++NumInsts;
+      atInsnStart = true;
+    if (atInsnStart && !isspace(*Str)) {
+      Length += MaxInstLength;
+      atInsnStart = false;
+    }
+    if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
+      atInsnStart = false;
   }
 
-  // Multiply by the worst-case length for each instruction.
-  return NumInsts * MaxInstLength;
+  return Length;
 }
 






More information about the llvm-commits mailing list