Computer Laboratory

tesla Namespace Reference

Namespaces

namespace  internal
 

Classes

class  TeslaConsumer
 
class  TeslaAction
 
class  TeslaActionFactory
 
class  Parser
 A parser for TESLA automata descriptions. More...
 
class  TeslaVisitor
 
class  Automaton
 An automata representation of a TESLA assertion. More...
 
class  NFA
 A non-deterministic automaton that represents a TESLA assertion. More...
 
class  DFA
 A DFA description of a TESLA assertion. More...
 
class  Manifest
 A description of TESLA instrumentation to perform. More...
 
class  State
 A state in a TESLA DFA. More...
 
struct  ManifestFile
 A file that describes TESLA automata. More...
 
struct  Usage
 How an automaton is used for instrumentation. More...
 
struct  AutomatonDescription
 An inline assertion describing the temporal behaviour of software. More...
 
struct  Identifier
 Something that uniquely identifies an automaton. More...
 
struct  Location
 An identifier for an automaton based on where it was defined. More...
 
struct  Expression
 A temporal expression. More...
 
struct  BooleanExpr
 A boolean combination of expressions (with equal precedence). More...
 
struct  Sequence
 A sequence of temporal events. More...
 
struct  NowEvent
 Execution has reached the point in the instrumented code where an inline assertion was defined. More...
 
struct  FunctionEvent
 A function has been called or has returned. More...
 
struct  FunctionRef
 A function that can be instrumented. More...
 
struct  FieldAssignment
 Assignment to a field in a structure. More...
 
struct  StructField
 A field within a structure. More...
 
struct  Argument
 An argument to a function. More...
 
class  Transition
 A transition from one TESLA state to another. More...
 
class  NullTransition
 An unconditional (and unrealisable) transition. More...
 
class  NowTransition
 The "now" event transition. More...
 
class  FnTransition
 A function-related transition. More...
 
class  FieldAssignTransition
 A field assignment transition. More...
 
class  SubAutomatonTransition
 A sub-automaton. More...
 
class  PtrAnnotation
 An annotation applied by LLVM to a pointer. More...
 
class  FieldAnnotation
 An annotation applied by Clang/TESLA to a structure field access. More...
 
class  AssertionSiteInstrumenter
 Converts calls to TESLA pseudo-assertions into instrumentation sites. More...
 
class  FnCalleeInstrumenter
 Instruments function calls in the callee context. More...
 
class  CalleeInstr
 Function instrumentation (callee context). More...
 
class  FnCallerInstrumenter
 Instruments function calls in the caller context. More...
 
class  CallerInstrumentation
 Function instrumentation (caller context). More...
 
class  FieldInstrumentation
 Instrumentation for a struct field assignment. More...
 
class  FieldReferenceInstrumenter
 Converts calls to TESLA pseudo-assertions into instrumentation sites. More...
 
class  FnInstrumentation
 Instrumentation for a function event. More...
 
class  InstInstrumentation
 Instrumentation on a single instruction that does not change control flow. More...
 
class  Instrumenter
 Base class for TESLA instrumenters. More...
 

Typedefs

typedef std::map< Identifier,
const AutomatonDescription * > 
AutomataMap
 
typedef llvm::ArrayRef< const
Argument * > 
ReferenceVector
 
typedef llvm::MutableArrayRef
< const Argument * > 
MutableReferenceVector
 
typedef llvm::SmallVector
< Transition *, 10 > 
TransitionVector
 Ungrouped transitions. More...
 
typedef llvm::SmallPtrSet
< const Transition *, 4 > 
TEquivalenceClass
 A set of TESLA transitions that are considered equivalent. More...
 
typedef std::vector
< TEquivalenceClass
TransitionSets
 Sets of transition equivalence classes. More...
 
typedef llvm::SmallVector
< llvm::SmallVector
< Transition *, 16 >, 4 > 
TransitionVectors
 
typedef llvm::SmallVector
< State *, 10 > 
StateVector
 
typedef llvm::SmallVector
< llvm::Value *, 3 > 
ArgVector
 A container for function arguments, which shouldn't be very numerous. More...
 
typedef llvm::SmallVector
< llvm::Type *, 3 > 
TypeVector
 A container for a few types (e.g., of function arguments). More...
 

Functions

template<class T >
void ReportError (ASTContext &Ctx, StringRef Message, T *Subject)
 
llvm::raw_ostream & debugs (llvm::StringRef DebugModuleName="tesla")
 
void panic (llvm::Twine Message, bool PrintStackTrace=true)
 
cl::opt< string > ManifestName ("tesla-manifest", cl::init(".tesla"), cl::Hidden, cl::desc("Name of TESLA manifest file"))
 
std::string ArgString (const Argument *)
 Convert an Argument into something human-readable. More...
 
