@@ -2948,68 +2948,72 @@ namespace Cpp {
2948
2948
TInterp_t CreateInterpreter (const std::vector<std::string>& Args,
2949
2949
const std::vector<std::string>& GpuArgs) {
2950
2950
// 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 );
2952
2953
2953
2954
// Construct the resource directory path
2954
2955
std::string ResourceDir = MakeResourcesPath ();
2955
2956
2956
2957
// 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);
2958
2960
2959
- #ifdef _WIN32
2960
- // Add Windows-specific workaround for delayed template parsing
2961
+ #ifdef _WIN32
2962
+ // FIXME : Workaround Sema::PushDeclContext assert on windows
2961
2963
ClingArgv.push_back (" -fno-delayed-template-parsing" );
2962
- #endif
2963
-
2964
- // Append user-provided arguments
2964
+ #endif
2965
2965
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.
2968
2969
if (!GpuArgs.empty ()) {
2969
2970
llvm::StringRef Arg0 = GpuArgs[0 ];
2970
2971
Arg0 = Arg0.trim ().ltrim (' -' );
2971
2972
if (Arg0 != " cuda" ) {
2972
2973
llvm::errs () << " [CreateInterpreter]: Make sure --cuda is passed as the"
2973
- << " first argument of the GpuArgs\n " ;
2974
+ << " first argument of the GpuArgs\n " ;
2974
2975
return nullptr ;
2975
2976
}
2976
2977
}
2977
2978
ClingArgv.insert (ClingArgv.end (), GpuArgs.begin (), GpuArgs.end ());
2978
2979
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" );
2981
2983
if (EnvOpt) {
2982
- llvm:: StringRef Env (*EnvOpt);
2984
+ StringRef Env (*EnvOpt);
2983
2985
while (!Env.empty ()) {
2984
- llvm:: StringRef Arg;
2986
+ StringRef Arg;
2985
2987
std::tie (Arg, Env) = Env.split (' ' );
2986
2988
ClingArgv.push_back (Arg.str ());
2987
2989
}
2988
2990
}
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*>
2991
2992
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 (); });
2995
2996
2996
- // Create the interpreter instance
2997
2997
auto I = new compat::Interpreter (ClingArgvCStr.size (), ClingArgvCStr.data ());
2998
2998
2999
- // Process LLVM-specific arguments
2999
+ // Honor -mllvm.
3000
+ //
3001
+ // FIXME: Remove this, one day.
3002
+ // This should happen AFTER plugins have been loaded!
3000
3003
const CompilerInstance* Clang = I->getCI ();
3001
3004
if (!Clang->getFrontendOpts ().LLVMArgs .empty ()) {
3002
3005
unsigned NumArgs = Clang->getFrontendOpts ().LLVMArgs .size ();
3003
3006
auto Args = std::make_unique<const char *[]>(NumArgs + 2 );
3004
3007
Args[0 ] = " clang (LLVM option parsing)" ;
3005
- for (unsigned i = 0 ; i != NumArgs; ++i) {
3008
+ for (unsigned i = 0 ; i != NumArgs; ++i)
3006
3009
Args[i + 1 ] = Clang->getFrontendOpts ().LLVMArgs [i].c_str ();
3007
- }
3008
3010
Args[NumArgs + 1 ] = nullptr ;
3009
3011
llvm::cl::ParseCommandLineOptions (NumArgs + 1 , Args.get ());
3010
3012
}
3011
3013
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.");
3013
3017
sInterpreter = I;
3014
3018
return I;
3015
3019
}
0 commit comments