From 4e1fffd4b503fbfae1ed1d384996e05847f50e09 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 6 Apr 2020 10:55:19 -0400
Subject: [PATCH 006/251] FIXME: more on experiment

---
 gcc/analyzer/revamp-state.cc | 44 +++++++++++++++++++++++++++++++-----
 gcc/analyzer/revamp-state.h  | 23 +++++++++++++++++--
 2 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/gcc/analyzer/revamp-state.cc b/gcc/analyzer/revamp-state.cc
index 72f248a6c11..5641692c3d1 100644
--- a/gcc/analyzer/revamp-state.cc
+++ b/gcc/analyzer/revamp-state.cc
@@ -93,17 +93,40 @@ var_decl_region::dump_to_pp (pretty_printer *pp) const
   pp_printf (pp, "var_decl_region(%qE)", m_decl);
 }
 
-/* class environment.  */
+void
+ssa_name_region::dump_to_pp (pretty_printer *pp) const
+{
+  pp_printf (pp, "ssa_name_region(%qE)", m_name);
+}
+
+/* class store.  */
 
 void
-environment::bind (region_val *dst, sval *val)
+store::bind (region_val *dst, sval *val)
 {
   m_map.put (dst, val);
   dump ();
 }
 
+json::value *
+store::to_json () const
+{
+  json::array *store_arr = new json::array ();
+  for (map_t::iterator iter = m_map.begin ();
+       iter != m_map.end ();
+       ++iter)
+    {
+      region_val *reg = (*iter).first;
+      sval *val = (*iter).second;
+      json::object *item_obj = new json::object ();
+      // TODO
+      store_arr->append (item_obj);
+    }
+  return store_arr;
+}
+
 DEBUG_FUNCTION void
-environment::dump ()
+store::dump ()
 {
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
@@ -114,7 +137,7 @@ environment::dump ()
 }
 
 void
-environment::dump_to_pp (pretty_printer *pp) const
+store::dump_to_pp (pretty_printer *pp) const
 {
   pp_character (pp, '{');
   for (map_t::iterator iter = m_map.begin ();
@@ -135,7 +158,7 @@ environment::dump_to_pp (pretty_printer *pp) const
 /* class revamp_state.  */
 
 revamp_state::revamp_state (const extrinsic_state &ext_state)
-: m_env (new environment ()) // FIXME
+: m_store (new store ()) // FIXME
 {
 }
 
@@ -314,7 +337,7 @@ revamp_state::bind (const extrinsic_state &ext_state,
   loc_val *dst = get_lvalue (ext_state, lhs);
   sval *src = get_rvalue (ext_state, rhs);
   if (region_val *rval = dst->dyn_cast_region_val ())
-    m_env->bind (rval, src);
+    m_store->bind (rval, src);
   else
     gcc_unreachable (); // unknown loc_val; what could be clobbered?
 }
@@ -326,6 +349,8 @@ revamp_state::get_lvalue (const extrinsic_state &ext_state, tree expr)
     {
     case VAR_DECL:
       return new var_decl_region (expr); // TODO: uniquify
+    case SSA_NAME:
+      return new ssa_name_region (expr); // TODO: uniquify
     default:
       gcc_unreachable ();
       //return ext_state::new_unknown_sval (expr);
@@ -345,6 +370,13 @@ revamp_state::get_rvalue (const extrinsic_state &ext_state, tree expr)
     }
 }
 
+json::value *
+revamp_state::to_json () const
+{
+  json::object *state_obj = new json::object ();
+  state_obj->set ("store", m_store->to_json ());
+  return state_obj;
+}
 
 } // namespace ana
 
diff --git a/gcc/analyzer/revamp-state.h b/gcc/analyzer/revamp-state.h
index 295d084df7d..182d21cee11 100644
--- a/gcc/analyzer/revamp-state.h
+++ b/gcc/analyzer/revamp-state.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_ANALYZER_REVAMP_STATE_H
 #define GCC_ANALYZER_REVAMP_STATE_H
 
+#include "json.h"
+
 namespace ana {
 
 class region_val;
@@ -80,7 +82,21 @@ private:
   tree m_decl;
 };
 
-class environment
+class ssa_name_region : public region_val
+{
+public:
+  ssa_name_region (tree name) : m_name (name)
+  {
+    gcc_assert (TREE_CODE (name) == SSA_NAME);
+  }
+
+  void dump_to_pp (pretty_printer *pp) const FINAL OVERRIDE;
+
+private:
+  tree m_name;
+};
+
+class store
 {
  public:
   typedef hash_map <region_val *, sval *> map_t; // or region * ?
@@ -88,6 +104,7 @@ class environment
 
   void bind (region_val *dst, sval *val);
 
+  json::value *to_json () const;
   void dump ();
   void dump_to_pp (pretty_printer *pp) const;
 
@@ -101,6 +118,8 @@ class revamp_state
 public:
   revamp_state (const extrinsic_state &ext_state);
 
+  json::value *to_json () const;
+
   bool on_stmt (const extrinsic_state &ext_state,
 		const supernode *snode,
 		const gimple *stmt);
@@ -131,7 +150,7 @@ private:
 				      const gswitch *switch_stmt);
 
   // TODO
-  environment *m_env;
+  store *m_store;
 };
 
 } // namespace ana
-- 
2.26.2

