From 1601b3b6b0600fc5bf7a49dc59119f76d7855ccd Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 31 Mar 2012 11:22:19 -0400 Subject: [PATCH] Internals: Merge VFlagChildDtype calls. No functional change intended. --- src/V3Ast.h | 1 + src/V3AstNodes.h | 27 +++++++++++++++++++++++---- src/V3Link.cpp | 3 ++- src/V3LinkParse.cpp | 2 +- src/verilog.y | 19 ++++++++++--------- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index 6a523b5ef..6ead99754 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -38,6 +38,7 @@ // Hint class so we can choose constructors class VFlagLogicPacked {}; class VFlagBitPacked {}; +class VFlagChildDType {}; // Used by parser.y to select constructor that sets childDType //###################################################################### diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 234a3bbae..83b488311 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -162,7 +162,7 @@ struct AstTypedef : public AstNode { private: string m_name; public: - AstTypedef(FileLine* fl, const string& name, AstNodeDType* dtp) + AstTypedef(FileLine* fl, const string& name, VFlagChildDType, AstNodeDType* dtp) : AstNode(fl), m_name(name) { setOp1p(dtp); widthSignedFrom(dtp); @@ -196,7 +196,8 @@ private: string m_name; void* m_containerp; // In what scope is the name unique, so we can know what are duplicate definitions (arbitrary value) public: - AstDefImplicitDType(FileLine* fl, const string& name, AstNode* containerp, AstNodeDType* dtp) + AstDefImplicitDType(FileLine* fl, const string& name, AstNode* containerp, + VFlagChildDType, AstNodeDType* dtp) : AstNodeDType(fl), m_name(name), m_containerp(containerp) { setOp1p(dtp); widthSignedFrom(dtp); @@ -220,6 +221,12 @@ struct AstArrayDType : public AstNodeDType { private: bool m_packed; public: + AstArrayDType(FileLine* fl, VFlagChildDType, AstNodeDType* dtp, AstRange* rangep, bool isPacked=false) + : AstNodeDType(fl), m_packed(isPacked) { + setOp1p(dtp); + setOp2p(rangep); + widthSignedFrom(dtp); + } AstArrayDType(FileLine* fl, AstNodeDType* dtp, AstRange* rangep, bool isPacked=false) : AstNodeDType(fl), m_packed(isPacked) { setOp1p(dtp); @@ -337,7 +344,8 @@ struct AstConstDType : public AstNodeDType { // const data type, ie "const some_dtype var_name [2:0]" // ConstDType are removed in V3LinkLValue and become AstVar::isConst. // When more generic types are supported AstConstDType will be propagated further. - AstConstDType(FileLine* fl, AstNodeDType* dtp) +public: + AstConstDType(FileLine* fl, VFlagChildDType, AstNodeDType* dtp) : AstNodeDType(fl) { setOp1p(dtp); widthSignedFrom(dtp); @@ -441,7 +449,8 @@ public: struct AstEnumDType : public AstNodeDType { // Parents: TYPEDEF/MODULE // Children: ENUMVALUEs - AstEnumDType(FileLine* fl, AstNodeDType* dtp, AstNode* itemsp) +public: + AstEnumDType(FileLine* fl, VFlagChildDType, AstNodeDType* dtp, AstNode* itemsp) : AstNodeDType(fl) { setOp1p(dtp); addNOp2p(itemsp); } ASTNODE_NODE_FUNCS(EnumDType, ENUMDTYPE) @@ -637,6 +646,16 @@ private: m_trace=false; } public: + AstVar(FileLine* fl, AstVarType type, const string& name, VFlagChildDType, AstNodeDType* dtp) + :AstNode(fl) + , m_name(name) { + init(); + combineType(type); setOp1p(dtp); + if (dtp && dtp->basicp()) { + numericFrom(dtp); + width(dtp->basicp()->width(), 0); + } else width(1, 0); + } AstVar(FileLine* fl, AstVarType type, const string& name, AstNodeDType* dtp) :AstNode(fl) , m_name(name) { diff --git a/src/V3Link.cpp b/src/V3Link.cpp index 408267c4c..42c7a2393 100644 --- a/src/V3Link.cpp +++ b/src/V3Link.cpp @@ -431,7 +431,8 @@ private: // also return the class reference. if (dtypep) dtypep->unlinkFrBack(); else dtypep = new AstBasicDType(nodep->fileline(), AstBasicDTypeKwd::LOGIC); - AstVar* newvarp = new AstVar(nodep->fileline(), AstVarType::OUTPUT, nodep->name(), dtypep); + AstVar* newvarp = new AstVar(nodep->fileline(), AstVarType::OUTPUT, nodep->name(), + VFlagChildDType(), dtypep); // Not dtype resolved yet if (nodep->isSigned()) newvarp->numeric(AstNumeric::SIGNED); newvarp->funcReturn(true); newvarp->trace(false); // Not user visible diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index b2665ec0a..ca77022c2 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -374,7 +374,7 @@ private: nodep->deleteTree(); nodep=NULL; return; } else { - defp = new AstTypedef(nodep->fileline(), nodep->name(), dtypep); + defp = new AstTypedef(nodep->fileline(), nodep->name(), VFlagChildDType(), dtypep); m_implTypedef.insert(make_pair(make_pair(nodep->containerp(), defp->name()), defp)); backp->addNextHere(defp); } diff --git a/src/verilog.y b/src/verilog.y index 21c1583e8..c79fb4525 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1165,7 +1165,7 @@ data_typeNoRef: // ==IEEE: data_type, excluding class_type etc referenc //UNSUP yUNION taggedE packedSigningE '{' struct_union_memberList '}' packed_dimensionListE //UNSUP { UNSUP } | enumDecl { $$ = new AstDefImplicitDType($1->fileline(),"__typeimpenum"+cvtToStr(GRAMMARP->m_modTypeImpNum++), - GRAMMARP->m_modp,$1); } + GRAMMARP->m_modp,VFlagChildDType(),$1); } | ySTRING { $$ = new AstBasicDType($1,AstBasicDTypeKwd::STRING); } | yCHANDLE { $$ = new AstBasicDType($1,AstBasicDTypeKwd::CHANDLE); } //UNSUP yEVENT { UNSUP } @@ -1249,7 +1249,7 @@ variable_dimension: // ==IEEE: variable_dimension // IEEE: part of data_type enumDecl: - yENUM enum_base_typeE '{' enum_nameList '}' { $$ = new AstEnumDType($1,$2,$4); } + yENUM enum_base_typeE '{' enum_nameList '}' { $$ = new AstEnumDType($1,VFlagChildDType(),$2,$4); } ; enum_base_typeE: // IEEE: enum_base_type @@ -1316,14 +1316,14 @@ data_declarationVarFront: // IEEE: part of data_declaration | /**/ yVAR lifetimeE signingE rangeList { /*VARRESET-in-ddVar*/ VARDTYPE(GRAMMARP->addRange(new AstBasicDType($1, LOGIC_IMPLICIT, $3), $4,false)); } // // // implicit_type expanded into /*empty*/ or "signingE rangeList" - | yCONST__ETC yVAR lifetimeE data_type { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, $4)); } - | yCONST__ETC yVAR lifetimeE { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, new AstBasicDType($2, LOGIC_IMPLICIT))); } - | yCONST__ETC yVAR lifetimeE signingE rangeList { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, GRAMMARP->addRange(new AstBasicDType($2, LOGIC_IMPLICIT, $4), $5,false))); } + | yCONST__ETC yVAR lifetimeE data_type { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, VFlagChildDType(), $4)); } + | yCONST__ETC yVAR lifetimeE { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, VFlagChildDType(), new AstBasicDType($2, LOGIC_IMPLICIT))); } + | yCONST__ETC yVAR lifetimeE signingE rangeList { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, VFlagChildDType(), GRAMMARP->addRange(new AstBasicDType($2, LOGIC_IMPLICIT, $4), $5,false))); } // // // Expanded: "constE lifetimeE data_type" | /**/ data_type { /*VARRESET-in-ddVar*/ VARDTYPE($1); } | /**/ lifetime data_type { /*VARRESET-in-ddVar*/ VARDTYPE($2); } - | yCONST__ETC lifetimeE data_type { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, $3)); } + | yCONST__ETC lifetimeE data_type { /*VARRESET-in-ddVar*/ VARDTYPE(new AstConstDType($1, VFlagChildDType(), $3)); } // // = class_new is in variable_decl_assignment ; @@ -1336,7 +1336,8 @@ implicit_typeE: // IEEE: part of *data_type_or_implicit type_declaration: // ==IEEE: type_declaration // // Use idAny, as we can redeclare a typedef on an existing typedef - yTYPEDEF data_type idAny variable_dimensionListE ';' { $$ = new AstTypedef($1, *$3, GRAMMARP->createArray($2,$4,false)); SYMP->reinsert($$); } + yTYPEDEF data_type idAny variable_dimensionListE ';' { $$ = new AstTypedef($1, *$3, VFlagChildDType(), GRAMMARP->createArray($2,$4,false)); + SYMP->reinsert($$); } //UNSUP yTYPEDEF id/*interface*/ '.' idAny/*type*/ idAny/*type*/ ';' { $$ = NULL; $1->v3error("Unsupported: SystemVerilog 2005 typedef in this context"); } //UNSUP // // Combines into above "data_type id" rule // // Verilator: Not important what it is in the AST, just need to make sure the yaID__aTYPE gets returned @@ -3218,7 +3219,7 @@ AstNodeDType* V3ParseGrammar::createArray(AstNodeDType* basep, AstRange* rangep, while (rangep) { AstRange* prevp = rangep->backp()->castRange(); if (prevp) rangep->unlinkFrBack(); - arrayp = new AstArrayDType(rangep->fileline(), arrayp, rangep, isPacked); + arrayp = new AstArrayDType(rangep->fileline(), VFlagChildDType(), arrayp, rangep, isPacked); rangep = prevp; } } @@ -3252,7 +3253,7 @@ AstVar* V3ParseGrammar::createVariable(FileLine* fileline, string name, AstRange // Split RANGE0-RANGE1-RANGE2 into ARRAYDTYPE0(ARRAYDTYPE1(ARRAYDTYPE2(BASICTYPE3),RANGE),RANGE) AstNodeDType* arrayDTypep = createArray(dtypep,arrayp,false); - AstVar* nodep = new AstVar(fileline, type, name, arrayDTypep); + AstVar* nodep = new AstVar(fileline, type, name, VFlagChildDType(), arrayDTypep); nodep->addAttrsp(attrsp); if (GRAMMARP->m_varDecl != AstVarType::UNKNOWN) nodep->combineType(GRAMMARP->m_varDecl); if (GRAMMARP->m_varIO != AstVarType::UNKNOWN) nodep->combineType(GRAMMARP->m_varIO);