replicode
guard_builder.h
Go to the documentation of this file.
1 // guard_builder.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef guard_builder_h
32 #define guard_builder_h
33 
34 #include "factory.h"
35 
36 
37 namespace r_exec {
38 
40  public _Object {
41 public:
42  GuardBuilder();
43  virtual ~GuardBuilder();
44 
45  virtual void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
46 };
47 
48 // fwd: t2=t0+period, t3=t1+period.
49 // bwd: t0=t2-period, t1=t3-period.
51  public GuardBuilder {
52 protected:
54 
55  void write_guard(Code *mdl, uint16_t l, uint16_t r, uint16_t opcode, uint64_t offset, uint16_t &write_index, uint16_t &extent_index) const;
56  void _build(Code *mdl, uint16_t t0, uint16_t t1, uint16_t &write_index) const;
57 public:
59  virtual ~TimingGuardBuilder();
60 
61  virtual void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
62 };
63 
64 // fwd: q1=q0+speed*period.
65 // bwd: speed=(q1-q0)/period, speed.after=q1.after-offset, speed.before=q1.before-offset.
67  public TimingGuardBuilder {
68 private:
69  uint64_t offset; // period-(speed.after-t0).
70 
71  void _build(Code *mdl, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const;
72 public:
75 
76  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
77 };
78 
79 // bwd: cmd.after=q1.after-offset, cmd.before=cmd.after+cmd_duration.
81  public TimingGuardBuilder {
82 protected:
85 
86  void _build(Code *mdl, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const;
87 public:
88  NoArgCmdGuardBuilder(uint64_t period, uint64_t offset, uint64_t cmd_duration);
90 
91  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
92 };
93 
94 // bwd: cmd.after=q1.after-period, cmd.before=q1.before-period.
96  public TimingGuardBuilder {
97 protected:
98  uint16_t cmd_arg_index;
99 
100  void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const;
101  void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
102 
103  CmdGuardBuilder(uint64_t period, uint16_t cmd_arg_index);
104 public:
105  virtual ~CmdGuardBuilder();
106 };
107 
108 // fwd: q1=q0*cmd_arg.
109 // bwd: cmd_arg=q1/q0.
111  public CmdGuardBuilder {
112 public:
114  ~MCGuardBuilder();
115 
116  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
117 };
118 
119 // fwd: q1=q0+cmd_arg.
120 // bwd: cmd_arg=q1-q0.
122  public CmdGuardBuilder {
123 private:
124 
125 public:
127  ~ACGuardBuilder();
128 
129  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
130 };
131 
132 // bwd: cause.after=t2-offset, cause.before=t3-offset.
134  public TimingGuardBuilder {
135 protected:
136  double constant;
138 
139  void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const;
140  void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
141 
142  ConstGuardBuilder(uint64_t period, double constant, uint64_t offset);
143 public:
145 };
146 
147 // fwd: q1=q0*constant.
148 // bwd: q0=q1/constant.
150  public ConstGuardBuilder {
151 public:
153  ~MGuardBuilder();
154 
155  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
156 };
157 
158 // fwd: q1=q0+constant.
159 // bwd: q0=q1-constant.
161  public ConstGuardBuilder {
162 public:
164  ~AGuardBuilder();
165 
166  void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const;
167 };
168 }
169 
170 
171 #endif
uint64_t cmd_duration
Definition: guard_builder.h:84
Definition: factory.h:98
TimingGuardBuilder(uint64_t period)
Definition: guard_builder.cpp:53
Definition: guard_builder.h:95
~NoArgCmdGuardBuilder()
Definition: guard_builder.cpp:208
uint64_t offset
Definition: guard_builder.h:137
MGuardBuilder(uint64_t period, double constant, uint64_t offset)
Definition: guard_builder.cpp:444
Definition: base.h:75
Definition: guard_builder.h:110
Definition: guard_builder.h:39
double constant
Definition: guard_builder.h:136
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:450
~MGuardBuilder()
Definition: guard_builder.cpp:447
virtual void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:96
uint16_t cmd_arg_index
Definition: guard_builder.h:98
Definition: guard_builder.h:149
SGuardBuilder(uint64_t period, uint64_t offset)
Definition: guard_builder.cpp:117
CmdGuardBuilder(uint64_t period, uint16_t cmd_arg_index)
Definition: guard_builder.cpp:267
Definition: _context.cpp:34
uint64_t period
Definition: guard_builder.h:53
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:182
void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const
Definition: guard_builder.cpp:273
Definition: guard_builder.h:50
MCGuardBuilder(uint64_t period, double cmd_arg_index)
Definition: guard_builder.cpp:343
uint64_t offset
Definition: guard_builder.h:69
virtual ~TimingGuardBuilder()
Definition: guard_builder.cpp:56
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:463
~ACGuardBuilder()
Definition: guard_builder.cpp:359
virtual void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:42
NoArgCmdGuardBuilder(uint64_t period, uint64_t offset, uint64_t cmd_duration)
Definition: guard_builder.cpp:205
~AGuardBuilder()
Definition: guard_builder.cpp:460
AGuardBuilder(uint64_t period, double constant, uint64_t offset)
Definition: guard_builder.cpp:457
Definition: guard_builder.h:80
~ConstGuardBuilder()
Definition: guard_builder.cpp:372
ConstGuardBuilder(uint64_t period, double constant, uint64_t offset)
Definition: guard_builder.cpp:369
void _build(Code *mdl, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const
Definition: guard_builder.cpp:123
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:349
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:244
void _build(Code *mdl, uint16_t fwd_opcode, uint16_t bwd_opcode, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const
Definition: guard_builder.cpp:375
Definition: guard_builder.h:66
Definition: guard_builder.h:160
~SGuardBuilder()
Definition: guard_builder.cpp:120
void _build(Code *mdl, uint16_t q0, uint16_t t0, uint16_t t1, uint16_t &write_index) const
Definition: guard_builder.cpp:211
uint64_t offset
Definition: guard_builder.h:83
Definition: object.h:172
Definition: guard_builder.h:133
virtual ~CmdGuardBuilder()
Definition: guard_builder.cpp:270
void build(Code *mdl, _Fact *premise_pattern, _Fact *cause_pattern, uint16_t &write_index) const
Definition: guard_builder.cpp:362
void write_guard(Code *mdl, uint16_t l, uint16_t r, uint16_t opcode, uint64_t offset, uint16_t &write_index, uint16_t &extent_index) const
Definition: guard_builder.cpp:59
GuardBuilder()
Definition: guard_builder.cpp:36
virtual ~GuardBuilder()
Definition: guard_builder.cpp:39
~MCGuardBuilder()
Definition: guard_builder.cpp:346
Definition: guard_builder.h:121
void _build(Code *mdl, uint16_t t0, uint16_t t1, uint16_t &write_index) const
Definition: guard_builder.cpp:70
ACGuardBuilder(uint64_t period, uint16_t cmd_arg_index)
Definition: guard_builder.cpp:356