Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5aa734d6
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,发现更多精彩内容 >>
提交
5aa734d6
编写于
3月 12, 2013
作者:
L
Luqman Aden
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parse operands properly and add a way to indicate volatile asm.
上级
885d0d3d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
145 addition
and
18 deletion
+145
-18
src/librustc/middle/trans/build.rs
src/librustc/middle/trans/build.rs
+2
-2
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/expr.rs
+6
-2
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+2
-1
src/libsyntax/ext/asm.rs
src/libsyntax/ext/asm.rs
+129
-11
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+6
-2
未找到文件。
src/librustc/middle/trans/build.rs
浏览文件 @
5aa734d6
...
...
@@ -873,12 +873,12 @@ pub fn add_comment(bcx: block, text: &str) {
}
pub
fn
InlineAsmCall
(
cx
:
block
,
asm
:
*
c_char
,
cons
:
*
c_char
,
dia
:
AsmDialect
)
->
ValueRef
{
volatile
:
lib
::
llvm
::
Bool
,
dia
:
AsmDialect
)
->
ValueRef
{
unsafe
{
count_insn
(
cx
,
"inlineasm"
);
let
llfty
=
T_fn
(
~
[],
T_void
());
let
v
=
llvm
::
LLVMInlineAsm
(
llfty
,
asm
,
cons
,
Fals
e
,
False
,
dia
);
let
v
=
llvm
::
LLVMInlineAsm
(
llfty
,
asm
,
cons
,
volatil
e
,
False
,
dia
);
Call
(
cx
,
v
,
~
[])
}
...
...
src/librustc/middle/trans/expr.rs
浏览文件 @
5aa734d6
...
...
@@ -691,10 +691,14 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast
::
expr_assign_op
(
op
,
dst
,
src
)
=>
{
return
trans_assign_op
(
bcx
,
expr
,
op
,
dst
,
src
);
}
ast
::
expr_inline_asm
(
asm
,
cons
)
=>
{
ast
::
expr_inline_asm
(
asm
,
cons
,
volatile
)
=>
{
// XXX: cons doesn't actual contain ALL the stuff we should
// be passing since the constraints for in/outputs aren't included
do
str
::
as_c_str
(
*
asm
)
|
a
|
{
do
str
::
as_c_str
(
*
cons
)
|
c
|
{
InlineAsmCall
(
bcx
,
a
,
c
,
lib
::
llvm
::
AD_ATT
);
let
v
=
if
volatile
{
lib
::
llvm
::
True
}
else
{
lib
::
llvm
::
False
};
InlineAsmCall
(
bcx
,
a
,
c
,
v
,
lib
::
llvm
::
AD_ATT
);
}
}
return
bcx
;
...
...
src/libsyntax/ast.rs
浏览文件 @
5aa734d6
...
...
@@ -601,7 +601,8 @@ pub enum expr_ {
expr_ret
(
Option
<@
expr
>
),
expr_log
(
log_level
,
@
expr
,
@
expr
),
expr_inline_asm
(
@~
str
/* asm */
,
@~
str
/* constraints */
),
/* asm, clobbers + constraints, volatile */
expr_inline_asm
(
@~
str
,
@~
str
,
bool
),
expr_mac
(
mac
),
...
...
src/libsyntax/ext/asm.rs
浏览文件 @
5aa734d6
...
...
@@ -20,29 +20,147 @@
use
codemap
::
span
;
use
ext
::
base
;
use
ext
::
base
::
*
;
use
parse
;
use
parse
::
token
;
enum
State
{
Asm
,
Outputs
,
Inputs
,
Clobbers
,
Options
}
fn
next_state
(
s
:
State
)
->
Option
<
State
>
{
match
s
{
Asm
=>
Some
(
Outputs
),
Outputs
=>
Some
(
Inputs
),
Inputs
=>
Some
(
Clobbers
),
Clobbers
=>
Some
(
Options
),
Options
=>
None
}
}
pub
fn
expand_asm
(
cx
:
ext_ctxt
,
sp
:
span
,
tts
:
&
[
ast
::
token_tree
])
->
base
::
MacResult
{
let
args
=
get_exprs_from_tts
(
cx
,
tts
);
if
args
.len
()
==
0
{
cx
.span_fatal
(
sp
,
"ast! takes at least 1 argument."
);
let
p
=
parse
::
new_parser_from_tts
(
cx
.parse_sess
(),
cx
.cfg
(),
vec
::
from_slice
(
tts
));
let
mut
asm
=
~
""
;
let
mut
outputs
=
~
[];
let
mut
inputs
=
~
[];
let
mut
cons
=
~
""
;
let
mut
volatile
=
false
;
let
mut
state
=
Asm
;
loop
outer
:
{
match
state
{
Asm
=>
{
asm
=
expr_to_str
(
cx
,
p
.parse_expr
(),
~
"inline assembly must be a string literal."
);
}
Outputs
=>
{
while
*
p
.token
!=
token
::
EOF
&&
*
p
.token
!=
token
::
COLON
&&
*
p
.token
!=
token
::
MOD_SEP
{
if
outputs
.len
()
!=
0
{
p
.eat
(
&
token
::
COMMA
);
}
let
constraint
=
p
.parse_str
();
p
.expect
(
&
token
::
LPAREN
);
let
out
=
p
.parse_expr
();
p
.expect
(
&
token
::
RPAREN
);
outputs
.push
((
constraint
,
out
));
}
}
Inputs
=>
{
while
*
p
.token
!=
token
::
EOF
&&
*
p
.token
!=
token
::
COLON
&&
*
p
.token
!=
token
::
MOD_SEP
{
if
inputs
.len
()
!=
0
{
p
.eat
(
&
token
::
COMMA
);
}
let
constraint
=
p
.parse_str
();
p
.expect
(
&
token
::
LPAREN
);
let
in
=
p
.parse_expr
();
p
.expect
(
&
token
::
RPAREN
);
inputs
.push
((
constraint
,
in
));
}
}
Clobbers
=>
{
let
mut
clobs
=
~
[];
while
*
p
.token
!=
token
::
EOF
&&
*
p
.token
!=
token
::
COLON
&&
*
p
.token
!=
token
::
MOD_SEP
{
if
clobs
.len
()
!=
0
{
p
.eat
(
&
token
::
COMMA
);
}
let
clob
=
~
"~{"
+
*
p
.parse_str
()
+
~
"}"
;
clobs
.push
(
clob
);
}
cons
=
str
::
connect
(
clobs
,
","
);
}
Options
=>
{
let
option
=
*
p
.parse_str
();
if
option
==
~
"volatile"
{
volatile
=
true
;
}
if
*
p
.token
==
token
::
COMMA
{
p
.eat
(
&
token
::
COMMA
);
}
}
}
while
*
p
.token
==
token
::
COLON
||
*
p
.token
==
token
::
MOD_SEP
||
*
p
.token
==
token
::
EOF
{
state
=
if
*
p
.token
==
token
::
COLON
{
p
.bump
();
match
next_state
(
state
)
{
Some
(
x
)
=>
x
,
None
=>
break
outer
}
}
else
if
*
p
.token
==
token
::
MOD_SEP
{
p
.bump
();
let
s
=
match
next_state
(
state
)
{
Some
(
x
)
=>
x
,
None
=>
break
outer
};
match
next_state
(
s
)
{
Some
(
x
)
=>
x
,
None
=>
break
outer
}
}
else
if
*
p
.token
==
token
::
EOF
{
break
outer
;
}
else
{
state
};
}
}
let
asm
=
expr_to_str
(
cx
,
args
[
0
],
~
"inline assembly must be a string literal."
);
let
cons
=
if
args
.len
()
>
1
{
expr_to_str
(
cx
,
args
[
1
],
~
"constraints must be a string literal."
)
}
else
{
~
""
};
MRExpr
(
@
ast
::
expr
{
id
:
cx
.next_id
(),
callee_id
:
cx
.next_id
(),
node
:
ast
::
expr_inline_asm
(
@
asm
,
@
cons
),
node
:
ast
::
expr_inline_asm
(
@
asm
,
@
cons
,
volatile
),
span
:
sp
})
}
//
// Local Variables:
// mode: rust
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
5aa734d6
...
...
@@ -1398,8 +1398,12 @@ fn print_field(s: @ps, field: ast::field) {
}
}
}
ast
::
expr_inline_asm
(
a
,
c
)
=>
{
word
(
s
.s
,
~
"__asm__"
);
ast
::
expr_inline_asm
(
a
,
c
,
v
)
=>
{
if
v
{
word
(
s
.s
,
~
"__volatile__ asm!"
);
}
else
{
word
(
s
.s
,
~
"asm!"
);
}
popen
(
s
);
print_string
(
s
,
*
a
);
word_space
(
s
,
~
","
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录