Skip to content

Commit 9a617f4

Browse files
committed
[WIP]
1 parent 396f022 commit 9a617f4

File tree

5 files changed

+19
-111
lines changed

5 files changed

+19
-111
lines changed

build_sysroot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ alloc_system = { path = "./alloc_system" }
1414
[patch.crates-io]
1515
rustc-std-workspace-core = { path = "./sysroot_src/src/tools/rustc-std-workspace-core" }
1616
rustc-std-workspace-alloc = { path = "./rustc-std-workspace-alloc" }
17-
compiler_builtins = { path = "./compiler_builtins" }
17+
#compiler_builtins = { path = "./compiler_builtins" }
1818

1919
[profile.release]
2020
debug = true

example/mini_core_hello_world.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,5 @@ fn take_f32(_f: f32) {}
118118
fn take_unique(_u: Unique<()>) {}
119119

120120
fn main() {
121-
assert_eq!((1u128 + 2) as u16, 3);
121+
122122
}

example/std_example.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,7 @@
33
use std::io::Write;
44

55
fn main() {
6-
let _ = ::std::iter::repeat('a' as u8).take(10).collect::<Vec<_>>();
7-
let stderr = ::std::io::stderr();
8-
let mut stderr = stderr.lock();
9-
10-
writeln!(stderr, "some {} text", "<unknown>").unwrap();
11-
12-
let _ = std::process::Command::new("true").env("c", "d").spawn();
13-
14-
println!("cargo:rustc-link-lib=z");
15-
16-
static ONCE: std::sync::Once = std::sync::ONCE_INIT;
17-
ONCE.call_once(|| {});
18-
19-
LoopState::Continue(()) == LoopState::Break(());
20-
21-
// Make sure ByValPair values with differently sized components are correctly passed
22-
map(None::<(u8, Box<Instruction>)>);
23-
24-
println!("{}", 2.3f32.exp());
25-
println!("{}", 2.3f32.exp2());
26-
println!("{}", 2.3f32.abs());
27-
println!("{}", 2.3f32.sqrt());
28-
println!("{}", 2.3f32.floor());
29-
println!("{}", 2.3f32.ceil());
30-
println!("{}", 2.3f32.min(1.0));
31-
println!("{}", 2.3f32.max(1.0));
6+
assert_eq!((1u128 + 2) as u16, 3);
327
}
338

349
#[derive(PartialEq)]

src/base.rs

+6-82
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,6 @@ pub fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
1111

1212
let mir = tcx.instance_mir(instance.def);
1313

14-
// Check fn sig for u128 and i128 and replace those functions with a trap.
15-
{
16-
// FIXME implement u128 and i128 support
17-
18-
// Check sig for u128 and i128
19-
let fn_sig = tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &instance.fn_sig(tcx));
20-
21-
struct UI128Visitor<'tcx>(TyCtxt<'tcx>, bool);
22-
23-
impl<'tcx> rustc::ty::fold::TypeVisitor<'tcx> for UI128Visitor<'tcx> {
24-
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
25-
if t.sty == self.0.types.u128.sty || t.sty == self.0.types.i128.sty {
26-
self.1 = true;
27-
return false; // stop visiting
28-
}
29-
30-
t.super_visit_with(self)
31-
}
32-
}
33-
34-
let mut visitor = UI128Visitor(tcx, false);
35-
fn_sig.visit_with(&mut visitor);
36-
37-
//If found replace function with a trap.
38-
if visitor.1 {
39-
tcx.sess.warn("u128 and i128 are not yet supported. \
40-
Functions using these as args will be replaced with a trap.");
41-
42-
// Declare function with fake signature
43-
let sig = Signature {
44-
params: vec![AbiParam::new(types::INVALID)],
45-
returns: vec![],
46-
call_conv: CallConv::Fast,
47-
};
48-
let name = tcx.symbol_name(instance).as_str();
49-
let func_id = cx.module.declare_function(&*name, linkage, &sig).unwrap();
50-
51-
// Create trapping function
52-
let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
53-
let mut func_ctx = FunctionBuilderContext::new();
54-
let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx);
55-
let start_ebb = bcx.create_ebb();
56-
bcx.append_ebb_params_for_function_params(start_ebb);
57-
bcx.switch_to_block(start_ebb);
58-
59-
let mut fx = FunctionCx {
60-
tcx,
61-
module: cx.module,
62-
pointer_type: pointer_ty(tcx),
63-
64-
instance,
65-
mir,
66-
67-
bcx,
68-
ebb_map: HashMap::new(),
69-
local_map: HashMap::new(),
70-
71-
clif_comments: crate::pretty_clif::CommentWriter::new(tcx, instance),
72-
constants: &mut cx.ccx,
73-
caches: &mut cx.caches,
74-
source_info_set: indexmap::IndexSet::new(),
75-
};
76-
77-
crate::trap::trap_unreachable(&mut fx, "[unimplemented] Called function with u128 or i128 as argument.");
78-
fx.bcx.seal_all_blocks();
79-
fx.bcx.finalize();
80-
81-
// Define function
82-
cx.caches.context.func = func;
83-
cx.module
84-
.define_function(func_id, &mut cx.caches.context)
85-
.unwrap();
86-
cx.caches.context.clear();
87-
return;
88-
}
89-
}
90-
9114
// Declare function
9215
let (name, sig) = get_function_name_and_sig(tcx, instance, false);
9316
let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
@@ -391,7 +314,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
391314
let rhs = trans_operand(fx, rhs);
392315

