summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-rc/llvm-rc.cpp
diff options
context:
space:
mode:
authorMarek Sokolowski <mnbvmar@gmail.com>2017-08-10 16:21:44 +0000
committerMarek Sokolowski <mnbvmar@gmail.com>2017-08-10 16:21:44 +0000
commit719e22d4f49c37dbfb4bd2fbcbea03c33ad1200a (patch)
treef17faf8dab71feb605daaf7889dfa9172277380d /llvm/tools/llvm-rc/llvm-rc.cpp
parent27fbd1e14a3710e621f947db932d9353d36c78d1 (diff)
downloadbcm5719-llvm-719e22d4f49c37dbfb4bd2fbcbea03c33ad1200a.tar.gz
bcm5719-llvm-719e22d4f49c37dbfb4bd2fbcbea03c33ad1200a.zip
Add .rc scripts tokenizer.
This extends the shell of llvm-rc tool with the ability of tokenization of the input files. Currently, ASCII and ASCII-compatible UTF-8 files are supported. Thanks to Nico Weber (thakis) for his original work in this area. Differential Revision: https://reviews.llvm.org/D35957 llvm-svn: 310621
Diffstat (limited to 'llvm/tools/llvm-rc/llvm-rc.cpp')
-rw-r--r--llvm/tools/llvm-rc/llvm-rc.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index aa97bf9c0d5..098daba14e2 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -1,4 +1,4 @@
-//===- llvm-rc.cpp - Compile .rc scripts into .res -------------*- C++ -*--===//
+//===-- llvm-rc.cpp - Compile .rc scripts into .res -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//
+#include "ResourceScriptToken.h"
+
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Error.h"
@@ -60,6 +62,12 @@ public:
};
static ExitOnError ExitOnErr;
+
+LLVM_ATTRIBUTE_NORETURN static void fatalError(Twine Message) {
+ errs() << Message << "\n";
+ exit(1);
+}
+
} // anonymous namespace
int main(int argc_, const char *argv_[]) {
@@ -81,8 +89,49 @@ int main(int argc_, const char *argv_[]) {
opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
// The tool prints nothing when invoked with no command-line arguments.
- if (InputArgs.hasArg(OPT_HELP))
+ if (InputArgs.hasArg(OPT_HELP)) {
T.PrintHelp(outs(), "rc", "Resource Converter", false);
+ return 0;
+ }
+
+ const bool BeVerbose = InputArgs.hasArg(OPT_VERBOSE);
+
+ std::vector<std::string> InArgsInfo = InputArgs.getAllArgValues(OPT_INPUT);
+ if (InArgsInfo.size() != 1) {
+ fatalError("Exactly one input file should be provided.");
+ }
+
+ // Read and tokenize the input file.
+ const Twine &Filename = InArgsInfo[0];
+ ErrorOr<std::unique_ptr<MemoryBuffer>> File = MemoryBuffer::getFile(Filename);
+ if (!File) {
+ fatalError("Error opening file '" + Filename +
+ "': " + File.getError().message());
+ }
+
+ std::unique_ptr<MemoryBuffer> FileContents = std::move(*File);
+ StringRef Contents = FileContents->getBuffer();
+
+ std::vector<RCToken> Tokens = ExitOnErr(tokenizeRC(Contents));
+
+ if (BeVerbose) {
+ const Twine TokenNames[] = {
+#define TOKEN(Name) #Name,
+#define SHORT_TOKEN(Name, Ch) #Name,
+#include "ResourceScriptTokenList.h"
+#undef TOKEN
+#undef SHORT_TOKEN
+ };
+
+ for (const RCToken &Token : Tokens) {
+ outs() << TokenNames[static_cast<int>(Token.kind())] << ": "
+ << Token.value();
+ if (Token.kind() == RCToken::Kind::Int)
+ outs() << "; int value = " << Token.intValue();
+
+ outs() << "\n";
+ }
+ }
return 0;
}
OpenPOWER on IntegriCloud