Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
latte
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zygzagZ
latte
Commits
69a63946
Commit
69a63946
authored
Jan 11, 2021
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix jump code generation
parent
b00ae3ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
19 deletions
+16
-19
QuadrupleGenerator.cpp
src/codeGen/QuadrupleGenerator.cpp
+8
-8
QuadrupleGenerator.h
src/codeGen/QuadrupleGenerator.h
+7
-10
Variable.h
src/codeGen/Variable.h
+1
-1
No files found.
src/codeGen/QuadrupleGenerator.cpp
View file @
69a63946
...
...
@@ -144,9 +144,7 @@ void QuadrupleGenerator::visitNeg(Neg *p) {
}
void
QuadrupleGenerator
::
visitNot
(
Not
*
p
)
{
swap
(
labelTrue
,
labelFalse
);
auto
var
=
evalExpr
(
p
->
expr_
);
swap
(
labelTrue
,
labelFalse
);
auto
var
=
evalJump
(
p
->
expr_
,
labelFalse
,
labelTrue
);
lastVar
=
alloc
();
addQuad
<
QAssign
>
(
lastVar
,
Op
::
Not
,
var
);
if
((
lastVar
->
constExpr
=
var
->
constExpr
))
{
...
...
@@ -187,8 +185,8 @@ void QuadrupleGenerator::visitEAdd(EAdd *p) {
}
void
QuadrupleGenerator
::
visitERel
(
ERel
*
p
)
{
auto
l
=
eval
Jump
(
p
->
expr_1
,
nullptr
,
nullptr
);
auto
r
=
eval
Jump
(
p
->
expr_2
,
nullptr
,
nullptr
);
auto
l
=
eval
Expr
(
p
->
expr_1
);
auto
r
=
eval
Expr
(
p
->
expr_2
);
lastVar
=
alloc
();
p
->
relop_
->
accept
(
this
);
if
((
lastVar
->
constExpr
=
l
->
constExpr
&&
r
->
constExpr
))
{
...
...
@@ -268,7 +266,7 @@ void QuadrupleGenerator::visitEOr(EOr *p) {
flushBasicBlock
();
leftValBlock
->
append
(
block
);
auto
r
=
eval
Expr
(
p
->
expr_2
);
auto
r
=
eval
Jump
(
p
->
expr_2
,
labelTrue
,
labelFalse
);
if
(
!
r
)
return
;
if
(
r
->
constExpr
)
{
...
...
@@ -327,7 +325,7 @@ void QuadrupleGenerator::visitEIndexAcc(EIndexAcc *p) {
}
void
QuadrupleGenerator
::
visitEClsMmbr
(
EClsMmbr
*
p
)
{
auto
l
=
eval
Expr
(
p
->
expr_
);
auto
l
=
eval
Jump
(
p
->
expr_
,
labelTrue
,
labelFalse
);
auto
var
=
p
->
pident_
->
var
.
lock
();
assert
(
var
);
// it cannot be function, as function might only be used in EApp and are handled directly there
...
...
@@ -457,6 +455,8 @@ void QuadrupleGenerator::assign(Expr* lval, VariablePtr val) {
}
else
{
// local variable - only assign
addQuad
<
QAssign
>
(
dest
,
Op
::
Copy
,
val
);
if
((
dest
->
constExpr
=
val
->
constExpr
))
dest
->
val
=
val
->
val
;
}
}
...
...
@@ -637,4 +637,4 @@ void QuadrupleGenerator::visitForEach(ForEach *p) {
auto
tab
=
evalExpr
(
p
->
expr_
);
// throw ParseError("ForEach is yet unimplemented!", p);
// TODO: implement
}
\ No newline at end of file
}
src/codeGen/QuadrupleGenerator.h
View file @
69a63946
...
...
@@ -41,30 +41,27 @@ private:
return
alloc
(
info
);
}
VariablePtr
eval
Expr
(
Visitable
*
expr
)
{
VariablePtr
eval
Jump
(
Visitable
*
expr
,
shared_ptr
<
QLabel
>
tLabel
,
shared_ptr
<
QLabel
>
fLabel
)
{
if
(
!
expr
)
throw
runtime_error
(
"No expr to eval"
);
lineno
=
expr
->
lineno
;
lastVar
=
nullptr
;
swap
(
labelTrue
,
tLabel
);
swap
(
labelFalse
,
fLabel
);
try
{
expr
->
accept
(
this
);
}
catch
(
const
ParseError
&
err
)
{
throw
ParseError
(
err
,
expr
);
}
if
(
!
lastVar
)
throw
ParseError
(
"No variable found"
,
expr
);
swap
(
labelTrue
,
tLabel
);
swap
(
labelFalse
,
fLabel
);
auto
ret
=
lastVar
;
lastVar
=
nullptr
;
return
ret
;
}
VariablePtr
evalJump
(
Visitable
*
expr
,
shared_ptr
<
QLabel
>
tLabel
,
shared_ptr
<
QLabel
>
fLabel
)
{
if
(
!
expr
)
throw
runtime_error
(
"No expr to eval"
);
lineno
=
expr
->
lineno
;
swap
(
labelTrue
,
tLabel
);
swap
(
labelFalse
,
fLabel
);
auto
ret
=
evalExpr
(
expr
);
swap
(
labelTrue
,
tLabel
);
swap
(
labelFalse
,
fLabel
);
return
ret
;
inline
VariablePtr
evalExpr
(
Visitable
*
expr
)
{
return
evalJump
(
expr
,
nullptr
,
nullptr
);
}
VariablePtr
alloc
(
const
VarInfoPtr
&
info
)
{
...
...
src/codeGen/Variable.h
View file @
69a63946
...
...
@@ -10,7 +10,7 @@
class
Variable
:
std
::
enable_shared_from_this
<
Variable
>
{
public:
Variable
()
=
default
;
explicit
Variable
(
VarInfoPtr
i
nfo
)
:
info
(
std
::
move
(
info
)
)
{};
explicit
Variable
(
VarInfoPtr
i
)
:
info
(
std
::
move
(
i
)),
type
(
info
->
type
)
{};
explicit
Variable
(
int
constVal
)
:
type
(
new
Int
),
constExpr
(
true
),
val
(
constVal
)
{};
explicit
Variable
(
std
::
string
symbolName
)
:
name
(
std
::
move
(
symbolName
))
{};
VarInfoPtr
info
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment