Skip to content

Commit

Permalink
Add missing expression types to bpf generation
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Jun 3, 2024
1 parent 6c8d53d commit 8e45e25
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cir/src/bin/commands/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ pub fn keymap(args: &crate::Keymap) {

if let Some(delay) = args.delay {
repeat.delay = delay;

log::debug!("updating autorepeat to delay:{}", delay);
}

if let Some(period) = args.period {
repeat.period = period;

log::debug!("updating autorepeat to period:{}", period);
}

if let Err(e) = inputdev.update_auto_repeat(&repeat) {
Expand Down
114 changes: 113 additions & 1 deletion irp/src/build_bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,119 @@ impl<'a> Builder<'a> {
unimplemented!("{expr}")
}
}
Expression::Or(left, right) => {
let left = self.expression(left, context);

let entry = self.builder.get_insert_block().unwrap();

let non_zero = self
.builder
.build_int_compare(
IntPredicate::NE,
left,
context.i64_type().const_zero(),
"non_zero",
)
.unwrap();

let eval_right = context.append_basic_block(self.function, "eval_right");
let done = context.append_basic_block(self.function, "done");

self.builder
.build_conditional_branch(non_zero, eval_right, done)
.unwrap();

self.builder.position_at_end(eval_right);

let right = self.expression(right, context);

self.builder.build_unconditional_branch(done).unwrap();

self.builder.position_at_end(done);

let res = self.builder.build_phi(context.i64_type(), "res").unwrap();

res.add_incoming(&[(&left, entry), (&right, eval_right)]);

res.as_basic_value().into_int_value()
}
Expression::And(left, right) => {
let left = self.expression(left, context);

let entry = self.builder.get_insert_block().unwrap();

let zero = self
.builder
.build_int_compare(
IntPredicate::EQ,
left,
context.i64_type().const_zero(),
"non_zero",
)
.unwrap();

let eval_right = context.append_basic_block(self.function, "eval_right");
let done = context.append_basic_block(self.function, "done");

self.builder
.build_conditional_branch(zero, eval_right, done)
.unwrap();

self.builder.position_at_end(eval_right);

let right = self.expression(right, context);

self.builder.build_unconditional_branch(done).unwrap();

self.builder.position_at_end(done);

let res = self.builder.build_phi(context.i64_type(), "res").unwrap();

res.add_incoming(&[(&left, entry), (&right, eval_right)]);

res.as_basic_value().into_int_value()
}
Expression::Conditional(cond, left, right) => {
let cond = self.expression(cond, context);

let non_zero = self
.builder
.build_int_compare(
IntPredicate::NE,
cond,
context.i64_type().const_zero(),
"non_zero",
)
.unwrap();

let eval_left = context.append_basic_block(self.function, "eval_left");
let eval_right = context.append_basic_block(self.function, "eval_right");
let done = context.append_basic_block(self.function, "done");

self.builder
.build_conditional_branch(non_zero, eval_left, eval_right)
.unwrap();

self.builder.position_at_end(eval_left);

let left = self.expression(left, context);

self.builder.build_unconditional_branch(done).unwrap();

self.builder.position_at_end(eval_right);

let right = self.expression(right, context);

self.builder.position_at_end(done);

self.builder.build_unconditional_branch(done).unwrap();

let res = self.builder.build_phi(context.i64_type(), "res").unwrap();

res.add_incoming(&[(&left, eval_left), (&right, eval_right)]);

res.as_basic_value().into_int_value()
}
Expression::FlashConstant(..)
| Expression::FlashIdentifier(..)
| Expression::GapConstant(..)
Expand All @@ -990,7 +1103,6 @@ impl<'a> Builder<'a> {
| Expression::List(..)
| Expression::Variation(..)
| Expression::Stream(..) => unreachable!(),
_ => unimplemented!("{expr}"),
}
}

Expand Down

0 comments on commit 8e45e25

Please sign in to comment.