Skip to content

Commit f018a88

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 6097 b: refs/heads/master c: 5b3bddc h: refs/heads/master i: 6095: c38ede3 v: v3
1 parent d35ad98 commit f018a88

File tree

9 files changed

+115
-75
lines changed

9 files changed

+115
-75
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: eed782c7783f3f7dd57323e238e674bf4cfe77a9
2+
refs/heads/master: 5b3bddcd8753d14a3f299c4f28f932570f2276b1

trunk/src/comp/back/link.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ mod write {
9494
if opts.stack_growth { llvm::LLVMRustEnableSegmentedStacks(); }
9595
link_intrinsics(sess, llmod);
9696
let pm = mk_pass_manager();
97-
let td = mk_target_data(x86::get_data_layout());
97+
let td = mk_target_data(
98+
sess.get_targ_cfg().target_strs.data_layout);
9899
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
99100
// TODO: run the linter here also, once there are llvm-c bindings for
100101
// it.
@@ -199,16 +200,17 @@ mod write {
199200
// Save the assembly file if -S is used
200201

201202
if opts.output_type == output_type_assembly {
202-
let _: () = str::as_buf(x86::get_target_triple(), {|buf_t|
203-
str::as_buf(output, {|buf_o|
204-
llvm::LLVMRustWriteOutputFile(pm.llpm,
205-
llmod,
206-
buf_t,
207-
buf_o,
208-
LLVMAssemblyFile,
209-
CodeGenOptLevel)
210-
})
211-
});
203+
let _: () = str::as_buf(
204+
sess.get_targ_cfg().target_strs.target_triple,
205+
{|buf_t|
206+
str::as_buf(output, {|buf_o|
207+
llvm::LLVMRustWriteOutputFile(
208+
pm.llpm,
209+
llmod,
210+
buf_t,
211+
buf_o,
212+
LLVMAssemblyFile,
213+
CodeGenOptLevel)})});
212214
}
213215

214216

@@ -217,32 +219,34 @@ mod write {
217219
if opts.output_type == output_type_object ||
218220
opts.output_type == output_type_exe {
219221
let _: () =
220-
str::as_buf(x86::get_target_triple(), {|buf_t|
221-
str::as_buf(output, {|buf_o|
222-
llvm::LLVMRustWriteOutputFile(pm.llpm,
223-
llmod,
224-
buf_t,
225-
buf_o,
226-
LLVMObjectFile,
227-
CodeGenOptLevel)
228-
})
229-
});
222+
str::as_buf(
223+
sess.get_targ_cfg().target_strs.target_triple,
224+
{|buf_t|
225+
str::as_buf(output, {|buf_o|
226+
llvm::LLVMRustWriteOutputFile(
227+
pm.llpm,
228+
llmod,
229+
buf_t,
230+
buf_o,
231+
LLVMObjectFile,
232+
CodeGenOptLevel)})});
230233
}
231234
} else {
232235
// If we aren't saving temps then just output the file
233236
// type corresponding to the '-c' or '-S' flag used
234237

235238
let _: () =
236-
str::as_buf(x86::get_target_triple(), {|buf_t|
237-
str::as_buf(output, {|buf_o|
238-
llvm::LLVMRustWriteOutputFile(pm.llpm,
239-
llmod,
240-
buf_t,
241-
buf_o,
242-
FileType,
243-
CodeGenOptLevel)
244-
})
245-
});
239+
str::as_buf(
240+
sess.get_targ_cfg().target_strs.target_triple,
241+
{|buf_t|
242+
str::as_buf(output, {|buf_o|
243+
llvm::LLVMRustWriteOutputFile(
244+
pm.llpm,
245+
llmod,
246+
buf_t,
247+
buf_o,
248+
FileType,
249+
CodeGenOptLevel)})});
246250
}
247251
// Clean up and return
248252

trunk/src/comp/back/target_strs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import std::str;
2+
3+
type t = {
4+
module_asm: str,
5+
meta_sect_name: str,
6+
data_layout: str,
7+
target_triple: str
8+
};

trunk/src/comp/back/x86.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1-
21
import lib::llvm::llvm;
32
import lib::llvm::llvm::ModuleRef;
43
import std::str;
5-
import std::os::target_os;
4+
import driver::session;
65

7-
fn get_module_asm() -> str { ret ""; }
6+
fn get_target_strs(target_os: session::os) -> target_strs::t {
7+
ret {
8+
module_asm: "",
89

9-
fn get_meta_sect_name() -> str {
10-
if str::eq(target_os(), "macos") { ret "__DATA,__note.rustc"; }
11-
if str::eq(target_os(), "win32") { ret ".note.rustc"; }
12-
ret ".note.rustc";
13-
}
10+
meta_sect_name: alt target_os {
11+
session::os_macos. { "__DATA,__note.rustc" }
12+
session::os_win32. { ".note.rustc" }
13+
session::os_linux. { ".note.rustc" }
14+
},
1415

15-
fn get_data_layout() -> str {
16-
if str::eq(target_os(), "macos") {
17-
ret "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" + "-i32:32:32-i64:32:64" +
16+
data_layout: alt target_os {
17+
session::os_macos. {
18+
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" + "-i32:32:32-i64:32:64" +
1819
"-f32:32:32-f64:32:64-v64:64:64" +
19-
"-v128:128:128-a0:0:64-f80:128:128" + "-n8:16:32";
20-
}
21-
if str::eq(target_os(), "win32") {
22-
ret "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32";
23-
}
24-
ret "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32";
25-
}
20+
"-v128:128:128-a0:0:64-f80:128:128" + "-n8:16:32"
21+
}
2622

27-
fn get_target_triple() -> str {
28-
if str::eq(target_os(), "macos") { ret "i686-apple-darwin"; }
29-
if str::eq(target_os(), "win32") { ret "i686-pc-mingw32"; }
30-
ret "i686-unknown-linux-gnu";
23+
session::os_win32. {
24+
"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32"
25+
}
26+
27+
session::os_linux. {
28+
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
29+
}
30+
},
31+
32+
target_triple: alt target_os {
33+
session::os_macos. { "i686-apple-darwin" }
34+
session::os_win32. { "i686-pc-mingw32" }
35+
session::os_linux. { "i686-unknown-linux-gnu" }
36+
}
37+
};
3138
}
39+
3240
//
3341
// Local Variables:
3442
// mode: rust

trunk/src/comp/driver/rustc.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import std::map::mk_hashmap;
1616
import std::option::{some, none};
1717
import std::getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
1818
import back::link::output_type;
19+
import back::x86;
1920

2021
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }
2122

@@ -302,12 +303,21 @@ fn get_arch(triple: str) -> session::arch {
302303
}
303304

304305
fn build_target_config(sopts: @session::options) -> @session::config {
306+
let os = get_os(sopts.target_triple);
307+
let arch = get_arch(sopts.target_triple);
308+
let (int_type, uint_type, float_type) = alt arch {
309+
session::arch_x86. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
310+
session::arch_x64. {(ast::ty_i64, ast::ty_u64, ast::ty_f64)}
311+
session::arch_arm. {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
312+
};
313+
let target_strs = alt arch {
314+
session::arch_x86. {x86::get_target_strs(os)}
315+
session::arch_x64. {x86::get_target_strs(os)}
316+
session::arch_arm. {x86::get_target_strs(os)}
317+
};
305318
let target_cfg: @session::config =
306-
@{os: get_os(sopts.target_triple),
307-
arch: get_arch(sopts.target_triple),
308-
int_type: ast::ty_i32,
309-
uint_type: ast::ty_u32,
310-
float_type: ast::ty_f64};
319+
@{os: os, arch: arch, target_strs: target_strs, int_type: int_type,
320+
uint_type: uint_type, float_type: float_type};
311321
ret target_cfg;
312322
}
313323

@@ -531,7 +541,10 @@ fn main(args: [str]) {
531541
none::<pp_mode>. {/* continue */ }
532542
}
533543
let ls = opt_present(match, "ls");
534-
if ls { metadata::creader::list_file_metadata(ifile, io::stdout()); ret; }
544+
if ls {
545+
metadata::creader::list_file_metadata(sess, ifile, io::stdout());
546+
ret;
547+
}
535548

536549
let stop_after_codegen =
537550
sopts.output_type != link::output_type_exe ||

trunk/src/comp/driver/session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import std::{uint, map, option, str};
77
import std::option::{some, none};
88
import syntax::parse::parser::parse_sess;
99
import util::filesearch;
10+
import back::target_strs;
1011

1112
tag os { os_win32; os_macos; os_linux; }
1213

@@ -15,6 +16,7 @@ tag arch { arch_x86; arch_x64; arch_arm; }
1516
type config =
1617
{os: os,
1718
arch: arch,
19+
target_strs: target_strs::t,
1820
int_type: ty_mach,
1921
uint_type: ty_mach,
2022
float_type: ty_mach};

trunk/src/comp/metadata/creader.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ fn visit_item(e: env, i: @ast::item) {
7272
}
7373

7474
// A diagnostic function for dumping crate metadata to an output stream
75-
fn list_file_metadata(path: str, out: io::writer) {
76-
alt get_metadata_section(path) {
75+
fn list_file_metadata(sess: session::session, path: str, out: io::writer) {
76+
alt get_metadata_section(sess, path) {
7777
option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
7878
option::none. {
7979
out.write_str("Could not find metadata in " + path + ".\n");
@@ -126,13 +126,14 @@ fn find_library_crate(sess: session::session, ident: ast::ident,
126126
}
127127
let nn = default_native_lib_naming(sess, sess.get_opts().static);
128128
let x =
129-
find_library_crate_aux(nn, metas, sess.filesearch());
129+
find_library_crate_aux(sess, nn, metas, sess.filesearch());
130130
if x != none || sess.get_opts().static { ret x; }
131131
let nn2 = default_native_lib_naming(sess, true);
132-
ret find_library_crate_aux(nn2, metas, sess.filesearch());
132+
ret find_library_crate_aux(sess, nn2, metas, sess.filesearch());
133133
}
134134

135-
fn find_library_crate_aux(nn: {prefix: str, suffix: str},
135+
fn find_library_crate_aux(sess: session::session,
136+
nn: {prefix: str, suffix: str},
136137
metas: [@ast::meta_item],
137138
filesearch: filesearch::filesearch) ->
138139
option::t<{ident: str, data: @[u8]}> {
@@ -148,7 +149,7 @@ fn find_library_crate_aux(nn: {prefix: str, suffix: str},
148149
option::none
149150
} else {
150151
log #fmt("%s is a candidate", path);
151-
alt get_metadata_section(path) {
152+
alt get_metadata_section(sess, path) {
152153
option::some(cvec) {
153154
if !metadata_matches(cvec, metas) {
154155
log #fmt["skipping %s, metadata doesn't match", path];
@@ -167,7 +168,8 @@ fn find_library_crate_aux(nn: {prefix: str, suffix: str},
167168
});
168169
}
169170

170-
fn get_metadata_section(filename: str) -> option::t<@[u8]> unsafe {
171+
fn get_metadata_section(sess: session::session,
172+
filename: str) -> option::t<@[u8]> {
171173
let mb = str::as_buf(filename, {|buf|
172174
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
173175
});
@@ -176,12 +178,14 @@ fn get_metadata_section(filename: str) -> option::t<@[u8]> unsafe {
176178
let si = mk_section_iter(of.llof);
177179
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
178180
let name_buf = llvm::LLVMGetSectionName(si.llsi);
179-
let name = str::str_from_cstr(name_buf);
180-
if str::eq(name, x86::get_meta_sect_name()) {
181+
let name = unsafe { str::str_from_cstr(name_buf) };
182+
if str::eq(name, sess.get_targ_cfg().target_strs.meta_sect_name) {
181183
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
182184
let csz = llvm::LLVMGetSectionSize(si.llsi);
183-
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
184-
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
185+
unsafe {
186+
let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
187+
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
188+
}
185189
}
186190
llvm::LLVMMoveToNextSection(si.llsi);
187191
}

trunk/src/comp/middle/trans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5999,7 +5999,7 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
59995999
});
60006000
llvm::LLVMSetInitializer(llglobal, llconst);
60016001
let _: () =
6002-
str::as_buf(x86::get_meta_sect_name(),
6002+
str::as_buf(cx.sess.get_targ_cfg().target_strs.meta_sect_name,
60036003
{|buf| llvm::LLVMSetSection(llglobal, buf) });
60046004
llvm::LLVMSetLinkage(llglobal,
60056005
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
@@ -6031,12 +6031,12 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
60316031
(buf, llvm::LLVMGetGlobalContext())
60326032
});
60336033
let _: () =
6034-
str::as_buf(x86::get_data_layout(),
6034+
str::as_buf(sess.get_targ_cfg().target_strs.data_layout,
60356035
{|buf| llvm::LLVMSetDataLayout(llmod, buf) });
60366036
let _: () =
6037-
str::as_buf(x86::get_target_triple(),
6037+
str::as_buf(sess.get_targ_cfg().target_strs.target_triple,
60386038
{|buf| llvm::LLVMSetTarget(llmod, buf) });
6039-
let td = mk_target_data(x86::get_data_layout());
6039+
let td = mk_target_data(sess.get_targ_cfg().target_strs.data_layout);
60406040
let tn = mk_type_names();
60416041
let intrinsics = declare_intrinsics(llmod);
60426042
let task_type = T_task();

trunk/src/comp/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ mod back {
9393
mod upcall;
9494
mod x86;
9595
mod rpath;
96+
mod target_strs;
9697
}
9798

9899
mod metadata {

0 commit comments

Comments
 (0)