blob: ecf19c2f8d51726673302f419fd2e31f687719ce [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"
23#include "llvm/DerivedTypes.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000024#include "llvm/Module.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000025#include "llvm/SymbolTable.h"
26#include "llvm/Target/TargetData.h"
Misha Brukmanb8d15b22003-10-14 21:42:11 +000027#include "Support/DynamicLinker.h"
John Criswell7a73b802003-06-30 21:59:07 +000028#include "Config/dlfcn.h"
29#include "Config/link.h"
Brian Gaeke70337982003-06-23 19:41:55 +000030#include <cmath>
Brian Gaekeb56a6bc2003-11-05 01:18:49 +000031#include <csignal>
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) {
Brian Gaekeb56a6bc2003-11-05 01:18:49 +0000146 raise (SIGABRT);
Chris Lattner1ee34a52002-05-20 21:17:16 +0000147 return GenericValue();
148}
149
Chris Lattnerc2593162001-10-27 08:28:11 +0000150// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000151GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000152 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000153 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000154}
155
Chris Lattner957d62a2003-04-23 19:55:24 +0000156// void *calloc(uint, uint)
157GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
158 assert(Args.size() == 2 && "calloc expects two arguments!");
159 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
160}
161
Chris Lattnerc2593162001-10-27 08:28:11 +0000162// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000163GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000164 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000165 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000166 return GenericValue();
167}
168
Chris Lattner782b9392001-11-26 18:18:18 +0000169// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000170GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000171 assert(Args.size() == 1);
172 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000173 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000174 return GV;
175}
176
Chris Lattnerc2593162001-10-27 08:28:11 +0000177// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000178GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000179 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000180 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000181 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000182 return GV;
183}
184
Chris Lattner34dd24b2002-02-18 19:06:25 +0000185// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000186GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000187 assert(Args.size() == 1);
188 GenericValue GV;
189 GV.DoubleVal = exp(Args[0].DoubleVal);
190 return GV;
191}
192
Chris Lattnerc063d382001-11-06 21:52:18 +0000193// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000194GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000195 assert(Args.size() == 1);
196 GenericValue GV;
197 GV.DoubleVal = sqrt(Args[0].DoubleVal);
198 return GV;
199}
Chris Lattnerc2593162001-10-27 08:28:11 +0000200
Chris Lattner86790052001-11-06 22:53:25 +0000201// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000202GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000203 assert(Args.size() == 1);
204 GenericValue GV;
205 GV.DoubleVal = log(Args[0].DoubleVal);
206 return GV;
207}
208
Chris Lattner782b9392001-11-26 18:18:18 +0000209// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000210GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000211 assert(Args.size() == 1);
212 GenericValue GV;
213 GV.DoubleVal = floor(Args[0].DoubleVal);
214 return GV;
215}
216
Chris Lattner86790052001-11-06 22:53:25 +0000217// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000218GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000219 assert(Args.size() == 0);
220 GenericValue GV;
221 GV.DoubleVal = drand48();
222 return GV;
223}
224
Chris Lattner1b600142001-11-13 05:46:08 +0000225// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000226GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000227 assert(Args.size() == 0);
228 GenericValue GV;
229 GV.IntVal = lrand48();
230 return GV;
231}
232
233// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000234GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000235 assert(Args.size() == 1);
236 srand48(Args[0].IntVal);
237 return GenericValue();
238}
239
Chris Lattner782b9392001-11-26 18:18:18 +0000240// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000241GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000242 assert(Args.size() == 1);
243 srand(Args[0].UIntVal);
244 return GenericValue();
245}
Chris Lattner86790052001-11-06 22:53:25 +0000246
Chris Lattnerb1118742003-01-13 00:59:47 +0000247// int puts(const char*)
248GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
249 assert(Args.size() == 1);
250 GenericValue GV;
251 GV.IntVal = puts((char*)GVTOP(Args[0]));
252 return GV;
253}
254
Chris Lattnere7c6f722001-12-13 00:43:47 +0000255// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
256// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000257GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000258 char *OutputBuffer = (char *)GVTOP(Args[0]);
259 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000260 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000261
262 // printf should return # chars printed. This is completely incorrect, but
263 // close enough for now.
264 GenericValue GV; GV.IntVal = strlen(FmtStr);
265 while (1) {
266 switch (*FmtStr) {
267 case 0: return GV; // Null terminator...
268 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000269 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000270 break;
271 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000272 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
273 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000274 break;
275 }
276 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000277 char FmtBuf[100] = "", Buffer[1000] = "";
278 char *FB = FmtBuf;
279 *FB++ = *FmtStr++;
280 char Last = *FB++ = *FmtStr++;
281 unsigned HowLong = 0;
282 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
283 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
284 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
285 Last != 'p' && Last != 's' && Last != '%') {
286 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
287 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000288 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000289 *FB = 0;
290
291 switch (Last) {
292 case '%':
293 sprintf(Buffer, FmtBuf); break;
294 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000295 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000296 case 'd': case 'i':
297 case 'u': case 'o':
298 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000299 if (HowLong >= 1) {
Chris Lattner1543e402003-08-24 14:02:47 +0000300 if (HowLong == 1 &&
301 TheInterpreter->getModule().getPointerSize()==Module::Pointer64 &&
Chris Lattner7471c482003-04-25 18:28:44 +0000302 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000303 // Make sure we use %lld with a 64 bit argument because we might be
304 // compiling LLI on a 32 bit compiler.
305 unsigned Size = strlen(FmtBuf);
306 FmtBuf[Size] = FmtBuf[Size-1];
307 FmtBuf[Size+1] = 0;
308 FmtBuf[Size-1] = 'l';
309 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000310 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000311 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000312 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
313 case 'e': case 'E': case 'g': case 'G': case 'f':
314 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
315 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000316 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000317 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000318 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000319 default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000320 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000321 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000322 strcpy(OutputBuffer, Buffer);
323 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000324 }
Chris Lattner08845a22001-10-29 20:27:45 +0000325 break;
326 }
Chris Lattner08845a22001-10-29 20:27:45 +0000327 }
328}
329
Chris Lattnere7c6f722001-12-13 00:43:47 +0000330// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000331GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000332 char Buffer[10000];
333 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000334 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000335 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000336 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnerda82ed52003-05-08 16:18:31 +0000337 std::cout << Buffer;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000338 return GV;
339}
340
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000341static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
342 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
343 void *Arg6, void *Arg7, void *Arg8) {
344 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
345
346 // Loop over the format string, munging read values as appropriate (performs
Misha Brukman5560c9d2003-08-18 14:43:39 +0000347 // byteswaps as necessary).
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000348 unsigned ArgNo = 0;
349 while (*Fmt) {
350 if (*Fmt++ == '%') {
351 // Read any flag characters that may be present...
352 bool Suppress = false;
353 bool Half = false;
354 bool Long = false;
355 bool LongLong = false; // long long or long double
356
357 while (1) {
358 switch (*Fmt++) {
359 case '*': Suppress = true; break;
360 case 'a': /*Allocate = true;*/ break; // We don't need to track this
361 case 'h': Half = true; break;
362 case 'l': Long = true; break;
363 case 'q':
364 case 'L': LongLong = true; break;
365 default:
366 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
367 goto Out;
368 }
369 }
370 Out:
371
372 // Read the conversion character
373 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
374 unsigned Size = 0;
375 const Type *Ty = 0;
376
377 switch (Fmt[-1]) {
378 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
379 case 'd':
380 if (Long || LongLong) {
381 Size = 8; Ty = Type::ULongTy;
382 } else if (Half) {
383 Size = 4; Ty = Type::UShortTy;
384 } else {
385 Size = 4; Ty = Type::UIntTy;
386 }
387 break;
388
389 case 'e': case 'g': case 'E':
390 case 'f':
391 if (Long || LongLong) {
392 Size = 8; Ty = Type::DoubleTy;
393 } else {
394 Size = 4; Ty = Type::FloatTy;
395 }
396 break;
397
398 case 's': case 'c': case '[': // No byteswap needed
399 Size = 1;
400 Ty = Type::SByteTy;
401 break;
402
403 default: break;
404 }
405
406 if (Size) {
407 GenericValue GV;
408 void *Arg = Args[ArgNo++];
409 memcpy(&GV, Arg, Size);
410 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
411 }
412 }
413 }
414 }
415}
416
Chris Lattner665ee882002-03-08 22:51:07 +0000417// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000418GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000419 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
420
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000421 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000422 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000423 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000424
425 GenericValue GV;
426 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
427 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000428 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
429 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
430 return GV;
431}
432
433// int scanf(const char *format, ...);
434GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
435 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
436
437 char *Args[10];
438 for (unsigned i = 0; i < args.size(); ++i)
439 Args[i] = (char*)GVTOP(args[i]);
440
441 GenericValue GV;
442 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
443 Args[5], Args[6], Args[7], Args[8], Args[9]);
444 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
445 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000446 return GV;
447}
448
449
Chris Lattner295fe672002-01-23 21:38:07 +0000450// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000451GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000452 extern int clock(void);
453 GenericValue GV; GV.IntVal = clock();
454 return GV;
455}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000456
Chris Lattner957d62a2003-04-23 19:55:24 +0000457
458//===----------------------------------------------------------------------===//
459// String Functions...
460//===----------------------------------------------------------------------===//
461
462// int strcmp(const char *S1, const char *S2);
463GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
464 assert(Args.size() == 2);
465 GenericValue Ret;
466 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
467 return Ret;
468}
469
470// char *strcat(char *Dest, const char *src);
471GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
472 assert(Args.size() == 2);
473 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
474}
475
476// char *strcpy(char *Dest, const char *src);
477GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
478 assert(Args.size() == 2);
479 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
480}
481
482// long strlen(const char *src);
483GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
484 assert(Args.size() == 1);
485 GenericValue Ret;
486 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
487 return Ret;
488}
489
Brian Gaeke70975ee2003-09-05 18:42:01 +0000490// char *strdup(const char *src);
491GenericValue lle_X_strdup(FunctionType *M, const vector<GenericValue> &Args) {
492 assert(Args.size() == 1);
493 return PTOGV(strdup((char*)GVTOP(Args[0])));
494}
495
Chris Lattnerc8cff9e2003-04-25 18:23:38 +0000496// char *__strdup(const char *src);
497GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
498 assert(Args.size() == 1);
499 return PTOGV(strdup((char*)GVTOP(Args[0])));
500}
501
Chris Lattner957d62a2003-04-23 19:55:24 +0000502// void *memset(void *S, int C, size_t N)
503GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
504 assert(Args.size() == 3);
505 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
506}
507
Chris Lattner5f311a72003-04-23 20:23:16 +0000508// void *memcpy(void *Dest, void *src, size_t Size);
509GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
510 assert(Args.size() == 3);
511 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
512 Args[2].UIntVal));
513}
Chris Lattner957d62a2003-04-23 19:55:24 +0000514
Chris Lattner665ee882002-03-08 22:51:07 +0000515//===----------------------------------------------------------------------===//
516// IO Functions...
517//===----------------------------------------------------------------------===//
518
Chris Lattner005cbce2002-10-02 21:12:13 +0000519// getFILE - Turn a pointer in the host address space into a legit pointer in
520// the interpreter address space. For the most part, this is an identity
521// transformation, but if the program refers to stdio, stderr, stdin then they
522// have pointers that are relative to the __iob array. If this is the case,
523// change the FILE into the REAL stdio stream.
524//
Chris Lattnerb1118742003-01-13 00:59:47 +0000525static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000526 static Module *LastMod = 0;
527 static PointerTy IOBBase = 0;
528 static unsigned FILESize;
529
Chris Lattnerfe11a972002-12-23 23:59:41 +0000530 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
531 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000532
533 // Check to see if the currently loaded module contains an __iob symbol...
534 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000535 SymbolTable &ST = M->getSymbolTable();
536 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
537 SymbolTable::VarMap &M = I->second;
538 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
539 J != E; ++J)
540 if (J->first == "__iob")
541 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
542 break;
543 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000544 }
545
Chris Lattnerfe11a972002-12-23 23:59:41 +0000546#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000547 // If we found an __iob symbol now, find out what the actual address it's
548 // held in is...
549 if (IOB) {
550 // Get the address the array lives in...
551 GlobalAddress *Address =
552 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
553 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
554
555 // Figure out how big each element of the array is...
556 const ArrayType *AT =
557 dyn_cast<ArrayType>(IOB->getType()->getElementType());
558 if (AT)
559 FILESize = TD.getTypeSize(AT->getElementType());
560 else
561 FILESize = 16*8; // Default size
562 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000563#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000564 }
565
566 // Check to see if this is a reference to __iob...
567 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000568 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000569 if (FDNum == 0)
570 return stdin;
571 else if (FDNum == 1)
572 return stdout;
573 else if (FDNum == 2)
574 return stderr;
575 }
576
577 return (FILE*)Ptr;
578}
579
580
Chris Lattner665ee882002-03-08 22:51:07 +0000581// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000582GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000583 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000584 return PTOGV(fopen((const char *)GVTOP(Args[0]),
585 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000586}
587
588// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000589GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000590 assert(Args.size() == 1);
591 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000592 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000593 return GV;
594}
595
Chris Lattner25f6f372002-11-08 19:10:26 +0000596// int feof(FILE *stream);
597GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
598 assert(Args.size() == 1);
599 GenericValue GV;
600
Chris Lattnerb1118742003-01-13 00:59:47 +0000601 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000602 return GV;
603}
604
Chris Lattner665ee882002-03-08 22:51:07 +0000605// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000606GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000607 assert(Args.size() == 4);
608 GenericValue GV;
609
Chris Lattnerb1118742003-01-13 00:59:47 +0000610 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
611 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000612 return GV;
613}
614
615// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000616GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000617 assert(Args.size() == 4);
618 GenericValue GV;
619
Chris Lattnerb1118742003-01-13 00:59:47 +0000620 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
621 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000622 return GV;
623}
624
625// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000626GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000627 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000628 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
629 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000630}
631
Chris Lattnera4479cd2002-11-07 19:33:50 +0000632// FILE *freopen(const char *path, const char *mode, FILE *stream);
633GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
634 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000635 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
636 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000637}
638
Chris Lattner665ee882002-03-08 22:51:07 +0000639// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000640GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000641 assert(Args.size() == 1);
642 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000643 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000644 return GV;
645}
646
647// int getc(FILE *stream);
648GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
649 assert(Args.size() == 1);
650 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000651 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000652 return GV;
653}
654
Chris Lattnerf87a1982003-04-23 19:20:50 +0000655// int _IO_getc(FILE *stream);
656GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
657 return lle_X_getc(F, Args);
658}
659
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000660// int fputc(int C, FILE *stream);
661GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
662 assert(Args.size() == 2);
663 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000664 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000665 return GV;
666}
667
668// int ungetc(int C, FILE *stream);
669GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
670 assert(Args.size() == 2);
671 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000672 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000673 return GV;
674}
675
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000676// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
677// useful.
678GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000679 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000680 char Buffer[10000];
681 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000682 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000683 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000684 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000685
Chris Lattnerb1118742003-01-13 00:59:47 +0000686 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000687 return GV;
688}
689
Chris Lattner374344c2003-05-08 16:52:43 +0000690//===----------------------------------------------------------------------===//
691// LLVM Intrinsic Functions...
692//===----------------------------------------------------------------------===//
693
Chris Lattner4c665492003-10-18 05:55:25 +0000694// <va_list> llvm.va_start() - Implement the va_start operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000695GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000696 assert(Args.size() == 0);
Chris Lattner374344c2003-05-08 16:52:43 +0000697 GenericValue Val;
698 Val.UIntVal = 0; // Start at the first '...' argument...
Chris Lattner4c665492003-10-18 05:55:25 +0000699 return Val;
Chris Lattner374344c2003-05-08 16:52:43 +0000700}
701
702// void llvm.va_end(<va_list> *) - Implement the va_end operation...
703GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
704 assert(Args.size() == 1);
705 return GenericValue(); // Noop!
706}
707
Chris Lattner4c665492003-10-18 05:55:25 +0000708// <va_list> llvm.va_copy(<va_list>) - Implement the va_copy operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000709GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000710 assert(Args.size() == 1);
711 return Args[0];
Chris Lattner374344c2003-05-08 16:52:43 +0000712}
713
Chris Lattner7720c8e2001-09-10 04:50:17 +0000714} // End extern "C"
Chris Lattner4721f132001-10-30 20:28:00 +0000715
716
Chris Lattnerda82ed52003-05-08 16:18:31 +0000717void Interpreter::initializeExternalFunctions() {
Chris Lattner0f279b22001-11-03 10:15:32 +0000718 FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
719 FuncNames["lle_ii_putchar"] = lle_ii_putchar;
720 FuncNames["lle_VB_putchar"] = lle_VB_putchar;
Chris Lattner0f279b22001-11-03 10:15:32 +0000721 FuncNames["lle_X_exit"] = lle_X_exit;
Chris Lattner1ee34a52002-05-20 21:17:16 +0000722 FuncNames["lle_X_abort"] = lle_X_abort;
Chris Lattner0f279b22001-11-03 10:15:32 +0000723 FuncNames["lle_X_malloc"] = lle_X_malloc;
Chris Lattner957d62a2003-04-23 19:55:24 +0000724 FuncNames["lle_X_calloc"] = lle_X_calloc;
Chris Lattner0f279b22001-11-03 10:15:32 +0000725 FuncNames["lle_X_free"] = lle_X_free;
Chris Lattner782b9392001-11-26 18:18:18 +0000726 FuncNames["lle_X_atoi"] = lle_X_atoi;
Chris Lattner0f279b22001-11-03 10:15:32 +0000727 FuncNames["lle_X_pow"] = lle_X_pow;
Chris Lattner34dd24b2002-02-18 19:06:25 +0000728 FuncNames["lle_X_exp"] = lle_X_exp;
Chris Lattner1b600142001-11-13 05:46:08 +0000729 FuncNames["lle_X_log"] = lle_X_log;
Chris Lattner782b9392001-11-26 18:18:18 +0000730 FuncNames["lle_X_floor"] = lle_X_floor;
731 FuncNames["lle_X_srand"] = lle_X_srand;
Chris Lattner1b600142001-11-13 05:46:08 +0000732 FuncNames["lle_X_drand48"] = lle_X_drand48;
733 FuncNames["lle_X_srand48"] = lle_X_srand48;
734 FuncNames["lle_X_lrand48"] = lle_X_lrand48;
Chris Lattnerc063d382001-11-06 21:52:18 +0000735 FuncNames["lle_X_sqrt"] = lle_X_sqrt;
Chris Lattnerb1118742003-01-13 00:59:47 +0000736 FuncNames["lle_X_puts"] = lle_X_puts;
Chris Lattner0f279b22001-11-03 10:15:32 +0000737 FuncNames["lle_X_printf"] = lle_X_printf;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000738 FuncNames["lle_X_sprintf"] = lle_X_sprintf;
Chris Lattner665ee882002-03-08 22:51:07 +0000739 FuncNames["lle_X_sscanf"] = lle_X_sscanf;
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000740 FuncNames["lle_X_scanf"] = lle_X_scanf;
Chris Lattner295fe672002-01-23 21:38:07 +0000741 FuncNames["lle_i_clock"] = lle_i_clock;
Chris Lattner957d62a2003-04-23 19:55:24 +0000742
743 FuncNames["lle_X_strcmp"] = lle_X_strcmp;
744 FuncNames["lle_X_strcat"] = lle_X_strcat;
745 FuncNames["lle_X_strcpy"] = lle_X_strcpy;
746 FuncNames["lle_X_strlen"] = lle_X_strlen;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000747 FuncNames["lle_X___strdup"] = lle_X___strdup;
Chris Lattner957d62a2003-04-23 19:55:24 +0000748 FuncNames["lle_X_memset"] = lle_X_memset;
Chris Lattner5f311a72003-04-23 20:23:16 +0000749 FuncNames["lle_X_memcpy"] = lle_X_memcpy;
Chris Lattner957d62a2003-04-23 19:55:24 +0000750
Chris Lattner665ee882002-03-08 22:51:07 +0000751 FuncNames["lle_X_fopen"] = lle_X_fopen;
752 FuncNames["lle_X_fclose"] = lle_X_fclose;
Chris Lattner25f6f372002-11-08 19:10:26 +0000753 FuncNames["lle_X_feof"] = lle_X_feof;
Chris Lattner665ee882002-03-08 22:51:07 +0000754 FuncNames["lle_X_fread"] = lle_X_fread;
755 FuncNames["lle_X_fwrite"] = lle_X_fwrite;
756 FuncNames["lle_X_fgets"] = lle_X_fgets;
757 FuncNames["lle_X_fflush"] = lle_X_fflush;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000758 FuncNames["lle_X_fgetc"] = lle_X_getc;
Chris Lattner005cbce2002-10-02 21:12:13 +0000759 FuncNames["lle_X_getc"] = lle_X_getc;
Chris Lattnerf87a1982003-04-23 19:20:50 +0000760 FuncNames["lle_X__IO_getc"] = lle_X__IO_getc;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000761 FuncNames["lle_X_fputc"] = lle_X_fputc;
762 FuncNames["lle_X_ungetc"] = lle_X_ungetc;
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000763 FuncNames["lle_X_fprintf"] = lle_X_fprintf;
Chris Lattnera4479cd2002-11-07 19:33:50 +0000764 FuncNames["lle_X_freopen"] = lle_X_freopen;
Chris Lattner374344c2003-05-08 16:52:43 +0000765
766 FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
767 FuncNames["lle_X_llvm.va_end"] = llvm_va_end;
768 FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
Chris Lattner4721f132001-10-30 20:28:00 +0000769}