blob: 44ba87f3b31e7e6e7bb87cf53d777eb807d1a882 [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//
Brian Gaeke58a6faa2003-10-10 17:03:10 +00006// External functions in the interpreter are implemented by
7// using the system's dynamic loader to look up the address of the function
8// we want to invoke. If a function is found, then one of the
9// many lle_* wrapper functions in this file will translate its arguments from
10// GenericValues to the types the function is actually expecting, before the
11// function is called.
Chris Lattner7720c8e2001-09-10 04:50:17 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "Interpreter.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000016#include "ExecutionAnnotations.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000017#include "llvm/DerivedTypes.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000018#include "llvm/Module.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000019#include "llvm/SymbolTable.h"
20#include "llvm/Target/TargetData.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000021#include "Support/DynamicLinker.h"
John Criswell7a73b802003-06-30 21:59:07 +000022#include "Config/dlfcn.h"
23#include "Config/link.h"
Brian Gaeke70337982003-06-23 19:41:55 +000024#include <cmath>
Misha Brukmanb8d15b22003-10-14 21:42:11 +000025#include <map>
Chris Lattner697954c2002-01-20 22:54:45 +000026using std::vector;
Chris Lattner7720c8e2001-09-10 04:50:17 +000027
Chris Lattnerb408b122002-03-29 03:57:15 +000028typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
29static std::map<const Function *, ExFunc> Functions;
Chris Lattner697954c2002-01-20 22:54:45 +000030static std::map<std::string, ExFunc> FuncNames;
Chris Lattner7720c8e2001-09-10 04:50:17 +000031
Chris Lattnere43db882001-10-27 04:15:57 +000032static Interpreter *TheInterpreter;
33
Chris Lattner7720c8e2001-09-10 04:50:17 +000034static char getTypeID(const Type *Ty) {
35 switch (Ty->getPrimitiveID()) {
36 case Type::VoidTyID: return 'V';
37 case Type::BoolTyID: return 'o';
38 case Type::UByteTyID: return 'B';
39 case Type::SByteTyID: return 'b';
40 case Type::UShortTyID: return 'S';
41 case Type::ShortTyID: return 's';
42 case Type::UIntTyID: return 'I';
43 case Type::IntTyID: return 'i';
44 case Type::ULongTyID: return 'L';
45 case Type::LongTyID: return 'l';
46 case Type::FloatTyID: return 'F';
47 case Type::DoubleTyID: return 'D';
48 case Type::PointerTyID: return 'P';
Chris Lattnerb408b122002-03-29 03:57:15 +000049 case Type::FunctionTyID: return 'M';
Chris Lattner7720c8e2001-09-10 04:50:17 +000050 case Type::StructTyID: return 'T';
51 case Type::ArrayTyID: return 'A';
52 case Type::OpaqueTyID: return 'O';
53 default: return 'U';
54 }
55}
56
Brian Gaeke58a6faa2003-10-10 17:03:10 +000057static ExFunc lookupFunction(const Function *F) {
Chris Lattner7720c8e2001-09-10 04:50:17 +000058 // Function not found, look it up... start by figuring out what the
59 // composite function name should be.
Chris Lattner697954c2002-01-20 22:54:45 +000060 std::string ExtName = "lle_";
Brian Gaeke58a6faa2003-10-10 17:03:10 +000061 const FunctionType *FT = F->getFunctionType();
62 for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
63 ExtName += getTypeID(FT->getContainedType(i));
64 ExtName += "_" + F->getName();
Chris Lattner7720c8e2001-09-10 04:50:17 +000065
Chris Lattner4721f132001-10-30 20:28:00 +000066 ExFunc FnPtr = FuncNames[ExtName];
67 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000068 FnPtr = (ExFunc)GetAddressOfSymbol(ExtName);
Chris Lattner4721f132001-10-30 20:28:00 +000069 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000070 FnPtr = FuncNames["lle_X_"+F->getName()];
Chris Lattner7720c8e2001-09-10 04:50:17 +000071 if (FnPtr == 0) // Try calling a generic function... if it exists...
Brian Gaeke58a6faa2003-10-10 17:03:10 +000072 FnPtr = (ExFunc)GetAddressOfSymbol(("lle_X_"+F->getName()).c_str());
Chris Lattner7720c8e2001-09-10 04:50:17 +000073 if (FnPtr != 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000074 Functions.insert(std::make_pair(F, FnPtr)); // Cache for later
Chris Lattner7720c8e2001-09-10 04:50:17 +000075 return FnPtr;
76}
77
Chris Lattnerda82ed52003-05-08 16:18:31 +000078GenericValue Interpreter::callExternalFunction(Function *M,
Chris Lattner44edb6b2003-05-14 14:21:30 +000079 const std::vector<GenericValue> &ArgVals) {
Chris Lattnere43db882001-10-27 04:15:57 +000080 TheInterpreter = this;
81
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000082 // Do a lookup to see if the function is in our cache... this should just be a
Misha Brukmand5d96b92003-10-10 17:42:19 +000083 // deferred annotation!
Chris Lattnerb408b122002-03-29 03:57:15 +000084 std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
85 ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
Chris Lattner7720c8e2001-09-10 04:50:17 +000086 if (Fn == 0) {
Chris Lattnerda82ed52003-05-08 16:18:31 +000087 std::cout << "Tried to execute an unknown external function: "
88 << M->getType()->getDescription() << " " << M->getName() << "\n";
Chris Lattner4721f132001-10-30 20:28:00 +000089 return GenericValue();
Chris Lattner7720c8e2001-09-10 04:50:17 +000090 }
91
92 // TODO: FIXME when types are not const!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000093 GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
94 ArgVals);
Chris Lattner4721f132001-10-30 20:28:00 +000095 return Result;
Chris Lattner7720c8e2001-09-10 04:50:17 +000096}
97
98
99//===----------------------------------------------------------------------===//
Chris Lattnerb408b122002-03-29 03:57:15 +0000100// Functions "exported" to the running application...
Chris Lattner7720c8e2001-09-10 04:50:17 +0000101//
102extern "C" { // Don't add C++ manglings to llvm mangling :)
103
Chris Lattner005cbce2002-10-02 21:12:13 +0000104// void putchar(sbyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000105GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000106 std::cout << Args[0].SByteVal;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000107 return GenericValue();
108}
109
Chris Lattner005cbce2002-10-02 21:12:13 +0000110// int putchar(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000111GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000112 std::cout << ((char)Args[0].IntVal) << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000113 return Args[0];
114}
115
Chris Lattner005cbce2002-10-02 21:12:13 +0000116// void putchar(ubyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000117GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000118 std::cout << Args[0].SByteVal << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000119 return Args[0];
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000120}
121
Chris Lattner44edb6b2003-05-14 14:21:30 +0000122// void atexit(Function*)
123GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
124 assert(Args.size() == 1);
125 TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
126 GenericValue GV;
127 GV.IntVal = 0;
128 return GV;
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000129}
130
Chris Lattner005cbce2002-10-02 21:12:13 +0000131// void exit(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000132GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere43db882001-10-27 04:15:57 +0000133 TheInterpreter->exitCalled(Args[0]);
134 return GenericValue();
135}
136
Chris Lattner005cbce2002-10-02 21:12:13 +0000137// void abort(void)
Chris Lattner1ee34a52002-05-20 21:17:16 +0000138GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
139 std::cerr << "***PROGRAM ABORTED***!\n";
140 GenericValue GV;
141 GV.IntVal = 1;
142 TheInterpreter->exitCalled(GV);
143 return GenericValue();
144}
145
Chris Lattnerc2593162001-10-27 08:28:11 +0000146// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000147GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000148 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000149 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000150}
151
Chris Lattner957d62a2003-04-23 19:55:24 +0000152// void *calloc(uint, uint)
153GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
154 assert(Args.size() == 2 && "calloc expects two arguments!");
155 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
156}
157
Chris Lattnerc2593162001-10-27 08:28:11 +0000158// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000159GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000160 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000161 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000162 return GenericValue();
163}
164
Chris Lattner782b9392001-11-26 18:18:18 +0000165// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000166GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000167 assert(Args.size() == 1);
168 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000169 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000170 return GV;
171}
172
Chris Lattnerc2593162001-10-27 08:28:11 +0000173// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000174GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000175 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000176 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000177 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000178 return GV;
179}
180
Chris Lattner34dd24b2002-02-18 19:06:25 +0000181// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000182GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000183 assert(Args.size() == 1);
184 GenericValue GV;
185 GV.DoubleVal = exp(Args[0].DoubleVal);
186 return GV;
187}
188
Chris Lattnerc063d382001-11-06 21:52:18 +0000189// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000190GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000191 assert(Args.size() == 1);
192 GenericValue GV;
193 GV.DoubleVal = sqrt(Args[0].DoubleVal);
194 return GV;
195}
Chris Lattnerc2593162001-10-27 08:28:11 +0000196
Chris Lattner86790052001-11-06 22:53:25 +0000197// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000198GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000199 assert(Args.size() == 1);
200 GenericValue GV;
201 GV.DoubleVal = log(Args[0].DoubleVal);
202 return GV;
203}
204
Chris Lattner782b9392001-11-26 18:18:18 +0000205// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000206GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000207 assert(Args.size() == 1);
208 GenericValue GV;
209 GV.DoubleVal = floor(Args[0].DoubleVal);
210 return GV;
211}
212
Chris Lattner86790052001-11-06 22:53:25 +0000213// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000214GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000215 assert(Args.size() == 0);
216 GenericValue GV;
217 GV.DoubleVal = drand48();
218 return GV;
219}
220
Chris Lattner1b600142001-11-13 05:46:08 +0000221// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000222GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000223 assert(Args.size() == 0);
224 GenericValue GV;
225 GV.IntVal = lrand48();
226 return GV;
227}
228
229// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000230GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000231 assert(Args.size() == 1);
232 srand48(Args[0].IntVal);
233 return GenericValue();
234}
235
Chris Lattner782b9392001-11-26 18:18:18 +0000236// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000237GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000238 assert(Args.size() == 1);
239 srand(Args[0].UIntVal);
240 return GenericValue();
241}
Chris Lattner86790052001-11-06 22:53:25 +0000242
Chris Lattnerb1118742003-01-13 00:59:47 +0000243// int puts(const char*)
244GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
245 assert(Args.size() == 1);
246 GenericValue GV;
247 GV.IntVal = puts((char*)GVTOP(Args[0]));
248 return GV;
249}
250
Chris Lattnere7c6f722001-12-13 00:43:47 +0000251// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
252// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000253GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000254 char *OutputBuffer = (char *)GVTOP(Args[0]);
255 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000256 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000257
258 // printf should return # chars printed. This is completely incorrect, but
259 // close enough for now.
260 GenericValue GV; GV.IntVal = strlen(FmtStr);
261 while (1) {
262 switch (*FmtStr) {
263 case 0: return GV; // Null terminator...
264 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000265 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000266 break;
267 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000268 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
269 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000270 break;
271 }
272 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000273 char FmtBuf[100] = "", Buffer[1000] = "";
274 char *FB = FmtBuf;
275 *FB++ = *FmtStr++;
276 char Last = *FB++ = *FmtStr++;
277 unsigned HowLong = 0;
278 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
279 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
280 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
281 Last != 'p' && Last != 's' && Last != '%') {
282 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
283 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000284 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000285 *FB = 0;
286
287 switch (Last) {
288 case '%':
289 sprintf(Buffer, FmtBuf); break;
290 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000291 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000292 case 'd': case 'i':
293 case 'u': case 'o':
294 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000295 if (HowLong >= 1) {
Chris Lattner1543e402003-08-24 14:02:47 +0000296 if (HowLong == 1 &&
297 TheInterpreter->getModule().getPointerSize()==Module::Pointer64 &&
Chris Lattner7471c482003-04-25 18:28:44 +0000298 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000299 // Make sure we use %lld with a 64 bit argument because we might be
300 // compiling LLI on a 32 bit compiler.
301 unsigned Size = strlen(FmtBuf);
302 FmtBuf[Size] = FmtBuf[Size-1];
303 FmtBuf[Size+1] = 0;
304 FmtBuf[Size-1] = 'l';
305 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000306 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000307 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000308 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
309 case 'e': case 'E': case 'g': case 'G': case 'f':
310 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
311 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000312 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000313 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000314 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000315 default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000316 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000317 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000318 strcpy(OutputBuffer, Buffer);
319 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000320 }
Chris Lattner08845a22001-10-29 20:27:45 +0000321 break;
322 }
Chris Lattner08845a22001-10-29 20:27:45 +0000323 }
324}
325
Chris Lattnere7c6f722001-12-13 00:43:47 +0000326// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000327GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000328 char Buffer[10000];
329 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000330 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000331 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000332 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnerda82ed52003-05-08 16:18:31 +0000333 std::cout << Buffer;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000334 return GV;
335}
336
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000337static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
338 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
339 void *Arg6, void *Arg7, void *Arg8) {
340 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
341
342 // Loop over the format string, munging read values as appropriate (performs
Misha Brukman5560c9d2003-08-18 14:43:39 +0000343 // byteswaps as necessary).
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000344 unsigned ArgNo = 0;
345 while (*Fmt) {
346 if (*Fmt++ == '%') {
347 // Read any flag characters that may be present...
348 bool Suppress = false;
349 bool Half = false;
350 bool Long = false;
351 bool LongLong = false; // long long or long double
352
353 while (1) {
354 switch (*Fmt++) {
355 case '*': Suppress = true; break;
356 case 'a': /*Allocate = true;*/ break; // We don't need to track this
357 case 'h': Half = true; break;
358 case 'l': Long = true; break;
359 case 'q':
360 case 'L': LongLong = true; break;
361 default:
362 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
363 goto Out;
364 }
365 }
366 Out:
367
368 // Read the conversion character
369 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
370 unsigned Size = 0;
371 const Type *Ty = 0;
372
373 switch (Fmt[-1]) {
374 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
375 case 'd':
376 if (Long || LongLong) {
377 Size = 8; Ty = Type::ULongTy;
378 } else if (Half) {
379 Size = 4; Ty = Type::UShortTy;
380 } else {
381 Size = 4; Ty = Type::UIntTy;
382 }
383 break;
384
385 case 'e': case 'g': case 'E':
386 case 'f':
387 if (Long || LongLong) {
388 Size = 8; Ty = Type::DoubleTy;
389 } else {
390 Size = 4; Ty = Type::FloatTy;
391 }
392 break;
393
394 case 's': case 'c': case '[': // No byteswap needed
395 Size = 1;
396 Ty = Type::SByteTy;
397 break;
398
399 default: break;
400 }
401
402 if (Size) {
403 GenericValue GV;
404 void *Arg = Args[ArgNo++];
405 memcpy(&GV, Arg, Size);
406 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
407 }
408 }
409 }
410 }
411}
412
Chris Lattner665ee882002-03-08 22:51:07 +0000413// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000414GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000415 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
416
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000417 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000418 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000419 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000420
421 GenericValue GV;
422 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
423 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000424 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
425 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
426 return GV;
427}
428
429// int scanf(const char *format, ...);
430GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
431 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
432
433 char *Args[10];
434 for (unsigned i = 0; i < args.size(); ++i)
435 Args[i] = (char*)GVTOP(args[i]);
436
437 GenericValue GV;
438 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
439 Args[5], Args[6], Args[7], Args[8], Args[9]);
440 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
441 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000442 return GV;
443}
444
445
Chris Lattner295fe672002-01-23 21:38:07 +0000446// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000447GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000448 extern int clock(void);
449 GenericValue GV; GV.IntVal = clock();
450 return GV;
451}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000452
Chris Lattner957d62a2003-04-23 19:55:24 +0000453
454//===----------------------------------------------------------------------===//
455// String Functions...
456//===----------------------------------------------------------------------===//
457
458// int strcmp(const char *S1, const char *S2);
459GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
460 assert(Args.size() == 2);
461 GenericValue Ret;
462 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
463 return Ret;
464}
465
466// char *strcat(char *Dest, const char *src);
467GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
468 assert(Args.size() == 2);
469 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
470}
471
472// char *strcpy(char *Dest, const char *src);
473GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
474 assert(Args.size() == 2);
475 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
476}
477
478// long strlen(const char *src);
479GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
480 assert(Args.size() == 1);
481 GenericValue Ret;
482 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
483 return Ret;
484}
485
Brian Gaeke70975ee2003-09-05 18:42:01 +0000486// char *strdup(const char *src);
487GenericValue lle_X_strdup(FunctionType *M, const vector<GenericValue> &Args) {
488 assert(Args.size() == 1);
489 return PTOGV(strdup((char*)GVTOP(Args[0])));
490}
491
Chris Lattnerc8cff9e2003-04-25 18:23:38 +0000492// char *__strdup(const char *src);
493GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
494 assert(Args.size() == 1);
495 return PTOGV(strdup((char*)GVTOP(Args[0])));
496}
497
Chris Lattner957d62a2003-04-23 19:55:24 +0000498// void *memset(void *S, int C, size_t N)
499GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
500 assert(Args.size() == 3);
501 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
502}
503
Chris Lattner5f311a72003-04-23 20:23:16 +0000504// void *memcpy(void *Dest, void *src, size_t Size);
505GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
506 assert(Args.size() == 3);
507 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
508 Args[2].UIntVal));
509}
Chris Lattner957d62a2003-04-23 19:55:24 +0000510
Chris Lattner665ee882002-03-08 22:51:07 +0000511//===----------------------------------------------------------------------===//
512// IO Functions...
513//===----------------------------------------------------------------------===//
514
Chris Lattner005cbce2002-10-02 21:12:13 +0000515// getFILE - Turn a pointer in the host address space into a legit pointer in
516// the interpreter address space. For the most part, this is an identity
517// transformation, but if the program refers to stdio, stderr, stdin then they
518// have pointers that are relative to the __iob array. If this is the case,
519// change the FILE into the REAL stdio stream.
520//
Chris Lattnerb1118742003-01-13 00:59:47 +0000521static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000522 static Module *LastMod = 0;
523 static PointerTy IOBBase = 0;
524 static unsigned FILESize;
525
Chris Lattnerfe11a972002-12-23 23:59:41 +0000526 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
527 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000528
529 // Check to see if the currently loaded module contains an __iob symbol...
530 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000531 SymbolTable &ST = M->getSymbolTable();
532 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
533 SymbolTable::VarMap &M = I->second;
534 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
535 J != E; ++J)
536 if (J->first == "__iob")
537 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
538 break;
539 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000540 }
541
Chris Lattnerfe11a972002-12-23 23:59:41 +0000542#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000543 // If we found an __iob symbol now, find out what the actual address it's
544 // held in is...
545 if (IOB) {
546 // Get the address the array lives in...
547 GlobalAddress *Address =
548 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
549 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
550
551 // Figure out how big each element of the array is...
552 const ArrayType *AT =
553 dyn_cast<ArrayType>(IOB->getType()->getElementType());
554 if (AT)
555 FILESize = TD.getTypeSize(AT->getElementType());
556 else
557 FILESize = 16*8; // Default size
558 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000559#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000560 }
561
562 // Check to see if this is a reference to __iob...
563 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000564 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000565 if (FDNum == 0)
566 return stdin;
567 else if (FDNum == 1)
568 return stdout;
569 else if (FDNum == 2)
570 return stderr;
571 }
572
573 return (FILE*)Ptr;
574}
575
576
Chris Lattner665ee882002-03-08 22:51:07 +0000577// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000578GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000579 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000580 return PTOGV(fopen((const char *)GVTOP(Args[0]),
581 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000582}
583
584// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000585GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000586 assert(Args.size() == 1);
587 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000588 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000589 return GV;
590}
591
Chris Lattner25f6f372002-11-08 19:10:26 +0000592// int feof(FILE *stream);
593GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
594 assert(Args.size() == 1);
595 GenericValue GV;
596
Chris Lattnerb1118742003-01-13 00:59:47 +0000597 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000598 return GV;
599}
600
Chris Lattner665ee882002-03-08 22:51:07 +0000601// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000602GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000603 assert(Args.size() == 4);
604 GenericValue GV;
605
Chris Lattnerb1118742003-01-13 00:59:47 +0000606 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
607 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000608 return GV;
609}
610
611// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000612GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000613 assert(Args.size() == 4);
614 GenericValue GV;
615
Chris Lattnerb1118742003-01-13 00:59:47 +0000616 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
617 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000618 return GV;
619}
620
621// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000622GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000623 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000624 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
625 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000626}
627
Chris Lattnera4479cd2002-11-07 19:33:50 +0000628// FILE *freopen(const char *path, const char *mode, FILE *stream);
629GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
630 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000631 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
632 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000633}
634
Chris Lattner665ee882002-03-08 22:51:07 +0000635// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000636GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000637 assert(Args.size() == 1);
638 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000639 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000640 return GV;
641}
642
643// int getc(FILE *stream);
644GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
645 assert(Args.size() == 1);
646 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000647 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000648 return GV;
649}
650
Chris Lattnerf87a1982003-04-23 19:20:50 +0000651// int _IO_getc(FILE *stream);
652GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
653 return lle_X_getc(F, Args);
654}
655
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000656// int fputc(int C, FILE *stream);
657GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
658 assert(Args.size() == 2);
659 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000660 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000661 return GV;
662}
663
664// int ungetc(int C, FILE *stream);
665GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
666 assert(Args.size() == 2);
667 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000668 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000669 return GV;
670}
671
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000672// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
673// useful.
674GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000675 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000676 char Buffer[10000];
677 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000678 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000679 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000680 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000681
Chris Lattnerb1118742003-01-13 00:59:47 +0000682 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000683 return GV;
684}
685
Chris Lattner374344c2003-05-08 16:52:43 +0000686//===----------------------------------------------------------------------===//
687// LLVM Intrinsic Functions...
688//===----------------------------------------------------------------------===//
689
Chris Lattner4c665492003-10-18 05:55:25 +0000690// <va_list> llvm.va_start() - Implement the va_start operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000691GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000692 assert(Args.size() == 0);
Chris Lattner374344c2003-05-08 16:52:43 +0000693 GenericValue Val;
694 Val.UIntVal = 0; // Start at the first '...' argument...
Chris Lattner4c665492003-10-18 05:55:25 +0000695 return Val;
Chris Lattner374344c2003-05-08 16:52:43 +0000696}
697
698// void llvm.va_end(<va_list> *) - Implement the va_end operation...
699GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
700 assert(Args.size() == 1);
701 return GenericValue(); // Noop!
702}
703
Chris Lattner4c665492003-10-18 05:55:25 +0000704// <va_list> llvm.va_copy(<va_list>) - Implement the va_copy operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000705GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000706 assert(Args.size() == 1);
707 return Args[0];
Chris Lattner374344c2003-05-08 16:52:43 +0000708}
709
Chris Lattner7720c8e2001-09-10 04:50:17 +0000710} // End extern "C"
Chris Lattner4721f132001-10-30 20:28:00 +0000711
712
Chris Lattnerda82ed52003-05-08 16:18:31 +0000713void Interpreter::initializeExternalFunctions() {
Chris Lattner0f279b22001-11-03 10:15:32 +0000714 FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
715 FuncNames["lle_ii_putchar"] = lle_ii_putchar;
716 FuncNames["lle_VB_putchar"] = lle_VB_putchar;
Chris Lattner0f279b22001-11-03 10:15:32 +0000717 FuncNames["lle_X_exit"] = lle_X_exit;
Chris Lattner1ee34a52002-05-20 21:17:16 +0000718 FuncNames["lle_X_abort"] = lle_X_abort;
Chris Lattner0f279b22001-11-03 10:15:32 +0000719 FuncNames["lle_X_malloc"] = lle_X_malloc;
Chris Lattner957d62a2003-04-23 19:55:24 +0000720 FuncNames["lle_X_calloc"] = lle_X_calloc;
Chris Lattner0f279b22001-11-03 10:15:32 +0000721 FuncNames["lle_X_free"] = lle_X_free;
Chris Lattner782b9392001-11-26 18:18:18 +0000722 FuncNames["lle_X_atoi"] = lle_X_atoi;
Chris Lattner0f279b22001-11-03 10:15:32 +0000723 FuncNames["lle_X_pow"] = lle_X_pow;
Chris Lattner34dd24b2002-02-18 19:06:25 +0000724 FuncNames["lle_X_exp"] = lle_X_exp;
Chris Lattner1b600142001-11-13 05:46:08 +0000725 FuncNames["lle_X_log"] = lle_X_log;
Chris Lattner782b9392001-11-26 18:18:18 +0000726 FuncNames["lle_X_floor"] = lle_X_floor;
727 FuncNames["lle_X_srand"] = lle_X_srand;
Chris Lattner1b600142001-11-13 05:46:08 +0000728 FuncNames["lle_X_drand48"] = lle_X_drand48;
729 FuncNames["lle_X_srand48"] = lle_X_srand48;
730 FuncNames["lle_X_lrand48"] = lle_X_lrand48;
Chris Lattnerc063d382001-11-06 21:52:18 +0000731 FuncNames["lle_X_sqrt"] = lle_X_sqrt;
Chris Lattnerb1118742003-01-13 00:59:47 +0000732 FuncNames["lle_X_puts"] = lle_X_puts;
Chris Lattner0f279b22001-11-03 10:15:32 +0000733 FuncNames["lle_X_printf"] = lle_X_printf;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000734 FuncNames["lle_X_sprintf"] = lle_X_sprintf;
Chris Lattner665ee882002-03-08 22:51:07 +0000735 FuncNames["lle_X_sscanf"] = lle_X_sscanf;
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000736 FuncNames["lle_X_scanf"] = lle_X_scanf;
Chris Lattner295fe672002-01-23 21:38:07 +0000737 FuncNames["lle_i_clock"] = lle_i_clock;
Chris Lattner957d62a2003-04-23 19:55:24 +0000738
739 FuncNames["lle_X_strcmp"] = lle_X_strcmp;
740 FuncNames["lle_X_strcat"] = lle_X_strcat;
741 FuncNames["lle_X_strcpy"] = lle_X_strcpy;
742 FuncNames["lle_X_strlen"] = lle_X_strlen;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000743 FuncNames["lle_X___strdup"] = lle_X___strdup;
Chris Lattner957d62a2003-04-23 19:55:24 +0000744 FuncNames["lle_X_memset"] = lle_X_memset;
Chris Lattner5f311a72003-04-23 20:23:16 +0000745 FuncNames["lle_X_memcpy"] = lle_X_memcpy;
Chris Lattner957d62a2003-04-23 19:55:24 +0000746
Chris Lattner665ee882002-03-08 22:51:07 +0000747 FuncNames["lle_X_fopen"] = lle_X_fopen;
748 FuncNames["lle_X_fclose"] = lle_X_fclose;
Chris Lattner25f6f372002-11-08 19:10:26 +0000749 FuncNames["lle_X_feof"] = lle_X_feof;
Chris Lattner665ee882002-03-08 22:51:07 +0000750 FuncNames["lle_X_fread"] = lle_X_fread;
751 FuncNames["lle_X_fwrite"] = lle_X_fwrite;
752 FuncNames["lle_X_fgets"] = lle_X_fgets;
753 FuncNames["lle_X_fflush"] = lle_X_fflush;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000754 FuncNames["lle_X_fgetc"] = lle_X_getc;
Chris Lattner005cbce2002-10-02 21:12:13 +0000755 FuncNames["lle_X_getc"] = lle_X_getc;
Chris Lattnerf87a1982003-04-23 19:20:50 +0000756 FuncNames["lle_X__IO_getc"] = lle_X__IO_getc;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000757 FuncNames["lle_X_fputc"] = lle_X_fputc;
758 FuncNames["lle_X_ungetc"] = lle_X_ungetc;
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000759 FuncNames["lle_X_fprintf"] = lle_X_fprintf;
Chris Lattnera4479cd2002-11-07 19:33:50 +0000760 FuncNames["lle_X_freopen"] = lle_X_freopen;
Chris Lattner374344c2003-05-08 16:52:43 +0000761
762 FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
763 FuncNames["lle_X_llvm.va_end"] = llvm_va_end;
764 FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
Chris Lattner4721f132001-10-30 20:28:00 +0000765}