-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_elem.h
40 lines (34 loc) · 848 Bytes
/
set_elem.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
#ifndef __set_elem_h__
#define __set_elem_h__
#include "stmt.h"
#include "access.h"
class SetElem : public Stmt{
public:
Id *array;
Expr *index;
Expr *expr;
SetElem(Access *x , Expr *y)
{
array = x->array;
index = x->index;
expr = y;
if( check(x->type,expr->type) == NULL)
{
error("type error");
}
};
Type * check(Type *p1 , Type *p2)
{
if(p1->isArray() || p2->isArray()) return NULL;
else if( p1 == p2) return p2;
else if ( Type::numeric(p1) && Type::numeric(p2) ) return p2;
else return NULL;
};
void gen(int b , int a)
{
std::string s1 = index->reduce()->toString();
std::string s2 = expr->reduce()->toString();
emit(array->toString() + " [" + s1 + " ]= " + s2);
};
};
#endif