@@ -28,6 +28,9 @@ static llvm::cl::list<std::string>
28
28
llvm::cl::CommaSeparated);
29
29
static llvm::cl::opt<bool > OptHostSupportsJit (" host-supports-jit" ,
30
30
llvm::cl::Hidden);
31
+ static llvm::cl::list<std::string> OptInputs (llvm::cl::Positional,
32
+ llvm::cl::ZeroOrMore,
33
+ llvm::cl::desc (" [code to run]" ));
31
34
32
35
static void LLVMErrorHandler (void *UserData, const std::string &Message,
33
36
bool GenCrashDiag) {
@@ -78,15 +81,22 @@ int main(int argc, const char **argv) {
78
81
static_cast <void *>(&CI->getDiagnostics ()));
79
82
80
83
auto Interp = ExitOnErr (clang::Interpreter::create (std::move (CI)));
81
- llvm::LineEditor LE (" clang-repl" );
82
- // FIXME: Add LE.setListCompleter
83
- while (llvm::Optional<std::string> Line = LE.readLine ()) {
84
- if (*Line == " quit" )
85
- break ;
86
- if (auto Err = Interp->ParseAndExecute (*Line))
84
+ for (const std::string &input : OptInputs) {
85
+ if (auto Err = Interp->ParseAndExecute (input))
87
86
llvm::logAllUnhandledErrors (std::move (Err), llvm::errs (), " error: " );
88
87
}
89
88
89
+ if (OptInputs.empty ()) {
90
+ llvm::LineEditor LE (" clang-repl" );
91
+ // FIXME: Add LE.setListCompleter
92
+ while (llvm::Optional<std::string> Line = LE.readLine ()) {
93
+ if (*Line == " quit" )
94
+ break ;
95
+ if (auto Err = Interp->ParseAndExecute (*Line))
96
+ llvm::logAllUnhandledErrors (std::move (Err), llvm::errs (), " error: " );
97
+ }
98
+ }
99
+
90
100
// Our error handler depends on the Diagnostics object, which we're
91
101
// potentially about to delete. Uninstall the handler now so that any
92
102
// later errors use the default handling behavior instead.
0 commit comments