forked from OSchip/llvm-project
parent
ff87436f48
commit
f94811af13
|
@ -1,4 +1,4 @@
|
||||||
//===-- ExternalMethods.cpp - Implement External Methods ------------------===//
|
//===-- ExternalMethods.cpp - Implement External Functions ----------------===//
|
||||||
//
|
//
|
||||||
// This file contains both code to deal with invoking "external" methods, but
|
// This file contains both code to deal with invoking "external" methods, but
|
||||||
// also contains code that implements "exported" external methods.
|
// also contains code that implements "exported" external methods.
|
||||||
|
@ -20,8 +20,8 @@
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
|
||||||
typedef GenericValue (*ExFunc)(MethodType *, const vector<GenericValue> &);
|
typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
|
||||||
static std::map<const Method *, ExFunc> Functions;
|
static std::map<const Function *, ExFunc> Functions;
|
||||||
static std::map<std::string, ExFunc> FuncNames;
|
static std::map<std::string, ExFunc> FuncNames;
|
||||||
|
|
||||||
static Interpreter *TheInterpreter;
|
static Interpreter *TheInterpreter;
|
||||||
|
@ -57,7 +57,7 @@ static char getTypeID(const Type *Ty) {
|
||||||
case Type::FloatTyID: return 'F';
|
case Type::FloatTyID: return 'F';
|
||||||
case Type::DoubleTyID: return 'D';
|
case Type::DoubleTyID: return 'D';
|
||||||
case Type::PointerTyID: return 'P';
|
case Type::PointerTyID: return 'P';
|
||||||
case Type::MethodTyID: return 'M';
|
case Type::FunctionTyID: return 'M';
|
||||||
case Type::StructTyID: return 'T';
|
case Type::StructTyID: return 'T';
|
||||||
case Type::ArrayTyID: return 'A';
|
case Type::ArrayTyID: return 'A';
|
||||||
case Type::OpaqueTyID: return 'O';
|
case Type::OpaqueTyID: return 'O';
|
||||||
|
@ -65,11 +65,11 @@ static char getTypeID(const Type *Ty) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ExFunc lookupMethod(const Method *M) {
|
static ExFunc lookupFunction(const Function *M) {
|
||||||
// Function not found, look it up... start by figuring out what the
|
// Function not found, look it up... start by figuring out what the
|
||||||
// composite function name should be.
|
// composite function name should be.
|
||||||
std::string ExtName = "lle_";
|
std::string ExtName = "lle_";
|
||||||
const MethodType *MT = M->getMethodType();
|
const FunctionType *MT = M->getFunctionType();
|
||||||
for (unsigned i = 0; const Type *Ty = MT->getContainedType(i); ++i)
|
for (unsigned i = 0; const Type *Ty = MT->getContainedType(i); ++i)
|
||||||
ExtName += getTypeID(Ty);
|
ExtName += getTypeID(Ty);
|
||||||
ExtName += "_" + M->getName();
|
ExtName += "_" + M->getName();
|
||||||
|
@ -87,14 +87,14 @@ static ExFunc lookupMethod(const Method *M) {
|
||||||
return FnPtr;
|
return FnPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericValue Interpreter::callExternalMethod(Method *M,
|
GenericValue Interpreter::callExternalMethod(Function *M,
|
||||||
const vector<GenericValue> &ArgVals) {
|
const vector<GenericValue> &ArgVals) {
|
||||||
TheInterpreter = this;
|
TheInterpreter = this;
|
||||||
|
|
||||||
// Do a lookup to see if the method is in our cache... this should just be a
|
// Do a lookup to see if the method is in our cache... this should just be a
|
||||||
// defered annotation!
|
// defered annotation!
|
||||||
std::map<const Method *, ExFunc>::iterator FI = Functions.find(M);
|
std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
|
||||||
ExFunc Fn = (FI == Functions.end()) ? lookupMethod(M) : FI->second;
|
ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
|
||||||
if (Fn == 0) {
|
if (Fn == 0) {
|
||||||
cout << "Tried to execute an unknown external method: "
|
cout << "Tried to execute an unknown external method: "
|
||||||
<< M->getType()->getDescription() << " " << M->getName() << "\n";
|
<< M->getType()->getDescription() << " " << M->getName() << "\n";
|
||||||
|
@ -102,25 +102,25 @@ GenericValue Interpreter::callExternalMethod(Method *M,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME when types are not const!
|
// TODO: FIXME when types are not const!
|
||||||
GenericValue Result = Fn(const_cast<MethodType*>(M->getMethodType()),ArgVals);
|
GenericValue Result = Fn(const_cast<FunctionType*>(M->getFunctionType()),ArgVals);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Methods "exported" to the running application...
|
// Functions "exported" to the running application...
|
||||||
//
|
//
|
||||||
extern "C" { // Don't add C++ manglings to llvm mangling :)
|
extern "C" { // Don't add C++ manglings to llvm mangling :)
|
||||||
|
|
||||||
// Implement void printstr([ubyte {x N}] *)
|
// Implement void printstr([ubyte {x N}] *)
|
||||||
GenericValue lle_VP_printstr(MethodType *M, const vector<GenericValue> &ArgVal){
|
GenericValue lle_VP_printstr(FunctionType *M, const vector<GenericValue> &ArgVal){
|
||||||
assert(ArgVal.size() == 1 && "printstr only takes one argument!");
|
assert(ArgVal.size() == 1 && "printstr only takes one argument!");
|
||||||
cout << (char*)ArgVal[0].PointerVal;
|
cout << (char*)ArgVal[0].PointerVal;
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement 'void print(X)' for every type...
|
// Implement 'void print(X)' for every type...
|
||||||
GenericValue lle_X_print(MethodType *M, const vector<GenericValue> &ArgVals) {
|
GenericValue lle_X_print(FunctionType *M, const vector<GenericValue> &ArgVals) {
|
||||||
assert(ArgVals.size() == 1 && "generic print only takes one argument!");
|
assert(ArgVals.size() == 1 && "generic print only takes one argument!");
|
||||||
|
|
||||||
Interpreter::print(M->getParamTypes()[0], ArgVals[0]);
|
Interpreter::print(M->getParamTypes()[0], ArgVals[0]);
|
||||||
|
@ -128,7 +128,7 @@ GenericValue lle_X_print(MethodType *M, const vector<GenericValue> &ArgVals) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement 'void printVal(X)' for every type...
|
// Implement 'void printVal(X)' for every type...
|
||||||
GenericValue lle_X_printVal(MethodType *M, const vector<GenericValue> &ArgVal) {
|
GenericValue lle_X_printVal(FunctionType *M, const vector<GenericValue> &ArgVal) {
|
||||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
||||||
|
|
||||||
// Specialize print([ubyte {x N} ] *) and print(sbyte *)
|
// Specialize print([ubyte {x N} ] *) and print(sbyte *)
|
||||||
|
@ -144,14 +144,14 @@ GenericValue lle_X_printVal(MethodType *M, const vector<GenericValue> &ArgVal) {
|
||||||
|
|
||||||
// Implement 'void printString(X)'
|
// Implement 'void printString(X)'
|
||||||
// Argument must be [ubyte {x N} ] * or sbyte *
|
// Argument must be [ubyte {x N} ] * or sbyte *
|
||||||
GenericValue lle_X_printString(MethodType *M, const vector<GenericValue> &ArgVal) {
|
GenericValue lle_X_printString(FunctionType *M, const vector<GenericValue> &ArgVal) {
|
||||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
||||||
return lle_VP_printstr(M, ArgVal);
|
return lle_VP_printstr(M, ArgVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement 'void print<TYPE>(X)' for each primitive type or pointer type
|
// Implement 'void print<TYPE>(X)' for each primitive type or pointer type
|
||||||
#define PRINT_TYPE_FUNC(TYPENAME,TYPEID) \
|
#define PRINT_TYPE_FUNC(TYPENAME,TYPEID) \
|
||||||
GenericValue lle_X_print##TYPENAME(MethodType *M,\
|
GenericValue lle_X_print##TYPENAME(FunctionType *M,\
|
||||||
const vector<GenericValue> &ArgVal) {\
|
const vector<GenericValue> &ArgVal) {\
|
||||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");\
|
assert(ArgVal.size() == 1 && "generic print only takes one argument!");\
|
||||||
assert(M->getParamTypes()[0].get()->getPrimitiveID() == Type::TYPEID);\
|
assert(M->getParamTypes()[0].get()->getPrimitiveID() == Type::TYPEID);\
|
||||||
|
@ -173,36 +173,36 @@ PRINT_TYPE_FUNC(Pointer, PointerTyID)
|
||||||
|
|
||||||
|
|
||||||
// void "putchar"(sbyte)
|
// void "putchar"(sbyte)
|
||||||
GenericValue lle_Vb_putchar(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
cout << Args[0].SByteVal;
|
cout << Args[0].SByteVal;
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// int "putchar"(int)
|
// int "putchar"(int)
|
||||||
GenericValue lle_ii_putchar(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
cout << ((char)Args[0].IntVal) << std::flush;
|
cout << ((char)Args[0].IntVal) << std::flush;
|
||||||
return Args[0];
|
return Args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// void "putchar"(ubyte)
|
// void "putchar"(ubyte)
|
||||||
GenericValue lle_VB_putchar(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
cout << Args[0].SByteVal << std::flush;
|
cout << Args[0].SByteVal << std::flush;
|
||||||
return Args[0];
|
return Args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// void "__main"()
|
// void "__main"()
|
||||||
GenericValue lle_V___main(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_V___main(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void "exit"(int)
|
// void "exit"(int)
|
||||||
GenericValue lle_X_exit(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
TheInterpreter->exitCalled(Args[0]);
|
TheInterpreter->exitCalled(Args[0]);
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void *malloc(uint)
|
// void *malloc(uint)
|
||||||
GenericValue lle_X_malloc(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1 && "Malloc expects one argument!");
|
assert(Args.size() == 1 && "Malloc expects one argument!");
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.PointerVal = (PointerTy)malloc(Args[0].UIntVal);
|
GV.PointerVal = (PointerTy)malloc(Args[0].UIntVal);
|
||||||
|
@ -210,14 +210,14 @@ GenericValue lle_X_malloc(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void free(void *)
|
// void free(void *)
|
||||||
GenericValue lle_X_free(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
free((void*)Args[0].PointerVal);
|
free((void*)Args[0].PointerVal);
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// int atoi(char *)
|
// int atoi(char *)
|
||||||
GenericValue lle_X_atoi(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.IntVal = atoi((char*)Args[0].PointerVal);
|
GV.IntVal = atoi((char*)Args[0].PointerVal);
|
||||||
|
@ -225,7 +225,7 @@ GenericValue lle_X_atoi(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double pow(double, double)
|
// double pow(double, double)
|
||||||
GenericValue lle_X_pow(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_pow(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 2);
|
assert(Args.size() == 2);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
|
GV.DoubleVal = pow(Args[0].DoubleVal, Args[1].DoubleVal);
|
||||||
|
@ -233,7 +233,7 @@ GenericValue lle_X_pow(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double exp(double)
|
// double exp(double)
|
||||||
GenericValue lle_X_exp(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_exp(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = exp(Args[0].DoubleVal);
|
GV.DoubleVal = exp(Args[0].DoubleVal);
|
||||||
|
@ -241,7 +241,7 @@ GenericValue lle_X_exp(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double sqrt(double)
|
// double sqrt(double)
|
||||||
GenericValue lle_X_sqrt(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_sqrt(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = sqrt(Args[0].DoubleVal);
|
GV.DoubleVal = sqrt(Args[0].DoubleVal);
|
||||||
|
@ -249,7 +249,7 @@ GenericValue lle_X_sqrt(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double log(double)
|
// double log(double)
|
||||||
GenericValue lle_X_log(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_log(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = log(Args[0].DoubleVal);
|
GV.DoubleVal = log(Args[0].DoubleVal);
|
||||||
|
@ -257,7 +257,7 @@ GenericValue lle_X_log(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double floor(double)
|
// double floor(double)
|
||||||
GenericValue lle_X_floor(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_floor(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = floor(Args[0].DoubleVal);
|
GV.DoubleVal = floor(Args[0].DoubleVal);
|
||||||
|
@ -265,7 +265,7 @@ GenericValue lle_X_floor(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// double drand48()
|
// double drand48()
|
||||||
GenericValue lle_X_drand48(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 0);
|
assert(Args.size() == 0);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.DoubleVal = drand48();
|
GV.DoubleVal = drand48();
|
||||||
|
@ -273,7 +273,7 @@ GenericValue lle_X_drand48(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// long lrand48()
|
// long lrand48()
|
||||||
GenericValue lle_X_lrand48(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 0);
|
assert(Args.size() == 0);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
GV.IntVal = lrand48();
|
GV.IntVal = lrand48();
|
||||||
|
@ -281,14 +281,14 @@ GenericValue lle_X_lrand48(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void srand48(long)
|
// void srand48(long)
|
||||||
GenericValue lle_X_srand48(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
srand48(Args[0].IntVal);
|
srand48(Args[0].IntVal);
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void srand(uint)
|
// void srand(uint)
|
||||||
GenericValue lle_X_srand(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
srand(Args[0].UIntVal);
|
srand(Args[0].UIntVal);
|
||||||
return GenericValue();
|
return GenericValue();
|
||||||
|
@ -296,7 +296,7 @@ GenericValue lle_X_srand(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
|
|
||||||
// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
|
// int sprintf(sbyte *, sbyte *, ...) - a very rough implementation to make
|
||||||
// output useful.
|
// output useful.
|
||||||
GenericValue lle_X_sprintf(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
char *OutputBuffer = (char *)Args[0].PointerVal;
|
char *OutputBuffer = (char *)Args[0].PointerVal;
|
||||||
const char *FmtStr = (const char *)Args[1].PointerVal;
|
const char *FmtStr = (const char *)Args[1].PointerVal;
|
||||||
unsigned ArgNo = 2;
|
unsigned ArgNo = 2;
|
||||||
|
@ -360,7 +360,7 @@ GenericValue lle_X_sprintf(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// int printf(sbyte *, ...) - a very rough implementation to make output useful.
|
// int printf(sbyte *, ...) - a very rough implementation to make output useful.
|
||||||
GenericValue lle_X_printf(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
char Buffer[10000];
|
char Buffer[10000];
|
||||||
vector<GenericValue> NewArgs;
|
vector<GenericValue> NewArgs;
|
||||||
GenericValue GV; GV.PointerVal = (PointerTy)Buffer;
|
GenericValue GV; GV.PointerVal = (PointerTy)Buffer;
|
||||||
|
@ -372,7 +372,7 @@ GenericValue lle_X_printf(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// int sscanf(const char *format, ...);
|
// int sscanf(const char *format, ...);
|
||||||
GenericValue lle_X_sscanf(MethodType *M, const vector<GenericValue> &args) {
|
GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
|
||||||
assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
|
assert(args.size() < 10 && "Only handle up to 10 args to sscanf right now!");
|
||||||
|
|
||||||
const char *Args[10];
|
const char *Args[10];
|
||||||
|
@ -387,7 +387,7 @@ GenericValue lle_X_sscanf(MethodType *M, const vector<GenericValue> &args) {
|
||||||
|
|
||||||
|
|
||||||
// int clock(void) - Profiling implementation
|
// int clock(void) - Profiling implementation
|
||||||
GenericValue lle_i_clock(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
extern int clock(void);
|
extern int clock(void);
|
||||||
GenericValue GV; GV.IntVal = clock();
|
GenericValue GV; GV.IntVal = clock();
|
||||||
return GV;
|
return GV;
|
||||||
|
@ -398,7 +398,7 @@ GenericValue lle_i_clock(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// FILE *fopen(const char *filename, const char *mode);
|
// FILE *fopen(const char *filename, const char *mode);
|
||||||
GenericValue lle_X_fopen(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 2);
|
assert(Args.size() == 2);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ GenericValue lle_X_fopen(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// int fclose(FILE *F);
|
// int fclose(FILE *F);
|
||||||
GenericValue lle_X_fclose(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ GenericValue lle_X_fclose(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
|
// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
|
||||||
GenericValue lle_X_fread(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fread(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 4);
|
assert(Args.size() == 4);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ GenericValue lle_X_fread(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
|
// size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
|
||||||
GenericValue lle_X_fwrite(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 4);
|
assert(Args.size() == 4);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ GenericValue lle_X_fwrite(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// char *fgets(char *s, int n, FILE *stream);
|
// char *fgets(char *s, int n, FILE *stream);
|
||||||
GenericValue lle_X_fgets(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 3);
|
assert(Args.size() == 3);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ GenericValue lle_X_fgets(MethodType *M, const vector<GenericValue> &Args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// int fflush(FILE *stream);
|
// int fflush(FILE *stream);
|
||||||
GenericValue lle_X_fflush(MethodType *M, const vector<GenericValue> &Args) {
|
GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
|
||||||
assert(Args.size() == 1);
|
assert(Args.size() == 1);
|
||||||
GenericValue GV;
|
GenericValue GV;
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ bool Interpreter::callMethod(const string &Name) {
|
||||||
std::vector<Value*> Options = LookupMatchingNames(Name);
|
std::vector<Value*> Options = LookupMatchingNames(Name);
|
||||||
|
|
||||||
for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
|
for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
|
||||||
if (!isa<Method>(Options[i])) {
|
if (!isa<Function>(Options[i])) {
|
||||||
Options.erase(Options.begin()+i);
|
Options.erase(Options.begin()+i);
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
@ -226,12 +226,12 @@ bool Interpreter::callMethod(const string &Name) {
|
||||||
if (PickedMeth == 0)
|
if (PickedMeth == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Method *M = cast<Method>(PickedMeth);
|
Function *F = cast<Function>(PickedMeth);
|
||||||
|
|
||||||
std::vector<GenericValue> Args;
|
std::vector<GenericValue> Args;
|
||||||
// TODO, get args from user...
|
// TODO, get args from user...
|
||||||
|
|
||||||
callMethod(M, Args); // Start executing it...
|
callMethod(F, Args); // Start executing it...
|
||||||
|
|
||||||
// Reset the current frame location to the top of stack
|
// Reset the current frame location to the top of stack
|
||||||
CurFrame = ECStack.size()-1;
|
CurFrame = ECStack.size()-1;
|
||||||
|
@ -264,7 +264,7 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||||
std::vector<Value*> Options = LookupMatchingNames(Name);
|
std::vector<Value*> Options = LookupMatchingNames(Name);
|
||||||
|
|
||||||
for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
|
for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
|
||||||
if (!isa<Method>(Options[i])) {
|
if (!isa<Function>(Options[i])) {
|
||||||
Options.erase(Options.begin()+i);
|
Options.erase(Options.begin()+i);
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
@ -274,8 +274,8 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||||
if (PickedMeth == 0)
|
if (PickedMeth == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Method *M = cast<Method>(PickedMeth);
|
Function *M = cast<Function>(PickedMeth);
|
||||||
const MethodType *MT = M->getMethodType();
|
const FunctionType *MT = M->getFunctionType();
|
||||||
|
|
||||||
std::vector<GenericValue> Args;
|
std::vector<GenericValue> Args;
|
||||||
switch (MT->getParamTypes().size()) {
|
switch (MT->getParamTypes().size()) {
|
||||||
|
|
Loading…
Reference in New Issue