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
c6b30568
Commit
c6b30568
authored
4 years ago
by
Rui Ueyama
Browse files
Options
Downloads
Patches
Plain Diff
Allow to define a function that takes/returns flonums
parent
8ec1ebf1
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
codegen.c
+19
-3
19 additions, 3 deletions
codegen.c
test/function.c
+11
-0
11 additions, 0 deletions
test/function.c
with
30 additions
and
3 deletions
codegen.c
+
19
−
3
View file @
c6b30568
...
...
@@ -735,6 +735,18 @@ static void emit_data(Obj *prog) {
}
}
static
void
store_fp
(
int
r
,
int
offset
,
int
sz
)
{
switch
(
sz
)
{
case
4
:
println
(
" movss %%xmm%d, %d(%%rbp)"
,
r
,
offset
);
return
;
case
8
:
println
(
" movsd %%xmm%d, %d(%%rbp)"
,
r
,
offset
);
return
;
}
unreachable
();
}
static
void
store_gp
(
int
r
,
int
offset
,
int
sz
)
{
switch
(
sz
)
{
case
1
:
...
...
@@ -803,9 +815,13 @@ static void emit_text(Obj *prog) {
}
// Save passed-by-register arguments to the stack
int
i
=
0
;
for
(
Obj
*
var
=
fn
->
params
;
var
;
var
=
var
->
next
)
store_gp
(
i
++
,
var
->
offset
,
var
->
ty
->
size
);
int
gp
=
0
,
fp
=
0
;
for
(
Obj
*
var
=
fn
->
params
;
var
;
var
=
var
->
next
)
{
if
(
is_flonum
(
var
->
ty
))
store_fp
(
fp
++
,
var
->
offset
,
var
->
ty
->
size
);
else
store_gp
(
gp
++
,
var
->
offset
,
var
->
ty
->
size
);
}
// Emit code
gen_stmt
(
fn
->
body
);
...
...
This diff is collapsed.
Click to expand it.
test/function.c
+
11
−
0
View file @
c6b30568
...
...
@@ -100,6 +100,14 @@ char *fmt(char *buf, char *fmt, ...) {
double
add_double
(
double
x
,
double
y
);
float
add_float
(
float
x
,
float
y
);
float
add_float3
(
float
x
,
float
y
,
float
z
)
{
return
x
+
y
+
z
;
}
double
add_double3
(
double
x
,
double
y
,
double
z
)
{
return
x
+
y
+
z
;
}
int
main
()
{
ASSERT
(
3
,
ret3
());
ASSERT
(
8
,
add2
(
3
,
5
));
...
...
@@ -163,6 +171,9 @@ int main() {
ASSERT
(
6
,
add_float
(
2
.
3
,
3
.
8
));
ASSERT
(
6
,
add_double
(
2
.
3
,
3
.
8
));
ASSERT
(
7
,
add_float3
(
2
.
5
,
2
.
5
,
2
.
5
));
ASSERT
(
7
,
add_double3
(
2
.
5
,
2
.
5
,
2
.
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