std::string ShortName (const Argument *)
 Convert an Argument into a very short, human-readable name. More...
 
std::string DotName (const Argument *)
 Convert an Argument into a very short name for GraphViz's dot. More...
 
std::string ShortName (const Identifier &)
 Convert an Identifier into a short, human-readable name. More...
 
std::string ShortName (const Location &)
 Convert an Location into a short, human-readable name. More...
 
std::string InstanceName (const ReferenceVector &, bool PlainAscii)
 Convert the name of an automata instance. More...
 
template<class T >
bool operator!= (const T &x, const T &y)
 
bool operator== (const Location &x, const Location &y)
 
bool operator== (const Identifier &x, const Identifier &y)
 
bool operator== (const Argument &A1, const Argument &A2)
 
bool operator== (const NowEvent &X, const NowEvent &Y)
 
bool operator== (const FunctionRef &X, const FunctionRef &Y)
 
bool operator== (const FunctionEvent &E1, const FunctionEvent &E2)
 
bool operator== (const StructField &X, const StructField &Y)
 
bool operator== (const FieldAssignment &X, const FieldAssignment &Y)
 
bool operator< (const Location &x, const Location &y)
 
bool operator< (const Identifier &x, const Identifier &y)
 
llvm::Value * ConstructKey (llvm::IRBuilder<> &Builder, llvm::Module &M, llvm::Function::ArgumentListType &InstrumentationArgs, FunctionEvent FnEventDescription)
 Map instrumentation arguments into a tesla_key that can be used to look up automata. More...
 
BasicBlock * MatchPattern (LLVMContext &Ctx, StringRef Name, Function *Fn, BasicBlock *MatchTarget, BasicBlock *NonMatchTarget, Value *Val, const tesla::Argument &Pattern)
 
BasicBlock * FindBlock (StringRef Name, Function &Fn)
 
StructType * KeyType (Module &M)
 
Function * Printf (Module &Mod)
 Find (or create) printf() declaration. More...
 
Function * TeslaDebugging (Module &Mod)
 Find (or create) tesla_debugging() declaration. More...
 
const char * Format (Type *T)
 
llvm::Type * IntPtrType (llvm::Module &)
 Extract the register_t type from an llvm::Module. More...
 
llvm::StructType * TransitionType (llvm::Module &)
 Extract the tesla_transition type from an llvm::Module. More...
 
llvm::StructType * TransitionSetType (llvm::Module &)
 Extract the tesla_transitions type from an llvm::Module. More...
 
llvm::Constant * TeslaContext (AutomatonDescription::Context Context, llvm::LLVMContext &Ctx)
 Find the constant for a libtesla context (either TESLA_CONTEXT_THREAD or TESLA_CONTEXT_GLOBAL). More...
 
llvm::BasicBlock * FindBlock (llvm::StringRef Name, llvm::Function &)
 Find a BasicBlock within a Function. More...
 
llvm::Function * FindStateUpdateFn (llvm::Module &, llvm::Type *IntType)
 Find the libtesla function tesla_update_state. More...
 
llvm::Value * Cast (llvm::Value *From, llvm::StringRef Name, llvm::Type *NewType, llvm::IRBuilder<> &)
 Cast an integer-ish Value to another type. More...
 
llvm::BasicBlock * CreateInstrPreamble (llvm::Module &Mod, llvm::Function *F, const llvm::Twine &Prefix, bool SuppressDebugInstrumentation)
 Initialise the instrumentation function's preamble. More...
 
llvm::Value * ConstructKey (llvm::IRBuilder<> &, llvm::Module &, llvm::ArrayRef< llvm::Value * > Args)
 Map a set of values into a tesla_key. More...
 
llvm::Constant * ConstructTransition (llvm::IRBuilder<> &, llvm::Module &, const Transition &)
 Construct a single tesla_transition. More...
 
llvm::Constant * ConstructTransitions (llvm::IRBuilder<> &, llvm::Module &, const TEquivalenceClass &)
 Construct a tesla_transitions for a TEquivalenceClass. More...
 
llvm::Function * FunctionInstrumentation (llvm::Module &, const llvm::Function &, FunctionEvent::Direction, FunctionEvent::CallContext, bool SuppressDebugInstr)
 Find (or create) one function-event instrumentation function. More...
 
llvm::Function * StructInstrumentation (llvm::Module &, llvm::StructType *, llvm::StringRef FieldName, size_t Index, bool Store, bool SuppressDebugInstr)
 Find (or create) one struct-field-event instrumentation function. More...
 

Variables

const std::string LLVM_PTR_ANNOTATION = "llvm.ptr.annotation"
 
const std::string TESLA_BASE = "__tesla_"
 
