blob: a7814397a2b80e6d8c06d7b015ea3571563526ac [file] [log] [blame]
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001//===-- ExternalFunctions.cpp - Implement External Functions --------------===//
Chris Lattner7720c8e2001-09-10 04:50:17 +00002//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00003// This file contains both code to deal with invoking "external" functions, but
4// also contains code that implements "exported" external functions.
Chris Lattner7720c8e2001-09-10 04:50:17 +00005//
Brian Gaeke58a6faa2003-10-10 17:03:10 +00006// External functions in the interpreter are implemented by
7// using the system's dynamic loader to look up the address of the function
8// we want to invoke. If a function is found, then one of the
9// many lle_* wrapper functions in this file will translate its arguments from
10// GenericValues to the types the function is actually expecting, before the
11// function is called.
Chris Lattner7720c8e2001-09-10 04:50:17 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "Interpreter.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000016#include "ExecutionAnnotations.h"
Chris Lattnerfe11a972002-12-23 23:59:41 +000017#include "llvm/Module.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000018#include "llvm/DerivedTypes.h"
Chris Lattner005cbce2002-10-02 21:12:13 +000019#include "llvm/SymbolTable.h"
20#include "llvm/Target/TargetData.h"
Chris Lattner7720c8e2001-09-10 04:50:17 +000021#include <map>
John Criswell7a73b802003-06-30 21:59:07 +000022#include "Config/dlfcn.h"
23#include "Config/link.h"
Brian Gaeke70337982003-06-23 19:41:55 +000024#include <cmath>
John Criswell7a73b802003-06-30 21:59:07 +000025#include "Config/stdio.h"
Brian Gaeke58a6faa2003-10-10 17:03:10 +000026#include "Support/DynamicLinker.h"
Chris Lattner697954c2002-01-20 22:54:45 +000027using std::vector;
Chris Lattner7720c8e2001-09-10 04:50:17 +000028
Chris Lattnerb408b122002-03-29 03:57:15 +000029typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
30static std::map<const Function *, ExFunc> Functions;
Chris Lattner697954c2002-01-20 22:54:45 +000031static std::map<std::string, ExFunc> FuncNames;
Chris Lattner7720c8e2001-09-10 04:50:17 +000032
Chris Lattnere43db882001-10-27 04:15:57 +000033static Interpreter *TheInterpreter;
34
Chris Lattner7720c8e2001-09-10 04:50:17 +000035static char getTypeID(const Type *Ty) {
36 switch (Ty->getPrimitiveID()) {
37 case Type::VoidTyID: return 'V';
38 case Type::BoolTyID: return 'o';
39 case Type::UByteTyID: return 'B';
40 case Type::SByteTyID: return 'b';
41 case Type::UShortTyID: return 'S';
42 case Type::ShortTyID: return 's';
43 case Type::UIntTyID: return 'I';
44 case Type::IntTyID: return 'i';
45 case Type::ULongTyID: return 'L';
46 case Type::LongTyID: return 'l';
47 case Type::FloatTyID: return 'F';
48 case Type::DoubleTyID: return 'D';
49 case Type::PointerTyID: return 'P';
Chris Lattnerb408b122002-03-29 03:57:15 +000050 case Type::FunctionTyID: return 'M';
Chris Lattner7720c8e2001-09-10 04:50:17 +000051 case Type::StructTyID: return 'T';
52 case Type::ArrayTyID: return 'A';
53 case Type::OpaqueTyID: return 'O';
54 default: return 'U';
55 }
56}
57
Brian Gaeke58a6faa2003-10-10 17:03:10 +000058static ExFunc lookupFunction(const Function *F) {
Chris Lattner7720c8e2001-09-10 04:50:17 +000059 // Function not found, look it up... start by figuring out what the
60 // composite function name should be.
Chris Lattner697954c2002-01-20 22:54:45 +000061 std::string ExtName = "lle_";
Brian Gaeke58a6faa2003-10-10 17:03:10 +000062 const FunctionType *FT = F->getFunctionType();
63 for (unsigned i = 0, e = FT->getNumContainedTypes(); i != e; ++i)
64 ExtName += getTypeID(FT->getContainedType(i));
65 ExtName += "_" + F->getName();
Chris Lattner7720c8e2001-09-10 04:50:17 +000066
Chris Lattner4721f132001-10-30 20:28:00 +000067 ExFunc FnPtr = FuncNames[ExtName];
68 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000069 FnPtr = (ExFunc)GetAddressOfSymbol(ExtName);
Chris Lattner4721f132001-10-30 20:28:00 +000070 if (FnPtr == 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000071 FnPtr = FuncNames["lle_X_"+F->getName()];
Chris Lattner7720c8e2001-09-10 04:50:17 +000072 if (FnPtr == 0) // Try calling a generic function... if it exists...
Brian Gaeke58a6faa2003-10-10 17:03:10 +000073 FnPtr = (ExFunc)GetAddressOfSymbol(("lle_X_"+F->getName()).c_str());
Chris Lattner7720c8e2001-09-10 04:50:17 +000074 if (FnPtr != 0)
Brian Gaeke58a6faa2003-10-10 17:03:10 +000075 Functions.insert(std::make_pair(F, FnPtr)); // Cache for later
Chris Lattner7720c8e2001-09-10 04:50:17 +000076 return FnPtr;
77}
78
Chris Lattnerda82ed52003-05-08 16:18:31 +000079GenericValue Interpreter::callExternalFunction(Function *M,
Chris Lattner44edb6b2003-05-14 14:21:30 +000080 const std::vector<GenericValue> &ArgVals) {
Chris Lattnere43db882001-10-27 04:15:57 +000081 TheInterpreter = this;
82
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000083 // Do a lookup to see if the function is in our cache... this should just be a
Chris Lattner7720c8e2001-09-10 04:50:17 +000084 // defered annotation!
Chris Lattnerb408b122002-03-29 03:57:15 +000085 std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
86 ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
Chris Lattner7720c8e2001-09-10 04:50:17 +000087 if (Fn == 0) {
Chris Lattnerda82ed52003-05-08 16:18:31 +000088 std::cout << "Tried to execute an unknown external function: "
89 << M->getType()->getDescription() << " " << M->getName() << "\n";
Chris Lattner4721f132001-10-30 20:28:00 +000090 return GenericValue();
Chris Lattner7720c8e2001-09-10 04:50:17 +000091 }
92
93 // TODO: FIXME when types are not const!
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000094 GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),
95 ArgVals);
Chris Lattner4721f132001-10-30 20:28:00 +000096 return Result;
Chris Lattner7720c8e2001-09-10 04:50:17 +000097}
98
99
100//===----------------------------------------------------------------------===//
Chris Lattnerb408b122002-03-29 03:57:15 +0000101// Functions "exported" to the running application...
Chris Lattner7720c8e2001-09-10 04:50:17 +0000102//
103extern "C" { // Don't add C++ manglings to llvm mangling :)
104
Chris Lattner005cbce2002-10-02 21:12:13 +0000105// void putchar(sbyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000106GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000107 std::cout << Args[0].SByteVal;
Chris Lattner7720c8e2001-09-10 04:50:17 +0000108 return GenericValue();
109}
110
Chris Lattner005cbce2002-10-02 21:12:13 +0000111// int putchar(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000112GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000113 std::cout << ((char)Args[0].IntVal) << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000114 return Args[0];
115}
116
Chris Lattner005cbce2002-10-02 21:12:13 +0000117// void putchar(ubyte)
Chris Lattnerb408b122002-03-29 03:57:15 +0000118GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerda82ed52003-05-08 16:18:31 +0000119 std::cout << Args[0].SByteVal << std::flush;
Chris Lattnere43db882001-10-27 04:15:57 +0000120 return Args[0];
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000121}
122
Chris Lattner44edb6b2003-05-14 14:21:30 +0000123// void atexit(Function*)
124GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
125 assert(Args.size() == 1);
126 TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
127 GenericValue GV;
128 GV.IntVal = 0;
129 return GV;
Chris Lattnerf8f2afb2001-10-18 21:55:32 +0000130}
131
Chris Lattner005cbce2002-10-02 21:12:13 +0000132// void exit(int)
Chris Lattnerb408b122002-03-29 03:57:15 +0000133GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere43db882001-10-27 04:15:57 +0000134 TheInterpreter->exitCalled(Args[0]);
135 return GenericValue();
136}
137
Chris Lattner005cbce2002-10-02 21:12:13 +0000138// void abort(void)
Chris Lattner1ee34a52002-05-20 21:17:16 +0000139GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
140 std::cerr << "***PROGRAM ABORTED***!\n";
141 GenericValue GV;
142 GV.IntVal = 1;
143 TheInterpreter->exitCalled(GV);
144 return GenericValue();
145}
146
Chris Lattnerc2593162001-10-27 08:28:11 +0000147// void *malloc(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000148GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner4721f132001-10-30 20:28:00 +0000149 assert(Args.size() == 1 && "Malloc expects one argument!");
Chris Lattnerb1118742003-01-13 00:59:47 +0000150 return PTOGV(malloc(Args[0].UIntVal));
Chris Lattnerc2593162001-10-27 08:28:11 +0000151}
152
Chris Lattner957d62a2003-04-23 19:55:24 +0000153// void *calloc(uint, uint)
154GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
155 assert(Args.size() == 2 && "calloc expects two arguments!");
156 return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
157}
158
Chris Lattnerc2593162001-10-27 08:28:11 +0000159// void free(void *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000160GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000161 assert(Args.size() == 1);
Chris Lattnerb1118742003-01-13 00:59:47 +0000162 free(GVTOP(Args[0]));
Chris Lattnerc2593162001-10-27 08:28:11 +0000163 return GenericValue();
164}
165
Chris Lattner782b9392001-11-26 18:18:18 +0000166// int atoi(char *)
Chris Lattnerb408b122002-03-29 03:57:15 +0000167GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000168 assert(Args.size() == 1);
169 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000170 GV.IntVal = atoi((char*)GVTOP(Args[0]));
Chris Lattner782b9392001-11-26 18:18:18 +0000171 return GV;
172}
173
Chris Lattnerc2593162001-10-27 08:28:11 +0000174// double pow(double, double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000175GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000176 assert(Args.size() == 2);
Chris Lattnerc2593162001-10-27 08:28:11 +0000177 GenericValue GV;
Chris Lattner08845a22001-10-29 20:27:45 +0000178 GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
Chris Lattnerc2593162001-10-27 08:28:11 +0000179 return GV;
180}
181
Chris Lattner34dd24b2002-02-18 19:06:25 +0000182// double exp(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000183GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner34dd24b2002-02-18 19:06:25 +0000184 assert(Args.size() == 1);
185 GenericValue GV;
186 GV.DoubleVal = exp(Args[0].DoubleVal);
187 return GV;
188}
189
Chris Lattnerc063d382001-11-06 21:52:18 +0000190// double sqrt(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000191GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerc063d382001-11-06 21:52:18 +0000192 assert(Args.size() == 1);
193 GenericValue GV;
194 GV.DoubleVal = sqrt(Args[0].DoubleVal);
195 return GV;
196}
Chris Lattnerc2593162001-10-27 08:28:11 +0000197
Chris Lattner86790052001-11-06 22:53:25 +0000198// double log(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000199GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000200 assert(Args.size() == 1);
201 GenericValue GV;
202 GV.DoubleVal = log(Args[0].DoubleVal);
203 return GV;
204}
205
Chris Lattner782b9392001-11-26 18:18:18 +0000206// double floor(double)
Chris Lattnerb408b122002-03-29 03:57:15 +0000207GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000208 assert(Args.size() == 1);
209 GenericValue GV;
210 GV.DoubleVal = floor(Args[0].DoubleVal);
211 return GV;
212}
213
Chris Lattner86790052001-11-06 22:53:25 +0000214// double drand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000215GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner86790052001-11-06 22:53:25 +0000216 assert(Args.size() == 0);
217 GenericValue GV;
218 GV.DoubleVal = drand48();
219 return GV;
220}
221
Chris Lattner1b600142001-11-13 05:46:08 +0000222// long lrand48()
Chris Lattnerb408b122002-03-29 03:57:15 +0000223GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000224 assert(Args.size() == 0);
225 GenericValue GV;
226 GV.IntVal = lrand48();
227 return GV;
228}
229
230// void srand48(long)
Chris Lattnerb408b122002-03-29 03:57:15 +0000231GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner1b600142001-11-13 05:46:08 +0000232 assert(Args.size() == 1);
233 srand48(Args[0].IntVal);
234 return GenericValue();
235}
236
Chris Lattner782b9392001-11-26 18:18:18 +0000237// void srand(uint)
Chris Lattnerb408b122002-03-29 03:57:15 +0000238GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner782b9392001-11-26 18:18:18 +0000239 assert(Args.size() == 1);
240 srand(Args[0].UIntVal);
241 return GenericValue();
242}
Chris Lattner86790052001-11-06 22:53:25 +0000243
Chris Lattnerb1118742003-01-13 00:59:47 +0000244// int puts(const char*)
245GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
246 assert(Args.size() == 1);
247 GenericValue GV;
248 GV.IntVal = puts((char*)GVTOP(Args[0]));
249 return GV;
250}
251
Chris Lattnere7c6f722001-12-13 00:43:47 +0000252// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
253// output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000254GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000255 char *OutputBuffer = (char *)GVTOP(Args[0]);
256 const char *FmtStr = (const char *)GVTOP(Args[1]);
Chris Lattnere7c6f722001-12-13 00:43:47 +0000257 unsigned ArgNo = 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000258
259 // printf should return # chars printed. This is completely incorrect, but
260 // close enough for now.
261 GenericValue GV; GV.IntVal = strlen(FmtStr);
262 while (1) {
263 switch (*FmtStr) {
264 case 0: return GV; // Null terminator...
265 default: // Normal nonspecial character
Chris Lattnere7c6f722001-12-13 00:43:47 +0000266 sprintf(OutputBuffer++, "%c", *FmtStr++);
Chris Lattner08845a22001-10-29 20:27:45 +0000267 break;
268 case '\\': { // Handle escape codes
Chris Lattnere7c6f722001-12-13 00:43:47 +0000269 sprintf(OutputBuffer, "%c%c", *FmtStr, *(FmtStr+1));
270 FmtStr += 2; OutputBuffer += 2;
Chris Lattner08845a22001-10-29 20:27:45 +0000271 break;
272 }
273 case '%': { // Handle format specifiers
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000274 char FmtBuf[100] = "", Buffer[1000] = "";
275 char *FB = FmtBuf;
276 *FB++ = *FmtStr++;
277 char Last = *FB++ = *FmtStr++;
278 unsigned HowLong = 0;
279 while (Last != 'c' && Last != 'd' && Last != 'i' && Last != 'u' &&
280 Last != 'o' && Last != 'x' && Last != 'X' && Last != 'e' &&
281 Last != 'E' && Last != 'g' && Last != 'G' && Last != 'f' &&
282 Last != 'p' && Last != 's' && Last != '%') {
283 if (Last == 'l' || Last == 'L') HowLong++; // Keep track of l's
284 Last = *FB++ = *FmtStr++;
Chris Lattner08845a22001-10-29 20:27:45 +0000285 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000286 *FB = 0;
287
288 switch (Last) {
289 case '%':
290 sprintf(Buffer, FmtBuf); break;
291 case 'c':
Chris Lattner2012d5e2002-04-17 17:43:01 +0000292 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000293 case 'd': case 'i':
294 case 'u': case 'o':
295 case 'x': case 'X':
Chris Lattner69ab7a82002-08-02 23:08:32 +0000296 if (HowLong >= 1) {
Chris Lattner1543e402003-08-24 14:02:47 +0000297 if (HowLong == 1 &&
298 TheInterpreter->getModule().getPointerSize()==Module::Pointer64 &&
Chris Lattner7471c482003-04-25 18:28:44 +0000299 sizeof(long) < sizeof(long long)) {
Chris Lattner69ab7a82002-08-02 23:08:32 +0000300 // Make sure we use %lld with a 64 bit argument because we might be
301 // compiling LLI on a 32 bit compiler.
302 unsigned Size = strlen(FmtBuf);
303 FmtBuf[Size] = FmtBuf[Size-1];
304 FmtBuf[Size+1] = 0;
305 FmtBuf[Size-1] = 'l';
306 }
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000307 sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
Chris Lattner69ab7a82002-08-02 23:08:32 +0000308 } else
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000309 sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
310 case 'e': case 'E': case 'g': case 'G': case 'f':
311 sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
312 case 'p':
Chris Lattnerb1118742003-01-13 00:59:47 +0000313 sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000314 case 's':
Chris Lattnerb1118742003-01-13 00:59:47 +0000315 sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
Chris Lattnerda82ed52003-05-08 16:18:31 +0000316 default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000317 ArgNo++; break;
Chris Lattner08845a22001-10-29 20:27:45 +0000318 }
Chris Lattnere7c6f722001-12-13 00:43:47 +0000319 strcpy(OutputBuffer, Buffer);
320 OutputBuffer += strlen(Buffer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000321 }
Chris Lattner08845a22001-10-29 20:27:45 +0000322 break;
323 }
Chris Lattner08845a22001-10-29 20:27:45 +0000324 }
325}
326
Chris Lattnere7c6f722001-12-13 00:43:47 +0000327// int printf(sbyte *, ...) - a very rough implementation to make output useful.
Chris Lattnerb408b122002-03-29 03:57:15 +0000328GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattnere7c6f722001-12-13 00:43:47 +0000329 char Buffer[10000];
330 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000331 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnere7c6f722001-12-13 00:43:47 +0000332 NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000333 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnerda82ed52003-05-08 16:18:31 +0000334 std::cout << Buffer;
Chris Lattnere7c6f722001-12-13 00:43:47 +0000335 return GV;
336}
337
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000338static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
339 void *Arg2, void *Arg3, void *Arg4, void *Arg5,
340 void *Arg6, void *Arg7, void *Arg8) {
341 void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 };
342
343 // Loop over the format string, munging read values as appropriate (performs
Misha Brukman5560c9d2003-08-18 14:43:39 +0000344 // byteswaps as necessary).
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000345 unsigned ArgNo = 0;
346 while (*Fmt) {
347 if (*Fmt++ == '%') {
348 // Read any flag characters that may be present...
349 bool Suppress = false;
350 bool Half = false;
351 bool Long = false;
352 bool LongLong = false; // long long or long double
353
354 while (1) {
355 switch (*Fmt++) {
356 case '*': Suppress = true; break;
357 case 'a': /*Allocate = true;*/ break; // We don't need to track this
358 case 'h': Half = true; break;
359 case 'l': Long = true; break;
360 case 'q':
361 case 'L': LongLong = true; break;
362 default:
363 if (Fmt[-1] > '9' || Fmt[-1] < '0') // Ignore field width specs
364 goto Out;
365 }
366 }
367 Out:
368
369 // Read the conversion character
370 if (!Suppress && Fmt[-1] != '%') { // Nothing to do?
371 unsigned Size = 0;
372 const Type *Ty = 0;
373
374 switch (Fmt[-1]) {
375 case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
376 case 'd':
377 if (Long || LongLong) {
378 Size = 8; Ty = Type::ULongTy;
379 } else if (Half) {
380 Size = 4; Ty = Type::UShortTy;
381 } else {
382 Size = 4; Ty = Type::UIntTy;
383 }
384 break;
385
386 case 'e': case 'g': case 'E':
387 case 'f':
388 if (Long || LongLong) {
389 Size = 8; Ty = Type::DoubleTy;
390 } else {
391 Size = 4; Ty = Type::FloatTy;
392 }
393 break;
394
395 case 's': case 'c': case '[': // No byteswap needed
396 Size = 1;
397 Ty = Type::SByteTy;
398 break;
399
400 default: break;
401 }
402
403 if (Size) {
404 GenericValue GV;
405 void *Arg = Args[ArgNo++];
406 memcpy(&GV, Arg, Size);
407 TheInterpreter->StoreValueToMemory(GV, (GenericValue*)Arg, Ty);
408 }
409 }
410 }
411 }
412}
413
Chris Lattner665ee882002-03-08 22:51:07 +0000414// int sscanf(const char *format, ...);
Chris Lattnerb408b122002-03-29 03:57:15 +0000415GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000416 assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
417
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000418 char *Args[10];
Chris Lattner665ee882002-03-08 22:51:07 +0000419 for (unsigned i = 0; i < args.size(); ++i)
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000420 Args[i] = (char*)GVTOP(args[i]);
Chris Lattner665ee882002-03-08 22:51:07 +0000421
422 GenericValue GV;
423 GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
424 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattnerf9a88b62003-03-31 22:12:37 +0000425 ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
426 Args[5], Args[6], Args[7], Args[8], Args[9], 0);
427 return GV;
428}
429
430// int scanf(const char *format, ...);
431GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
432 assert(args.size() < 10 && "Only handle up to 10 args to scanf right now!");
433
434 char *Args[10];
435 for (unsigned i = 0; i < args.size(); ++i)
436 Args[i] = (char*)GVTOP(args[i]);
437
438 GenericValue GV;
439 GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
440 Args[5], Args[6], Args[7], Args[8], Args[9]);
441 ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
442 Args[5], Args[6], Args[7], Args[8], Args[9]);
Chris Lattner665ee882002-03-08 22:51:07 +0000443 return GV;
444}
445
446
Chris Lattner295fe672002-01-23 21:38:07 +0000447// int clock(void) - Profiling implementation
Chris Lattnerb408b122002-03-29 03:57:15 +0000448GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner295fe672002-01-23 21:38:07 +0000449 extern int clock(void);
450 GenericValue GV; GV.IntVal = clock();
451 return GV;
452}
Chris Lattnere7c6f722001-12-13 00:43:47 +0000453
Chris Lattner957d62a2003-04-23 19:55:24 +0000454
455//===----------------------------------------------------------------------===//
456// String Functions...
457//===----------------------------------------------------------------------===//
458
459// int strcmp(const char *S1, const char *S2);
460GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
461 assert(Args.size() == 2);
462 GenericValue Ret;
463 Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
464 return Ret;
465}
466
467// char *strcat(char *Dest, const char *src);
468GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
469 assert(Args.size() == 2);
470 return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
471}
472
473// char *strcpy(char *Dest, const char *src);
474GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
475 assert(Args.size() == 2);
476 return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
477}
478
479// long strlen(const char *src);
480GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
481 assert(Args.size() == 1);
482 GenericValue Ret;
483 Ret.LongVal = strlen((char*)GVTOP(Args[0]));
484 return Ret;
485}
486
Brian Gaeke70975ee2003-09-05 18:42:01 +0000487// char *strdup(const char *src);
488GenericValue lle_X_strdup(FunctionType *M, const vector<GenericValue> &Args) {
489 assert(Args.size() == 1);
490 return PTOGV(strdup((char*)GVTOP(Args[0])));
491}
492
Chris Lattnerc8cff9e2003-04-25 18:23:38 +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 Lattner957d62a2003-04-23 19:55:24 +0000499// void *memset(void *S, int C, size_t N)
500GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
501 assert(Args.size() == 3);
502 return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
503}
504
Chris Lattner5f311a72003-04-23 20:23:16 +0000505// void *memcpy(void *Dest, void *src, size_t Size);
506GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
507 assert(Args.size() == 3);
508 return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
509 Args[2].UIntVal));
510}
Chris Lattner957d62a2003-04-23 19:55:24 +0000511
Chris Lattner665ee882002-03-08 22:51:07 +0000512//===----------------------------------------------------------------------===//
513// IO Functions...
514//===----------------------------------------------------------------------===//
515
Chris Lattner005cbce2002-10-02 21:12:13 +0000516// getFILE - Turn a pointer in the host address space into a legit pointer in
517// the interpreter address space. For the most part, this is an identity
518// transformation, but if the program refers to stdio, stderr, stdin then they
519// have pointers that are relative to the __iob array. If this is the case,
520// change the FILE into the REAL stdio stream.
521//
Chris Lattnerb1118742003-01-13 00:59:47 +0000522static FILE *getFILE(void *Ptr) {
Chris Lattner005cbce2002-10-02 21:12:13 +0000523 static Module *LastMod = 0;
524 static PointerTy IOBBase = 0;
525 static unsigned FILESize;
526
Chris Lattnerfe11a972002-12-23 23:59:41 +0000527 if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
528 Module *M = LastMod = &TheInterpreter->getModule();
Chris Lattner005cbce2002-10-02 21:12:13 +0000529
530 // Check to see if the currently loaded module contains an __iob symbol...
531 GlobalVariable *IOB = 0;
Chris Lattner6e6026b2002-11-20 18:36:02 +0000532 SymbolTable &ST = M->getSymbolTable();
533 for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
534 SymbolTable::VarMap &M = I->second;
535 for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
536 J != E; ++J)
537 if (J->first == "__iob")
538 if ((IOB = dyn_cast<GlobalVariable>(J->second)))
539 break;
540 if (IOB) break;
Chris Lattner005cbce2002-10-02 21:12:13 +0000541 }
542
Chris Lattnerfe11a972002-12-23 23:59:41 +0000543#if 0 /// FIXME! __iob support for LLI
Chris Lattner005cbce2002-10-02 21:12:13 +0000544 // If we found an __iob symbol now, find out what the actual address it's
545 // held in is...
546 if (IOB) {
547 // Get the address the array lives in...
548 GlobalAddress *Address =
549 (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
550 IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
551
552 // Figure out how big each element of the array is...
553 const ArrayType *AT =
554 dyn_cast<ArrayType>(IOB->getType()->getElementType());
555 if (AT)
556 FILESize = TD.getTypeSize(AT->getElementType());
557 else
558 FILESize = 16*8; // Default size
559 }
Chris Lattnerfe11a972002-12-23 23:59:41 +0000560#endif
Chris Lattner005cbce2002-10-02 21:12:13 +0000561 }
562
563 // Check to see if this is a reference to __iob...
564 if (IOBBase) {
Chris Lattnerb1118742003-01-13 00:59:47 +0000565 unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
Chris Lattner005cbce2002-10-02 21:12:13 +0000566 if (FDNum == 0)
567 return stdin;
568 else if (FDNum == 1)
569 return stdout;
570 else if (FDNum == 2)
571 return stderr;
572 }
573
574 return (FILE*)Ptr;
575}
576
577
Chris Lattner665ee882002-03-08 22:51:07 +0000578// FILE *fopen(const char *filename, const char *mode);
Chris Lattnerb408b122002-03-29 03:57:15 +0000579GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000580 assert(Args.size() == 2);
Chris Lattnerb1118742003-01-13 00:59:47 +0000581 return PTOGV(fopen((const char *)GVTOP(Args[0]),
582 (const char *)GVTOP(Args[1])));
Chris Lattner665ee882002-03-08 22:51:07 +0000583}
584
585// int fclose(FILE *F);
Chris Lattnerb408b122002-03-29 03:57:15 +0000586GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000587 assert(Args.size() == 1);
588 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000589 GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000590 return GV;
591}
592
Chris Lattner25f6f372002-11-08 19:10:26 +0000593// int feof(FILE *stream);
594GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
595 assert(Args.size() == 1);
596 GenericValue GV;
597
Chris Lattnerb1118742003-01-13 00:59:47 +0000598 GV.IntVal = feof(getFILE(GVTOP(Args[0])));
Chris Lattner25f6f372002-11-08 19:10:26 +0000599 return GV;
600}
601
Chris Lattner665ee882002-03-08 22:51:07 +0000602// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000603GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000604 assert(Args.size() == 4);
605 GenericValue GV;
606
Chris Lattnerb1118742003-01-13 00:59:47 +0000607 GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
608 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000609 return GV;
610}
611
612// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000613GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000614 assert(Args.size() == 4);
615 GenericValue GV;
616
Chris Lattnerb1118742003-01-13 00:59:47 +0000617 GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
618 Args[2].UIntVal, getFILE(GVTOP(Args[3])));
Chris Lattner665ee882002-03-08 22:51:07 +0000619 return GV;
620}
621
622// char *fgets(char *s, int n, FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000623GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000624 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000625 return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
626 getFILE(GVTOP(Args[2]))));
Chris Lattner665ee882002-03-08 22:51:07 +0000627}
628
Chris Lattnera4479cd2002-11-07 19:33:50 +0000629// FILE *freopen(const char *path, const char *mode, FILE *stream);
630GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
631 assert(Args.size() == 3);
Chris Lattnerb1118742003-01-13 00:59:47 +0000632 return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
633 getFILE(GVTOP(Args[2]))));
Chris Lattnera4479cd2002-11-07 19:33:50 +0000634}
635
Chris Lattner665ee882002-03-08 22:51:07 +0000636// int fflush(FILE *stream);
Chris Lattnerb408b122002-03-29 03:57:15 +0000637GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner665ee882002-03-08 22:51:07 +0000638 assert(Args.size() == 1);
639 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000640 GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
Chris Lattner005cbce2002-10-02 21:12:13 +0000641 return GV;
642}
643
644// int getc(FILE *stream);
645GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
646 assert(Args.size() == 1);
647 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000648 GV.IntVal = getc(getFILE(GVTOP(Args[0])));
Chris Lattner665ee882002-03-08 22:51:07 +0000649 return GV;
650}
651
Chris Lattnerf87a1982003-04-23 19:20:50 +0000652// int _IO_getc(FILE *stream);
653GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
654 return lle_X_getc(F, Args);
655}
656
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000657// int fputc(int C, FILE *stream);
658GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
659 assert(Args.size() == 2);
660 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000661 GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000662 return GV;
663}
664
665// int ungetc(int C, FILE *stream);
666GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
667 assert(Args.size() == 2);
668 GenericValue GV;
Chris Lattnerb1118742003-01-13 00:59:47 +0000669 GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
Chris Lattnera5c0bfe2002-11-06 22:59:28 +0000670 return GV;
671}
672
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000673// int fprintf(FILE *,sbyte *, ...) - a very rough implementation to make output
674// useful.
675GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
Chris Lattner9dbf6dd2003-04-21 22:43:20 +0000676 assert(Args.size() >= 2);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000677 char Buffer[10000];
678 vector<GenericValue> NewArgs;
Chris Lattnerb1118742003-01-13 00:59:47 +0000679 NewArgs.push_back(PTOGV(Buffer));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000680 NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
Chris Lattnerb1118742003-01-13 00:59:47 +0000681 GenericValue GV = lle_X_sprintf(M, NewArgs);
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000682
Chris Lattnerb1118742003-01-13 00:59:47 +0000683 fputs(Buffer, getFILE(GVTOP(Args[0])));
Chris Lattnercf9b4f02002-11-06 23:05:03 +0000684 return GV;
685}
686
Chris Lattner374344c2003-05-08 16:52:43 +0000687//===----------------------------------------------------------------------===//
688// LLVM Intrinsic Functions...
689//===----------------------------------------------------------------------===//
690
691// void llvm.va_start(<va_list> *) - Implement the va_start operation...
692GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
693 assert(Args.size() == 1);
694 GenericValue *VAListP = (GenericValue *)GVTOP(Args[0]);
695 GenericValue Val;
696 Val.UIntVal = 0; // Start at the first '...' argument...
697 TheInterpreter->StoreValueToMemory(Val, VAListP, Type::UIntTy);
698 return GenericValue();
699}
700
701// void llvm.va_end(<va_list> *) - Implement the va_end operation...
702GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
703 assert(Args.size() == 1);
704 return GenericValue(); // Noop!
705}
706
707// void llvm.va_copy(<va_list> *, <va_list>) - Implement the va_copy
708// operation...
709GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
710 assert(Args.size() == 2);
711 GenericValue *DestVAList = (GenericValue*)GVTOP(Args[0]);
712 TheInterpreter->StoreValueToMemory(Args[1], DestVAList, Type::UIntTy);
713 return GenericValue();
714}
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}