From 98a52d8c8781b6da607d50ed10a128aef3e1adab Mon Sep 17 00:00:00 2001
From: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
Date: Tue, 4 Oct 2016 12:46:53 +0200
Subject: [PATCH] add-flowfacts: allow regexp in function names

---
 lib/core/program.rb     |  9 +++++++++
 lib/core/programinfo.rb | 19 +++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/lib/core/program.rb b/lib/core/program.rb
index 23ebebc..98e20c5 100644
--- a/lib/core/program.rb
+++ b/lib/core/program.rb
@@ -488,6 +488,15 @@ module PML
       end
     end
 
+    # all called functions
+    def callees
+      Enumerator.new do |ss|
+        callsites.each{|cs|
+          cs.callees.each {|c| ss << c}
+        }
+      end
+    end
+
     # find all instructions that a callee may return to
     def identify_return_sites
       blocks.each { |b|
diff --git a/lib/core/programinfo.rb b/lib/core/programinfo.rb
index dbc65f6..52c8e4c 100644
--- a/lib/core/programinfo.rb
+++ b/lib/core/programinfo.rb
@@ -325,13 +325,24 @@ module PML
         lhs = "+ " + lhs
       end
       terms = []
+      mf_scope = pml.machine_functions.by_label(scope)
       while lhs != "" do
         m = /(?<sign>[+-])\s*((?<factor>[0-9]+)\s*)?(?<pp>[^+-]*)\s*(?<lhs>.*)/.match(lhs)
 
-        factor = (m[:factor] || "1").to_i
-        factor *= {"+"=>1, "-"=>-1}[m[:sign]]
-        terms.push ({"factor"=>factor,
-                    "program-point"=> {"function"=>m[:pp]}})
+        if m[:pp][0] == "/"
+          reg = Regexp.new m[:pp][1..-2]
+          functions = pml.machine_functions\
+                      .select {|mf| mf.label =~ reg  && mf_scope.callees.member?(mf.label) }\
+                      .map {|mf| mf.label}
+        else
+          functions = [m[:pp]]
+        end
+        functions.each {|mf_label|
+          factor = (m[:factor] || "1").to_i
+          factor *= {"+"=>1, "-"=>-1}[m[:sign]]
+          terms.push ({"factor"=>factor,
+                       "program-point"=> {"function"=>mf_label}})
+        }
         lhs = m[:lhs]
       end
 
-- 
GitLab