Skip to content

Commit

Permalink
Merge pull request #11 from dkfellows/clone-module
Browse files Browse the repository at this point in the history
Add command for copying a module
  • Loading branch information
dkfellows authored Mar 20, 2018
2 parents 531495f + 7848e2f commit 7658dfa
Showing 1 changed file with 35 additions and 0 deletions.
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

0 comments on commit 7658dfa

Please sign in to comment.