forked from OSchip/llvm-project
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. llvm-svn: 37254
This commit is contained in:
parent
0306944992
commit
80fcb754d9
|
@ -71,14 +71,14 @@ static ExFunc lookupFunction(const Function *F) {
|
|||
ExtName += "_" + F->getName();
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue