pinapa-tree-decoration.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * arch-tag: Matthieu Moy  April 14, 2003 (parser/include/scp-tree-decoration.h)
00003  *------------------------------------------------------------------------------
00004  *         Copyright (c) STMicroelectronics,Verimag
00005  * Pinapa is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018  * MA 02111-1307, USA
00019  *------------------------------------------------------------------------------
00020  *                 System Platform Group - HPC
00021  *******************************************************************************/
00022 
00035 #include "pinapa-parser-all.h"
00036 
00037 namespace pinapa {
00038 
00039   class st_tree_deco_t;
00040   typedef st_tree_deco_t * tree_deco_t;
00041 
00042   class st_dependant_deco;
00043   typedef st_dependant_deco * dependant_deco;
00044 
00045   class st_type_deco;
00046   typedef st_type_deco * type_deco;
00047 
00048   class st_data_member_decl_deco;
00049   typedef st_data_member_decl_deco * data_member_decl_deco;
00050 
00051   class st_event_tree_deco;
00052   typedef st_event_tree_deco * event_tree_deco;
00053 
00054   class st_inst_dependant_deco;
00055   typedef st_inst_dependant_deco * inst_dependant_deco;
00056 }
00057 
00058 #ifndef PINAPA_TREE_DECORATION_H
00059 #define PINAPA_TREE_DECORATION_H
00060 
00061 #define PINAPA_NO_DEBUG
00062 
00063 #include <ext/hash_set>
00064 
00065 #include "pinapa-hash.h"
00066 #include "pinapa-tree.h"
00067 #include "pinapa-tree-utils.h"
00068 #include "pinapa-sensitivity-list.h"
00069 #include "pinapa-systemc-light.h"
00070 #include "pinapa-decoration-base.h"
00071 #include "pinapa-c-value.h"
00072 #include "pinapa-interface-plus.h"
00073 
00074 namespace pinapa {
00075   
00076   typedef st_deco_first<st_tree_deco_t,
00077                         tree_node> st_tree_deco;
00078   typedef st_tree_deco * tree_deco;
00079   
00080 }
00081 
00082 #define PINAPA_BEGIN_DOX
00083 #define PINAPA_END_DOX
00084 
00085 #ifdef PINAPA_INSIDE_DOXYGEN
00086 #define PINAPA_DECLARE_PRIMITIVE(prim, com) PINAPA_BEGIN_DOX com PINAPA_END_DOX prim,
00087 #else
00088 #define PINAPA_DECLARE_PRIMITIVE(prim, com) prim,
00089 #endif
00090 
00091 namespace pinapa {
00092 
00094   typedef enum {
00095 #include "pinapa-primitives.def"
00096   } sc_primitive_t;
00097   
00098   char * get_name(sc_primitive_t prim);
00099   char * get_doc(sc_primitive_t prim);
00100   
00104   typedef enum {
00105     PINAPA_TLM_ADDRESS_TYPE, 
00106     PINAPA_TLM_DATA_TYPE, 
00107     PINAPA_STANDARD_TYPE 
00108   } type_of_type;
00109 
00110 
00119   extern hash_map<tree, tree_deco> tree_decoration_map;
00120 
00124   template<class deco>
00125   class st_deco_first<deco, tree_node> : public st_deco_b {
00126   public:
00127     st_deco_first<deco, tree_node>() {}
00128     st_deco_first<deco, tree_node>(deco d) : m_deco(d) {}
00129     st_deco_first<deco, tree_node>(sc_primitive_t p, tree t) : m_deco(p, t) {}
00130     static st_deco_first<deco, tree_node> & get(tree_node * p);
00131     static st_deco_first<deco, tree_node> * get_deco(tree_node * p);
00132     static bool is_null(tree_node * p) {
00133       return tree_decoration_map.find(p) == tree_decoration_map.end();}
00134     void attach(tree_node * p);
00135     deco * operator -> () {return & m_deco;}
00136     deco * get_deco() {return & m_deco;}
00137   private:
00138     deco m_deco;
00139   };
00140 
00141   template <class deco>
00142   inline st_deco_first<deco, tree_node> &
00143   st_deco_first<deco,tree_node>::get(tree_node * p) {
00144     st_deco_first<deco,tree_node> * res =
00145       tree_decoration_map[p];
00146     if (res == NULL) {
00147       res = new st_deco_first<deco,tree_node>(p);
00148       res->attach(p);
00149       (*res)->set_tree(p);
00150     }
00151     return *res;
00152   }
00153 
00154   template <class deco>
00155   inline st_deco_first<deco, tree_node> *
00156   st_deco_first<deco,tree_node>::get_deco(tree_node * p) {
00157     st_deco_first<deco,tree_node> * res =
00158       tree_decoration_map[p];
00159     return res;
00160   }
00161 
00162   template <class deco>
00163   void st_deco_first<deco,tree_node>::attach(tree_node * p){
00164     tree_decoration_map[p] = this;
00165     tree decoration = p->common.pinapa_decoration;
00166     while(decoration != NULL_TREE) {
00167       tree_decoration_map[TREE_VALUE(decoration)] = this;
00168       decoration = TREE_CHAIN(decoration);
00169     }
00170   }
00171 
00172   typedef st_deco_first<st_tree_deco_t,
00173                         tree_node> st_tree_deco;
00174 
00175   typedef st_tree_deco * tree_deco;
00176 
00177   struct hash_key_assoc_tree_handle;
00178   struct equal_to_key_assoc_tree_handle;
00179 
00187   class key_assoc_tree_handle {
00188     friend class equal_to_key_assoc_tree_handle;
00189     friend class hash_key_assoc_tree_handle;
00190   public:
00191     key_assoc_tree_handle(const tree t, const sc_process_b * h)
00192       : m_tree(t), m_handle(h) {}
00193 
00194     key_assoc_tree_handle(const key_assoc_tree_handle& k)
00195       : m_tree(k.m_tree), m_handle(k.m_handle) {}
00196 
00197     const tree m_tree;
00198     const sc_process_b * m_handle;
00199 
00200     key_assoc_tree_handle & operator=(const key_assoc_tree_handle & k) {
00201       key_assoc_tree_handle * assign = new key_assoc_tree_handle(k);
00202       return *assign;
00203     }
00204   };
00205 
00210   struct equal_to_key_assoc_tree_handle {
00211     bool operator()(const key_assoc_tree_handle k1,
00212                     const key_assoc_tree_handle k2) const {
00213       return ((k1.m_tree == k2.m_tree) && (k1.m_handle == k2.m_handle));
00214     }
00215   };
00216 
00217   struct hash_key_assoc_tree_handle {
00218     size_t operator () (const key_assoc_tree_handle k) const {
00219       hash<sc_process_b *> H1;
00220       hash<tree>           H2;
00221 
00222       // Hashing on pointer values.
00223       return H1(k.m_handle) + H2(k.m_tree);
00224     }
00225   };
00228   class st_tree_instance_deco_t {
00229   public:
00230     st_tree_instance_deco_t() : m_related_object(NULL),
00231                                 m_initial_value(NULL),
00232                                 m_deco(NULL) {}
00233     sc_object * get_related_object() const {return m_related_object;}
00234     void set_related_object(sc_object * r) {m_related_object = r;}
00242     hash_set<sc_interface *> get_channels() const {return m_channels;}
00243     sc_interface * get_channel() const {
00244       PINAPA_ASSERT(m_channels.size() == 1, "Only one channel currently allowed. Got " << m_channels.size());
00245       return *m_channels.begin();}
00246     void add_channel(sc_interface * c) {m_channels.insert(c);}
00252     tree get_initial_value() const {return m_initial_value;}
00253     void set_initial_value(tree i, tree attach);
00254 
00258     inst_dependant_deco get_dependant_deco() const {return m_deco;}
00259     void set_dependant_deco(inst_dependant_deco  d) {m_deco = d;}
00260 
00261   private:
00262     sc_object * m_related_object;
00263     hash_set<sc_interface *> m_channels;
00264     tree m_initial_value;
00265     inst_dependant_deco m_deco;
00266   };
00267 
00268   template<>
00269   void * get_decoration<key_assoc_tree_handle>
00270   (key_assoc_tree_handle & th);
00271 
00272   template<>
00273   void set_decoration<key_assoc_tree_handle>
00274   (key_assoc_tree_handle & th, void * d);
00275 
00276 
00277   typedef st_deco_first<st_tree_instance_deco_t,
00278                         key_assoc_tree_handle> st_tree_instance_deco;
00279 
00280   typedef st_tree_instance_deco * tree_instance_deco;
00281 
00282   typedef hash_map<key_assoc_tree_handle,
00283                    tree_instance_deco,
00284                    hash_key_assoc_tree_handle,
00285                    equal_to_key_assoc_tree_handle > assoc_tree_handle;
00286   extern assoc_tree_handle instances_deco;
00287 
00288 #ifdef PINAPA_GDB
00289   void gdb_dump_instance_deco();
00290 #endif
00291 
00293   class st_tree_deco_t {
00294 
00298     static bool may_require_warning;
00299 
00300   public:
00304     static tree_deco get(tree body);
00305 
00306     static sc_primitive_t get_primitive(tree body) {
00307       return get(body) == NULL ? CPP_STANDARD : (*get(body))->get_primitive();}
00308 
00311     static void initialize(tree body) {
00312       if (tree_decoration_map.find(body) == tree_decoration_map.end()) {
00313         tree_decoration_map[body] = NULL;
00314       }
00315     }
00319     st_tree_deco_t(sc_primitive_t sc_primitive, tree t);
00320 
00323     st_tree_deco_t(tree t);
00324 
00325   public:
00326 
00327     sc_primitive_t get_primitive() const {return m_primitive;}
00328     sc_object * get_related_object(sc_process_b * h) const {
00329       return
00330         st_tree_instance_deco::get(key_assoc_tree_handle(get_tree(), h))
00331         ->get_related_object();}
00332     void set_related_object(sc_object * o, sc_process_b * h) {
00333       st_tree_instance_deco::get(key_assoc_tree_handle(get_tree(), h))
00334         ->set_related_object(o);}
00335 
00337     dependant_deco get_dependant_deco() const {return m_deco;}
00338     void set_dependant_deco(dependant_deco  d) {m_deco = d;}
00341     void * pinapa_decoration;
00342 
00343     const tree get_tree() const {return m_tree;}
00344     void set_tree(tree  t) {m_tree = t;}
00345 
00346     type_of_type get_type() const {return m_type;}
00347     void set_type(type_of_type  t) {m_type = t;}
00348 
00355     tree get_old_node() const {return m_old_node;}
00356     void set_old_node(tree b) {
00357       m_old_node = b;
00358       st_tree_deco::get_deco(get_tree())->attach(b);
00359     }
00367     static void set_location(tree t, const char * filename, int line);
00368     bool has_location();
00369     const char * get_input_filename();
00370     int get_input_line();
00373   private:
00374     const sc_primitive_t m_primitive;
00375     tree m_tree;
00376     type_of_type m_type;
00377     tree m_old_node;
00378 
00379   public:
00380     dependant_deco m_deco;
00381   };
00382 
00384   class st_dependant_deco {
00385   public:
00386 
00387   protected:
00388     st_dependant_deco() {}
00389     virtual ~st_dependant_deco() {};
00390   };
00391 
00393   class st_read_deco : public st_dependant_deco {
00394   public:
00395 
00396   private:
00397 
00398   };
00399 
00401   class st_write_deco : public st_dependant_deco {
00402   public:
00403 
00404   };
00405 
00407   class st_func_decl_deco : public st_dependant_deco {
00408   public:
00409     tree get_return_value() const {return return_value;}
00410     void set_return_value(tree r) {return_value = r;}
00411 
00412   private:
00413     tree return_value;
00414   };
00415 
00417   class st_tlm_write_deco : public st_dependant_deco {
00418   public:
00419 
00420   };
00421 
00423   class st_type_deco : public st_dependant_deco {
00424     //
00425   };
00426 
00428   class st_data_member_decl_deco : public st_dependant_deco {
00429     //
00430   };
00431 
00433   class st_inst_dependant_deco {
00434   public:
00435 
00436   protected:
00437     st_inst_dependant_deco() {}
00438     virtual ~st_inst_dependant_deco() {};
00439   };
00440 
00442   class st_event_tree_deco : public st_inst_dependant_deco {
00443   public:
00445     st_event_tree_deco (sc_event * event) : m_event(event) {}
00446     sc_event * get_event() const {return m_event;}
00447   private:
00448     sc_event * m_event;
00449   };
00450   void print_primitive(sc_primitive_t sc_primitive);
00451 
00453   class st_wait_deco : public st_inst_dependant_deco {
00454   public:
00455     st_wait_deco(sensitivity s) : m_sensitivity(s) {}
00456     sensitivity get_sensitivity() const {return m_sensitivity;}
00457   private:
00458     sensitivity m_sensitivity;
00459   };
00460 
00461   typedef st_wait_deco * wait_deco;
00462 
00463 }
00464 
00465 #endif // PINAPA_TREE_DECORATION_H
00466 
Generated by
Matthieu Moy <Matthieu.Moy@st.com>
Back to Pinapa Home Page