-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlir.rs
More file actions
70 lines (56 loc) · 1.81 KB
/
lir.rs
File metadata and controls
70 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::io::Write;
use serde::{Deserialize, Serialize};
use zip::{write::FileOptions, ZipWriter};
use crate::MirNodeId;
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct LirNodeId(String);
impl LirNodeId {
pub fn new(id: &str) -> Self {
Self(id.to_string())
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct LirStreamId(usize);
impl LirStreamId {
pub fn new(id: usize) -> Self {
Self(id)
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct LirNode {
pub id: LirNodeId,
/// Node type, e.g., map, join, etc.
pub operation: String,
/// The list of Mir node ids that this LIR node implementa completely or partially.
#[serde(default)]
pub implements: Vec<MirNodeId>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct LirEdge {
/// Stream id if this edge is a stream edge. None if this is a dependency edge.
/// Dependency edges connect operators that implement a single logical function,
/// e.g., exchange sender and receiver or the input and output halves of Z1.
pub stream_id: Option<LirStreamId>,
pub from: LirNodeId,
pub to: LirNodeId,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct LirCircuit {
pub nodes: Vec<LirNode>,
pub edges: Vec<LirEdge>,
}
impl LirCircuit {
pub fn as_json(&self) -> String {
serde_json::to_string(self).unwrap()
}
pub fn as_zip(&self) -> Vec<u8> {
let json = self.as_json();
let json = json.as_bytes();
let mut zip = ZipWriter::new(std::io::Cursor::new(Vec::with_capacity(65536)));
zip.start_file("ir.json", FileOptions::default()).unwrap();
zip.write_all(json).unwrap();
zip.finish().unwrap().into_inner()
}
}