Computer Laboratory

Detailed Description

An automata representation of a TESLA assertion.

This representation can be either deterministic (for easy generation of instrumentation code) or non-deterministic (for easy creation and analysis).

An Automaton owns its consituent State objects; Transition ownership rests with the State objects.

Definition at line 74 of file Automaton.h.

#include "Automaton.h"

+ Inheritance diagram for tesla::Automaton:
+ Collaboration diagram for tesla::Automaton:

Public Types

enum  Type { Unlinked, Linked, Deterministic }
 Automata representations, in increasing order of realisability. More...
 
typedef llvm::SmallVector
< State *, 10 > 
StateVector
 

Public Member Functions

virtual ~Automaton ()
 
virtual bool IsRealisable () const
 
size_t ID () const
 
const AutomatonDescriptiongetAssertion () const
 
const UsageUse () const
 
size_t StateCount () const
 
size_t TransitionCount () const
 
std::string Name () const
 Short, unique name. More...
 
std::string String () const
 Human-readable representation. More...
 
std::string Dot () const
 GraphViz representation. More...
 
TransitionSets::const_iterator begin () const
 Iterate over state transitions. More...
 
TransitionSets::const_iterator end () const
 

Protected Member Functions

 Automaton (size_t id, const AutomatonDescription &, const Usage *, llvm::StringRef Name, llvm::ArrayRef< State * >, const TransitionSets &)
 

Protected Attributes

const size_t id
 
const AutomatonDescriptionassertion
 Automaton states. More...
 
const Usageuse
 How the automaton is used. More...
 
const std::string name
 
StateVector States
 
TransitionSets Transitions
 

Friends

class internal::DFABuilder
 

Member Typedef Documentation

typedef llvm::SmallVector<State*,10> tesla::Automaton::StateVector

Definition at line 92 of file Automaton.h.

Member Enumeration Documentation

Automata representations, in increasing order of realisability.

Enumerator
Unlinked 

An NFA representation that includes sub-automata pseudo-transitions, e.g.

"transition from state 2 to state 8 via sub-automaton 'active_close'".

Linked 

An NFA with realisable transitions.

Deterministic 

A DFA that can actually be implemented as instrumentation.

Definition at line 78 of file Automaton.h.

78  {
83  Unlinked,
84 
86  Linked,
87 
90  };

Constructor & Destructor Documentation

virtual tesla::Automaton::~Automaton ( )
inlinevirtual

Definition at line 95 of file Automaton.h.

95 {}
tesla::Automaton::Automaton ( size_t  id,
const AutomatonDescription ,
const Usage ,
llvm::StringRef  Name,
llvm::ArrayRef< State * >  ,
const TransitionSets  
)
protected

Definition at line 131 of file Automaton.cpp.

References tesla::Usage::identifier, tesla::AutomatonDescription::identifier, and States.

135 {
136  assert(!Use || A.identifier() == Use->identifier());
137  States.insert(States.begin(), S.begin(), S.end());
138 }

Member Function Documentation

TransitionSets::const_iterator tesla::Automaton::begin ( ) const
inline

Iterate over state transitions.

Definition at line 109 of file Automaton.h.

References Transitions.

109 { return Transitions.begin(); }
string tesla::Automaton::Dot ( ) const

GraphViz representation.

Definition at line 163 of file Automaton.cpp.

References Name(), States, and Transitions.

163  {
164  stringstream ss;
165  ss
166  << "/*\n"
167  << " * " << Name() << "\n"
168  << " */\n"
169  << "digraph automaton_" << id << " {\n"
170  << "\tgraph [ truecolor=true, bgcolor=\"transparent\", dpi = 60 ];\n"
171  << "\tnode ["
172  << " shape = circle,"
173  << " fontname = \"Monospace\","
174  << " style = filled, fillcolor = \"white\""
175  << "];\n"
176  << "\tedge [ fontname = \"Monospace\" ];\n"
177  << "\n"
178  ;
179 
180  for (State *S : States) {
181  ss << "\t" << S->Dot() << "\n";
182  }
183 
184  int i = 0;
185  for (auto EquivalenceClass : Transitions) {
186  string color = ("\"/dark28/" + Twine(i++ % 8 + 1) + "\"").str();
187  auto *Head = *EquivalenceClass.begin();
188 
189  ss
190  << "\n\t/*\n"
191  << "\t * " << Head->ShortLabel() << "\n"
192  << "\t */\n"
193  << "\tedge [ "
194  << "color = " << color << ", "
195  << "fontcolor = " << color << ",\n\t\t"
196  << "label = \"" << Head->DotLabel();
197 
198  if (Head->RequiresInit())
199  ss << "\\n&laquo;init&raquo;";
200 
201  if (Head->RequiresCleanup())
202  ss << "\\n&laquo;cleanup&raquo;";
203 
204  ss
205  << "\""
206  << " ];\n";
207 
208  for (auto *T : EquivalenceClass)
209  ss
210  << "\t" << T->Source().ID() << " -> " << T->Destination().ID() << ";\n"
211  ;
212  }
213 
214  ss
215  << "\n\t/*\n"
216  << "\t * Footer:\n"
217  << "\t */\n"
218  << "\tfontname = \"Monospace\";\n"
219  << "\tlabel = \"" << Name() << "\";\n"
220  << "\tlabelloc = top;\n"
221  << "\tlabeljust = left;\n"
222  << "}";
223 
224  return ss.str();
225 }

