aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-10-27 04:15:57 +0000
committerChris Lattner <sabre@nondot.org>2001-10-27 04:15:57 +0000
commite43db88b2d12f2aebbe62aca8465a46c92292fce (patch)
tree5000957a2f8f861cbf457dd2b916ff6cb3103409 /lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
parent7dcd61209a1575e82ea23430cf9099a8b8086dbb (diff)
* Implement exit() builtin function
* Implement linked in runtime library with puts(char*) in it * implement builtin putchar(int) function git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@985 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp')
-rw-r--r--lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index bcd584a6b5..973cca6842 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -18,6 +18,24 @@
typedef GenericValue (*ExFunc)(MethodType *, const vector<GenericValue> &);
static map<const Method *, ExFunc> Functions;
+static Interpreter *TheInterpreter;
+
+// getCurrentExecutablePath() - Return the directory that the lli executable
+// lives in.
+//
+string Interpreter::getCurrentExecutablePath() const {
+ Dl_info Info;
+ if (dladdr(&TheInterpreter, &Info) == 0) return "";
+
+ string LinkAddr(Info.dli_fname);
+ unsigned SlashPos = LinkAddr.rfind('/');
+ if (SlashPos != string::npos)
+ LinkAddr.resize(SlashPos); // Trim the executable name off...
+
+ return LinkAddr;
+}
+
+
static char getTypeID(const Type *Ty) {
switch (Ty->getPrimitiveID()) {
case Type::VoidTyID: return 'V';
@@ -61,6 +79,8 @@ static ExFunc lookupMethod(const Method *M) {
void Interpreter::callExternalMethod(Method *M,
const vector<GenericValue> &ArgVals) {
+ TheInterpreter = this;
+
// Do a lookup to see if the method is in our cache... this should just be a
// defered annotation!
map<const Method *, ExFunc>::iterator FI = Functions.find(M);
@@ -127,10 +147,16 @@ GenericValue lle_Vb_putchar(MethodType *M, const vector<GenericValue> &Args) {
return GenericValue();
}
+// int "putchar"(int)
+GenericValue lle_ii_putchar(MethodType *M, const vector<GenericValue> &Args) {
+ cout << ((char)Args[0].IntVal) << flush;
+ return Args[0];
+}
+
// void "putchar"(ubyte)
GenericValue lle_VB_putchar(MethodType *M, const vector<GenericValue> &Args) {
- cout << Args[0].UByteVal;
- return GenericValue();
+ cout << Args[0].SByteVal << flush;
+ return Args[0];
}
// void "__main"()
@@ -138,4 +164,10 @@ GenericValue lle_V___main(MethodType *M, const vector<GenericValue> &Args) {
return GenericValue();
}
+// void "exit"(int)
+GenericValue lle_Vi_exit(MethodType *M, const vector<GenericValue> &Args) {
+ TheInterpreter->exitCalled(Args[0]);
+ return GenericValue();
+}
+
} // End extern "C"