|
28 | 28 | #include "llvm/Support/ManagedStatic.h" // llvm_shutdown |
29 | 29 | #include "llvm/Support/Signals.h" |
30 | 30 | #include "llvm/Support/TargetSelect.h" |
| 31 | +#include "llvm/Support/raw_ostream.h" |
31 | 32 | #include "llvm/TargetParser/Host.h" |
32 | 33 | #include <optional> |
33 | 34 |
|
@@ -364,15 +365,34 @@ int main(int argc, const char **argv) { |
364 | 365 | } |
365 | 366 |
|
366 | 367 | Input += L; |
| 368 | + // If we add more % commands, there should be better architecture than |
| 369 | + // this. |
367 | 370 | if (Input == R"(%quit)") { |
368 | 371 | break; |
369 | 372 | } |
370 | 373 | if (Input == R"(%undo)") { |
371 | 374 | if (auto Err = Interp->Undo()) |
372 | 375 | llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); |
| 376 | + } else if (Input == R"(%help)") { |
| 377 | + llvm::outs() << "%help\t\tlist clang-repl %commands\n" |
| 378 | + << "%undo\t\tundo the previous input\n" |
| 379 | + << "%lib\t<path>\tlink a dynamic library\n" |
| 380 | + << "%quit\t\texit clang-repl\n"; |
| 381 | + } else if (Input == R"(%lib)") { |
| 382 | + auto Err = llvm::make_error<llvm::StringError>( |
| 383 | + "%lib expects 1 argument: the path to a dynamic library\n", |
| 384 | + std::error_code()); |
| 385 | + llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); |
373 | 386 | } else if (Input.rfind("%lib ", 0) == 0) { |
374 | 387 | if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5)) |
375 | 388 | llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); |
| 389 | + } else if (Input[0] == '%') { |
| 390 | + auto Err = llvm::make_error<llvm::StringError>( |
| 391 | + llvm::formatv( |
| 392 | + "Invalid % command \"{0}\", use \"%help\" to list commands\n", |
| 393 | + Input), |
| 394 | + std::error_code()); |
| 395 | + llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); |
376 | 396 | } else if (auto Err = Interp->ParseAndExecute(Input)) { |
377 | 397 | llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: "); |
378 | 398 | } |
|
0 commit comments