Add support for setjmp/longjmp primitives
authorChris Lattner <sabre@nondot.org>
Sat, 17 May 2003 22:26:33 +0000 (22:26 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 May 2003 22:26:33 +0000 (22:26 +0000)
Patch checked in for Bill Wendling :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6241 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Intrinsics.h
lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp
lib/VMCore/Function.cpp
lib/VMCore/Verifier.cpp

index c07d9c1a8268387e2cadb8f09c28888c7ed28c0b..a1deb5f3d6944fa7b572517d79ebdb1431e8dd70 100644 (file)
 namespace LLVMIntrinsic {
   enum ID {
     not_intrinsic = 0,   // Must be zero
+
     va_start,            // Used to represent a va_start call in C
     va_end,              // Used to represent a va_end call in C
     va_copy,             // Used to represent a va_copy call in C
+
+    setjmp,              // Used to represent a setjmp call in C
+    longjmp,             // Used to represent a longjmp call in C
   };
 }
 
index 577054e245ce6b48696b963a6d9d076334fdccf2..bfd6bc953e82a149ca128e3e3950e74cceb9c8f9 100644 (file)
@@ -543,6 +543,7 @@ void CWriter::printModule(Module *M) {
   Out << "/* Provide Declarations */\n";
   generateAllocaDecl(Out);
   Out << "#include <stdarg.h>\n";
+  Out << "#include <setjmp.h>\n";
   
   // Provide a definition for null if one does not already exist,
   // and for `bool' if not compiling with a C++ compiler.
@@ -1022,7 +1023,6 @@ void CWriter::visitCallInst(CallInst &I) {
         writeOperand(&I.getParent()->getParent()->aback());
         Out << ")";
         return;
-
       case LLVMIntrinsic::va_end:
         Out << "va_end((va_list)*";
         writeOperand(I.getOperand(1));
@@ -1035,6 +1035,19 @@ void CWriter::visitCallInst(CallInst &I) {
         writeOperand(I.getOperand(2));
         Out << ")";
         return;
+        
+      case LLVMIntrinsic::setjmp:
+        Out << "setjmp((jmp_buf)";
+        writeOperand(I.getOperand(1));
+        Out << ")";
+        return;
+      case LLVMIntrinsic::longjmp:
+        Out << "longjmp((jmp_buf)";
+        writeOperand(I.getOperand(1));
+        Out << ", ";
+        writeOperand(I.getOperand(2));
+        Out << ")";
+        return;
       }
     }
 
index 577054e245ce6b48696b963a6d9d076334fdccf2..bfd6bc953e82a149ca128e3e3950e74cceb9c8f9 100644 (file)
@@ -543,6 +543,7 @@ void CWriter::printModule(Module *M) {
   Out << "/* Provide Declarations */\n";
   generateAllocaDecl(Out);
   Out << "#include <stdarg.h>\n";
+  Out << "#include <setjmp.h>\n";
   
   // Provide a definition for null if one does not already exist,
   // and for `bool' if not compiling with a C++ compiler.
@@ -1022,7 +1023,6 @@ void CWriter::visitCallInst(CallInst &I) {
         writeOperand(&I.getParent()->getParent()->aback());
         Out << ")";
         return;
-
       case LLVMIntrinsic::va_end:
         Out << "va_end((va_list)*";
         writeOperand(I.getOperand(1));
@@ -1035,6 +1035,19 @@ void CWriter::visitCallInst(CallInst &I) {
         writeOperand(I.getOperand(2));
         Out << ")";
         return;
+        
+      case LLVMIntrinsic::setjmp:
+        Out << "setjmp((jmp_buf)";
+        writeOperand(I.getOperand(1));
+        Out << ")";
+        return;
+      case LLVMIntrinsic::longjmp:
+        Out << "longjmp((jmp_buf)";
+        writeOperand(I.getOperand(1));
+        Out << ", ";
+        writeOperand(I.getOperand(2));
+        Out << ")";
+        return;
       }
     }
 
index 0d5f90b45df271edf1ee0be8b6c84df663dc0e2c..89195a34a42cd294d559e72ecb6fd68ca6993aeb 100644 (file)
@@ -164,20 +164,16 @@ unsigned Function::getIntrinsicID() const {
     return 0;  // All intrinsics start with 'llvm.'
   
   switch (getName()[5]) {
+  case 'l':
+    if (getName() == "llvm.longjmp")  return LLVMIntrinsic::longjmp;
+    break;
+  case 's':
+    if (getName() == "llvm.setjmp")   return LLVMIntrinsic::setjmp;
+    break;
   case 'v':
-    if (getName().size() >= 9) {
-      switch (getName()[8]) {
-      case 's':
-        if (getName() == "llvm.va_start") return LLVMIntrinsic::va_start;
-        break;
-      case 'e':
-        if (getName() == "llvm.va_end") return LLVMIntrinsic::va_end;
-        break;
-      case 'c':
-        if (getName() == "llvm.va_copy") return LLVMIntrinsic::va_copy;
-        break;
-      }
-    }
+    if (getName() == "llvm.va_copy")  return LLVMIntrinsic::va_copy;
+    if (getName() == "llvm.va_end")   return LLVMIntrinsic::va_end;
+    if (getName() == "llvm.va_start") return LLVMIntrinsic::va_start;
     break;
   }
   // The "llvm." namespace is reserved!
index 7dc870fd398aaf19ce88c690249728a74942aa9e..54f8f050141c86e4efcd3086221225d052ca1b29 100644 (file)
@@ -517,8 +517,10 @@ void Verifier::visitIntrinsicFunctionCall(LLVMIntrinsic::ID ID, CallInst &CI) {
             " args!", &CI);
     NumArgs = 1;
     break;
-  case LLVMIntrinsic::va_end: NumArgs = 1; break;
+  case LLVMIntrinsic::va_end:  NumArgs = 1; break;
   case LLVMIntrinsic::va_copy: NumArgs = 2; break;
+  case LLVMIntrinsic::setjmp:  NumArgs = 1; break;
+  case LLVMIntrinsic::longjmp: NumArgs = 2; break;
   case LLVMIntrinsic::not_intrinsic: 
     assert(0 && "Invalid intrinsic!"); NumArgs = 0; break;
   }