Skip to content

Commit 3ff78bb

Browse files
committed
---
yaml --- r: 131833 b: refs/heads/dist-snap c: d3096c2 h: refs/heads/master i: 131831: 2cd7807 v: v3
1 parent 050763d commit 3ff78bb

File tree

15 files changed

+217
-164
lines changed

15 files changed

+217
-164
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: b1ae09e52a712f34de7823de55aaa6ef142c6fe9
9+
refs/heads/dist-snap: d3096c2348b463ccdbb1c066b688d487e72e6c73
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ src/etc/dl
8686
.settings/
8787
/build
8888
i686-pc-mingw32/
89-
src/librustc/lib/llvmdeps.rs
89+
src/librustc_llvm/llvmdeps.rs
9090
*.pot

branches/dist-snap/mk/crates.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
5353
uuid serialize sync getopts collections num test time rand \
5454
url log regex graphviz core rlibc alloc debug rustrt \
5555
unicode
56-
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros
56+
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros rustc_llvm
5757
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5858
TOOLS := compiletest rustdoc rustc
5959

@@ -70,8 +70,9 @@ DEPS_green := std native:context_switch
7070
DEPS_rustuv := std native:uv native:uv_support
7171
DEPS_native := std
7272
DEPS_syntax := std term serialize log fmt_macros debug
73-
DEPS_rustc := syntax native:rustllvm flate arena serialize getopts \
74-
time log graphviz debug
73+
DEPS_rustc := syntax flate arena serialize getopts \
74+
time log graphviz debug rustc_llvm
75+
DEPS_rustc_llvm := native:rustllvm libc std
7576
DEPS_rustdoc := rustc native:hoedown serialize getopts \
7677
test time debug
7778
DEPS_flate := std native:miniz

