int main(int argc, const char **argv) {
  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);

  CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory);

  if (!Commands.empty() && !CommandFiles.empty()) {
    llvm::errs() << argv[0] << ": cannot specify both -c and -f\n";
    return 1;
  }

  ClangTool Tool(OptionsParser.getCompilations(),
                 OptionsParser.getSourcePathList());
  std::vector<std::unique_ptr<ASTUnit>> ASTs;
  if (Tool.buildASTs(ASTs) != 0)
    return 1;

  QuerySession QS(ASTs);

  if (!Commands.empty()) {
    for (cl::list<std::string>::iterator I = Commands.begin(),
                                         E = Commands.end();
         I != E; ++I) {
      QueryRef Q = QueryParser::parse(*I, QS);
      if (!Q->run(llvm::outs(), QS))
        return 1;
    }
  } else if (!CommandFiles.empty()) {
    for (cl::list<std::string>::iterator I = CommandFiles.begin(),
                                         E = CommandFiles.end();
         I != E; ++I) {
      std::ifstream Input(I->c_str());
      if (!Input.is_open()) {
        llvm::errs() << argv[0] << ": cannot open " << *I << "\n";
        return 1;
      }
      while (Input.good()) {
        std::string Line;
        std::getline(Input, Line);

        QueryRef Q = QueryParser::parse(Line, QS);
        if (!Q->run(llvm::outs(), QS))
          return 1;
      }
    }
  } else {
    LineEditor LE("clang-query");
    LE.setListCompleter([&QS](StringRef Line, size_t Pos) {
      return QueryParser::complete(Line, Pos, QS);
    });
    while (llvm::Optional<std::string> Line = LE.readLine()) {
      QueryRef Q = QueryParser::parse(*Line, QS);
      Q->run(llvm::outs(), QS);
      llvm::outs().flush();
      if (QS.Terminate)
        break;
    }
  }

  return 0;
}
// BuildLinkItems -- This function generates a LinkItemList for the LinkItems
// linker function by combining the Files and Libraries in the order they were
// declared on the command line.
static void BuildLinkItems(
  Linker::ItemList& Items,
  const cl::list<std::string>& Files,
  const cl::list<std::string>& Libraries) {

  // Build the list of linkage items for LinkItems.

  cl::list<std::string>::const_iterator fileIt = Files.begin();
  cl::list<std::string>::const_iterator libIt  = Libraries.begin();

  int libPos = -1, filePos = -1;
  while ( libIt != Libraries.end() || fileIt != Files.end() ) {
    if (libIt != Libraries.end())
      libPos = Libraries.getPosition(libIt - Libraries.begin());
    else
      libPos = -1;
    if (fileIt != Files.end())
      filePos = Files.getPosition(fileIt - Files.begin());
    else
      filePos = -1;

    if (filePos != -1 && (libPos == -1 || filePos < libPos)) {
      // Add a source file
      Items.push_back(std::make_pair(*fileIt++, false));
    } else if (libPos != -1 && (filePos == -1 || libPos < filePos)) {
      // Add a library
      Items.push_back(std::make_pair(*libIt++, true));
    }
  }
}
Esempio n. 3
0
InternalizePass::InternalizePass()
  : ModulePass(ID) {
  initializeInternalizePassPass(*PassRegistry::getPassRegistry());
  if (!APIFile.empty())           // If a filename is specified, use it.
    LoadFile(APIFile.c_str());
  ExternalNames.insert(APIList.begin(), APIList.end());
  DSONames.insert(DSOList.begin(), DSOList.end());
}
Esempio n. 4
0
    virtual bool
    runOnModule(Module& M)
    {
      AliasAnalysis& aa = this->getAnalysis<AliasAnalysis>();
      bool checked = false;

      errs() <<  "GatherInterfacePass::runOnModule: " << M.getModuleIdentifier() << "\n";
      
      if (!GatherInterfaceMain.empty()) {
        checked = true;
        for (cl::list<std::string>::const_iterator i = GatherInterfaceMain.begin(), e = GatherInterfaceMain.end();
            i != e; ++i) {
          Function* f = M.getFunction(*i);
          if (f == NULL) {
            errs() << "Function '" << *i << "' not found, skipping\n";
            continue;
          }
          if (f->isDeclaration()) {
            errs() << "Function '" << *i << "' is declaration, skipping\n";
            continue;
          }
          errs() << "Gathering from: " << *f << "\n";
          GatherInterface(*f, this->interface, &aa);
        }
      }
      if (!GatherInterfaceEntry.empty()) {
        checked = true;
        ComponentInterface ci;
        for (cl::list<std::string>::const_iterator i = GatherInterfaceEntry.begin(), e = GatherInterfaceEntry.end();
              i != e; ++i) {
          errs() << "Reading interface from '" << *i << "'...";
          if (ci.readFromFile(*i)) {
            errs() << "success\n";
          } else {
            errs() << "failed\n";
            continue;
          }
        }
        for (ComponentInterface::FunctionIterator i = ci.begin(), e = ci.end(); i != e; ++i) {
          Function* f = M.getFunction(i->first());
          if (f == NULL) continue;
          if (!GatherInterface(*f, this->interface, &aa)) break;
        }
      }
      if (!checked) {
        GatherInterface(M, this->interface, &aa);
      }

      if (GatherInterfaceOutput != "") {
        proto::ComponentInterface ci;
        codeInto<ComponentInterface, proto::ComponentInterface> (
            this->interface, ci);
        std::ofstream output(GatherInterfaceOutput.c_str(), std::ios::binary);
        assert(ci.SerializeToOstream(&output));
        output.close();
      }
      return false;
    }
