extend example, add doc
This commit is contained in:
parent
76a2127120
commit
7305cf99f0
3 changed files with 20 additions and 5 deletions
|
@ -1,5 +1,11 @@
|
||||||
//! Module containing constant propagation for the typed AST
|
//! Module containing constant propagation for the typed AST
|
||||||
//!
|
//!
|
||||||
|
//! On top of the usual behavior of removing statements which assign a constant to a variable (as the variable can simply be
|
||||||
|
//! substituted for the constant whenever used), we provide a `verbose` mode which does not remove such statements. This is done
|
||||||
|
//! as for partial passes which do not visit the whole program, the variables being defined may be be used in parts of the program
|
||||||
|
//! that are not visited. Keeping the statements is semantically equivalent and enables rebuilding the set of constants at the
|
||||||
|
//! next pass.
|
||||||
|
//!
|
||||||
//! @file propagation.rs
|
//! @file propagation.rs
|
||||||
//! @author Thibaut Schaeffer <thibaut@schaeff.fr>
|
//! @author Thibaut Schaeffer <thibaut@schaeff.fr>
|
||||||
//! @date 2018
|
//! @date 2018
|
||||||
|
@ -16,7 +22,7 @@ pub struct Propagator<'ast, T: Field> {
|
||||||
// we currently do not support partially constant expressions: `field [x, 1][1]` is not considered constant, `field [0, 1][1]` is
|
// we currently do not support partially constant expressions: `field [x, 1][1]` is not considered constant, `field [0, 1][1]` is
|
||||||
constants: HashMap<TypedAssignee<'ast, T>, TypedExpression<'ast, T>>,
|
constants: HashMap<TypedAssignee<'ast, T>, TypedExpression<'ast, T>>,
|
||||||
// the verbose mode doesn't remove statements which assign constants to variables
|
// the verbose mode doesn't remove statements which assign constants to variables
|
||||||
// it required when using propagation in combination with unrolling
|
// it's required when using propagation in combination with unrolling
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["4838400", "10"]
|
"values": ["4838400", "10", "25"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"Ok": {
|
"Ok": {
|
||||||
"values": ["0", "10"]
|
"values": ["0", "10", "25"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
def main(field[4] values) -> (field, field):
|
def main(field[4] values) -> (field, field, field):
|
||||||
field res0 = 1
|
field res0 = 1
|
||||||
field res1 = 0
|
field res1 = 0
|
||||||
|
|
||||||
|
@ -15,4 +15,13 @@ def main(field[4] values) -> (field, field):
|
||||||
res1 = res1 + 1
|
res1 = res1 + 1
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return res0, res1
|
field res2 = 0
|
||||||
|
field i = 0
|
||||||
|
for field i in i..5 do
|
||||||
|
i = 5
|
||||||
|
for field i in 0..i do
|
||||||
|
res2 = res2 + 1
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return res0, res1, res2
|
Loading…
Reference in a new issue