Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32bit #46

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions interpreter/cling/include/cling/Interpreter/RuntimeUniverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,65 @@ namespace cling {
/// when clang emits diagnostics on artificially inserted AST node.
int InterpreterGeneratedCodeDiagnosticsMaybeIncorrect;

///\brief Set the value of the GenericValue for the expression
/// evaluated at the prompt.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [in] value - The float value of the assignment to be stored
/// in GenericValue.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void setValueNoAlloc(void* vpInterp, void* vpQT, float value,
void* vpStoredValRef);

///\brief Set the value of the GenericValue for the expression
/// evaluated at the prompt.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [in] value - The double value of the assignment to be stored
/// in GenericValue.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void setValueNoAlloc(void* vpInterp, void* vpQT, double value,
void* vpStoredValRef);

///\brief Set the value of the GenericValue for the expression
/// evaluated at the prompt.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [in] value - The uint64_t value of the assignment to be stored
/// in GenericValue.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void setValueNoAlloc(void* vpInterp, void* vpQT, unsigned long long value,
void* vpStoredValRef);

///\brief Set the value of the GenericValue for the expression
/// evaluated at the prompt.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [in] value - The int64_t value of the assignment to be stored
/// in GenericValue.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void setValueNoAlloc(void* vpInterp, void* vpQT, long long value,
void* vpStoredValRef);

///\brief Set the value of the GenericValue for the expression
/// evaluated at the prompt.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [in] value - The void* value of the assignment to be stored
/// in GenericValue.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void setValueNoAlloc(void* vpInterp, void* vpQT, void* value,
void* vpStoredValRef);

///\brief Set the value of the Generic value and return the address
/// for the allocated storage space.
///\param [in] vpInterp - The cling::Interpreter for StoredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value.
///\param [out] vpStoredValRef - The StoredValueRef that is created.
void* setValueWithAlloc(Interpreter& interp, void* vpQT,
void* vpStoredValRef);


//__cxa_atexit is declared later for WIN32
#if (!_WIN32)
// Force the module to define __cxa_atexit, we need it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace cling {
void* GetDtorWrapperPtr(clang::CXXRecordDecl* CXXRD);
public:
/// \brief Construct a valid StoredValue, allocating as needed.
StoredValue(Interpreter& interp, clang::QualType clangTy,
const llvm::Type* llvmTy);
StoredValue(Interpreter& interp, clang::QualType clangTy);
/// \brief Destruct and deallocate if necessary.
~StoredValue();

Expand Down Expand Up @@ -64,7 +63,7 @@ namespace cling {
public:
/// \brief Allocate an object of type t and return a StoredValueRef to it.
static StoredValueRef allocate(Interpreter& interp,
clang::QualType t, const llvm::Type* llvmTy);
clang::QualType t);
/// \brief Create a bitwise copy of value wrapped in a StoredValueRef.
static StoredValueRef bitwiseCopy(Interpreter& interp, const cling::Value& value);
/// \brief Create a bitwise copy of svalue.
Expand Down
97 changes: 73 additions & 24 deletions interpreter/cling/lib/Interpreter/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "cling/Interpreter/Interpreter.h" // FIXME: Remove when at_exit is ready

#include "clang/AST/Type.h"
#include "clang/AST/ASTContext.h"
#include "clang/Sema/Sema.h"

