source: icGREP/icgrep-devel/icgrep/pablo/pe_var.h @ 5202

Last change on this file since 5202 was 5202, checked in by nmedfort, 3 years ago

Initial work on adding types to PabloAST and mutable Var objects.

File size: 2.9 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef PE_VAR_H
8#define PE_VAR_H
9
10#include <pablo/pabloAST.h>
11#include <pablo/pe_string.h>
12#include <pablo/pe_integer.h>
13
14namespace pablo {
15
16class Assign;
17
18// A Var is unique in that it is not a statement but a "lives" within a
19// scope and cannot be accessed outside of it. A Var is mutable (via an
20// Assign instruction.
21
22class Var : public PabloAST {
23    friend class PabloBlock;
24    friend class PabloAST;
25    friend class PabloFunction;
26    friend class Statement;
27public:
28    static inline bool classof(const PabloAST * e) {
29        return e->getClassTypeId() == ClassTypeId::Var;
30    }
31    static inline bool classof(const void *) {
32        return false;
33    }
34protected:
35    Var(const PabloAST * name, Type * const type)
36    : PabloAST(ClassTypeId::Var, type, cast<String>(name)) {
37
38    }
39};
40
41class Extract : public Statement {
42    friend class PabloBlock;
43public:
44    static inline bool classof(const PabloAST * e) {
45        return e->getClassTypeId() == ClassTypeId::Extract;
46    }
47    static inline bool classof(const void *) {
48        return false;
49    }
50    virtual ~Extract(){
51    }
52    inline PabloAST * getArray() const {
53        return getOperand(0);
54    }
55    inline Integer * getIndex() const {
56        return cast<Integer>(getOperand(1));
57    }
58protected:
59    Extract(PabloAST * array, PabloAST * const index, const String * const name)
60    : Statement(ClassTypeId::Extract, cast<ArrayType>(array->getType())->getArrayElementType(), {array, cast<Integer>(index)}, name) {
61
62    }
63};
64
65//class Extract : public PabloAST {
66//    friend class PabloBlock;
67//public:
68//    static inline bool classof(const PabloAST * e) {
69//        return e->getClassTypeId() == ClassTypeId::Extract;
70//    }
71//    static inline bool classof(const void *) {
72//        return false;
73//    }
74//    virtual ~Extract(){
75//    }
76//    inline const String * getName() const {
77//        if (isa<Parameter>(mArray)) {
78//            return cast<Parameter>(mArray)->getName();
79//        } else {
80//            return cast<Statement>(mArray)->getName();
81//        }
82//    }
83//    inline const PabloAST * getArray() const {
84//        return mArray;
85//    }
86//    inline const Integer * getIndex() const {
87//        return mIndex;
88//    }
89//protected:
90//    Extract(PabloAST * array, PabloAST * const index)
91//    : PabloAST(ClassTypeId::Extract, array->getType()->getIndexedType())
92//    , mArray(array)
93//    , mIndex(cast<Integer>(index)) {
94//        assert (isa<Parameter>(array) || isa<Statement>(array));
95//    }
96//private:
97//    PabloAST * mArray;
98//    Integer * mIndex;
99//};
100
101//class ParameterBinding {
102//    using Allocator = SlabAllocator<Parameter *>;
103
104//public:
105
106//    void add(Parameter * const param);
107
108//private:
109//    std::vector<Parameter *, Allocator> mParameters;
110//};
111
112
113}
114
115#endif // PE_VAR_H
116
117
Note: See TracBrowser for help on using the repository browser.