const std::string AUTOMATON = TESLA_BASE + "automaton_"
 
const std::string AUTOMATON_DESC = AUTOMATON + "description"
 
const std::string AUTOMATON_MAPPING = AUTOMATON + "mapping"
 
const std::string AUTOMATON_USAGE = AUTOMATON + "usage"
 
const std::string AUTOMATON_USES = TESLA_BASE + "struct_uses_automaton"
 
const std::string GLOBAL = TESLA_BASE + "global"
 
const std::string PERTHREAD = TESLA_BASE + "perthread"
 
const std::string ANY = TESLA_BASE + "any"
 
const std::string EVENT = TESLA_BASE + "event"
 
const std::string IGNORE = TESLA_BASE + "ignore"
 
const std::string NOW = TESLA_BASE + "now"
 
const std::string OPTIONAL = TESLA_BASE + "optional"
 
const std::string SEQUENCE = TESLA_BASE + "sequence"
 
const std::string INLINE_ASSERTION = TESLA_BASE + "inline_assertion"
 
const std::string INSTR_BASE = TESLA_BASE + "instrumentation_"
 
const std::string STRUCT_INSTR = INSTR_BASE + "struct_field_"
 
const std::string LOAD = "load_"
 
const std::string STORE = "store_"
 
const std::string CALL = INSTR_BASE + "call"
 
const std::string RETURN = INSTR_BASE + "return"
 
const std::string CALLEE = "callee_"
 
const std::string CALLER = "caller_"
 
const std::string ENTER = "enter_"
 
const std::string EXIT = "return_"
 
const std::string FLAGS = TESLA_BASE + "flags"
 
const std::string MASK = TESLA_BASE + "mask"
 
const std::string ASSERTION_REACHED = INSTR_BASE + "assertion_reached"
 
raw_ostream & debug = debugs("tesla.instrumentation.field_assign")
 

Class Documentation

struct tesla::ManifestFile
+ Collaboration diagram for tesla::ManifestFile:
Class Members
repeated AutomatonDescription automaton All of the automata described by the manifest.
repeated Usage root The automata that are actually used in their own right (as opposed to those that are only included by other automata).
struct tesla::Usage
+ Collaboration diagram for tesla::Usage:
Class Members
optional Expression beginning Where the automaton begins: a bound, a place for initialisation.
optional Expression end Where the automataon ends: a bound, a place for cleanup.
required Identifier identifier The identifier of the automaton in question.
struct tesla::Identifier
+ Collaboration diagram for tesla::Identifier:
Class Members
optional Location location If there is no assigned name, the location the automaton is defined.
optional string name Programmer-assigned name.
struct tesla::Location
+ Collaboration diagram for tesla::Location:
Class Members
required int32 counter
required string filename
required int32 line
struct tesla::Sequence
+ Collaboration diagram for tesla::Sequence:
Class Members
repeated Expression expression
struct tesla::NowEvent
+ Collaboration diagram for tesla::NowEvent:
Class Members
required Location location
struct tesla::FunctionRef
+ Collaboration diagram for tesla::FunctionRef:
Class Members
required string name The function's name.

TODO: we may need further disambiguation if two modules contain static functions with the same name. This may only matter when compiling via LLVM IR: I think this will fail when linking ELF object files.

struct tesla::StructField
+ Collaboration diagram for tesla::StructField:
Class Members
required Argument base Reference to the structure.
required int32 index Index of the field within the struct.
required string name Name of the struct field.
required string type Name of the structure type.

Typedef Documentation

typedef llvm::SmallVector<llvm::Value*,3> tesla::ArgVector

A container for function arguments, which shouldn't be very numerous.

Definition at line 91 of file Instrumentation.h.

Definition at line 63 of file Automaton.h.

typedef llvm::MutableArrayRef<const Argument*> tesla::MutableReferenceVector

Definition at line 53 of file Transition.h.

typedef llvm::ArrayRef<const Argument*> tesla::ReferenceVector

Definition at line 46 of file Names.h.

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

Definition at line 40 of file Types.h.

typedef llvm::SmallPtrSet<const Transition*,4> tesla::TEquivalenceClass

A set of TESLA transitions that are considered equivalent.

Definition at line 61 of file Transition.h.

Sets of transition equivalence classes.

Definition at line 64 of file Transition.h.

typedef llvm::SmallVector<Transition*,10> tesla::TransitionVector

Ungrouped transitions.

Definition at line 58 of file Transition.h.

typedef llvm::SmallVector<llvm::SmallVector<Transition*, 16>, 4> tesla::TransitionVectors

Definition at line 66 of file Transition.h.

typedef llvm::SmallVector<llvm::Type*,3> tesla::TypeVector

A container for a few types (e.g., of function arguments).

Definition at line 94 of file Instrumentation.h.

