From 7f8adccb5056152edc4aacf08ce2ed040f076171 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 27 Jul 2021 14:33:52 +0100 Subject: Add support for varadic extern "c" functions like printf Varadic functions are only allowed in extern functions as far as I know. --- gcc/rust/backend/rust-compile-context.h | 11 ++++++++--- gcc/rust/backend/rust-compile-extern.h | 6 ++---- gcc/rust/backend/rust-compile-tyty.h | 12 +++++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index bb4f0ab..0aaf084 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -371,9 +371,14 @@ public: parameters.push_back (compiled_param); } - translated = ctx->get_backend ()->function_type ( - receiver, parameters, results, NULL, - ctx->get_mappings ()->lookup_location (type.get_ref ())); + if (!type.is_varadic ()) + translated = ctx->get_backend ()->function_type ( + receiver, parameters, results, NULL, + ctx->get_mappings ()->lookup_location (type.get_ref ())); + else + translated = ctx->get_backend ()->function_type_varadic ( + receiver, parameters, results, NULL, + ctx->get_mappings ()->lookup_location (type.get_ref ())); } void visit (TyTy::FnPtr &type) override diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index 1eba011..a0ad200 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -51,10 +51,8 @@ public: rust_assert (ok); std::string name = item.get_item_name (); - - // FIXME - // this is assuming C ABI - std::string asm_name = "_" + name; + // FIXME this is assuming C ABI + std::string asm_name = name; Btype *type = TyTyResolveCompile::compile (ctx, resolved_type); bool is_external = true; diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 2d0856d..3ddc29a 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -95,9 +95,15 @@ public: parameters.push_back (compiled_param); } - translated - = backend->function_type (receiver, parameters, results, NULL, - mappings->lookup_location (type.get_ref ())); + if (!type.is_varadic ()) + translated + = backend->function_type (receiver, parameters, results, NULL, + mappings->lookup_location (type.get_ref ())); + else + translated + = backend->function_type_varadic (receiver, parameters, results, NULL, + mappings->lookup_location ( + type.get_ref ())); } void visit (TyTy::BoolType &) override -- cgit v1.1