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
c938ad6f
Commit
c938ad6f
authored
Jan 16, 2021
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lazy bool evaluation
parent
8256c661
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
16 deletions
+11
-16
Compiler.cpp
src/Compiler.cpp
+3
-0
BasicBlock.h
src/codeGen/BasicBlock.h
+1
-0
QuadrupleGenerator.cpp
src/codeGen/QuadrupleGenerator.cpp
+6
-9
QuadrupleGenerator.h
src/codeGen/QuadrupleGenerator.h
+1
-7
No files found.
src/Compiler.cpp
View file @
c938ad6f
...
...
@@ -406,6 +406,8 @@ void Compiler::generatePhiXCHG(const map<VariablePtr, VariablePtr> &varMap) {
void
Compiler
::
generateQJump
(
QJump
&
q
)
{
auto
thisBlock
=
q
.
block
;
auto
tgBlock
=
q
.
target
->
block
;
assert
(
thisBlock
&&
tgBlock
);
thisBlock
->
append
(
tgBlock
);
const
auto
&
map
=
tgBlock
->
getPhiMapping
(
thisBlock
);
generatePhiXCHG
(
map
);
append
(
"JMP"
,
getBlockLabelText
(
q
.
target
));
...
...
@@ -435,6 +437,7 @@ void Compiler::generateQJumpCond(QJumpCond &q) {
auto
thisBlock
=
q
.
block
;
auto
tgBlock
=
q
.
target
->
block
;
assert
(
thisBlock
&&
tgBlock
);
thisBlock
->
append
(
tgBlock
);
const
auto
&
map
=
tgBlock
->
getPhiMapping
(
thisBlock
);
for
(
const
auto
&
phiVars
:
map
)
{
if
((
phiVars
.
first
->
info
&&
phiVars
.
second
->
info
&&
phiVars
.
first
->
info
!=
phiVars
.
second
->
info
)
||
...
...
src/codeGen/BasicBlock.h
View file @
c938ad6f
...
...
@@ -24,6 +24,7 @@ public:
shared_ptr
<
QPhi
>
phi
;
void
append
(
const
BasicBlockPtr
&
after
)
{
assert
(
after
);
if
(
find
(
out
.
begin
(),
out
.
end
(),
after
)
!=
out
.
end
())
return
;
out
.
push_back
(
after
);
after
->
in
.
push_back
(
shared_from_this
());
after
->
phi
->
phi
.
emplace_back
();
...
...
src/codeGen/QuadrupleGenerator.cpp
View file @
c938ad6f
...
...
@@ -201,8 +201,9 @@ void QuadrupleGenerator::visitEAdd(EAdd *p) {
void
QuadrupleGenerator
::
visitERel
(
ERel
*
p
)
{
auto
l
=
evalExpr
(
p
->
expr_1
);
auto
r
=
evalExpr
(
p
->
expr_2
);
lastVar
=
alloc
(
l
);
p
->
relop_
->
accept
(
this
);
lastVar
=
alloc
(
l
);
addQuad
<
QAssign
>
(
lastVar
,
l
,
op
,
r
);
if
((
lastVar
->
constExpr
=
l
->
constExpr
&&
r
->
constExpr
))
{
if
(
op
==
Op
::
LT
)
lastVar
->
val
=
l
->
val
<
r
->
val
;
...
...
@@ -216,14 +217,13 @@ void QuadrupleGenerator::visitERel(ERel *p) {
lastVar
->
val
=
l
->
val
>=
r
->
val
;
else
if
(
op
==
Op
::
GT
)
lastVar
->
val
=
l
->
val
>
r
->
val
;
addQuad
<
QAssign
>
(
lastVar
,
l
,
op
,
r
);
}
else
{
addLastVarCondJump
(
l
,
op
,
r
);
}
}
void
QuadrupleGenerator
::
visitEAnd
(
EAnd
*
p
)
{
auto
labelAfter
=
make_shared
<
QLabel
>
(
"and_e
lse
"
);
auto
labelAfter
=
make_shared
<
QLabel
>
(
"and_e
nd
"
);
auto
l
=
evalJump
(
p
->
expr_1
,
nullptr
,
labelFalse
);
if
(
!
l
)
return
;
if
(
l
->
constExpr
)
{
...
...
@@ -266,7 +266,7 @@ void QuadrupleGenerator::visitEAnd(EAnd *p) {
}
void
QuadrupleGenerator
::
visitEOr
(
EOr
*
p
)
{
auto
labelAfter
=
make_shared
<
QLabel
>
(
"or_e
lse
"
);
auto
labelAfter
=
make_shared
<
QLabel
>
(
"or_e
nd
"
);
auto
l
=
evalJump
(
p
->
expr_1
,
labelTrue
,
nullptr
);
if
(
!
l
)
return
;
if
(
l
->
constExpr
)
{
...
...
@@ -290,19 +290,16 @@ void QuadrupleGenerator::visitEOr(EOr *p) {
lastVar
=
r
->
val
?
r
:
l
;
}
}
else
{
auto
rightValBlock
=
block
;
flushBasicBlock
();
auto
rightValBlock
=
flushBasicBlock
();
addQuad
(
labelAfter
);
rightValBlock
->
append
(
block
);
leftValBlock
->
append
(
block
);
lastVar
=
alloc
();
if
(
!
labelTrue
||
!
labelFalse
)
{
lastVar
=
alloc
();
block
->
addPhi
(
rightValBlock
,
lastVar
,
r
);
block
->
addPhi
(
leftValBlock
,
lastVar
,
l
);
}
else
{
lastVar
=
nullptr
;
}
}
}
...
...
src/codeGen/QuadrupleGenerator.h
View file @
c938ad6f
...
...
@@ -108,17 +108,11 @@ private:
if
(
labelTrue
&&
labelFalse
)
{
addQuad
<
QJumpCond
>
(
labelTrue
,
l
,
op
,
r
);
addQuad
<
QJump
>
(
labelFalse
);
return
;
}
else
if
(
labelTrue
)
{
addQuad
<
QJumpCond
>
(
labelTrue
,
l
,
op
,
r
);
lastVar
=
alloc
(
0
);
}
else
if
(
labelFalse
)
{
addQuad
<
QJumpCond
>
(
labelFalse
,
l
,
op
.
neg
(),
r
);
lastVar
=
alloc
(
1
);
}
else
if
(
lastVar
==
l
||
lastVar
==
r
)
return
;
// return needed because otherwise we get multiple lastVar assignments
// assign needed because otherwise some vars never have assignments
addQuad
<
QAssign
>
(
lastVar
,
l
,
op
,
r
);
}
}
QuadruplePtr
lastQuad
;
...
...
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