e_parse.y
来自「对于研究FPGA结构的人来说」· Y 代码 · 共 1,369 行 · 第 1/3 页
Y
1,369 行
{ free($1); } ; owner: '(' EP_owner StringToken ')' { free($3); } ;unit: '(' EP_unit StringToken ')' { ABORTTAG("unit"); } ;userData: '(' EP_userData { SKIPTAG("userData"); } ; library: '(' EP_library libraryNameDef edifLevel technology library_h ')' { if(!pLibraryHT) pLibraryHT = hash_alloc(DEFAULT_LIBRARIES, hash_hashfunc1, free_LIBRARY); VERBOSE("Adding library %s.\n", pActiveLibrary->name); hash_add(pLibraryHT, pActiveLibrary->name, pActiveLibrary); pActiveLibrary = NULL; } ;library_h: | status library_h | cell library_h | comment library_h | userData library_h ;libraryNameDef: nameDef { pActiveLibrary = (LIBRARY *) malloc(sizeof(LIBRARY)); mem_assert(pActiveLibrary); pActiveLibrary->name = $1; pActiveLibrary->pCellHT = hash_alloc(DEFAULT_CELLS, hash_hashfunc1, free_CELL); } ;external: '(' EP_external externalNameDef edifLevel technology external_h ')' { /* CHANGE */ if(pLibraryHT==NULL) pLibraryHT = hash_alloc(DEFAULT_LIBRARIES, hash_hashfunc1, free_LIBRARY); VERBOSE("Adding external library %s.\n", pActiveLibrary->name); hash_add(pLibraryHT, pActiveLibrary->name, pActiveLibrary); pActiveLibrary = NULL; } ;external_h: | status external_h | cell external_h | comment external_h | userData external_h ;externalNameDef: nameDef { debug("Beginning new library %s.\n", $1); pActiveLibrary = (LIBRARY *) malloc(sizeof(LIBRARY)); mem_assert(pActiveLibrary); pActiveLibrary->name = $1; pActiveLibrary->pCellHT = hash_alloc(DEFAULT_CELLS, hash_hashfunc1, free_CELL); } ;technology: '(' EP_technology { EP_skipping=1; } ;cell: '(' cell_tag cellNameDef cellType cell_h ')' { int i; NETLISTVIEW *pView; my_assert(pActiveCell && pActiveLibrary); /* Check that the cell has an interface */ if(!pActiveCell->pViewLL) { ERROR("Error: Cell %s has no interface.\n", pActiveCell->name); exit(1); } /* Check that the interface has a definition */ if(!pActiveCell->pViewLL->pFirstNet) { /* Oh oh! No definition */ CELL *pCell; int nIn; /* Get the entry from the default library */ pCell = hash_get(defaultLib->pCellHT, pActiveCell->name); if(!pCell) { if(opt.func) { ERROR("Error: Cell %s has no known definition.\n", pActiveCell->name); exit(-1); } else if(pActiveCell->pViewLL->nOutPorts != 1) { ERROR("Error: Cell %s has more than one output and no definition.\n", pActiveCell->name); exit(-1); } else { pActiveCell->pViewLL->tag = logic; pActiveCell->pViewLL->TT = NULL; } } else { VERBOSE("Found definition for undefined cell %s in defaultLib.\n", pActiveCell->name); if(pCell->pViewLL->nPorts != pActiveCell->pViewLL->nPorts || pCell->pViewLL->nOutPorts != pActiveCell->pViewLL->nOutPorts) { ERROR("Error: Cell %s's interface (# of ports) doesn't match definition.\n", pActiveCell->name); exit(1); } /* Was the reference an alias or a define/latch/map? */ if(pCell->pViewLL->ports) { int i; for(i=0; i<pCell->pViewLL->nPorts; i++) { if(strcmp(pCell->pViewLL->ports[i].name, pActiveCell->pViewLL->ports[i].name)) { ERROR("Error: Cell %s's port %s doesn't match definition (%s).\n", pActiveCell->name, pActiveCell->pViewLL->ports[i].name, pCell->pViewLL->ports[i].name); exit(1); } pActiveCell->pViewLL->ports[i].ignore = pCell->pViewLL->ports[i].ignore; } } /* Interface matches. */ pActiveCell->pViewLL->tag = pCell->pViewLL->tag; pActiveCell->pViewLL->pFirstInstance = NULL; pActiveCell->pViewLL->pFirstNet = NULL; pActiveCell->pViewLL->nIn = pCell->pViewLL->nIn; debug("Copying truth table.\n"); if(pActiveCell->pViewLL->tag == logic) { nIn = pActiveCell->pViewLL->nIn; nIn = (nIn>=3) ? (1 << (nIn-3)) : 1; pActiveCell->pViewLL->TT = (char *) malloc(nIn * sizeof(char)); mem_assert(pActiveCell->pViewLL->TT); memcpy(pActiveCell->pViewLL->TT, pCell->pViewLL->TT, nIn*sizeof(char)); } else { pActiveCell->pViewLL->output_pin = pCell->pViewLL->output_pin; pActiveCell->pViewLL->input_pin = pCell->pViewLL->input_pin; pActiveCell->pViewLL->clock_pin = pCell->pViewLL->clock_pin; } VERBOSE("Found match for cell %s.\n", pActiveCell->name); } } /* Retire the active cell to the active library */ debug("Add: pActiveCell (%s) to pActiveLibrary (%s) ->pCellHT\n", pActiveCell->name, pActiveLibrary->name); if(!hash_add(pActiveLibrary->pCellHT, pActiveCell->name, pActiveCell)) { ERROR("Error: Cell name %s already in active library.\n", pActiveCell->name); exit(1); } /* Set the last cell processed to be the current one (for purposes of figuring out what the top-level cell is in case it isn't given */ pLastCell = pActiveCell; /* Output cell information */ VERBOSE("Cell: %s.\n", pActiveCell->name); /* Output Detailed info */ pView = pActiveCell->pViewLL; for(; pView; pView = pView->pNextView) { verbose("\tNETLISTVIEW: %s (%d)\n", pView->name, pView->tag); verbose("\t\tInput pins:"); for(i=pView->nOutPorts; i<pView->nPorts; i++) verbose(" %s", pView->ports[i].name); verbose("\n\t\tOutput pins:"); for(i=0; i<pView->nOutPorts; i++) verbose(" %s", pView->ports[i].name); verbose("\n"); } pActiveCell = NULL; } ;cell_tag: EP_cell { if(pInOutHT) hash_free(pInOutHT); pInOutHT = hash_alloc(13, hash_hashfunc1, free_string); } ;cellNameDef: nameDef { my_assert(pActiveCell==NULL); /* Allocate the new cell */ debug("Beginning new cell %s.\n", $1); pActiveCell = (CELL *) malloc(sizeof(CELL)); mem_assert(pActiveCell); pActiveCell->name = $1; pActiveCell->pViewLL = NULL; } ;cellType: '(' EP_cellType NameToken ')' { /* Check whether this is a valid cellType */ if(strcasecmp("GENERIC", $3)) { ERROR("Error: cellType %s not " "recognized/supported in cell %s.\n", $3, pActiveCell->name); exit(1); } free($3); } ;cell_h: | status cell_h | viewMap cell_h | view cell_h | comment cell_h | userData cell_h | property cell_h ;viewMap: '(' EP_viewMap { SKIPTAG("viewMap"); } ;view: '(' EP_view viewNameDef viewType interface view_h ')' { my_assert(pActiveView); if(pActiveView->tag==noview) { ERROR("Error: No netlist view for cell %s. " "Ignoring.\n", pActiveCell->name); exit(-1); } /* Retire it to the view list of the active cell */ debug("Add: pActiveView (%s) to pActiveCell" " (%s) ->pViewLL\n", pActiveView->name, pActiveCell->name); pActiveView->pNextView = pActiveCell->pViewLL; pActiveCell->pViewLL = pActiveView; /* Miscellaneous clean-up or tag setting */ debug("Cleaning up pActiveView->tag (%d)\n", pActiveView->tag); switch(pActiveView->tag) { case netlist: debug("Free: pInstanceHT\n"); hash_free(pInstanceHT); break; default: ERROR("Error: No destruction instructions for active view."); } debug("Complete: View %s\n", pActiveView->name); pActiveView = NULL; } ;view_h: | status view_h | contents view_h | comment view_h | property view_h | userData view_h ;viewNameDef: nameDef { my_assert(!pActiveView); debug("Alloc: view %s.\n", $1); pActiveView = (NETLISTVIEW *) malloc(sizeof(NETLISTVIEW)); mem_assert(pActiveView); pActiveView->name = $1; pActiveView->tag = noview; pActiveView->ports = NULL; pActiveView->pFirstInstance = NULL; pActiveView->pFirstNet = NULL; pActiveView->TT = NULL; pActiveView->pNextView = NULL; } ;viewType: '(' EP_viewType NameToken ')' { my_assert(pActiveView); debug("ViewType: %s\n", $3); /* Check if viewType is valid and adjust valid view for type-specific fields */ if(!strcasecmp($3, "NETLIST")) { pActiveView->tag = netlist; /* Create hashtable for netlist */ debug("Alloc: new netlist hash table.\n"); pInstanceHT = hash_alloc(DEFAULT_INSTANCES, hash_hashfunc1, NULL); } else { pActiveView->tag = noview; WARN("Warning: viewType %s not supported. " "Attempting to skip...\n", $3); } free($3); } ;/* LIMIT: Partial */interface: '(' EP_interface interface_h ')' { /* If no active view, then ignore all info (unsupported view type) */ if(pActiveView->tag != noview) { PORT *pPort; int outPortIdx, inPortIdx; /* Allocate and initialize to NULL the pPortArray */ debug("Alloc: pActiveView->ports (%d)\n", pPortLL->nEntries); pActiveView->ports = (PORT *) malloc(pPortLL->nEntries * sizeof(PORT)); mem_assert(pActiveView->ports); memset(pActiveView->ports, 0, sizeof(PORT) * pPortLL->nEntries); pActiveView->nOutPorts = 0; pActiveView->nPorts = 0; /* FIRST PASS: * Count the number of output ports in the list */ LL_LOOP(pPortLL) { pPort = (PORT *) ll_get(pPortLL); if(pPort->direction == out) { pActiveView->nOutPorts++; } } debug("%d output ports found.\n", pActiveView->nOutPorts); /* SECOND PASS: * copy ports into the port array such that the output * ports are first, followed by the input ports */ outPortIdx = pActiveView->nOutPorts; inPortIdx = pActiveView->nPorts = pPortLL->nEntries; debug("copying ports into port array.\n"); LL_LOOP(pPortLL) { int index; /* Read the port from the list and determine its place in the array */ pPort = (PORT *) ll_get(pPortLL); if(pPort->direction == out) { index = --outPortIdx; } else { index = --inPortIdx; } pActiveView->ports[index].name = strdup(pPort->name); pActiveView->ports[index].direction = pPort->direction; pActiveView->ports[index].ignore = 0; pActiveView->ports[index].pNet = NULL; } debug("finished.\n"); } /* Reset pPortLL */ debug("Free: pPortLL\n"); ll_free(pPortLL); } ;interface_h: | designator interface_h | port interface_h ;designator: '(' EP_designator { SKIPTAG("designator"); } ;/* Partial */port: '(' EP_port nameDef port_h ')' { if(!pActivePort) { ERROR("Error: port %s declared without direction.\n", $3); exit(1); } /* Begin a new port list if necessary */ if(pPortLL == NULL) { debug("Alloc: port linked list\n"); pPortLL = ll_alloc(free_PORT); } if(pActivePort->direction == inout) { char buffer[512]; sprintf(buffer, "%s_in", $3); pActivePort->name = strdup(buffer); pActivePort->direction = in; ll_add(pPortLL, pActivePort); sprintf(buffer, "%s_out", $3); pActivePort = (PORT *) malloc(sizeof(PORT)); mem_assert(pActivePort); pActivePort->direction = out; pActivePort->name = strdup(buffer); pActivePort->ignore = 0; pActivePort->pNet = 0; ll_add(pPortLL, pActivePort); if(!hash_add(pInOutHT, $3, $3)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?