Function Documentation

std::string tesla::ArgString ( const Argument *  A)

Convert an Argument into something human-readable.

Definition at line 43 of file Names.cpp.

References tesla::StructField::base, tesla::Argument::field, tesla::Argument::index, tesla::Argument::indirection, tesla::StructField::name, tesla::Argument::name, ShortName(), and tesla::Argument::type.

43  {
44  if (A == NULL)
45  return "NULL";
46 
47  switch (A->type()) {
48  case Argument::Constant:
49  return A->name();
50 
51  case Argument::Variable:
52  return (Twine()
53  + Twine(A->index())
54  + "('"
55  + A->name()
56  + "')"
57  ).str();
58 
59  case Argument::Any:
60  return "<anything>";
61 
62  case Argument::Indirect:
63  assert(A->has_indirection());
64  return "*" + ShortName(&A->indirection());
65 
66  case Argument::Field:
67  assert(A->has_field());
68  return ShortName(&A->field().base()) + "." + A->field().name();
69  }
70 }

+ Here is the call graph for this function:

llvm::Value* tesla::Cast ( llvm::Value *  From,
llvm::StringRef  Name,
llvm::Type *  NewType,
llvm::IRBuilder<> &   
)

Cast an integer-ish Value to another type.

We use this for casting to register_t, but it's possible that other integer types might work too. Maybe.

Referenced by tesla::FieldReferenceInstrumenter::runOnModule().

+ Here is the caller graph for this function:

llvm::Value* tesla::ConstructKey ( llvm::IRBuilder<> &  Builder,
llvm::Module &  M,
llvm::Function::ArgumentListType &  InstrumentationArgs,
FunctionEvent  FnEventDescription 
)

Map instrumentation arguments into a tesla_key that can be used to look up automata.

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

+ Here is the caller graph for this function:

llvm::Value* tesla::ConstructKey ( llvm::IRBuilder<> &  ,
llvm::Module &  ,
llvm::ArrayRef< llvm::Value * >  Args 
)

Map a set of values into a tesla_key.

llvm::Constant* tesla::ConstructTransition ( llvm::IRBuilder<> &  ,
llvm::Module &  ,
const Transition &   
)

Construct a single tesla_transition.

llvm::Constant* tesla::ConstructTransitions ( llvm::IRBuilder<> &  ,
llvm::Module &  ,
const TEquivalenceClass &   
)

Construct a tesla_transitions for a TEquivalenceClass.

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

+ Here is the caller graph for this function:

llvm::BasicBlock* tesla::CreateInstrPreamble ( llvm::Module &  Mod,
llvm::Function *  F,
const llvm::Twine &  Prefix,
bool  SuppressDebugInstrumentation 
)

Initialise the instrumentation function's preamble.

For instance, we might like to insert a (conditional) printf that describes the event being interpreted.

llvm::raw_ostream& tesla::debugs ( llvm::StringRef  DebugModuleName = "tesla")

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

+ Here is the caller graph for this function:

std::string tesla::DotName ( const Argument *  A)

Convert an Argument into a very short name for GraphViz's dot.

Definition at line 106 of file Names.cpp.

References tesla::StructField::base, tesla::Argument::field, tesla::Argument::indirection, tesla::StructField::name, tesla::Argument::name, ShortName(), and tesla::Argument::type.

Referenced by tesla::FnTransition::DotLabel(), and InstanceName().

