Skip to content

transpile: simplify dynamic argument parsing #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions c2rust-transpile/src/translator/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,16 +646,9 @@ impl<'c> Translation<'c> {
) -> TranslationResult<WithStmts<Box<Expr>>> {
let args = self.convert_exprs(ctx.used(), args)?;
args.and_then(|args| {
let mut args = args.into_iter();
let a = args
.next()
.ok_or("Missing first argument to convert_overflow_arith")?;
let b = args
.next()
.ok_or("Missing second argument to convert_overflow_arith")?;
let c = args
.next()
.ok_or("Missing third argument to convert_overflow_arith")?;
let [a, b, c]: [_; 3] = args
.try_into()
.map_err(|_| "`convert_overflow_arith` must have exactly 3 arguments")?;
let overflowing = mk().method_call_expr(a, method_name, vec![b]);
let sum_name = self.renamer.borrow_mut().fresh();
let over_name = self.renamer.borrow_mut().fresh();
Expand Down Expand Up @@ -691,16 +684,9 @@ impl<'c> Translation<'c> {
let mem = mk().path_expr(vec!["libc", name]);
let args = self.convert_exprs(ctx.used(), args)?;
args.and_then(|args| {
let mut args = args.into_iter();
let dst = args
.next()
.ok_or("Missing dst argument to convert_libc_fns")?;
let c = args
.next()
.ok_or("Missing c argument to convert_libc_fns")?;
let len = args
.next()
.ok_or("Missing len argument to convert_libc_fns")?;
let [dst, c, len]: [_; 3] = args
.try_into()
.map_err(|_| "`convert_libc_fns` must have exactly 3 arguments: [dst, c, len]")?;
let size_t = mk().path_ty(vec!["libc", "size_t"]);
let len1 = mk().cast_expr(len, size_t);
let mem_expr = mk().call_expr(mem, vec![dst, c, len1]);
Expand Down
13 changes: 3 additions & 10 deletions c2rust-transpile/src/translator/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,9 @@ impl<'c> Translation<'c> {
let param_translation =
self.convert_exprs(ctx.used(), &[first_expr_id, second_expr_id, mask_expr_id])?;
param_translation.and_then(|params| {
let mut params = params.into_iter();
let first = params
.next()
.ok_or("Missing first param in convert_shuffle_vector")?;
let second = params
.next()
.ok_or("Missing second param in convert_shuffle_vector")?;
let third = params
.next()
.ok_or("Missing third param in convert_shuffle_vector")?;
let [first, second, third]: [_; 3] = params
.try_into()
.map_err(|_| "`convert_shuffle_vector` must have exactly 3 parameters")?;
let mut new_params = vec![first];

// Some don't take a second param, but the expr is still there for some reason
Expand Down