Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
C Compiler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gyuri
C Compiler
Commits
fb2decbe
Commit
fb2decbe
authored
Nov 21, 2020
by
gyuri
Browse files
Options
Downloads
Patches
Plain Diff
Add stub sizeof implementation
Will be useful when types are properly implemented
parent
79d245ad
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cg.c
+2
-1
2 additions, 1 deletion
src/cg.c
test/compiler_test.c
+7
-7
7 additions, 7 deletions
test/compiler_test.c
with
9 additions
and
8 deletions
src/cg.c
+
2
−
1
View file @
fb2decbe
...
@@ -245,7 +245,8 @@ static val cg_gen_expr(struct state *s, const struct ast_node *n) {
...
@@ -245,7 +245,8 @@ static val cg_gen_expr(struct state *s, const struct ast_node *n) {
// TODO;
// TODO;
break
;
break
;
case
AST_SIZEOF_EXPR
:
case
AST_SIZEOF_EXPR
:
// TODO
fprintf
(
s
->
f
,
"mov rax, %lld
\n
"
,
8LL
);
// TODO: types
return
val_push_new
(
s
,
"rax"
);
break
;
break
;
case
AST_ALIGNOF_EXPR
:
case
AST_ALIGNOF_EXPR
:
// TODO
// TODO
...
...
This diff is collapsed.
Click to expand it.
test/compiler_test.c
+
7
−
7
View file @
fb2decbe
...
@@ -15,32 +15,32 @@ int main() {
...
@@ -15,32 +15,32 @@ int main() {
if
(
c
==
'['
)
{
if
(
c
==
'['
)
{
// push onto stack
// push onto stack
*
(
stack
+
sp
)
=
pc
;
*
(
stack
+
sp
)
=
pc
;
sp
=
sp
+
8
;
sp
=
sp
+
sizeof
(
int
)
;
}
}
if
(
c
==
']'
)
{
if
(
c
==
']'
)
{
// pop from stack
// pop from stack
sp
=
sp
-
8
;
sp
=
sp
-
sizeof
(
int
)
;
int
jmp_pc
;
int
jmp_pc
;
jmp_pc
=
*
(
stack
+
sp
);
jmp_pc
=
*
(
stack
+
sp
);
*
(
jumps
+
pc
)
=
jmp_pc
;
*
(
jumps
+
pc
)
=
jmp_pc
;
*
(
jumps
+
jmp_pc
)
=
pc
;
*
(
jumps
+
jmp_pc
)
=
pc
;
}
}
pc
=
pc
+
8
;
pc
=
pc
+
sizeof
(
int
)
;
}
}
*
(
program
+
pc
+
8
)
=
0
;
*
(
program
+
pc
+
sizeof
(
int
)
)
=
0
;
int
i
=
0
;
int
i
=
0
;
while
(
i
<
65536
)
{
while
(
i
<
65536
)
{
*
(
stack
+
i
)
=
0
;
*
(
stack
+
i
)
=
0
;
i
=
i
+
8
;
i
=
i
+
sizeof
(
int
)
;
}
}
int
ptr
=
0
;
int
ptr
=
0
;
pc
=
0
;
pc
=
0
;
while
(
c
=
*
(
program
+
pc
))
{
while
(
c
=
*
(
program
+
pc
))
{
if
(
c
==
'>'
)
{
ptr
=
ptr
+
8
;
}
if
(
c
==
'>'
)
{
ptr
=
ptr
+
sizeof
(
int
)
;
}
if
(
c
==
'<'
)
{
ptr
=
ptr
-
8
;
}
if
(
c
==
'<'
)
{
ptr
=
ptr
-
sizeof
(
int
)
;
}
if
(
c
==
'+'
)
{
++*
(
stack
+
ptr
);
}
if
(
c
==
'+'
)
{
++*
(
stack
+
ptr
);
}
if
(
c
==
'-'
)
{
--*
(
stack
+
ptr
);
}
if
(
c
==
'-'
)
{
--*
(
stack
+
ptr
);
}
if
(
c
==
'.'
)
{
printf
(
"%c"
,
*
(
stack
+
ptr
));
}
if
(
c
==
'.'
)
{
printf
(
"%c"
,
*
(
stack
+
ptr
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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