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
698a4326
Commit
698a4326
authored
Oct 30, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
I got the result right!
parent
78e208f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
2 deletions
+25
-2
src/cminusfc/cminusf_builder.cpp
src/cminusfc/cminusf_builder.cpp
+25
-2
No files found.
src/cminusfc/cminusf_builder.cpp
View file @
698a4326
...
@@ -182,8 +182,29 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
...
@@ -182,8 +182,29 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
if
(
global
)
if
(
global
)
cur_value
=
cur_value
=
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FLOAT_T
,
false
,
FloatInitializer
);
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FLOAT_T
,
false
,
FloatInitializer
);
else
else
{
cur_value
=
builder
->
create_alloca
(
INT32_T
);
/* Beautiful is better than ugly.
* Explicit is better than implicit.
* Simple is better than complex.
* Complex is better than complicated.
* Flat is better than nested.
* Sparse is better than dense.
* Readability counts.
* Special cases aren't special enough to break the rules.
* Although practicality beats purity.
* Errors should never pass silently.
* Unless explicitly silenced.
* In the face of ambiguity, refuse the temptation to guess.
* There should be one-- and preferably only one --obvious way to do it.
* Although that way may not be obvious at first unless you're Dutch.
* Now is better than never.
* Although never is often better than *right* now.
* If the implementation is hard to explain, it's a bad idea.
* If the implementation is easy to explain, it may be a good idea.
* Namespaces are one honking great idea -- let's do more of those! */
// cur_value = builder->create_alloca(INT32_T);
cur_value
=
builder
->
create_alloca
(
FLOAT_T
);
}
break
;
break
;
default:
default:
error_exit
(
"Variable type(not array) is not int or float"
);
error_exit
(
"Variable type(not array) is not int or float"
);
...
@@ -296,6 +317,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) {
...
@@ -296,6 +317,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) {
* builder->create_br(bb);
* builder->create_br(bb);
* builder->set_insert_point(bb); */
* builder->set_insert_point(bb); */
scope
.
enter
();
scope
.
enter
();
for
(
auto
&
decl
:
node
.
local_declarations
)
{
for
(
auto
&
decl
:
node
.
local_declarations
)
{
decl
->
accept
(
*
this
);
decl
->
accept
(
*
this
);
}
}
...
@@ -305,6 +327,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) {
...
@@ -305,6 +327,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) {
if
(
builder
->
get_insert_block
()
->
get_terminator
()
!=
nullptr
)
if
(
builder
->
get_insert_block
()
->
get_terminator
()
!=
nullptr
)
break
;
break
;
}
}
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