106  {
107  const static std::string Star = "&#8902;";
108  const static std::string Asterisk = "&#x2217;";
109 
110  if (A == NULL)
111  return Star;
112 
113  switch (A->type()) {
114  case Argument::Constant:
115  return ConstantName(A);
116 
117  case Argument::Variable:
118  return A->name();
119 
120  case Argument::Any:
121  return Star;
122 
123  case Argument::Indirect:
124  assert(A->has_indirection());
125  return Asterisk + DotName(&A->indirection());
126 
127  case Argument::Field:
128  assert(A->has_field());
129  return ShortName(&A->field().base()) + "." + A->field().name();
130  }
131 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

BasicBlock* tesla::FindBlock ( StringRef  Name,
Function &  Fn 
)

Definition at line 65 of file Instrumentation.cpp.

References panic().

Referenced by tesla::FnInstrumentation::AppendInstrumentation().

65  {
66  for (auto& B : Fn)
67  if (B.getName() == Name)
68  return &B;
69 
70  panic("instrumentation function '" + Fn.getName()
71  + "' has no '" + Name + "' block");
72 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::BasicBlock* tesla::FindBlock ( llvm::StringRef  Name,
llvm::Function &   
)

Find a BasicBlock within a Function.

llvm::Function* tesla::FindStateUpdateFn ( llvm::Module &  ,
llvm::Type *  IntType 
)

Find the libtesla function tesla_update_state.

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

+ Here is the caller graph for this function:

const char* tesla::Format ( Type *  T)

Definition at line 168 of file Instrumentation.cpp.

168  {
169  if (T->isPointerTy()) return " 0x%llx";
170  if (T->isIntegerTy()) return " %d";
171  if (T->isFloatTy()) return " %f";
172  if (T->isDoubleTy()) return " %f";
173 
174  assert(false && "Unhandled arg type");
175  abort();
176 }
llvm::Function* tesla::FunctionInstrumentation ( llvm::Module &  ,
const llvm::Function &  ,
FunctionEvent::Direction  ,
FunctionEvent::CallContext  ,
bool  SuppressDebugInstr 
)

Find (or create) one function-event instrumentation function.

Referenced by tesla::CalleeInstr::Build(), and tesla::CallerInstrumentation::Build().

+ Here is the caller graph for this function:

std::string tesla::InstanceName ( const ReferenceVector &  Refs,
bool  PlainAscii 
)

Convert the name of an automata instance.

Definition at line 150 of file Names.cpp.

References DotName(), and ShortName().

Referenced by tesla::State::Dot(), and tesla::State::String().

150  {
151 
152  std::stringstream InstanceName;
153 
154  InstanceName << "(";
155 
156  for (auto i = Refs.begin(); i != Refs.end(); ) {
157  InstanceName << (PlainAscii ? ShortName(*i) : DotName(*i));
158 
159  if (++i != Refs.end())
160  InstanceName << ",";
161  }
162 
163  InstanceName << ")";
164 
165  return InstanceName.str();
166 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Type* tesla::IntPtrType ( llvm::Module &  )

Extract the register_t type from an llvm::Module.

Referenced by KeyType().

+ Here is the caller graph for this function:

StructType* tesla::KeyType ( Module &  M)

Definition at line 127 of file Instrumentation.cpp.

References IntPtrType(), and TESLA_KEY_SIZE.

127  {
128  const char Name[] = "tesla_key";
129  StructType *T = M.getTypeByName(Name);
130 
131  if (T == NULL) {
132  // A struct tesla_key is just a mask and a set of keys.
133  vector<Type*> KeyElements(TESLA_KEY_SIZE, IntPtrType(M));
134  KeyElements.push_back(Type::getInt32Ty(M.getContext()));
135  T = StructType::create(KeyElements, Name);
136  }
137 
138  return T;
139 }

+ Here is the call graph for this function:

cl::opt<string> tesla::ManifestName ( "tesla-manifest"  ,
cl::  init".tesla",
cl::Hidden  ,
cl::  desc"Name of TESLA manifest file" 
)

Referenced by tesla::Manifest::defaultLocation(), and main().

+ Here is the caller graph for this function:

BasicBlock * tesla::MatchPattern ( LLVMContext &  Ctx,
StringRef  Name,
Function *  Fn,
BasicBlock *  MatchTarget,
BasicBlock *  NonMatchTarget,
Value *  Val,
const tesla::Argument Pattern 
)

Definition at line 416 of file Instrumentation.cpp.

References tesla::Argument::type, and tesla::Argument::value.

Referenced by tesla::FnInstrumentation::AppendInstrumentation().

419  {
420 
421  if (Pattern.type() != Argument::Constant)
422  return MatchTarget;
423 
424  auto *MatchBlock = BasicBlock::Create(Ctx, Name, Fn, MatchTarget);
425  MatchTarget->replaceAllUsesWith(MatchBlock);
426 
427  IRBuilder<> M(MatchBlock);
428  Value *PatternValue = ConstantInt::getSigned(Val->getType(), Pattern.value());
429  Value *Cmp;
430 
431  switch (Pattern.constantmatch()) {
432  case Argument::Exact:
433  Cmp = M.CreateICmpEQ(Val, PatternValue);
434  break;
435 
436  case Argument::Flags:
437  // test that x contains mask: (val & pattern) == pattern
438  Cmp = M.CreateICmpEQ(M.CreateAnd(Val, PatternValue), PatternValue);
439  break;
440 
441  case Argument::Mask:
442  // test that x contains no more than mask: (val & pattern) == val
443  Cmp = M.CreateICmpEQ(M.CreateAnd(Val, PatternValue), Val);
444  break;
445  }
446 
447  M.CreateCondBr(Cmp, MatchTarget, NonMatchTarget);
448 
449  return MatchBlock;
450 }

+ Here is the caller graph for this function:

template<class T >
bool tesla::operator!= ( const T &  x,
const T &  y 
)
inline

Definition at line 46 of file Protocol.h.

46 { return !(x == y); }
bool tesla::operator< ( const Location &  x,
const Location &  y 
)
inline

Definition at line 147 of file Protocol.h.

References tesla::Location::counter, tesla::Location::filename, and tesla::Location::line.

147  {
148  // Again, don't trust operator<(string&,string&) because of NULL funniness.
149  int cmp = strcmp(x.filename().c_str(), y.filename().c_str());
150  if (cmp < 0) return true;
151  if (cmp > 0) return false;
152 
153  if (x.line() < y.line()) return true;
154  if (x.line() > y.line()) return false;
155 
156  return (x.counter() < y.counter());
157 }
bool tesla::operator< ( const Identifier &  x,
const Identifier &  y 
)
inline

Definition at line 159 of file Protocol.h.

References tesla::Identifier::location, and tesla::Identifier::name.

159  {
160  if (x.has_name()) {
161  if (!y.has_name())
162  return true;
163 
164  return (x.name() < y.name());
165  }
166 
167  return (x.location() < y.location());
168 }
bool tesla::operator== ( const Location &  x,
const Location &  y 
)
inline

Definition at line 48 of file Protocol.h.

References tesla::Location::counter, tesla::Location::filename, and tesla::Location::line.

48  {
49  return (
50  // Don't rely on operator==(string&,string&); it might produce unexpected
51  // results depending on the presence of NULL terminators.
52  (strcmp(x.filename().c_str(), y.filename().c_str()) == 0)
53  && (x.line() == y.line())
54  && (x.counter() == y.counter())
55  );
56 }
bool tesla::operator== ( const Identifier &  x,
const Identifier &  y 
)
inline

Definition at line 58 of file Protocol.h.

References tesla::Identifier::location, and tesla::Identifier::name.

58  {
59  if (x.has_name())
60  return (x.name() == y.name());
61 
62  return (x.location() == y.location());
63 }
bool tesla::operator== ( const Argument &  A1,
const Argument &  A2 
)
inline

Definition at line 65 of file Protocol.h.

References tesla::Argument::index, tesla::Argument::name, tesla::Argument::type, and tesla::Argument::value.

65  {
66  if (A1.type() != A2.type())
67  return false;
68 
69  if (A1.has_index() ^ A2.has_index())
70  return false;
71 
72  if (A1.has_index() && ((A1.index() != A2.index())))
73  return false;
74 
75  if (A1.has_name() ^ A2.has_name())
76  return false;
77 
78  if (A1.has_name() && (A1.name() != A2.name()))
79  return false;
80 
81  if (A1.has_value() ^ A2.has_value())
82  return false;
83 
84  if (A1.has_value() && (A1.value() != A2.value()))
85  return false;
86 
87  return true;
88 }
bool tesla::operator== ( const NowEvent &  X,
const NowEvent &  Y 
)
inline

Definition at line 90 of file Protocol.h.

References tesla::NowEvent::location.

90  {
91  return X.location() == Y.location();
92 }
bool tesla::operator== ( const FunctionRef &  X,
const FunctionRef &  Y 
)
inline

Definition at line 94 of file Protocol.h.

References tesla::FunctionRef::name.

94  {
95  return (X.name() == Y.name());
96 }
bool tesla::operator== ( const FunctionEvent &  E1,
const FunctionEvent &  E2 
)
inline

Definition at line 98 of file Protocol.h.

References tesla::FunctionEvent::argument, tesla::FunctionEvent::context, tesla::FunctionEvent::direction, and tesla::FunctionEvent::function.

98  {
99  if (E1.function() != E2.function())
100  return false;
101 
102  if (E1.has_direction() ^ E2.has_direction())
103  return false;
104 
105  if (E1.has_direction() && (E1.direction() != E2.direction()))
106  return false;
107 
108  if (E1.has_context() ^ E2.has_context())
109  return false;
110 
111  if (E1.has_context() && (E1.context() != E2.context()))
112  return false;
113 
114  if (E1.has_expectedreturnvalue() ^ E2.has_expectedreturnvalue())
115  return false;
116 
117  if (E1.has_expectedreturnvalue()
118  && (E1.expectedreturnvalue() != E2.expectedreturnvalue()))
119  return false;
120 
121  if (E1.argument_size() != E2.argument_size()) return false;
122  for (int i=0 ; i<E1.argument_size() ; i++)
123  if (E1.argument(i) != E2.argument(i)) return false;
124 
125  return true;
126 }
bool tesla::operator== ( const StructField &  X,
const StructField &  Y 
)
inline

Definition at line 128 of file Protocol.h.

References tesla::StructField::base, tesla::StructField::index, tesla::StructField::name, and tesla::StructField::type.

128  {
129  return (
130  (X.type() == Y.type())
131  && (X.base() == Y.base())
132  && (X.name() == Y.name())
133  && (X.index() == Y.index())
134  );
135 }
bool tesla::operator== ( const FieldAssignment &  X,
const FieldAssignment &  Y 
)
inline

Definition at line 137 of file Protocol.h.

References tesla::FieldAssignment::field, tesla::FieldAssignment::operation, tesla::FieldAssignment::strict, and tesla::FieldAssignment::value.

137  {
138  return (
139  (X.field() == Y.field())
140  && (X.operation() == Y.operation())
141  && (X.value() == Y.value())
142  && (X.strict() == Y.strict())
143  );
144 }
void tesla::panic ( llvm::Twine  Message,
bool  PrintStackTrace = true 
)

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::Manifest::FindAutomaton(), FindBlock(), tesla::TeslaConsumer::HandleTranslationUnit(), main(), tesla::internal::NFAParser::Parse(), and tesla::FieldReferenceInstrumenter::runOnModule().

+ Here is the caller graph for this function:

Function* tesla::Printf ( Module &  Mod)

Find (or create) printf() declaration.

Definition at line 143 of file Instrumentation.cpp.

143  {
144  auto& Ctx = Mod.getContext();
145 
146  FunctionType *PrintfType = FunctionType::get(
147  IntegerType::get(Ctx, 32), // return: int32
148  PointerType::getUnqual(IntegerType::get(Ctx, 8)), // format string: char*
149  true); // use varargs
150 
151  Function* Printf = cast<Function>(
152  Mod.getOrInsertFunction("printf", PrintfType));
153 
154  return Printf;
155 }
template<class T >
void tesla::ReportError ( ASTContext &  Ctx,
StringRef  Message,
T *  Subject 
)

Definition at line 45 of file Visitor.cpp.

45  {
46  DiagnosticsEngine& Diag = Ctx.getDiagnostics();
47  int DiagID = Diag.getCustomDiagID(DiagnosticsEngine::Error,
48  ("TESLA: " + Message).str());
49 
50  Diag.Report(Subject->getLocStart(), DiagID) << Subject->getSourceRange();
51 }
std::string tesla::ShortName ( const Argument *  A)

Convert an Argument into a very short, human-readable name.

Definition at line 82 of file Names.cpp.

References tesla::StructField::base, tesla::Argument::field, tesla::Argument::indirection, tesla::StructField::name, tesla::Argument::name, and tesla::Argument::type.

Referenced by ArgString(), tesla::FieldAssignTransition::DotLabel(), tesla::SubAutomatonTransition::DotLabel(), DotName(), tesla::Manifest::FindAutomaton(), InstanceName(), tesla::internal::NFAParser::Parse(), tesla::FnTransition::ShortLabel(), tesla::FieldAssignTransition::ShortLabel(), tesla::SubAutomatonTransition::ShortLabel(), ShortName(), and tesla::Transition::String().

82  {
83  if (A == NULL)
84  return "X";
85 
86  switch (A->type()) {
87  case Argument::Constant:
88  return ConstantName(A);
89 
90  case Argument::Variable:
91  return A->name();
92 
93  case Argument::Any:
94  return "X";
95 
96  case Argument::Indirect:
97  assert(A->has_indirection());
98  return "*" + ShortName(&A->indirection());
99 
100  case Argument::Field:
101  assert(A->has_field());
102  return ShortName(&A->field().base()) + "." + A->field().name();
103  }
104 }

+ Here is the caller graph for this function:

std::string tesla::ShortName ( const Identifier &  ID)

Convert an Identifier into a short, human-readable name.

Definition at line 133 of file Names.cpp.

References tesla::Identifier::location, tesla::Identifier::name, and ShortName().

133  {
134  if (ID.has_name())
135  return ID.name();
136 
137  return ShortName(ID.location());
138 }

+ Here is the call graph for this function:

std::string tesla::ShortName ( const Location &  Loc)

Convert an Location into a short, human-readable name.

Definition at line 140 of file Names.cpp.

References tesla::Location::counter, tesla::Location::filename, and tesla::Location::line.

140  {
141  return (Twine()
142  + Loc.filename()
143  + ":"
144  + Twine(Loc.line())
145  + "#"
146  + Twine(Loc.counter())
147  ).str();
148 }
llvm::Function* tesla::StructInstrumentation ( llvm::Module &  ,
llvm::StructType *  ,
llvm::StringRef  FieldName,
size_t  Index,
bool  Store,
bool  SuppressDebugInstr 
)

Find (or create) one struct-field-event instrumentation function.

llvm::Constant* tesla::TeslaContext ( AutomatonDescription::Context  Context,
llvm::LLVMContext &  Ctx 
)

Find the constant for a libtesla context (either TESLA_CONTEXT_THREAD or TESLA_CONTEXT_GLOBAL).

Referenced by tesla::FieldInstrumentation::AppendInstrumentation(), tesla::FnInstrumentation::AppendInstrumentation(), and tesla::Parser::AssertionParser().

+ Here is the caller graph for this function:

Function* tesla::TeslaDebugging ( Module &  Mod)

Find (or create) tesla_debugging() declaration.

Definition at line 158 of file Instrumentation.cpp.

158  {
159  auto& Ctx = Mod.getContext();
160 
161  FunctionType *FnType = FunctionType::get(
162  IntegerType::get(Ctx, 32), // return: int32
163  PointerType::getUnqual(IntegerType::get(Ctx, 8))); // debug name: char*
164 
165  return cast<Function>(Mod.getOrInsertFunction("tesla_debugging", FnType));
166 }
llvm::StructType* tesla::TransitionSetType ( llvm::Module &  )

Extract the tesla_transitions type from an llvm::Module.

llvm::StructType* tesla::TransitionType ( llvm::Module &  )

Extract the tesla_transition type from an llvm::Module.

Variable Documentation

const std::string tesla::ANY = TESLA_BASE + "any"

Definition at line 63 of file Names.h.

const std::string tesla::ASSERTION_REACHED = INSTR_BASE + "assertion_reached"

Definition at line 90 of file Names.h.

const std::string tesla::AUTOMATON = TESLA_BASE + "automaton_"

Definition at line 54 of file Names.h.

const std::string tesla::AUTOMATON_DESC = AUTOMATON + "description"

Definition at line 55 of file Names.h.

Referenced by tesla::TeslaVisitor::VisitFunctionDecl().

const std::string tesla::AUTOMATON_MAPPING = AUTOMATON + "mapping"

Definition at line 56 of file Names.h.

const std::string tesla::AUTOMATON_USAGE = AUTOMATON + "usage"

Definition at line 57 of file Names.h.

Referenced by tesla::TeslaVisitor::VisitFunctionDecl().

const std::string tesla::AUTOMATON_USES = TESLA_BASE + "struct_uses_automaton"

Definition at line 58 of file Names.h.

Referenced by tesla::Parser::MappingParser(), and tesla::TeslaVisitor::VisitFunctionDecl().

const std::string tesla::CALL = INSTR_BASE + "call"

Definition at line 78 of file Names.h.

const std::string tesla::CALLEE = "callee_"

Definition at line 81 of file Names.h.

const std::string tesla::CALLER = "caller_"

Definition at line 82 of file Names.h.

raw_ostream& tesla::debug = debugs("tesla.instrumentation.field_assign")
const std::string tesla::ENTER = "enter_"

Definition at line 84 of file Names.h.

const std::string tesla::EVENT = TESLA_BASE + "event"

Definition at line 64 of file Names.h.

const std::string tesla::EXIT = "return_"

Definition at line 85 of file Names.h.

const std::string tesla::FLAGS = TESLA_BASE + "flags"

Definition at line 87 of file Names.h.

const std::string tesla::GLOBAL = TESLA_BASE + "global"

Definition at line 60 of file Names.h.

const std::string tesla::IGNORE = TESLA_BASE + "ignore"

Definition at line 65 of file Names.h.

const std::string tesla::INLINE_ASSERTION = TESLA_BASE + "inline_assertion"
const std::string tesla::INSTR_BASE = TESLA_BASE + "instrumentation_"

Definition at line 72 of file Names.h.

const std::string tesla::LLVM_PTR_ANNOTATION = "llvm.ptr.annotation"

Definition at line 50 of file Names.h.

Referenced by tesla::FieldReferenceInstrumenter::runOnModule().

const std::string tesla::LOAD = "load_"

Definition at line 75 of file Names.h.

const std::string tesla::MASK = TESLA_BASE + "mask"

Definition at line 88 of file Names.h.

const std::string tesla::NOW = TESLA_BASE + "now"

Definition at line 66 of file Names.h.

const std::string tesla::OPTIONAL = TESLA_BASE + "optional"

Definition at line 67 of file Names.h.

const std::string tesla::PERTHREAD = TESLA_BASE + "perthread"

Definition at line 61 of file Names.h.

const std::string tesla::RETURN = INSTR_BASE + "return"

Definition at line 79 of file Names.h.

const std::string tesla::SEQUENCE = TESLA_BASE + "sequence"

Definition at line 68 of file Names.h.

const std::string tesla::STORE = "store_"

Definition at line 76 of file Names.h.

const std::string tesla::STRUCT_INSTR = INSTR_BASE + "struct_field_"

Definition at line 74 of file Names.h.

const std::string tesla::TESLA_BASE = "__tesla_"

Definition at line 52 of file Names.h.

Referenced by tesla::TeslaVisitor::VisitCallExpr().