blob: aa900ea3b434b9413ca2cad280665d050f468163 [file] [log] [blame]
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001//===-- ExternalFunctions.cpp - Implement External Functions --------------===//
Chris Lattner7720c8e2001-09-10 04:50:17 +00002//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00003// This file contains both code to deal with invoking "external" functions, but
4// also contains code that implements "exported" external functions.
Chris Lattner7720c8e2001-09-10 04:50:17 +00005//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00006// External functions in LLI are implemented by dlopen'ing the lli executable
7// and using dlsym to look op the functions that we want to invoke. If a
8// function is found, then the arguments are mangled and passed in to the
9// function call.
Chris Lattner7720c8e2001-09-10 04:50:17 +000010//
11//===----------------------------------------------------------------------===//
12
13#include "Interpreter.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000014#include "ExecutionAnnotations.h"
Chris Lattnerfe11a972002-12-23 23:59:41 +000015#include "llvm/Module.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000016#include "llvm/DerivedTypes.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000017#include "llvm/SymbolTable.h"
18#include "llvm/Target/TargetData.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000019#include <map>
20#include <dlfcn.h>
21#include <link.h>
Chris Lattnerc2593162001-10-27 08:28:11 +000022#include <math.h>
Chris Lattnerc063d382001-11-06 21:52:18 +000023#include <stdio.h>
Chris Lattner697954c2002-01-20 22:54:45 +000024using std::vector;
25using std::cout;
Chris Lattner7720c8e2001-09-10 04:50:17 +000026
Chris Lattnerb408b122002-03-29 03:57:15 +000027typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
28static std::map<const Function *, ExFunc> Functions;
Chris Lattner697954c2002-01-20 22:54:45 +000029static std::map<std::string, ExFunc> FuncNames;
Chris Lattner7720c8e2001-09-10 04:50:17 +000030
Chris Lattnere43db882001-10-27 04:15:57 +000031static Interpreter *TheInterpreter;
32
33// getCurrentExecutablePath() - Return the directory that the lli executable
34// lives in.
35//
Chris Lattner697954c2002-01-20 22:54:45 +000036std::string Interpreter::getCurrentExecutablePath() const {
Chris Lattnere43db882001-10-27 04:15:57 +000037 Dl_info Info;
38 if (dladdr(&TheInterpreter, &Info) == 0) return "";
39
Chris Lattner697954c2002-01-20 22:54:45 +000040 std::string LinkAddr(Info.dli_fname);
Chris Lattnere43db882001-10-27 04:15:57 +000041 unsigned SlashPos = LinkAddr.rfind('/');
Chris Lattner697954c2002-01-20 22:54:45 +000042 if (SlashPos != std::string::npos)
Chris Lattnere43db882001-10-27 04:15:57 +000043 LinkAddr.resize(SlashPos); // Trim the executable name off...
44
45 return LinkAddr;
46}
47
48
Chris Lattner7720c8e2001-09-10 04:50:17 +000049static char getTypeID(const Type *Ty) {
50 switch (Ty->getPrimitiveID()) {
51 case Type::VoidTyID: return 'V';
52 case Type::BoolTyID: return 'o';
53 case Type::UByteTyID: return 'B';
54 case Type::SByteTyID: return 'b';
55 case Type::UShortTyID: return 'S';
56 case Type::ShortTyID: return 's';
57 case Type::UIntTyID: return 'I';
58 case Type::IntTyID: return 'i';
59 case Type::ULongTyID: return 'L';
60 case Type::LongTyID: return 'l';
61 case Type::FloatTyID: return 'F';
62 case Type::DoubleTyID: return 'D';
63 case Type::PointerTyID: return 'P';
Chris Lattnerb408b122002-03-29 03:57:15 +000064 case Type::FunctionTyID: return 'M';
Chris Lattner7720c8e2001-09-10 04:50:17 +000065 case Type::StructTyID: return 'T';
66 case Type::ArrayTyID: return 'A';
67 case Type::OpaqueTyID: return 'O';
68 default: return 'U';
69 }
70}
71
Chris Lattnerb408b122002-03-29 03:57:15 +000072static ExFunc lookupFunction(const Function *M) {
Chris Lattner7720c8e2001-09-10 04:50:17 +000073 // Function not found, look it up... start by figuring out what the
74 // composite function name should be.
Chris Lattner697954c2002-01-20 22:54:45 +000075 std::string ExtName = "lle_";
Chris Lattnerb408b122002-03-29 03:57:15 +000076 const FunctionType *MT = M->getFunctionType();
Chris Lattner7720c8e2001-09-10 04:50:17 +000077 for (unsigned i = 0; const Type *Ty = MT->getContainedType(i); ++i)
78 ExtName += getTypeID(Ty);
79 ExtName += "_" + M->getName();
80
81 //cout << "Tried: '" << ExtName << "'\n";
Chris Lattner4721f132001-10-30 20:28:00 +000082 ExFunc FnPtr = FuncNames[ExtName];
83 if (FnPtr == 0)
84 FnPtr = (ExFunc)dlsym(RTLD_DEFAULT, ExtName.c_str());
85 if (FnPtr == 0)
86 FnPtr = FuncNames["lle_X_"+M->getName()];
Chris Lattner7720c8e2001-09-10 04:50:17 +000087 if (FnPtr == 0) // Try calling a generic function... if it exists...
88 FnPtr = (ExFunc)dlsym(RTLD_DEFAULT, ("lle_X_"+M->getName()).c_str());
89 if (FnPtr != 0)
Chris Lattner697954c2002-01-20 22:54:45 +000090 Functions.insert(std::make_pair(M, FnPtr)); // Cache for later
Chris Lattner7720c8e2001-09-10 04:50:17 +000091 return FnPtr;
92}
93
Chris Lattnerb408b122002-03-29 03:57:15 +000094GenericValue Interpreter::callExternalMethod(Function *M,
Chris Lattner4721f132001-10-30 20:28:00 +000095 const vector<GenericValue> &ArgVals) {
Chris Lattnere43db882001-10-27 04:15:57 +000096 TheInterpreter = this;
97
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000098 // Do a lookup to see if the function is in our cache... this should just be a
Chris Lattner7720c8e2001-09-10 04:50:17 +000099 // defered annotation!
Chris Lattnerb408b122002-03-29 03:57:15 +0000100 std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
101 ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000102 if (Fn == 0) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000103 cout << "Tried to execute an unknown external function: "
Chris Lattner697954c2002-01-20 22:54:45 +0000104 << M->getType()->getDescription() << " " << M->getName() << "\n";
Chris Lattner4721f132001-10-30 20:28:00 +0000105 return GenericValue();
Chris Lattner7720c8e2001-09-10 04:50:17 +0000106 }
107
108 // TODO: FIXME when types are not const!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000109 GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
110 ArgVals);
Chris Lattner4721f132001-10-30 20:28:00 +0000111 return Result;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000112}
113
114
115//===----------------------------------------------------------------------===//
Chris Lattnerb408b122002-03-29 03:57:15 +0000116// Functions "exported" to the running application...
Chris Lattner7720c8e2001-09-10 04:50:17 +0000117//
118extern "C" { // Don't add C++ manglings to llvm mangling :)
119
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000120// Implement void printstr([ubyte {x N}] *)
Chris Lattnerb1118742003-01-13 00:59:47 +0000121GenericValue lle_VP_printstr(FunctionType *M,
122 const vector<GenericValue> &ArgVal){
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000123 assert(ArgVal.size() == 1 && "printstr only takes one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000124 cout << (char*)GVTOP(ArgVal[0]);
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000125 return GenericValue();
126}
127
Chris Lattner7720c8e2001-09-10 04:50:17 +0000128// Implement 'void print(X)' for every type...
Chris Lattnerb408b122002-03-29 03:57:15 +0000129GenericValue lle_X_print(FunctionType *M, const vector<GenericValue> &ArgVals) {
Chris Lattner7720c8e2001-09-10 04:50:17 +0000130 assert(ArgVals.size() == 1 && "generic print only takes one argument!");
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000131
132 Interpreter::print(M->getParamTypes()[0], ArgVals[0]);
133 return GenericValue();
134}
135
136// Implement 'void printVal(X)' for every type...
Chris Lattnerb1118742003-01-13 00:59:47 +0000137GenericValue lle_X_printVal(FunctionType *M,
138 const vector<GenericValue> &ArgVal) {
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000139 assert(ArgVal.size() == 1 && "generic print only takes one argument!");
140
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000141 // Specialize print([ubyte {x N} ] *) and print(sbyte *)
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000142 if (const PointerType *PTy =
143 dyn_cast<PointerType>(M->getParamTypes()[0].get()))
Chris Lattner7a176752001-12-04 00:03:30 +0000144 if (PTy->getElementType() == Type::SByteTy ||
145 isa<ArrayType>(PTy->getElementType())) {
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000146 return lle_VP_printstr(M, ArgVal);
147 }
148
149 Interpreter::printValue(M->getParamTypes()[0], ArgVal[0]);
Chris Lattner7720c8e2001-09-10 04:50:17 +0000150 return GenericValue();
151}
152
Vikram S. Adve3eb60f82001-10-28 20:52:27 +0000153// Implement 'void printString(X)'
154// Argument must be [ubyte {x N} ] * or sbyte *
Chris Lattnerb1118742003-01-13 00:59:47 +0000155GenericValue lle_X_printString(FunctionType *M,
156 const vector<GenericValue> &ArgVal) {
Vikram S. Adve3eb60f82001-10-28 20:52:27 +0000157 assert(ArgVal.size() == 1 && "generic print only takes one argument!");
158 return lle_VP_printstr(M, ArgVal);
159}
160
161// Implement 'void print<TYPE>(X)' for each primitive type or pointer type
162#define PRINT_TYPE_FUNC(TYPENAME,TYPEID) \
Chris Lattnerb408b122002-03-29 03:57:15 +0000163 GenericValue lle_X_print##TYPENAME(FunctionType *M,\
Chris Lattner316a65b2001-10-28 22:38:22 +0000164 const vector<GenericValue> &ArgVal) {\
Vikram S. Adve3eb60f82001-10-28 20:52:27 +0000165 assert(ArgVal.size() == 1 && "generic print only takes one argument!");\
Chris Lattner69b5ce92001-11-26 19:19:27 +0000166 assert(M->getParamTypes()[0].get()->getPrimitiveID() == Type::TYPEID);\
Vikram S. Adve3eb60f82001-10-28 20:52:27 +0000167 Interpreter::printValue(M->getParamTypes()[0], ArgVal[0]);\
168 return GenericValue();\
169 }
170
Chris Lattner4721f132001-10-30 20:28:00 +0000171PRINT_TYPE_FUNC(SByte, SByteTyID)
Vikram S. Adve3eb60f82001-10-28 20:52:27 +0000172PRINT_TYPE_FUNC(UByte, UByteTyID)
173PRINT_TYPE_FUNC(Short, ShortTyID)
174PRINT_TYPE_FUNC(UShort, UShortTyID)
175PRINT_TYPE_FUNC(Int, IntTyID)
176PRINT_TYPE_FUNC(UInt, UIntTyID)
177PRINT_TYPE_FUNC(Long, LongTyID)
178PRINT_TYPE_FUNC(ULong, ULongTyID)
179PRINT_TYPE_FUNC(Float, FloatTyID)
180PRINT_TYPE_FUNC(Double, DoubleTyID)
181PRINT_TYPE_FUNC(Pointer, PointerTyID)
182
183
Chris Lattner005cbce2002-10-02 21:12:13 +0000184// void putchar(sbyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000185GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner7720c8e2001-09-10 04:50:17 +0000186 cout << Args[0].SByteVal;
187 return GenericValue();
188}
189
Chris Lattner005cbce2002-10-02 21:12:13 +0000190// int putchar(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000191GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner697954c2002-01-20 22:54:45 +0000192 cout << ((char)Args[0].IntVal) << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000193 return Args[0];
194}
195
Chris Lattner005cbce2002-10-02 21:12:13 +0000196// void putchar(ubyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000197GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner697954c2002-01-20 22:54:45 +0000198 cout << Args[0].SByteVal << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000199 return Args[0];
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000200}
201
Chris Lattner005cbce2002-10-02 21:12:13 +0000202// void __main()
Chris Lattnerb408b122002-03-29 03:57:15 +0000203GenericValue lle_V___main(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000204 return GenericValue();
205}
206
Chris Lattner005cbce2002-10-02 21:12:13 +0000207// void exit(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000208GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere43db882001-10-27 04:15:57 +0000209 TheInterpreter->exitCalled(Args[0]);
210 return GenericValue();
211}
212
Chris Lattner005cbce2002-10-02 21:12:13 +0000213// void abort(void)
Chris Lattner1ee34a52002-05-20 21:17:16 +0000214GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
215 std::cerr << "***PROGRAM ABORTED***!\n";
216 GenericValue GV;
217 GV.IntVal = 1;
218 TheInterpreter->exitCalled(GV);
219 return GenericValue();
220}
221
Chris Lattnerc2593162001-10-27 08:28:11 +0000222// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000223GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000224 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000225 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000226}
227
Chris Lattner957d62a2003-04-23 19:55:24 +0000228// void *calloc(uint, uint)
229GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
230 assert(Args.size() == 2 && "calloc expects two arguments!");
231 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
232}
233
Chris Lattnerc2593162001-10-27 08:28:11 +0000234// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000235GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000236 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000237 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000238 return GenericValue();
239}
240
Chris Lattner782b9392001-11-26 18:18:18 +0000241// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000242GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000243 assert(Args.size() == 1);
244 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000245 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000246 return GV;
247}
248
Chris Lattnerc2593162001-10-27 08:28:11 +0000249// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000250GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000251 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000252 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000253 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000254 return GV;
255}
256
Chris Lattner34dd24b2002-02-18 19:06:25 +0000257// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000258GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000259 assert(Args.size() == 1);
260 GenericValue GV;
261 GV.DoubleVal = exp(Args[0].DoubleVal);
262 return GV;
263}
264
Chris Lattnerc063d382001-11-06 21:52:18 +0000265// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000266GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000267 assert(Args.size() == 1);
268 GenericValue GV;
269 GV.DoubleVal = sqrt(Args[0].DoubleVal);
270 return GV;
271}
Chris Lattnerc2593162001-10-27 08:28:11 +0000272
Chris Lattner86790052001-11-06 22:53:25 +0000273// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000274GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000275 assert(Args.size() == 1);
276 GenericValue GV;
277 GV.DoubleVal = log(Args[0].DoubleVal);
278 return GV;
279}
280
Chris Lattnerdbcda222002-12-20 04:18:13 +0000281// int isnan(double value);
282GenericValue lle_X_isnan(FunctionType *F, const vector<GenericValue> &Args) {
283 assert(Args.size() == 1);
284 GenericValue GV;
285 GV.IntVal = isnan(Args[0].DoubleVal);
286 return GV;
287}
288
Chris Lattner782b9392001-11-26 18:18:18 +0000289// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000290GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000291 assert(Args.size() == 1);
292 GenericValue GV;
293 GV.DoubleVal = floor(Args[0].DoubleVal);
294 return GV;
295}
296
Chris Lattner86790052001-11-06 22:53:25 +0000297// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000298GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000299 assert(Args.size() == 0);
300 GenericValue GV;
301 GV.DoubleVal = drand48();
302 return GV;
303}
304
Chris Lattner1b600142001-11-13 05:46:08 +0000305// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000306GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000307 assert(Args.size() == 0);
308 GenericValue GV;
309 GV.IntVal = lrand48();
310 return GV;
311}
312
313// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000314GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000315 assert(Args.size() == 1);
316 srand48(Args[0].IntVal);
317 return GenericValue();
318}
319
Chris Lattner782b9392001-11-26 18:18:18 +0000320// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000321GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000322 assert(Args.size() == 1);
323 srand(Args[0].UIntVal);
324 return GenericValue();
325}
Chris Lattner86790052001-11-06 22:53:25 +0000326
Chris Lattnerb1118742003-01-13 00:59:47 +0000327// int puts(const char*)
328GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
329 assert(Args.size() == 1);
330 GenericValue GV;
331 GV.IntVal = puts((char*)GVTOP(Args[0]));
332 return GV;
333}
334
Chris Lattnere7c6f722001-12-13 00:43:47 +0000335// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
336// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000337GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000338 char *OutputBuffer = (char *)GVTOP(Args[0]);
339 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000340 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000341
342 // printf should return # chars printed. This is completely incorrect, but
343 // close enough for now.
344 GenericValue GV; GV.IntVal = strlen(FmtStr);
345 while (1) {
346 switch (*FmtStr) {
347 case 0: return GV; // Null terminator...
348 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000349 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000350 break;
351 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000352 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
353 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000354 break;
355 }
356 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000357 char FmtBuf[100] = "", Buffer[1000] = "";
358 char *FB = FmtBuf;
359 *FB++ = *FmtStr++;
360 char Last = *FB++ = *FmtStr++;
361 unsigned HowLong = 0;
362 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
363 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
364 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
365 Last != 'p' && Last != 's' && Last != '%') {
366 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
367 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000368 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000369 *FB = 0;
370
371 switch (Last) {
372 case '%':
373 sprintf(Buffer, FmtBuf); break;
374 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000375 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000376 case 'd': case 'i':
377 case 'u': case 'o':
378 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000379 if (HowLong >= 1) {
Chris Lattner7471c482003-04-25 18:28:44 +0000380 if (HowLong == 1 && TheInterpreter->getModule().has64BitPointers() &&
381 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000382 // Make sure we use %lld with a 64 bit argument because we might be
383 // compiling LLI on a 32 bit compiler.
384 unsigned Size = strlen(FmtBuf);
385 FmtBuf[Size] = FmtBuf[Size-1];
386 FmtBuf[Size+1] = 0;
387 FmtBuf[Size-1] = 'l';
388 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000389 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000390 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000391 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
392 case 'e': case 'E': case 'g': case 'G': case 'f':
393 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
394 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000395 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000396 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000397 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000398 default: cout << "<unknown printf code '" << *FmtStr << "'!>";
399 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000400 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000401 strcpy(OutputBuffer, Buffer);
402 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000403 }
Chris Lattner08845a22001-10-29 20:27:45 +0000404 break;
405 }
Chris Lattner08845a22001-10-29 20:27:45 +0000406 }
407}
408
Chris Lattnere7c6f722001-12-13 00:43:47 +0000409// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000410GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000411 char Buffer[10000];
412 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000413 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000414 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000415 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000416 cout << Buffer;
417 return GV;
418}
419
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000420static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
421 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
422 void *Arg6, void *Arg7, void *Arg8) {
423 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
424
425 // Loop over the format string, munging read values as appropriate (performs
426 // byteswaps as neccesary).
427 unsigned ArgNo = 0;
428 while (*Fmt) {
429 if (*Fmt++ == '%') {
430 // Read any flag characters that may be present...
431 bool Suppress = false;
432 bool Half = false;
433 bool Long = false;
434 bool LongLong = false; // long long or long double
435
436 while (1) {
437 switch (*Fmt++) {
438 case '*': Suppress = true; break;
439 case 'a': /*Allocate = true;*/ break; // We don't need to track this
440 case 'h': Half = true; break;
441 case 'l': Long = true; break;
442 case 'q':
443 case 'L': LongLong = true; break;
444 default:
445 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
446 goto Out;
447 }
448 }
449 Out:
450
451 // Read the conversion character
452 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
453 unsigned Size = 0;
454 const Type *Ty = 0;
455
456 switch (Fmt[-1]) {
457 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
458 case 'd':
459 if (Long || LongLong) {
460 Size = 8; Ty = Type::ULongTy;
461 } else if (Half) {
462 Size = 4; Ty = Type::UShortTy;
463 } else {
464 Size = 4; Ty = Type::UIntTy;
465 }
466 break;
467
468 case 'e': case 'g': case 'E':
469 case 'f':
470 if (Long || LongLong) {
471 Size = 8; Ty = Type::DoubleTy;
472 } else {
473 Size = 4; Ty = Type::FloatTy;
474 }
475 break;
476
477 case 's': case 'c': case '[': // No byteswap needed
478 Size = 1;
479 Ty = Type::SByteTy;
480 break;
481
482 default: break;
483 }
484
485 if (Size) {
486 GenericValue GV;
487 void *Arg = Args[ArgNo++];
488 memcpy(&GV, Arg, Size);
489 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
490 }
491 }
492 }
493 }
494}
495
Chris Lattner665ee882002-03-08 22:51:07 +0000496// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000497GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000498 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
499
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000500 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000501 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000502 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000503
504 GenericValue GV;
505 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
506 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000507 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
508 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
509 return GV;
510}
511
512// int scanf(const char *format, ...);
513GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
514 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
515
516 char *Args[10];
517 for (unsigned i = 0; i < args.size(); ++i)
518 Args[i] = (char*)GVTOP(args[i]);
519
520 GenericValue GV;
521 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
522 Args[5], Args[6], Args[7], Args[8], Args[9]);
523 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
524 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000525 return GV;
526}
527
528
Chris Lattner295fe672002-01-23 21:38:07 +0000529// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000530GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000531 extern int clock(void);
532 GenericValue GV; GV.IntVal = clock();
533 return GV;
534}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000535
Chris Lattner957d62a2003-04-23 19:55:24 +0000536
537//===----------------------------------------------------------------------===//
538// String Functions...
539//===----------------------------------------------------------------------===//
540
541// int strcmp(const char *S1, const char *S2);
542GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
543 assert(Args.size() == 2);
544 GenericValue Ret;
545 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
546 return Ret;
547}
548
549// char *strcat(char *Dest, const char *src);
550GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
551 assert(Args.size() == 2);
552 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
553}
554
555// char *strcpy(char *Dest, const char *src);
556GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
557 assert(Args.size() == 2);
558 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
559}
560
561// long strlen(const char *src);
562GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
563 assert(Args.size() == 1);
564 GenericValue Ret;
565 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
566 return Ret;
567}
568
Chris Lattnerc8cff9e2003-04-25 18:23:38 +0000569// char *__strdup(const char *src);
570GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
571 assert(Args.size() == 1);
572 return PTOGV(strdup((char*)GVTOP(Args[0])));
573}
574
Chris Lattner957d62a2003-04-23 19:55:24 +0000575// void *memset(void *S, int C, size_t N)
576GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
577 assert(Args.size() == 3);
578 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
579}
580
Chris Lattner5f311a72003-04-23 20:23:16 +0000581// void *memcpy(void *Dest, void *src, size_t Size);
582GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
583 assert(Args.size() == 3);
584 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
585 Args[2].UIntVal));
586}
Chris Lattner957d62a2003-04-23 19:55:24 +0000587
Chris Lattner665ee882002-03-08 22:51:07 +0000588//===----------------------------------------------------------------------===//
589// IO Functions...
590//===----------------------------------------------------------------------===//
591
Chris Lattner005cbce2002-10-02 21:12:13 +0000592// getFILE - Turn a pointer in the host address space into a legit pointer in
593// the interpreter address space. For the most part, this is an identity
594// transformation, but if the program refers to stdio, stderr, stdin then they
595// have pointers that are relative to the __iob array. If this is the case,
596// change the FILE into the REAL stdio stream.
597//
Chris Lattnerb1118742003-01-13 00:59:47 +0000598static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000599 static Module *LastMod = 0;
600 static PointerTy IOBBase = 0;
601 static unsigned FILESize;
602
Chris Lattnerfe11a972002-12-23 23:59:41 +0000603 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
604 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000605
606 // Check to see if the currently loaded module contains an __iob symbol...
607 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000608 SymbolTable &ST = M->getSymbolTable();
609 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
610 SymbolTable::VarMap &M = I->second;
611 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
612 J != E; ++J)
613 if (J->first == "__iob")
614 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
615 break;
616 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000617 }
618
Chris Lattnerfe11a972002-12-23 23:59:41 +0000619#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000620 // If we found an __iob symbol now, find out what the actual address it's
621 // held in is...
622 if (IOB) {
623 // Get the address the array lives in...
624 GlobalAddress *Address =
625 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
626 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
627
628 // Figure out how big each element of the array is...
629 const ArrayType *AT =
630 dyn_cast<ArrayType>(IOB->getType()->getElementType());
631 if (AT)
632 FILESize = TD.getTypeSize(AT->getElementType());
633 else
634 FILESize = 16*8; // Default size
635 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000636#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000637 }
638
639 // Check to see if this is a reference to __iob...
640 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000641 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000642 if (FDNum == 0)
643 return stdin;
644 else if (FDNum == 1)
645 return stdout;
646 else if (FDNum == 2)
647 return stderr;
648 }
649
650 return (FILE*)Ptr;
651}
652
653
Chris Lattner665ee882002-03-08 22:51:07 +0000654// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000655GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000656 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000657 return PTOGV(fopen((const char *)GVTOP(Args[0]),
658 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000659}
660
661// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000662GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000663 assert(Args.size() == 1);
664 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000665 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000666 return GV;
667}
668
Chris Lattner25f6f372002-11-08 19:10:26 +0000669// int feof(FILE *stream);
670GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
671 assert(Args.size() == 1);
672 GenericValue GV;
673
Chris Lattnerb1118742003-01-13 00:59:47 +0000674 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000675 return GV;
676}
677
Chris Lattner665ee882002-03-08 22:51:07 +0000678// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000679GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000680 assert(Args.size() == 4);
681 GenericValue GV;
682
Chris Lattnerb1118742003-01-13 00:59:47 +0000683 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
684 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000685 return GV;
686}
687
688// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000689GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000690 assert(Args.size() == 4);
691 GenericValue GV;
692
Chris Lattnerb1118742003-01-13 00:59:47 +0000693 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
694 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000695 return GV;
696}
697
698// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000699GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000700 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000701 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
702 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000703}
704
Chris Lattnera4479cd2002-11-07 19:33:50 +0000705// FILE *freopen(const char *path, const char *mode, FILE *stream);
706GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
707 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000708 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
709 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000710}
711
Chris Lattner665ee882002-03-08 22:51:07 +0000712// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000713GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000714 assert(Args.size() == 1);
715 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000716 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000717 return GV;
718}
719
720// int getc(FILE *stream);
721GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
722 assert(Args.size() == 1);
723 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000724 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000725 return GV;
726}
727
Chris Lattnerf87a1982003-04-23 19:20:50 +0000728// int _IO_getc(FILE *stream);
729GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
730 return lle_X_getc(F, Args);
731}
732
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000733// int fputc(int C, FILE *stream);
734GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
735 assert(Args.size() == 2);
736 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000737 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000738 return GV;
739}
740
741// int ungetc(int C, FILE *stream);
742GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
743 assert(Args.size() == 2);
744 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000745 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000746 return GV;
747}
748
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000749// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
750// useful.
751GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000752 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000753 char Buffer[10000];
754 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000755 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000756 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000757 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000758
Chris Lattnerb1118742003-01-13 00:59:47 +0000759 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000760 return GV;
761}
762
Chris Lattner7720c8e2001-09-10 04:50:17 +0000763} // End extern "C"
Chris Lattner4721f132001-10-30 20:28:00 +0000764
765
766void Interpreter::initializeExternalMethods() {
767 FuncNames["lle_VP_printstr"] = lle_VP_printstr;
768 FuncNames["lle_X_print"] = lle_X_print;
769 FuncNames["lle_X_printVal"] = lle_X_printVal;
770 FuncNames["lle_X_printString"] = lle_X_printString;
771 FuncNames["lle_X_printUByte"] = lle_X_printUByte;
772 FuncNames["lle_X_printSByte"] = lle_X_printSByte;
773 FuncNames["lle_X_printUShort"] = lle_X_printUShort;
774 FuncNames["lle_X_printShort"] = lle_X_printShort;
775 FuncNames["lle_X_printInt"] = lle_X_printInt;
776 FuncNames["lle_X_printUInt"] = lle_X_printUInt;
777 FuncNames["lle_X_printLong"] = lle_X_printLong;
778 FuncNames["lle_X_printULong"] = lle_X_printULong;
779 FuncNames["lle_X_printFloat"] = lle_X_printFloat;
780 FuncNames["lle_X_printDouble"] = lle_X_printDouble;
781 FuncNames["lle_X_printPointer"] = lle_X_printPointer;
Chris Lattner0f279b22001-11-03 10:15:32 +0000782 FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
783 FuncNames["lle_ii_putchar"] = lle_ii_putchar;
784 FuncNames["lle_VB_putchar"] = lle_VB_putchar;
785 FuncNames["lle_V___main"] = lle_V___main;
786 FuncNames["lle_X_exit"] = lle_X_exit;
Chris Lattner1ee34a52002-05-20 21:17:16 +0000787 FuncNames["lle_X_abort"] = lle_X_abort;
Chris Lattner0f279b22001-11-03 10:15:32 +0000788 FuncNames["lle_X_malloc"] = lle_X_malloc;
Chris Lattner957d62a2003-04-23 19:55:24 +0000789 FuncNames["lle_X_calloc"] = lle_X_calloc;
Chris Lattner0f279b22001-11-03 10:15:32 +0000790 FuncNames["lle_X_free"] = lle_X_free;
Chris Lattner782b9392001-11-26 18:18:18 +0000791 FuncNames["lle_X_atoi"] = lle_X_atoi;
Chris Lattner0f279b22001-11-03 10:15:32 +0000792 FuncNames["lle_X_pow"] = lle_X_pow;
Chris Lattner34dd24b2002-02-18 19:06:25 +0000793 FuncNames["lle_X_exp"] = lle_X_exp;
Chris Lattner1b600142001-11-13 05:46:08 +0000794 FuncNames["lle_X_log"] = lle_X_log;
Chris Lattnerdbcda222002-12-20 04:18:13 +0000795 FuncNames["lle_X_isnan"] = lle_X_isnan;
Chris Lattner782b9392001-11-26 18:18:18 +0000796 FuncNames["lle_X_floor"] = lle_X_floor;
797 FuncNames["lle_X_srand"] = lle_X_srand;
Chris Lattner1b600142001-11-13 05:46:08 +0000798 FuncNames["lle_X_drand48"] = lle_X_drand48;
799 FuncNames["lle_X_srand48"] = lle_X_srand48;
800 FuncNames["lle_X_lrand48"] = lle_X_lrand48;
Chris Lattnerc063d382001-11-06 21:52:18 +0000801 FuncNames["lle_X_sqrt"] = lle_X_sqrt;
Chris Lattnerb1118742003-01-13 00:59:47 +0000802 FuncNames["lle_X_puts"] = lle_X_puts;
Chris Lattner0f279b22001-11-03 10:15:32 +0000803 FuncNames["lle_X_printf"] = lle_X_printf;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000804 FuncNames["lle_X_sprintf"] = lle_X_sprintf;
Chris Lattner665ee882002-03-08 22:51:07 +0000805 FuncNames["lle_X_sscanf"] = lle_X_sscanf;
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000806 FuncNames["lle_X_scanf"] = lle_X_scanf;
Chris Lattner295fe672002-01-23 21:38:07 +0000807 FuncNames["lle_i_clock"] = lle_i_clock;
Chris Lattner957d62a2003-04-23 19:55:24 +0000808
809 FuncNames["lle_X_strcmp"] = lle_X_strcmp;
810 FuncNames["lle_X_strcat"] = lle_X_strcat;
811 FuncNames["lle_X_strcpy"] = lle_X_strcpy;
812 FuncNames["lle_X_strlen"] = lle_X_strlen;
Chris Lattnerc8cff9e2003-04-25 18:23:38 +0000813 FuncNames["lle_X___strdup"] = lle_X___strdup;
Chris Lattner957d62a2003-04-23 19:55:24 +0000814 FuncNames["lle_X_memset"] = lle_X_memset;
Chris Lattner5f311a72003-04-23 20:23:16 +0000815 FuncNames["lle_X_memcpy"] = lle_X_memcpy;
Chris Lattner957d62a2003-04-23 19:55:24 +0000816
Chris Lattner665ee882002-03-08 22:51:07 +0000817 FuncNames["lle_X_fopen"] = lle_X_fopen;
818 FuncNames["lle_X_fclose"] = lle_X_fclose;
Chris Lattner25f6f372002-11-08 19:10:26 +0000819 FuncNames["lle_X_feof"] = lle_X_feof;
Chris Lattner665ee882002-03-08 22:51:07 +0000820 FuncNames["lle_X_fread"] = lle_X_fread;
821 FuncNames["lle_X_fwrite"] = lle_X_fwrite;
822 FuncNames["lle_X_fgets"] = lle_X_fgets;
823 FuncNames["lle_X_fflush"] = lle_X_fflush;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000824 FuncNames["lle_X_fgetc"] = lle_X_getc;
Chris Lattner005cbce2002-10-02 21:12:13 +0000825 FuncNames["lle_X_getc"] = lle_X_getc;
Chris Lattnerf87a1982003-04-23 19:20:50 +0000826 FuncNames["lle_X__IO_getc"] = lle_X__IO_getc;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000827 FuncNames["lle_X_fputc"] = lle_X_fputc;
828 FuncNames["lle_X_ungetc"] = lle_X_ungetc;
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000829 FuncNames["lle_X_fprintf"] = lle_X_fprintf;
Chris Lattnera4479cd2002-11-07 19:33:50 +0000830 FuncNames["lle_X_freopen"] = lle_X_freopen;
Chris Lattner4721f132001-10-30 20:28:00 +0000831}