blob: b2c21e1ee1d04ba66a5a0dac4690f8aebd3a319d [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>
Misha Brukmanb8d15b22003-10-14 21:42:11 +000031#include <map>
Chris Lattner697954c2002-01-20 22:54:45 +000032using std::vector;
Chris Lattner7720c8e2001-09-10 04:50:17 +000033
Chris Lattnerb408b122002-03-29 03:57:15 +000034typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
35static std::map<const Function *, ExFunc> Functions;
Chris Lattner697954c2002-01-20 22:54:45 +000036static std::map<std::string, ExFunc> FuncNames;
Chris Lattner7720c8e2001-09-10 04:50:17 +000037
Chris Lattnere43db882001-10-27 04:15:57 +000038static Interpreter *TheInterpreter;
39
Chris Lattner7720c8e2001-09-10 04:50:17 +000040static char getTypeID(const Type *Ty) {
41 switch (Ty->getPrimitiveID()) {
42 case Type::VoidTyID: return 'V';
43 case Type::BoolTyID: return 'o';
44 case Type::UByteTyID: return 'B';
45 case Type::SByteTyID: return 'b';
46 case Type::UShortTyID: return 'S';
47 case Type::ShortTyID: return 's';
48 case Type::UIntTyID: return 'I';
49 case Type::IntTyID: return 'i';
50 case Type::ULongTyID: return 'L';
51 case Type::LongTyID: return 'l';
52 case Type::FloatTyID: return 'F';
53 case Type::DoubleTyID: return 'D';
54 case Type::PointerTyID: return 'P';
Chris Lattnerb408b122002-03-29 03:57:15 +000055 case Type::FunctionTyID: return 'M';
Chris Lattner7720c8e2001-09-10 04:50:17 +000056 case Type::StructTyID: return 'T';
57 case Type::ArrayTyID: return 'A';
58 case Type::OpaqueTyID: return 'O';
59 default: return 'U';
60 }
61}
62
Brian Gaeke58a6faa2003-10-10 17:03:10 +000063static ExFunc lookupFunction(const Function *F) {
Chris Lattner7720c8e2001-09-10 04:50:17 +000064 // Function not found, look it up... start by figuring out what the
65 // composite function name should be.
Chris Lattner697954c2002-01-20 22:54:45 +000066 std::string ExtName = "lle_";
Brian Gaeke58a6faa2003-10-10 17:03:10 +000067 const FunctionType *FT = F->getFunctionType();
68 for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
69 ExtName += getTypeID(FT->getContainedType(i));
70 ExtName += "_" + F->getName();
Chris Lattner7720c8e2001-09-10 04:50:17 +000071
Chris Lattner4721f132001-10-30 20:28:00 +000072 ExFunc FnPtr = FuncNames[ExtName];
73 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000074 FnPtr = (ExFunc)GetAddressOfSymbol(ExtName);
Chris Lattner4721f132001-10-30 20:28:00 +000075 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000076 FnPtr = FuncNames["lle_X_"+F->getName()];
Chris Lattner7720c8e2001-09-10 04:50:17 +000077 if (FnPtr == 0) // Try calling a generic function... if it exists...
Brian Gaeke58a6faa2003-10-10 17:03:10 +000078 FnPtr = (ExFunc)GetAddressOfSymbol(("lle_X_"+F->getName()).c_str());
Chris Lattner7720c8e2001-09-10 04:50:17 +000079 if (FnPtr != 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000080 Functions.insert(std::make_pair(F, FnPtr)); // Cache for later
Chris Lattner7720c8e2001-09-10 04:50:17 +000081 return FnPtr;
82}
83
Chris Lattnerda82ed52003-05-08 16:18:31 +000084GenericValue Interpreter::callExternalFunction(Function *M,
Chris Lattner44edb6b2003-05-14 14:21:30 +000085 const std::vector<GenericValue> &ArgVals) {
Chris Lattnere43db882001-10-27 04:15:57 +000086 TheInterpreter = this;
87
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000088 // Do a lookup to see if the function is in our cache... this should just be a
Misha Brukmand5d96b92003-10-10 17:42:19 +000089 // deferred annotation!
Chris Lattnerb408b122002-03-29 03:57:15 +000090 std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
91 ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
Chris Lattner7720c8e2001-09-10 04:50:17 +000092 if (Fn == 0) {
Chris Lattnerda82ed52003-05-08 16:18:31 +000093 std::cout << "Tried to execute an unknown external function: "
94 << M->getType()->getDescription() << " " << M->getName() << "\n";
Chris Lattner4721f132001-10-30 20:28:00 +000095 return GenericValue();
Chris Lattner7720c8e2001-09-10 04:50:17 +000096 }
97
98 // TODO: FIXME when types are not const!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000099 GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
100 ArgVals);
Chris Lattner4721f132001-10-30 20:28:00 +0000101 return Result;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000102}
103
104
105//===----------------------------------------------------------------------===//
Chris Lattnerb408b122002-03-29 03:57:15 +0000106// Functions "exported" to the running application...
Chris Lattner7720c8e2001-09-10 04:50:17 +0000107//
108extern "C" { // Don't add C++ manglings to llvm mangling :)
109
Chris Lattner005cbce2002-10-02 21:12:13 +0000110// void putchar(sbyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000111GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000112 std::cout << Args[0].SByteVal;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000113 return GenericValue();
114}
115
Chris Lattner005cbce2002-10-02 21:12:13 +0000116// int putchar(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000117GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000118 std::cout << ((char)Args[0].IntVal) << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000119 return Args[0];
120}
121
Chris Lattner005cbce2002-10-02 21:12:13 +0000122// void putchar(ubyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000123GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000124 std::cout << Args[0].SByteVal << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000125 return Args[0];
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000126}
127
Chris Lattner44edb6b2003-05-14 14:21:30 +0000128// void atexit(Function*)
129GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
130 assert(Args.size() == 1);
131 TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
132 GenericValue GV;
133 GV.IntVal = 0;
134 return GV;
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000135}
136
Chris Lattner005cbce2002-10-02 21:12:13 +0000137// void exit(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000138GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere43db882001-10-27 04:15:57 +0000139 TheInterpreter->exitCalled(Args[0]);
140 return GenericValue();
141}
142
Chris Lattner005cbce2002-10-02 21:12:13 +0000143// void abort(void)
Chris Lattner1ee34a52002-05-20 21:17:16 +0000144GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
145 std::cerr << "***PROGRAM ABORTED***!\n";
146 GenericValue GV;
147 GV.IntVal = 1;
148 TheInterpreter->exitCalled(GV);
149 return GenericValue();
150}
151
Chris Lattnerc2593162001-10-27 08:28:11 +0000152// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000153GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000154 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000155 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000156}
157
Chris Lattner957d62a2003-04-23 19:55:24 +0000158// void *calloc(uint, uint)
159GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
160 assert(Args.size() == 2 && "calloc expects two arguments!");
161 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
162}
163
Chris Lattnerc2593162001-10-27 08:28:11 +0000164// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000165GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000166 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000167 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000168 return GenericValue();
169}
170
Chris Lattner782b9392001-11-26 18:18:18 +0000171// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000172GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000173 assert(Args.size() == 1);
174 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000175 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000176 return GV;
177}
178
Chris Lattnerc2593162001-10-27 08:28:11 +0000179// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000180GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000181 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000182 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000183 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000184 return GV;
185}
186
Chris Lattner34dd24b2002-02-18 19:06:25 +0000187// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000188GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000189 assert(Args.size() == 1);
190 GenericValue GV;
191 GV.DoubleVal = exp(Args[0].DoubleVal);
192 return GV;
193}
194
Chris Lattnerc063d382001-11-06 21:52:18 +0000195// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000196GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000197 assert(Args.size() == 1);
198 GenericValue GV;
199 GV.DoubleVal = sqrt(Args[0].DoubleVal);
200 return GV;
201}
Chris Lattnerc2593162001-10-27 08:28:11 +0000202
Chris Lattner86790052001-11-06 22:53:25 +0000203// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000204GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000205 assert(Args.size() == 1);
206 GenericValue GV;
207 GV.DoubleVal = log(Args[0].DoubleVal);
208 return GV;
209}
210
Chris Lattner782b9392001-11-26 18:18:18 +0000211// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000212GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000213 assert(Args.size() == 1);
214 GenericValue GV;
215 GV.DoubleVal = floor(Args[0].DoubleVal);
216 return GV;
217}
218
Chris Lattner86790052001-11-06 22:53:25 +0000219// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000220GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000221 assert(Args.size() == 0);
222 GenericValue GV;
223 GV.DoubleVal = drand48();
224 return GV;
225}
226
Chris Lattner1b600142001-11-13 05:46:08 +0000227// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000228GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000229 assert(Args.size() == 0);
230 GenericValue GV;
231 GV.IntVal = lrand48();
232 return GV;
233}
234
235// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000236GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000237 assert(Args.size() == 1);
238 srand48(Args[0].IntVal);
239 return GenericValue();
240}
241
Chris Lattner782b9392001-11-26 18:18:18 +0000242// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000243GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000244 assert(Args.size() == 1);
245 srand(Args[0].UIntVal);
246 return GenericValue();
247}
Chris Lattner86790052001-11-06 22:53:25 +0000248
Chris Lattnerb1118742003-01-13 00:59:47 +0000249// int puts(const char*)
250GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
251 assert(Args.size() == 1);
252 GenericValue GV;
253 GV.IntVal = puts((char*)GVTOP(Args[0]));
254 return GV;
255}
256
Chris Lattnere7c6f722001-12-13 00:43:47 +0000257// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
258// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000259GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000260 char *OutputBuffer = (char *)GVTOP(Args[0]);
261 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000262 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000263
264 // printf should return # chars printed. This is completely incorrect, but
265 // close enough for now.
266 GenericValue GV; GV.IntVal = strlen(FmtStr);
267 while (1) {
268 switch (*FmtStr) {
269 case 0: return GV; // Null terminator...
270 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000271 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000272 break;
273 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000274 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
275 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000276 break;
277 }
278 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000279 char FmtBuf[100] = "", Buffer[1000] = "";
280 char *FB = FmtBuf;
281 *FB++ = *FmtStr++;
282 char Last = *FB++ = *FmtStr++;
283 unsigned HowLong = 0;
284 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
285 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
286 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
287 Last != 'p' && Last != 's' && Last != '%') {
288 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
289 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000290 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000291 *FB = 0;
292
293 switch (Last) {
294 case '%':
295 sprintf(Buffer, FmtBuf); break;
296 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000297 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000298 case 'd': case 'i':
299 case 'u': case 'o':
300 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000301 if (HowLong >= 1) {
Chris Lattner1543e402003-08-24 14:02:47 +0000302 if (HowLong == 1 &&
303 TheInterpreter->getModule().getPointerSize()==Module::Pointer64 &&
Chris Lattner7471c482003-04-25 18:28:44 +0000304 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000305 // Make sure we use %lld with a 64 bit argument because we might be
306 // compiling LLI on a 32 bit compiler.
307 unsigned Size = strlen(FmtBuf);
308 FmtBuf[Size] = FmtBuf[Size-1];
309 FmtBuf[Size+1] = 0;
310 FmtBuf[Size-1] = 'l';
311 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000312 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000313 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000314 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
315 case 'e': case 'E': case 'g': case 'G': case 'f':
316 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
317 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000318 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000319 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000320 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000321 default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000322 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000323 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000324 strcpy(OutputBuffer, Buffer);
325 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000326 }
Chris Lattner08845a22001-10-29 20:27:45 +0000327 break;
328 }
Chris Lattner08845a22001-10-29 20:27:45 +0000329 }
330}
331
Chris Lattnere7c6f722001-12-13 00:43:47 +0000332// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000333GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000334 char Buffer[10000];
335 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000336 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000337 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000338 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnerda82ed52003-05-08 16:18:31 +0000339 std::cout << Buffer;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000340 return GV;
341}
342
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000343static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
344 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
345 void *Arg6, void *Arg7, void *Arg8) {
346 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
347
348 // Loop over the format string, munging read values as appropriate (performs
Misha Brukman5560c9d2003-08-18 14:43:39 +0000349 // byteswaps as necessary).
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000350 unsigned ArgNo = 0;
351 while (*Fmt) {
352 if (*Fmt++ == '%') {
353 // Read any flag characters that may be present...
354 bool Suppress = false;
355 bool Half = false;
356 bool Long = false;
357 bool LongLong = false; // long long or long double
358
359 while (1) {
360 switch (*Fmt++) {
361 case '*': Suppress = true; break;
362 case 'a': /*Allocate = true;*/ break; // We don't need to track this
363 case 'h': Half = true; break;
364 case 'l': Long = true; break;
365 case 'q':
366 case 'L': LongLong = true; break;
367 default:
368 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
369 goto Out;
370 }
371 }
372 Out:
373
374 // Read the conversion character
375 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
376 unsigned Size = 0;
377 const Type *Ty = 0;
378
379 switch (Fmt[-1]) {
380 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
381 case 'd':
382 if (Long || LongLong) {
383 Size = 8; Ty = Type::ULongTy;
384 } else if (Half) {
385 Size = 4; Ty = Type::UShortTy;
386 } else {
387 Size = 4; Ty = Type::UIntTy;
388 }
389 break;
390
391 case 'e': case 'g': case 'E':
392 case 'f':
393 if (Long || LongLong) {
394 Size = 8; Ty = Type::DoubleTy;
395 } else {
396 Size = 4; Ty = Type::FloatTy;
397 }
398 break;
399
400 case 's': case 'c': case '[': // No byteswap needed
401 Size = 1;
402 Ty = Type::SByteTy;
403 break;
404
405 default: break;
406 }
407
408 if (Size) {
409 GenericValue GV;
410 void *Arg = Args[ArgNo++];
411 memcpy(&GV, Arg, Size);
412 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
413 }
414 }
415 }
416 }
417}
418
Chris Lattner665ee882002-03-08 22:51:07 +0000419// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000420GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000421 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
422
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000423 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000424 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000425 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000426
427 GenericValue GV;
428 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
429 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000430 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
431 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
432 return GV;
433}
434
435// int scanf(const char *format, ...);
436GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
437 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
438
439 char *Args[10];
440 for (unsigned i = 0; i < args.size(); ++i)
441 Args[i] = (char*)GVTOP(args[i]);
442
443 GenericValue GV;
444 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
445 Args[5], Args[6], Args[7], Args[8], Args[9]);
446 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
447 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000448 return GV;
449}
450
451
Chris Lattner295fe672002-01-23 21:38:07 +0000452// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000453GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000454 extern int clock(void);
455 GenericValue GV; GV.IntVal = clock();
456 return GV;
457}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000458
Chris Lattner957d62a2003-04-23 19:55:24 +0000459
460//===----------------------------------------------------------------------===//
461// String Functions...
462//===----------------------------------------------------------------------===//
463
464// int strcmp(const char *S1, const char *S2);
465GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
466 assert(Args.size() == 2);
467 GenericValue Ret;
468 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
469 return Ret;
470}
471
472// char *strcat(char *Dest, const char *src);
473GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
474 assert(Args.size() == 2);
475 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
476}
477
478// char *strcpy(char *Dest, const char *src);
479GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
480 assert(Args.size() == 2);
481 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
482}
483
484// long strlen(const char *src);
485GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
486 assert(Args.size() == 1);
487 GenericValue Ret;
488 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
489 return Ret;
490}
491
Brian Gaeke70975ee2003-09-05 18:42:01 +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 Lattnerc8cff9e2003-04-25 18:23:38 +0000498// char *__strdup(const char *src);
499GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
500 assert(Args.size() == 1);
501 return PTOGV(strdup((char*)GVTOP(Args[0])));
502}
503
Chris Lattner957d62a2003-04-23 19:55:24 +0000504// void *memset(void *S, int C, size_t N)
505GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
506 assert(Args.size() == 3);
507 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
508}
509
Chris Lattner5f311a72003-04-23 20:23:16 +0000510// void *memcpy(void *Dest, void *src, size_t Size);
511GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
512 assert(Args.size() == 3);
513 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
514 Args[2].UIntVal));
515}
Chris Lattner957d62a2003-04-23 19:55:24 +0000516
Chris Lattner665ee882002-03-08 22:51:07 +0000517//===----------------------------------------------------------------------===//
518// IO Functions...
519//===----------------------------------------------------------------------===//
520
Chris Lattner005cbce2002-10-02 21:12:13 +0000521// getFILE - Turn a pointer in the host address space into a legit pointer in
522// the interpreter address space. For the most part, this is an identity
523// transformation, but if the program refers to stdio, stderr, stdin then they
524// have pointers that are relative to the __iob array. If this is the case,
525// change the FILE into the REAL stdio stream.
526//
Chris Lattnerb1118742003-01-13 00:59:47 +0000527static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000528 static Module *LastMod = 0;
529 static PointerTy IOBBase = 0;
530 static unsigned FILESize;
531
Chris Lattnerfe11a972002-12-23 23:59:41 +0000532 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
533 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000534
535 // Check to see if the currently loaded module contains an __iob symbol...
536 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000537 SymbolTable &ST = M->getSymbolTable();
538 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
539 SymbolTable::VarMap &M = I->second;
540 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
541 J != E; ++J)
542 if (J->first == "__iob")
543 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
544 break;
545 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000546 }
547
Chris Lattnerfe11a972002-12-23 23:59:41 +0000548#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000549 // If we found an __iob symbol now, find out what the actual address it's
550 // held in is...
551 if (IOB) {
552 // Get the address the array lives in...
553 GlobalAddress *Address =
554 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
555 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
556
557 // Figure out how big each element of the array is...
558 const ArrayType *AT =
559 dyn_cast<ArrayType>(IOB->getType()->getElementType());
560 if (AT)
561 FILESize = TD.getTypeSize(AT->getElementType());
562 else
563 FILESize = 16*8; // Default size
564 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000565#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000566 }
567
568 // Check to see if this is a reference to __iob...
569 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000570 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000571 if (FDNum == 0)
572 return stdin;
573 else if (FDNum == 1)
574 return stdout;
575 else if (FDNum == 2)
576 return stderr;
577 }
578
579 return (FILE*)Ptr;
580}
581
582
Chris Lattner665ee882002-03-08 22:51:07 +0000583// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000584GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000585 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000586 return PTOGV(fopen((const char *)GVTOP(Args[0]),
587 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000588}
589
590// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000591GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000592 assert(Args.size() == 1);
593 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000594 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000595 return GV;
596}
597
Chris Lattner25f6f372002-11-08 19:10:26 +0000598// int feof(FILE *stream);
599GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
600 assert(Args.size() == 1);
601 GenericValue GV;
602
Chris Lattnerb1118742003-01-13 00:59:47 +0000603 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000604 return GV;
605}
606
Chris Lattner665ee882002-03-08 22:51:07 +0000607// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000608GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000609 assert(Args.size() == 4);
610 GenericValue GV;
611
Chris Lattnerb1118742003-01-13 00:59:47 +0000612 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
613 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000614 return GV;
615}
616
617// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000618GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000619 assert(Args.size() == 4);
620 GenericValue GV;
621
Chris Lattnerb1118742003-01-13 00:59:47 +0000622 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
623 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000624 return GV;
625}
626
627// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000628GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000629 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000630 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
631 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000632}
633
Chris Lattnera4479cd2002-11-07 19:33:50 +0000634// FILE *freopen(const char *path, const char *mode, FILE *stream);
635GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
636 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000637 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
638 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000639}
640
Chris Lattner665ee882002-03-08 22:51:07 +0000641// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000642GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000643 assert(Args.size() == 1);
644 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000645 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000646 return GV;
647}
648
649// int getc(FILE *stream);
650GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
651 assert(Args.size() == 1);
652 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000653 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000654 return GV;
655}
656
Chris Lattnerf87a1982003-04-23 19:20:50 +0000657// int _IO_getc(FILE *stream);
658GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
659 return lle_X_getc(F, Args);
660}
661
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000662// int fputc(int C, FILE *stream);
663GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
664 assert(Args.size() == 2);
665 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000666 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000667 return GV;
668}
669
670// int ungetc(int C, FILE *stream);
671GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
672 assert(Args.size() == 2);
673 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000674 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000675 return GV;
676}
677
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000678// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
679// useful.
680GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000681 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000682 char Buffer[10000];
683 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000684 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000685 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000686 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000687
Chris Lattnerb1118742003-01-13 00:59:47 +0000688 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000689 return GV;
690}
691
Chris Lattner374344c2003-05-08 16:52:43 +0000692//===----------------------------------------------------------------------===//
693// LLVM Intrinsic Functions...
694//===----------------------------------------------------------------------===//
695
Chris Lattner4c665492003-10-18 05:55:25 +0000696// <va_list> llvm.va_start() - Implement the va_start operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000697GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000698 assert(Args.size() == 0);
Chris Lattner374344c2003-05-08 16:52:43 +0000699 GenericValue Val;
700 Val.UIntVal = 0; // Start at the first '...' argument...
Chris Lattner4c665492003-10-18 05:55:25 +0000701 return Val;
Chris Lattner374344c2003-05-08 16:52:43 +0000702}
703
704// void llvm.va_end(<va_list> *) - Implement the va_end operation...
705GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
706 assert(Args.size() == 1);
707 return GenericValue(); // Noop!
708}
709
Chris Lattner4c665492003-10-18 05:55:25 +0000710// <va_list> llvm.va_copy(<va_list>) - Implement the va_copy operation...
Chris Lattner374344c2003-05-08 16:52:43 +0000711GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
Chris Lattner4c665492003-10-18 05:55:25 +0000712 assert(Args.size() == 1);
713 return Args[0];
Chris Lattner374344c2003-05-08 16:52:43 +0000714}
715
Chris Lattner7720c8e2001-09-10 04:50:17 +0000716} // End extern "C"
Chris Lattner4721f132001-10-30 20:28:00 +0000717
718
Chris Lattnerda82ed52003-05-08 16:18:31 +0000719void Interpreter::initializeExternalFunctions() {
Chris Lattner0f279b22001-11-03 10:15:32 +0000720 FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
721 FuncNames["lle_ii_putchar"] = lle_ii_putchar;
722 FuncNames["lle_VB_putchar"] = lle_VB_putchar;
Chris Lattner0f279b22001-11-03 10:15:32 +0000723 FuncNames["lle_X_exit"] = lle_X_exit;
Chris Lattner1ee34a52002-05-20 21:17:16 +0000724 FuncNames["lle_X_abort"] = lle_X_abort;
Chris Lattner0f279b22001-11-03 10:15:32 +0000725 FuncNames["lle_X_malloc"] = lle_X_malloc;
Chris Lattner957d62a2003-04-23 19:55:24 +0000726 FuncNames["lle_X_calloc"] = lle_X_calloc;
Chris Lattner0f279b22001-11-03 10:15:32 +0000727 FuncNames["lle_X_free"] = lle_X_free;
Chris Lattner782b9392001-11-26 18:18:18 +0000728 FuncNames["lle_X_atoi"] = lle_X_atoi;
Chris Lattner0f279b22001-11-03 10:15:32 +0000729 FuncNames["lle_X_pow"] = lle_X_pow;
Chris Lattner34dd24b2002-02-18 19:06:25 +0000730 FuncNames["lle_X_exp"] = lle_X_exp;
Chris Lattner1b600142001-11-13 05:46:08 +0000731 FuncNames["lle_X_log"] = lle_X_log;
Chris Lattner782b9392001-11-26 18:18:18 +0000732 FuncNames["lle_X_floor"] = lle_X_floor;
733 FuncNames["lle_X_srand"] = lle_X_srand;
Chris Lattner1b600142001-11-13 05:46:08 +0000734 FuncNames["lle_X_drand48"] = lle_X_drand48;
735 FuncNames["lle_X_srand48"] = lle_X_srand48;
736 FuncNames["lle_X_lrand48"] = lle_X_lrand48;
Chris Lattnerc063d382001-11-06 21:52:18 +0000737 FuncNames["lle_X_sqrt"] = lle_X_sqrt;
Chris Lattnerb1118742003-01-13 00:59:47 +0000738 FuncNames["lle_X_puts"] = lle_X_puts;
Chris Lattner0f279b22001-11-03 10:15:32 +0000739 FuncNames["lle_X_printf"] = lle_X_printf;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000740 FuncNames["lle_X_sprintf"] = lle_X_sprintf;
Chris Lattner665ee882002-03-08 22:51:07 +0000741 FuncNames["lle_X_sscanf"] = lle_X_sscanf;
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000742 FuncNames["lle_X_scanf"] = lle_X_scanf;
Chris Lattner295fe672002-01-23 21:38:07 +0000743 FuncNames["lle_i_clock"] = lle_i_clock;
Chris Lattner957d62a2003-04-23 19:55:24 +0000744
745 FuncNames["lle_X_strcmp"] = lle_X_strcmp;
746 FuncNames["lle_X_strcat"] = lle_X_strcat;
747 FuncNames["lle_X_strcpy"] = lle_X_strcpy;
748 FuncNames["lle_X_strlen"] = lle_X_strlen;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000749 FuncNames["lle_X___strdup"] = lle_X___strdup;
Chris Lattner957d62a2003-04-23 19:55:24 +0000750 FuncNames["lle_X_memset"] = lle_X_memset;
Chris Lattner5f311a72003-04-23 20:23:16 +0000751 FuncNames["lle_X_memcpy"] = lle_X_memcpy;
Chris Lattner957d62a2003-04-23 19:55:24 +0000752
Chris Lattner665ee882002-03-08 22:51:07 +0000753 FuncNames["lle_X_fopen"] = lle_X_fopen;
754 FuncNames["lle_X_fclose"] = lle_X_fclose;
Chris Lattner25f6f372002-11-08 19:10:26 +0000755 FuncNames["lle_X_feof"] = lle_X_feof;
Chris Lattner665ee882002-03-08 22:51:07 +0000756 FuncNames["lle_X_fread"] = lle_X_fread;
757 FuncNames["lle_X_fwrite"] = lle_X_fwrite;
758 FuncNames["lle_X_fgets"] = lle_X_fgets;
759 FuncNames["lle_X_fflush"] = lle_X_fflush;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000760 FuncNames["lle_X_fgetc"] = lle_X_getc;
Chris Lattner005cbce2002-10-02 21:12:13 +0000761 FuncNames["lle_X_getc"] = lle_X_getc;
Chris Lattnerf87a1982003-04-23 19:20:50 +0000762 FuncNames["lle_X__IO_getc"] = lle_X__IO_getc;
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000763 FuncNames["lle_X_fputc"] = lle_X_fputc;
764 FuncNames["lle_X_ungetc"] = lle_X_ungetc;
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000765 FuncNames["lle_X_fprintf"] = lle_X_fprintf;
Chris Lattnera4479cd2002-11-07 19:33:50 +0000766 FuncNames["lle_X_freopen"] = lle_X_freopen;
Chris Lattner374344c2003-05-08 16:52:43 +0000767
768 FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
769 FuncNames["lle_X_llvm.va_end"] = llvm_va_end;
770 FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
Chris Lattner4721f132001-10-30 20:28:00 +0000771}