Skip to content

Commit 0477b26

Browse files
committed
WIP: fix endianness of non-native 128-bit integers
1 parent 07f2116 commit 0477b26

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

.github/workflows/m68k.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ jobs:
140140
141141
- name: Build
142142
run: |
143-
./y.sh prepare --only-libcore
144-
# TODO: move into prepare command under a flag --cross-patches?
145-
pushd build_sysroot/sysroot_src
146-
git am ../../cross_patches/*.patch
147-
popd
148-
./build.sh
143+
./y.sh prepare --only-libcore --cross
144+
./y.sh build --target m68k-unknown-linux-gnu
149145
cargo test
150146
./clean_all.sh
151147

src/context.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
2020
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
2121

2222
use crate::callee::get_fn;
23+
use crate::common::SignType;
2324

2425
#[derive(Clone)]
2526
pub struct FuncSig<'gcc> {
@@ -187,8 +188,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
187188
let ulonglong_type = context.new_c_type(CType::ULongLong);
188189
let sizet_type = context.new_c_type(CType::SizeT);
189190

190-
let isize_type = context.new_c_type(CType::Int);
191-
let usize_type = context.new_c_type(CType::UInt);
191+
let usize_type = sizet_type;
192+
let isize_type = usize_type;
192193
let bool_type = context.new_type::<bool>();
193194

194195
// TODO(antoyo): only have those assertions on x86_64.
@@ -212,7 +213,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
212213
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));
213214
}
214215

215-
Self {
216+
let mut cx = Self {
216217
check_overflow,
217218
codegen_unit,
218219
context,
@@ -274,7 +275,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
274275
pointee_infos: Default::default(),
275276
structs_as_pointer: Default::default(),
276277
cleanup_blocks: Default::default(),
277-
}
278+
};
279+
// TODO(antoyo): instead of doing this, add SsizeT to libgccjit.
280+
cx.isize_type = usize_type.to_signed(&cx);
281+
cx
278282
}
279283

280284
pub fn rvalue_as_function(&self, value: RValue<'gcc>) -> Function<'gcc> {

src/int.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gccjit::{ComparisonOp, FunctionType, RValue, ToRValue, Type, UnaryOp, Binary
88
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
99
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeMethods, BuilderMethods, OverflowOp};
1010
use rustc_middle::ty::Ty;
11+
use rustc_target::abi::Endian;
1112

1213
use crate::builder::ToGccComp;
1314
use crate::{builder::Builder, common::{SignType, TypeReflection}, context::CodegenCx};
@@ -792,10 +793,16 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
792793
}
793794

794795
fn from_low_high(&self, typ: Type<'gcc>, low: i64, high: i64) -> RValue<'gcc> {
796+
let (first, last) =
797+
match self.sess().target.options.endian {
798+
Endian::Little => (low, high),
799+
Endian::Big => (high, low),
800+
};
801+
795802
let native_int_type = typ.dyncast_array().expect("get element type");
796803
let values = [
797-
self.context.new_rvalue_from_long(native_int_type, low),
798-
self.context.new_rvalue_from_long(native_int_type, high),
804+
self.context.new_rvalue_from_long(native_int_type, first),
805+
self.context.new_rvalue_from_long(native_int_type, last),
799806
];
800807
self.context.new_array_constructor(None, typ, &values)
801808
}

tests/lang_tests_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn main_inner(profile: Profile) {
7474
}
7575
// Test command 2: run `tempdir/x`.
7676
let vm_parent_dir = "/home/bouanto/Ordinateur/VirtualMachines";
77-
let vm_dir = "debian-m68k-root-img/";
77+
let vm_dir = "debian-m68k-root/";
7878
let exe_filename = exe.file_name().unwrap();
7979
let vm_exe_path = PathBuf::from(vm_parent_dir).join(vm_dir).join("home").join(exe_filename);
8080
// FIXME: panicking here makes the test pass.

0 commit comments

Comments
 (0)