diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-05-19 01:36:17 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-05-19 01:36:17 +0000 |
commit | cc442cabf6585084ae6238f8003c14e5ebc386f6 (patch) | |
tree | 9127440f2529e0a9ff9b33c64493008749d8cea8 /lib/ExecutionEngine | |
parent | 8a282967efead093e8be526d6997e446d6e09b86 (diff) | |
download | external_llvm-cc442cabf6585084ae6238f8003c14e5ebc386f6.zip external_llvm-cc442cabf6585084ae6238f8003c14e5ebc386f6.tar.gz external_llvm-cc442cabf6585084ae6238f8003c14e5ebc386f6.tar.bz2 |
On Linux platforms and at optimization levels -O1 and above, llvm-gcc can
turn "putchar" calls into _IO_putc calls which is a lower-level interface.
This patch allows these calls to be executed by lli in interpreter mode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37254 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 53f5deb..14dcdf9 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -72,13 +72,13 @@ static ExFunc lookupFunction(const Function *F) { ExFunc FnPtr = FuncNames[ExtName]; if (FnPtr == 0) - FnPtr = - (ExFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol(ExtName); - if (FnPtr == 0) FnPtr = FuncNames["lle_X_"+F->getName()]; if (FnPtr == 0) // Try calling a generic function... if it exists... FnPtr = (ExFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol( ("lle_X_"+F->getName()).c_str()); + if (FnPtr == 0) + FnPtr = (ExFunc)(intptr_t) + sys::DynamicLibrary::SearchForAddressOfSymbol(F->getName()); if (FnPtr != 0) Functions.insert(std::make_pair(F, FnPtr)); // Cache for later return FnPtr; @@ -118,6 +118,16 @@ GenericValue lle_X_putchar(FunctionType *FT, const vector<GenericValue> &Args){ return Args[0]; } +// void _IO_putc(int c, FILE* fp) +GenericValue lle_X__IO_putc(FunctionType *FT, const vector<GenericValue> &Args){ +#ifdef __linux__ + _IO_putc((char)Args[0].IntVal.getZExtValue(), (FILE*) Args[1].PointerVal); +#else + assert(0 && "Can't call _IO_putc on this platform"); +#endif + return Args[0]; +} + // void atexit(Function*) GenericValue lle_X_atexit(FunctionType *FT, const vector<GenericValue> &Args) { assert(Args.size() == 1); @@ -694,6 +704,7 @@ GenericValue lle_X_fprintf(FunctionType *FT, const vector<GenericValue> &Args) { void Interpreter::initializeExternalFunctions() { FuncNames["lle_X_putchar"] = lle_X_putchar; + FuncNames["lle_X__IO_putc"] = lle_X__IO_putc; FuncNames["lle_X_exit"] = lle_X_exit; FuncNames["lle_X_abort"] = lle_X_abort; FuncNames["lle_X_malloc"] = lle_X_malloc; |