Esempio n. 5
0
// Helper function used by Build().
// Traverses initial portions of the toolchains (up to the first Join node).
// This function is also responsible for handling the -x option.
void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
                                     const sys::Path& TempDir) {
    // This is related to -x option handling.
    cl::list<std::string>::const_iterator xIter = Languages.begin(),
                                          xBegin = xIter, xEnd = Languages.end();
    bool xEmpty = true;
    const std::string* xLanguage = 0;
    unsigned xPos = 0, xPosNext = 0, filePos = 0;

    if (xIter != xEnd) {
        xEmpty = false;
        xPos = Languages.getPosition(xIter - xBegin);
        cl::list<std::string>::const_iterator xNext = llvm::next(xIter);
        xPosNext = (xNext == xEnd) ? std::numeric_limits<unsigned>::max()
                   : Languages.getPosition(xNext - xBegin);
        xLanguage = (*xIter == "none") ? 0 : &(*xIter);
    }

    // For each input file:
    for (cl::list<std::string>::const_iterator B = InputFilenames.begin(),
            CB = B, E = InputFilenames.end(); B != E; ++B) {
        sys::Path In = sys::Path(*B);

        // Code for handling the -x option.
        // Output: std::string* xLanguage (can be NULL).
        if (!xEmpty) {
            filePos = InputFilenames.getPosition(B - CB);

            if (xPos < filePos) {
                if (filePos < xPosNext) {
                    xLanguage = (*xIter == "none") ? 0 : &(*xIter);
                }
                else { // filePos >= xPosNext
                    // Skip xIters while filePos > xPosNext
                    while (filePos > xPosNext) {
                        ++xIter;
                        xPos = xPosNext;

                        cl::list<std::string>::const_iterator xNext = llvm::next(xIter);
                        if (xNext == xEnd)
                            xPosNext = std::numeric_limits<unsigned>::max();
                        else
                            xPosNext = Languages.getPosition(xNext - xBegin);
                        xLanguage = (*xIter == "none") ? 0 : &(*xIter);
                    }
                }
            }
        }

        // Find the toolchain corresponding to this file.
        const Node* N = FindToolChain(In, xLanguage, InLangs);
        // Pass file through the chain starting at head.
        PassThroughGraph(In, N, InLangs, TempDir);
    }
}
Esempio n. 6
0
int main(int argc, char **argv) {
  // Print a stack trace if we signal out.
  sys::PrintStackTraceOnErrorSignal();
  PrettyStackTraceProgram X(argc, argv);

  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
  cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");

  ToolName = argv[0];
  if (OutputFormatShort.getNumOccurrences())
    OutputFormat = OutputFormatShort;
  if (RadixShort.getNumOccurrences())
    Radix = RadixShort;

  if (InputFilenames.size() == 0)
    InputFilenames.push_back("a.out");

  if (OutputFormat == berkeley)
    outs() << "   text    data     bss     "
           << (Radix == octal ? "oct" : "dec")
           << "     hex filename\n";

  std::for_each(InputFilenames.begin(), InputFilenames.end(),
                PrintFileSectionSizes);

  return 0;
}
Esempio n. 7
0
int main(int argc, char **argv) {
  llvm::sys::PrintStackTraceOnErrorSignal();
  llvm::PrettyStackTraceProgram X(argc, argv);
  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
  cl::ParseCommandLineOptions(argc, argv,
                              "LLVM automatic testcase reducer. See\nhttp://"
                              "llvm.org/cmds/bugpoint.html"
                              " for more information.\n");
  sys::SetInterruptFunction(BugpointInterruptFunction);
  
  BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
  if (D.addSources(InputFilenames)) return 1;
  D.addPasses(PassList.begin(), PassList.end());

  // Bugpoint has the ability of generating a plethora of core files, so to
  // avoid filling up the disk, we prevent it
  sys::Process::PreventCoreFiles();

  try {
    return D.run();
  } catch (ToolExecutionError &TEE) {
    std::cerr << "Tool execution error: " << TEE.what() << '\n';
  } catch (const std::string& msg) {
    std::cerr << argv[0] << ": " << msg << "\n";
  } catch (...) {
    std::cerr << "Whoops, an exception leaked out of bugpoint.  "
              << "This is a bug in bugpoint!\n";
  }
  return 1;
}
Esempio n. 8
0
bool DefineExtsPass::runOnModule(Module& M) {

  bool modified = false;

  for(cl::list<std::string>::iterator it = NullSymbols.begin(), it2 = NullSymbols.end(); it != it2; ++it) {

    GlobalValue* GV = M.getNamedValue(*it);
    if(!GV) {

      errs() << "Warning: skipped value " << *it << " (symbol not found)\n";
      continue;

    }
    
    if(Function* F = dyn_cast<Function>(GV)) {
      if(!F->isDeclaration()) {

	errs() << "Warning: skipped function " << *it << " because it has a definition\n";
	continue;

      }
    }

    GV->replaceAllUsesWith(Constant::getNullValue(GV->getType()));
    modified = true;

  }

  return modified;

}
Esempio n. 9
0
bool Preparer::runOnModule(Module &M) {
  IdentifyThreadFuncs &ITF = getAnalysis<IdentifyThreadFuncs>();

  for (cl::list<string>::const_iterator itr = OtherThreadFunctions.begin();
       itr != OtherThreadFunctions.end(); ++itr) {
    DEBUG(dbgs() << "Other thread functions: " << *itr << "\n";);
  }
Esempio n. 10
0
int main(int argc, char **argv) {
  // Print a stack trace if we signal out.
  sys::PrintStackTraceOnErrorSignal();
  PrettyStackTraceProgram X(argc, argv);

  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
  cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");

  ToolName = argv[0];
  if (OutputFormatShort.getNumOccurrences())
    OutputFormat = OutputFormatShort;
  if (RadixShort.getNumOccurrences())
    Radix = RadixShort;

  for (unsigned i = 0; i < ArchFlags.size(); ++i) {
    if (ArchFlags[i] == "all") {
      ArchAll = true;
    } else {
      if (!MachOObjectFile::isValidArch(ArchFlags[i])) {
        outs() << ToolName << ": for the -arch option: Unknown architecture "
               << "named '" << ArchFlags[i] << "'";
        return 1;
      }
    }
  }

  if (InputFilenames.size() == 0)
    InputFilenames.push_back("a.out");

  moreThanOneFile = InputFilenames.size() > 1;
  std::for_each(InputFilenames.begin(), InputFilenames.end(),
                PrintFileSectionSizes);

  return 0;
}
/// EmitShellScript - Output the wrapper file that invokes the JIT on the LLVM
/// bytecode file for the program.
static void EmitShellScript(char **argv) {
  if (Verbose)
    cout << "Emitting Shell Script\n";
#if defined(_WIN32) || defined(__CYGWIN__)
  // Windows doesn't support #!/bin/sh style shell scripts in .exe files.  To
  // support windows systems, we copy the llvm-stub.exe executable from the
  // build tree to the destination file.
  std::string ErrMsg;  
  sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
  if (llvmstub.isEmpty())
    PrintAndExit("Could not find llvm-stub.exe executable!");

  if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg))
    PrintAndExit(ErrMsg);

  return;
