}
pub fn declare_global_with_linkage(&self, name: &str, ty: Type<'gcc>, linkage: GlobalKind) -> RValue<'gcc> {
- //debug!("declare_global_with_linkage(name={:?})", name);
let global = self.context.new_global(None, linkage, ty, name)
.get_address(None);
self.globals.borrow_mut().insert(name.to_string(), global);
pub fn declare_func(&self, name: &str, return_type: Type<'gcc>, params: &[Type<'gcc>], variadic: bool) -> RValue<'gcc> {
self.linkage.set(FunctionType::Exported);
let func = declare_raw_fn(self, name, () /*llvm::CCallConv*/, return_type, params, variadic);
- // FIXME: this is a wrong cast. That requires changing the compiler API.
+ // FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
unsafe { std::mem::transmute(func) }
}
pub fn declare_global(&self, name: &str, ty: Type<'gcc>, is_tls: bool, link_section: Option<Symbol>) -> RValue<'gcc> {
- //debug!("declare_global(name={:?})", name);
- // FIXME: correctly support global variable initialization.
+ // FIXME(antoyo): correctly support global variable initialization.
if name.starts_with(ARGV_INIT_ARRAY) {
// NOTE: hack to avoid having to update the names in mangled_std_symbols: we save the
// name of the variable now to actually declare it later.
}
pub fn declare_cfn(&self, name: &str, _fn_type: Type<'gcc>) -> RValue<'gcc> {
- // TODO: use the fn_type parameter.
+ // TODO(antoyo): use the fn_type parameter.
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
let return_type = self.type_i32();
let variadic = false;
// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
// for the main function.
*self.current_func.borrow_mut() = Some(func);
- // FIXME: this is a wrong cast. That requires changing the compiler API.
+ // FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
unsafe { std::mem::transmute(func) }
}
self.global_names.borrow_mut().insert(global, global_name.to_string());
self.argv_initialized.set(true);
}
- //debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi);
let (return_type, params, variadic) = fn_abi.gcc_type(self);
let func = declare_raw_fn(self, name, () /*fn_abi.llvm_cconv()*/, return_type, ¶ms, variadic);
- //fn_abi.apply_attrs_llfn(self, func);
- // FIXME: this is a wrong cast. That requires changing the compiler API.
+ // FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
unsafe { std::mem::transmute(func) }
}
}
pub fn get_declared_value(&self, name: &str) -> Option<RValue<'gcc>> {
- //debug!("get_declared_value(name={:?})", name);
- // TODO: use a different field than globals, because this seems to return a function?
+ // TODO(antoyo): use a different field than globals, because this seems to return a function?
self.globals.borrow().get(name).cloned()
}
-
- /*fn get_defined_value(&self, name: &str) -> Option<RValue<'gcc>> {
- // TODO: gcc does not allow global initialization.
- None
- /*self.get_declared_value(name).and_then(|val| {
- let declaration = unsafe { llvm::LLVMIsDeclaration(val) != 0 };
- if !declaration { Some(val) } else { None }
- })*/
- }*/
}
/// Declare a function.
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing Value instead.
fn declare_raw_fn<'gcc>(cx: &CodegenCx<'gcc, '_>, name: &str, _callconv: () /*llvm::CallConv*/, return_type: Type<'gcc>, param_types: &[Type<'gcc>], variadic: bool) -> Function<'gcc> {
- //debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
- /*let llfn = unsafe {
- llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_ptr().cast(), name.len(), ty)
- };*/
-
if name.starts_with("llvm.") {
return llvm::intrinsic(name, cx);
}
}
else {
let params: Vec<_> = param_types.into_iter().enumerate()
- .map(|(index, param)| cx.context.new_parameter(None, *param, &format!("param{}", index))) // TODO: set name.
+ .map(|(index, param)| cx.context.new_parameter(None, *param, &format!("param{}", index))) // TODO(antoyo): set name.
.collect();
let func = cx.context.new_function(None, cx.linkage.get(), return_type, ¶ms, mangle_name(name), variadic);
cx.functions.borrow_mut().insert(name.to_string(), func);
func
};
- //llvm::SetFunctionCallConv(llfn, callconv); // TODO
- // Function addresses in Rust are never significant, allowing functions to
- // be merged.
- //llvm::SetUnnamedAddress(llfn, llvm::UnnamedAddr::Global); // TODO
-
- /*if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.target.options.disable_redzone) {
- llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);
- }*/
-
- //attributes::default_optimisation_attrs(cx.tcx.sess, llfn);
- //attributes::non_lazy_bind(cx.sess(), llfn);
+ // TODO(antoyo): set function calling convention.
+ // TODO(antoyo): set unnamed address.
+ // TODO(antoyo): set no red zone function attribute.
+ // TODO(antoyo): set attributes for optimisation.
+ // TODO(antoyo): set attributes for non lazy bind.
- // FIXME: invalid cast.
- // TODO: is this line useful?
- //cx.globals.borrow_mut().insert(name.to_string(), unsafe { std::mem::transmute(func) });
+ // FIXME(antoyo): invalid cast.
func
}
-// FIXME: this is a hack because libgccjit currently only supports alpha, num and _.
+// FIXME(antoyo): this is a hack because libgccjit currently only supports alpha, num and _.
// Unsupported characters: `$` and `.`.
pub fn mangle_name(name: &str) -> String {
name.replace(|char: char| {