Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2c514f33
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c514f33
编写于
9月 23, 2010
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More fleshing-out on rustc.me.trans. Emitting modules and fns corresponding to parsed input now.
上级
04a55df5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
16 deletion
+64
-16
src/comp/driver/session.rs
src/comp/driver/session.rs
+10
-3
src/comp/fe/parser.rs
src/comp/fe/parser.rs
+16
-0
src/comp/me/trans.rs
src/comp/me/trans.rs
+38
-13
未找到文件。
src/comp/driver/session.rs
浏览文件 @
2c514f33
import
util
.common.span
;
import
std
._uint
;
io
obj
session
()
{
io
fn
span_err
(
span
sp
,
str
msg
)
{
obj
session
()
{
fn
span_err
(
span
sp
,
str
msg
)
{
let
str
s
=
sp
.filename
;
s
+=
':'
as
u8
;
// We really need #fmt soon!
...
...
@@ -19,12 +19,19 @@
fail
;
}
io
fn
err
(
str
msg
)
{
fn
err
(
str
msg
)
{
let
str
s
=
"error: "
;
s
+=
msg
;
log
s
;
fail
;
}
fn
unimpl
(
str
msg
)
{
let
str
s
=
"error: unimplemented "
;
s
+=
msg
;
log
s
;
fail
;
}
}
...
...
src/comp/fe/parser.rs
浏览文件 @
2c514f33
...
...
@@ -218,11 +218,27 @@ fn get_span() -> common.span {
ret
tup
(
id
,
ast
.item_fn
(
@
f
));
}
state
fn
parse_mod
(
parser
p
)
->
tup
(
ast
.ident
,
ast
.item
)
{
expect
(
p
,
token
.MOD
);
auto
id
=
parse_ident
(
p
);
expect
(
p
,
token
.LBRACE
);
let
ast
._mod
m
=
new_str_hash
[
ast
.item
]();
while
(
p
.peek
()
!=
token
.RBRACE
)
{
auto
i
=
parse_item
(
p
);
m
.insert
(
i
._0
,
i
._1
);
}
expect
(
p
,
token
.RBRACE
);
ret
tup
(
id
,
ast
.item_mod
(
@
m
));
}
state
fn
parse_item
(
parser
p
)
->
tup
(
ast
.ident
,
ast
.item
)
{
alt
(
p
.peek
())
{
case
(
token
.FN
)
{
ret
parse_fn
(
p
);
}
case
(
token
.MOD
)
{
ret
parse_mod
(
p
);
}
}
p
.err
(
"expectied item"
);
fail
;
...
...
src/comp/me/trans.rs
浏览文件 @
2c514f33
...
...
@@ -17,6 +17,10 @@
import
lib
.llvm.False
;
import
lib
.llvm.True
;
type
trans_ctxt
=
rec
(
session
.session
sess
,
ModuleRef
llmod
,
str
path
);
fn
T_nil
()
->
TypeRef
{
ret
llvm
.LLVMVoidType
();
}
...
...
@@ -32,35 +36,54 @@ fn T_fn(vec[TypeRef] inputs, TypeRef output) -> TypeRef {
False
());
}
fn
trans_fn
(
ModuleRef
llmod
,
str
name
,
&
ast
._fn
f
)
{
let
vec
[
TypeRef
]
args
=
vec
();
let
TypeRef
llty
=
T_fn
(
args
,
T_nil
());
let
ValueRef
llfn
=
llvm
.LLVMAddFunction
(
llmod
,
_
str
.buf
(
name
),
llty
);
fn
trans_log
(
&
trans_ctxt
cx
,
builder
b
,
&
ast
.atom
a
)
{
}
fn
trans_block
(
ast
.block
b
,
ValueRef
llfn
)
{
fn
trans_stmt
(
&
trans_ctxt
cx
,
builder
b
,
&
ast
.stmt
s
)
{
alt
(
s
)
{
case
(
ast
.stmt_log
(
?
a
))
{
trans_log
(
cx
,
b
,
*
a
);
}
case
(
_
)
{
cx
.sess
.unimpl
(
"stmt variant"
);
}
}
}
fn
trans_block
(
&
trans_ctxt
cx
,
ValueRef
llfn
,
&
ast
.block
b
)
{
let
BasicBlockRef
llbb
=
llvm
.LLVMAppendBasicBlock
(
llfn
,
0
as
sbuf
);
llvm
.LLVMAppendBasicBlock
(
llfn
,
_
str
.buf
(
""
)
);
let
BuilderRef
llbuild
=
llvm
.LLVMCreateBuilder
();
llvm
.LLVMPositionBuilderAtEnd
(
llbuild
,
llbb
);
auto
b
=
builder
(
llbuild
);
auto
bld
=
builder
(
llbuild
);
for
(
@
ast
.stmt
s
in
b
)
{
trans_stmt
(
cx
,
bld
,
*
s
);
}
}
fn
trans_fn
(
&
trans_ctxt
cx
,
&
ast
._fn
f
)
{
let
vec
[
TypeRef
]
args
=
vec
();
let
TypeRef
llty
=
T_fn
(
args
,
T_nil
());
let
ValueRef
llfn
=
llvm
.LLVMAddFunction
(
cx
.llmod
,
_
str
.buf
(
cx
.path
),
llty
);
trans_block
(
cx
,
llfn
,
f
.body
);
}
fn
trans_mod_item
(
ModuleRef
llmod
,
str
name
,
&
ast
.item
item
)
{
fn
trans_item
(
&
trans_ctxt
cx
,
&
str
name
,
&
ast
.item
item
)
{
auto
sub_cx
=
rec
(
path
=
cx
.path
+
"."
+
name
with
cx
);
alt
(
item
)
{
case
(
ast
.item_fn
(
?
f
))
{
trans_fn
(
llmod
,
name
,
*
f
);
trans_fn
(
sub_cx
,
*
f
);
}
case
(
ast
.item_mod
(
?
m
))
{
trans_mod
(
llmod
,
name
,
*
m
);
trans_mod
(
sub_cx
,
*
m
);
}
}
}
fn
trans_mod
(
ModuleRef
llmod
,
str
name
,
&
ast
._mod
m
)
{
fn
trans_mod
(
&
trans_ctxt
cx
,
&
ast
._mod
m
)
{
for
each
(
tup
(
str
,
ast
.item
)
pair
in
m
.items
())
{
trans_
mod_item
(
llmod
,
name
+
"."
+
pair
._0
,
pair
._1
);
trans_
item
(
cx
,
pair
._0
,
pair
._1
);
}
}
...
...
@@ -69,6 +92,8 @@ fn trans_crate(session.session sess, ast.crate crate) {
llvm
.LLVMModuleCreateWithNameInContext
(
_
str
.buf
(
"rust_out"
),
llvm
.LLVMGetGlobalContext
());
auto
cx
=
rec
(
sess
=
sess
,
llmod
=
llmod
,
path
=
""
);
trans_mod
(
cx
,
crate
.module
);
llvm
.LLVMWriteBitcodeToFile
(
llmod
,
_
str
.buf
(
"rust_out.bc"
));
llvm
.LLVMDisposeModule
(
llmod
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录