ACT Library
Loading...
Searching...
No Matches
act_array.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * This file is part of the ACT library
4 *
5 * Copyright (c) 2018-2019 Rajit Manohar
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 **************************************************************************
23 */
24#ifndef __ACT_ARRAY_H__
25#define __ACT_ARRAY_H__
26
27#include <act/expr.h>
28#include <common/list.h>
29
30class ActNamespace;
31class Scope;
32class Arraystep;
33class ActId;
34class InstType;
35class ValueIdx;
36
37
65class Array {
66
82 };
83
95 long lo, hi;
96 };
97
103 unsigned int isrange:2;
105 union {
108 };
109 };
110
111
112 public:
116 int isSparse() { return next == NULL ? 0 : 1; }
117
122 int isDeref() { return deref; }
123
128 void mkArray() { deref = 0; }
129
133 int nDims() { return dims; }
134
140 int effDims();
141
152 void Concat (Array *a);
153
159 void preConcat (Array *a);
160
171 int isEqual (Array *a, int strict);
172
178
186 void Merge (Array *a);
187
195 Array (Expr *e, Expr *f = NULL);
196
202 Array (int lo, int hi);
203
208 Array (int idx);
209
211
219 void Print (FILE *fp, int style = 0);
220
228 void sPrint (char *buf, int sz, int style = 0);
229
237 int sPrintOne (char *buf, int sz, int style = 0);
238
245 void PrintOne (FILE *fp, int style = 0);
246
251 Array *Next() { return next; }
252
254
256
259
260 int isExpanded() { return expanded; }
263 int size();
266 int range_size(int d);
276 void update_range (int d, int lo, int hi);
277
281 int isrange (int d) { return (r[d].u.ex.isrange == 1); }
282
288 Expr *lo (int d) { return r[d].u.ue.lo; }
289
295 Expr *hi (int d) { return r[d].u.ue.hi; }
296
304 Array *Expand (ActNamespace *ns, Scope *s, int is_ref = 0);
305
313 Array *ExpandRef (ActNamespace *ns, Scope *s) { return Expand (ns, s, 1); }
314
323
332 int Validate (Array *a);
333
340
348 Expr *getDeref (int idx);
349
359 int Offset (Array *a);
360
368 int Offset (int *a);
369
376 Array *unOffset (int offset);
377
387 Arraystep *stepper(Array *sub = NULL);
388
389private:
390 Array ();
392 int in_range (Array *a);
393 int in_range (int *a);
394
395 int dims;
401 struct range {
402 union {
405 } u;
406 } *r;
408 void dumprange (struct range *r);
419 void _merge_range (int idx, Array *prev, struct range *m);
420
427 int overlapping (struct range *a, struct range *b);
428
429
430 unsigned int range_sz;
437 unsigned int deref:1;
440 unsigned int expanded:1;
443 friend class Arraystep;
444};
445
471public:
478 Arraystep (Array *a, Array *sub = NULL);
479
481
482 void step();
483
484 int index() { return idx; }
486
487 int index(Array *b) { return b->Offset (deref); }
491
492 int isend();
493
494 int typesize() { return base->size(); }
496
497 char *string(int style = 0);
500
503
509 void Print (FILE *fp, int style = 0);
510
511private:
512 int idx;
513 int *deref;
517};
518
519
520class AExprstep;
521
529class AExpr {
530 public:
535 enum type {
536 CONCAT, COMMA, /*SUBRANGE,*/ EXPR
537 };
538
541
542 AExpr (Expr *e);
544
548
550
551 int isEqual (AExpr *a);
554 AExpr *GetLeft () { return l; }
555 AExpr *GetRight () { return r; }
556
557 void SetRight (AExpr *a) { r = a; }
558
559 void Print (FILE *fp);
560 void sPrint (char *buf, int sz);
561
563
575 InstType *getInstType (Scope *s, int *islocal, int expanded = 0);
576
577 AExpr *Expand (ActNamespace *, Scope *, int is_lval = 0);
586
591 int isBase() { return t == EXPR ? 1 : 0; }
592
601
604
607
608 private:
609 enum type t;
610
615 AExpr *l, *r;
617
618 friend class AExprstep;
619};
620
632public:
635 void step();
636 int isend();
637
638 unsigned long getPInt();
639 long getPInts();
640 double getPReal();
641 int getPBool();
643
653 void getID (ActId **id, int *idx, int *typesize);
654
660 void getsimpleID (ActId **id, int *idx, int *typesize);
661
666
667
668private:
669 list_t *stack;
671
672 union {
674 struct {
675 /* this is used for non-parameter identifiers */
679 int issimple:1;
680 } id;
681 struct {
682 /* this is used for arrays of parameters */
685 Arraystep *a;
686 } vx;
687 } u;
688 unsigned int type:2;
690};
691
692#endif /* __ACT_ARRAY_H__ */
Array expressions.
Definition: act_array.h:529
AExpr * GetLeft()
access left component
Definition: act_array.h:554
enum type t
simple/compound expression type
Definition: act_array.h:609
InstType * getInstType(Scope *s, int *islocal, int expanded=0)
void sPrint(char *buf, int sz)
print array expression to string
int isEqual(AExpr *a)
AExpr(type t, AExpr *l, AExpr *r)
AExpr(Expr *e)
AExpr * r
Definition: act_array.h:615
int isBase()
Definition: act_array.h:591
int isArrayExpr()
void Print(FILE *fp)
print array expression
AExpr * GetRight()
access right component
Definition: act_array.h:555
AExpr * l
Definition: act_array.h:615
InstType * isType()
AExprstep * stepper()
type
Definition: act_array.h:535
@ EXPR
Definition: act_array.h:536
@ COMMA
Definition: act_array.h:536
@ CONCAT
Definition: act_array.h:536
void SetRight(AExpr *a)
assign right component to a
Definition: act_array.h:557
AExpr * Clone()
deep copy of array expression
AExpr(ActId *e)
ActId * toid()
AExpr * Expand(ActNamespace *, Scope *, int is_lval=0)
Class for stepping through an array expression element-by-element.
Definition: act_array.h:631
list_t * stack
stack of AExprs to be processed
Definition: act_array.h:669
void getID(ActId **id, int *idx, int *typesize)
Expr * const_expr
current constant expression, or:
Definition: act_array.h:673
Scope * s
scope in which to evaluate
Definition: act_array.h:684
ValueIdx * vx
base value idx
Definition: act_array.h:683
AExprstep(AExpr *a)
construct an array expression stepper
union AExprstep::@3 u
Arraystep * a
if it is an array or subrange
Definition: act_array.h:677
unsigned long getPInt()
get the current pint value
int isend()
returns 1 on an end of array, 0 otherwise
InstType * getPType()
get the current ptype value
long getPInts()
get the current signed pint(not used)
double getPReal()
get the current preal value
AExpr * cur
current element being processed
Definition: act_array.h:670
struct AExprstep::@3::@4 id
int getPBool()
get the current pbool value
void step()
advance by one element
int isSimpleID()
int issimple
1 if this is a raw id
Definition: act_array.h:679
unsigned int type
Definition: act_array.h:688
ActId * act_id
identifier
Definition: act_array.h:676
void getsimpleID(ActId **id, int *idx, int *typesize)
This class is used to store Act identifiers that correspond to instances. Identifiers have an optiona...
Definition: act_id.h:56
The ActNamespace class holds all the information about a namespace.
Definition: namespaces.h:469
Dense arrays, sparse arrays, and array dereferences.
Definition: act_array.h:65
int overlapping(struct range *a, struct range *b)
struct Array::range * r
void sPrint(char *buf, int sz, int style=0)
unsigned int expanded
Definition: act_array.h:440
int Offset(Array *a)
int Offset(int *a)
Expr * lo(int d)
Definition: act_array.h:288
void preConcat(Array *a)
int isEqual(Array *a, int strict)
Array(int lo, int hi)
Expr * getDeref(int idx)
int isrange(int d)
Definition: act_array.h:281
int isDeref()
Definition: act_array.h:122
int in_range(Array *a)
offset within a range, -1 if missing
Array(int idx)
Array * CloneOne()
only return a deep copy of the current dense range
void mkArray()
Definition: act_array.h:128
int in_range(int *a)
offset within a range, -1 if missing
void Merge(Array *a)
Array(Expr *e, Expr *f=NULL)
int effDims()
void PrintOne(FILE *fp, int style=0)
void dumprange(struct range *r)
void Print(FILE *fp, int style=0)
int isDynamicDeref()
int isSparse()
Definition: act_array.h:116
Array * Expand(ActNamespace *ns, Scope *s, int is_ref=0)
unsigned int range_sz
Definition: act_array.h:430
int size()
int sPrintOne(char *buf, int sz, int style=0)
int nDims()
Definition: act_array.h:133
unsigned int deref
Definition: act_array.h:437
int isExpanded()
Definition: act_array.h:260
void update_range(int d, int lo, int hi)
Array * unOffset(int offset)
Array * next
Definition: act_array.h:433
Arraystep * stepper(Array *sub=NULL)
int dims
Definition: act_array.h:395
int Validate(Array *a)
Array * ExpandRefCHP(ActNamespace *ns, Scope *s)
int isDimCompatible(Array *a)
void Concat(Array *a)
Expr * hi(int d)
Definition: act_array.h:295
int range_size(int d)
Array * Clone()
returns a deep copy of the entire array
Array * Next()
Definition: act_array.h:251
Array * Reduce()
Array * ExpandRef(ActNamespace *ns, Scope *s)
Definition: act_array.h:313
void _merge_range(int idx, Array *prev, struct range *m)
Class for stepping through an array.
Definition: act_array.h:470
void step()
advance to the next element in the array
Arraystep(Array *a, Array *sub=NULL)
void Print(FILE *fp, int style=0)
Array * insubrange
part of subrange walker state
Definition: act_array.h:516
int index(Array *b)
Definition: act_array.h:487
int index()
Definition: act_array.h:484
int idx
used to track the current index
Definition: act_array.h:512
int isend()
char * string(int style=0)
int typesize()
Definition: act_array.h:494
Array * toArray()
int * deref
used to track the current array de-reference
Definition: act_array.h:513
Array * subrange
the subrange, if any
Definition: act_array.h:515
Array * base
the base array
Definition: act_array.h:514
An instance type.
Definition: inst.h:92
This is the data structure that holds all instances and their associated types within a scope....
Definition: namespaces.h:77
This class is used to create an instance in a scope. The name comes from the fact that this is used t...
Definition: value.h:342
A range specifier that can include parameters/etc. This is used during parsing, prior to expansion.
Definition: act_array.h:80
Expr * lo
Definition: act_array.h:81
Expr * hi
Definition: act_array.h:81
A range specifier post expansion where all parameters/etc. are substituted, resulting in a constant r...
Definition: act_array.h:94
long lo
Definition: act_array.h:95
long hi
Definition: act_array.h:95
Used to hold the result of an expanded array range reference.
Definition: act_array.h:102
Expr * deref
for case 2, dynamic de-reference
Definition: act_array.h:107
unsigned int isrange
Definition: act_array.h:103
struct _act_array_exprex_pair idx
for case 0 and 1
Definition: act_array.h:106
Definition: act_array.h:401
union Array::range::@2 u
struct _act_array_expr_pair ue
unexanded range
Definition: act_array.h:403
struct _act_array_internal ex
expanded range
Definition: act_array.h:404
Definition: expr.h:79