From 55bebc8c39722e1cbe98c7d9af12d47f6a4d5ab2 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 3 Nov 2012 17:41:11 -0700 Subject: [PATCH] Stub to pform class properties and null expressions. --- PClass.h | 2 ++ PExpr.cc | 8 ++++++++ PExpr.h | 8 ++++++++ parse.y | 36 ++++++++++++++++++++++++------------ pform.h | 4 ++++ pform_dump.cc | 16 ++++++++++++++++ pform_pclass.cc | 28 ++++++++++++++++++++++++++++ pform_types.h | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 127 insertions(+), 12 deletions(-) diff --git a/PClass.h b/PClass.h index ee44772aa..1153fd48c 100644 --- a/PClass.h +++ b/PClass.h @@ -35,6 +35,8 @@ class PClass : public PScopeExtra, public LineInfo { explicit PClass (perm_string name, LexicalScope*parent); ~PClass(); + public: + class_type_t*type; }; #endif diff --git a/PExpr.cc b/PExpr.cc index e43d3a5ad..adbc36c2f 100644 --- a/PExpr.cc +++ b/PExpr.cc @@ -281,6 +281,14 @@ PExpr* PEEvent::expr() const return expr_; } +PENull::PENull(void) +{ +} + +PENull::~PENull() +{ +} + PEFNumber::PEFNumber(verireal*v) : value_(v) { diff --git a/PExpr.h b/PExpr.h index ebd530314..13c52a3f9 100644 --- a/PExpr.h +++ b/PExpr.h @@ -467,6 +467,14 @@ class PENew : public PExpr { PExpr*size_; }; +class PENull : public PExpr { + public: + explicit PENull(); + ~PENull(); + + virtual void dump(ostream&) const; +}; + class PENumber : public PExpr { public: diff --git a/parse.y b/parse.y index 31f27394f..2713333a9 100644 --- a/parse.y +++ b/parse.y @@ -387,6 +387,7 @@ static void current_function_set_statement(const YYLTYPE&loc, vector data_type_t*data_type; class_type_t*class_type; real_type_t::type_t real_type; + property_qualifier_t property_qualifier; verinum* number; @@ -562,6 +563,10 @@ static void current_function_set_statement(const YYLTYPE&loc, vector %type struct_union_member_list %type struct_data_type +%type class_item_qualifier property_qualifier +%type property_qualifier_list property_qualifier_opt +%type random_qualifier + %type range range_opt variable_dimension %type dimensions_opt dimensions @@ -762,13 +767,19 @@ class_item /* IEEE1800-2005: A.1.8 */ /* Class properties... */ | property_qualifier_opt data_type list_of_variable_decl_assignments ';' - + { pform_class_property(@2, $1, $2, $3); } /* Class methods... */ | method_qualifier_opt task_declaration + { yyerror(@2, "sorry: Class methods (tasks) not supported yet."); + yyerrok; + } | method_qualifier_opt function_declaration + { yyerror(@2, "sorry: Class methods (functions) not supported yet."); + yyerrok; + } /* Class constraints... */ @@ -801,9 +812,9 @@ class_item /* IEEE1800-2005: A.1.8 */ ; class_item_qualifier /* IEEE1800-2005 A.1.8 */ - : K_static - | K_protected - | K_local + : K_static { $$ = property_qualifier_t::set_static(); } + | K_protected { $$ = property_qualifier_t::set_protected(); } + | K_local { $$ = property_qualifier_t::set_local(); } ; class_new /* IEEE1800-2005 A.2.4 */ @@ -1402,18 +1413,18 @@ property_qualifier /* IEEE1800-2005 A.1.8 */ ; property_qualifier_opt /* IEEE1800-2005 A.1.8: ... { property_qualifier } */ - : property_qualifier_list - | + : property_qualifier_list { $$ = $1; } + | { $$ = property_qualifier_t::set_none(); } ; property_qualifier_list /* IEEE1800-2005 A.1.8 */ - : property_qualifier_list property_qualifier - | property_qualifier + : property_qualifier_list property_qualifier { $$ = $1 | $2; } + | property_qualifier { $$ = $1; } ; random_qualifier /* IEEE1800-2005 A.1.8 */ - : K_rand - | K_randc + : K_rand { $$ = property_qualifier_t::set_rand(); } + | K_randc { $$ = property_qualifier_t::set_randc(); } ; /* real and realtime are exactly the same so save some code @@ -3230,8 +3241,9 @@ expr_primary { $$ = $1; } | K_null - { yyerror("sorry: null expressions not supported yet."); - $$ = 0; + { PENull*tmp = new PENull; + FILE_NAME(tmp, @1); + $$ = tmp; } ; diff --git a/pform.h b/pform.h index 95ec884cc..287763d85 100644 --- a/pform.h +++ b/pform.h @@ -181,6 +181,10 @@ extern void pform_endmodule(const char*, bool inside_celldefine, extern void pform_start_class_declaration(const struct vlltype&loc, class_type_t*type); +extern void pform_class_property(const struct vlltype&loc, + property_qualifier_t pq, + data_type_t*data_type, + std::list*decls); extern void pform_end_class_declaration(void); extern void pform_start_package_declaration(const struct vlltype&loc, diff --git a/pform_dump.cc b/pform_dump.cc index 4a6c60ae5..fc7668588 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -164,6 +164,17 @@ void struct_type_t::pform_dump(ostream&out, unsigned indent) const } } +void class_type_t::pform_dump(ostream&out, unsigned indent) const +{ + out << setw(indent) << "" << "class " << name << " {"; + + for (map::const_iterator cur = properties.begin() + ; cur != properties.end() ; ++cur) { + out << " " << cur->first; + } + out << " }" << endl; +} + void struct_member_t::pform_dump(ostream&out, unsigned indent) const { out << setw(indent) << "" << type; @@ -267,6 +278,11 @@ void PENew::dump(ostream&out) const out << "new [" << *size_ << "]"; } +void PENull::dump(ostream&out) const +{ + out << "null"; +} + void PENumber::dump(ostream&out) const { out << value(); diff --git a/pform_pclass.cc b/pform_pclass.cc index 1c7329ba0..89e4f8115 100644 --- a/pform_pclass.cc +++ b/pform_pclass.cc @@ -19,16 +19,44 @@ # include "pform.h" # include "PClass.h" +# include "parse_misc.h" static PClass*pform_cur_class = 0; void pform_start_class_declaration(const struct vlltype&loc, class_type_t*type) { PClass*class_scope = pform_push_class_scope(loc, type->name); + class_scope->type = type; assert(pform_cur_class == 0); pform_cur_class = class_scope; } +void pform_class_property(const struct vlltype&loc, + property_qualifier_t property_qual, + data_type_t*data_type, + list*decls) +{ + assert(pform_cur_class); + + if (property_qual.test_static()) { + // I think the thing to do with static properties is to + // make them PWires directly in the PClass scope. They + // are wires like program/modules wires, and not + // instance members. + VLerror(loc, "sorry: static class properties not implemented."); + return; + } + + for (list::iterator cur = decls->begin() + ; cur != decls->end() ; ++cur) { + + decl_assignment_t*curp = *cur; + pform_cur_class->type->properties[curp->name] = data_type; + } + + VLerror(loc, "sorry: class properties not implemented yet."); +} + void pform_end_class_declaration(void) { assert(pform_cur_class); diff --git a/pform_types.h b/pform_types.h index df2c8f9b8..6193d99c2 100644 --- a/pform_types.h +++ b/pform_types.h @@ -175,10 +175,47 @@ struct string_type_t : public data_type_t { }; struct class_type_t : public data_type_t { + inline explicit class_type_t(perm_string n) : name(n) { } + void pform_dump(std::ostream&out, unsigned indent) const; + perm_string name; + + std::map properties; +}; + +class property_qualifier_t { + public: + static inline property_qualifier_t set_none() + { property_qualifier_t res; res.mask_ = 0; return res; } + + static inline property_qualifier_t set_static() + { property_qualifier_t res; res.mask_ = 1; return res; } + + static inline property_qualifier_t set_protected() + { property_qualifier_t res; res.mask_ = 2; return res; } + + static inline property_qualifier_t set_local() + { property_qualifier_t res; res.mask_ = 4; return res; } + + static inline property_qualifier_t set_rand() + { property_qualifier_t res; res.mask_ = 8; return res; } + + static inline property_qualifier_t set_randc() + { property_qualifier_t res; res.mask_ = 16; return res; } + + inline property_qualifier_t operator | (property_qualifier_t r) + { property_qualifier_t res; res.mask_ = mask_ | r.mask_; return res; } + + public: + inline bool test_static() const { return mask_ & 1; } + inline bool test_protected() const { return mask_ & 2; } + inline bool test_local() const { return mask_ & 4; } + + private: + int mask_; }; /*