Computer Laboratory

Detailed Description

A transition from one TESLA state to another.

Definition at line 69 of file Transition.h.

#include "Transition.h"

+ Inheritance diagram for tesla::Transition:
+ Collaboration diagram for tesla::Transition:

Public Types

enum  TransitionKind {
  Null, Now, Fn, FieldAssign,
  SubAutomaton
}
 Information for LLVM's RTTI (isa<>, cast<>, etc.). More...
 

Public Member Functions

virtual ~Transition ()
 
const StateSource () const
 
const StateDestination () const
 
virtual bool EquivalentTo (const Transition &T) const =0
 Does this transition consume and produce the same symbols as another? More...
 
bool RequiresInit () const
 This transition triggers initialisation of its TESLA automata class. More...
 
bool RequiresCleanup () const
 This transition triggers cleanup of its TESLA automata class. More...
 
virtual bool IsStrict () const
 This transition can only occur as described in an automaton. More...
 
virtual const ReferenceVector Arguments () const =0
 Arguments referenced by this transition. More...
 
llvm::SmallVector< const
Argument *, 4 > 
NewArguments () const
 Arguments newly referenced by this transition (unknown to previous state). More...
 
int NewArgMask () const
 A bitmask representing the arguments newly referenced by this transition. More...
 
void ReferencesThusFar (llvm::OwningArrayPtr< const Argument * > &Args, ReferenceVector &Ref) const
 The references known at the point this transition occurs. More...
 
virtual bool IsRealisable () const =0
 Can this transition be captured by real instrumentation code? More...
 
virtual std::string ShortLabel () const =0
 A short, human-readable label. More...
 
virtual std::string DotLabel () const =0
 A label that can go in a .dot file (can use newline, Greek HTML codes...). More...
 
virtual std::string String () const
 
bool InScope () const
 
virtual TransitionKind getKind () const =0
 

Static Public Member Functions

static void Create (State &From, State &To, TransitionVector &Transitions, bool Init=false, bool Cleanup=false)
 Create an unconditional transition. More...
 
static void Create (State &From, State &To, const FunctionEvent &Ev, TransitionVector &, bool Init, bool Cleanup, bool OutOfScope=false)
 Create a FunctionEvent transition. More...
 
static void Create (State &From, State &To, const FieldAssignment &A, TransitionVector &, bool Init, bool Cleanup, bool OutOfScope=false)
 Create a FieldAssignment transition. More...
 
static void Create (State &From, State &To, const NowEvent &, const AutomatonDescription &, TransitionVector &, bool Init, bool Cleanup)
 
static void CreateSubAutomaton (State &From, State &To, const Identifier &, TransitionVector &)
 
static void Copy (State &From, State &To, const Transition *Other, TransitionVector &, bool OutOfScope=false)
 Creates a transition between the specified states, with the same transition type as the copied transition. More...
 
static void GroupClasses (const TransitionVector &, TransitionSets &)
 Group transitions into equivalence classes. More...
 

Protected Member Functions

 Transition (const State &From, const State &To, bool Init, bool Cleanup, bool OutOfScope)
 

Static Protected Member Functions

static void Register (llvm::OwningPtr< Transition > &, State &From, State &To, TransitionVector &)
 
static void Append (const llvm::OwningPtr< Transition > &, TransitionSets &)
 

Protected Attributes

const StateFrom
 
const StateTo
 
bool Init
 This transition triggers initialisation. More...
 
bool Cleanup
 This transition triggers cleanup. More...
 
const bool OutOfScope
 

Member Enumeration Documentation

Information for LLVM's RTTI (isa<>, cast<>, etc.).

Enumerator
Null 
Now 
Fn 
FieldAssign 
SubAutomaton 

Definition at line 186 of file Transition.h.

Constructor & Destructor Documentation

virtual tesla::Transition::~Transition ( )
inlinevirtual

Definition at line 137 of file Transition.h.

137 {}
tesla::Transition::Transition ( const State From,
const State To,
bool  Init,
bool  Cleanup,
bool  OutOfScope 
)
inlineprotected

Definition at line 195 of file Transition.h.

197  : From(From), To(To), Init(Init), Cleanup(Cleanup),
199  {
200  // An out-of-scope event cannot cause initialisation.
201  assert(!Init || !OutOfScope);
202  }

Member Function Documentation

static void tesla::Transition::Append ( const llvm::OwningPtr< Transition > &  ,
TransitionSets  
)
staticprotected
virtual const ReferenceVector tesla::Transition::Arguments ( ) const
pure virtual
void tesla::Transition::Copy ( State From,
State To,
const Transition Other,
TransitionVector Transitions,
bool  OutOfScope = false 
)
static

