Skip to content

Commit 5150b98

Browse files
crabtwbrson
authored andcommitted
rustc: MIPS32 support
1 parent 0ecd9e0 commit 5150b98

File tree

18 files changed

+164
-11
lines changed

18 files changed

+164
-11
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ DRIVER_CRATE := $(S)src/driver/driver.rs
244244
######################################################################
245245

246246
# FIXME: x86-ism
247-
LLVM_COMPONENTS=x86 arm ipo bitreader bitwriter linker asmparser jit mcjit \
247+
LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
248248
interpreter
249249

250250
define DEF_LLVM_VARS

src/libcore/cleanup.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ struct Registers {
4141
data: [u32 * 16]
4242
}
4343

44+
#[cfg(target_arch="mips")]
45+
struct Registers {
46+
data: [u32 * 32]
47+
}
48+
4449
#[cfg(target_arch="x86")]
4550
#[cfg(target_arch="arm")]
51+
#[cfg(target_arch="mips")]
4652
struct Context {
4753
regs: Registers,
4854
next: *Context,
@@ -69,6 +75,7 @@ struct BoxedRegion {
6975

7076
#[cfg(target_arch="x86")]
7177
#[cfg(target_arch="arm")]
78+
#[cfg(target_arch="mips")]
7279
struct Task {
7380
// Public fields
7481
refcount: intptr_t, // 0

src/libcore/libc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pub mod types {
203203

204204
#[cfg(target_arch = "x86")]
205205
#[cfg(target_arch = "arm")]
206+
#[cfg(target_arch = "mips")]
206207
pub mod arch {
207208
pub mod c95 {
208209
pub type c_char = i8;

src/libcore/num/uint-template/uint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub mod inst {
2828

2929
#[cfg(target_arch = "x86")]
3030
#[cfg(target_arch = "arm")]
31+
#[cfg(target_arch = "mips")]
3132
pub const bits: uint = 32;
3233

3334
#[cfg(target_arch = "x86_64")]

src/libcore/os.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,9 @@ pub mod consts {
10971097
#[cfg(target_arch = "arm")]
10981098
pub use os::consts::arm::*;
10991099
1100+
#[cfg(target_arch = "mips")]
1101+
use os::consts::mips::*;
1102+
11001103
pub mod x86 {
11011104
pub const ARCH: &str = "x86";
11021105
}
@@ -1106,6 +1109,9 @@ pub mod consts {
11061109
pub mod arm {
11071110
pub const ARCH: &str = "arm";
11081111
}
1112+
pub mod mips {
1113+
pub const ARCH: &str = "mips";
1114+
}
11091115
}
11101116
11111117
#[cfg(test)]

src/libcore/path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub pure fn Path(s: &str) -> Path {
9191
mod stat {
9292
#[cfg(target_arch = "x86")]
9393
#[cfg(target_arch = "arm")]
94+
#[cfg(target_arch = "mips")]
9495
pub mod arch {
9596
use libc;
9697

src/libcore/sys.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub mod tests {
166166
#[test]
167167
#[cfg(target_arch = "x86")]
168168
#[cfg(target_arch = "arm")]
169+
#[cfg(target_arch = "mips")]
169170
pub fn size_of_32() {
170171
assert size_of::<uint>() == 4u;
171172
assert size_of::<*uint>() == 4u;
@@ -196,6 +197,7 @@ pub mod tests {
196197
#[test]
197198
#[cfg(target_arch = "x86")]
198199
#[cfg(target_arch = "arm")]
200+
#[cfg(target_arch = "mips")]
199201
pub fn align_of_32() {
200202
assert pref_align_of::<uint>() == 4u;
201203
assert pref_align_of::<*uint>() == 4u;

src/librustc/back/mips.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2012 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+
use back::target_strs;
12+
use driver::session;
13+
use session::sess_os_to_meta_os;
14+
use metadata::loader::meta_section_name;
15+
16+
pub fn get_target_strs(target_os: session::os) -> target_strs::t {
17+
return target_strs::t {
18+
module_asm: ~"",
19+
20+
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
21+
22+
data_layout: match target_os {
23+
session::os_macos => {
24+
~"e-p:32:32:32" +
25+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
26+
~"-f32:32:32-f64:64:64" +
27+
~"-v64:64:64-v128:64:128" +
28+
~"-a0:0:64-n32"
29+
}
30+
31+
session::os_win32 => {
32+
~"e-p:32:32:32" +
33+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
34+
~"-f32:32:32-f64:64:64" +
35+
~"-v64:64:64-v128:64:128" +
36+
~"-a0:0:64-n32"
37+
}
38+
39+
session::os_linux => {
40+
~"e-p:32:32:32" +
41+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
42+
~"-f32:32:32-f64:64:64" +
43+
~"-v64:64:64-v128:64:128" +
44+
~"-a0:0:64-n32"
45+
}
46+
47+
session::os_android => {
48+
~"e-p:32:32:32" +
49+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
50+
~"-f32:32:32-f64:64:64" +
51+
~"-v64:64:64-v128:64:128" +
52+
~"-a0:0:64-n32"
53+
}
54+
55+
session::os_freebsd => {
56+
~"e-p:32:32:32" +
57+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
58+
~"-f32:32:32-f64:64:64" +
59+
~"-v64:64:64-v128:64:128" +
60+
~"-a0:0:64-n32"
61+
}
62+
},
63+
64+
target_triple: match target_os {
65+
session::os_macos => ~"mips-apple-darwin",
66+
session::os_win32 => ~"mips-pc-mingw32",
67+
session::os_linux => ~"mips-unknown-linux-gnu",
68+
session::os_android => ~"mips-unknown-android-gnu",
69+
session::os_freebsd => ~"mips-unknown-freebsd"
70+
},
71+
72+
cc_args: ~[]
73+
};
74+
}
75+
76+
77+
//
78+
// Local Variables:
79+
// mode: rust
80+
// fill-column: 78;
81+
// indent-tabs-mode: nil
82+
// c-basic-offset: 4
83+
// buffer-file-coding-system: utf-8-unix
84+
// End:
85+
//

src/librustc/driver/driver.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use core::prelude::*;
1212

1313
use back::link;
14-
use back::{arm, x86, x86_64};
14+
use back::{arm, x86, x86_64, mips};
1515
use driver::session::{Aggressive};
1616
use driver::session::{Session, Session_, OptLevel, No, Less, Default};
1717
use driver::session;
@@ -94,7 +94,8 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
9494
let (end,arch,wordsz) = match sess.targ_cfg.arch {
9595
session::arch_x86 => (~"little",~"x86",~"32"),
9696
session::arch_x86_64 => (~"little",~"x86_64",~"64"),
97-
session::arch_arm => (~"little",~"arm",~"32")
97+
session::arch_arm => (~"little",~"arm",~"32"),
98+
session::arch_mips => (~"little",~"arm",~"32")
9899
};
99100

100101
return ~[ // Target bindings.
@@ -472,6 +473,8 @@ pub fn get_arch(triple: ~str) -> Option<session::arch> {
472473
} else if str::contains(triple, ~"arm") ||
473474
str::contains(triple, ~"xscale") {
474475
Some(session::arch_arm)
476+
} else if str::contains(triple, ~"mips") {
477+
Some(session::arch_mips)
475478
} else { None }
476479
}
477480

@@ -490,12 +493,14 @@ pub fn build_target_config(sopts: @session::options,
490493
let (int_type, uint_type, float_type) = match arch {
491494
session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
492495
session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
493-
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
496+
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
497+
session::arch_mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
494498
};
495499
let target_strs = match arch {
496500
session::arch_x86 => x86::get_target_strs(os),
497501
session::arch_x86_64 => x86_64::get_target_strs(os),
498-
session::arch_arm => arm::get_target_strs(os)
502+
session::arch_arm => arm::get_target_strs(os),
503+
session::arch_mips => mips::get_target_strs(os)
499504
};
500505
let target_cfg = @session::config {
501506
os: os,

src/librustc/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use syntax;
3333
pub enum os { os_win32, os_macos, os_linux, os_android, os_freebsd, }
3434

3535
#[deriving_eq]
36-
pub enum arch { arch_x86, arch_x86_64, arch_arm, }
36+
pub enum arch { arch_x86, arch_x86_64, arch_arm, arch_mips, }
3737

3838
pub enum crate_type { bin_crate, lib_crate, unknown_crate, }
3939

0 commit comments

Comments
 (0)