Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chibicc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
邓家琪
Chibicc
Commits
fade39d8
Commit
fade39d8
authored
4 years ago
by
Rui Ueyama
Browse files
Options
Downloads
Patches
Plain Diff
Handle flonum for if, while, do, !, ?:, || and &&
parent
f3667e27
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
codegen.c
+20
-9
20 additions, 9 deletions
codegen.c
test/control.c
+15
-0
15 additions, 0 deletions
test/control.c
test/float.c
+8
-0
8 additions, 0 deletions
test/float.c
with
43 additions
and
9 deletions
codegen.c
+
20
−
9
View file @
fade39d8
...
...
@@ -149,6 +149,17 @@ static void store(Type *ty) {
}
static
void
cmp_zero
(
Type
*
ty
)
{
switch
(
ty
->
kind
)
{
case
TY_FLOAT
:
println
(
" xorps %%xmm1, %%xmm1"
);
println
(
" ucomiss %%xmm1, %%xmm0"
);
return
;
case
TY_DOUBLE
:
println
(
" xorpd %%xmm1, %%xmm1"
);
println
(
" ucomisd %%xmm1, %%xmm0"
);
return
;
}
if
(
is_integer
(
ty
)
&&
ty
->
size
<=
4
)
println
(
" cmp $0, %%eax"
);
else
...
...
@@ -316,7 +327,7 @@ static void gen_expr(Node *node) {
case
ND_COND
:
{
int
c
=
count
();
gen_expr
(
node
->
cond
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
cond
->
ty
);
println
(
" je .L.else.%d"
,
c
);
gen_expr
(
node
->
then
);
println
(
" jmp .L.end.%d"
,
c
);
...
...
@@ -327,7 +338,7 @@ static void gen_expr(Node *node) {
}
case
ND_NOT
:
gen_expr
(
node
->
lhs
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
lhs
->
ty
);
println
(
" sete %%al"
);
println
(
" movzx %%al, %%rax"
);
return
;
...
...
@@ -338,10 +349,10 @@ static void gen_expr(Node *node) {
case
ND_LOGAND
:
{
int
c
=
count
();
gen_expr
(
node
->
lhs
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
lhs
->
ty
);
println
(
" je .L.false.%d"
,
c
);
gen_expr
(
node
->
rhs
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
rhs
->
ty
);
println
(
" je .L.false.%d"
,
c
);
println
(
" mov $1, %%rax"
);
println
(
" jmp .L.end.%d"
,
c
);
...
...
@@ -353,10 +364,10 @@ static void gen_expr(Node *node) {
case
ND_LOGOR
:
{
int
c
=
count
();
gen_expr
(
node
->
lhs
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
lhs
->
ty
);
println
(
" jne .L.true.%d"
,
c
);
gen_expr
(
node
->
rhs
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
rhs
->
ty
);
println
(
" jne .L.true.%d"
,
c
);
println
(
" mov $0, %%rax"
);
println
(
" jmp .L.end.%d"
,
c
);
...
...
@@ -558,7 +569,7 @@ static void gen_stmt(Node *node) {
case
ND_IF
:
{
int
c
=
count
();
gen_expr
(
node
->
cond
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
cond
->
ty
);
println
(
" je .L.else.%d"
,
c
);
gen_stmt
(
node
->
then
);
println
(
" jmp .L.end.%d"
,
c
);
...
...
@@ -575,7 +586,7 @@ static void gen_stmt(Node *node) {
println
(
".L.begin.%d:"
,
c
);
if
(
node
->
cond
)
{
gen_expr
(
node
->
cond
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
cond
->
ty
);
println
(
" je %s"
,
node
->
brk_label
);
}
gen_stmt
(
node
->
then
);
...
...
@@ -592,7 +603,7 @@ static void gen_stmt(Node *node) {
gen_stmt
(
node
->
then
);
println
(
"%s:"
,
node
->
cont_label
);
gen_expr
(
node
->
cond
);
println
(
" cmp $0, %%rax"
);
cmp_zero
(
node
->
cond
->
ty
);
println
(
" jne .L.begin.%d"
,
c
);
println
(
"%s:"
,
node
->
brk_label
);
return
;
...
...
This diff is collapsed.
Click to expand it.
test/control.c
+
15
−
0
View file @
fade39d8
...
...
@@ -68,6 +68,21 @@ int main() {
ASSERT
(
7
,
({
int
i
=
0
;
int
j
=
0
;
do
{
j
++
;
}
while
(
i
++
<
6
);
j
;
}));
ASSERT
(
4
,
({
int
i
=
0
;
int
j
=
0
;
int
k
=
0
;
do
{
if
(
++
j
>
3
)
break
;
continue
;
k
++
;
}
while
(
1
);
j
;
}));
ASSERT
(
0
,
0
.
0
&&
0
.
0
);
ASSERT
(
0
,
0
.
0
&&
0
.
1
);
ASSERT
(
0
,
0
.
3
&&
0
.
0
);
ASSERT
(
1
,
0
.
3
&&
0
.
5
);
ASSERT
(
0
,
0
.
0
||
0
.
0
);
ASSERT
(
1
,
0
.
0
||
0
.
1
);
ASSERT
(
1
,
0
.
3
||
0
.
0
);
ASSERT
(
1
,
0
.
3
||
0
.
5
);
ASSERT
(
5
,
({
int
x
;
if
(
0
.
0
)
x
=
3
;
else
x
=
5
;
x
;
}));
ASSERT
(
3
,
({
int
x
;
if
(
0
.
1
)
x
=
3
;
else
x
=
5
;
x
;
}));
ASSERT
(
5
,
({
int
x
=
5
;
if
(
0
.
0
)
x
=
3
;
x
;
}));
ASSERT
(
3
,
({
int
x
=
5
;
if
(
0
.
1
)
x
=
3
;
x
;
}));
ASSERT
(
10
,
({
double
i
=
10
.
0
;
int
j
=
0
;
for
(;
i
;
i
--
,
j
++
);
j
;
}));
ASSERT
(
10
,
({
double
i
=
10
.
0
;
int
j
=
0
;
do
j
++
;
while
(
--
i
);
j
;
}));
printf
(
"OK
\n
"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
test/float.c
+
8
−
0
View file @
fade39d8
...
...
@@ -80,6 +80,14 @@ int main() {
ASSERT
(
0
,
0
.
0
/
0
.
0
>
0
);
ASSERT
(
0
,
0
.
0
/
0
.
0
>=
0
);
ASSERT
(
0
,
!
3
.);
ASSERT
(
1
,
!
0
.);
ASSERT
(
0
,
!
3
.
f
);
ASSERT
(
1
,
!
0
.
f
);
ASSERT
(
5
,
0
.
0
?
3
:
5
);
ASSERT
(
3
,
1
.
2
?
3
:
5
);
printf
(
"OK
\n
"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment