oil: make ObjectAddr a const reference

This commit is contained in:
Jake Hillion 2023-01-27 04:55:02 -08:00 committed by Jake Hillion
parent ee56decc10
commit fcaede9e7d
5 changed files with 32 additions and 31 deletions

View File

@ -118,7 +118,7 @@ class OILibrary {
private:
class OILibraryImpl *pimpl_;
size_t (*fp)(void *) = nullptr;
size_t (*fp)(const void *) = nullptr;
};
template <class T>
@ -141,7 +141,7 @@ class CodegenHandler {
delete lib;
}
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
static int getObjectSize(const T &ObjectAddr, size_t &ObjectSize) {
OILibrary *lib;
if (int responseCode = getLibrary(lib);
responseCode != Response::OIL_SUCCESS) {
@ -151,7 +151,7 @@ class CodegenHandler {
return lib->getObjectSize((void *)&ObjectAddr, ObjectSize);
}
static int getObjectSize(T &ObjectAddr, size_t &ObjectSize,
static int getObjectSize(const T &ObjectAddr, size_t &ObjectSize,
const options &opts, bool checkOptions = true) {
OILibrary *lib;
if (int responseCode = getLibrary(lib, opts, checkOptions);
@ -196,7 +196,7 @@ class CodegenHandler {
}
curBoxedLib = getLib();
int (*sizeFp)(T &, size_t &) = &getObjectSize;
int (*sizeFp)(const T &, size_t &) = &getObjectSize;
void *typedFp = reinterpret_cast<void *>(sizeFp);
OILibrary *newLib = new OILibrary(typedFp, opts);
@ -230,7 +230,7 @@ class CodegenHandler {
* Ahead-Of-Time (AOT) compilation.
*/
template <class T>
int getObjectSize(T &ObjectAddr, size_t &ObjectSize, const options &opts,
int getObjectSize(const T &ObjectAddr, size_t &ObjectSize, const options &opts,
bool checkOptions = true) {
return CodegenHandler<T>::getObjectSize(ObjectAddr, ObjectSize, opts,
checkOptions);
@ -248,7 +248,8 @@ int getObjectSize(T &ObjectAddr, size_t &ObjectSize, const options &opts,
* production system.
*/
template <class T>
int __attribute__((weak)) getObjectSize(T &ObjectAddr, size_t &ObjectSize) {
int __attribute__((weak))
getObjectSize(const T &ObjectAddr, size_t &ObjectSize) {
#ifdef OIL_AOT_COMPILATION
return Response::OIL_UNINITIALISED;
#else

View File

@ -267,6 +267,28 @@ void FuncGen::DefineTopLevelGetSizeRef(std::string& testCode,
testCode.append(fmt.str());
}
void FuncGen::DefineTopLevelGetSizeRefRet(std::string& testCode,
const std::string& rawType) {
std::string func = R"(
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-attributes"
/* Raw Type: %1% */
size_t __attribute__((used, retain)) getSize(const OIInternal::__ROOT_TYPE__& t)
#pragma GCC diagnostic pop
{
pointers.initialize();
size_t ret = 0;
pointers.add((uintptr_t)&t);
SAVE_DATA((uintptr_t)t);
OIInternal::getSizeType(t, ret);
return ret;
}
)";
boost::format fmt = boost::format(func) % rawType;
testCode.append(fmt.str());
}
void FuncGen::DefineTopLevelGetSizePtr(std::string& testCode,
const std::string& type,
const std::string& rawType) {
@ -299,28 +321,6 @@ void FuncGen::DefineTopLevelGetSizePtr(std::string& testCode,
testCode.append(fmt.str());
}
void FuncGen::DefineTopLevelGetSizePtrRet(std::string& testCode,
const std::string& rawType) {
std::string func = R"(
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-attributes"
/* Raw Type: %1% */
size_t __attribute__((used, retain)) getSize(const OIInternal::__ROOT_TYPE__* t)
#pragma GCC diagnostic pop
{
pointers.initialize();
size_t ret = 0;
pointers.add((uintptr_t)t);
SAVE_DATA((uintptr_t)t);
OIInternal::getSizeType(*t, ret);
return ret;
}
)";
boost::format fmt = boost::format(func) % rawType;
testCode.append(fmt.str());
}
void FuncGen::DefineTopLevelGetSizeSmartPtr(std::string& testCode,
const std::string& rawType) {
std::string func = R"(

View File

@ -61,7 +61,7 @@ class FuncGen {
void DefineTopLevelGetSizeRef(std::string& testCode,
const std::string& rawType);
void DefineTopLevelGetSizePtrRet(std::string& testCode,
void DefineTopLevelGetSizeRefRet(std::string& testCode,
const std::string& type);
void DefineTopLevelGetSizeSmartPtr(std::string& testCode,

View File

@ -3450,7 +3450,7 @@ bool OICodeGen::generateJitCode(std::string &code) {
}
} else {
if (linkageName.empty()) {
funcGen.DefineTopLevelGetSizePtrRet(functionsCode, rawTypeName);
funcGen.DefineTopLevelGetSizeRefRet(functionsCode, rawTypeName);
} else {
funcGen.DefineTopLevelGetObjectSize(functionsCode, rawTypeName,
linkageName);

View File

@ -281,7 +281,7 @@ int OILibraryImpl::compileCode() {
_self->fp = nullptr;
for (const auto &[symName, symAddr] : jitSymbols) {
if (symName.starts_with("_Z7getSize")) {
_self->fp = (size_t(*)(void *))symAddr;
_self->fp = (size_t(*)(const void *))symAddr;
break;
}
}