litex/infer/
infer_result.rs1use crate::prelude::*;
2use std::collections::HashSet;
3
4#[derive(Clone, Debug)]
5pub struct InferResult {
6 infer_facts: Vec<String>,
8 facts: Vec<Fact>,
10}
11
12impl InferResult {
13 pub fn new() -> Self {
14 InferResult {
15 infer_facts: vec![],
16 facts: vec![],
17 }
18 }
19
20 pub fn from_fact(fact: &Fact) -> Self {
22 let mut r = Self::new();
23 r.new_fact(fact);
24 r
25 }
26
27 pub fn is_empty(&self) -> bool {
28 self.infer_facts.is_empty() && self.facts.is_empty()
29 }
30
31 pub fn infer_lines(&self) -> &[String] {
33 &self.infer_facts
34 }
35
36 pub fn infer_lines_unique_in_order(&self) -> Vec<String> {
38 let mut seen = HashSet::new();
39 self.infer_facts
40 .iter()
41 .filter(|s| seen.insert((*s).clone()))
42 .cloned()
43 .collect()
44 }
45
46 pub fn inferred_facts(&self) -> &[Fact] {
48 &self.facts
49 }
50
51 pub fn join_infer_lines(&self, sep: &str) -> String {
52 self.infer_facts.join(sep)
53 }
54
55 pub fn new_with_msg(&mut self, msg: String) {
56 self.infer_facts.push(msg);
57 }
58
59 pub fn new_fact(&mut self, fact: &Fact) {
60 self.infer_facts.push(fact.to_string());
61 self.facts.push(fact.clone());
62 }
63
64 pub fn push_atomic_fact(&mut self, atomic_fact: &AtomicFact) {
65 self.infer_facts.push(atomic_fact.to_string());
66 self.facts.push(atomic_fact.clone().into());
67 }
68
69 pub fn new_infer_result_inside(&mut self, other_infer_result: InferResult) {
70 self.infer_facts.extend(other_infer_result.infer_facts);
71 self.facts.extend(other_infer_result.facts);
72 }
73}