-
Notifications
You must be signed in to change notification settings - Fork 7
/
state.h
151 lines (134 loc) · 3.18 KB
/
state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*************************************************************************
*
* Copyright (c) 2021 Rajit Manohar
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#ifndef __ACTSIM_STATE_H__
#define __ACTSIM_STATE_H__
#include <act/act.h>
class ActSimCore;
class expr_multires {
public:
expr_multires(Data *d = NULL) {
_d = NULL;
nvals = 0;
v = NULL;
_init (d);
}
~expr_multires() {
_delete_objects ();
}
void setSingle (BigInt &x) {
_d = NULL;
if (nvals != 1) {
_delete_objects ();
nvals = 1;
NEW (v, BigInt);
new (v) BigInt;
}
*v = x;
}
void setSingle (unsigned long val) {
_d = NULL;
if (nvals != 1) {
_delete_objects ();
nvals = 1;
NEW (v, BigInt);
new (v) BigInt;
}
v->setWidth (BIGINT_BITS_ONE);
v->setVal (0, val);
}
expr_multires (expr_multires &&m) {
v = m.v;
nvals = m.nvals;
m.nvals = 0;
m.v = NULL;
_d = m._d;
}
expr_multires (expr_multires &m) {
nvals = m.nvals;
if (nvals > 0) {
MALLOC (v, BigInt, nvals);
for (int i=0; i < nvals; i++) {
new (&v[i]) BigInt;
v[i] = m.v[i];
}
}
_d = m._d;
}
void Print (FILE *fp);
expr_multires &operator=(expr_multires &&m) {
if (nvals > 0) {
FREE (v);
}
v = m.v;
nvals = m.nvals;
m.nvals = 0;
_d = m._d;
return *this;
}
expr_multires &operator=(expr_multires &m) {
if (nvals != m.nvals) {
_delete_objects ();
if (m.nvals > 0) {
MALLOC (v, BigInt, m.nvals);
for (int i=0; i < m.nvals; i++) {
new (&v[i]) BigInt;
}
}
}
nvals = m.nvals;
if (nvals > 0) {
for (int i=0; i < nvals; i++) {
v[i] = m.v[i];
}
}
_d = m._d;
return *this;
}
void fillValue (Data *d, ActSimCore *sc, int off_i, int off_b);
void setField (ActId *field, BigInt *v);
void setField (ActId *field, expr_multires *v);
BigInt *getField (ActId *x);
expr_multires getStruct (ActId *x);
BigInt *v;
int nvals;
private:
void _delete_objects () {
if (nvals > 0) {
for (int i=0; i < nvals; i++) {
v[i].~BigInt();
}
FREE (v);
}
v = NULL;
nvals = 0;
}
int _count (Data *d);
void _init_helper (Data *d, int *pos);
void _init (Data *d);
void _fill_helper (Data *d, ActSimCore *sc, int *pos, int *oi, int *ob);
Data *_d;
};
struct extra_state_alloc {
void *space;
int sz;
};
#endif /* __ACTSIM_STATE_H__ */