Creates a transition between the specified states, with the same transition type as the copied transition.

This is used when constructing DFA transitions from NFA transitions.

Definition at line 94 of file Transition.cpp.

References getKind(), OutOfScope, RequiresCleanup(), and RequiresInit().

Referenced by tesla::internal::DFABuilder::ConstructDFA(), and tesla::internal::NFAParser::Parse().

95  {
96 
97  OwningPtr<Transition> New;
98  bool Init = Other->RequiresInit();
99  bool Cleanup = Other->RequiresCleanup();
100 
101  OutOfScope |= Other->OutOfScope;
102  assert(!Init || !OutOfScope);
103 
104  switch (Other->getKind()) {
105  case Null:
106  assert(!OutOfScope);
107  return;
108 
109  case Now: {
110  assert(!OutOfScope);
111  auto O = cast<NowTransition>(Other);
112  New.reset(new NowTransition(From, To, O->Ev, O->Refs, Init, Cleanup));
113  break;
114  }
115 
116  case Fn:
117  New.reset(new FnTransition(From, To, cast<FnTransition>(Other)->Ev,
118  Init, Cleanup, OutOfScope));
119  break;
120 
121  case FieldAssign:
122  New.reset(new FieldAssignTransition(
123  From, To, cast<FieldAssignTransition>(Other)->Assign,
124  Init, Cleanup, OutOfScope));
125  break;
126 
127  case SubAutomaton:
128  assert(!OutOfScope);
129  New.reset(new SubAutomatonTransition(From, To,
130  cast<SubAutomatonTransition>(Other)->ID));
131  break;
132  }
133 
134  assert(New);
135  Register(New, From, To, Transitions);
136 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tesla::Transition::Create ( State From,
State To,
TransitionVector Transitions,
bool  Init = false,
bool  Cleanup = false 
)
static

Create an unconditional transition.

An unconditional transition (&#949; in the automata literature) cannot be driven by instrumentation, so it should only appear in an NFA.

Parameters
[in,out]FromThe state to transition from; will be given ownership of the new transition.
[in]ToThe state to transition to.
[out]TransitionsA place to record the new transition.
[in]InitTransition triggers class initialisation.
[in]CleanupTransition triggers class cleanup.

Definition at line 49 of file Transition.cpp.

50  {
51  OwningPtr<Transition> T(new NullTransition(From, To, Init, Cleanup));
52  Register(T, From, To, Transitions);
53 }
void tesla::Transition::Create ( State From,
State To,
const FunctionEvent Ev,
TransitionVector Transitions,
bool  Init,
bool  Cleanup,
bool  OutOfScope = false 
)
static

Create a FunctionEvent transition.

Parameters
[in,out]FromThe state to transition from; will be given ownership of the new transition.
[in]ToThe state to transition to.
[in]EvProtobuf representation of the event.
[out]TransitionsA place to record the new transition.
[in]InitTransition triggers class initialisation.
[in]CleanupTransition triggers class cleanup.
[in]OutOfScopeThe transition is out of a conditional automaton's scope.

Definition at line 66 of file Transition.cpp.

68  {
69 
70  OwningPtr<Transition> T(
71  new FnTransition(From, To, Ev, Init, Cleanup, OutOfScope));
72 
73  Register(T, From, To, Transitions);
74 }
void tesla::Transition::Create ( State From,
State To,
const FieldAssignment A,
TransitionVector Transitions,
bool  Init,
bool  Cleanup,
bool  OutOfScope = false 
)
static

Create a FieldAssignment transition.

Parameters
[in,out]FromThe state to transition from; will be given ownership of the new transition.
[in]ToThe state to transition to.
[in]AProtobuf representation of the event.
[out]TransitionsA place to record the new transition.
[in]InitTransition triggers class initialisation.
[in]CleanupTransition triggers class cleanup.
[in]OutOfScopeThe transition is out of a conditional automaton's scope.

Definition at line 76 of file Transition.cpp.

78  {
79 
80  OwningPtr<Transition> T(
81  new FieldAssignTransition(From, To, A, Init, Cleanup, OutOfScope));
82 
83  Register(T, From, To, Transitions);
84 }
void tesla::Transition::Create ( State From,
State To,
const NowEvent Ev,
const AutomatonDescription Automaton,
TransitionVector Transitions,
bool  Init,
bool  Cleanup 
)
static

Definition at line 55 of file Transition.cpp.

References tesla::AutomatonDescription::argument.

57  {
58 
59  ReferenceVector Refs(Automaton.argument().data(),
60  Automaton.argument_size());
61 
62  OwningPtr<Transition> T(new NowTransition(From, To, Ev, Refs, Init, Cleanup));
63  Register(T, From, To, Transitions);
64 }
void tesla::Transition::CreateSubAutomaton ( State From,
State To,
const Identifier ID,
TransitionVector Transitions 
)
static

Definition at line 86 of file Transition.cpp.

88  {
89 
90  OwningPtr<Transition> T(new SubAutomatonTransition(From, To, ID));
91  Register(T, From, To, Transitions);
92 }
const State& tesla::Transition::Destination ( ) const
inline

Definition at line 140 of file Transition.h.

References To.

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

140 { return To; }

+ Here is the caller graph for this function:

virtual std::string tesla::Transition::DotLabel ( ) const
pure virtual

A label that can go in a .dot file (can use newline, Greek HTML codes...).

Implemented in tesla::SubAutomatonTransition, tesla::FieldAssignTransition, tesla::FnTransition, tesla::NowTransition, and tesla::NullTransition.

virtual bool tesla::Transition::EquivalentTo ( const Transition T) const
pure virtual

Does this transition consume and produce the same symbols as another?

Implemented in tesla::SubAutomatonTransition, tesla::FieldAssignTransition, tesla::FnTransition, tesla::NowTransition, and tesla::NullTransition.

void tesla::Transition::GroupClasses ( const TransitionVector Ungrouped,
TransitionSets EquivalenceClasses 
)
static

Group transitions into equivalence classes.

Definition at line 153 of file Transition.cpp.

References tesla::debugs().

Referenced by tesla::internal::DFABuilder::ConstructDFA(), and tesla::internal::NFAParser::Parse().

154  {
155 
156  auto& Out = debugs("tesla.automata.transitions.equivalence");
157  Out << "grouping transitions:\n";
158 
159  for (auto *T : Ungrouped) {
160  Out << " " << T->String() << "\n";
161 
162  bool FoundEquivalent = false;
163  for (auto& Set : EquivalenceClasses) {
164  auto *Head = *Set.begin();
165  if (T->EquivalentTo(*Head)) {
166  assert(Head->EquivalentTo(*T));
167  FoundEquivalent = true;
168  Set.insert(T);
169  break;
170  }
171  }
172 
173  if (!FoundEquivalent) {
174  SmallPtrSet<const Transition*, 4> New;
175  New.insert(T);
176  EquivalenceClasses.push_back(New);
177  }
178  }
179 
180  Out << "equivalence classes:\n";
181  for (auto& EquivClass : EquivalenceClasses) {
182  bool Head = true;
183  for (const Transition *T : EquivClass) {
184  Out << (Head ? " " : " == ") << T->String() << "\n";
185  Head = false;
186  }
187  }
188 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool tesla::Transition::InScope ( ) const
inline

Definition at line 183 of file Transition.h.

References OutOfScope.

Referenced by tesla::State::UpdateReferences().

183 { return !OutOfScope; }

+ Here is the caller graph for this function:

virtual bool tesla::Transition::IsRealisable ( ) const
pure virtual

Can this transition be captured by real instrumentation code?

Implemented in tesla::SubAutomatonTransition, tesla::FieldAssignTransition, tesla::FnTransition, tesla::NowTransition, and tesla::NullTransition.

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

+ Here is the caller graph for this function:

virtual bool tesla::Transition::IsStrict ( ) const
inlinevirtual

This transition can only occur as described in an automaton.

Reimplemented in tesla::FieldAssignTransition, and tesla::FnTransition.

Definition at line 152 of file Transition.h.

152 { return false; }
int tesla::Transition::NewArgMask ( ) const

A bitmask representing the arguments newly referenced by this transition.

Definition at line 239 of file Transition.cpp.

239  {
240  auto NewArgs(NewArguments());
241  int Mask = 0;
242 
243  for (int i = 0; i < NewArgs.size(); i++)
244  if ((NewArgs[i] != NULL) && (NewArgs[i]->type() == Argument::Variable))
245  Mask += (1 << i);
246 
247  return Mask;
248 }
SmallVector< const Argument *, 4 > tesla::Transition::NewArguments ( ) const

Arguments newly referenced by this transition (unknown to previous state).

Definition at line 226 of file Transition.cpp.

226  {
227  auto OldArgs(From.References());
228  auto TransArgs(Arguments());
229 
230  SmallVector<const Argument*,4> NewArgs(TransArgs.size());
231  for (size_t i = 0; i < NewArgs.size(); i++)
232  if ((OldArgs.size() <= i) || (OldArgs[i] == NULL))
233  NewArgs[i] = TransArgs[i];
234 
235  return NewArgs;
236 }
void tesla::Transition::ReferencesThusFar ( llvm::OwningArrayPtr< const Argument * > &  Args,
ReferenceVector Ref 
) const

The references known at the point this transition occurs.

Parameters
[out]Argswhere to store the resulting array of arguments
[out]Refa reference to the created arguments; includes length

Definition at line 191 of file Transition.cpp.

Referenced by tesla::State::UpdateReferences().

192  {
193 
194  // Put this transition's *variable* references in var-index order.
195  SmallVector<const Argument*, 4> MyRefs;
196  for (auto Arg : this->Arguments())
197  if (Arg && Arg->type() == Argument::Variable) {
198  size_t i = Arg->index();
199 
200  if (MyRefs.size() <= i)
201  MyRefs.resize(i + 1);
202 
203  MyRefs[i] = Arg;
204  }
205 
206  auto& FromRefs = From.References();
207  const size_t Size = FromRefs.size();
208 
209  auto Arguments = new const Argument*[Size];
210  for (size_t i = 0; i < Size; i++) {
211  if ((MyRefs.size() > i) && MyRefs[i])
212  Arguments[i] = MyRefs[i];
213 
214  else if ((FromRefs.size() > i) && FromRefs[i])
215  Arguments[i] = FromRefs[i];
216 
217  else
218  Arguments[i] = NULL;
219  }
220 
221  Args.reset(Arguments);
222  Ref = ReferenceVector(Arguments, Size);
223 }

+ Here is the caller graph for this function:

void tesla::Transition::Register ( llvm::OwningPtr< Transition > &  ,
State From,
State To,
TransitionVector  
)
staticprotected

Definition at line 138 of file Transition.cpp.

References tesla::State::AddTransition(), tesla::debugs(), tesla::State::ID(), and tesla::State::UpdateReferences().

139  {
140 
141  Transitions.push_back(T.get());
142  debugs("tesla.automata.transitions") << "registered " << T->String() << "\n";
143 
144  // We should never try to update the start state's references.
145  assert(To.ID() != 0);
146 
147  // Update the state we're pointing to with the references it should
148  // know about thus far in the execution of the automaton.
149  To.UpdateReferences(*T.get());
150  From.AddTransition(T);
151 }

+ Here is the call graph for this function:

bool tesla::Transition::RequiresCleanup ( ) const
inline

This transition triggers cleanup of its TESLA automata class.

Definition at line 149 of file Transition.h.

References Cleanup.

Referenced by Copy().

149 { return Cleanup; }

+ Here is the caller graph for this function:

bool tesla::Transition::RequiresInit ( ) const
inline

This transition triggers initialisation of its TESLA automata class.

Definition at line 146 of file Transition.h.

References Init.

Referenced by Copy().

146 { return Init; }

+ Here is the caller graph for this function:

virtual std::string tesla::Transition::ShortLabel ( ) const
pure virtual
const State& tesla::Transition::Source ( ) const
inline

Definition at line 139 of file Transition.h.

References From.

139 { return From; }
string tesla::Transition::String ( ) const
virtual

Definition at line 251 of file Transition.cpp.

References tesla::ShortName().

Referenced by tesla::State::String().

251  {
252  string NewArgs;
253  for (auto A : NewArguments())
254  if ((A != NULL) && (A->type() == Argument::Variable))
255  NewArgs += " " + ShortName(A);
256 
257  string Special =
258  string(RequiresInit() ? "<<init>>" : "")
259  + (RequiresCleanup() ? "<<cleanup>>" : "")
260  ;
261 
262  return (Twine()
263  + "--("
264  + ShortLabel()
265  + (NewArgs.empty() ? "" : ":" + NewArgs)
266  + (Special.empty() ? "" : " " + Special)
267  + ")-->("
268  + Twine(To.ID())
269  + ")"
270  ).str();
271 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool tesla::Transition::Cleanup
protected

This transition triggers cleanup.

This transition is not named by the (conditional) TESLA automaton.

Definition at line 208 of file Transition.h.

Referenced by RequiresCleanup().

const State& tesla::Transition::From
protected

Definition at line 204 of file Transition.h.

Referenced by Source().

bool tesla::Transition::Init
protected

This transition triggers initialisation.

Definition at line 207 of file Transition.h.

Referenced by RequiresInit().

const bool tesla::Transition::OutOfScope
protected

Definition at line 211 of file Transition.h.

Referenced by Copy(), and InScope().

const State& tesla::Transition::To
protected

Definition at line 205 of file Transition.h.

Referenced by Destination().


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