Skip to content

Commit

Permalink
WIP: fix endianness of non-native 128-bit integers
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Oct 19, 2023
1 parent 07f2116 commit 3c34db0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/m68k.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,8 @@ jobs:
- name: Build
run: |
./y.sh prepare --only-libcore
# TODO: move into prepare command under a flag --cross-patches?
pushd build_sysroot/sysroot_src
git am ../../cross_patches/*.patch
popd
./build.sh
./y.sh prepare --only-libcore --cross
./y.sh build
cargo test
./clean_all.sh
Expand Down
12 changes: 8 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};

use crate::callee::get_fn;
use crate::common::SignType;

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

let isize_type = context.new_c_type(CType::Int);
let usize_type = context.new_c_type(CType::UInt);
let usize_type = sizet_type;
let isize_type = usize_type;
let bool_type = context.new_type::<bool>();

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

Self {
let mut cx = Self {
check_overflow,
codegen_unit,
context,
Expand Down Expand Up @@ -274,7 +275,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
pointee_infos: Default::default(),
structs_as_pointer: Default::default(),
cleanup_blocks: Default::default(),
}
};
// TODO(antoyo): instead of doing this, add SsizeT to libgccjit.
cx.isize_type = usize_type.to_signed(&cx);
cx
}

pub fn rvalue_as_function(&self, value: RValue<'gcc>) -> Function<'gcc> {
Expand Down
11 changes: 9 additions & 2 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use gccjit::{ComparisonOp, FunctionType, RValue, ToRValue, Type, UnaryOp, Binary
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeMethods, BuilderMethods, OverflowOp};
use rustc_middle::ty::Ty;
use rustc_target::abi::Endian;

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

fn from_low_high(&self, typ: Type<'gcc>, low: i64, high: i64) -> RValue<'gcc> {
let (first, last) =
match self.sess().target.options.endian {
Endian::Little => (low, high),
Endian::Big => (high, low),
};

let native_int_type = typ.dyncast_array().expect("get element type");
let values = [
self.context.new_rvalue_from_long(native_int_type, low),
self.context.new_rvalue_from_long(native_int_type, high),
self.context.new_rvalue_from_long(native_int_type, first),
self.context.new_rvalue_from_long(native_int_type, last),
];
self.context.new_array_constructor(None, typ, &values)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lang_tests_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn main_inner(profile: Profile) {
}
// Test command 2: run `tempdir/x`.
let vm_parent_dir = "/home/bouanto/Ordinateur/VirtualMachines";
let vm_dir = "debian-m68k-root-img/";
let vm_dir = "debian-m68k-root/";
let exe_filename = exe.file_name().unwrap();
let vm_exe_path = PathBuf::from(vm_parent_dir).join(vm_dir).join("home").join(exe_filename);
// FIXME: panicking here makes the test pass.
Expand Down

0 comments on commit 3c34db0

Please sign in to comment.