Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
9c08cd98
wa
项目概览
wa-lang
/
wa
11 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9c08cd98
编写于
7月 25, 2022
作者:
3
3dgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
区分Scope的“局部变量”和“临时变量”,二者区别为局部变量出现于Scope头部
上级
c859e7f9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
17 deletion
+26
-17
internal/backends/compiler_c/cir/scope.go
internal/backends/compiler_c/cir/scope.go
+17
-8
internal/backends/compiler_c/compile_func.go
internal/backends/compiler_c/compile_func.go
+6
-6
internal/backends/compiler_c/compile_global.go
internal/backends/compiler_c/compile_global.go
+3
-3
未找到文件。
internal/backends/compiler_c/cir/scope.go
浏览文件 @
9c08cd98
...
...
@@ -17,14 +17,16 @@ type Scope struct {
//在该域中定义的结构体
Structs
[]
*
StructDecl
//在该域中定义的变量
Vars
[]
*
VarDecl
locals
[]
*
VarDecl
//在该域中定义的函数
Funcs
[]
*
FuncDecl
//域中包含的语句
Stmts
[]
Stmt
//在该域中定义的变量(含局部变量和临时变量,局部变量位于域头部结构体之后,临时变量可出现于域内任意位置)
Vars
[]
*
VarDecl
}
//实现Stmt接口
...
...
@@ -51,13 +53,20 @@ func (s *Scope) AddTupleDecl(t ctypes.Tuple) *StructDecl {
return
&
decl
}
func
(
s
*
Scope
)
AddVarDecl
(
name
string
,
t
ctypes
.
Type
)
*
VarDeclStmt
{
func
(
s
*
Scope
)
Add
Temp
VarDecl
(
name
string
,
t
ctypes
.
Type
)
*
VarDeclStmt
{
decl
:=
NewVarDeclStmt
(
name
,
t
)
s
.
Stmts
=
append
(
s
.
Stmts
,
decl
)
s
.
Vars
=
append
(
s
.
Vars
,
&
decl
.
VarDecl
)
return
decl
}
func
(
s
*
Scope
)
AddLocalVarDecl
(
name
string
,
t
ctypes
.
Type
)
*
VarDecl
{
decl
:=
NewVarDecl
(
name
,
t
)
s
.
locals
=
append
(
s
.
locals
,
decl
)
s
.
Vars
=
append
(
s
.
Vars
,
decl
)
return
decl
}
func
(
s
*
Scope
)
AddFuncDecl
(
name
string
,
result
ctypes
.
Type
,
params
[]
VarDecl
)
*
FuncDecl
{
decl
:=
NewFuncDecl
(
name
,
result
,
params
)
s
.
Funcs
=
append
(
s
.
Funcs
,
decl
)
...
...
@@ -156,11 +165,11 @@ func (s *Scope) CIRString() string {
buf
.
WriteString
(
";
\n
"
)
}
//for _, v := range s.Var
s {
//
buf.WriteString(genIndent(indent))
//
buf.WriteString(v.CIRString())
//
buf.WriteString(";\n")
//
}
for
_
,
v
:=
range
s
.
local
s
{
buf
.
WriteString
(
genIndent
(
indent
))
buf
.
WriteString
(
v
.
CIRString
())
buf
.
WriteString
(
";
\n
"
)
}
for
_
,
v
:=
range
s
.
Funcs
{
b
:=
v
.
Body
...
...
internal/backends/compiler_c/compile_func.go
浏览文件 @
9c08cd98
...
...
@@ -147,7 +147,7 @@ func (g *functionGenerator) genFunction(f *ssa.Function) {
g
.
compiler
.
curScope
=
fn
.
Body
defer
func
()
{
g
.
compiler
.
curScope
=
fn
.
Body
.
Parent
}()
g
.
var_cur_block
=
&
g
.
compiler
.
curScope
.
AddVarDecl
(
"$T_Block_Current"
,
ctypes
.
Uint32
)
.
Var
g
.
var_cur_block
=
&
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
"$T_Block_Current"
,
ctypes
.
Uint32
)
.
Var
for
_
,
b
:=
range
f
.
Blocks
{
g
.
genBlock
(
b
)
...
...
@@ -200,7 +200,7 @@ func (g *functionGenerator) createInstruction(inst ssa.Instruction) {
if
v
.
Type
()
.
Equal
(
ctypes
.
Void
)
{
g
.
compiler
.
curScope
.
AddExprStmt
(
v
)
}
else
{
r
:=
g
.
compiler
.
curScope
.
AddVarDecl
(
g
.
genRegister
(),
v
.
Type
())
r
:=
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
g
.
genRegister
(),
v
.
Type
())
r
.
AssociatedSSAObj
=
inst
r
.
InitVal
=
v
}
...
...
@@ -338,14 +338,14 @@ func (g *functionGenerator) genAlloc(inst *ssa.Alloc) {
if
inst
.
Heap
{
ref_type
:=
ctypes
.
NewRefType
(
cir
.
ToCType
(
inst
.
Type
()
.
(
*
types
.
Pointer
)
.
Elem
()))
v
:=
cir
.
NewRawExpr
(
ref_type
.
CIRString
()
+
"::New()"
,
ref_type
)
r
:=
g
.
compiler
.
curScope
.
AddVarDecl
(
g
.
genRegister
(),
v
.
Type
())
r
:=
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
g
.
genRegister
(),
v
.
Type
())
r
.
AssociatedSSAObj
=
inst
r
.
InitVal
=
v
return
}
c_type
:=
cir
.
ToCType
(
inst
.
Type
()
.
(
*
types
.
Pointer
)
.
Elem
())
r
:=
g
.
compiler
.
curScope
.
AddVarDecl
(
g
.
genRegister
(),
c_type
)
r
:=
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
g
.
genRegister
(),
c_type
)
switch
c_type
:=
c_type
.
(
type
)
{
case
*
ctypes
.
Array
:
r
.
AssociatedSSAObj
=
inst
...
...
@@ -354,7 +354,7 @@ func (g *functionGenerator) genAlloc(inst *ssa.Alloc) {
r
.
AssociatedSSAObj
=
inst
default
:
rt
:=
g
.
compiler
.
curScope
.
AddVarDecl
(
g
.
genRegister
(),
ctypes
.
NewPointerType
(
c_type
))
rt
:=
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
g
.
genRegister
(),
ctypes
.
NewPointerType
(
c_type
))
rt
.
InitVal
=
cir
.
NewGetaddrExpr
(
&
r
.
Var
)
rt
.
AssociatedSSAObj
=
inst
}
...
...
@@ -509,7 +509,7 @@ func (g *functionGenerator) genPrint(v cir.Expr) cir.Expr {
}
func
(
g
*
functionGenerator
)
genPhi
(
inst
*
ssa
.
Phi
)
{
r
:=
&
g
.
compiler
.
curScope
.
AddVarDecl
(
g
.
genRegister
(),
cir
.
ToCType
(
inst
.
Type
()))
.
Var
r
:=
&
g
.
compiler
.
curScope
.
Add
Temp
VarDecl
(
g
.
genRegister
(),
cir
.
ToCType
(
inst
.
Type
()))
.
Var
r
.
AssociatedSSAObj
=
inst
var
edges
[]
cir
.
PhiEdge
...
...
internal/backends/compiler_c/compile_global.go
浏览文件 @
9c08cd98
...
...
@@ -14,13 +14,13 @@ func (p *CompilerC) compileGlobal(g *ssa.Global) {
switch
c_type
.
(
type
)
{
case
*
ctypes
.
Array
:
p
.
curScope
.
AddVarDecl
(
g
.
Name
(),
c_type
)
.
Var
.
AssociatedSSAObj
=
g
p
.
curScope
.
Add
Local
VarDecl
(
g
.
Name
(),
c_type
)
.
Var
.
AssociatedSSAObj
=
g
default
:
c_name
:=
"$Global_"
+
g
.
Name
()
c_var
:=
&
p
.
curScope
.
AddVarDecl
(
c_name
,
c_type
)
.
Var
c_var
:=
&
p
.
curScope
.
Add
Local
VarDecl
(
c_name
,
c_type
)
.
Var
w_var_decl
:=
p
.
curScope
.
AddVarDecl
(
g
.
Name
(),
ctypes
.
NewPointerType
(
c_type
))
w_var_decl
:=
p
.
curScope
.
Add
Local
VarDecl
(
g
.
Name
(),
ctypes
.
NewPointerType
(
c_type
))
w_var_decl
.
InitVal
=
cir
.
NewGetaddrExpr
(
c_var
)
w_var_decl
.
Var
.
AssociatedSSAObj
=
g
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录