#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
Expand Down Expand Up @@ -215,6 +217,8 @@ ExecutionContext::executeFunction(llvm::StringRef funcname,
"could not find function named " << funcname << '\n';
return kExeFunctionNotCompiled;
}
typedef void (*PromptWrapper_t)(void*);
PromptWrapper_t func = (PromptWrapper_t)
m_engine->getPointerToFunction(f);
// check if there is any unresolved symbol in the list
if (!m_unresolvedSymbols.empty()) {
Expand All @@ -234,31 +238,10 @@ ExecutionContext::executeFunction(llvm::StringRef funcname,
return kExeUnresolvedSymbols;
}

std::vector<llvm::GenericValue> args;
bool wantReturn = (returnValue);
StoredValueRef aggregateRet;

if (f->hasStructRetAttr()) {
// Function expects to receive the storage for the returned aggregate as
// first argument. Allocate returnValue:
aggregateRet = StoredValueRef::allocate(interp, retType,
f->getReturnType());
if (returnValue) {
*returnValue = aggregateRet;
} else {
returnValue = &aggregateRet;
}
args.push_back(returnValue->get().getGV());
// will get set as arg0, must not assign.
wantReturn = false;
}

if (wantReturn) {
llvm::GenericValue gvRet = m_engine->runFunction(f, args);
// rescue the ret value (which might be aggregate) from the stack
*returnValue = StoredValueRef::bitwiseCopy(interp, Value(gvRet, retType));
if (!returnValue) {
(*func)(0);
} else {
m_engine->runFunction(f, args);
(*func)(returnValue);
}

return kExeSuccess;
Expand Down Expand Up @@ -420,3 +403,69 @@ ExecutionContext::getPointerToGlobalFromJIT(const llvm::GlobalValue& GV) const {
// Function not yet codegened by the JIT, force this to happen now.
return m_engine->getPointerToGlobal(&GV);
}

namespace {
///\brief Allocate the StoredValueRef and return the GenericValue
/// for an expression evaluated at the prompt.
///
///\param [in] interp - The cling::Interpreter to allocate the SToredValueRef.
///\param [in] vpQT - The opaque ptr for the clang::QualType of value stored.
///\param [out] vpStoredValRef - The StoredValueRef that is allocated.
static llvm::GenericValue& allocateStoredRefValueAndGetGV(Interpreter& interp,
void* vpQT,
void* vpStoredValRef) {
clang::QualType QT = clang::QualType::getFromOpaquePtr(vpQT);
cling::StoredValueRef& SVR = *(cling::StoredValueRef*)vpStoredValRef;
return StoredValueRef::allocate(interp, QT).get().getGV();
}
}

namespace runtime {
namespace internal {
void setValueNoAlloc(void* vpInterp, void* vpStoredValRef, void* vpQT,
float value) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
allocateStoredRefValueAndGetGV(*interp, vpQT,
vpStoredValRef).FloatVal = value;
}
void setValueNoAlloc(void* vpInterp, void* vpStoredValRef, void* vpQT,
double value) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
allocateStoredRefValueAndGetGV(*interp, vpQT,
vpStoredValRef).DoubleVal = value;
}
void setValueNoAlloc(void* vpInterp, void* vpStoredValRef, void* vpQT,
uint64_t value) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
clang::QualType QT = clang::QualType::getFromOpaquePtr(vpQT);
// Unsigned integer types.
allocateStoredRefValueAndGetGV(*interp, vpQT, vpStoredValRef).IntVal =
llvm::APInt(interp->getSema().getASTContext().getTypeSize(QT),
value, false);

}
void setValueNoAlloc(void* vpInterp, void* vpStoredValRef, void* vpQT,
int64_t value) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
clang::QualType QT = clang::QualType::getFromOpaquePtr(vpQT);
// Signed integer types.
allocateStoredRefValueAndGetGV(*interp, vpQT, vpStoredValRef).IntVal =
llvm::APInt(interp->getSema().getASTContext().getTypeSize(QT),
value, true);
}
void setValueNoAlloc(void* vpInterp, void* vpStoredValRef, void* vpQT,
void* value) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
allocateStoredRefValueAndGetGV(*interp, vpQT,
vpStoredValRef).PointerVal = value;
}

void* setValueWithAlloc(void* vpInterp, void* vpQT,
void* vpStoredValRef) {
cling::Interpreter* interp = (cling::Interpreter*)(vpInterp);
return allocateStoredRefValueAndGetGV(*interp, vpQT,
vpStoredValRef).PointerVal;
}
}
}

12 changes: 5 additions & 7 deletions interpreter/cling/lib/Interpreter/StoredValueRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ using namespace clang;
using namespace llvm;

StoredValueRef::StoredValue::StoredValue(Interpreter& interp,
QualType clangTy,
const llvm::Type* llvm_Ty)
: Value(GenericValue(), clangTy, llvm_Ty), m_Interp(interp), m_Mem(0){
QualType clangTy)
: Value(GenericValue(), clangTy), m_Interp(interp), m_Mem(0){
if (clangTy->isIntegralOrEnumerationType() ||
clangTy->isRealFloatingType() ||
clangTy->hasPointerRepresentation()) {
Expand Down Expand Up @@ -134,15 +133,14 @@ void StoredValueRef::dump() const {
valuePrinterInternal::StreamStoredValueRef(llvm::errs(), this, ctx);
}

StoredValueRef StoredValueRef::allocate(Interpreter& interp, QualType t,
const llvm::Type* llvmTy) {
return new StoredValue(interp, t, llvmTy);
StoredValueRef StoredValueRef::allocate(Interpreter& interp, QualType t) {
return new StoredValue(interp, t);
}

StoredValueRef StoredValueRef::bitwiseCopy(Interpreter& interp,
const cling::Value& value) {
StoredValue* SValue
= new StoredValue(interp, value.getClangType(), value.getLLVMType());
= new StoredValue(interp, value.getClangType());
if (SValue->m_Mem) {
const char* src = (const char*)value.getGV().PointerVal;
// It's not a pointer. LLVM stores a char[5] (i.e. 5 x i8) as an i40,
Expand Down