This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
334 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <stdarg.h> | ||
#include "codegen/function_wrapper.h" | ||
#include "type/value_factory.h" | ||
#include "type/ephemeral_pool.h" | ||
|
||
namespace peloton { | ||
namespace codegen { | ||
|
||
inline std::vector<peloton::type::Value> GetArguments( | ||
int n_args, va_list &ap) { | ||
std::vector<peloton::type::Value> args; | ||
for (int i = 0; i < n_args; ++i) { | ||
peloton::type::TypeId type_id = peloton::type::TypeId(va_arg(ap, int32_t)); | ||
switch (type_id) { | ||
case peloton::type::TypeId::TINYINT: | ||
args.push_back(peloton::type::ValueFactory::GetTinyIntValue( | ||
va_arg(ap, int32_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::SMALLINT: | ||
args.push_back(peloton::type::ValueFactory::GetSmallIntValue( | ||
va_arg(ap, int32_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::INTEGER: | ||
args.push_back(peloton::type::ValueFactory::GetIntegerValue( | ||
va_arg(ap, int32_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::BIGINT: | ||
args.push_back(peloton::type::ValueFactory::GetBigIntValue( | ||
va_arg(ap, int64_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::DECIMAL: | ||
args.push_back(peloton::type::ValueFactory::GetDecimalValue( | ||
va_arg(ap, double) | ||
)); | ||
break; | ||
case peloton::type::TypeId::DATE: | ||
args.push_back(peloton::type::ValueFactory::GetDateValue( | ||
va_arg(ap, int32_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::TIMESTAMP: | ||
args.push_back(peloton::type::ValueFactory::GetTimestampValue( | ||
va_arg(ap, int64_t) | ||
)); | ||
break; | ||
case peloton::type::TypeId::VARCHAR: | ||
args.push_back(peloton::type::ValueFactory::GetVarcharValue( | ||
va_arg(ap, const char*) | ||
)); | ||
break; | ||
default: | ||
args.push_back(peloton::type::ValueFactory::GetNullValueByType(type_id)); | ||
break; | ||
} | ||
} | ||
return args; | ||
} | ||
|
||
int8_t FunctionWrapper::TinyIntWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int8_t>(); | ||
} | ||
|
||
int16_t FunctionWrapper::SmallIntWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int16_t>(); | ||
} | ||
|
||
int32_t FunctionWrapper::IntegerWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int32_t>(); | ||
} | ||
|
||
int64_t FunctionWrapper::BigIntWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int64_t>(); | ||
} | ||
|
||
double FunctionWrapper::DecimalWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<double>(); | ||
} | ||
|
||
int32_t FunctionWrapper::DateWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int32_t>(); | ||
} | ||
|
||
int64_t FunctionWrapper::TimestampWrapper(int64_t func, int n_args, ...) { | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
return ret.GetAs<int64_t>(); | ||
} | ||
|
||
const char* FunctionWrapper::VarcharWrapper(int64_t func, int n_args, ...) { | ||
// TODO: put this pool to a proper place | ||
static type::EphemeralPool pool; | ||
va_list ap; | ||
va_start(ap, n_args); | ||
std::vector<peloton::type::Value> args = GetArguments(n_args, ap); | ||
peloton::type::Value ret = ((BuiltInFuncType)func)(args); | ||
char* str = static_cast<char*>(pool.Allocate(ret.GetLength())); | ||
strcpy(str, ret.GetData()); | ||
return str; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "codegen/proxy/function_wrapper_proxy.h" | ||
|
||
namespace peloton { | ||
namespace codegen { | ||
|
||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, TinyIntWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, SmallIntWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, IntegerWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, BigIntWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, DecimalWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, DateWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, TimestampWrapper); | ||
DEFINE_METHOD(peloton::codegen, FunctionWrapper, VarcharWrapper); | ||
|
||
} // namespace codegen | ||
} // namespace peloton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "type/types.h" | ||
#include "type/value.h" | ||
|
||
namespace peloton { | ||
namespace codegen { | ||
|
||
class FunctionWrapper { | ||
typedef peloton::type::Value (*BuiltInFuncType)(const std::vector<peloton::type::Value> &); | ||
public: | ||
static int8_t TinyIntWrapper(int64_t func, int n_args, ...); | ||
static int16_t SmallIntWrapper(int64_t func, int n_args, ...); | ||
static int32_t IntegerWrapper(int64_t func, int n_args, ...); | ||
static int64_t BigIntWrapper(int64_t func, int n_args, ...); | ||
static double DecimalWrapper(int64_t func, int n_args, ...); | ||
static int32_t DateWrapper(int64_t func, int n_args, ...); | ||
static int64_t TimestampWrapper(int64_t func, int n_args, ...); | ||
static const char *VarcharWrapper(int64_t func, int n_args, ...); | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "codegen/function_wrapper.h" | ||
#include "codegen/proxy/proxy.h" | ||
#include "codegen/proxy/type_builder.h" | ||
|
||
namespace peloton { | ||
namespace codegen { | ||
|
||
PROXY(FunctionWrapper) { | ||
DECLARE_METHOD(TinyIntWrapper); | ||
DECLARE_METHOD(SmallIntWrapper); | ||
DECLARE_METHOD(IntegerWrapper); | ||
DECLARE_METHOD(BigIntWrapper); | ||
DECLARE_METHOD(DecimalWrapper); | ||
DECLARE_METHOD(DateWrapper); | ||
DECLARE_METHOD(TimestampWrapper); | ||
DECLARE_METHOD(VarcharWrapper); | ||
}; | ||
|
||
} // namespace codegen | ||
} // namespace peloton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.