Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
225353d8
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,发现更多精彩内容 >>
提交
225353d8
编写于
9月 09, 2014
作者:
K
Keegan McAllister
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a Rust string ostream for LLVM
上级
77b3a7ba
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
24 deletion
+67
-24
src/librustc/middle/trans/type_.rs
src/librustc/middle/trans/type_.rs
+7
-14
src/librustc_llvm/lib.rs
src/librustc_llvm/lib.rs
+28
-2
src/rustllvm/RustWrapper.cpp
src/rustllvm/RustWrapper.cpp
+4
-8
src/rustllvm/rustllvm.h
src/rustllvm/rustllvm.h
+28
-0
未找到文件。
src/librustc/middle/trans/type_.rs
浏览文件 @
225353d8
...
...
@@ -21,11 +21,10 @@
use
std
::
c_str
::
ToCStr
;
use
std
::
mem
;
use
std
::
string
;
use
std
::
cell
::
RefCell
;
use
std
::
collections
::
HashMap
;
use
libc
::
{
c_uint
,
c_void
,
free
}
;
use
libc
::
c_uint
;
#[deriving(Clone,
PartialEq,
Show)]
pub
struct
Type
{
...
...
@@ -339,12 +338,9 @@ pub fn find_type(&self, s: &str) -> Option<Type> {
}
pub
fn
type_to_string
(
&
self
,
ty
:
Type
)
->
String
{
unsafe
{
let
s
=
llvm
::
LLVMTypeToString
(
ty
.to_ref
());
let
ret
=
string
::
raw
::
from_buf
(
s
as
*
const
u8
);
free
(
s
as
*
mut
c_void
);
ret
}
llvm
::
build_string
(|
s
|
unsafe
{
llvm
::
LLVMWriteTypeToString
(
ty
.to_ref
(),
s
);
})
.expect
(
"non-UTF8 type description from LLVM"
)
}
pub
fn
types_to_str
(
&
self
,
tys
:
&
[
Type
])
->
String
{
...
...
@@ -353,11 +349,8 @@ pub fn types_to_str(&self, tys: &[Type]) -> String {
}
pub
fn
val_to_string
(
&
self
,
val
:
ValueRef
)
->
String
{
unsafe
{
let
s
=
llvm
::
LLVMValueToString
(
val
);
let
ret
=
string
::
raw
::
from_buf
(
s
as
*
const
u8
);
free
(
s
as
*
mut
c_void
);
ret
}
llvm
::
build_string
(|
s
|
unsafe
{
llvm
::
LLVMWriteValueToString
(
val
,
s
);
})
.expect
(
"nun-UTF8 value description from LLVM"
)
}
}
src/librustc_llvm/lib.rs
浏览文件 @
225353d8
...
...
@@ -28,6 +28,8 @@
extern
crate
libc
;
use
std
::
c_str
::
ToCStr
;
use
std
::
cell
::
RefCell
;
use
std
::{
raw
,
mem
};
use
libc
::{
c_uint
,
c_ushort
,
uint64_t
,
c_int
,
size_t
,
c_char
};
use
libc
::{
c_longlong
,
c_ulonglong
};
use
debuginfo
::{
DIBuilderRef
,
DIDescriptor
,
...
...
@@ -1839,8 +1841,8 @@ pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
->
ValueRef
;
pub
fn
LLVMDICompositeTypeSetTypeArray
(
CompositeType
:
ValueRef
,
TypeArray
:
ValueRef
);
pub
fn
LLVM
TypeToString
(
Type
:
TypeRef
)
->
*
const
c_char
;
pub
fn
LLVM
ValueToString
(
value_ref
:
ValueRef
)
->
*
const
c_char
;
pub
fn
LLVM
WriteTypeToString
(
Type
:
TypeRef
,
s
:
RustStringRef
)
;
pub
fn
LLVM
WriteValueToString
(
value_ref
:
ValueRef
,
s
:
RustStringRef
)
;
pub
fn
LLVMIsAArgument
(
value_ref
:
ValueRef
)
->
ValueRef
;
...
...
@@ -2046,6 +2048,30 @@ pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
}
}
pub
enum
RustString_opaque
{}
pub
type
RustStringRef
=
*
mut
RustString_opaque
;
type
RustStringRepr
=
*
mut
RefCell
<
Vec
<
u8
>>
;
/// Appending to a Rust string -- used by raw_rust_string_ostream.
#[no_mangle]
pub
unsafe
extern
"C"
fn
rust_llvm_string_write_impl
(
sr
:
RustStringRef
,
ptr
:
*
const
c_char
,
size
:
size_t
)
{
let
slice
:
&
[
u8
]
=
mem
::
transmute
(
raw
::
Slice
{
data
:
ptr
as
*
const
u8
,
len
:
size
as
uint
,
});
let
sr
:
RustStringRepr
=
mem
::
transmute
(
sr
);
(
*
sr
)
.borrow_mut
()
.push_all
(
slice
);
}
pub
fn
build_string
(
f
:
|
RustStringRef
|)
->
Option
<
String
>
{
let
mut
buf
=
RefCell
::
new
(
Vec
::
new
());
f
(
&
mut
buf
as
RustStringRepr
as
RustStringRef
);
String
::
from_utf8
(
buf
.unwrap
())
.ok
()
}
// FIXME #15460 - create a public function that actually calls our
// static LLVM symbols. Otherwise the linker will just throw llvm
// away. We're just calling lots of stuff until we transitively get
...
...
src/rustllvm/RustWrapper.cpp
浏览文件 @
225353d8
...
...
@@ -645,22 +645,18 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
#endif
}
extern
"C"
char
*
LLVMTypeToString
(
LLVMTypeRef
Type
)
{
std
::
string
s
;
llvm
::
raw_string_ostream
os
(
s
);
extern
"C"
void
LLVMWriteTypeToString
(
LLVMTypeRef
Type
,
RustStringRef
str
)
{
raw_rust_string_ostream
os
(
str
);
unwrap
<
llvm
::
Type
>
(
Type
)
->
print
(
os
);
return
strdup
(
os
.
str
().
data
());
}
extern
"C"
char
*
LLVMValueToString
(
LLVMValueRef
Value
)
{
std
::
string
s
;
llvm
::
raw_string_ostream
os
(
s
);
extern
"C"
void
LLVMWriteValueToString
(
LLVMValueRef
Value
,
RustStringRef
str
)
{
raw_rust_string_ostream
os
(
str
);
os
<<
"("
;
unwrap
<
llvm
::
Value
>
(
Value
)
->
getType
()
->
print
(
os
);
os
<<
":"
;
unwrap
<
llvm
::
Value
>
(
Value
)
->
print
(
os
);
os
<<
")"
;
return
strdup
(
os
.
str
().
data
());
}
#if LLVM_VERSION_MINOR >= 5
...
...
src/rustllvm/rustllvm.h
浏览文件 @
225353d8
...
...
@@ -69,3 +69,31 @@
#endif
void
LLVMRustSetLastError
(
const
char
*
);
typedef
struct
OpaqueRustString
*
RustStringRef
;
extern
"C"
void
rust_llvm_string_write_impl
(
RustStringRef
str
,
const
char
*
ptr
,
size_t
size
);
class
raw_rust_string_ostream
:
public
llvm
::
raw_ostream
{
RustStringRef
str
;
uint64_t
pos
;
void
write_impl
(
const
char
*
ptr
,
size_t
size
)
override
{
rust_llvm_string_write_impl
(
str
,
ptr
,
size
);
pos
+=
size
;
}
uint64_t
current_pos
()
const
override
{
return
pos
;
}
public:
explicit
raw_rust_string_ostream
(
RustStringRef
str
)
:
str
(
str
),
pos
(
0
)
{
}
~
raw_rust_string_ostream
()
{
// LLVM requires this.
flush
();
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录