1 /**************************************************************************** 2 Copyright (C) 1987-2015 by Jeffery P. Hansen 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 18 Last edit by hansen on Fri Jan 9 22:53:43 2009 19 ****************************************************************************/ 20 #ifndef __mitem_h 21 #define __mitem_h 22 23 /* 24 * Module item flags 25 */ 26 #define MIF_IMMEDIATE 0x1 /* Schedule item for immediate execution on startup */ 27 28 29 /***************************************************************************** 30 * 31 * itemcode_t - code for module item type 32 * 33 *****************************************************************************/ 34 typedef enum { 35 IC_ASSIGN, /* assign statement */ 36 IC_ALWAYS, /* always statement */ 37 IC_INITIAL, /* initial statement */ 38 IC_INSTANCE, /* module instantiation */ 39 IC_PARAMETER, /* module parameter */ 40 IC_REGINIT, /* register initialization */ 41 IC_NETDECL, /* net declaration */ 42 IC_GATE, /* gate instantiation */ 43 } itemcode_t; 44 45 /***************************************************************************** 46 * 47 * gateargcode_t - code for primitive gate argument handling 48 * 49 *****************************************************************************/ 50 typedef enum { 51 GAC_MULTIN, /* Multiple inputs */ 52 GAC_MULTOUT, /* Multiple outputs */ 53 GAC_FIXED, /* Fixed number of ports */ 54 } gateargcode_t; 55 56 typedef struct GateDesc_str { 57 int gd_code; /* Code for this gate type */ 58 char *gd_name; /* Name of this gate type */ 59 gateargcode_t gd_gac; /* Gate argument handling */ 60 int gd_minPorts; /* Minimum number of ports */ 61 valueop_f *gd_baseFunc; /* Base function */ 62 valueop_f *gd_outFunc; /* Final output function */ 63 } GateDesc; 64 65 /***************************************************************************** 66 * 67 * NetDecl - Declaration of a net in a module. 68 * 69 * 70 *****************************************************************************/ 71 typedef struct { 72 char *n_name; /* Name of net */ 73 nettype_t n_type; /* Type of net */ 74 VRange *n_range; /* Range for declaration (object is shared) */ 75 VRange *n_addrRange; /* Address range for memories */ 76 Place n_place; /* Place where net was declared */ 77 } NetDecl; 78 79 80 typedef VGThread *MIgenerate_f(ModuleItem *mi,ModuleInst *modCtx,CodeBlock *cb); 81 typedef void MIprint_f(ModuleItem *mi,FILE *f); 82 83 /***************************************************************************** 84 * 85 * Vtable for MItem objects 86 * 87 *****************************************************************************/ 88 typedef struct { 89 MIgenerate_f *miv_generate; /* Generate code */ 90 MIprint_f *miv_print; /* Print mitem */ 91 } MItemVTable; 92 93 94 /***************************************************************************** 95 * 96 * MICommon - Common field in mitem objects 97 * 98 *****************************************************************************/ 99 typedef struct { 100 itemcode_t mb_type; /* Type code of mitem */ 101 MItemVTable *mb_vtable; /* Virtual function pointer table */ 102 Place mb_place; /* Location of declaration */ 103 DynamicModule *mb_dynMod; /* Dynamic module if dynamically loaded */ 104 unsigned mb_flags; /* Item flags */ 105 } MICommon; 106 107 /***************************************************************************** 108 * 109 * MIParameter - A parameter declaration 110 * 111 *****************************************************************************/ 112 typedef struct { 113 MICommon mip_common; /* Common fields */ 114 const char *mip_name; /* Name of parameter */ 115 Expr *mip_expr; /* Parameter expression */ 116 int mip_ppPos; /* Parameter port position (-1 if not port) */ 117 } MIParameter; 118 119 /***************************************************************************** 120 * 121 * MINetDecl - A net declaration 122 * 123 *****************************************************************************/ 124 typedef struct { 125 MICommon mid_common; /* Common fields */ 126 NetDecl *mid_decl; /* Net declaration */ 127 } MINetDecl; 128 129 /***************************************************************************** 130 * 131 * MIAssign - An assignment 132 * 133 * Examples: 134 * assign w2 = a & b; 135 * assign w3 = #5 a & b; 136 * assign {w4,w5[2]} = #5 a & b; 137 * 138 *****************************************************************************/ 139 typedef struct { 140 MICommon mia_common; /* Common fields */ 141 Expr *mia_lhs; /* Left hand side of assignment */ 142 Expr *mia_rhs; /* Right hand side of assignment */ 143 Expr *mia_bcond; /* Block condition (delay/trigger) */ 144 } MIAssign; 145 146 /***************************************************************************** 147 * 148 * MIBlock - An initial or always block 149 * 150 *****************************************************************************/ 151 typedef struct { 152 itemcode_t mib_type; /* Type code IC_INITIAL or IC_ALWAYS */ 153 Place mib_place; /* Location of declaration */ 154 StatDecl *mib_stat; /* Statement to execute */ 155 } MIBlock; 156 157 /***************************************************************************** 158 * 159 * MIInstance - An instance item 160 * 161 *****************************************************************************/ 162 typedef struct { 163 MICommon mii_common; /* Common fields */ 164 const char *mii_name; /* Name of instance type */ 165 const char *mii_instName; /* Name of instance */ 166 VRange *mii_slices; /* Range/number of slices */ 167 List/*NameExpr*/ *mii_parms; /* Parameters */ 168 List/*NameExpr*/ *mii_ports; /* Ports */ 169 } MIInstance; 170 171 172 /***************************************************************************** 173 * 174 * MIGate - A gate instance item 175 * 176 *****************************************************************************/ 177 typedef struct { 178 MICommon mig_common; /* Common fields */ 179 GateDesc *mig_desc; /* Type description */ 180 Expr *mig_delay; /* Delay expression */ 181 const char *mig_instName; /* Name of instance */ 182 VRange *mig_slices; /* Range/number of slices */ 183 List/*Expr*/ *mig_ports; /* Ports */ 184 } MIGate; 185 186 187 /***************************************************************************** 188 * 189 * ModuleItem - Object that can be at the top level in a module description. 190 * 191 * There are four types of modules items: assign, initial, always, instance. 192 * 193 *****************************************************************************/ 194 union ModuleItem_uni { 195 itemcode_t mi_type; /* Type of module item */ 196 MICommon mi_base; /* Base item members */ 197 MIAssign mi_asgn; /* An "assign" item */ 198 MIBlock mi_block; /* An "initial" or "always" item */ 199 MIInstance mi_inst; /* An instance item */ 200 MIGate mi_gate; /* An gate instance item */ 201 MINetDecl mi_netdec; /* An net declaration item */ 202 MIParameter mi_parm; /* An parameter item */ 203 }; 204 205 /***************************************************************************** 206 * ModuleItem methods 207 *****************************************************************************/ 208 ModuleItem *new_ModuleItem(itemcode_t); 209 void ModuleItem_print(ModuleItem *mi,FILE *f); 210 VGThread *ModuleItem_generate(ModuleItem *mi,ModuleInst *modCtx,CodeBlock *cb); 211 #define ModuleItem_getPlace(mi) (&((ModuleItem*)(mi))->mi_base.mb_place) 212 #define ModuleItem_getType(mi) (mi)->mi_type 213 #define ModuleItem_getDynamicModule(mi) ((ModuleItem*)(mi))->mi_base.mb_dynMod 214 #define ModuleItem_setDynamicModule(mi,dm) (((ModuleItem*)(mi))->mi_base.mb_dynMod = (dm)) 215 void ModuleItem_killNotify(ModuleItem *mi); 216 #define ModuleItem_getFlags(mi) (mi)->mi_flags.mb_flags 217 #define ModuleItem_setFlags(mi,flags) ((mi)->mi_base.mb_flags |= (flags)) 218 #define ModuleItem_clearFlags(mi,flags) ((mi)->mi_base.mi_flags &= ~(flags)) 219 220 /***************************************************************************** 221 * MIAssign methods 222 *****************************************************************************/ 223 MIAssign *new_MIAssign(Expr*,Expr*,Expr*); 224 int MIAssign_pathdGenerate(MIAssign *mia,ModuleInst *mi,CodeBlock *codeBlock,List *asgns); 225 226 /***************************************************************************** 227 * MIBlock methods 228 *****************************************************************************/ 229 MIBlock *new_MIBlock(itemcode_t,StatDecl*); 230 231 /***************************************************************************** 232 * MIInstance methods 233 *****************************************************************************/ 234 MIInstance *new_MIInstance(const char *name, const char *instName, VRange *slices, List *parms, List *ports); 235 Expr *MIInstance_findParm(MIInstance *mi,const char *name, int ppIdx); 236 237 /***************************************************************************** 238 * MIGate methods 239 *****************************************************************************/ 240 MIGate *new_MIGate(unsigned gateType, Expr *delay, const char *instName, VRange *slices, List *ports); 241 int MIGate_pathdGenerate(MIGate *mig,ModuleInst *mi,CodeBlock *codeBlock,List *asgns); 242 243 /***************************************************************************** 244 * MINetDecl methods 245 *****************************************************************************/ 246 MINetDecl *new_MINetDecl(NetDecl *nd); 247 248 /***************************************************************************** 249 * MIParameter methods 250 *****************************************************************************/ 251 MIParameter *new_MIParameter(const char *name,Expr *expr); 252 253 /***************************************************************************** 254 * NetDecl methods 255 *****************************************************************************/ 256 NetDecl *new_NetDecl(const char *name,int wtype,VRange *range,VRange *addrRange,Place *place); 257 #define NetDecl_getType(nd) (nd)->n_type 258 #define NetDecl_getRange(nd) (nd)->n_range 259 #define NetDecl_getName(nd) (nd)->n_name 260 #define NetDecl_getPlace(nd) (&(nd)->n_place) 261 262 int NT_getStr(nettype_t nt,char *buf); 263 void NT_printDecl(nettype_t nt,FILE *f); 264 265 #endif 266