Up to now, only unused IMove expressions where discarded.
So we also distinguish pure ICode from non pure ICode.
Signed-off-by: Jean Privat <jean@pryen.org>
if r != null and r.slot_index != null then
assert s != null
v.add_assignment(v.register(r), s)
if r != null and r.slot_index != null then
assert s != null
v.add_assignment(v.register(r), s)
- else if s != null and not self isa IMove then
+ else if s != null and not is_pure then
+ # ICode with side effects must be evaluated
+ # even if the result is not wanted
v.add_instr(s + ";")
end
end
v.add_instr(s + ";")
end
end
# The location of the icode (if any)
readable writable var _location: nullable Location = null
# The location of the icode (if any)
readable writable var _location: nullable Location = null
+
+ # Is the icode side effect free?
+ fun is_pure: Bool do return false
end
# An icode that uses no registers (no args)
end
# An icode that uses no registers (no args)
+
+ redef readable writable var _is_pure: Bool = false
end
# A register assigment
end
# A register assigment
+
+ redef fun is_pure do return true
end
# An attribute read access
end
# An attribute read access
super(r)
_property = p
end
super(r)
_property = p
end
+
+ redef fun is_pure do return true
end
# An attribute assignment
end
# An attribute assignment
super(r)
_property = p
end
super(r)
_property = p
end
+
+ redef fun is_pure do return true
+
+ redef fun is_pure do return true
+
+ redef fun is_pure do return true
end
# The unary 'not' operation
end
# The unary 'not' operation
+
+ redef fun is_pure do return true
end
# Evaluate body once them return the same value again and again
end
# Evaluate body once them return the same value again and again
+
+ redef fun is_pure do return true
end
#################################################
end
#################################################
fun lit_true_reg: IRegister
do
var e = new INative("TAG_Bool(true)", null)
fun lit_true_reg: IRegister
do
var e = new INative("TAG_Bool(true)", null)
return expr(e, module.type_bool)
end
return expr(e, module.type_bool)
end
fun lit_false_reg: IRegister
do
var e = new INative("TAG_Bool(false)", null)
fun lit_false_reg: IRegister
do
var e = new INative("TAG_Bool(false)", null)
return expr(e, module.type_bool)
end
return expr(e, module.type_bool)
end
redef class INative
redef fun inner_dup_with(d)
do
redef class INative
redef fun inner_dup_with(d)
do
- return new INative(code, d.dup_iregs(exprs))
+ var c2 = new INative(code, d.dup_iregs(exprs))
+ c2.is_pure = is_pure
+ return c2