[PATCH] D25929: Add llvm-echo command.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 11:58:32 PDT 2016


ruiu updated this revision to Diff 75925.
ruiu added a comment.

- Reverted a change to TestRunner.py.
- Use llvm::outs() instead of std::cout.


https://reviews.llvm.org/D25929

Files:
  CMakeLists.txt
  utils/llvm-echo/CMakeLists.txt
  utils/llvm-echo/llvm-echo.cpp


Index: utils/llvm-echo/llvm-echo.cpp
===================================================================
--- /dev/null
+++ utils/llvm-echo/llvm-echo.cpp
@@ -0,0 +1,44 @@
+//===- llvm-echo.cpp - The 'echo' command --------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is an implementation of a portable "echo" command.
+// It tokenizes command line arguments in the Unix style even on Windows.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/raw_ostream.h"
+
+#if LLVM_ON_WIN32
+#include <windows.h>
+#endif
+
+using namespace llvm;
+
+int main(int Argc, const char **Argv) {
+  SmallVector<const char *, 4> Args;
+
+#if LLVM_ON_WIN32
+  const char *Cmdline = GetCommandLineA();
+  BumpPtrAllocator Alloc;
+  StringSaver Saver(Alloc);
+  llvm::cl::TokenizeGNUCommandLine(Cmdline, Saver, Args);
+#else
+  Args.insert(Args.begin(), Argv, Argv + Argc);
+#endif
+
+  for (int I = 1, E = Args.size(); I < E; ++I) {
+    if (I != 1)
+      llvm::outs() << " ";
+    llvm::outs() << Args[I];
+  }
+  llvm::outs() << "\n";
+  return 0;
+}
Index: utils/llvm-echo/CMakeLists.txt
===================================================================
--- /dev/null
+++ utils/llvm-echo/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_llvm_utility(llvm-echo llvm-echo.cpp)
+
+target_link_libraries(llvm-echo LLVMSupport)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -782,6 +782,7 @@
   add_subdirectory(utils/PerfectShuffle)
   add_subdirectory(utils/count)
   add_subdirectory(utils/not)
+  add_subdirectory(utils/llvm-echo)
   add_subdirectory(utils/llvm-lit)
   add_subdirectory(utils/yaml-bench)
   add_subdirectory(utils/unittest)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25929.75925.patch
Type: text/x-patch
Size: 2095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161026/89091b80/attachment.bin>


More information about the llvm-commits mailing list