38 #include "llvm/IR/Function.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/IR/LLVMContext.h"
41 #include "llvm/IR/Module.h"
43 #include "llvm/Support/CommandLine.h"
44 #include "llvm/Support/MemoryBuffer.h"
45 #include "llvm/Support/SourceMgr.h"
46 #include "llvm/Support/raw_ostream.h"
47 #include "llvm/Support/system_error.h"
49 #include <google/protobuf/text_format.h>
59 cl::opt<string>
ManifestName(
"tesla-manifest", cl::init(
".tesla"), cl::Hidden,
60 cl::desc(
"Name of TESLA manifest file"));
62 const string Manifest::SEP =
"===\n";
65 Manifest::~Manifest() {
66 for (
auto i : Automata)
71 auto i = Automata.find(ID);
72 if (i == Automata.end())
73 panic(
"TESLA manifest does not contain assertion " +
ShortName(ID));
80 *ID.mutable_location() = Loc;
82 return FindAutomaton(ID);
89 OwningPtr<MemoryBuffer> Buffer;
91 error_code Error = MemoryBuffer::getFile(Path, Buffer);
94 <<
"Failed to open TESLA analysis file '" << Path <<
"': "
95 << Error.message() <<
"\n"
102 if (!::google::protobuf::TextFormat::ParseFromString(Buffer->getBuffer(),
104 ErrorStream <<
"Error parsing TESLA manifest '" << Path <<
"'\n";
109 map<Identifier,const Automaton*> Automata;
112 ArrayRef<const Usage*> Roots(Protobuf->root().data(), Protobuf->root_size());
113 map<Identifier,const Usage*> Uses;
114 for (
auto *U : Roots)
115 Uses[U->identifier()] = U;
117 for (
auto& A : Protobuf->automaton())
118 Descriptions[A.identifier()] = &A;
121 for (
auto i : Descriptions) {
125 OwningPtr<NFA> N(NFA::Parse(Descrip, Uses[ID],
id++));
127 for (
auto i : Automata)
delete i.second;
128 for (
auto i : Descriptions)
delete i.second;
132 OwningPtr<Automaton> Result;
134 if (T == Automaton::Unlinked)
135 Result.reset(N.take());
138 N.reset(N->Link(Descriptions));
140 if (T == Automaton::Linked)
141 Result.reset(N.take());
144 Result.reset(DFA::Convert(N.get()));
147 Automata[ID] = Result.take();
150 return new Manifest(Protobuf, Descriptions, Automata, Roots);