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

Add command for copying a module #11

Merged
merged 2 commits into from
Mar 20, 2018
Merged
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
35 changes: 35 additions & 0 deletions generic/llvmtcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,40 @@ GetHostTripleObjCmd(
}

static int
CopyModuleFromModuleCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
if (objc < 2 || objc > 4) {
Tcl_WrongNumArgs(interp, 1, objv, "M ?NewModuleID? ?NewSourceFile?");
return TCL_ERROR;
}
LLVMModuleRef srcmod = 0;
if (GetLLVMModuleRefFromObj(interp, objv[1], srcmod) != TCL_OK)
return TCL_ERROR;
LLVMModuleRef tgtmod = LLVMCloneModule(srcmod);
if (objc > 2) {
std::string tgtid = Tcl_GetString(objv[2]);
llvm::unwrap(tgtmod)->setModuleIdentifier(tgtid);
}
if (objc > 3) {
#ifdef API_4
std::string tgtfile = Tcl_GetString(objv[3]);
llvm::unwrap(tgtmod)->setSourceFileName(tgtfile);
#else // !API_4
LLVMDisposeModule(tgtmod);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"setting source filename not supported in older LLVMs: upgrade to 4.0 or later"));
return TCL_ERROR;
#endif // API_4
}
Tcl_SetObjResult(interp, SetLLVMModuleRefAsObj(interp, tgtmod));
return TCL_OK;
}

static int
CreateModuleFromBitcodeCmd(
ClientData clientData,
Tcl_Interp *interp,
Expand Down Expand Up @@ -1098,6 +1132,7 @@ DLLEXPORT int Llvmtcl_Init(Tcl_Interp *interp)
LLVMObjCmd("llvmtcl::CreateMCJITCompilerForModule",
CreateMCJITCompilerForModuleObjCmd);
LLVMObjCmd("llvmtcl::GetHostTriple", GetHostTripleObjCmd);
LLVMObjCmd("llvmtcl::CopyModuleFromModule", CopyModuleFromModuleCmd);
LLVMObjCmd("llvmtcl::CreateModuleFromBitcode", CreateModuleFromBitcodeCmd);
LLVMObjCmd("llvmtcl::GarbageCollectUnusedFunctionsInModule",
GarbageCollectUnusedFunctionsInModuleCmd);
Expand Down