[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Thu Oct 28 12:37:51 PDT 2004



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.130 -> 1.131
---
Log message:

i2c, i2b and i2s truncate the value and cast it back to an int before
pushing it on the operand stack.


---
Diffs of the changes:  (+10 -3)

Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.130 llvm-java/lib/Compiler/Compiler.cpp:1.131
--- llvm-java/lib/Compiler/Compiler.cpp:1.130	Thu Oct 28 02:49:05 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Thu Oct 28 14:37:41 2004
@@ -1200,9 +1200,9 @@
     void do_d2i() { do_cast_common(Type::IntTy); }
     void do_d2l() { do_cast_common(Type::LongTy); }
     void do_d2f() { do_cast_common(Type::FloatTy); }
-    void do_i2b() { do_cast_common(Type::SByteTy); }
-    void do_i2c() { do_cast_common(Type::UShortTy); }
-    void do_i2s() { do_cast_common(Type::ShortTy); }
+    void do_i2b() { do_truncate_common(Type::SByteTy); }
+    void do_i2c() { do_truncate_common(Type::UShortTy); }
+    void do_i2s() { do_truncate_common(Type::ShortTy); }
 
     void do_cast_common(Type* type) {
       Value* v1 = currentOpStack_->pop(currentBB_);
@@ -1210,6 +1210,13 @@
       currentOpStack_->push(v1, currentBB_);
     }
 
+    void do_truncate_common(Type* type) {
+      Value* v1 = currentOpStack_->pop(currentBB_);
+      v1 = new CastInst(v1, type, TMP, currentBB_);
+      v1 = new CastInst(v1, Type::IntTy, TMP, currentBB_);
+      currentOpStack_->push(v1, currentBB_);
+    }
+
     void do_lcmp() {
       Value* v2 = currentOpStack_->pop(currentBB_);
       Value* v1 = currentOpStack_->pop(currentBB_);






More information about the llvm-commits mailing list