|
53 | 53 | #define NEWSTRING(text) (string((text))) |
54 | 54 | #define SPACED(a,b) ((a)+(((a)=="" || (b)=="")?"":" ")+(b)) |
55 | 55 |
|
| 56 | +#define VARS_PUSH() { GRAMMARP->m_varStack.push_back(GRAMMARP->m_var); } |
| 57 | +#define VARS_POP() { GRAMMARP->m_var = GRAMMARP->m_varStack.back(); GRAMMARP->m_varStack.pop_back(); } |
| 58 | + |
56 | 59 | #define VARRESET_LIST(decl) { GRAMMARP->pinNum(1); VARRESET(); VARDECL(decl); } // Start of pinlist |
57 | 60 | #define VARRESET_NONLIST(decl) { GRAMMARP->pinNum(0); VARRESET(); VARDECL(decl); } // Not in a pinlist |
58 | 61 | #define VARRESET() { VARDECL(""); VARIO(""); VARNET(""); VARDTYPE(""); } // Start of one variable decl |
59 | 62 |
|
60 | 63 | // VARDECL("") indicates inside a port list or IO list and we shouldn't declare the variable |
61 | | -#define VARDECL(type) { GRAMMARP->m_varDecl = (type); } // genvar, parameter, localparam |
62 | | -#define VARIO(type) { GRAMMARP->m_varIO = (type); } // input, output, inout, ref, const ref |
63 | | -#define VARNET(type) { GRAMMARP->m_varNet = (type); } // supply*,wire,tri |
64 | | -#define VARDTYPE(type) { GRAMMARP->m_varDType = (type); } // "signed", "int", etc |
| 64 | +#define VARDECL(type) \ |
| 65 | + { GRAMMARP->m_var.m_decl = (type); } // genvar, parameter, localparam |
| 66 | +#define VARIO(type) \ |
| 67 | + { GRAMMARP->m_var.m_io = (type); } // input, output, inout, ref, const ref |
| 68 | +#define VARNET(type) \ |
| 69 | + { GRAMMARP->m_var.m_net = (type); } // supply*,wire,tri |
| 70 | +#define VARDTYPE(type) \ |
| 71 | + { GRAMMARP->m_var.m_dtype = (type); } // "signed", "int", etc |
65 | 72 |
|
66 | 73 | #define PINNUMINC() { GRAMMARP->pinNumInc(); } |
67 | 74 |
|
|
70 | 77 |
|
71 | 78 | enum net_idx {NI_NETNAME = 0, NI_MSB, NI_LSB}; |
72 | 79 |
|
73 | | -static void VARDONE(VFileLine* fl, const string& name, const string& array, const string& value) { |
74 | | - if (GRAMMARP->m_varIO!="" && GRAMMARP->m_varDecl=="") GRAMMARP->m_varDecl="port"; |
75 | | - if (GRAMMARP->m_varDecl!="") { |
76 | | - PARSEP->varCb(fl, GRAMMARP->m_varDecl, name, PARSEP->symObjofUpward(), GRAMMARP->m_varNet, |
77 | | - GRAMMARP->m_varDType, array, value); |
| 80 | +static void VARDONE(VFileLine * fl, const string& name, const string& array, const string& value) { |
| 81 | + if (GRAMMARP->m_var.m_io != "" && GRAMMARP->m_var.m_decl == "") |
| 82 | + GRAMMARP->m_var.m_decl = "port"; |
| 83 | + if (GRAMMARP->m_var.m_decl != "") { |
| 84 | + PARSEP->varCb(fl, GRAMMARP->m_var.m_decl, name, PARSEP->symObjofUpward(), |
| 85 | + GRAMMARP->m_var.m_net, GRAMMARP->m_var.m_dtype, array, value); |
78 | 86 | } |
79 | | - if (GRAMMARP->m_varIO!="" || GRAMMARP->pinNum()) { |
80 | | - PARSEP->portCb(fl, name, PARSEP->symObjofUpward(), |
81 | | - GRAMMARP->m_varIO, GRAMMARP->m_varDType, array, GRAMMARP->pinNum()); |
| 87 | + if (GRAMMARP->m_var.m_io != "" || GRAMMARP->pinNum()) { |
| 88 | + PARSEP->portCb(fl, name, PARSEP->symObjofUpward(), GRAMMARP->m_var.m_io, |
| 89 | + GRAMMARP->m_var.m_dtype, array, GRAMMARP->pinNum()); |
82 | 90 | } |
83 | | - if (GRAMMARP->m_varDType == "type") { |
84 | | - PARSEP->syms().replaceInsert(VAstType::TYPE,name); |
| 91 | + if (GRAMMARP->m_var.m_dtype == "type") { |
| 92 | + PARSEP->syms().replaceInsert(VAstType::TYPE, name); |
85 | 93 | } |
86 | 94 | } |
87 | 95 |
|
88 | 96 | static void VARDONETYPEDEF(VFileLine* fl, const string& name, const string& type, const string& array) { |
89 | 97 | VARRESET(); VARDECL("typedef"); VARDTYPE(type); |
90 | 98 | VARDONE(fl,name,array,""); |
91 | 99 | // TYPE shouldn't override a more specific node type, as often is forward reference |
92 | | - PARSEP->syms().replaceInsert(VAstType::TYPE,name); |
| 100 | + PARSEP->syms().replaceInsert(VAstType::TYPE, name); |
93 | 101 | } |
94 | 102 |
|
95 | 103 | static void parse_net_constants(VFileLine* fl, VParseHashElem nets[][3]) { |
@@ -1543,8 +1551,11 @@ struct_union_memberList: // IEEE: { struct_union_member } |
1543 | 1551 | ; |
1544 | 1552 |
|
1545 | 1553 | struct_union_member: // ==IEEE: struct_union_member |
1546 | | - random_qualifierE data_type_or_void { VARRESET_NONLIST("member"); VARDTYPE(SPACED($1,$2)); } |
1547 | | - /*cont*/ list_of_variable_decl_assignments ';' { } |
| 1554 | + random_qualifierE data_type_or_void |
| 1555 | + { VARS_PUSH(); // Structs can be recursive, or under a parameter typs |
| 1556 | + VARRESET_NONLIST("member"); VARDTYPE(SPACED($1,$2)); } |
| 1557 | + /*cont*/ list_of_variable_decl_assignments ';' |
| 1558 | + { VARS_POP(); } |
1548 | 1559 | ; |
1549 | 1560 |
|
1550 | 1561 | list_of_variable_decl_assignments: // ==IEEE: list_of_variable_decl_assignments |
@@ -1739,12 +1750,12 @@ data_declarationVarFrontClass: // IEEE: part of data_declaration (for class_prop |
1739 | 1750 | // // VARRESET called before this rule |
1740 | 1751 | // // yCONST is removed, added to memberQual rules |
1741 | 1752 | // // implicit_type expanded into /*empty*/ or "signingE rangeList" |
1742 | | - yVAR lifetimeE data_type { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_varDType,$3)); } |
1743 | | - | yVAR lifetimeE { VARDECL("var"); VARDTYPE(GRAMMARP->m_varDType); } |
1744 | | - | yVAR lifetimeE signingE rangeList { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_varDType,SPACED($3,$4))); } |
| 1753 | + yVAR lifetimeE data_type { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_var.m_dtype, $3)); } |
| 1754 | + | yVAR lifetimeE { VARDECL("var"); VARDTYPE(GRAMMARP->m_var.m_dtype); } |
| 1755 | + | yVAR lifetimeE signingE rangeList { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_var.m_dtype, SPACED($3, $4))); } |
1745 | 1756 | // |
1746 | 1757 | // // Expanded: "constE lifetimeE data_type" |
1747 | | - | /**/ data_typeVar { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_varDType,$1)); } |
| 1758 | + | /**/ data_typeVar { VARDECL("var"); VARDTYPE(SPACED(GRAMMARP->m_var.m_dtype, $1)); } |
1748 | 1759 | // // lifetime is removed, added to memberQual rules to avoid conflict |
1749 | 1760 | // // yCONST is removed, added to memberQual rules to avoid conflict |
1750 | 1761 | // // = class_new is in variable_decl_assignment |
|
0 commit comments