int main(int argc, char **argv) {
  llvm::cl::ParseCommandLineOptions(argc, argv);

  if (HuffOnly && CBCOnly) {
    llvm::errs() << "Can't select two compression mode at once." << '\n';
    return EXIT_FAILURE;
  }

  auto input = llvm::MemoryBuffer::getSTDIN();

  if (!input) {
    llvm::errs() << input.getError().message() << '\n';
    return EXIT_FAILURE;
  }

  llvm::StringRef inputContents = input.get()->getBuffer();

  llvm::Regex maybeSymbol("_T[_a-zA-Z0-9$]+");
  llvm::SmallVector<llvm::StringRef, 1> matches;
  while (maybeSymbol.match(inputContents, &matches)) {
    llvm::outs() << substrBefore(inputContents, matches.front());
    llvm::outs() << Compress(matches.front().str(), !DecompressMode);
    inputContents = substrAfter(inputContents, matches.front());
  }
  llvm::outs() << inputContents;

  return EXIT_SUCCESS;
}
Example #2
0
int main(int argc, char **argv) {
#if defined(__CYGWIN__)
  // Cygwin clang 3.5.2 with '-O3' generates CRASHING BINARY,
  // if main()'s first function call is passing argv[0].
  std::rand();
#endif  
  llvm::cl::ParseCommandLineOptions(argc, argv);

  swift::Demangle::DemangleOptions options;
  options.SynthesizeSugarOnTypes = !DisableSugar;
  if (Simplified)
    options = swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions();

  if (InputNames.empty()) {
    CompactMode = true;
    auto input = llvm::MemoryBuffer::getSTDIN();
    if (!input) {
      llvm::errs() << input.getError().message() << '\n';
      return EXIT_FAILURE;
    }
    llvm::StringRef inputContents = input.get()->getBuffer();

    // This doesn't handle Unicode symbols, but maybe that's okay.
    llvm::Regex maybeSymbol("_T[_a-zA-Z0-9$]+");
    llvm::SmallVector<llvm::StringRef, 1> matches;
    while (maybeSymbol.match(inputContents, &matches)) {
      llvm::outs() << substrBefore(inputContents, matches.front());
      demangle(llvm::outs(), matches.front(), options);
      inputContents = substrAfter(inputContents, matches.front());
    }
    llvm::outs() << inputContents;

  } else {
    for (llvm::StringRef name : InputNames) {
      demangle(llvm::outs(), name, options);
      llvm::outs() << '\n';
    }
  }

  return EXIT_SUCCESS;
}
Example #3
0
static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
  // This doesn't handle Unicode symbols, but maybe that's okay.
  // Also accept the future mangling prefix.
  llvm::Regex maybeSymbol("(_T|_?\\$[Ss])[_a-zA-Z0-9$.]+");

  swift::Demangle::Context DCtx;
  for (std::string mangled; std::getline(std::cin, mangled);) {
    llvm::StringRef inputContents(mangled);

    llvm::SmallVector<llvm::StringRef, 1> matches;
    while (maybeSymbol.match(inputContents, &matches)) {
      llvm::outs() << substrBefore(inputContents, matches.front());
      demangle(llvm::outs(), matches.front(), DCtx, options);
      inputContents = substrAfter(inputContents, matches.front());
    }

    llvm::outs() << inputContents << '\n';
  }

  return EXIT_SUCCESS;
}