Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
2
2022fall-Compiler_CMinus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晓奇
2022fall-Compiler_CMinus
Commits
9e13604b
Commit
9e13604b
authored
Oct 28, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
88 points, wow hahaha!
parent
b8f14d6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
Reports/3-ir-gen/report.md
Reports/3-ir-gen/report.md
+4
-0
src/cminusfc/cminusf_builder.cpp
src/cminusfc/cminusf_builder.cpp
+27
-11
No files found.
Reports/3-ir-gen/report.md
View file @
9e13604b
...
@@ -110,6 +110,10 @@ PB20111654 李晓奇
...
@@ -110,6 +110,10 @@ PB20111654 李晓奇
-
发现ifelse语句忘了无条件跳转了……
-
发现ifelse语句忘了无条件跳转了……
-
返现布尔表达式必须使用i1类型,类型要求真的太严格了!!
-
返现布尔表达式必须使用i1类型,类型要求真的太严格了!!
-
知道了为什么clang生成的中间代码,会把实参声明一遍再拷贝了。
在我看来方便编译器代码的生成,因为重新声明,push给scope的值是指针类型而不是纯值,这在后边访问Var中有用。
## 实验设计
## 实验设计
...
...
src/cminusfc/cminusf_builder.cpp
View file @
9e13604b
...
@@ -262,18 +262,21 @@ void CminusfBuilder::visit(ASTFunDeclaration &node) {
...
@@ -262,18 +262,21 @@ void CminusfBuilder::visit(ASTFunDeclaration &node) {
void
CminusfBuilder
::
visit
(
ASTParam
&
node
)
{
void
CminusfBuilder
::
visit
(
ASTParam
&
node
)
{
//!TODO: This function is empty now.
//!TODO: This function is empty now.
// If the parameter is int|float, copy and store them
// If the parameter is int|float, copy and store them
auto
param_value
=
cur_value
;
switch
(
node
.
type
)
{
switch
(
node
.
type
)
{
case
TYPE_INT
:
{
case
TYPE_INT
:
{
scope
.
push
(
node
.
id
,
cur_value
);
cur_value
=
builder
->
create_alloca
(
INT32_T
);
break
;
break
;
}
}
case
TYPE_FLOAT
:
{
case
TYPE_FLOAT
:
{
scope
.
push
(
node
.
id
,
cur_value
);
cur_value
=
builder
->
create_alloca
(
FLOAT_T
);
break
;
break
;
}
}
case
TYPE_VOID
:
case
TYPE_VOID
:
break
;
return
;
}
}
scope
.
push
(
node
.
id
,
cur_value
);
builder
->
create_store
(
param_value
,
cur_value
);
}
}
// Done?
// Done?
...
@@ -314,17 +317,30 @@ void CminusfBuilder::visit(ASTSelectionStmt &node) {
...
@@ -314,17 +317,30 @@ void CminusfBuilder::visit(ASTSelectionStmt &node) {
node
.
expression
->
accept
(
*
this
);
node
.
expression
->
accept
(
*
this
);
auto
cond
=
cur_value
;
auto
cond
=
cur_value
;
cast_to_i1
(
cond
);
cast_to_i1
(
cond
);
auto
TBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
auto
FBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
TBB
,
FBB
);
builder
->
set_insert_point
(
TBB
);
node
.
if_statement
->
accept
(
*
this
);
builder
->
create_br
(
FBB
);
builder
->
set_insert_point
(
FBB
);
auto
ifBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
auto
endBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
if
(
node
.
else_statement
)
{
if
(
node
.
else_statement
)
{
auto
elseBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
ifBB
,
elseBB
);
builder
->
set_insert_point
(
ifBB
);
node
.
if_statement
->
accept
(
*
this
);
builder
->
create_br
(
endBB
);
builder
->
set_insert_point
(
elseBB
);
node
.
else_statement
->
accept
(
*
this
);
node
.
else_statement
->
accept
(
*
this
);
builder
->
create_br
(
endBB
);
builder
->
set_insert_point
(
endBB
);
}
else
{
builder
->
create_cond_br
(
cond
,
ifBB
,
endBB
);
builder
->
set_insert_point
(
ifBB
);
node
.
if_statement
->
accept
(
*
this
);
builder
->
create_br
(
endBB
);
builder
->
set_insert_point
(
endBB
);
}
}
scope
.
exit
();
scope
.
exit
();
}
}
...
...
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