Printable PrintRegUnit(unsigned Unit, const TargetRegisterInfo *TRI) { return Printable([Unit, TRI](raw_ostream &OS) { // Generic printout when TRI is missing. if (!TRI) { OS << "Unit~" << Unit; return; } // Check for invalid register units. if (Unit >= TRI->getNumRegUnits()) { OS << "BadUnit~" << Unit; return; } // Normal units have at least one root. MCRegUnitRootIterator Roots(Unit, TRI); assert(Roots.isValid() && "Unit has no roots."); OS << TRI->getName(*Roots); for (++Roots; Roots.isValid(); ++Roots) OS << '~' << TRI->getName(*Roots); }); }
Manifest* Manifest::load(raw_ostream& ErrorStream, Automaton::Type T, StringRef Path) { llvm::SourceMgr SM; OwningPtr<MemoryBuffer> Buffer; error_code Error = MemoryBuffer::getFile(Path, Buffer); if (Error != 0) { ErrorStream << "Failed to open TESLA analysis file '" << Path << "': " << Error.message() << "\n" ; return NULL; } OwningPtr<ManifestFile> Protobuf(new ManifestFile); StringRef buf = Buffer->getBuffer(); const bool TextFormat = buf.ltrim().startswith("automaton") or buf.ltrim().startswith("#line 1") // for preprocessed manifests or buf.ltrim().startswith("# 1") // GNU cpp version of the above ; const bool success = TextFormat ? google::protobuf::TextFormat::ParseFromString(buf, Protobuf.get()) : Protobuf->ParseFromArray(buf.data(), buf.size()) ; if (!success) { ErrorStream << "Error parsing TESLA manifest '" << Path << "' (in " << (TextFormat ? "text" : "binary") << " format)\n" ; return NULL; } AutomataMap Descriptions; map<Identifier,const Automaton*> Automata; // Note the top-level automata that are explicitly named as roots. ArrayRef<const Usage*> Roots(Protobuf->root().data(), Protobuf->root_size()); map<Identifier,const Usage*> Uses; for (auto *U : Roots) Uses[U->identifier()] = U; for (auto& A : Protobuf->automaton()) Descriptions[A.identifier()] = &A; vector<Automaton::Lifetime> Lifetimes; int id = 0; for (auto i : Descriptions) { const Identifier& ID = i.first; const AutomatonDescription *Descrip = i.second; OwningPtr<NFA> N(NFA::Parse(Descrip, Uses[ID], id++)); if (!N) { for (auto i : Automata) delete i.second; for (auto i : Descriptions) delete i.second; return NULL; } OwningPtr<Automaton> Result; if (T == Automaton::Unlinked) Result.reset(N.take()); else { N.reset(N->Link(Descriptions)); if (T == Automaton::Linked) Result.reset(N.take()); else Result.reset(DFA::Convert(N.get())); } Automaton::Lifetime L = Result->getLifetime(); if (L.Init != NULL and find(Lifetimes.begin(), Lifetimes.end(), L) == Lifetimes.end()) { Lifetimes.push_back(L); assert(Lifetimes.back() == L); } Automata[ID] = Result.take(); } raw_ostream& debug = debugs("tesla.manifest.lifetimes"); debug << "--------\nUnique automata lifetimes:\n"; for (auto& Lifetime : Lifetimes) debug << " * " << Lifetime.String() << "\n"; debug << "--------\n"; return new Manifest(Protobuf, Descriptions, Automata, Roots, Lifetimes); }
int Eigenvalues(Ttensor t, double vals[]) { tg = &t; return Roots(DetPoly, 3, 0.01, ZERO, -20, 20, vals); }