- GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
- Args[5], Args[6], Args[7], Args[8], Args[9]);
- ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
- Args[5], Args[6], Args[7], Args[8], Args[9]);
- return GV;
-}
-
-
-// int clock(void) - Profiling implementation
-GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
- extern int clock(void);
- GenericValue GV; GV.IntVal = clock();
- return GV;
-}
-
-
-//===----------------------------------------------------------------------===//
-// String Functions...
-//===----------------------------------------------------------------------===//
-
-// int strcmp(const char *S1, const char *S2);
-GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- GenericValue Ret;
- Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
- return Ret;
-}
-
-// char *strcat(char *Dest, const char *src);
-GenericValue lle_X_strcat(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
-}
-
-// char *strcpy(char *Dest, const char *src);
-GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
-}
-
-// long strlen(const char *src);
-GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue Ret;
- Ret.LongVal = strlen((char*)GVTOP(Args[0]));
- return Ret;
-}
-
-// char *strdup(const char *src);
-GenericValue lle_X_strdup(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- return PTOGV(strdup((char*)GVTOP(Args[0])));
-}
-
-// char *__strdup(const char *src);
-GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- return PTOGV(strdup((char*)GVTOP(Args[0])));
-}
-
-// void *memset(void *S, int C, size_t N)
-GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, Args[2].UIntVal));
-}
-
-// void *memcpy(void *Dest, void *src, size_t Size);
-GenericValue lle_X_memcpy(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
- Args[2].UIntVal));
-}
-
-//===----------------------------------------------------------------------===//
-// IO Functions...
-//===----------------------------------------------------------------------===//
-
-// getFILE - Turn a pointer in the host address space into a legit pointer in
-// the interpreter address space. For the most part, this is an identity
-// transformation, but if the program refers to stdio, stderr, stdin then they
-// have pointers that are relative to the __iob array. If this is the case,
-// change the FILE into the REAL stdio stream.
-//
-static FILE *getFILE(void *Ptr) {
- static Module *LastMod = 0;
- static PointerTy IOBBase = 0;
- static unsigned FILESize;
-
- if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize?
- Module *M = LastMod = &TheInterpreter->getModule();
-
- // Check to see if the currently loaded module contains an __iob symbol...
- GlobalVariable *IOB = 0;
- SymbolTable &ST = M->getSymbolTable();
- for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
- SymbolTable::VarMap &M = I->second;
- for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
- J != E; ++J)
- if (J->first == "__iob")
- if ((IOB = dyn_cast<GlobalVariable>(J->second)))
- break;
- if (IOB) break;
- }
-
-#if 0 /// FIXME! __iob support for LLI
- // If we found an __iob symbol now, find out what the actual address it's
- // held in is...
- if (IOB) {
- // Get the address the array lives in...
- GlobalAddress *Address =
- (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
- IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
-
- // Figure out how big each element of the array is...
- const ArrayType *AT =
- dyn_cast<ArrayType>(IOB->getType()->getElementType());
- if (AT)
- FILESize = TD.getTypeSize(AT->getElementType());
- else
- FILESize = 16*8; // Default size
- }
-#endif
- }
-
- // Check to see if this is a reference to __iob...
- if (IOBBase) {
- unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize;
- if (FDNum == 0)
- return stdin;
- else if (FDNum == 1)
- return stdout;
- else if (FDNum == 2)
- return stderr;
- }
-
- return (FILE*)Ptr;
-}
-
-
-// FILE *fopen(const char *filename, const char *mode);
-GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- return PTOGV(fopen((const char *)GVTOP(Args[0]),
- (const char *)GVTOP(Args[1])));
-}
-
-// int fclose(FILE *F);
-GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
- return GV;
-}
-
-// int feof(FILE *stream);
-GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
-
- GV.IntVal = feof(getFILE(GVTOP(Args[0])));
- return GV;
-}
-
-// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
-GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 4);
- GenericValue GV;
-
- GV.UIntVal = fread((void*)GVTOP(Args[0]), Args[1].UIntVal,
- Args[2].UIntVal, getFILE(GVTOP(Args[3])));
- return GV;
-}
-
-// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
-GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 4);
- GenericValue GV;
-
- GV.UIntVal = fwrite((void*)GVTOP(Args[0]), Args[1].UIntVal,
- Args[2].UIntVal, getFILE(GVTOP(Args[3])));
- return GV;
-}
-
-// char *fgets(char *s, int n, FILE *stream);
-GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
- getFILE(GVTOP(Args[2]))));
-}
-
-// FILE *freopen(const char *path, const char *mode, FILE *stream);
-GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
- getFILE(GVTOP(Args[2]))));
-}
-
-// int fflush(FILE *stream);
-GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
- return GV;
-}
-
-// int getc(FILE *stream);
-GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = getc(getFILE(GVTOP(Args[0])));