Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c40d6265
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,发现更多精彩内容 >>
提交
c40d6265
编写于
7月 18, 2011
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support x86 stdcall convention
This allows rust to call the Win32 API
上级
68287592
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
61 addition
and
6 deletion
+61
-6
src/comp/lib/llvm.rs
src/comp/lib/llvm.rs
+9
-0
src/comp/metadata/tydecode.rs
src/comp/metadata/tydecode.rs
+1
-0
src/comp/metadata/tyencode.rs
src/comp/metadata/tyencode.rs
+1
-0
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+26
-6
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+1
-0
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+2
-0
src/test/run-pass/x86stdcall.rs
src/test/run-pass/x86stdcall.rs
+21
-0
未找到文件。
src/comp/lib/llvm.rs
浏览文件 @
c40d6265
...
...
@@ -1314,6 +1314,15 @@ fn FastCall(ValueRef Fn, &ValueRef[] Args) -> ValueRef {
ret
v
;
}
fn
CallWithConv
(
ValueRef
Fn
,
&
ValueRef
[]
Args
,
uint
Conv
)
->
ValueRef
{
assert
!
(
*
terminated
);
auto
v
=
llvm
::
LLVMBuildCall
(
B
,
Fn
,
ivec
::
to_ptr
(
Args
),
ivec
::
len
(
Args
),
str
::
buf
(
""
));
llvm
::
LLVMSetInstructionCallConv
(
v
,
Conv
);
ret
v
;
}
fn
Select
(
ValueRef
If
,
ValueRef
Then
,
ValueRef
Else
)
->
ValueRef
{
assert
(
!*
terminated
);
ret
llvm
::
LLVMBuildSelect
(
B
,
If
,
Then
,
Else
,
str
::
buf
(
""
));
...
...
src/comp/metadata/tydecode.rs
浏览文件 @
c40d6265
...
...
@@ -221,6 +221,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
case
(
'i'
)
{
abi
=
ast
::
native_abi_rust_intrinsic
;
}
case
(
'c'
)
{
abi
=
ast
::
native_abi_cdecl
;
}
case
(
'l'
)
{
abi
=
ast
::
native_abi_llvm
;
}
case
(
's'
)
{
abi
=
ast
::
native_abi_x86stdcall
;
}
}
auto
func
=
parse_ty_fn
(
st
,
sd
);
ret
ty
::
mk_native_fn
(
st
.tcx
,
abi
,
func
._0
,
func
._1
);
...
...
src/comp/metadata/tyencode.rs
浏览文件 @
c40d6265
...
...
@@ -155,6 +155,7 @@ fn enc_sty(&ioivec::writer w, &@ctxt cx, &ty::sty st) {
}
case
(
native_abi_cdecl
)
{
w
.write_char
(
'c'
);
}
case
(
native_abi_llvm
)
{
w
.write_char
(
'l'
);
}
case
(
native_abi_x86stdcall
)
{
w
.write_char
(
's'
);
}
}
enc_ty_fn
(
w
,
cx
,
args
,
out
,
return
,
~
[]);
}
...
...
src/comp/middle/trans.rs
浏览文件 @
c40d6265
...
...
@@ -751,7 +751,8 @@ fn trans_native_call(&builder b, @glue_fns glues, ValueRef lltaskptr,
ModuleRef
llmod
,
&
str
name
,
bool
pass_task
,
&
ValueRef
[]
args
)
->
ValueRef
{
let
int
n
=
std
::
ivec
::
len
[
ValueRef
](
args
)
as
int
;
let
ValueRef
llnative
=
get_simple_extern_fn
(
externs
,
llmod
,
name
,
n
);
let
ValueRef
llnative
=
get_simple_extern_fn
(
externs
,
llmod
,
name
,
n
);
let
ValueRef
[]
call_args
=
~
[];
for
(
ValueRef
a
in
args
)
{
call_args
+=
~
[
b
.ZExtOrBitCast
(
a
,
T_int
())];
}
ret
b
.Call
(
llnative
,
call_args
);
...
...
@@ -8142,6 +8143,11 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, &str[] path, str name,
uses_retptr
=
false
;
cast_to_i32
=
false
;
}
case
(
ast
::
native_abi_x86stdcall
)
{
pass_task
=
false
;
uses_retptr
=
false
;
cast_to_i32
=
true
;
}
}
auto
lltaskptr
;
...
...
@@ -8185,7 +8191,7 @@ fn convert_arg_to_i32(&@block_ctxt cx, ValueRef v, ty::t t, ty::mode mode)
fn
trans_simple_native_abi
(
&@
block_ctxt
bcx
,
str
name
,
&
mutable
ValueRef
[]
call_args
,
ty
::
t
fn_type
,
uint
first_arg_n
,
bool
uses_retptr
)
->
bool
uses_retptr
,
uint
cc
)
->
tup
(
ValueRef
,
ValueRef
)
{
let
TypeRef
[]
call_arg_tys
=
~
[];
for
(
ValueRef
arg
in
call_args
)
{
call_arg_tys
+=
~
[
val_ty
(
arg
)];
}
...
...
@@ -8202,8 +8208,12 @@ fn trans_simple_native_abi(&@block_ctxt bcx, str name,
auto
llnativefn
=
get_extern_fn
(
bcx
.fcx.lcx.ccx.externs
,
bcx
.fcx.lcx.ccx.llmod
,
name
,
lib
::
llvm
::
LLVMCCallConv
,
llnativefnty
);
auto
r
=
bcx
.build
.Call
(
llnativefn
,
call_args
);
name
,
cc
,
llnativefnty
);
auto
r
=
if
(
cc
==
lib
::
llvm
::
LLVMCCallConv
)
{
bcx
.build
.Call
(
llnativefn
,
call_args
)
}
else
{
bcx
.build
.CallWithConv
(
llnativefn
,
call_args
,
cc
)
};
auto
rptr
=
bcx
.fcx.llretptr
;
ret
tup
(
r
,
rptr
);
}
...
...
@@ -8231,7 +8241,8 @@ fn trans_simple_native_abi(&@block_ctxt bcx, str name,
case
(
ast
::
native_abi_llvm
)
{
auto
result
=
trans_simple_native_abi
(
bcx
,
name
,
call_args
,
fn_type
,
arg_n
,
uses_retptr
);
uses_retptr
,
lib
::
llvm
::
LLVMCCallConv
);
r
=
result
._0
;
rptr
=
result
._1
;
}
...
...
@@ -8239,7 +8250,16 @@ fn trans_simple_native_abi(&@block_ctxt bcx, str name,
auto
external_name
=
"rust_intrinsic_"
+
name
;
auto
result
=
trans_simple_native_abi
(
bcx
,
external_name
,
call_args
,
fn_type
,
arg_n
,
uses_retptr
);
fn_type
,
arg_n
,
uses_retptr
,
lib
::
llvm
::
LLVMCCallConv
);
r
=
result
._0
;
rptr
=
result
._1
;
}
case
(
ast
::
native_abi_x86stdcall
)
{
auto
result
=
trans_simple_native_abi
(
bcx
,
name
,
call_args
,
fn_type
,
arg_n
,
uses_retptr
,
lib
::
llvm
::
LLVMX86StdcallCallConv
);
r
=
result
._0
;
rptr
=
result
._1
;
}
...
...
src/comp/syntax/ast.rs
浏览文件 @
c40d6265
...
...
@@ -526,6 +526,7 @@ fn ty_mach_to_str(ty_mach tm) -> str {
native_abi_cdecl
;
native_abi_llvm
;
native_abi_rust_intrinsic
;
native_abi_x86stdcall
;
}
type
native_mod
=
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
c40d6265
...
...
@@ -2004,6 +2004,8 @@ fn parse_item_native_mod(&parser p, &ast::attribute[] attrs) -> @ast::item {
abi
=
ast
::
native_abi_llvm
;
}
else
if
(
str
::
eq
(
t
,
"rust-intrinsic"
))
{
abi
=
ast
::
native_abi_rust_intrinsic
;
}
else
if
(
str
::
eq
(
t
,
"x86stdcall"
))
{
abi
=
ast
::
native_abi_x86stdcall
;
}
else
{
p
.fatal
(
"unsupported abi: "
+
t
);
fail
;
}
}
expect_word
(
p
,
"mod"
);
...
...
src/test/run-pass/x86stdcall.rs
0 → 100644
浏览文件 @
c40d6265
// xfail-stage0
#[cfg(target_os
=
"win32"
)]
mod
m
{
native
"x86stdcall"
mod
kernel32
{
fn
SetLastError
(
uint
err
);
fn
GetLastError
()
->
uint
;
}
fn
main
()
{
auto
expected
=
10u
;
kernel32
::
SetLastError
(
expected
);
auto
actual
=
kernel32
::
GetLastError
();
assert
expected
==
actual
;
}
}
#[cfg(target_os
=
"macos"
)]
#[cfg(target_os
=
"linux"
)]
fn
main
()
{
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录