1
/* PeTe - Petri Engine exTremE
2
* Copyright (C) 2011 Jonas Finnemann Jensen <jopsen@gmail.com>,
3
* Thomas Søndersø Nielsen <primogens@gmail.com>,
4
* Lars Kærlund Østergaard <larsko@gmail.com>,
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "../PetriNet.h"
24
#include "../Structures/DistanceMatrix.h"
25
#include "../Structures/StateConstraints.h"
31
namespace PetriEngine {
34
/** Context provided for context analysis */
35
class AnalysisContext{
37
std::vector<std::string> _places;
38
std::vector<std::string> _variables;
39
std::vector<ExprError> _errors;
41
/** A resolution result */
42
struct ResolutionResult {
43
/** Offset in relevant vector */
45
/** True, if the resolution was successful */
47
/** True if the identifer was resolved to a place */
50
AnalysisContext(const PetriNet& net)
51
: _places(net.placeNames()), _variables(net.variableNames()) {}
52
AnalysisContext(const std::vector<std::string>& places,
53
const std::vector<std::string>& variables)
54
: _places(places), _variables(variables) {}
56
/** Resolve an identifier */
57
ResolutionResult resolve(std::string identifier) const{
58
ResolutionResult result;
60
result.success = false;
61
for(size_t i = 0; i < _places.size(); i++){
62
if(_places[i] == identifier){
64
result.isPlace = true;
65
result.success = true;
69
for(size_t i = 0; i < _variables.size(); i++){
70
if(_variables[i] == identifier){
72
result.isPlace = false;
73
result.success = true;
81
void reportError(const ExprError& error){
82
_errors.push_back(error);
84
/** Get list of errors */
85
const std::vector<ExprError>& errors() const{
90
/** Context provided for evalation */
91
class EvaluationContext{
93
/** Create evaluation context, this doesn't take ownershop */
94
EvaluationContext(const MarkVal* marking, const VarVal* assignment){
96
_assignment = assignment;
98
const MarkVal* marking() const {return _marking;}
99
const VarVal* assignment() const {return _assignment;}
101
const MarkVal* _marking;
102
const VarVal* _assignment;
105
/** Context for distance computation */
106
class DistanceContext : public EvaluationContext{
108
/** Strategy flags for distance computation */
109
enum DistanceStrategy{
119
DistanceContext(const PetriNet& net,
120
DistanceStrategy strategy,
121
const MarkVal* marking,
122
const VarVal* valuation,
123
Structures::DistanceMatrix* dm)
124
: EvaluationContext(marking, valuation), _net(net) {
125
_strategy = strategy;
129
DistanceStrategy strategy() const { return _strategy; }
130
const PetriNet& net() const { return _net; }
131
void negate() { _negated = !_negated; }
132
bool negated() const { return _negated; }
133
const Structures::DistanceMatrix* distanceMatrix() const { return _dm; }
135
const PetriNet& _net;
136
DistanceStrategy _strategy;
138
Structures::DistanceMatrix* _dm;
141
/** Constraint Analysis Context used for over-approximation */
142
class ConstraintAnalysisContext{
144
typedef std::vector<Structures::StateConstraints*> ConstraintSet;
146
ConstraintAnalysisContext(const PetriNet& net) : _net(net) {
150
const PetriNet& net() const { return _net; }
153
ConstraintSet retval;
155
const PetriNet& _net;
158
/** Context for condition to TAPAAL export */
159
class TAPAALConditionExportContext{
165
/** Just-In-Time compilation context */
166
class CodeGenerationContext{
168
CodeGenerationContext(llvm::Value* marking,
169
llvm::Value* valuation,
170
llvm::BasicBlock* label,
171
llvm::LLVMContext& context)
172
: _context(context) {
174
_valuation = valuation;
178
llvm::Value* marking() { return _marking; }
179
/** Variable valuation */
180
llvm::Value* valuation() { return _valuation; }
181
/** Label for the current code block */
182
llvm::BasicBlock* label() { return _label; }
183
/** LLVM Context that is currently generating */
184
llvm::LLVMContext& context() { return _context; }
186
llvm::Value* _marking;
187
llvm::Value* _valuation;
188
llvm::BasicBlock* _label;
189
llvm::LLVMContext& _context;