Skip to content

Commit 0443c3a

Browse files
committed
Use more of the new reflection API
1 parent 729ecd9 commit 0443c3a

File tree

8 files changed

+44
-55
lines changed

8 files changed

+44
-55
lines changed

gcc_path

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/tmp/gcc-build/build/gcc
1+
/home/bouanto/Ordinateur/Programmation/Projets/gcc-build/build/gcc

src/abi.rs

-4
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
162162
fn ptr_to_gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
163163
let (return_type, params, variadic) = self.gcc_type(cx);
164164
let pointer_type = cx.context.new_function_pointer_type(None, return_type, &params, variadic);
165-
cx.function_type_param_return_value.borrow_mut().insert(pointer_type, FuncSig {
166-
params,
167-
return_type,
168-
});
169165
pointer_type
170166
}
171167

src/builder.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ impl<'gcc, 'tcx> Builder<'_, 'gcc, 'tcx> {
154154

155155
let mut all_args_match = true;
156156
let mut param_types = vec![];
157-
let func_types = self.cx.function_type_param_return_value.borrow();
158-
let ptr: *mut usize = unsafe { std::mem::transmute(func.get_type()) };
159-
let func_sig = func_types.get(&func.get_type())
160-
.unwrap_or_else(|| panic!("No function_type_param_return_value for {:?}", func.get_type()));
161-
for (index, arg) in args.iter().enumerate().take(func_sig.params.len()) {
162-
let param = func_sig.params[index];
157+
let gcc_func: Function<'gcc> = self.cx.rvalue_as_function(func);
158+
for (index, arg) in args.iter().enumerate().take(gcc_func.get_param_count()) {
159+
let param = gcc_func.get_param(index as i32).to_rvalue().get_type();
163160
if param != arg.get_type() {
164161
all_args_match = false;
165162
}
@@ -265,9 +262,8 @@ impl<'gcc, 'tcx> Builder<'_, 'gcc, 'tcx> {
265262

266263
// gccjit requires to use the result of functions, even when it's not used.
267264
// That's why we assign the result to a local or call add_eval().
268-
let return_type = self.function_type_param_return_value.borrow().get(&func.get_type())
269-
.map(|func_sig| func_sig.return_type)
270-
.unwrap_or_else(|| panic!("No return type for {:?}", func));
265+
let gcc_func: Function<'gcc> = self.cx.rvalue_as_function(func);
266+
let return_type = gcc_func.get_return_type();
271267
let current_block = self.current_block.borrow().expect("block");
272268
let void_type = self.context.new_type::<()>();
273269
let current_func = current_block.get_function();
@@ -764,10 +760,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
764760
else if let Some(fields) = type_fields {
765761
self.fields.borrow_mut().insert(aligned_type, fields);
766762
}
767-
else if self.function_type_param_return_value.borrow().contains_key(&ty) {
768-
let func_sig = self.function_type_param_return_value.borrow().get(&ty).expect("function sig").clone();
769-
self.function_type_param_return_value.borrow_mut().insert(aligned_type, func_sig);
770-
}
771763

772764
// TODO: It might be better to return a LValue, but fixing the rustc API is non-trivial.
773765
self.current_func().new_local(None, aligned_type, "stack_var").get_address(None)

src/common.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -336,70 +336,70 @@ pub trait TypeReflection<'gcc, 'tcx> {
336336

337337
impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
338338
fn is_uchar(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
339-
self.get_original() == cx.u8_type
339+
self.unqualified() == cx.u8_type
340340
}
341341

342342
fn is_ushort(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
343-
self.get_original() == cx.u16_type
343+
self.unqualified() == cx.u16_type
344344
}
345345

346346
fn is_uint(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
347-
self.get_original() == cx.uint_type
347+
self.unqualified() == cx.uint_type
348348
}
349349

350350
fn is_ulong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
351-
self.get_original() == cx.ulong_type
351+
self.unqualified() == cx.ulong_type
352352
}
353353

354354
fn is_ulonglong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
355-
self.get_original() == cx.ulonglong_type
355+
self.unqualified() == cx.ulonglong_type
356356
}
357357

358358
fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
359-
self.get_original() == cx.i8_type
359+
self.unqualified() == cx.i8_type
360360
}
361361

362362
fn is_u8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
363-
self.get_original() == cx.u8_type
363+
self.unqualified() == cx.u8_type
364364
}
365365

366366
fn is_i16(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
367-
self.get_original() == cx.i16_type
367+
self.unqualified() == cx.i16_type
368368
}
369369

370370
fn is_u16(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
371-
self.get_original() == cx.u16_type
371+
self.unqualified() == cx.u16_type
372372
}
373373

374374
fn is_i32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
375-
self.get_original() == cx.i32_type
375+
self.unqualified() == cx.i32_type
376376
}
377377

378378
fn is_u32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
379-
self.get_original() == cx.u32_type
379+
self.unqualified() == cx.u32_type
380380
}
381381

