Skip to content

Commit

Permalink
Add version string to REPL.
Browse files Browse the repository at this point in the history
Summary:
Add the extra version printer from the driver to the REPL.

We link the REPL against the CompilerDriver and disable the "features"
list, which is only useful when running the compiler.

Reviewed By: willholen

Differential Revision: D16224556

fbshipit-source-id: d58a00b745a6608ea39c5d60f6dda5002af289be
  • Loading branch information
avp authored and facebook-github-bot committed Jul 12, 2019
1 parent 4667a8c commit 6472c0f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/hermes/CompilerDriver/CompilerDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ void printHermesCompilerVMVersion(llvm::raw_ostream &s);
/// Print the Hermes version (without VM) to the given stream \p s.
void printHermesCompilerVersion(llvm::raw_ostream &s);

/// Print the Hermes version for the REPL to the given stream \p s.
void printHermesREPLVersion(llvm::raw_ostream &s);

} // namespace driver
} // namespace hermes

Expand Down
19 changes: 14 additions & 5 deletions lib/CompilerDriver/CompilerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,15 +1658,21 @@ CompileResult processSourceFiles(

/// Print the Hermes version to the stream \p s, outputting the \p vmStr (which
/// may be empty).
void printHermesVersion(llvm::raw_ostream &s, const char *vmStr = "") {
/// \param features when true, print the list of enabled features.
void printHermesVersion(
llvm::raw_ostream &s,
const char *vmStr = "",
bool features = true) {
s << "Hermes JavaScript compiler" << vmStr << ".\n"
<< " HBC bytecode version: " << hermes::hbc::BYTECODE_VERSION << "\n"
<< "\n"
<< " Features:\n"
<< "\n";
if (features) {
s << " Features:\n"
#ifdef HERMES_ENABLE_DEBUGGER
<< " Debugger\n"
<< " Debugger\n"
#endif
<< " Zip file input\n";
<< " Zip file input\n";
}
}

} // namespace
Expand All @@ -1680,6 +1686,9 @@ void printHermesCompilerVMVersion(llvm::raw_ostream &s) {
void printHermesCompilerVersion(llvm::raw_ostream &s) {
printHermesVersion(s);
}
void printHermesREPLVersion(llvm::raw_ostream &s) {
printHermesVersion(s, " REPL", false);
}

CompileResult compileFromCommandLineOptions() {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)
Expand Down
1 change: 1 addition & 0 deletions tools/repl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_llvm_tool(hermes-repl

target_link_libraries(hermes-repl
hermesVMRuntime
hermesCompilerDriver
hermesConsoleHost
hermesAST
hermesHBCBackend
Expand Down
2 changes: 2 additions & 0 deletions tools/repl/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"

#include "hermes/CompilerDriver/CompilerDriver.h"
#include "hermes/ConsoleHost/ConsoleHost.h"
#include "hermes/ConsoleHost/RuntimeFlags.h"
#include "hermes/Parser/JSLexer.h"
Expand Down Expand Up @@ -226,6 +227,7 @@ int main(int argc, char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal("Hermes REPL");
llvm::PrettyStackTraceProgram X(argc, argv);
llvm::llvm_shutdown_obj Y;
llvm::cl::AddExtraVersionPrinter(driver::printHermesREPLVersion);
llvm::cl::ParseCommandLineOptions(argc, argv, "Hermes REPL driver\n");

auto runtime = vm::Runtime::create(
Expand Down

0 comments on commit 6472c0f

Please sign in to comment.