litex/stmt/
tooling_stmt.rs1use crate::prelude::*;
2use std::fmt;
3
4#[derive(Clone)]
5pub enum ImportStmt {
6 ImportRelativePath(ImportRelativePathStmt),
7 ImportGlobalModule(ImportGlobalModuleStmt),
8}
9
10#[derive(Clone)]
11pub struct ImportRelativePathStmt {
12 pub path: String,
13 pub as_mod_name: Option<String>,
14 pub line_file: LineFile,
15}
16
17#[derive(Clone)]
18pub struct ImportGlobalModuleStmt {
19 pub mod_name: String,
20 pub as_mod_name: Option<String>,
21 pub line_file: LineFile,
22}
23
24#[derive(Clone)]
25pub struct RunFileStmt {
26 pub file_path: String,
27 pub line_file: LineFile,
28}
29
30impl RunFileStmt {
31 pub fn new(file_path: String, line_file: LineFile) -> Self {
32 RunFileStmt {
33 file_path,
34 line_file,
35 }
36 }
37}
38
39impl fmt::Display for RunFileStmt {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 write!(f, "{}", self.file_path)
42 }
43}
44
45impl fmt::Display for ImportStmt {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 ImportStmt::ImportRelativePath(import_relative_path) => {
49 write!(f, "{}", import_relative_path)
50 }
51 ImportStmt::ImportGlobalModule(import_global_mod) => write!(f, "{}", import_global_mod),
52 }
53 }
54}
55
56impl ImportRelativePathStmt {
57 pub fn new(path: String, as_mod_name: Option<String>, line_file: LineFile) -> Self {
58 ImportRelativePathStmt {
59 path,
60 as_mod_name,
61 line_file,
62 }
63 }
64}
65
66impl ImportGlobalModuleStmt {
67 pub fn new(mod_name: String, as_mod_name: Option<String>, line_file: LineFile) -> Self {
68 ImportGlobalModuleStmt {
69 mod_name,
70 as_mod_name,
71 line_file,
72 }
73 }
74}
75
76impl fmt::Display for ImportRelativePathStmt {
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 match &self.as_mod_name {
79 Some(name) => write!(
80 f,
81 "{} {}{}{} {} {}",
82 IMPORT, DOUBLE_QUOTE, self.path, DOUBLE_QUOTE, AS, name
83 ),
84 None => write!(
85 f,
86 "{} {}{}{}",
87 IMPORT, DOUBLE_QUOTE, self.path, DOUBLE_QUOTE
88 ),
89 }
90 }
91}
92
93impl fmt::Display for ImportGlobalModuleStmt {
94 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95 match &self.as_mod_name {
96 Some(name) => write!(f, "{} {} {} {}", IMPORT, self.mod_name, AS, name),
97 None => write!(f, "{} {}", IMPORT, self.mod_name),
98 }
99 }
100}
101
102impl ImportStmt {
103 pub fn line_file(&self) -> LineFile {
104 match self {
105 ImportStmt::ImportRelativePath(import_relative_path) => {
106 import_relative_path.line_file.clone()
107 }
108 ImportStmt::ImportGlobalModule(import_global_mod) => {
109 import_global_mod.line_file.clone()
110 }
111 }
112 }
113}
114
115#[derive(Clone)]
116pub struct DoNothingStmt {
117 pub line_file: LineFile,
118}
119
120impl DoNothingStmt {
121 pub fn new(line_file: LineFile) -> Self {
122 DoNothingStmt { line_file }
123 }
124}
125
126impl fmt::Display for DoNothingStmt {
127 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128 write!(f, "{}", DO_NOTHING)
129 }
130}