382382
fn is_i64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
383-
self.get_original() == cx.i64_type
383+
self.unqualified() == cx.i64_type
384384
}
385385

386386
fn is_u64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
387-
self.get_original() == cx.u64_type
387+
self.unqualified() == cx.u64_type
388388
}
389389

390390
fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
391-
self.get_original() == cx.i128_type
391+
self.unqualified() == cx.i128_type
392392
}
393393

394394
fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
395-
self.get_original() == cx.u128_type
395+
self.unqualified() == cx.u128_type
396396
}
397397

398398
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
399-
self.get_original() == cx.context.new_type::<f32>()
399+
self.unqualified() == cx.context.new_type::<f32>()
400400
}
401401

402402
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
403-
self.get_original() == cx.context.new_type::<f64>()
403+
self.unqualified() == cx.context.new_type::<f64>()
404404
}
405405
}

src/context.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub struct CodegenCx<'gcc, 'tcx> {
4949
// TODO: First set it to a dummy block to avoid using Option?
5050
pub current_block: RefCell<Option<Block<'gcc>>>,
5151
pub current_func: RefCell<Option<Function<'gcc>>>,
52-
pub function_type_param_return_value: RefCell<FxHashMap<Type<'gcc>, FuncSig<'gcc>>>,
5352
pub normal_function_addresses: RefCell<FxHashSet<RValue<'gcc>>>,
5453

5554
/// The function where globals are initialized.
@@ -177,7 +176,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
177176
context,
178177
current_block: RefCell::new(None),
179178
current_func: RefCell::new(None),
180-
function_type_param_return_value: Default::default(),
181179
normal_function_addresses: Default::default(),
182180
functions: RefCell::new(functions),
183181
global_init_func,
@@ -238,7 +236,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
238236
pub fn rvalue_as_function(&self, value: RValue<'gcc>) -> Function<'gcc> {
239237
let function: Function<'gcc> = unsafe { std::mem::transmute(value) };
240238
debug_assert!(self.functions.borrow().values().find(|value| **value == function).is_some(),
241-
"{:?} is not a function", value);
239+
"{:?} ({:?}) is not a function", value, value.get_type());
242240
function
243241
}
244242

@@ -291,10 +289,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
291289
let pointer_type = ptr.get_type();
292290

293291
self.normal_function_addresses.borrow_mut().insert(ptr);
294-
self.function_type_param_return_value.borrow_mut().insert(pointer_type, FuncSig {
295-
params,
296-
return_type,
297-
});
298292

299293
ptr
300294
}

src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
12461246
}
12471247

12481248
fn int_width(&self, typ: Type<'gcc>) -> i64 {
1249-
typ.get_size() as i64 * 8
1249+
self.cx.int_width(typ) as i64
12501250
}
12511251

12521252
fn overflow_intrinsic_call(&mut self, intrinsic: &str, lhs: RValue<'gcc>, rhs: RValue<'gcc>, result: &PlaceRef<'tcx, RValue<'gcc>>) {

src/type_.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
105105
}
106106

107107
fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
108-
let pointer_type = self.context.new_function_pointer_type(None, return_type, params, false);
109-
// TODO: check if necessary.
110-
/*self.function_type_param_return_value.borrow_mut().insert(pointer_type, crate::context::FuncSig {
111-
params: params.to_vec(),
112-
return_type,
113-
});*/
114-
pointer_type
108+
self.context.new_function_pointer_type(None, return_type, params, false)
115109
}
116110

117111
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
@@ -185,7 +179,24 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
185179
}
186180

187181
fn int_width(&self, typ: Type<'gcc>) -> u64 {
188-
typ.get_size() as u64 * 8
182+
if typ.is_i8(self) || typ.is_u8(self) {
183+
8
184+
}
185+
else if typ.is_i16(self) || typ.is_u16(self) {
186+
16
187+
}
188+
else if typ.is_i32(self) || typ.is_u32(self) {
189+
32
190+
}
191+
else if typ.is_i64(self) || typ.is_u64(self) {
192+
64
193+
}
194+
else if typ.is_i128(self) || typ.is_u128(self) {
195+
128
196+
}
197+
else {
198+
panic!("Cannot get width of int type {:?}", typ);
199+
}
189200
}
190201

191202
fn val_ty(&self, value: RValue<'gcc>) -> Type<'gcc> {

src/type_of.rs

-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
177177
// TODO: don't compute the params and return value twice.
178178
let (return_type, params, _) = fn_abi.gcc_type(cx);
179179
let fn_ptr_type = cx.fn_ptr_backend_type(&fn_abi);
180-
cx.function_type_param_return_value.borrow_mut().insert(fn_ptr_type, FuncSig {
181-
params,
182-
return_type,
183-
});
184180
fn_ptr_type
185181
},
186182
_ => self.scalar_gcc_type_at(cx, scalar, Size::ZERO),

0 commit comments

Comments
 (0)