Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
813a9fc4
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,发现更多精彩内容 >>
提交
813a9fc4
编写于
1月 22, 2020
作者:
A
Amanieu d'Antras
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add asm! to AST
上级
989edf6d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
214 addition
and
1 deletion
+214
-1
Cargo.lock
Cargo.lock
+2
-0
src/librustc_ast/Cargo.toml
src/librustc_ast/Cargo.toml
+1
-0
src/librustc_ast/ast.rs
src/librustc_ast/ast.rs
+56
-1
src/librustc_ast/mut_visit.rs
src/librustc_ast/mut_visit.rs
+21
-0
src/librustc_ast/visit.rs
src/librustc_ast/visit.rs
+21
-0
src/librustc_ast_pretty/Cargo.toml
src/librustc_ast_pretty/Cargo.toml
+1
-0
src/librustc_ast_pretty/pprust.rs
src/librustc_ast_pretty/pprust.rs
+112
-0
未找到文件。
Cargo.lock
浏览文件 @
813a9fc4
...
...
@@ -3631,6 +3631,7 @@ dependencies = [
"rustc_lexer",
"rustc_macros",
"rustc_span",
"rustc_target",
"scoped-tls",
"serialize",
"smallvec 1.4.0",
...
...
@@ -3678,6 +3679,7 @@ dependencies = [
"log",
"rustc_ast",
"rustc_span",
"rustc_target",
]
[[package]]
...
...
src/librustc_ast/Cargo.toml
浏览文件 @
813a9fc4
...
...
@@ -19,3 +19,4 @@ rustc_index = { path = "../librustc_index" }
rustc_lexer
=
{
path
=
"../librustc_lexer"
}
rustc_macros
=
{
path
=
"../librustc_macros"
}
smallvec
=
{
version
=
"1.0"
,
features
=
[
"union"
,
"may_dangle"
]
}
rustc_target
=
{
path
=
"../librustc_target"
}
src/librustc_ast/ast.rs
浏览文件 @
813a9fc4
...
...
@@ -34,6 +34,7 @@
use
rustc_span
::
source_map
::{
respan
,
Spanned
};
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
,
Symbol
};
use
rustc_span
::{
Span
,
DUMMY_SP
};
use
rustc_target
::
asm
::{
InlineAsmOptions
,
InlineAsmTemplatePiece
};
use
std
::
convert
::
TryFrom
;
use
std
::
fmt
;
...
...
@@ -1121,7 +1122,7 @@ pub fn precedence(&self) -> ExprPrecedence {
ExprKind
::
Break
(
..
)
=>
ExprPrecedence
::
Break
,
ExprKind
::
Continue
(
..
)
=>
ExprPrecedence
::
Continue
,
ExprKind
::
Ret
(
..
)
=>
ExprPrecedence
::
Ret
,
ExprKind
::
LlvmInlineAsm
(
..
)
=>
ExprPrecedence
::
InlineAsm
,
ExprKind
::
InlineAsm
(
..
)
|
ExprKind
::
LlvmInlineAsm
(
..
)
=>
ExprPrecedence
::
InlineAsm
,
ExprKind
::
MacCall
(
..
)
=>
ExprPrecedence
::
Mac
,
ExprKind
::
Struct
(
..
)
=>
ExprPrecedence
::
Struct
,
ExprKind
::
Repeat
(
..
)
=>
ExprPrecedence
::
Repeat
,
...
...
@@ -1250,6 +1251,8 @@ pub enum ExprKind {
/// A `return`, with an optional value to be returned.
Ret
(
Option
<
P
<
Expr
>>
),
/// Output of the `asm!()` macro.
InlineAsm
(
InlineAsm
),
/// Output of the `llvm_asm!()` macro.
LlvmInlineAsm
(
P
<
LlvmInlineAsm
>
),
...
...
@@ -1864,6 +1867,58 @@ pub enum TraitObjectSyntax {
None
,
}
/// Inline assembly operand explicit register or register class.
///
/// E.g., `"eax"` as in `asm!("mov eax, 2", out("eax") result)`.
#[derive(Clone,
Copy,
RustcEncodable,
RustcDecodable,
Debug)]
pub
enum
InlineAsmRegOrRegClass
{
Reg
(
Symbol
),
RegClass
(
Symbol
),
}
/// Inline assembly operand.
///
/// E.g., `out("eax") result` as in `asm!("mov eax, 2", out("eax") result)`.
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
pub
enum
InlineAsmOperand
{
In
{
reg
:
InlineAsmRegOrRegClass
,
expr
:
P
<
Expr
>
,
},
Out
{
reg
:
InlineAsmRegOrRegClass
,
late
:
bool
,
expr
:
Option
<
P
<
Expr
>>
,
},
InOut
{
reg
:
InlineAsmRegOrRegClass
,
late
:
bool
,
expr
:
P
<
Expr
>
,
},
SplitInOut
{
reg
:
InlineAsmRegOrRegClass
,
late
:
bool
,
in_expr
:
P
<
Expr
>
,
out_expr
:
Option
<
P
<
Expr
>>
,
},
Const
{
expr
:
P
<
Expr
>
,
},
Sym
{
expr
:
P
<
Expr
>
,
},
}
/// Inline assembly.
///
/// E.g., `asm!("NOP");`.
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
pub
struct
InlineAsm
{
pub
template
:
Vec
<
InlineAsmTemplatePiece
>
,
pub
operands
:
Vec
<
(
InlineAsmOperand
,
Span
)
>
,
pub
options
:
InlineAsmOptions
,
}
/// Inline assembly dialect.
///
/// E.g., `"intel"` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`.
...
...
src/librustc_ast/mut_visit.rs
浏览文件 @
813a9fc4
...
...
@@ -1205,6 +1205,27 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr,
ExprKind
::
Ret
(
expr
)
=>
{
visit_opt
(
expr
,
|
expr
|
vis
.visit_expr
(
expr
));
}
ExprKind
::
InlineAsm
(
asm
)
=>
{
for
(
op
,
_
)
in
&
mut
asm
.operands
{
match
op
{
InlineAsmOperand
::
In
{
expr
,
..
}
|
InlineAsmOperand
::
InOut
{
expr
,
..
}
|
InlineAsmOperand
::
Const
{
expr
,
..
}
|
InlineAsmOperand
::
Sym
{
expr
,
..
}
=>
vis
.visit_expr
(
expr
),
InlineAsmOperand
::
Out
{
expr
,
..
}
=>
{
if
let
Some
(
expr
)
=
expr
{
vis
.visit_expr
(
expr
);
}
}
InlineAsmOperand
::
SplitInOut
{
in_expr
,
out_expr
,
..
}
=>
{
vis
.visit_expr
(
in_expr
);
if
let
Some
(
out_expr
)
=
out_expr
{
vis
.visit_expr
(
out_expr
);
}
}
}
}
}
ExprKind
::
LlvmInlineAsm
(
asm
)
=>
{
let
LlvmInlineAsm
{
asm
:
_
,
...
...
src/librustc_ast/visit.rs
浏览文件 @
813a9fc4
...
...
@@ -818,6 +818,27 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
}
ExprKind
::
MacCall
(
ref
mac
)
=>
visitor
.visit_mac
(
mac
),
ExprKind
::
Paren
(
ref
subexpression
)
=>
visitor
.visit_expr
(
subexpression
),
ExprKind
::
InlineAsm
(
ref
ia
)
=>
{
for
(
op
,
_
)
in
&
ia
.operands
{
match
op
{
InlineAsmOperand
::
In
{
expr
,
..
}
|
InlineAsmOperand
::
InOut
{
expr
,
..
}
|
InlineAsmOperand
::
Const
{
expr
,
..
}
|
InlineAsmOperand
::
Sym
{
expr
,
..
}
=>
visitor
.visit_expr
(
expr
),
InlineAsmOperand
::
Out
{
expr
,
..
}
=>
{
if
let
Some
(
expr
)
=
expr
{
visitor
.visit_expr
(
expr
);
}
}
InlineAsmOperand
::
SplitInOut
{
in_expr
,
out_expr
,
..
}
=>
{
visitor
.visit_expr
(
in_expr
);
if
let
Some
(
out_expr
)
=
out_expr
{
visitor
.visit_expr
(
out_expr
);
}
}
}
}
}
ExprKind
::
LlvmInlineAsm
(
ref
ia
)
=>
{
for
&
(
_
,
ref
input
)
in
&
ia
.inputs
{
visitor
.visit_expr
(
input
)
...
...
src/librustc_ast_pretty/Cargo.toml
浏览文件 @
813a9fc4
...
...
@@ -13,3 +13,4 @@ doctest = false
log
=
"0.4"
rustc_span
=
{
path
=
"../librustc_span"
}
rustc_ast
=
{
path
=
"../librustc_ast"
}
rustc_target
=
{
path
=
"../librustc_target"
}
src/librustc_ast_pretty/pprust.rs
浏览文件 @
813a9fc4
...
...
@@ -4,6 +4,7 @@
use
rustc_ast
::
ast
::{
self
,
BlockCheckMode
,
PatKind
,
RangeEnd
,
RangeSyntax
};
use
rustc_ast
::
ast
::{
Attribute
,
GenericArg
,
MacArgs
};
use
rustc_ast
::
ast
::{
GenericBound
,
SelfKind
,
TraitBoundModifier
};
use
rustc_ast
::
ast
::{
InlineAsmOperand
,
InlineAsmRegOrRegClass
};
use
rustc_ast
::
attr
;
use
rustc_ast
::
ptr
::
P
;
use
rustc_ast
::
token
::{
self
,
BinOpToken
,
DelimToken
,
Nonterminal
,
Token
,
TokenKind
};
...
...
@@ -14,6 +15,7 @@
use
rustc_span
::
source_map
::{
SourceMap
,
Spanned
};
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
,
IdentPrinter
,
Symbol
};
use
rustc_span
::{
BytePos
,
FileName
,
Span
};
use
rustc_target
::
asm
::{
InlineAsmOptions
,
InlineAsmTemplatePiece
};
use
std
::
borrow
::
Cow
;
...
...
@@ -2014,6 +2016,116 @@ fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline: bool) {
self
.print_expr_maybe_paren
(
expr
,
parser
::
PREC_JUMP
);
}
}
ast
::
ExprKind
::
InlineAsm
(
ref
a
)
=>
{
enum
AsmArg
<
'a
>
{
Template
(
String
),
Operand
(
&
'a
InlineAsmOperand
),
Options
(
InlineAsmOptions
),
}
let
mut
args
=
vec!
[];
args
.push
(
AsmArg
::
Template
(
InlineAsmTemplatePiece
::
to_string
(
&
a
.template
)));
args
.extend
(
a
.operands
.iter
()
.map
(|(
o
,
_
)|
AsmArg
::
Operand
(
o
)));
if
!
a
.options
.is_empty
()
{
args
.push
(
AsmArg
::
Options
(
a
.options
));
}
self
.word
(
"asm!"
);
self
.popen
();
self
.commasep
(
Consistent
,
&
args
,
|
s
,
arg
|
match
arg
{
AsmArg
::
Template
(
template
)
=>
s
.print_string
(
&
template
,
ast
::
StrStyle
::
Cooked
),
AsmArg
::
Operand
(
op
)
=>
{
let
print_reg_or_class
=
|
s
:
&
mut
Self
,
r
:
&
InlineAsmRegOrRegClass
|
match
r
{
InlineAsmRegOrRegClass
::
Reg
(
r
)
=>
{
s
.print_string
(
&
r
.as_str
(),
ast
::
StrStyle
::
Cooked
)
}
InlineAsmRegOrRegClass
::
RegClass
(
r
)
=>
s
.word
(
r
.to_string
()),
};
match
op
{
InlineAsmOperand
::
In
{
reg
,
expr
}
=>
{
s
.word
(
"in"
);
s
.popen
();
print_reg_or_class
(
s
,
reg
);
s
.pclose
();
s
.space
();
s
.print_expr
(
expr
);
}
InlineAsmOperand
::
Out
{
reg
,
late
,
expr
}
=>
{
s
.word
(
if
*
late
{
"lateout"
}
else
{
"out"
});
s
.popen
();
print_reg_or_class
(
s
,
reg
);
s
.pclose
();
s
.space
();
match
expr
{
Some
(
expr
)
=>
s
.print_expr
(
expr
),
None
=>
s
.word
(
"_"
),
}
}
InlineAsmOperand
::
InOut
{
reg
,
late
,
expr
}
=>
{
s
.word
(
if
*
late
{
"inlateout"
}
else
{
"inout"
});
s
.popen
();
print_reg_or_class
(
s
,
reg
);
s
.pclose
();
s
.space
();
s
.print_expr
(
expr
);
}
InlineAsmOperand
::
SplitInOut
{
reg
,
late
,
in_expr
,
out_expr
}
=>
{
s
.word
(
if
*
late
{
"inlateout"
}
else
{
"inout"
});
s
.popen
();
print_reg_or_class
(
s
,
reg
);
s
.pclose
();
s
.space
();
s
.print_expr
(
in_expr
);
s
.space
();
s
.word_space
(
"=>"
);
match
out_expr
{
Some
(
out_expr
)
=>
s
.print_expr
(
out_expr
),
None
=>
s
.word
(
"_"
),
}
}
InlineAsmOperand
::
Const
{
expr
}
=>
{
s
.word
(
"const"
);
s
.space
();
s
.print_expr
(
expr
);
}
InlineAsmOperand
::
Sym
{
expr
}
=>
{
s
.word
(
"sym"
);
s
.space
();
s
.print_expr
(
expr
);
}
}
}
AsmArg
::
Options
(
opts
)
=>
{
s
.word
(
"options"
);
s
.popen
();
let
mut
options
=
vec!
[];
if
opts
.contains
(
InlineAsmOptions
::
PURE
)
{
options
.push
(
"pure"
);
}
if
opts
.contains
(
InlineAsmOptions
::
NOMEM
)
{
options
.push
(
"nomem"
);
}
if
opts
.contains
(
InlineAsmOptions
::
READONLY
)
{
options
.push
(
"readonly"
);
}
if
opts
.contains
(
InlineAsmOptions
::
PRESERVES_FLAGS
)
{
options
.push
(
"preserves_flags"
);
}
if
opts
.contains
(
InlineAsmOptions
::
NORETURN
)
{
options
.push
(
"noreturn"
);
}
if
opts
.contains
(
InlineAsmOptions
::
NOSTACK
)
{
options
.push
(
"nostack"
);
}
s
.commasep
(
Inconsistent
,
&
options
,
|
s
,
&
opt
|
{
s
.word
(
opt
);
});
s
.pclose
();
}
});
self
.pclose
();
}
ast
::
ExprKind
::
LlvmInlineAsm
(
ref
a
)
=>
{
self
.s
.word
(
"llvm_asm!"
);
self
.popen
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录