#endif

  // Output the script to start the program...
  std::ofstream Out2(OutputFilename.c_str());
  if (!Out2.good())
    PrintAndExit("error opening '" + OutputFilename + "' for writing!");

  Out2 << "#!/bin/sh\n";
  // Allow user to setenv LLVMINTERP if lli is not in their PATH.
  Out2 << "lli=${LLVMINTERP-lli}\n";
  Out2 << "exec $lli \\\n";
  // gcc accepts -l<lib> and implicitly searches /lib and /usr/lib.
  LibPaths.push_back("/lib");
  LibPaths.push_back("/usr/lib");
  LibPaths.push_back("/usr/X11R6/lib");
  // We don't need to link in libc! In fact, /usr/lib/libc.so may not be a
  // shared object at all! See RH 8: plain text.
  std::vector<std::string>::iterator libc =
    std::find(Libraries.begin(), Libraries.end(), "c");
  if (libc != Libraries.end()) Libraries.erase(libc);
  // List all the shared object (native) libraries this executable will need
  // on the command line, so that we don't have to do this manually!
  for (std::vector<std::string>::iterator i = Libraries.begin(),
         e = Libraries.end(); i != e; ++i) {
    sys::Path FullLibraryPath = sys::Path::FindLibrary(*i);
    if (!FullLibraryPath.isEmpty() && FullLibraryPath.isDynamicLibrary())
      Out2 << "    -load=" << FullLibraryPath.toString() << " \\\n";
  }
  Out2 << "    $0.bc ${1+\"$@\"}\n";
  Out2.close();
}
Esempio n. 12
0
// getRelPos - Extract the member filename from the command line for
// the [relpos] argument associated with a, b, and i modifiers
void getRelPos() {
    if(RestOfArgs.size() > 0) {
        RelPos = RestOfArgs[0];
        RestOfArgs.erase(RestOfArgs.begin());
    }
    else
        throw "Expected [relpos] for a, b, or i modifier";
}
Esempio n. 13
0
bool Preparer::is_specified_thread_function(const Function *f) const {
  for (cl::list<string>::const_iterator itr = OtherThreadFunctions.begin();
       itr != OtherThreadFunctions.end(); ++itr) {
    if (f->getName() == *itr)
      return true;
  }
  return false;
}
Esempio n. 14
0
// getArchive - Get the archive file name from the command line
void getArchive() {
    if(RestOfArgs.size() > 0) {
        ArchiveName = RestOfArgs[0];
        RestOfArgs.erase(RestOfArgs.begin());
    }
    else
        throw "An archive name must be specified.";
}
Esempio n. 15
0
InternalizePass::InternalizePass(bool AllButMain)
  : ModulePass(ID), AllButMain(AllButMain){
  initializeInternalizePassPass(*PassRegistry::getPassRegistry());
  if (!APIFile.empty())           // If a filename is specified, use it.
    LoadFile(APIFile.c_str());
  if (!APIList.empty())           // If a list is specified, use it as well.
    ExternalNames.insert(APIList.begin(), APIList.end());
}
Esempio n. 16
0
// Try to find the first match in buffer for any prefix. If a valid match is
// found, return that prefix and set its type and location.  If there are almost
// matches (e.g. the actual prefix string is found, but is not an actual check
// string), but no valid match, return an empty string and set the position to
// resume searching from. If no partial matches are found, return an empty
// string and the location will be StringRef::npos. If one prefix is a substring
// of another, the maximal match should be found. e.g. if "A" and "AA" are
// prefixes then AA-CHECK: should match the second one.
static StringRef FindFirstCandidateMatch(StringRef &Buffer,
                                         Check::CheckType &CheckTy,
                                         size_t &CheckLoc) {
  StringRef FirstPrefix;
  size_t FirstLoc = StringRef::npos;
  size_t SearchLoc = StringRef::npos;
  Check::CheckType FirstTy = Check::CheckNone;

  CheckTy = Check::CheckNone;
  CheckLoc = StringRef::npos;

  for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end();
       I != E; ++I) {
    StringRef Prefix(*I);
    size_t PrefixLoc = Buffer.find(Prefix);

    if (PrefixLoc == StringRef::npos)
      continue;

    // Track where we are searching for invalid prefixes that look almost right.
    // We need to only advance to the first partial match on the next attempt
    // since a partial match could be a substring of a later, valid prefix.
    // Need to skip to the end of the word, otherwise we could end up
    // matching a prefix in a substring later.
    if (PrefixLoc < SearchLoc)
      SearchLoc = SkipWord(Buffer, PrefixLoc);

    // We only want to find the first match to avoid skipping some.
    if (PrefixLoc > FirstLoc)
      continue;
    // If one matching check-prefix is a prefix of another, choose the
    // longer one.
    if (PrefixLoc == FirstLoc && Prefix.size() < FirstPrefix.size())
      continue;

    StringRef Rest = Buffer.drop_front(PrefixLoc);
    // Make sure we have actually found the prefix, and not a word containing
    // it. This should also prevent matching the wrong prefix when one is a
    // substring of another.
    if (PrefixLoc != 0 && IsPartOfWord(Buffer[PrefixLoc - 1]))
      FirstTy = Check::CheckNone;
    else
      FirstTy = FindCheckType(Rest, Prefix);

    FirstLoc = PrefixLoc;
    FirstPrefix = Prefix;
  }

  // If the first prefix is invalid, we should continue the search after it.
  if (FirstTy == Check::CheckNone) {
    CheckLoc = SearchLoc;
    return "";
  }

  CheckTy = FirstTy;
  CheckLoc = FirstLoc;
  return FirstPrefix;
}
Esempio n. 17
0
int main(int argc, const char **argv) {
    CommonOptionsParser OptionsParser(argc, argv, NoGlobalStyleCategory);
    ClangTool Tool(OptionsParser.getCompilations(),
                   OptionsParser.getSourcePathList());
    
    MatchFinder finder;

    // Snarf abstract-only namespaces from the environment.
    std::vector<std::string> abstract_namespaces_v, banned_namespaces_v;
    std::copy(abstract_namespaces.begin(), abstract_namespaces.end(), std::back_inserter(abstract_namespaces_v));
    std::copy(banned_namespaces.begin(), banned_namespaces.end(), std::back_inserter(banned_namespaces_v));
    std::unique_ptr<RuleCheckerBase> rules[] = {
        make_unique<DisallowNew>(),
        make_unique<DisallowDelete>(),
        make_unique<DisallowGlobals>(),
        make_unique<DisallowNonAbstract>(abstract_namespaces_v),
        make_unique<DisallowCoupling>(banned_namespaces_v)
    };
    size_t rules_size = sizeof(rules) / sizeof(rules[0]);
    auto rules_begin = &rules[0];
    auto rules_end = &rules[rules_size];

    std::vector<std::string> analyze_paths_v;
    std::copy(analyze_paths.begin(), analyze_paths.end(), std::back_inserter(analyze_paths_v));

    for (size_t i = 0; i < sizeof(rules) / sizeof(rules[0]); ++i) {
        auto &rule = rules[i];
        rule->setAnalyzePaths(analyze_paths_v);
        rule->SetupMatches(finder);
        rule->getPrinter().setDebug(Debug.getValue());
    }
    
#ifndef NDEBUG
    llvm::DebugFlag = Debug.getValue();
#endif

    return Tool.run(newFrontendActionFactory(&finder).get()) || 
        (Werror.getValue() && 
         std::any_of
         (rules_begin, rules_end, 
          [] (const std::unique_ptr<RuleCheckerBase> &rule) {
             return rule->getPrinter().getWarnings();
         }));
}
Esempio n. 18
0
File: Jade.cpp Progetto: orcc/jade
void setTraces(Network* network){
    std::list<Instance*>::iterator it;
    std::list<Instance*>* instances = network->getInstances();

    bool traceAll = false;

    // Check if "all" option is activate
    if (debexec.begin()->compare("all")==0){
        traceAll = true;
    }

    for (it = instances->begin(); it != instances->end(); it++){
        Instance* instance = *it;

        if (traceAll || (debexec.end() != find(debexec.begin(), debexec.end(), instance->getId()))){
            instance->setTrace(true);
        }
    }
}
Esempio n. 19
0
// getCount - Extract the [count] argument associated with the N modifier
// from the command line and check its value.
void getCount() {
  if(RestOfArgs.size() == 0)
    show_help("Expected [count] value with N modifier");

  Count = atoi(RestOfArgs[0].c_str());
  RestOfArgs.erase(RestOfArgs.begin());

  // Non-positive counts are not allowed
  if (Count < 1)
    show_help("Invalid [count] value (not a positive integer)");
}
Esempio n. 20
0
// Determine whether the inliner will be run.
bool willInline() {
    if (doInline())
        return true;
    // It may also have been specified explicitly on the command line as an explicit pass
    typedef cl::list<const PassInfo*, bool, PassNameParser> PL;
    for (PL::iterator I = passList.begin(), E = passList.end(); I != E; ++I) {
        if (!std::strcmp((*I)->getPassArgument(), "inline"))
            return true;
    }
    return false;
}
Esempio n. 21
0
// getCount - Extract the [count] argument associated with the N modifier
// from the command line and check its value.
void getCount() {
    if(RestOfArgs.size() > 0) {
        Count = atoi(RestOfArgs[0].c_str());
        RestOfArgs.erase(RestOfArgs.begin());
    }
    else
        throw "Expected [count] value with N modifier";

    // Non-positive counts are not allowed
    if (Count < 1)
        throw "Invalid [count] value (not a positive integer)";
}
Esempio n. 22
0
int main(int argc, char **argv) {
  // The command line is unusual compared to other fuzzers due to the need to
  // specify the target. Options like -triple, -mcpu, and -mattr work like
  // their counterparts in llvm-mc, while -fuzzer-args collects options for the
  // fuzzer itself.
  //
  // Examples:
  //
  // Fuzz the big-endian MIPS32R6 disassembler using 100,000 inputs of up to
  // 4-bytes each and use the contents of ./corpus as the test corpus:
  //   llvm-mc-fuzzer -triple mips-linux-gnu -mcpu=mips32r6 -disassemble \
  //       -fuzzer-args -max_len=4 -runs=100000 ./corpus
  //
  // Infinitely fuzz the little-endian MIPS64R2 disassembler with the MSA
  // feature enabled using up to 64-byte inputs:
  //   llvm-mc-fuzzer -triple mipsel-linux-gnu -mcpu=mips64r2 -mattr=msa \
  //       -disassemble -fuzzer-args ./corpus
  //
  // If your aim is to find instructions that are not tested, then it is
  // advisable to constrain the maximum input size to a single instruction
  // using -max_len as in the first example. This results in a test corpus of
  // individual instructions that test unique paths. Without this constraint,
  // there will be considerable redundancy in the corpus.

  LLVMInitializeAllTargetInfos();
  LLVMInitializeAllTargetMCs();
  LLVMInitializeAllDisassemblers();

  cl::ParseCommandLineOptions(argc, argv);

  // Package up features to be passed to target/subtarget
  // We have to pass it via a global since the callback doesn't
  // permit any user data.
  if (MAttrs.size()) {
    SubtargetFeatures Features;
    for (unsigned i = 0; i != MAttrs.size(); ++i)
      Features.AddFeature(MAttrs[i]);
    FeaturesStr = Features.getString();
  }

  // Insert the program name into the FuzzerArgv.
  FuzzerArgv.insert(FuzzerArgv.begin(), argv[0]);

  if (Action == AC_Assemble)
    errs() << "error: -assemble is not implemented\n";
  else if (Action == AC_Disassemble)
    return fuzzer::FuzzerDriver(FuzzerArgv, DisassembleOneInput);

  llvm_unreachable("Unknown action");
  return 1;
}
Esempio n. 23
0
static bool ValidateCheckPrefixes() {
  StringSet<> PrefixSet;

  for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end();
       I != E; ++I) {
    StringRef Prefix(*I);

    if (!PrefixSet.insert(Prefix))
      return false;

    if (!ValidateCheckPrefix(Prefix))
      return false;
  }

  return true;
}
Esempio n. 24
0
int main(int argc, char **argv) {
  // Print a stack trace if we signal out.
  sys::PrintStackTraceOnErrorSignal();
  PrettyStackTraceProgram X(argc, argv);
  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.

  cl::ParseCommandLineOptions(argc, argv, "llvm dwarf dumper\n");

  // Defaults to a.out if no filenames specified.
  if (InputFilenames.size() == 0)
    InputFilenames.push_back("a.out");

  std::for_each(InputFilenames.begin(), InputFilenames.end(), DumpInput);

  return 0;
}
Esempio n. 25
0
int main(int argc, char **argv) {
  // Print a stack trace if we signal out.
  sys::PrintStackTraceOnErrorSignal();
  PrettyStackTraceProgram X(argc, argv);

  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
  cl::ParseCommandLineOptions(argc, argv, "llvm MC markup parser\n");

  ToolName = argv[0];

  // If no input files specified, read from stdin.
  if (InputFilenames.size() == 0)
    InputFilenames.push_back("-");

  std::for_each(InputFilenames.begin(), InputFilenames.end(),
                parseMCMarkup);
  return 0;
}
Esempio n. 26
0
bool Mutator::runOnModule(Module &M) {
	
  unsigned siteId = 0;
  
  OperatorManager   *OMgr = OperatorManager::getInstance();
  OperatorInfoList  oplst;

  // Loop through all functions within module
  for (Module::iterator F = M.begin(), ME = M.end(); F != ME; ++F) {	
    // Loop through all basic blocks within function
    for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {
      // Loop through all instructions within basic block
      for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE; I++) {
        // Consider only mutable instructions
        OMgr->getCompatibleOperators(I, oplst);
        
        bool mutated = false;
        for (OperatorInfoList::iterator opi = oplst.begin(); opi != oplst.end(); opi++) {
          cl::list<unsigned>::iterator sid = find (MutationIDS.begin(), MutationIDS.end(), siteId++);
          if (sid != MutationIDS.end()) {
            // One of the specified mutations was found
            if (!mutated) {
              MutationOperator *op = (*opi)->build();
              Value *newv = op->apply(I);
              //cerr << *I << " --> " << *newv << "\n";
              
              if (newv != NULL) {
                  ReplaceInstWithValue(B->getInstList(), I, newv);
              } else {
                  
              }
              mutated = true;
            } else {
              throw std::string("An instruction is being mutated twice! Aborting...");
            }
          }
		}
      }
    }
  }
  
  // notify change of program 
  return true;
}
Esempio n. 27
0
    RewriteComponentPass() :
        ModulePass(ID), transform()
    {

        errs() << "RewriteComponentPass()\n";

        for (cl::list<std::string>::const_iterator b = RewriteComponentInput.begin(), e = RewriteComponentInput.end();
                b != e; ++b) {
            errs() << "Reading file '" << *b << "'...";
            if (transform.readTransformFromFile(*b)) {
                errs() << "success\n";
            } else {
                errs() << "failed\n";
            }
        }

        transform.dump();

        errs() << "Done reading (" << transform.rewriteCount() << " rewrites)\n";
    }
Esempio n. 28
0
// Get the archive file name from the command line
static void getArchive() {
  if(RestOfArgs.size() == 0)
    show_help("An archive name must be specified");
  ArchiveName = RestOfArgs[0];
  RestOfArgs.erase(RestOfArgs.begin());
}
Esempio n. 29
0
static void getOptions() {
  if(RestOfArgs.size() == 0)
    show_help("Expected options");
  Options = RestOfArgs[0];
  RestOfArgs.erase(RestOfArgs.begin());
}
Esempio n. 30
0
// Extract the member filename from the command line for the [relpos] argument
// associated with a, b, and i modifiers
static void getRelPos() {
  if(RestOfArgs.size() == 0)
    show_help("Expected [relpos] for a, b, or i modifier");
  RelPos = RestOfArgs[0];
  RestOfArgs.erase(RestOfArgs.begin());
}