Skip to content

Commit ea6a818

Browse files
committed
Fixed and found some constexpr pruning
Signed-off-by: Luke Quinn <[email protected]>
1 parent 29fdbf7 commit ea6a818

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

backends/cpp_hart_gen/lib/constexpr_pass.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def constexpr?(symtab)
1313
class IdAst
1414
def constexpr?(symtab)
1515
sym = symtab.get(name)
16-
return true if sym.nil? # assuming undefined syms are local (be sure to type check first!!)
16+
return true if sym.nil?
1717
return true if sym.is_a?(Type)
18+
return false if sym.value.nil? # assuming undefined syms are local (be sure to type check first!!)
1819

1920
if sym.param?
2021
symtab.cfg_arch.params_with_value.any? { |p| p.name == text_value }

backends/cpp_hart_gen/lib/gen_cpp.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
399399
lines = []
400400
symtab.push(nil)
401401
init.add_symbol(symtab)
402+
symtab.get(init.lhs.text_value).value = nil
403+
402404
stmts.each do |s|
403405
lines << s.gen_cpp(symtab, indent_spaces, indent_spaces:)
404406
end

lib/idl/passes/prune.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def prune(symtab)
8585
init.prune(symtab),
8686
condition.prune(symtab),
8787
update.prune(symtab),
88-
stmts.map { |s| s.prune(symtab) }
88+
#stmts.map { |s| s.prune(symtab) } #TODO need to not prune a = a + 1 since is known for each loop iter but should accumulate
89+
stmts.map { |s| s.dup() }
8990
)
9091
ensure
9192
symtab.pop

0 commit comments

Comments
 (0)