- 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 *FT, const vector<GenericValue> &Args) {
- extern unsigned int clock(void);
- GenericValue GV;
- GV.IntVal = APInt(32, clock());
- return GV;
-}
-
-
-//===----------------------------------------------------------------------===//
-// String Functions...
-//===----------------------------------------------------------------------===//
-
-// int strcmp(const char *S1, const char *S2);
-GenericValue lle_X_strcmp(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- GenericValue Ret;
- Ret.IntVal = APInt(32, strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
- return Ret;
-}
-
-// char *strcat(char *Dest, const char *src);
-GenericValue lle_X_strcat(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- assert(isa<PointerType>(FT->getReturnType()) &&"strcat must return pointer");
- return PTOGV(strcat((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
-}
-
-// char *strcpy(char *Dest, const char *src);
-GenericValue lle_X_strcpy(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- assert(isa<PointerType>(FT->getReturnType()) &&"strcpy must return pointer");
- return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
-}
-
-static GenericValue size_t_to_GV (size_t n) {
- GenericValue Ret;
- if (sizeof (size_t) == sizeof (uint64_t)) {
- Ret.IntVal = APInt(64, n);
- } else {
- assert (sizeof (size_t) == sizeof (unsigned int));
- Ret.IntVal = APInt(32, n);
- }
- return Ret;
-}
-
-static size_t GV_to_size_t (GenericValue GV) {
- size_t count;
- if (sizeof (size_t) == sizeof (uint64_t)) {
- count = (size_t)GV.IntVal.getZExtValue();
- } else {
- assert (sizeof (size_t) == sizeof (unsigned int));
- count = (size_t)GV.IntVal.getZExtValue();
- }
- return count;
-}
-
-// size_t strlen(const char *src);
-GenericValue lle_X_strlen(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- size_t strlenResult = strlen ((char *) GVTOP (Args[0]));
- return size_t_to_GV (strlenResult);
-}
-
-// char *strdup(const char *src);
-GenericValue lle_X_strdup(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- assert(isa<PointerType>(FT->getReturnType()) && "strdup must return pointer");
- return PTOGV(strdup((char*)GVTOP(Args[0])));
-}
-
-// char *__strdup(const char *src);
-GenericValue lle_X___strdup(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- assert(isa<PointerType>(FT->getReturnType()) &&"_strdup must return pointer");
- return PTOGV(strdup((char*)GVTOP(Args[0])));
-}
-
-// void *memset(void *S, int C, size_t N)
-GenericValue lle_X_memset(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- size_t count = GV_to_size_t (Args[2]);
- assert(isa<PointerType>(FT->getReturnType()) && "memset must return pointer");
- return PTOGV(memset(GVTOP(Args[0]), uint32_t(Args[1].IntVal.getZExtValue()),
- count));
-}
-
-// void *memcpy(void *Dest, void *src, size_t Size);
-GenericValue lle_X_memcpy(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- assert(isa<PointerType>(FT->getReturnType()) && "memcpy must return pointer");
- size_t count = GV_to_size_t (Args[2]);
- return PTOGV(memcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]), count));
-}
-
-// void *memcpy(void *Dest, void *src, size_t Size);
-GenericValue lle_X_memmove(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- assert(isa<PointerType>(FT->getReturnType()) && "memmove must return pointer");
- size_t count = GV_to_size_t (Args[2]);
- return PTOGV(memmove((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]), count));
-}
-
-//===----------------------------------------------------------------------===//
-// IO Functions...
-//===----------------------------------------------------------------------===//
-
-// getFILE - Turn a pointer in the host address space into a legit pointer in
-// the interpreter address space. This is an identity transformation.
-#define getFILE(ptr) ((FILE*)ptr)
-
-// FILE *fopen(const char *filename, const char *mode);
-GenericValue lle_X_fopen(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- assert(isa<PointerType>(FT->getReturnType()) && "fopen must return pointer");
- return PTOGV(fopen((const char *)GVTOP(Args[0]),
- (const char *)GVTOP(Args[1])));
-}
-
-// int fclose(FILE *F);
-GenericValue lle_X_fclose(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = APInt(32, fclose(getFILE(GVTOP(Args[0]))));
- return GV;
-}
-
-// int feof(FILE *stream);
-GenericValue lle_X_feof(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
-
- GV.IntVal = APInt(32, 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 *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 4);
- size_t result;
-
- result = fread((void*)GVTOP(Args[0]), GV_to_size_t (Args[1]),
- GV_to_size_t (Args[2]), getFILE(GVTOP(Args[3])));
- return size_t_to_GV (result);
-}
-
-// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
-GenericValue lle_X_fwrite(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 4);
- size_t result;
-
- result = fwrite((void*)GVTOP(Args[0]), GV_to_size_t (Args[1]),
- GV_to_size_t (Args[2]), getFILE(GVTOP(Args[3])));
- return size_t_to_GV (result);
-}
-
-// char *fgets(char *s, int n, FILE *stream);
-GenericValue lle_X_fgets(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- return PTOGV(fgets((char*)GVTOP(Args[0]), Args[1].IntVal.getZExtValue(),
- getFILE(GVTOP(Args[2]))));
-}
-
-// FILE *freopen(const char *path, const char *mode, FILE *stream);
-GenericValue lle_X_freopen(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 3);
- assert(isa<PointerType>(FT->getReturnType()) &&"freopen must return pointer");
- return PTOGV(freopen((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]),
- getFILE(GVTOP(Args[2]))));
-}
-
-// int fflush(FILE *stream);
-GenericValue lle_X_fflush(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = APInt(32, fflush(getFILE(GVTOP(Args[0]))));
- return GV;
-}
-
-// int getc(FILE *stream);
-GenericValue lle_X_getc(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = APInt(32, getc(getFILE(GVTOP(Args[0]))));
- return GV;
-}
-
-// int _IO_getc(FILE *stream);
-GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
- return lle_X_getc(F, Args);
-}
-
-// int fputc(int C, FILE *stream);
-GenericValue lle_X_fputc(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- GenericValue GV;
- GV.IntVal = APInt(32, fputc(Args[0].IntVal.getZExtValue(),
- getFILE(GVTOP(Args[1]))));
- return GV;
-}
-
-// int ungetc(int C, FILE *stream);
-GenericValue lle_X_ungetc(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 2);
- GenericValue GV;
- GV.IntVal = APInt(32, ungetc(Args[0].IntVal.getZExtValue(),
- getFILE(GVTOP(Args[1]))));
- return GV;
-}
-
-// int ferror (FILE *stream);
-GenericValue lle_X_ferror(FunctionType *FT, const vector<GenericValue> &Args) {
- assert(Args.size() == 1);
- GenericValue GV;
- GV.IntVal = APInt(32, ferror (getFILE(GVTOP(Args[0]))));