-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogical.h
More file actions
50 lines (43 loc) · 1002 Bytes
/
logical.h
File metadata and controls
50 lines (43 loc) · 1002 Bytes
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
#ifndef __logical_h__
#define __logical_h__
#include "expr.h"
#include <string>
#include "temp.h"
class Token;
class Type;
class Logical : public Expr{
public:
Expr *expr1 , *expr2;
Logical(Token * tok,Expr *x1 , Expr *x2)
: Expr(tok,NULL)
{
expr1 = x1;
expr2 = x2;
type = check(expr1->type,expr2->type);
}
virtual Type *check(Type *p1 , Type *p2)
{
if(p1 == Type::Bool() && p2 == Type::Bool()){
return Type::Bool();
}
return NULL;
}
Expr * gen()
{
int f = newlabel();
int a = newlabel();
this->jumping(0,f);
Temp *temp = new Temp(type);
emit(temp->toString()+" = true");
emit("goto L" + std::to_string(a));
emitlabel(f);
emit(temp->toString() + " = false");
emitlabel(a);
return temp;
}
std::string toString()
{
return expr1->toString()+" "+op->toString()+" "+expr2->toString();
}
};
#endif