Skip to content

Commit a5bb010

Browse files
committed
Improved formatting of the code for better readability.
1 parent 72d5c63 commit a5bb010

File tree

1 file changed

+63
-126
lines changed

1 file changed

+63
-126
lines changed

lib/Interpreter/CppInterOp.cpp

+63-126
Original file line numberDiff line numberDiff line change
@@ -2930,69 +2930,6 @@ namespace Cpp {
29302930
std::vector<std::string> GpuArgsStr(GpuArgs.begin(), GpuArgs.end());
29312931
//forwarding to the overloaded implementation
29322932
return CreateInterpreter(ArgsStr, GpuArgsStr);
2933-
2934-
// std::string MainExecutableName =
2935-
// sys::fs::getMainExecutable(nullptr, nullptr);
2936-
// std::string ResourceDir = MakeResourcesPath();
2937-
// std::vector<const char *> ClingArgv = {"-resource-dir", ResourceDir.c_str(),
2938-
// "-std=c++14"};
2939-
// ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
2940-
// #ifdef _WIN32
2941-
// // FIXME : Workaround Sema::PushDeclContext assert on windows
2942-
// ClingArgv.push_back("-fno-delayed-template-parsing");
2943-
// #endif
2944-
// ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
2945-
// // To keep the Interpreter creation interface between cling and clang-repl
2946-
// // to some extent compatible we should put Args and GpuArgs together. On the
2947-
// // receiving end we should check for -xcuda to know.
2948-
// if (!GpuArgs.empty()) {
2949-
// llvm::StringRef Arg0 = GpuArgs[0];
2950-
// Arg0 = Arg0.trim().ltrim('-');
2951-
// if (Arg0 != "cuda") {
2952-
// llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
2953-
// << " first argument of the GpuArgs\n";
2954-
// return nullptr;
2955-
// }
2956-
// }
2957-
// ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
2958-
2959-
// // Process externally passed arguments if present.
2960-
// std::vector<std::string> ExtraArgs;
2961-
// auto EnvOpt =
2962-
// llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
2963-
// if (EnvOpt) {
2964-
// StringRef Env(*EnvOpt);
2965-
// while (!Env.empty()) {
2966-
// StringRef Arg;
2967-
// std::tie(Arg, Env) = Env.split(' ');
2968-
// ExtraArgs.push_back(Arg.str());
2969-
// }
2970-
// }
2971-
// std::transform(ExtraArgs.begin(), ExtraArgs.end(),
2972-
// std::back_inserter(ClingArgv),
2973-
// [&](const std::string& str) { return str.c_str(); });
2974-
2975-
// auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]);
2976-
2977-
// // Honor -mllvm.
2978-
// //
2979-
// // FIXME: Remove this, one day.
2980-
// // This should happen AFTER plugins have been loaded!
2981-
// const CompilerInstance* Clang = I->getCI();
2982-
// if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
2983-
// unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
2984-
// auto Args = std::make_unique<const char*[]>(NumArgs + 2);
2985-
// Args[0] = "clang (LLVM option parsing)";
2986-
// for (unsigned i = 0; i != NumArgs; ++i)
2987-
// Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
2988-
// Args[NumArgs + 1] = nullptr;
2989-
// llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
2990-
// }
2991-
// // FIXME: Enable this assert once we figure out how to fix the multiple
2992-
// // calls to CreateInterpreter.
2993-
// //assert(!sInterpreter && "Interpreter already set.");
2994-
// sInterpreter = I;
2995-
// return I;
29962933
}
29972934

29982935
//Overloaded defination of CreateInterpreter using std::initializer_list
@@ -3004,78 +2941,78 @@ namespace Cpp {
30042941
std::initializer_list<std::string> GpuArgs) {
30052942
return CreateInterpreter(std::vector<std::string>(Args),
30062943
std::vector<std::string>(GpuArgs));
3007-
}
2944+
}
30082945

30092946
//overloaded defination of CreateInterpreter using std::vector<std::string>
30102947
// for Args and GpuArgs
30112948
TInterp_t CreateInterpreter(const std::vector<std::string>& Args,
30122949
const std::vector<std::string>& GpuArgs) {
3013-
// Retrieve the path to the main executable
3014-
std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr);
2950+
// Retrieve the path to the main executable
2951+
std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr);
2952+
2953+
// Construct the resource directory path
2954+
std::string ResourceDir = MakeResourcesPath();
2955+
2956+
// Initialize the argument list for the interpreter
2957+
std::vector<std::string> ClingArgv = {MainExecutableName, "-resource-dir", ResourceDir, "-std=c++14"};
2958+
2959+
#ifdef _WIN32
2960+
// Add Windows-specific workaround for delayed template parsing
2961+
ClingArgv.push_back("-fno-delayed-template-parsing");
2962+
#endif
2963+
2964+
// Append user-provided arguments
2965+
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
2966+
2967+
// Validate and append GPU-specific arguments
2968+
if (!GpuArgs.empty()) {
2969+
llvm::StringRef Arg0 = GpuArgs[0];
2970+
Arg0 = Arg0.trim().ltrim('-');
2971+
if (Arg0 != "cuda") {
2972+
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
2973+
<< " first argument of the GpuArgs\n";
2974+
return nullptr;
2975+
}
2976+
}
2977+
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
30152978

