summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/Orc/Core.cpp
blob: 2733528790d00125493caa8cf2689ed28d894905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//===--------- Core.cpp - Core ORC APIs (SymbolSource, VSO, etc.) ---------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/OrcError.h"

namespace llvm {
namespace orc {

AsynchronousSymbolQuery::AsynchronousSymbolQuery(
                                  const SymbolNameSet &Symbols,
                                  SymbolsResolvedCallback NotifySymbolsResolved,
                                  SymbolsReadyCallback NotifySymbolsReady)
    : NotifySymbolsResolved(std::move(NotifySymbolsResolved)),
      NotifySymbolsReady(std::move(NotifySymbolsReady)) {
  assert(this->NotifySymbolsResolved &&
         "Symbols resolved callback must be set");
  assert(this->NotifySymbolsReady && "Symbols ready callback must be set");
  OutstandingResolutions = OutstandingFinalizations = Symbols.size();
}

void AsynchronousSymbolQuery::setFailed(Error Err) {
  OutstandingResolutions = OutstandingFinalizations = 0;
  if (NotifySymbolsResolved)
    NotifySymbolsResolved(std::move(Err));
  else
    NotifySymbolsReady(std::move(Err));
}

void AsynchronousSymbolQuery::setDefinition(SymbolStringPtr Name,
                                            JITSymbol Sym) {
  // If OutstandingResolutions is zero we must have errored out already. Just
  // ignore this.
  if (OutstandingResolutions == 0)
    return;

  assert(NotifySymbolsResolved && "Notify callback not set");

  errs()
    << "OutstandingResolutions = " << OutstandingResolutions << "\n"
    << "OutstandingFinalizations = " << OutstandingFinalizations << "\n"
    << "Symbols.size() = " << Symbols.size() << "\n"
    << "Symbols.count(Name) = " << Symbols.count(Name) << "\n";

  assert(!Symbols.count(Name) &&
         "Symbol has already been assigned an address");
  errs() << "Past assert\n";
  Symbols.insert(std::make_pair(std::move(Name), std::move(Sym)));
  errs() << "Past insert\n";
  --OutstandingResolutions;
  errs() << "Past subtract\n";
  if (OutstandingResolutions == 0) {
    errs() << "Past test\n";
    NotifySymbolsResolved(std::move(Symbols));
    // Null out NotifySymbolsResolved to indicate that we've already called it.
    errs() << "Past callback\n";
    NotifySymbolsResolved = {};
    errs() << "Past callback-reset\n";
  }
}

void AsynchronousSymbolQuery::notifySymbolFinalized() {
  // If OutstandingFinalizations is zero we must have errored out already. Just
  // ignore this.
  if (OutstandingFinalizations == 0)
    return;

  assert(OutstandingFinalizations > 0 && "All symbols already finalized");
  --OutstandingFinalizations;
  if (OutstandingFinalizations == 0)
    NotifySymbolsReady(Error::success());
}

} // End namespace orc.
} // End namespace llvm.
OpenPOWER on IntegriCloud