@@ -2948,68 +2948,72 @@ namespace Cpp {
29482948 TInterp_t CreateInterpreter (const std::vector<std::string>& Args,
29492949 const std::vector<std::string>& GpuArgs) {
29502950 // Retrieve the path to the main executable
2951- std::string MainExecutableName = sys::fs::getMainExecutable (nullptr , nullptr );
2951+ std::string MainExecutableName =
2952+ sys::fs::getMainExecutable (nullptr , nullptr );
29522953
29532954 // Construct the resource directory path
29542955 std::string ResourceDir = MakeResourcesPath ();
29552956
29562957 // Initialize the argument list for the interpreter
2957- std::vector<std::string> ClingArgv = {MainExecutableName, " -resource-dir" , ResourceDir, " -std=c++14" };
2958+ std::vector<std::string> ClingArgv = {" -resource-dir" , ResourceDir, " -std=c++14" };
2959+ ClingArgv.insert (ClingArgv.begin (), MainExecutableName);
29582960
2959- #ifdef _WIN32
2960- // Add Windows-specific workaround for delayed template parsing
2961+ #ifdef _WIN32
2962+ // FIXME : Workaround Sema::PushDeclContext assert on windows
29612963 ClingArgv.push_back (" -fno-delayed-template-parsing" );
2962- #endif
2963-
2964- // Append user-provided arguments
2964+ #endif
29652965 ClingArgv.insert (ClingArgv.end (), Args.begin (), Args.end ());
2966-
2967- // Validate and append GPU-specific arguments
2966+ // To keep the Interpreter creation interface between cling and clang-repl
2967+ // to some extent compatible we should put Args and GpuArgs together. On the
2968+ // receiving end we should check for -xcuda to know.
29682969 if (!GpuArgs.empty ()) {
29692970 llvm::StringRef Arg0 = GpuArgs[0 ];
29702971 Arg0 = Arg0.trim ().ltrim (' -' );
29712972 if (Arg0 != " cuda" ) {
29722973 llvm::errs () << " [CreateInterpreter]: Make sure --cuda is passed as the"
2973- << " first argument of the GpuArgs\n " ;
2974+ << " first argument of the GpuArgs\n " ;
29742975 return nullptr ;
29752976 }
29762977 }
29772978 ClingArgv.insert (ClingArgv.end (), GpuArgs.begin (), GpuArgs.end ());
29782979
2979- // Process additional arguments from the environment variable
2980- auto EnvOpt = llvm::sys::Process::GetEnv (" CPPINTEROP_EXTRA_INTERPRETER_ARGS" );
2980+ // Process externally passed arguments if present.
2981+ auto EnvOpt =
2982+ llvm::sys::Process::GetEnv (" CPPINTEROP_EXTRA_INTERPRETER_ARGS" );
29812983 if (EnvOpt) {
2982- llvm:: StringRef Env (*EnvOpt);
2984+ StringRef Env (*EnvOpt);
29832985 while (!Env.empty ()) {
2984- llvm:: StringRef Arg;
2986+ StringRef Arg;
29852987 std::tie (Arg, Env) = Env.split (' ' );
29862988 ClingArgv.push_back (Arg.str ());
29872989 }
29882990 }
2989-
2990- // Convert std::vector<std::string> to std::vector<const char*> for compatibility
2991+ // Convert std::vector<std::string> to std::vector<const char*>
29912992 std::vector<const char *> ClingArgvCStr;
2992- for ( const auto & arg : ClingArgv) {
2993- ClingArgvCStr. push_back (arg. c_str ());
2994- }
2993+ std::transform ( ClingArgv. begin (), ClingArgv. end (),
2994+ std::back_inserter (ClingArgvCStr),
2995+ []( const std::string& str) { return str. c_str (); });
29952996
2996- // Create the interpreter instance
29972997 auto I = new compat::Interpreter (ClingArgvCStr.size (), ClingArgvCStr.data ());
29982998
2999- // Process LLVM-specific arguments
2999+ // Honor -mllvm.
3000+ //
3001+ // FIXME: Remove this, one day.
3002+ // This should happen AFTER plugins have been loaded!
30003003 const CompilerInstance* Clang = I->getCI ();
30013004 if (!Clang->getFrontendOpts ().LLVMArgs .empty ()) {
30023005 unsigned NumArgs = Clang->getFrontendOpts ().LLVMArgs .size ();
30033006 auto Args = std::make_unique<const char *[]>(NumArgs + 2 );
30043007 Args[0 ] = " clang (LLVM option parsing)" ;
3005- for (unsigned i = 0 ; i != NumArgs; ++i) {
3008+ for (unsigned i = 0 ; i != NumArgs; ++i)
30063009 Args[i + 1 ] = Clang->getFrontendOpts ().LLVMArgs [i].c_str ();
3007- }
30083010 Args[NumArgs + 1 ] = nullptr ;
30093011 llvm::cl::ParseCommandLineOptions (NumArgs + 1 , Args.get ());
30103012 }
30113013
3012- // Set the global interpreter instance
3014+ // FIXME: Enable this assert once we figure out how to fix the multiple
3015+ // calls to CreateInterpreter.
3016+ // assert(!sInterpreter && "Interpreter already set.");
30133017 sInterpreter = I;
30143018 return I;
30153019 }
0 commit comments