branches/dist-snap/mk/llvm.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $(foreach host,$(CFG_HOST), \
5757
$(foreach host,$(CFG_HOST), \
5858
$(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
5959

60-
$(S)src/librustc/lib/llvmdeps.rs: \
60+
$(S)src/librustc_llvm/llvmdeps.rs: \
6161
$(LLVM_CONFIGS) \
6262
$(S)src/etc/mklldeps.py \
6363
$(MKFILE_DEPS)

branches/dist-snap/mk/target.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
134134

135135
define TARGET_HOST_RULES
136136

137-
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc: $(S)src/librustc/lib/llvmdeps.rs
137+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $(S)src/librustc_llvm/llvmdeps.rs
138138

139139
$$(TBIN$(1)_T_$(2)_H_$(3))/:
140140
mkdir -p $$@

branches/dist-snap/src/doc/guide.md

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,102 +1264,6 @@ do that with `match`.
12641264

12651265
## Match
12661266

1267-
Often, a simple `if`/`else` isn't enough, because you have more than two
1268-
possible options. And `else` conditions can get incredibly complicated. So
1269-
what's the solution?
1270-
1271-
Rust has a keyword, `match`, that allows you to replace complicated `if`/`else`
1272-
groupings with something more powerful. Check it out:
1273-
1274-
```rust
1275-
let x = 5i;
1276-
1277-
match x {
1278-
1 => println!("one"),
1279-
2 => println!("two"),
1280-
3 => println!("three"),
1281-
4 => println!("four"),
1282-
5 => println!("five"),
1283-
_ => println!("something else"),
1284-
}
1285-
```
1286-
1287-
`match` takes an expression, and then branches based on its value. Each 'arm' of
1288-
the branch is of the form `val => expression`. When the value matches, that arm's
1289-
expression will be evaluated. It's called `match` because of the term 'pattern
1290-
matching,' which `match` is an implementation of.
1291-
1292-
So what's the big advantage here? Well, there are a few. First of all, `match`
1293-
does 'exhaustiveness checking.' Do you see that last arm, the one with the
1294-
underscore (`_`)? If we remove that arm, Rust will give us an error:
1295-
1296-
```{ignore,notrust}
1297-
error: non-exhaustive patterns: `_` not covered
1298-
```
1299-
1300-
In other words, Rust is trying to tell us we forgot a value. Because `x` is an
1301-
integer, Rust knows that it can have a number of different values. For example,
1302-
`6i`. But without the `_`, there is no arm that could match, and so Rust refuses
1303-
to compile. `_` is sort of like a catch-all arm. If none of the other arms match,
1304-
the arm with `_` will. And since we have this catch-all arm, we now have an arm
1305-
for every possible value of `x`, and so our program will now compile.
1306-
1307-
`match` statements also destructure enums, as well. Remember this code from the
1308-
section on enums?
1309-
1310-
```{rust}
1311-
let x = 5i;
1312-
let y = 10i;
1313-
1314-
let ordering = x.cmp(&y);
1315-
1316-
if ordering == Less {
1317-
println!("less");
1318-
} else if ordering == Greater {
1319-
println!("greater");
1320-
} else if ordering == Equal {
1321-
println!("equal");
1322-
}
1323-
```
1324-
1325-
We can re-write this as a `match`:
1326-
1327-
```{rust}
1328-
let x = 5i;
1329-
let y = 10i;
1330-
1331-
match x.cmp(&y) {
1332-
Less => println!("less"),
1333-
Greater => println!("greater"),
1334-
Equal => println!("equal"),
1335-
}
1336-
```
1337-
1338-
This version has way less noise, and it also checks exhaustively to make sure
1339-
that we have covered all possible variants of `Ordering`. With our `if`/`else`
1340-
version, if we had forgotten the `Greater` case, for example, our program would
1341-
have happily compiled. If we forget in the `match`, it will not. Rust helps us
1342-
make sure to cover all of our bases.
1343-
1344-
`match` is also an expression, which means we can use it on the right hand side
1345-
of a `let` binding. We could also implement the previous line like this:
1346-
1347-
```
1348-
let x = 5i;
1349-
let y = 10i;
1350-
1351-
let result = match x.cmp(&y) {
1352-
Less => "less",
1353-
Greater => "greater",
1354-
Equal => "equal",
1355-
};
1356-
1357-
println!("{}", result);
1358-
```
1359-
1360-
In this case, it doesn't make a lot of sense, as we are just making a temporary
1361-
string where we don't need to, but sometimes, it's a nice pattern.
1362-
13631267
## Looping
13641268

13651269
for

branches/dist-snap/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ let mut b = Foo { x: 5, y: box 10 };
979979
b.x = 10;
980980
~~~~
981981

982-
If an object doesn't contain any non-`Send` types, it consists of a single
982+
If an object doesn't contain any non-Send types, it consists of a single
983983
ownership tree and is itself given the `Send` trait which allows it to be sent
984984
between tasks. Custom destructors can only be implemented directly on types
985985
that are `Send`, but non-`Send` types can still *contain* types with custom

branches/dist-snap/src/librustc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern crate flate;
4141
extern crate getopts;
4242
extern crate graphviz;
4343
extern crate libc;
44+
extern crate llvm = "rustc_llvm";
4445
extern crate serialize;
4546
extern crate time;
4647
#[phase(plugin, link)] extern crate log;
@@ -128,8 +129,7 @@ pub mod util {
128129
}
129130

130131
pub mod lib {
131-
pub mod llvm;
132-
pub mod llvmdeps;
132+
pub use llvm;
133133
}
134134

135135
__build_diagnostic_array!(DIAGNOSTICS)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
12+
// take a look at src/etc/mklldeps.py if you're interested
13+
14+
#[cfg(target_arch = "x86_64", target_os = "linux")]
15+
#[link(name = "LLVMInstrumentation", kind = "static")]
16+
#[link(name = "LLVMInterpreter", kind = "static")]
17+
#[link(name = "LLVMMCJIT", kind = "static")]
18+
#[link(name = "LLVMRuntimeDyld", kind = "static")]
19+
#[link(name = "LLVMJIT", kind = "static")]
20+
#[link(name = "LLVMExecutionEngine", kind = "static")]
21+
#[link(name = "LLVMAsmParser", kind = "static")]
22+
#[link(name = "LLVMLinker", kind = "static")]
23+
#[link(name = "LLVMBitWriter", kind = "static")]
24+
#[link(name = "LLVMipo", kind = "static")]
25+
#[link(name = "LLVMVectorize", kind = "static")]
26+
#[link(name = "LLVMMipsDisassembler", kind = "static")]
27+
#[link(name = "LLVMMipsCodeGen", kind = "static")]
28+
#[link(name = "LLVMMipsAsmParser", kind = "static")]
29+
#[link(name = "LLVMMipsDesc", kind = "static")]
30+
#[link(name = "LLVMMipsInfo", kind = "static")]
31+
#[link(name = "LLVMMipsAsmPrinter", kind = "static")]
32+
#[link(name = "LLVMARMDisassembler", kind = "static")]
33+
#[link(name = "LLVMARMCodeGen", kind = "static")]
34+
#[link(name = "LLVMARMAsmParser", kind = "static")]
35+
#[link(name = "LLVMARMDesc", kind = "static")]
36+
#[link(name = "LLVMARMInfo", kind = "static")]
37+
#[link(name = "LLVMARMAsmPrinter", kind = "static")]
38+
#[link(name = "LLVMX86Disassembler", kind = "static")]
39+
#[link(name = "LLVMX86AsmParser", kind = "static")]
40+
#[link(name = "LLVMX86CodeGen", kind = "static")]
41+
#[link(name = "LLVMSelectionDAG", kind = "static")]
42+
#[link(name = "LLVMAsmPrinter", kind = "static")]
43+
#[link(name = "LLVMMCParser", kind = "static")]
44+
#[link(name = "LLVMCodeGen", kind = "static")]
45+
#[link(name = "LLVMScalarOpts", kind = "static")]
46+
#[link(name = "LLVMInstCombine", kind = "static")]
47+
#[link(name = "LLVMTransformUtils", kind = "static")]
48+
#[link(name = "LLVMipa", kind = "static")]
49+
#[link(name = "LLVMAnalysis", kind = "static")]
50+
#[link(name = "LLVMTarget", kind = "static")]
51+
#[link(name = "LLVMX86Desc", kind = "static")]
52+
#[link(name = "LLVMX86Info", kind = "static")]
53+
#[link(name = "LLVMX86AsmPrinter", kind = "static")]
54+
#[link(name = "LLVMMC", kind = "static")]
55+
#[link(name = "LLVMObject", kind = "static")]
56+
#[link(name = "LLVMBitReader", kind = "static")]
57+
#[link(name = "LLVMCore", kind = "static")]
58+
#[link(name = "LLVMX86Utils", kind = "static")]
59+
#[link(name = "LLVMSupport", kind = "static")]
60+
#[link(name = "pthread")]
61+
#[link(name = "dl")]
62+
#[link(name = "m")]
63+
#[link(name = "stdc++")]
64+
extern {}

branches/dist-snap/src/librustc/middle/trans/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use driver::config::NoDebugInfo;
1212
use driver::session::Session;
1313
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
14-
use lib::llvm::{llvm, TargetData, TypeNames};
14+
use lib::llvm::{llvm, TargetData};
1515
use lib::llvm::mk_target_data;
1616
use metadata::common::LinkMeta;
1717
use middle::resolve;
@@ -21,7 +21,7 @@ use middle::trans::builder::Builder;
2121
use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res};
2222
use middle::trans::debuginfo;
2323
use middle::trans::monomorphize::MonoId;
24-
use middle::trans::type_::Type;
24+
use middle::trans::type_::{Type, TypeNames};
2525
use middle::ty;
2626
use util::sha2::Sha256;
2727
use util::nodemap::{NodeMap, NodeSet, DefIdMap};

branches/dist-snap/src/librustc/middle/trans/type_.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![allow(non_uppercase_pattern_statics)]
1212

13-
use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind};
13+
use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind, ValueRef};
1414
use lib::llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
1515

