ldlex.l

来自「基于4个mips核的noc设计」· L 代码 · 共 669 行 · 第 1/2 页

L
669
字号
/* Filename without commas, needed to parse mri stuff */				 yylval.name = xstrdup(yytext); 				  return NAME;				}<BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}*	{				 yylval.name = xstrdup(yytext); 				  return NAME;				}<BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {				  yylval.name = xstrdup (yytext + 2);				  return LNAME;				}<SCRIPT>{WILDCHAR}* {		/* Annoyingly, this pattern can match comments, and we have		   longest match issues to consider.  So if the first two		   characters are a comment opening, put the input back and		   try again.  */		if (yytext[0] == '/' && yytext[1] == '*')		  {		    yyless(2);		    comment ();		  }		else		  {		    yylval.name = xstrdup(yytext);		    return NAME;		  }	}<EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {					/* No matter the state, quotes					   give what's inside */					yylval.name = xstrdup(yytext+1);					yylval.name[yyleng-2] = 0;					return NAME;				}<BOTH,SCRIPT,EXPRESSION>"\n"		{ lineno++;}<MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+	{ }<VERS_NODE,VERS_SCRIPT>[:,;]	{ return *yytext; }<VERS_NODE>global		{ RTOKEN(GLOBAL); }<VERS_NODE>local		{ RTOKEN(LOCAL); }<VERS_NODE>extern		{ RTOKEN(EXTERN); }<VERS_NODE>{V_IDENTIFIER}	{ yylval.name = xstrdup (yytext);				  return VERS_IDENTIFIER; }<VERS_SCRIPT>{V_TAG}		{ yylval.name = xstrdup (yytext);				  return VERS_TAG; }<VERS_START>"{"			{ BEGIN(VERS_SCRIPT); return *yytext; }<VERS_SCRIPT>"{"		{ BEGIN(VERS_NODE); 				  vers_node_nesting = 0;				  return *yytext;				}<VERS_SCRIPT>"}"		{ return *yytext; }<VERS_NODE>"{"			{ vers_node_nesting++; return *yytext; }<VERS_NODE>"}"			{ if (--vers_node_nesting < 0)				    BEGIN(VERS_SCRIPT);				  return *yytext;				}<VERS_START,VERS_NODE,VERS_SCRIPT>[\n]		{ lineno++; }<VERS_START,VERS_NODE,VERS_SCRIPT>#.*		{ /* Eat up comments */ }<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+   	{ /* Eat up whitespace */ }<<EOF>> {  include_stack_ptr--;      if (include_stack_ptr == 0)   {    yyterminate();  }  else   {    yy_switch_to_buffer(include_stack[include_stack_ptr]);  }  BEGIN(SCRIPT);  ldfile_input_filename = file_name_stack[include_stack_ptr - 1];  lineno = lineno_stack[include_stack_ptr - 1];  return END;}<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.	lex_warn_invalid(" in script", yytext);<EXPRESSION,DEFSYMEXP,BOTH>.	lex_warn_invalid(" in expression", yytext);    %%/* Switch flex to reading script file NAME, open on FILE,   saving the current input info on the include stack.  */voidlex_push_file (file, name)     FILE *file;     const char *name;{  if (include_stack_ptr >= MAX_INCLUDE_DEPTH)     {      einfo("%F:includes nested too deeply\n");    }  file_name_stack[include_stack_ptr] = name;  lineno_stack[include_stack_ptr] = 1;  include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;  include_stack_ptr++;  yyin = file;  yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));  BEGIN (SCRIPT);}/* Return a newly created flex input buffer containing STRING,   which is SIZE bytes long.  */static YY_BUFFER_STATE yy_create_string_buffer (string, size)     CONST char *string;     size_t size;{  YY_BUFFER_STATE b;  /* Calls to m-alloc get turned by sed into xm-alloc.  */  b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));  b->yy_input_file = 0;  b->yy_buf_size = size;  /* yy_ch_buf has to be 2 characters longer than the size given because     we need to put in 2 end-of-buffer characters.  */  b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));  b->yy_ch_buf[0] = '\n';  strcpy (b->yy_ch_buf+1, string);  b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;  b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;  b->yy_n_chars = size+1;  b->yy_buf_pos = &b->yy_ch_buf[1];  b->yy_is_our_buffer = 1;  b->yy_is_interactive = 0;  b->yy_at_bol = 1;  b->yy_fill_buffer = 0;  /* flex 2.4.7 changed the interface.  FIXME: We should not be using     a flex internal interface in the first place!  */#ifdef YY_BUFFER_NEW  b->yy_buffer_status = YY_BUFFER_NEW;#else  b->yy_eof_status = EOF_NOT_SEEN;#endif  return b;}/* Switch flex to reading from STRING, saving the current input info   on the include stack.  */voidlex_redirect (string)     CONST char *string;{  YY_BUFFER_STATE tmp;  yy_init = 0;  if (include_stack_ptr >= MAX_INCLUDE_DEPTH)     {      einfo("%F: macros nested too deeply\n");    }  file_name_stack[include_stack_ptr] = "redirect";  lineno_stack[include_stack_ptr] = 0;  include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;  include_stack_ptr++;  tmp = yy_create_string_buffer (string, strlen (string));  yy_switch_to_buffer (tmp);  BEGIN (SCRIPT);}/* Functions to switch to a different flex start condition,   saving the current start condition on `state_stack'.  */static int state_stack[MAX_INCLUDE_DEPTH * 2];static int *state_stack_p = state_stack;voidldlex_script (){  *(state_stack_p)++ = yy_start;  BEGIN (SCRIPT);}voidldlex_mri_script (){  *(state_stack_p)++ = yy_start;  BEGIN (MRI);}voidldlex_version_script (){  *(state_stack_p)++ = yy_start;  BEGIN (VERS_START);}voidldlex_version_file (){  *(state_stack_p)++ = yy_start;  BEGIN (VERS_SCRIPT);}voidldlex_defsym (){  *(state_stack_p)++ = yy_start;  BEGIN (DEFSYMEXP);}	   voidldlex_expression (){  *(state_stack_p)++ = yy_start;  BEGIN (EXPRESSION);}voidldlex_both (){  *(state_stack_p)++ = yy_start;  BEGIN (BOTH);}voidldlex_popstate (){  yy_start = *(--state_stack_p);}/* Place up to MAX_SIZE characters in BUF and return in *RESULT   either the number of characters read, or 0 to indicate EOF.  */static voidyy_input (buf, result, max_size)     char *buf;     int *result;     int max_size;{  *result = 0;   if (yy_current_buffer->yy_input_file)    {      if (yyin)	{	  *result = read (fileno (yyin), (char *) buf, max_size);	  if (*result < 0) 	    einfo ("%F%P: read in flex scanner failed\n");	}    }}/* Eat the rest of a C-style comment.  */static voidcomment (){  int c;  while (1)  {    c = input();    while (c != '*' && c != EOF)     {      if (c == '\n')	lineno++;      c = input();    }    if (c == '*')    {      c = input();      while (c == '*')       c = input();      if (c == '/')       break;			/* found the end */    }    if (c == '\n')      lineno++;    if (c == EOF)    {      einfo( "%F%P: EOF in comment\n");      break;    }  }}/* Warn the user about a garbage character WHAT in the input   in context WHERE.  */static voidlex_warn_invalid (where, what)     char *where, *what;{  char buf[5];  /* If we have found an input file whose format we do not recognize,     and we are therefore treating it as a linker script, and we find     an invalid character, then most likely this is a real object file     of some different format.  Treat it as such.  */  if (ldfile_assumed_script)    {      bfd_set_error (bfd_error_file_not_recognized);      einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);    }  if (! isprint ((unsigned char) *what))    {      sprintf (buf, "\\%03o", (unsigned int) *what);      what = buf;    }  einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?