blob: a859f181a13ff5478e0fa35f3aa888bddd1bc6d5 [file] [log] [blame]
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001//===-- ExternalFunctions.cpp - Implement External Functions --------------===//
Chris Lattner7720c8e2001-09-10 04:50:17 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000010// This file contains both code to deal with invoking "external" functions, but
11// also contains code that implements "exported" external functions.
Chris Lattner7720c8e2001-09-10 04:50:17 +000012//
Brian Gaeke58a6faa2003-10-10 17:03:10 +000013// External functions in the interpreter are implemented by
14// using the system's dynamic loader to look up the address of the function
15// we want to invoke. If a function is found, then one of the
16// many lle_* wrapper functions in this file will translate its arguments from
17// GenericValues to the types the function is actually expecting, before the
18// function is called.
Chris Lattner7720c8e2001-09-10 04:50:17 +000019//
20//===----------------------------------------------------------------------===//
21
22#include "Interpreter.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000023#include "ExecutionAnnotations.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000024#include "llvm/DerivedTypes.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000025#include "llvm/Module.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000026#include "llvm/SymbolTable.h"
27#include "llvm/Target/TargetData.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000028#include "Support/DynamicLinker.h"
John Criswell7a73b802003-06-30 21:59:07 +000029#include "Config/dlfcn.h"
30#include "Config/link.h"
Brian Gaeke70337982003-06-23 19:41:55 +000031#include <cmath>
Misha Brukmanb8d15b22003-10-14 21:42:11 +000032#include <map>
Chris Lattner697954c2002-01-20 22:54:45 +000033using std::vector;
Chris Lattner7720c8e2001-09-10 04:50:17 +000034
Chris Lattnerb408b122002-03-29 03:57:15 +000035typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
36static std::map<const Function *, ExFunc> Functions;
Chris Lattner697954c2002-01-20 22:54:45 +000037static std::map<std::string, ExFunc> FuncNames;
Chris Lattner7720c8e2001-09-10 04:50:17 +000038
Chris Lattnere43db882001-10-27 04:15:57 +000039static Interpreter *TheInterpreter;
40
Chris Lattner7720c8e2001-09-10 04:50:17 +000041static char getTypeID(const Type *Ty) {
42 switch (Ty->getPrimitiveID()) {
43 case Type::VoidTyID: return 'V';
44 case Type::BoolTyID: return 'o';
45 case Type::UByteTyID: return 'B';
46 case Type::SByteTyID: return 'b';
47 case Type::UShortTyID: return 'S';
48 case Type::ShortTyID: return 's';
49 case Type::UIntTyID: return 'I';
50 case Type::IntTyID: return 'i';
51 case Type::ULongTyID: return 'L';
52 case Type::LongTyID: return 'l';
53 case Type::FloatTyID: return 'F';
54 case Type::DoubleTyID: return 'D';
55 case Type::PointerTyID: return 'P';
Chris Lattnerb408b122002-03-29 03:57:15 +000056 case Type::FunctionTyID: return 'M';
Chris Lattner7720c8e2001-09-10 04:50:17 +000057 case Type::StructTyID: return 'T';
58 case Type::ArrayTyID: return 'A';
59 case Type::OpaqueTyID: return 'O';
60 default: return 'U';
61 }
62}
63
Brian Gaeke58a6faa2003-10-10 17:03:10 +000064static ExFunc lookupFunction(const Function *F) {
Chris Lattner7720c8e2001-09-10 04:50:17 +000065 // Function not found, look it up... start by figuring out what the
66 // composite function name should be.
Chris Lattner697954c2002-01-20 22:54:45 +000067 std::string ExtName = "lle_";
Brian Gaeke58a6faa2003-10-10 17:03:10 +000068 const FunctionType *FT = F->getFunctionType();
69 for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
70 ExtName += getTypeID(FT->getContainedType(i));
71 ExtName += "_" + F->getName();
Chris Lattner7720c8e2001-09-10 04:50:17 +000072
Chris Lattner4721f132001-10-30 20:28:00 +000073 ExFunc FnPtr = FuncNames[ExtName];
74 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000075 FnPtr = (ExFunc)GetAddressOfSymbol(ExtName);
Chris Lattner4721f132001-10-30 20:28:00 +000076 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000077 FnPtr = FuncNames["lle_X_"+F->getName()];
Chris Lattner7720c8e2001-09-10 04:50:17 +000078 if (FnPtr == 0) // Try calling a generic function... if it exists...
Brian Gaeke58a6faa2003-10-10 17:03:10 +000079 FnPtr = (ExFunc)GetAddressOfSymbol(("lle_X_"+F->getName()).c_str());
Chris Lattner7720c8e2001-09-10 04:50:17 +000080 if (FnPtr != 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000081 Functions.insert(std::make_pair(F, FnPtr)); // Cache for later
Chris Lattner7720c8e2001-09-10 04:50:17 +000082 return FnPtr;
83}
84
Chris Lattnerda82ed52003-05-08 16:18:31 +000085GenericValue Interpreter::callExternalFunction(Function *M,
Chris Lattner44edb6b2003-05-14 14:21:30 +000086 const std::vector<GenericValue> &ArgVals) {
Chris Lattnere43db882001-10-27 04:15:57 +000087 TheInterpreter = this;
88
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000089 // Do a lookup to see if the function is in our cache... this should just be a
Misha Brukmand5d96b92003-10-10 17:42:19 +000090 // deferred annotation!
Chris Lattnerb408b122002-03-29 03:57:15 +000091 std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
92 ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
Chris Lattner7720c8e2001-09-10 04:50:17 +000093 if (Fn == 0) {
Chris Lattnerda82ed52003-05-08 16:18:31 +000094 std::cout << "Tried to execute an unknown external function: "
95 << M->getType()->getDescription() << " " << M->getName() << "\n";
Chris Lattner4721f132001-10-30 20:28:00 +000096 return GenericValue();
Chris Lattner7720c8e2001-09-10 04:50:17 +000097 }
98
99 // TODO: FIXME when types are not const!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000100 GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
101 ArgVals);
Chris Lattner4721f132001-10-30 20:28:00 +0000102 return Result;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000103}
104
105
106//===----------------------------------------------------------------------===//
Chris Lattnerb408b122002-03-29 03:57:15 +0000107// Functions "exported" to the running application...
Chris Lattner7720c8e2001-09-10 04:50:17 +0000108//
109extern "C" { // Don't add C++ manglings to llvm mangling :)
110
Chris Lattner005cbce2002-10-02 21:12:13 +0000111// void putchar(sbyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000112GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000113 std::cout << Args[0].SByteVal;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000114 return GenericValue();
115}
116
Chris Lattner005cbce2002-10-02 21:12:13 +0000117// int putchar(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000118GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000119 std::cout << ((char)Args[0].IntVal) << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000120 return Args[0];
121}
122
Chris Lattner005cbce2002-10-02 21:12:13 +0000123// void putchar(ubyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000124GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000125 std::cout << Args[0].SByteVal << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000126 return Args[0];
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000127}
128
Chris Lattner44edb6b2003-05-14 14:21:30 +0000129// void atexit(Function*)
130GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
131 assert(Args.size() == 1);
132 TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
133 GenericValue GV;
134 GV.IntVal = 0;
135 return GV;
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000136}
137
Chris Lattner005cbce2002-10-02 21:12:13 +0000138// void exit(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000139GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere43db882001-10-27 04:15:57 +0000140 TheInterpreter->exitCalled(Args[0]);
141 return GenericValue();
142}
143
Chris Lattner005cbce2002-10-02 21:12:13 +0000144// void abort(void)
Chris Lattner1ee34a52002-05-20 21:17:16 +0000145GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
146 std::cerr << "***PROGRAM ABORTED***!\n";
147 GenericValue GV;
148 GV.IntVal = 1;
149 TheInterpreter->exitCalled(GV);
150 return GenericValue();
151}
152
Chris Lattnerc2593162001-10-27 08:28:11 +0000153// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000154GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000155 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000156 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000157}
158
Chris Lattner957d62a2003-04-23 19:55:24 +0000159// void *calloc(uint, uint)
160GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
161 assert(Args.size() == 2 && "calloc expects two arguments!");
162 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
163}
164
Chris Lattnerc2593162001-10-27 08:28:11 +0000165// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000166GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000167 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000168 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000169 return GenericValue();
170}
171
Chris Lattner782b9392001-11-26 18:18:18 +0000172// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000173GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000174 assert(Args.size() == 1);
175 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000176 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000177 return GV;
178}
179
Chris Lattnerc2593162001-10-27 08:28:11 +0000180// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000181GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000182 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000183 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000184 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000185 return GV;
186}
187
Chris Lattner34dd24b2002-02-18 19:06:25 +0000188// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000189GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000190 assert(Args.size() == 1);
191 GenericValue GV;
192 GV.DoubleVal = exp(Args[0].DoubleVal);
193 return GV;
194}
195
Chris Lattnerc063d382001-11-06 21:52:18 +0000196// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000197GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000198 assert(Args.size() == 1);
199 GenericValue GV;
200 GV.DoubleVal = sqrt(Args[0].DoubleVal);
201 return GV;
202}
Chris Lattnerc2593162001-10-27 08:28:11 +0000203
Chris Lattner86790052001-11-06 22:53:25 +0000204// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000205GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000206 assert(Args.size() == 1);
207 GenericValue GV;
208 GV.DoubleVal = log(Args[0].DoubleVal);
209 return GV;
210}
211
Chris Lattner782b9392001-11-26 18:18:18 +0000212// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000213GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000214 assert(Args.size() == 1);
215 GenericValue GV;
216 GV.DoubleVal = floor(Args[0].DoubleVal);
217 return GV;
218}
219
Chris Lattner86790052001-11-06 22:53:25 +0000220// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000221GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000222 assert(Args.size() == 0);
223 GenericValue GV;
224 GV.DoubleVal = drand48();
225 return GV;
226}
227
Chris Lattner1b600142001-11-13 05:46:08 +0000228// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000229GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000230 assert(Args.size() == 0);
231 GenericValue GV;
232 GV.IntVal = lrand48();
233 return GV;
234}
235
236// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000237GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000238 assert(Args.size() == 1);
239 srand48(Args[0].IntVal);
240 return GenericValue();
241}
242
Chris Lattner782b9392001-11-26 18:18:18 +0000243// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000244GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000245 assert(Args.size() == 1);
246 srand(Args[0].UIntVal);
247 return GenericValue();
248}
Chris Lattner86790052001-11-06 22:53:25 +0000249
Chris Lattnerb1118742003-01-13 00:59:47 +0000250// int puts(const char*)
251GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
252 assert(Args.size() == 1);
253 GenericValue GV;
254 GV.IntVal = puts((char*)GVTOP(Args[0]));
255 return GV;
256}
257
Chris Lattnere7c6f722001-12-13 00:43:47 +0000258// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
259// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000260GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000261 char *OutputBuffer = (char *)GVTOP(Args[0]);
262 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000263 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000264
265 // printf should return # chars printed. This is completely incorrect, but
266 // close enough for now.
267 GenericValue GV; GV.IntVal = strlen(FmtStr);
268 while (1) {
269 switch (*FmtStr) {
270 case 0: return GV; // Null terminator...
271 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000272 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000273 break;
274 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000275 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
276 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000277 break;
278 }
279 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000280 char FmtBuf[100] = "", Buffer[1000] = "";
281 char *FB = FmtBuf;
282 *FB++ = *FmtStr++;
283 char Last = *FB++ = *FmtStr++;
284 unsigned HowLong = 0;
285 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
286 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
287 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
288 Last != 'p' && Last != 's' && Last != '%') {
289 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
290 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000291 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000292 *FB = 0;
293
294 switch (Last) {
295 case '%':
296 sprintf(Buffer, FmtBuf); break;
297 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000298 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000299 case 'd': case 'i':
300 case 'u': case 'o':
301 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000302 if (HowLong >= 1) {
Chris Lattner1543e402003-08-24 14:02:47 +0000303 if (HowLong == 1 &&
304 TheInterpreter->getModule().getPointerSize()==Module::Pointer64 &&
Chris Lattner7471c482003-04-25 18:28:44 +0000305 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000306 // Make sure we use %lld with a 64 bit argument because we might be
307 // compiling LLI on a 32 bit compiler.
308 unsigned Size = strlen(FmtBuf);
309 FmtBuf[Size] = FmtBuf[Size-1];
310 FmtBuf[Size+1] = 0;
311 FmtBuf[Size-1] = 'l';
312 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000313 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000314 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000315 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
316 case 'e': case 'E': case 'g': case 'G': case 'f':
317 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
318 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000319 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000320 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000321 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000322 default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000323 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000324 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000325 strcpy(OutputBuffer, Buffer);
326 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000327 }
Chris Lattner08845a22001-10-29 20:27:45 +0000328 break;
329 }
Chris Lattner08845a22001-10-29 20:27:45 +0000330 }
331}
332
Chris Lattnere7c6f722001-12-13 00:43:47 +0000333// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000334GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000335 char Buffer[10000];
336 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000337 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000338 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000339 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnerda82ed52003-05-08 16:18:31 +0000340 std::cout << Buffer;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000341 return GV;
342}
343
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000344static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
345 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
346 void *Arg6, void *Arg7, void *Arg8) {
347 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
348
349 // Loop over the format string, munging read values as appropriate (performs
Misha Brukman5560c9d2003-08-18 14:43:39 +0000350 // byteswaps as necessary).
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000351 unsigned ArgNo = 0;
352 while (*Fmt) {
353 if (*Fmt++ == '%') {
354 // Read any flag characters that may be present...
355 bool Suppress = false;
356 bool Half = false;
357 bool Long = false;
358 bool LongLong = false; // long long or long double
359
360 while (1) {
361 switch (*Fmt++) {
362 case '*': Suppress = true; break;
363 case 'a': /*Allocate = true;*/ break; // We don't need to track this
364 case 'h': Half = true; break;
365 case 'l': Long = true; break;
366 case 'q':
367 case 'L': LongLong = true; break;
368 default:
369 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
370 goto Out;
371 }
372 }
373 Out:
374
375 // Read the conversion character
376 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
377 unsigned Size = 0;
378 const Type *Ty = 0;
379
380 switch (Fmt[-1]) {
381 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
382 case 'd':
383 if (Long || LongLong) {
384 Size = 8; Ty = Type::ULongTy;
385 } else if (Half) {
386 Size = 4; Ty = Type::UShortTy;
387 } else {
388 Size = 4; Ty = Type::UIntTy;
389 }
390 break;
391
392 case 'e': case 'g': case 'E':
393 case 'f':
394 if (Long || LongLong) {
395 Size = 8; Ty = Type::DoubleTy;
396 } else {
397 Size = 4; Ty = Type::FloatTy;
398 }
399 break;
400
401 case 's': case 'c': case '[': // No byteswap needed
402 Size = 1;
403 Ty = Type::SByteTy;
404 break;
405
406 default: break;
407 }
408
409 if (Size) {
410 GenericValue GV;
411 void *Arg = Args[ArgNo++];
412 memcpy(&GV, Arg, Size);
413 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
414 }
415 }
416 }
417 }
418}
419
Chris Lattner665ee882002-03-08 22:51:07 +0000420// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000421GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000422 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
423
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000424 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000425 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000426 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000427
428 GenericValue GV;
429 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
430 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000431 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
432 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
433 return GV;
434}
435
436// int scanf(const char *format, ...);
437GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
438 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
439
440 char *Args[10];
441 for (unsigned i = 0; i < args.size(); ++i)
442 Args[i] = (char*)GVTOP(args[i]);
443
444 GenericValue GV;
445 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
446 Args[5], Args[6], Args[7], Args[8], Args[9]);
447 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
448 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000449 return GV;
450}
451
452
Chris Lattner295fe672002-01-23 21:38:07 +0000453// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000454GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000455 extern int clock(void);
456 GenericValue GV; GV.IntVal = clock();
457 return GV;
458}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000459
Chris Lattner957d62a2003-04-23 19:55:24 +0000460
461//===----------------------------------------------------------------------===//
462// String Functions...
463//===----------------------------------------------------------------------===//
464
465// int strcmp(const char *S1, const char *S2);
466GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
467 assert(Args.size() == 2);
468 GenericValue Ret;
469 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
470 return Ret;
471}
472
473// char *strcat(char *Dest, const char *src);
474GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
475 assert(Args.size() == 2);
476 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
477}
478
479// char *strcpy(char *Dest, const char *src);
480GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
481 assert(Args.size() == 2);
482 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
483}
484
485// long strlen(const char *src);
486GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
487 assert(Args.size() == 1);
488 GenericValue Ret;
489 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
490 return Ret;
491}
492
Brian Gaeke70975ee2003-09-05 18:42:01 +0000493// char *strdup(const char *src);
494GenericValue lle_X_strdup(FunctionType *M, const vector<GenericValue> &Args) {
495 assert(Args.size() == 1);
496 return PTOGV(strdup((char*)GVTOP(Args[0])));
497}
498
Chris Lattnerc8cff9e2003-04-25 18:23:38 +0000499// char *__strdup(const char *src);
500GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
501 assert(Args.size() == 1);
502 return PTOGV(strdup((char*)GVTOP(Args[0])));
503}
504
Chris Lattner957d62a2003-04-23 19:55:24 +0000505// void *memset(void *S, int C, size_t N)
506GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
507 assert(Args.size() == 3);
508 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
509}
510
Chris Lattner5f311a72003-04-23 20:23:16 +0000511// void *memcpy(void *Dest, void *src, size_t Size);
512GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
513 assert(Args.size() == 3);
514 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
515 Args[2].UIntVal));
516}
Chris Lattner957d62a2003-04-23 19:55:24 +0000517
Chris Lattner665ee882002-03-08 22:51:07 +0000518//===----------------------------------------------------------------------===//
519// IO Functions...
520//===----------------------------------------------------------------------===//
521
Chris Lattner005cbce2002-10-02 21:12:13 +0000522// getFILE - Turn a pointer in the host address space into a legit pointer in
523// the interpreter address space. For the most part, this is an identity
524// transformation, but if the program refers to stdio, stderr, stdin then they
525// have pointers that are relative to the __iob array. If this is the case,
526// change the FILE into the REAL stdio stream.
527//
Chris Lattnerb1118742003-01-13 00:59:47 +0000528static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000529 static Module *LastMod = 0;
530 static PointerTy IOBBase = 0;
531 static unsigned FILESize;
532
Chris Lattnerfe11a972002-12-23 23:59:41 +0000533 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
534 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000535
536 // Check to see if the currently loaded module contains an __iob symbol...
537 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000538 SymbolTable &ST = M->getSymbolTable();
539 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
540 SymbolTable::VarMap &M = I->second;
541 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
542 J != E; ++J)
543 if (J->first == "__iob")
544 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
545 break;
546 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000547 }
548
Chris Lattnerfe11a972002-12-23 23:59:41 +0000549#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000550 // If we found an __iob symbol now, find out what the actual address it's
551 // held in is...
552 if (IOB) {
553 // Get the address the array lives in...
554 GlobalAddress *Address =
555 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
556 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
557
558 // Figure out how big each element of the array is...
559 const ArrayType *AT =
560 dyn_cast<ArrayType>(IOB->getType()->getElementType());
561 if (AT)
562 FILESize = TD.getTypeSize(AT->getElementType());
563 else
564 FILESize = 16*8; // Default size
565 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000566#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000567 }
568
569 // Check to see if this is a reference to __iob...
570 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000571 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000572 if (FDNum == 0)
573 return stdin;
574 else if (FDNum == 1)
575 return stdout;
576 else if (FDNum == 2)
577 return stderr;
578 }
579
580 return (FILE*)Ptr;
581}
582
583
Chris Lattner665ee882002-03-08 22:51:07 +0000584// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000585GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000586 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000587 return PTOGV(fopen((const char *)GVTOP(Args[0]),
588 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000589}
590
591// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000592GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000593 assert(Args.size() == 1);
594 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000595 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000596 return GV;
597}
598
Chris Lattner25f6f372002-11-08 19:10:26 +0000599// int feof(FILE *stream);
600GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
601 assert(Args.size() == 1);
602 GenericValue GV;
603
Chris Lattnerb1118742003-01-13 00:59:47 +0000604 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000605 return GV;
606}
607
Chris Lattner665ee882002-03-08 22:51:07 +0000608// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000609GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000610 assert(Args.size() == 4);
611 GenericValue GV;
612
Chris Lattnerb1118742003-01-13 00:59:47 +0000613 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
614 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000615 return GV;
616}
617
618// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000619GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000620 assert(Args.size() == 4);
621 GenericValue GV;
622
Chris Lattnerb1118742003-01-13 00:59:47 +0000623 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
624 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000625 return GV;
626}
627
628// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000629GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000630 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000631 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
632 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000633}
634
Chris Lattnera4479cd2002-11-07 19:33:50 +0000635// FILE *freopen(const char *path, const char *mode, FILE *stream);
636GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
637 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000638 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
639 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000640}
641
Chris Lattner665ee882002-03-08 22:51:07 +0000642// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000643GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000644 assert(Args.size() == 1);
645 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000646 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000647 return GV;
648}
649
650// int getc(FILE *stream);
651GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
652 assert(Args.size() == 1);
653 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000654 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000655 return GV;
656}
657
Chris Lattnerf87a1982003-04-23 19:20:50 +0000658// int _IO_getc(FILE *stream);
659GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
660 return lle_X_getc(F, Args);
661}
662
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000663// int fputc(int C, FILE *stream);
664GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
665 assert(Args.size() == 2);
666 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000667 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000668 return GV;
669}
670
671// int ungetc(int C, FILE *stream);
672GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
673 assert(Args.size() == 2);
674 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000675 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000676 return GV;
677}
678
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000679// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
680// useful.
681GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000682 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000683 char Buffer[10000];
684 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000685 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000686 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000687 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000688
Chris Lattnerb1118742003-01-13 00:59:47 +0000689 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000690 return GV;
691}
692
Chris Lattner374344c2003-05-08 16:52:43 +0000693//===----------------------------------------------------------------------===//
694// LLVM Intrinsic Functions...
695//===----------------------------------------------------------------------===//
696
Chris Lattner4c665492003-10-18 05:55:25 +0000697// <va_list> llvm.va_start() - Implement the va_start operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000698GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000699 assert(Args.size() == 0);
Chris Lattner374344c2003-05-08 16:52:43 +0000700 GenericValue Val;
701 Val.UIntVal = 0; // Start at the first '...' argument...
Chris Lattner4c665492003-10-18 05:55:25 +0000702 return Val;
Chris Lattner374344c2003-05-08 16:52:43 +0000703}
704
705// void llvm.va_end(<va_list> *) - Implement the va_end operation...
706GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
707 assert(Args.size() == 1);
708 return GenericValue(); // Noop!
709}
710
Chris Lattner4c665492003-10-18 05:55:25 +0000711// <va_list> llvm.va_copy(<va_list>) - Implement the va_copy operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000712GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000713 assert(Args.size() == 1);
714 return Args[0];
Chris Lattner374344c2003-05-08 16:52:43 +0000715}
716
Chris Lattner7720c8e2001-09-10 04:50:17 +0000717} // End extern "C"
Chris Lattner4721f132001-10-30 20:28:00 +0000718
719
Chris Lattnerda82ed52003-05-08 16:18:31 +0000720void Interpreter::initializeExternalFunctions() {
Chris Lattner0f279b22001-11-03 10:15:32 +0000721 FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
722 FuncNames["lle_ii_putchar"] = lle_ii_putchar;
723 FuncNames["lle_VB_putchar"] = lle_VB_putchar;
Chris Lattner0f279b22001-11-03 10:15:32 +0000724 FuncNames["lle_X_exit"] = lle_X_exit;
Chris Lattner1ee34a52002-05-20 21:17:16 +0000725 FuncNames["lle_X_abort"] = lle_X_abort;
Chris Lattner0f279b22001-11-03 10:15:32 +0000726 FuncNames["lle_X_malloc"] = lle_X_malloc;
Chris Lattner957d62a2003-04-23 19:55:24 +0000727 FuncNames["lle_X_calloc"] = lle_X_calloc;
Chris Lattner0f279b22001-11-03 10:15:32 +0000728 FuncNames["lle_X_free"] = lle_X_free;
Chris Lattner782b9392001-11-26 18:18:18 +0000729 FuncNames["lle_X_atoi"] = lle_X_atoi;
Chris Lattner0f279b22001-11-03 10:15:32 +0000730 FuncNames["lle_X_pow"] = lle_X_pow;
Chris Lattner34dd24b2002-02-18 19:06:25 +0000731 FuncNames["lle_X_exp"] = lle_X_exp;
Chris Lattner1b600142001-11-13 05:46:08 +0000732 FuncNames["lle_X_log"] = lle_X_log;
Chris Lattner782b9392001-11-26 18:18:18 +0000733 FuncNames["lle_X_floor"] = lle_X_floor;
734 FuncNames["lle_X_srand"] = lle_X_srand;
Chris Lattner1b600142001-11-13 05:46:08 +0000735 FuncNames["lle_X_drand48"] = lle_X_drand48;
736 FuncNames["lle_X_srand48"] = lle_X_srand48;
737 FuncNames["lle_X_lrand48"] = lle_X_lrand48;
Chris Lattnerc063d382001-11-06 21:52:18 +0000738 FuncNames["lle_X_sqrt"] = lle_X_sqrt;
Chris Lattnerb1118742003-01-13 00:59:47 +0000739 FuncNames["lle_X_puts"] = lle_X_puts;
Chris Lattner0f279b22001-11-03 10:15:32 +0000740 FuncNames["lle_X_printf"] = lle_X_printf;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000741 FuncNames["lle_X_sprintf"] = lle_X_sprintf;
Chris Lattner665ee882002-03-08 22:51:07 +0000742 FuncNames["lle_X_sscanf"] = lle_X_sscanf;
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000743 FuncNames["lle_X_scanf"] = lle_X_scanf;
Chris Lattner295fe672002-01-23 21:38:07 +0000744 FuncNames["lle_i_clock"] = lle_i_clock;
Chris Lattner957d62a2003-04-23 19:55:24 +0000745
746 FuncNames["lle_X_strcmp"] = lle_X_strcmp;
747 FuncNames["lle_X_strcat"] = lle_X_strcat;
748 FuncNames["lle_X_strcpy"] = lle_X_strcpy;
749 FuncNames["lle_X_strlen"] = lle_X_strlen;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000750 FuncNames["lle_X___strdup"] = lle_X___strdup;
Chris Lattner957d62a2003-04-23 19:55:24 +0000751 FuncNames["lle_X_memset"] = lle_X_memset;
Chris Lattner5f311a72003-04-23 20:23:16 +0000752 FuncNames["lle_X_memcpy"] = lle_X_memcpy;
Chris Lattner957d62a2003-04-23 19:55:24 +0000753
Chris Lattner665ee882002-03-08 22:51:07 +0000754 FuncNames["lle_X_fopen"] = lle_X_fopen;
755 FuncNames["lle_X_fclose"] = lle_X_fclose;
Chris Lattner25f6f372002-11-08 19:10:26 +0000756 FuncNames["lle_X_feof"] = lle_X_feof;
Chris Lattner665ee882002-03-08 22:51:07 +0000757 FuncNames["lle_X_fread"] = lle_X_fread;
758 FuncNames["lle_X_fwrite"] = lle_X_fwrite;
759 FuncNames["lle_X_fgets"] = lle_X_fgets;
760 FuncNames["lle_X_fflush"] = lle_X_fflush;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000761 FuncNames["lle_X_fgetc"] = lle_X_getc;
Chris Lattner005cbce2002-10-02 21:12:13 +0000762 FuncNames["lle_X_getc"] = lle_X_getc;
Chris Lattnerf87a1982003-04-23 19:20:50 +0000763 FuncNames["lle_X__IO_getc"] = lle_X__IO_getc;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000764 FuncNames["lle_X_fputc"] = lle_X_fputc;
765 FuncNames["lle_X_ungetc"] = lle_X_ungetc;
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000766 FuncNames["lle_X_fprintf"] = lle_X_fprintf;
Chris Lattnera4479cd2002-11-07 19:33:50 +0000767 FuncNames["lle_X_freopen"] = lle_X_freopen;
Chris Lattner374344c2003-05-08 16:52:43 +0000768
769 FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
770 FuncNames["lle_X_llvm.va_end"] = llvm_va_end;
771 FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
Chris Lattner4721f132001-10-30 20:28:00 +0000772}