1616
use middle::trans::context::CrateContext;
@@ -20,8 +20,11 @@ use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel};
2020

2121
use std::c_str::ToCStr;
2222
use std::mem;
23+
use std::cell::RefCell;
24+
use std::collections::HashMap;
25+
use std::str::raw::from_c_str;
2326

24-
use libc::{c_uint};
27+
use libc::{c_uint, c_void, free};
2528

2629
#[deriving(Clone, PartialEq, Show)]
2730
pub struct Type {
@@ -303,3 +306,50 @@ impl Type {
303306
}
304307
}
305308
}
309+
310+
/* Memory-managed object interface to type handles. */
311+
312+
pub struct TypeNames {
313+
named_types: RefCell<HashMap<String, TypeRef>>,
314+
}
315+
316+
impl TypeNames {
317+
pub fn new() -> TypeNames {
318+
TypeNames {
319+
named_types: RefCell::new(HashMap::new())
320+
}
321+
}
322+
323+
pub fn associate_type(&self, s: &str, t: &Type) {
324+
assert!(self.named_types.borrow_mut().insert(s.to_string(),
325+
t.to_ref()));
326+
}
327+
328+
pub fn find_type(&self, s: &str) -> Option<Type> {
329+
self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
330+
}
331+
332+
pub fn type_to_str(&self, ty: Type) -> String {
333+
unsafe {
334+
let s = llvm::LLVMTypeToString(ty.to_ref());
335+
let ret = from_c_str(s);
336+
free(s as *mut c_void);
337+
ret.to_string()
338+
}
339+
}
340+
341+
pub fn types_to_str(&self, tys: &[Type]) -> String {
342+
let strs: Vec<String> = tys.iter().map(|t| self.type_to_str(*t)).collect();
343+
format!("[{}]", strs.connect(","))
344+
}
345+
346+
pub fn val_to_str(&self, val: ValueRef) -> String {
347+
unsafe {
348+
let s = llvm::LLVMValueToString(val);
349+
let ret = from_c_str(s);
350+
free(s as *mut c_void);
351+
ret.to_string()
352+
}
353+
}
354+
}
355+

0 commit comments

Comments
 (0)