aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-17 22:26:33 +0000
committerChris Lattner <sabre@nondot.org>2003-05-17 22:26:33 +0000
commitc436b37262fd1552fd591f50e14a7ff0067465e2 (patch)
treec9269f027b23d129cc50c7037d6e1e837498825e
parent9b11f4871162d911f372cef1586fdd17910ed58f (diff)
Add support for setjmp/longjmp primitives
Patch checked in for Bill Wendling :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6241 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Intrinsics.h4
-rw-r--r--lib/Target/CBackend/CBackend.cpp15
-rw-r--r--lib/Target/CBackend/Writer.cpp15
-rw-r--r--lib/VMCore/Function.cpp22
-rw-r--r--lib/VMCore/Verifier.cpp4
5 files changed, 44 insertions, 16 deletions
diff --git a/include/llvm/Intrinsics.h b/include/llvm/Intrinsics.h
index c07d9c1a82..a1deb5f3d6 100644
--- a/include/llvm/Intrinsics.h
+++ b/include/llvm/Intrinsics.h
@@ -12,9 +12,13 @@
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
};
}
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 577054e245..bfd6bc953e 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -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;
}
}
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 577054e245..bfd6bc953e 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -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;
}
}
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 0d5f90b45d..89195a34a4 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -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!
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 7dc870fd39..54f8f05014 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -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;
}