nextpnr/common/route/awooter/rust/src/lib.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2022-11-20 11:20:09 +08:00
use std::ptr::NonNull;
#[macro_use]
mod npnr;
2022-11-21 10:48:00 +08:00
enum Subpartition {
Part(Box<Partition>),
Nets(Vec<Net>),
}
struct Partition {
parts: [Option<Subpartition>; 4],
borders: [[Vec<npnr::WireId>; 4]; 4]
}
struct Net {
source: npnr::WireId,
sinks: Vec<npnr::WireId>
}
2022-11-20 11:20:09 +08:00
#[no_mangle]
pub extern "C" fn npnr_router_awooter(ctx: Option<NonNull<npnr::Context>>) -> bool {
std::panic::catch_unwind(move || {
let ctx: &mut npnr::Context = unsafe { ctx.expect("non-null context").as_mut() };
route(ctx)
})
.unwrap_or_else(|x| {
if let Ok(x) = x.downcast::<String>() {
log_error!("caught panic: {}", x);
}
false
})
}
fn route(ctx: &mut npnr::Context) -> bool {
log_info!("Hello from Rust!\n");
log_info!(
"Running on a {}x{} grid\n",
ctx.grid_dim_x(),
ctx.grid_dim_y()
);
2022-11-21 10:48:00 +08:00
let _belid = npnr::BelId::null();
2022-11-20 11:20:09 +08:00
log_info!("Managed to survive BelId()\n");
2022-11-21 10:48:00 +08:00
let nets = npnr::NetIter::new(ctx).into_iter().collect::<Vec<_>>();
log_info!("Found {} nets\n", nets.len());
2022-11-20 11:20:09 +08:00
true
}