diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 | 
| commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
| tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/TableGen/Main.cpp | |
| parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) | |
Notes
Diffstat (limited to 'lib/TableGen/Main.cpp')
| -rw-r--r-- | lib/TableGen/Main.cpp | 38 | 
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 3a07016260897..02698416609f0 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -46,6 +46,10 @@ static cl::list<std::string>  IncludeDirs("I", cl::desc("Directory of include files"),              cl::value_desc("directory"), cl::Prefix); +static cl::list<std::string> +MacroNames("D", cl::desc("Name of the macro to be defined"), +            cl::value_desc("macro name"), cl::Prefix); +  static int reportError(const char *ProgName, Twine Msg) {    errs() << ProgName << ": " << Msg;    errs().flush(); @@ -91,28 +95,44 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) {    // it later.    SrcMgr.setIncludeDirs(IncludeDirs); -  TGParser Parser(SrcMgr, Records); +  TGParser Parser(SrcMgr, MacroNames, Records);    if (Parser.ParseFile())      return 1; -  std::error_code EC; -  ToolOutputFile Out(OutputFilename, EC, sys::fs::F_Text); -  if (EC) -    return reportError(argv0, "error opening " + OutputFilename + ":" + -                                  EC.message() + "\n"); +  // Write output to memory. +  std::string OutString; +  raw_string_ostream Out(OutString); +  if (MainFn(Out, Records)) +    return 1; + +  // Always write the depfile, even if the main output hasn't changed. +  // If it's missing, Ninja considers the output dirty.  If this was below +  // the early exit below and someone deleted the .inc.d file but not the .inc +  // file, tablegen would never write the depfile.    if (!DependFilename.empty()) {      if (int Ret = createDependencyFile(Parser, argv0))        return Ret;    } -  if (MainFn(Out.os(), Records)) -    return 1; +  // Only updates the real output file if there are any differences. +  // This prevents recompilation of all the files depending on it if there +  // aren't any. +  if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename)) +    if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) +      return 0; + +  std::error_code EC; +  ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_Text); +  if (EC) +    return reportError(argv0, "error opening " + OutputFilename + ":" + +                                  EC.message() + "\n"); +  OutFile.os() << Out.str();    if (ErrorsPrinted > 0)      return reportError(argv0, Twine(ErrorsPrinted) + " errors.\n");    // Declare success. -  Out.keep(); +  OutFile.keep();    return 0;  }  | 
