e_parse.y
来自「对于研究FPGA结构的人来说」· Y 代码 · 共 1,369 行 · 第 1/3 页
Y
1,369 行
%{/*------------------------------------------------------------------------** Copyright 1998 by Paul Leventis, Jonathan Rose and the University of ** Toronto. Use is permitted, provided that this attribution is retained ** and no part of the code is re-distributed or included in any commercial ** product except by written agreement with the above parties. ** ** For more information, contact us directly: ** Paul Leventis (leventi@eecg.utoronto.ca) ** Jonathan Rose (jayar@eecg.toronto.edu) ** Department of Electrical and Computer Engineering ** University of Toronto, 10 King's College Rd., ** Toronto, Ontario, CANADA M5S 1A4 ** Phone: (416) 978-6992 Fax: (416) 971-2286 **------------------------------------------------------------------------*//* e_parse.y * * Grammar for EDIF parser * This implements a sub-set of the EDIF grammar. So far, it can handle * MCNC edif. This list will hopefully grow longer when testing commences. * * This code slowly grew and changed as my data structures and support code * changed. As a result, my coding style and even ways I did things range * from obscure to silly. The main thing to change is the gross amount of * dynamic memory allocation, and the instantiations for CELLS, etc. should * be done in subroutines. But I'd really like to start on a neat placement * tool, so the tool will have to be memory inefficient and slow. * * POSSIBLE BUGS: Memory leaks. I think I've got them all, but you never know. * * NOTE: This code is currently NOT reentrant. The change to do so requires * saving a couple of the globals/pushing them on a stack, and doing two * things having to do with bison that I just don't remember right * now.*//* Fixes problems with size of the files the parser can handle. * Increase this value if you run into problems.*/#define YYMAXDEPTH 300000#include <stdio.h>#include <stdlib.h>#include <string.h>#include "e_graph.h"#include "e_ll.h"#include "e_hash.h"#include "e_shared.h"/* Various optional print statements */#define debug (!0) ? 1 : printf#define info (!opt.edif_info) ? 1 : printf#define warn (!opt.edif_warn) ? 1 : printf#define verbose (!opt.edif_verbose) ? 1 : printf#define error printf#define WARN (!opt.edif_warn) ? 1 : printf("line %4d: ", EP_lineno), warn#define VERBOSE (!opt.edif_verbose) ? 1 : printf("line %4d: ", EP_lineno), verbose #define ERROR printf("line %4d: ", EP_lineno), error #define SKIPTAG(msg) { \ if(!opt.edif_warn_once) \ WARN("Warning: Skipping unsupported/unknown tag %s\n", msg); \ else if(!hash_get(pWarningHT, msg)) { \ WARN("Warning: Skipping unsupported/unknown tag %s\n", msg); \ hash_add(pWarningHT, msg, (void *) 1); \ } \ EP_skipping=1; \}#define WARNTAG(msg) { \ if(!opt.edif_warn_once) \ WARN("Warning: Partially supported tag %s\n", msg); \ else if(!hash_get(pWarningHT, msg)) { \ WARN("Warning: Partially supported tag %s\n", msg); \ hash_add(pWarningHT, msg, (void *) 1); \ } \} #define ABORTTAG(msg) { \ ERROR("Error: Unsupported tag '%s'.\n" \ "Please e-mail the offending code fragment to Paul Leventis (leventi@eecg.utoronto.ca)\n" \ , msg); \ exit(1); \}/* GLOBALS */int EP_skipping=0;int EP_lineno=1;int EP_tokenpos=1;HASH_TABLE *pLibraryHT = NULL;/* INTERNAL GLOBALS *//* Active items */static CELL *pActiveCell = NULL;static PORT *pActivePort = NULL;static LIBRARY *pActiveLibrary = NULL;static NETLISTVIEW *pActiveView = NULL;static INSTANCE *pActiveInstance = NULL;/* Storage */static LL *pPortLL = NULL;static LL *pPortRefLL = NULL;static HASH_TABLE *pInstanceHT = NULL;static HASH_TABLE *pInOutHT = NULL;static CELL *pLastCell = NULL;/* Warning Flags *//* Used to stop warnings from happening continuously */static HASH_TABLE *pWarningHT = NULL;int warning_1pin = 0;/* EXPORTS */LIBRARY *defaultLib = NULL;CELL *pTopCell = NULL;void ep_parse(FILE *fp);void free_string(void *pPayload){ free((char *)pPayload);}%}%union { int iVal; char *sVal; struct INSTANCE_type *pInstance; struct CELL_type *pCell; struct LIBRARY_type *pLibrary; struct NET_type *pNet; struct PORTREF_type *pPortRef; struct NETLISTVIEW_type *pView;}%token <iVal> IntegerToken%token <sVal> StringToken NameToken%type <sVal> version nameDef nameRef rename name rename_h1 rename_h2 %type <pCell> cellRef%type <pLibrary> libraryRef%type <pInstance> instanceRef%type <pPortRef> portRef/* Status */%token EP_written EP_timeStamp EP_author EP_program EP_dataOrigin%token EP_property EP_userData%token EP_acload EP_after EP_annotate EP_apply %token EP_arc EP_array EP_arrayMacro EP_arrayRelatedInfo %token EP_arraySite EP_atLeast EP_atMost EP_author %token EP_baseArray EP_becomes EP_between EP_boolean %token EP_booleanDisplay EP_booleanMap EP_booleanValue EP_borderPattern %token EP_borderWidth EP_boundingBox EP_cell EP_cellNameDef %token EP_cellNameRef EP_cellRef EP_cellType EP_change %token EP_circle EP_color EP_comment EP_commentGraphics %token EP_compound EP_connectLocation EP_contents EP_cornerType %token EP_criticality EP_currentMap EP_curve EP_cycle %token EP_dataOrigin EP_dcFaninLoad EP_dcFanoutLoad EP_dcMaxFanin %token EP_dcMaxFanout EP_delay EP_delta EP_derivation %token EP_design EP_designator EP_designNameDef EP_difference %token EP_direction EP_display EP_dominates EP_dot %token EP_duration EP_e EP_edif EP_ediffileNameDef %token EP_edifLevel EP_edifVersion EP_enclosureDistance EP_endType %token EP_entry EP_event EP_exactly EP_external %token EP_fabricate EP_false EP_figure EP_figureArea %token EP_figureGroup EP_figuregroupNameDef EP_figuregroupNameRef EP_figureGroupObject %token EP_figureGroupOverride EP_figureGroupRef EP_figureOp EP_figurePerimeter %token EP_figureWidth EP_fillPattern EP_follow EP_forbiddenEvent %token EP_form EP_globalPortRef EP_greaterThan EP_gridMap %token EP_ignore EP_includeFiguregroup EP_initial EP_instance %token EP_instanceBackAnnotate EP_instanceGroup EP_instanceMap EP_instanceNameDef %token EP_instanceNameRef EP_instanceRef EP_integer EP_integerDisplay %token EP_integerValue EP_interface EP_interFiguregroupSpacing EP_intersection %token EP_intraFigureGroupSpacing EP_inverse EP_isolated EP_joined %token EP_justify EP_keywordDisplay EP_keywordLevel EP_keywordMap %token EP_keywordNameRef EP_layerNameDef EP_lessThan EP_library %token EP_libraryRef EP_listOfNets EP_listOfPorts EP_loadDelay %token EP_logicAssign EP_logicInput EP_logicList EP_logicMapInput %token EP_logicMapOutput EP_logicNameDef EP_logicNameRef EP_logicOneOf %token EP_logicOutput EP_logicPort EP_logicRef EP_logicValue %token EP_logicWaveform EP_maintain EP_match EP_member EP_minomax %token EP_mnm EP_multipleValueSet EP_mustJoin EP_name %token EP_nameDef EP_nameRef EP_net EP_netBackAnnotate %token EP_netBundle EP_netDelay EP_netgroup EP_netMap %token EP_netRef EP_noChange EP_nonPermutable EP_notAllowed %token EP_notchSpacing EP_number EP_numberDefinition EP_numberDisplay %token EP_numberValue EP_offPageConnector EP_offsetEvent EP_openShape %token EP_orientation EP_origin EP_overhangDistance EP_overlapDistance %token EP_oversize EP_owner EP_page EP_pageSize %token EP_parameter EP_parameterAssign EP_parameterDisplay EP_path %token EP_pathDelay EP_pathWidth EP_permutable EP_physicalDesignRule %token EP_plug EP_point EP_pointDisplay EP_pointList %token EP_pointValue EP_polygon EP_port EP_portBackAnnotate %token EP_portBundle EP_portDelay EP_portGroup EP_portImplementation %token EP_portInstance EP_portList EP_portListAlias EP_portMap %token EP_portRef EP_program EP_property EP_propertyDisplay %token EP_propertyNameDef EP_propertyNameRef EP_protectionFrame EP_pt %token EP_range EP_rangeVector EP_rectangle EP_rectangleSize %token EP_rename EP_resolves EP_ruleNameDef EP_scale %token EP_scaledInteger EP_scaleX EP_scaleY EP_section %token EP_shape EP_simulate EP_simulateNameDef EP_simulationInfo %token EP_singleValueSet EP_site EP_socket EP_socketSet %token EP_status EP_steady EP_string EP_stringDisplay %token EP_stringValue EP_strong EP_symbol EP_symmetry %token EP_table EP_tableDefault EP_technology EP_textHeight %token EP_timeInterval EP_timeStamp EP_timing EP_transform %token EP_transition EP_trigger EP_true EP_typedValue %token EP_unconstrained EP_undefined EP_union EP_unit %token EP_unused EP_userData EP_version EP_view %token EP_viewList EP_viewMap EP_viewNameDef EP_viewNameRef %token EP_viewRef EP_viewType EP_visible EP_voltageMap %token EP_waveValue EP_weak EP_weakJoined EP_when %token EP_written%% goal: edif { if(opt.edif_warn_once) { info("Note: To view more than one warning, run with the -edif_warn_once flag\n"); } if(pTopCell==NULL) { warn("No top cell specified. Assuming last cell in file.\n"); pTopCell = pLastCell; } info("Top level cell: %s\n", pTopCell->name); /* Clean up */ hash_free(pWarningHT); /* Done; Success! */ return 0; } ;display: '(' EP_display { ABORTTAG("display"); } ;display_m: | display display_m ;comment: '(' EP_comment comment_h ')' ;comment_h: | comment_h StringToken { VERBOSE("Comment: %s\n", $2); } ;nameDef: NameToken { $$ = $1; } | name { $$ = $1; } | rename { $$ = $1; } ;nameRef: NameToken { $$ = $1; } | name { $$ = $1; } ;name: '(' EP_name NameToken display_m ')' { $$ = $3; } ;/* I DONT THINK THIS IS RIGHT!!! */rename: '(' EP_rename rename_h1 rename_h2 ')' { WARNTAG("rename"); $$ = $3; free($4); } ;rename_h1: NameToken { $$ = $1; } | name { $$ = $1; } ;/* LIMIT: no stringDisplay here */rename_h2: StringToken { $$ = $1; } ;typedValue: '(' { SKIPTAG("typedValue"); } ;/* Main tag. Helper functions are used to allow interchangable tags */edif: '(' edif_name edifFileNameDef edifVersion edifLevel keywordMap edif_h ')' ;edif_name: EP_edif { info("\n** Parsing EDIF file '%s' **\n", opt.edif_filename); /* Initialization of data structures */ pWarningHT = hash_alloc(23, hash_hashfunc1, NULL); } ; edif_h: | status edif_h | external edif_h | library edif_h | design edif_h | comment edif_h | userData edif_h ;edifFileNameDef: NameToken { VERBOSE("EDIF FileNameDef = %s\n", $1); free($1); } ;edifVersion: '(' EP_edifVersion IntegerToken IntegerToken IntegerToken ')' { VERBOSE("Edif Version: %d %d %d\n", $3, $4, $5); if(($3 != 2) || ($4 != 0) || ($5 != 0)) { WARN("Wrong EDIF version, trying anyway..."); } } ;edifLevel: '(' EP_edifLevel IntegerToken ')' { if($3!=0) { WARN("Warning: Unsupported edifLevel found. Attempting to parse...\n"); } } ;keywordMap: '(' EP_keywordMap { EP_skipping = 1; } ;status: '(' EP_status status_h ')' ;status_h: | written status_h | comment status_h | userData status_h ;written: '(' EP_written timeStamp written_h ')' ;/* Restrictions: No more than 1 author, program or dataOrigin tag */written_h: | author written_h | program written_h | dataOrigin written_h | property written_h | comment written_h | userData written_h ;timeStamp: '(' EP_timeStamp IntegerToken IntegerToken IntegerToken IntegerToken IntegerToken IntegerToken ')' { VERBOSE("Timestamp: %d %d %d %d %d %d\n", $3, $4, $5, $6, $7, $8); } ;author: '(' EP_author StringToken ')' { VERBOSE("Author: %s\n", $3); free($3); } ;program: '(' EP_program StringToken ')' { VERBOSE("Program: %s\n", $3); free($3); } | '(' EP_program StringToken version ')' { VERBOSE("Program: %s, version: %s\n", $3, $4); free($3); free($4); } ;version: '(' EP_version StringToken ')' { $$ = $3; } ;dataOrigin: '(' EP_dataOrigin StringToken ')' { VERBOSE("dataOrigin: %s\n", $3); free($3); } | '(' EP_dataOrigin StringToken version ')' { VERBOSE("dataOrigin: %s, version: %s\n", $3, $4); free($3); free($4); } ;property: '(' EP_property { SKIPTAG("property"); } ;/* NO RESTRICTION: One owner, one unit */property_h: | owner property_h | unit property_h | property property_h | comment property_h ;propertyNameDef: NameToken
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?