393316
let res = match ty.sty {
394-
ty::Bool => trans_bool_binop(fx, *bin_op, lhs, rhs, lval.layout().ty),
317+
ty::Bool => trans_bool_binop(fx, *bin_op, lhs, rhs),
395318
ty::Uint(_) => {
396319
trans_int_binop(fx, *bin_op, lhs, rhs, lval.layout().ty, false)
397320
}
@@ -656,7 +579,9 @@ fn trans_stmt<'a, 'tcx: 'a>(
656579
| StatementKind::Retag { .. }
657580
| StatementKind::AscribeUserType(..) => {}
658581

659-
StatementKind::InlineAsm { .. } => unimpl!("Inline assembly is not supported"),
582+
StatementKind::InlineAsm { .. } => {
583+
crate::trap::trap_panic(fx, "Inline assembly is not supported");
584+
}
660585
}
661586
}
662587

@@ -805,10 +730,9 @@ fn trans_bool_binop<'a, 'tcx: 'a>(
805730
bin_op: BinOp,
806731
lhs: CValue<'tcx>,
807732
rhs: CValue<'tcx>,
808-
ty: Ty<'tcx>,
809733
) -> CValue<'tcx> {
810734
let res = binop_match! {
811-
fx, bin_op, false, lhs, rhs, ty, "bool";
735+
fx, bin_op, false, lhs, rhs, fx.tcx.types.bool, "bool";
812736
Add (_) bug;
813737
Sub (_) bug;
814738
Mul (_) bug;
@@ -849,7 +773,7 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(
849773
);
850774
}
851775

852-
if out_ty == fx.tcx.types.u128 || out_ty == fx.tcx.types.i128 {
776+
if lhs.layout().ty == fx.tcx.types.u128 || lhs.layout().ty == fx.tcx.types.i128 {
853777
return match (bin_op, signed) {
854778
_ => {
855779
let layout = fx.layout_of(out_ty);

src/common.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,23 @@ pub fn clif_intcast<'a, 'tcx: 'a>(
8282
if from == to {
8383
return val;
8484
}
85+
if to == types::I128 {
86+
let wider = if signed {
87+
fx.bcx.ins().sextend(types::I64, val)
88+
} else {
89+
fx.bcx.ins().uextend(types::I64, val)
90+
};
91+
let zero = fx.bcx.ins().iconst(types::I64, 0);
92+
return fx.bcx.ins().iconcat(wider, zero);
93+
}
8594
if to.wider_or_equal(from) {
8695
if signed {
8796
fx.bcx.ins().sextend(to, val)
8897
} else {
8998
fx.bcx.ins().uextend(to, val)
9099
}
91100
} else if from == types::I128 {
92-
let (lsb, msb) = fx.bcx.ins().isplit(val);
101+
let (lsb, _msb) = fx.bcx.ins().isplit(val);
93102
fx.bcx.ins().ireduce(to, lsb)
94103
} else {
95104
fx.bcx.ins().ireduce(to, val)

0 commit comments

Comments
 (0)