Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Let hermesc output a more helpful message by default
Browse files Browse the repository at this point in the history
Summary:
Before this diff, running `hermesc` reads stdin and then fails
saying execution is unsupported. With this diff, it instead
says to choose output and gives an example.

Reviewed By: avp

Differential Revision: D20967165

fbshipit-source-id: c6349cbaffe1deaa43d7a5344e89f7e07e945c81
  • Loading branch information
willholen authored and facebook-github-bot committed Apr 10, 2020
1 parent a3e5639 commit 181f6c6
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/hermes/CompilerDriver/CompilerDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ struct CompileResult {
/* implicit */ CompileResult(CompileStatus status) : status(status) {}
};

/// Return the type of operation we're about to perform.
OutputFormatKind outputFormatFromCommandLineOptions();

/// Drive the Hermes compiler according to the command line options.
/// \return an exit status.
CompileResult compileFromCommandLineOptions();
Expand Down
3 changes: 3 additions & 0 deletions lib/CompilerDriver/CompilerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,9 @@ void printHermesCompilerVersion(llvm::raw_ostream &s) {
void printHermesREPLVersion(llvm::raw_ostream &s) {
printHermesVersion(s, " REPL", false);
}
OutputFormatKind outputFormatFromCommandLineOptions() {
return cl::DumpTarget;
}

CompileResult compileFromCommandLineOptions() {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/await-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheck --match-full-lines %s

(async await => 3);
// CHECK: {{.*}}:10:8: error: Unexpected usage of 'await' as an identifier
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/binding-error-strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheck --match-full-lines %s
'use strict';

class let {}
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/const-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheck --match-full-lines %s

const abc;
// CHECK: {{.*}}:10:7: error: missing initializer in const declaration
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/export-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc -commonjs -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast -commonjs -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s

export { implements as x };
// CHECK: {{.*}}/export-error.js:10:10: error: Invalid exported name
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/for-of-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheck --match-full-lines %s

function *foo() { for (yield of x) print(1) }
// CHECK: {{.*}}:10:24: error: invalid assignment left-hand side
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/import-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc -commonjs -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast -commonjs -pretty-json %s 2>&1 ) | %FileCheck --match-full-lines %s
'use strict';
import { foo , foo } from 'foo.js';
// CHECK: {{.*}}/import-error.js:10:16: error: Duplicate entry in import declaration list
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/let-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1 ) | %FileCheck --match-full-lines %s
// RUN: (! %hermesc -dump-ast %s 2>&1 ) | %FileCheck --match-full-lines %s

let let = 3;
// CHECK: {{.*}}:10:5: error: 'let' is disallowed as a lexically bound name
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/nullish-coalescing-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s 2>&1) | %FileCheck %s --match-full-lines
// RUN: (! %hermesc -dump-ast %s 2>&1) | %FileCheck %s --match-full-lines

a ?? b && c;
// CHECK: {{.*}}:10:1: error: Mixing '??' with '&&' or '||' requires parentheses
Expand Down
13 changes: 13 additions & 0 deletions tools/hermesc/hermesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ int main(int argc, char **argv) {
llvm::llvm_shutdown_obj Y;
llvm::cl::AddExtraVersionPrinter(driver::printHermesCompilerVersion);
llvm::cl::ParseCommandLineOptions(argc, argv, "Hermes driver\n");

if (driver::outputFormatFromCommandLineOptions() ==
OutputFormatKind::Execute) {
// --help says "Choose output:" so mimic the wording here
llvm::errs()
<< "Please choose output, e.g. -emit-binary. hermesc does not support -exec.\n";
llvm::errs() << "Example: hermesc -emit-binary -out myfile.hbc myfile.js\n";
return EXIT_FAILURE;
}

driver::CompileResult res = driver::compileFromCommandLineOptions();
if (res.bytecodeProvider) {
llvm::errs() << "Execution not supported with hermesc\n";
assert(
false &&
"Execution mode was not checked prior to compileFromCommandLineOptions");
return EXIT_FAILURE;
}
return res.status;
Expand Down

0 comments on commit 181f6c6

Please sign in to comment.