forked from ComCompiler/nhwc_compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode2ast_pass.rs
More file actions
59 lines (52 loc) · 2.09 KB
/
Copy pathcode2ast_pass.rs
File metadata and controls
59 lines (52 loc) · 2.09 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
use crate::toolkit::{
context::NhwcCtx, dot::Config, etc::{generate_png_by_graph_multi_tasks, read_file_content}, gen_ast::parse_as_ast_tree, pass_manager::Pass
};
use anyhow::Result;
#[derive(Debug)]
pub struct Code2AstPass {
is_gen_png:bool,
}
impl Code2AstPass {
pub fn new(is_gen_png:bool) -> Self { Code2AstPass { is_gen_png } }
}
impl Pass for Code2AstPass {
// 运行这个pass
fn run(&mut self, ctx:&mut NhwcCtx) -> Result<()> {
ctx.code = read_file_content(ctx.args.input.to_string_lossy().into_owned());
let defs = "int getint();
int getch();
int getarray(int zz_array[]);
float getfloat();
int getfarray(float zz_array[]);
void putint(int zz_int );
void putch(int zz_ch );
void putarray(int x, int zz_array[]);
void putfloat(float zz_float);
void putfarray(int zz_len, float zz_farray[]);
// putf(char *s, ...)
void putf();
// macros are not supported as for now
// #define starttime() _sysy_starttime(__LINE__)
// #define stoptime() _sysy_stoptime(__LINE__)
void starttime();
void stoptime();
void memset(void *zz_ptr, int zz_val, int zz_len);
void memcpy(void *zz_dest, void *zz_ptr, int zz_len);";
if !ctx.args.no_header{
ctx.code.insert_str(0,defs);
}
parse_as_ast_tree(ctx);
// 生成对应的png
Ok(())
}
// 返回pass的描述,具体作用
fn get_desc(&self) -> String { return "pass Code2AstPass description".to_string(); }
// 返回pass的名称
fn get_pass_name(&self) -> String { return "Code2AstPass".to_string(); }
fn when_finish_or_panic(&mut self, ctx:&mut crate::toolkit::context::NhwcCtx) {
if self.is_gen_png {
let ast_tree = &mut ctx.ast_tree;
generate_png_by_graph_multi_tasks(&ast_tree.clone(), "ast_tree".to_string(), &[Config::EdgeNoLabel, Config::Record, Config::Title("ast_tree".to_string())],&mut ctx.io_task_list);
}
}
}