3016-
// Construct the resource directory path
3017-
std::string ResourceDir = MakeResourcesPath();
2979+
// Process additional arguments from the environment variable
2980+
auto EnvOpt = llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
2981+
if (EnvOpt) {
2982+
llvm::StringRef Env(*EnvOpt);
2983+
while (!Env.empty()) {
2984+
llvm::StringRef Arg;
2985+
std::tie(Arg, Env) = Env.split(' ');
2986+
ClingArgv.push_back(Arg.str());
2987+
}
2988+
}
30182989

3019-
// Initialize the argument list for the interpreter
3020-
std::vector<std::string> ClingArgv = {MainExecutableName, "-resource-dir", ResourceDir, "-std=c++14"};
2990+
// Convert std::vector<std::string> to std::vector<const char*> for compatibility
2991+
std::vector<const char*> ClingArgvCStr;
2992+
for (const auto& arg : ClingArgv) {
2993+
ClingArgvCStr.push_back(arg.c_str());
2994+
}
30212995

3022-
#ifdef _WIN32
3023-
// Add Windows-specific workaround for delayed template parsing
3024-
ClingArgv.push_back("-fno-delayed-template-parsing");
3025-
#endif
2996+
// Create the interpreter instance
2997+
auto I = new compat::Interpreter(ClingArgvCStr.size(), ClingArgvCStr.data());
2998+
2999+
// Process LLVM-specific arguments
3000+
const CompilerInstance* Clang = I->getCI();
3001+
if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
3002+
unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
3003+
auto Args = std::make_unique<const char*[]>(NumArgs + 2);
3004+
Args[0] = "clang (LLVM option parsing)";
3005+
for (unsigned i = 0; i != NumArgs; ++i) {
3006+
Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
3007+
}
3008+
Args[NumArgs + 1] = nullptr;
3009+
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
3010+
}
30263011

3027-
// Append user-provided arguments
3028-
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
3029-
3030-
// Validate and append GPU-specific arguments
3031-
if (!GpuArgs.empty()) {
3032-
llvm::StringRef Arg0 = GpuArgs[0];
3033-
Arg0 = Arg0.trim().ltrim('-');
3034-
if (Arg0 != "cuda") {
3035-
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
3036-
<< " first argument of the GpuArgs\n";
3037-
return nullptr;
3038-
}
3039-
}
3040-
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
3041-
3042-
// Process additional arguments from the environment variable
3043-
auto EnvOpt = llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
3044-
if (EnvOpt) {
3045-
llvm::StringRef Env(*EnvOpt);
3046-
while (!Env.empty()) {
3047-
llvm::StringRef Arg;
3048-
std::tie(Arg, Env) = Env.split(' ');
3049-
ClingArgv.push_back(Arg.str());
3050-
}
3051-
}
3052-
3053-
// Convert std::vector<std::string> to std::vector<const char*> for compatibility
3054-
std::vector<const char*> ClingArgvCStr;
3055-
for (const auto& arg : ClingArgv) {
3056-
ClingArgvCStr.push_back(arg.c_str());
3057-
}
3058-
3059-
// Create the interpreter instance
3060-
auto I = new compat::Interpreter(ClingArgvCStr.size(), ClingArgvCStr.data());
3061-
3062-
// Process LLVM-specific arguments
3063-
const CompilerInstance* Clang = I->getCI();
3064-
if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
3065-
unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
3066-
auto Args = std::make_unique<const char*[]>(NumArgs + 2);
3067-
Args[0] = "clang (LLVM option parsing)";
3068-
for (unsigned i = 0; i != NumArgs; ++i) {
3069-
Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
3070-
}
3071-
Args[NumArgs + 1] = nullptr;
3072-
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
3073-
}
3074-
3075-
// Set the global interpreter instance
3076-
sInterpreter = I;
3077-
return I;
3078-
}
3012+
// Set the global interpreter instance
3013+
sInterpreter = I;
3014+
return I;
3015+
}
30793016

30803017
TInterp_t GetInterpreter() { return sInterpreter; }
30813018

0 commit comments

Comments
 (0)