Skip to content

Implement construct and destruct interfaces. #74

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

Merged
merged 2 commits into from
May 8, 2023
Merged
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
15 changes: 15 additions & 0 deletions include/clang/Interpreter/InterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace InterOp {
using TCppFuncAddr_t = void*;
using TCppSema_t = void*;
using TInterp_t = void*;
using TCppObject_t = void*;
typedef void (*CallFuncWrapper_t)(void*, int, void**, void*);

/// Enables or disables the debugging printouts on stderr.
Expand Down Expand Up @@ -243,6 +244,20 @@ namespace InterOp {
}

std::vector<long int> GetDimensions(TCppType_t type);

/// Allocates memory for a given class.
TCppObject_t Allocate(TCppScope_t scope);

/// Deallocates memory for a given class.
void Deallocate(TCppScope_t scope, TCppObject_t address);

/// Creates an object of class \c scope and calls its default constructor. If
/// \c arena is set it uses placement new.
TCppObject_t Construct(TInterp_t interp, TCppScope_t scope,
void* arena = nullptr);

/// Calls the destructor of object of type \c type.
void Destruct(TInterp_t interp, TCppObject_t This, TCppScope_t type);
} // end namespace InterOp

#endif // INTEROP_INTEROP_H
9 changes: 9 additions & 0 deletions include/clang/Interpreter/InterOpInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,20 @@ class Interpreter {
}
}

clang::LangOptions& LO
= const_cast<clang::LangOptions&>(getCompilerInstance()->getLangOpts());
bool SavedAccessControl = LO.AccessControl;
LO.AccessControl = withAccessControl;

if (auto Err = ParseAndExecute(code)) {
LO.AccessControl = SavedAccessControl;
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(),
"Failed to compileFunction: ");
return nullptr;
}

LO.AccessControl = SavedAccessControl;

return getAddressOfGlobal(name);
}

Expand Down
Loading