Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
94c8bb46
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
94c8bb46
编写于
11月 16, 2014
作者:
J
Jakub Bukaj
浏览文件
操作
浏览文件
下载
差异文件
rollup merge of #18979: inrustwetrust/codegen-options-parsing
上级
4c30cb25
3391ddda
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
16 deletion
+66
-16
src/librustc/driver/config.rs
src/librustc/driver/config.rs
+27
-8
src/librustc/driver/mod.rs
src/librustc/driver/mod.rs
+4
-8
src/test/run-make/codegen-options-parsing/Makefile
src/test/run-make/codegen-options-parsing/Makefile
+24
-0
src/test/run-make/codegen-options-parsing/dummy.rs
src/test/run-make/codegen-options-parsing/dummy.rs
+11
-0
未找到文件。
src/librustc/driver/config.rs
浏览文件 @
94c8bb46
...
...
@@ -268,8 +268,21 @@ pub fn basic_codegen_options() -> CodegenOptions {
pub
type
CodegenSetter
=
fn
(
&
mut
CodegenOptions
,
v
:
Option
<&
str
>
)
->
bool
;
pub
const
CG_OPTIONS
:
&
'static
[(
&
'static
str
,
CodegenSetter
,
&
'static
str
)]
=
&
[
$
(
(
stringify!
(
$opt
),
cgsetters
::
$opt
,
$desc
)
),
*
];
Option
<&
'static
str
>
,
&
'static
str
)]
=
&
[
$
(
(
stringify!
(
$opt
),
cgsetters
::
$opt
,
cg_type_descs
::
$parse
,
$desc
)
),
*
];
#[allow(non_upper_case_globals)]
mod
cg_type_descs
{
pub
const
parse_bool
:
Option
<&
'static
str
>
=
None
;
pub
const
parse_opt_bool
:
Option
<&
'static
str
>
=
None
;
pub
const
parse_string
:
Option
<&
'static
str
>
=
Some
(
"a string"
);
pub
const
parse_opt_string
:
Option
<&
'static
str
>
=
Some
(
"a string"
);
pub
const
parse_list
:
Option
<&
'static
str
>
=
Some
(
"a space-separated list of strings"
);
pub
const
parse_opt_list
:
Option
<&
'static
str
>
=
Some
(
"a space-separated list of strings"
);
pub
const
parse_uint
:
Option
<&
'static
str
>
=
Some
(
"a number"
);
pub
const
parse_passes
:
Option
<&
'static
str
>
=
Some
(
"a space-separated list of passes, or `all`"
);
}
mod
cgsetters
{
use
super
::{
CodegenOptions
,
Passes
,
SomePasses
,
AllPasses
};
...
...
@@ -420,19 +433,25 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
let
value
=
iter
.next
();
let
option_to_lookup
=
key
.replace
(
"-"
,
"_"
);
let
mut
found
=
false
;
for
&
(
candidate
,
setter
,
_
)
in
CG_OPTIONS
.iter
()
{
for
&
(
candidate
,
setter
,
opt_type_desc
,
_
)
in
CG_OPTIONS
.iter
()
{
if
option_to_lookup
.as_slice
()
!=
candidate
{
continue
}
if
!
setter
(
&
mut
cg
,
value
)
{
match
value
{
Some
(
..
)
=>
{
match
(
value
,
opt_type_desc
)
{
(
Some
(
..
),
None
)
=>
{
early_error
(
format!
(
"codegen option `{}` takes no
\
value"
,
key
)
.as_slice
())
}
None
=>
{
(
None
,
Some
(
type_desc
))
=>
{
early_error
(
format!
(
"codegen option `{0}` requires
\
a value (-C {0}=<value>)"
,
key
)
.as_slice
())
{1} (-C {0}=<value>)"
,
key
,
type_desc
)
.as_slice
())
}
(
Some
(
value
),
Some
(
type_desc
))
=>
{
early_error
(
format!
(
"incorrect value `{}` for codegen
\
option `{}` - {} was expected"
,
value
,
key
,
type_desc
)
.as_slice
())
}
(
None
,
None
)
=>
unreachable!
()
}
}
found
=
true
;
...
...
src/librustc/driver/mod.rs
浏览文件 @
94c8bb46
...
...
@@ -299,14 +299,10 @@ fn describe_debug_flags() {
fn
describe_codegen_flags
()
{
println!
(
"
\n
Available codegen options:
\n
"
);
let
mut
cg
=
config
::
basic_codegen_options
();
for
&
(
name
,
parser
,
desc
)
in
config
::
CG_OPTIONS
.iter
()
{
// we invoke the parser function on `None` to see if this option needs
// an argument or not.
let
(
width
,
extra
)
=
if
parser
(
&
mut
cg
,
None
)
{
(
25
,
""
)
}
else
{
(
21
,
"=val"
)
for
&
(
name
,
_
,
opt_type_desc
,
desc
)
in
config
::
CG_OPTIONS
.iter
()
{
let
(
width
,
extra
)
=
match
opt_type_desc
{
Some
(
..
)
=>
(
21
,
"=val"
),
None
=>
(
25
,
""
)
};
println!
(
" -C {:>width$s}{} -- {}"
,
name
.replace
(
"_"
,
"-"
),
extra
,
desc
,
width
=
width
);
...
...
src/test/run-make/codegen-options-parsing/Makefile
0 → 100644
浏览文件 @
94c8bb46
-include
../tools.mk
all
:
#Option taking a number
$(RUSTC)
-C
codegen-units dummy.rs 2>&1 |
\
grep
'codegen option `codegen-units` requires a number'
$(RUSTC)
-C
codegen-units
=
dummy.rs 2>&1 |
\
grep
'incorrect value `` for codegen option `codegen-units` - a number was expected'
$(RUSTC)
-C
codegen-units
=
foo dummy.rs 2>&1 |
\
grep
'incorrect value `foo` for codegen option `codegen-units` - a number was expected'
$(RUSTC)
-C
codegen-units
=
1 dummy.rs
#Option taking a string
$(RUSTC)
-C
extra-filename dummy.rs 2>&1 |
\
grep
'codegen option `extra-filename` requires a string'
$(RUSTC)
-C
extra-filename
=
dummy.rs 2>&1
$(RUSTC)
-C
extra-filename
=
foo dummy.rs 2>&1
#Option taking no argument
$(RUSTC)
-C
lto
=
dummy.rs 2>&1 |
\
grep
'codegen option `lto` takes no value'
$(RUSTC)
-C
lto
=
1 dummy.rs 2>&1 |
\
grep
'codegen option `lto` takes no value'
$(RUSTC)
-C
lto
=
foo dummy.rs 2>&1 |
\
grep
'codegen option `lto` takes no value'
$(RUSTC)
-C
lto dummy.rs
src/test/run-make/codegen-options-parsing/dummy.rs
0 → 100644
浏览文件 @
94c8bb46
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录