00001
00002 #if !defined(oagFpgaVerilogDesign_P)
00003 #define oagFpgaVerilogDesign_P
00004
00005 #include <string>
00006 #include <list>
00007
00008 namespace oagFpga {
00009
00010
00011
00012
00014
00015
00016
00017 class VerilogDesign {
00018
00019 private:
00020
00024 static const bool DELETE_UPON_DESTRUCTION = true;
00025
00026 public:
00027
00028 class AlwaysBlock;
00029 class Assignment;
00030 class Bundle;
00031 class Case;
00032 class Declaration;
00033 class Expression;
00034 class Function;
00035 class Instantiation;
00036 class Module;
00037 class Port;
00038 class PortConnection;
00039 class Primary;
00040 class Statement;
00041 class Trigger;
00042
00043 std::list<Module *> modules;
00044
00045
00046
00047
00049
00052
00053
00054
00055 class Module {
00056 public:
00057 std::string name;
00058
00059 VerilogDesign *design;
00060 std::list<Port*> *ports;
00061 std::list<Declaration*> declarations;
00062 std::list<Declaration*> parameters;
00063 std::list<Declaration*> *parameterOverrides;
00064 std::list<Assignment*> *assignments;
00065 std::list<AlwaysBlock*> *alwaysBlocks;
00066 std::list<Statement*> *initialBlocks;
00067 std::list<Function*> *functions;
00068 std::list<Instantiation*> *instantiations;
00069
00070 Module() {
00071 design = NULL;
00072 ports = NULL;
00073 assignments = NULL;
00074 alwaysBlocks = NULL;
00075 initialBlocks = NULL;
00076 functions = NULL;
00077 instantiations = NULL;
00078 };
00079
00080 ~Module();
00081 };
00082
00083
00084
00085
00092
00093
00094
00095 class Declaration {
00096 public:
00097
00098 std::string name;
00099 typedef enum{UNKNOWN,
00100 INPUT,
00101 OUTPUT,
00102 WIRE,
00103 REG,
00104 INOUT,
00105 PARAMETER,
00106 SUPPLY0,
00107 SUPPLY1,
00108 TRI,
00109 WIREAND,
00110 WIREOR,
00111 TRI0,
00112 TRI1,
00113 TRIAND,
00114 TRIOR
00115 } Type;
00116 Type type;
00117
00118 Expression *start, *stop;
00119 Expression *start2D, *stop2D;
00120
00121 Expression *value;
00122
00123 Declaration() { start = stop = start2D = stop2D = value = NULL; }
00124
00125 ~Declaration();
00126 };
00127
00128
00129
00130
00132
00133
00134
00135 class Function {
00136 public:
00137
00138 std::string name;
00139
00140 Expression *start, *stop;
00141
00142 std::list<Declaration *> *declarations;
00143 Statement *action;
00144
00145 Function() { start = stop = NULL; declarations = NULL; action = NULL; }
00146
00147 ~Function();
00148 };
00149
00150
00151
00152
00154
00155
00156
00157 class Port {
00158 public:
00159
00160 std::string externalName;
00161 int position;
00162 std::string internalName;
00163
00164
00165 ~Port() { }
00166 };
00167
00168
00169
00170
00177
00178
00179
00180 class Trigger {
00181 public:
00182 typedef enum{UNKNOWN,
00183 BOTH,
00184 POSEDGE,
00185 NEGEDGE} Type;
00186 Type type;
00187 Expression *net;
00188
00189 Trigger() { net = NULL; }
00190
00191 ~Trigger();
00192 };
00193
00194
00195
00196
00198
00199
00200
00201 class Assignment {
00202 public:
00203
00204 Expression *lval;
00205 Expression *value;
00206
00207 Assignment() { lval = value = NULL; }
00208
00209 ~Assignment();
00210 };
00211
00212
00213
00214
00216
00217
00218
00219 class AlwaysBlock {
00220 public:
00221
00222 std::list<Trigger*> *triggers;
00223 Statement *action;
00224
00225 AlwaysBlock() { triggers = NULL; action = NULL; }
00226
00227 ~AlwaysBlock();
00228 };
00229
00230
00231
00232
00233
00235
00236
00237
00238 class Case {
00239 public:
00240 std::list<Expression*> *conditions;
00241 Statement *action;
00242 bool isDefault;
00243
00244 Case() { conditions = NULL; action = NULL; }
00245
00246 ~Case();
00247 };
00248
00249
00250
00251
00260
00261
00262
00263 class Statement {
00264 public:
00265
00266 typedef enum{NOP,
00267 BLOCK,
00268 IF,
00269 CASE, CASEX, CASEZ,
00270 BLOCKING_ASSIGNMENT,
00271 NONBLOCKING_ASSIGNMENT} Type;
00272 Type type;
00273
00274
00275 struct {
00276 Expression *condition;
00277 Statement *ifTrue;
00278 Statement *ifFalse;
00279
00280 std::list<Case*> *cases;
00281 } ifc;
00282
00283
00284 struct {
00285 Expression *lval;
00286 Expression *rval;
00287 } assign;
00288
00289
00290 struct {
00291 std::list<Statement *> *block;
00292 std::list<Declaration*> *declarations;
00293 } begin_end;
00294
00295 std::string name;
00296
00297 Statement() {
00298 type = NOP;
00299 ifc.condition = NULL;
00300 ifc.ifTrue = ifc.ifFalse = NULL;
00301 ifc.cases = NULL;
00302 assign.lval = assign.rval = NULL;
00303 begin_end.block = NULL;
00304 begin_end.declarations = NULL;
00305 }
00306
00307 ~Statement();
00308 };
00309
00310
00311
00312
00314
00315
00316
00317 class Instantiation {
00318 public:
00319
00320 std::string name;
00321 std::string type;
00322 typedef enum { ISNT_PRIMITIVE,
00323 AND, NAND,
00324 OR, NOR,
00325 XOR, XNOR,
00326 NOT, BUF } PrimitiveType;
00327 PrimitiveType primitive;
00328
00329 std::list<Expression*> *parameters;
00330 std::list<PortConnection*> *connections;
00331
00332 Instantiation() { parameters = NULL; connections = NULL; }
00333
00334 ~Instantiation();
00335 };
00336
00337
00338
00339
00341
00342
00343
00344 class PortConnection {
00345 public:
00346
00347 std::string name;
00348 int position;
00349 Expression *value;
00350
00351 PortConnection() { position = -1; value = NULL; }
00352 PortConnection(const std::string &n, int p, Expression *v) { name = n; position = p; value = v; }
00353
00354
00355 ~PortConnection();
00356 };
00357
00358
00359
00360
00376
00377
00378
00379 class Expression {
00380 public:
00381
00382 typedef enum{UNKNOWN,
00383 PRIMARY,
00384 BUNDLE,
00385 BITWISE_AND, BITWISE_NAND,
00386 BITWISE_OR, BITWISE_NOR,
00387 BITWISE_XOR, BITWISE_XNOR,
00388 BITWISE_NOT,
00389 LOGICAL_AND, LOGICAL_NOT, LOGICAL_OR,
00390 REDUCTION_AND, REDUCTION_OR, REDUCTION_XOR,
00391 REDUCTION_NAND, REDUCTION_NOR, REDUCTION_XNOR,
00392 LESS_THAN, LESS_THAN_EQUAL,
00393 GREATER_THAN, GREATER_THAN_EQUAL,
00394 EQUAL, NOTEQUAL,
00395 IF_ELSE,
00396 LEFT_SHIFT, RIGHT_SHIFT,
00397 ADD, SUBTRACT,
00398 MULTIPLY,
00399 DIVIDE, MODULO,
00400 NEGATE} Operator;
00401 Operator type;
00402
00403 union {
00404 Expression *op1;
00405 Primary *primary;
00406 Bundle *bundle;
00407 };
00408
00409 Expression *op2, *op3;
00410
00411 Expression() { op1 = op2 = op3 = NULL; type = UNKNOWN; }
00412 Expression(Primary *p) { primary = p; type = PRIMARY; }
00413 Expression(Bundle *b) { bundle = b; type = BUNDLE; }
00414 Expression(Expression *e1) { op1 = e1; op2 = op3 = NULL; type = UNKNOWN; }
00415 Expression(Expression *e1, Expression *e2) { op1 = e1; op2 = e2; op3 = NULL; type = UNKNOWN; }
00416 Expression(Expression *e1,
00417 Expression *e2,
00418 Expression *e3) { op1 = e1; op2 = e2; op3 = e3; type = UNKNOWN; }
00419
00420
00421 ~Expression();
00422 };
00423
00424
00425
00426
00434
00435
00436
00437 class Primary {
00438 public:
00439
00440 typedef enum{UNKNOWN,
00441 NET,
00442 CONST,
00443 FUNCTION_CALL} Type;
00444 Type type;
00445
00446 std::string name;
00447
00448 struct {
00449 bool negative;
00450 unsigned int intValue;
00451 int bitWidth;
00452 unsigned int xMask, zMask;
00453 } number;
00454
00455 struct {
00456 Expression *start;
00457 Expression *stop;
00458 } range;
00459
00460 std::list<Expression *> *arguments;
00461
00462 Primary(const std::string &n) {
00463
00464 name = n; range.start = range.stop = NULL; type = NET;
00465 arguments = NULL;
00466 }
00467 Primary(unsigned int v, unsigned int w) {
00468
00469 range.start = range.stop = NULL;
00470 number.intValue = v; number.bitWidth = w;
00471 type = CONST; number.negative = false;
00472 arguments = NULL;
00473 }
00474 Primary(const std::string &n, Expression *i) {
00475
00476 name = n; range.start = range.stop = i; type = NET;
00477 arguments = NULL;
00478 }
00479 Primary(const std::string &n, Expression *f, Expression *l) {
00480
00481 name = n; range.start = f; range.stop = l; type = NET;
00482 arguments = NULL;
00483 }
00484 Primary(const std::string &n, std::list<Expression *> *args) {
00485
00486 name = n; arguments = args; type = FUNCTION_CALL;
00487 range.start = range.stop = NULL;
00488 }
00489
00490
00491 ~Primary();
00492 };
00493
00494
00495
00496
00498
00499
00500
00501 class Bundle {
00502 public:
00503
00504 std::list<Expression*> *members;
00505 Expression *replication;
00506
00507 Bundle(std::list<Expression*> *m) { members = m; replication = NULL;}
00508 Bundle(std::list<Expression*> *m, class Expression *r) { members = m; replication = r;}
00509
00510 ~Bundle();
00511 };
00512
00513 ~VerilogDesign();
00514 };
00515
00516 }
00517
00518 #endif