+ Here is the call graph for this function:

TransitionSets::const_iterator tesla::Automaton::end ( ) const
inline

Definition at line 110 of file Automaton.h.

References Transitions.

110 { return Transitions.end(); }
const AutomatonDescription& tesla::Automaton::getAssertion ( ) const
inline

Definition at line 99 of file Automaton.h.

References assertion.

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::FnInstrumentation::AppendInstrumentation(), and tesla::internal::DFABuilder::ConstructDFA().

99 { return assertion; }

+ Here is the caller graph for this function:

size_t tesla::Automaton::ID ( ) const
inline

Definition at line 98 of file Automaton.h.

References id.

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::FnInstrumentation::AppendInstrumentation(), and tesla::internal::DFABuilder::ConstructDFA().

98 { return id; }

+ Here is the caller graph for this function:

bool tesla::Automaton::IsRealisable ( ) const
virtual

Reimplemented in tesla::DFA.

Definition at line 140 of file Automaton.cpp.

References Transitions.

140  {
141  for (auto i : Transitions)
142  for (const Transition *T : i)
143  if (!T->IsRealisable())
144  return false;
145 
146  return true;
147 }
std::string tesla::Automaton::Name ( ) const
inline

Short, unique name.

Definition at line 104 of file Automaton.h.

References name.

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::FnInstrumentation::AppendInstrumentation(), tesla::internal::DFABuilder::ConstructDFA(), Dot(), and String().

+ Here is the caller graph for this function:

size_t tesla::Automaton::StateCount ( ) const
inline

Definition at line 101 of file Automaton.h.

References States.

101 { return States.size(); }
string tesla::Automaton::String ( ) const

Human-readable representation.

Definition at line 149 of file Automaton.cpp.

References Name(), and States.

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::FnInstrumentation::AppendInstrumentation(), tesla::internal::DFABuilder::ConstructDFA(), and main().

149  {
150  stringstream ss;
151  ss << "automaton '" << Name() << "' {\n";
152 
153  for (State *S : States) {
154  assert(S != NULL);
155  ss << "\t" << S->String() << "\n";
156  }
157 
158  ss << "}";
159 
160  return ss.str();
161 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t tesla::Automaton::TransitionCount ( ) const
inline

Definition at line 102 of file Automaton.h.

References Transitions.

102 { return Transitions.size(); }
const Usage* tesla::Automaton::Use ( ) const
inline

Definition at line 100 of file Automaton.h.

References use.

Referenced by tesla::internal::DFABuilder::ConstructDFA().

100 { return use; }

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class internal::DFABuilder
friend

Definition at line 75 of file Automaton.h.

Member Data Documentation

const AutomatonDescription& tesla::Automaton::assertion
protected

Automaton states.

Definition at line 118 of file Automaton.h.

Referenced by getAssertion(), and tesla::NFA::Link().

const size_t tesla::Automaton::id
protected

Definition at line 117 of file Automaton.h.

Referenced by ID().

const std::string tesla::Automaton::name
protected

Definition at line 120 of file Automaton.h.

Referenced by Name().

StateVector tesla::Automaton::States
protected
TransitionSets tesla::Automaton::Transitions
protected

Definition at line 123 of file Automaton.h.

Referenced by begin(), Dot(), end(), IsRealisable(), and TransitionCount().

const Usage* tesla::Automaton::use
protected

How the automaton is used.

Definition at line 119 of file Automaton.h.

Referenced by tesla::NFA::Link(), and Use().


The documentation for this class was generated from the following files: