From 8675beae4f7a8415fc2e88451da95dc068719194 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 13 Apr 2010 02:28:56 +0000 Subject: Restructure as a source translation based compiler. Implement support for closures (via lambda lifting phase). git-svn-id: http://svn.drobilla.net/resp/resp@254 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/resp.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/resp.cpp') diff --git a/src/resp.cpp b/src/resp.cpp index 003a76c..89b77ef 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -35,14 +35,15 @@ print_usage(char* name, bool error) os << "Usage: " << name << " [OPTION]... [FILE]..." << endl; os << "Evaluate and/or compile Resp code" << endl; os << endl; - os << " -h Display this help and exit" << endl; - os << " -r Enter REPL after evaluating files" << endl; - os << " -p Pretty-print input only" << endl; - os << " -b BACKEND Backend (llvm or c)" << endl; - os << " -g Debug (disable optimisation)" << endl; - os << " -d Dump assembly output" << endl; - os << " -e EXPRESSION Evaluate EXPRESSION" << endl; - os << " -o FILE Compile output to FILE (don't run)" << endl; + os << " -h Display this help and exit" << endl; + os << " -r Enter REPL after evaluating files" << endl; + os << " -p Pretty-print input only" << endl; + os << " -b BACKEND Use backend (llvm or c)" << endl; + os << " -g Debug (disable optimisation)" << endl; + os << " -d Dump generated code during compilation" << endl; + os << " -S Stop after compilation (output assembler)" << endl; + os << " -e EXPRESSION Evaluate EXPRESSION" << endl; + os << " -o FILE Compile output to FILE (don't run)" << endl; return error ? 1 : 0; } @@ -60,7 +61,8 @@ main(int argc, char** argv) } else if (!strncmp(argv[i], "-r", 3) || !strncmp(argv[i], "-p", 3) || !strncmp(argv[i], "-g", 3) - || !strncmp(argv[i], "-d", 3)) { + || !strncmp(argv[i], "-d", 3) + || !strncmp(argv[i], "-S", 3)) { args.insert(make_pair(argv[i], "")); } else if (i == argc-1 || argv[i+1][0] == '-') { return print_usage(argv[0], true); @@ -131,15 +133,21 @@ main(int argc, char** argv) if (args.find("-r") != args.end() || (files.empty() && args.find("-e") == args.end())) ret = repl(*cenv); - if (output != "") { - ofstream os(output.c_str()); + if (cenv->args.find("-S") != cenv->args.end() || cenv->args.find("-d") != cenv->args.end()) { + ofstream fs; + if (output != "") + fs.open(output.c_str()); + + ostream& os = (output != "") ? fs : cout; + if (os.good()) { cenv->engine()->writeModule(*cenv, os); } else { cerr << argv[0] << ": " << a->second << ": " << strerror(errno) << endl; ++ret; } - os.close(); + if (output != "") + fs.close(); } delete cenv; -- cgit v1.2.1