@@ -394,7 +394,9 @@ static void usage(const char *argv0) {
394394 llvm::errs ()
395395 << " -pic generate position independent code\n " ;
396396 llvm::errs () << " -run execute the program without "
397- " writing to disk\n " ;
397+ " writing to disk\n "
398+ << " use -- to pass arguments to the "
399+ " program: -run file.crm -- arg1 arg2\n " ;
398400 llvm::errs () << " -timing show timing information\n " ;
399401 llvm::errs () << " -verbose be verbose\n " ;
400402 llvm::errs () << " -full-match-errors show universal patterns in match "
@@ -517,6 +519,8 @@ int main2(int argc, char **argv, char const *const *envp) {
517519 string ceramicScriptImports;
518520 string ceramicScript;
519521
522+ vector<string> programArgs;
523+
520524 vector<string> libSearchPathArgs;
521525 vector<string> libSearchPath;
522526 string linkerFlags;
@@ -794,23 +798,17 @@ int main2(int argc, char **argv, char const *const *envp) {
794798 dependenciesOutputFile = argv[i];
795799 } else if (strcmp (argv[i], " --" ) == 0 ) {
796800 ++i;
797- if (ceramicFile.empty ()) {
798- if (i != argc - 1 ) {
799- llvm::errs ()
800- << " error: ceramic file already specified: " << argv[i]
801- << " , unrecognized parameter: " << argv[i + 1 ] << ' \n ' ;
801+ if (ceramicFile.empty () && ceramicScript.empty ()) {
802+ if (i >= argc) {
803+ llvm::errs () << " error: ceramic file missing after --\n " ;
802804 return 1 ;
803805 }
804806 ceramicFile = argv[i];
805- } else {
806- if (i != argc) {
807- llvm::errs ()
808- << " error: ceramic file already specified: "
809- << ceramicFile
810- << " , unrecognized parameter: " << argv[i] << ' \n ' ;
811- return 1 ;
812- }
807+ ++i;
813808 }
809+ for (; i < argc; ++i)
810+ programArgs.push_back (argv[i]);
811+ break ;
814812 } else if (strcmp (argv[i], " -help" ) == 0 ||
815813 strcmp (argv[i], " --help" ) == 0 ||
816814 strcmp (argv[i], " /?" ) == 0 ) {
@@ -849,6 +847,11 @@ int main2(int argc, char **argv, char const *const *envp) {
849847 }
850848 }
851849
850+ if (!programArgs.empty () && !run) {
851+ llvm::errs () << " error: program arguments after -- require -run\n " ;
852+ return 1 ;
853+ }
854+
852855 if (!ceramicScriptImports.empty () && ceramicScript.empty ()) {
853856 llvm::errs () << " error: -M specified without -e\n " ;
854857 }
@@ -1055,7 +1058,9 @@ int main2(int argc, char **argv, char const *const *envp) {
10551058
10561059 if (run) {
10571060 vector<string> runArgs;
1058- runArgs.push_back (ceramicFile);
1061+ runArgs.push_back (ceramicFile.empty () ? " -e" : ceramicFile);
1062+ runArgs.insert (runArgs.end (), programArgs.begin (),
1063+ programArgs.end ());
10591064 runModule (llvmModule, runArgs, envp, libSearchPath, libraries);
10601065 } else if (repl) {
10611066 // TODO: future me task
0 commit comments