removed unused files

This commit is contained in:
schippes 2020-08-10 09:22:21 +02:00
parent 8383bb0e39
commit b8ed97d2d5
2 changed files with 0 additions and 640 deletions

View File

@ -1,432 +0,0 @@
/* File: expandlabel.y
*
* This file is part of XSCHEM,
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
* simulation.
* Copyright (C) 1998-2020 Stefan Frederik Schippers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* label parser */
%{
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct /* used in expandlabel.y */
{
char *str; /* label name */
int m; /* label multiplicity, number of wires */
} Stringptr;
#define YYERROR_VERBOSE
#define SIGN(x) ( (x) < 0 ? -1: 1 )
#define INITIALIDXSIZE 8
extern Stringptr dest_string; /* 20140108 */
static int idxsize=INITIALIDXSIZE;
extern int yylex();
extern FILE *errfp;
extern void *my_malloc(int id, size_t size);
extern void my_free(void *ptr);
extern void my_realloc(int id, void *ptr,size_t size);
extern void my_strdup(int id, char **dest, char *src);
extern int debug_var;
extern void dbg(int level, char *fmt, ...);
extern int my_snprintf(char *str, int size, const char *fmt, ...);
static void yyerror (const char *s) /* Called by yyparse on error */
{
dbg(3, "yyerror(): yyparse():%s\n", s);
}
static char *expandlabel_strdup(char *src)
{
char *ptr;
if(src==NULL || src[0]=='\0') {
ptr=NULL;
my_strdup(121, &ptr,"");
return ptr;
}
else
{
ptr=NULL;
my_strdup(122, &ptr,src);
dbg(3, "expandlabel_strdup: duplicated %lu string %s\n",(unsigned long)ptr,src);
return ptr;
}
}
static char *my_strcat2(char *s1, char c, char *s2)
/* concatenates s1 and s2, with c in between */
{
int l1=0,l2=0;
char *res;
if(s1!=NULL) l1=strlen(s1);
if(s1!=NULL) l2=strlen(s2);
res=my_malloc(123, l1+l2+2); /* 2 strings plus 'c' and '\0' */
/* 20180923 */
memcpy(res, s1, l1);
res[l1] = c;
memcpy(res + l1 + 1, s2, l2+1);
/* *res='\0'; */
/* if(l1) strcpy(res, s1); */
/* res[l1]=c; */
/* if(l2) strcpy(res+l1+1, s2); */
return res;
}
/* */
/* example: */
/* if n==3 and s="a,b,c" return "a,a,a,b,b,b,c,c,c" */
/* */
static char *my_strmult2(int n, char *s)
/* if n==0 returns "\0" */
{
register int i, len;
register char *pos,*prev;
char *str, *ss;
dbg(3, "my_strmult2: n=%d s=%s\n", n, s);
if(n==0) return expandlabel_strdup("");
len=strlen(s);
prev=s;
ss = str=my_malloc(124, (len+1)*n);
str[0]='\0';
for(pos=s;pos<=s+len;pos++) {
if(*pos==',' || *pos=='\0') {
for(i=0;i<n;i++) {
memcpy(ss, prev, pos-prev); /* 20180923 */
if(i == n - 1 && *pos == '\0') {
ss[pos - prev] = '\0';
} else {
ss[pos - prev] = ',';
}
ss += pos-prev+1; /* 20180923 */
}
/* if(*pos==',') strcat(str,","); */
prev=pos+1;
}
}
return str;
}
/* */
/* example: */
/* if n==3 and s="a,b,c" return "a,b,c,a,b,c,a,b,c" */
/* */
static char *my_strmult(int n, char *s)
/* if n==0 returns "\0" */
{
register int i, len;
register char *pos;
char *str;
if(n==0) return expandlabel_strdup("");
len=strlen(s);
str=pos=my_malloc(125, (len+1)*n);
for(i=1;i<=n;i++)
{
/* strcpy(pos,s); */
memcpy(pos, s, len); /* 20180923 */
pos[len]=',';
pos+=len+1;
}
*(pos-1)='\0';
return str;
}
static char *my_strbus(char *s, int *n)
{
int i,l;
int tmplen;
char *res=NULL;
char *tmp=NULL;
my_realloc(126, &res, n[0]*(strlen(s)+20));
my_realloc(127, &tmp, strlen(s)+30);
l=0;
for(i=1;i<n[0];i++)
{
tmplen = sprintf(tmp, "%s[%d],", s, n[i]);
/* strcpy(res+l,tmp); */
memcpy(res+l,tmp, tmplen+1); /* 20180923 */
l+=tmplen;
}
my_free(&tmp);
sprintf(res+l, "%s[%d]", s, n[i]);
return res;
}
static void check_idx(int **ptr,int n)
{
if(n>=idxsize)
{
idxsize*=2;
dbg(3, "check_idx(): reallocating idx array: size=%d\n",idxsize);
my_realloc(128, ptr, idxsize*sizeof(int));
}
}
static char *my_strbus_nobracket(char *s, int *n)
{
int i,l;
int tmplen;
char *res=NULL;
char *tmp=NULL;
my_realloc(107, &res, n[0]*(strlen(s)+20));
my_realloc(108, &tmp, strlen(s)+30);
l=0;
for(i=1;i<n[0];i++)
{
tmplen = sprintf(tmp, "%s%d,", s, n[i]);
/* strcpy(res+l,tmp); */
memcpy(res+l,tmp, tmplen+1); /* 20180923 */
l+=tmplen;
}
my_free(&tmp);
sprintf(res+l, "%s%d", s, n[i]);
return res;
}
%}
%union{
int val; /* For returning numbers.*/
Stringptr ptr; /* strings, that is, identifiers */
char * str;
int *idx; /* for bus index & bus index ranges */
}
/* BISON Declarations: terminal tokens*/
%token <val> B_NUM
%token <val> B_CAR
%token <val> B_IDXNUM
%token <val> B_DOUBLEDOT
%token <str> B_NAME
%token <str> B_LINE
/* BISON Declarations: non terminal symbols*/
%type <ptr> list
%type <idx> index
%type <idx> index_nobracket
/* operator precedences (bottom = highest) and associativity */
%left B_DOUBLEDOT
%left B_CAR
%left ','
%left ':'
%left '*'
/* Grammar follows */
%%
input: /* empty string. allows ctrl-D as input */
| input line
;
line: list {
my_strdup(129, &(dest_string.str),$1.str); /*19102004 */
my_free(&$1.str); /*19102004 */
dest_string.m=$1.m;
}
;
list: B_NAME {
dbg(3, "yyparse(): B_NAME (%lu) \n", (unsigned long) $1);
dbg(3, "yyparse(): B_NAME, $1=%s\n", $1);
$$.str = expandlabel_strdup($1); /* 19102004 prima era =$1 */
my_free(&$1); /*191020004 */
$$.m = 1;
}
| B_LINE {
dbg(3, "yyparse(): B_LINE\n");
$$.str = expandlabel_strdup($1); /* 19102004 prima era =$1 */
my_free(&$1); /*191020004 */
$$.m = 1;
}
| list '*' B_NUM{
dbg(3, "yyparse(): list * B_NUM\n");
dbg(3, "yyparse(): |%s| %d \n",$1.str,$3);
$$.str=my_strmult2($3,$1.str);
dbg(3, "yyparse(): |%s|\n",$$.str);
$$.m = $3 * $1.m;
my_free(&$1.str);
}
| B_NUM '*' list{
dbg(3, "yyparse(): B_NUM * list\n");
$$.str=my_strmult($1,$3.str);
$$.m = $1 * $3.m;
my_free(&$3.str);
}
| list ',' list {
dbg(3, "yyparse(): list , list\n");
$$.str=my_strcat2($1.str, ',', $3.str);
$$.m = $1.m + $3.m;
my_free(&$1.str), my_free(&$3.str);
}
| list B_CAR list
{
dbg(3, "yyparse(): list B_CAR list\n");
$$.str=my_strcat2($1.str, $2, $3.str);
$$.m = $1.m + $3.m;
my_free(&$1.str), my_free(&$3.str);
}
| '(' list ')' {
dbg(3, "yyparse(): ( list )\n");
$$=$2;
}
| B_NAME '[' B_NAME ']'
{
int size = strlen($1) + strlen($3) + 3;
$$.str = my_malloc(81, size);
$$.m=1;
my_snprintf($$.str, size, "%s[%s]", $1, $3);
my_free(&$1);
my_free(&$3);
}
| B_NAME '[' index ']'
{
dbg(3, "yyparse(): making bus: n=%d\n",$3[0]);
dbg(3, "yyparse(): B_NAME[ index ] , $1=%s $3=%d\n", $1, *$3);
$$.str=my_strbus($1,$3);
my_free(&$1);
dbg(3, "yyparse(): done making bus: n=%d\n",$3[0]);
$$.m=$3[0];
my_free(&$3); /*19102004 */
idxsize=INITIALIDXSIZE;
}
| B_NAME '[' index_nobracket ']'
{
dbg(3, "yyparse(): making nobracket bus: n=%d\n",$3[0]);
$$.str=my_strbus_nobracket($1,$3);
my_free(&$1);
dbg(3, "yyparse(): done making nobracket bus: n=%d\n",$3[0]);
$$.m=$3[0];
my_free(&$3); /*19102004 */
idxsize=INITIALIDXSIZE;
}
;
index: B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
{
int i; /* 20120229 */
int sign;
sign = SIGN($3-$1);
$$=my_malloc(130, INITIALIDXSIZE*sizeof(int));
$$[0]=0;
dbg(3, "yyparse(): parsing first idx range\n");
for(i=$1;;i+=sign*$5)
{
check_idx(&$$,++$$[0]);
$$[$$[0]]=i;
if(sign==1 && i>=$3) break;
if(sign==-1 && i<=$3) break;
} /* /20120229 */
}
| B_IDXNUM ':' B_IDXNUM
{
int i;
$$=my_malloc(131, INITIALIDXSIZE*sizeof(int));
$$[0]=0;
dbg(3, "yyparse(): parsing first idx range\n");
for(i=$1;;i+=SIGN($3-$1))
{
check_idx(&$$,++$$[0]);
$$[$$[0]]=i;
if(i==$3) break;
}
}
| B_IDXNUM {
dbg(3, "yyparse(): parsing first idx item\n");
$$=my_malloc(132, INITIALIDXSIZE*sizeof(int));
$$[0]=0;
check_idx(&$$, ++$$[0]);
$$[$$[0]]=$1;
}
| index ',' B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
{
int i; /* 20120229 */
int sign;
sign = SIGN($5-$3);
dbg(3, "yyparse(): parsing comma sep idx range\n");
for(i=$3;;i+=sign*$7)
{
check_idx(&$$, ++$$[0]);
$$[$$[0]]=i;
if(sign==1 && i>=$5) break;
if(sign==-1 && i<=$5) break;
} /* /20120229 */
}
| index ',' B_IDXNUM ':' B_IDXNUM
{
int i;
dbg(3, "yyparse(): parsing comma sep idx range\n");
for(i=$3;;i+=SIGN($5-$3))
{
check_idx(&$$, ++$$[0]);
$$[$$[0]]=i;
if(i==$5) break;
}
}
| index ',' B_IDXNUM
{
dbg(3, "yyparse(): parsing comma sep idx list\n");
check_idx(&$$, ++$$[0]);
$$[$$[0]]=$3;
}
;
index_nobracket: B_IDXNUM B_DOUBLEDOT B_IDXNUM
{
int i;
$$=my_malloc(85, INITIALIDXSIZE*sizeof(int));
$$[0]=0;
dbg(3, "yyparse(): doubledot\n");
for(i=$1;;i+=SIGN($3-$1))
{
check_idx(&$$,++$$[0]);
$$[$$[0]]=i;
if(i==$3) break;
}
}
| B_IDXNUM B_DOUBLEDOT B_IDXNUM B_DOUBLEDOT B_IDXNUM
{
int i;
int sign;
sign = SIGN($3-$1);
$$=my_malloc(109, INITIALIDXSIZE*sizeof(int));
$$[0]=0;
dbg(3, "yyparse(): parsing first idx range\n");
for(i=$1;;i+=sign*$5)
{
check_idx(&$$,++$$[0]);
$$[$$[0]]=i;
if(sign==1 && i>=$3) break;
if(sign==-1 && i<=$3) break;
}
}
%%

View File

@ -1,208 +0,0 @@
/* File: parselabel.l
*
* This file is part of XSCHEM,
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
* simulation.
* Copyright (C) 1998-2020 Stefan Frederik Schippers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
%option never-interactive
%option noyywrap
%option noinput
%option nounput
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CAD_SPICE_NETLIST 1
extern int netlist_type;
int dbg_var = 0;
extern FILE *errfp;
extern void my_strdup(int id, char **dest, char *src);
extern void my_free(void *ptr);
extern char bus_replacement_char[];
typedef struct /* used in expandlabel.y */
{
char *str; /* label name */
int m; /* label multiplicity, number of wires */
} Stringptr;
/* commented 20170412, fixes problems with older bison/flex versions */
/* #define YYPARSE_PARAM */
#include "expandlabel.h" /* Bison header file */
Stringptr dest_string={NULL,0}; /*19102004; */
static int bracket=0;
extern int yyparse(void) ;
void clear_expandlabel_data(void)
{
my_free(&dest_string.str);
}
void strreplace(char s[], char chr, char repl_chr)
{
int i=0;
while(s[i]!='\0')
{
if(s[i]==chr)
{
s[i]=repl_chr;
}
i++;
}
}
const char *expandlabel(const char *s, int *m)
{
YY_BUFFER_STATE buf;
my_free(&dest_string.str); /* 30102004 delete 'memory' of previous execution */
if(dbg_var >= 3) fprintf(errfp, "expandlabel(): entering\n");
buf=yy_scan_string(s);
bracket=0;
yyparse();
yy_delete_buffer(buf);
if(dbg_var >= 3) fprintf(errfp, "expandlabel(): returning %s from %s mult=%d\n",dest_string.str, s, dest_string.m);
if(dest_string.str)
*m = dest_string.m;
else
*m=-1;
if(dest_string.str) {
if(netlist_type == CAD_SPICE_NETLIST && bus_replacement_char[0]) {
strreplace(dest_string.str, '[', bus_replacement_char[0]);
strreplace(dest_string.str, ']', bus_replacement_char[1]);
}
return dest_string.str;
} else {
return s;
}
}
%}
/*
Lexical analyzer
*/
%x label
%x next_to_alias
%x rest
%%
^(alias|ipin|iopin|opin)[+ \n]+[^+\n ]+/[\n +]+ {
yylval.ptr.str=NULL; /*19102004 */
/* these things are freed after use in expandlabel.y */
my_strdup(298, &yylval.ptr.str, yytext);
BEGIN(next_to_alias);
if(dbg_var >= 3) fprintf(errfp, "yylex(): alias, yytext = %s\n", yytext);
return B_LINE;
}
<next_to_alias>[\n +]+ { /* get all white space and return a single separator */
BEGIN(label);
if(dbg_var >= 3) fprintf(errfp, "yylex(): next_to_alias, yytext = %s\n", yytext);
yylval.val=yytext[0];
return B_CAR;
}
^[^*] {
if(dbg_var >= 3) fprintf(errfp, "yylex(): matched: ^[^*] |%s|, push back\n",yytext);
yyless(0); /* push entire token back to input */
BEGIN(label); /* we know that a label follows. */
/* so go and process it. */
}
^\*.* { /* a comment, return as LINE token */
yylval.ptr.str=NULL; /*19102004 */
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_LINE: %s\n",yytext);
my_strdup(299, &yylval.ptr.str, yytext); /* these things are freed after use in expandlabel.y */
return B_LINE;
}
<label>{
[ \n]+ { /* this ends the <label> start condition */
BEGIN(rest);
yylval.val=yytext[0];
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_CAR: %s\n",yytext);
return B_CAR;
}
\.\. {
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_DOUBLEDOT: %s\n", yytext);
return B_DOUBLEDOT;
}
[0-9]+ {
sscanf(yytext, "%d",&yylval.val);
if(bracket) {
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_IDXNUM: %s\n", yytext);
return B_IDXNUM;
}
else {
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_NUM: %s\n", yytext);
return B_NUM;
}
}
/* recognize AA[width-1:0], AA[0:width-1], AA[width-1..4], AA[3.width+3], AA[aa:bb] AA[aa..bb] */
([-+a-z=A-Z][-+\\/=_a-zA-Z0-9]*:[-+a-z=A-Z0-9][-+\\/=_a-zA-Z0-9]*)|([-+a-z=A-Z0-9][-+\\/=_a-zA-Z0-9]*:[-+a-z=A-Z][-+\\/=_a-zA-Z0-9]*)|([-+a-z=A-Z][-+\\/=_a-zA-Z0-9]*\.\.[-+a-z=A-Z0-9][-+\\/=_a-zA-Z0-9]*)|([-+a-z=A-Z0-9][-+\\/=_a-zA-Z0-9]*\.\.[-+a-z=A-Z][-+\\/=_a-zA-Z0-9]*) {
yylval.ptr.str=NULL;
my_strdup(92, &yylval.ptr.str, yytext);
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_NAME 1: %s\n", yytext);
return B_NAME;
}
/* recognize the most esotheric identifiers */
([-+=_a-zA-Z][-\\/:.=_+a-zA-Z0-9]*)|([-+.=_a-zA-Z][-\\/:=_+a-zA-Z0-9]*)|([-=+_a-zA-Z][-\\/:.=_+a-zA-Z0-9]*\([-+\\/:.=_a-zA-Z0-9]*\)) {
yylval.ptr.str=NULL;/*19102004 */
my_strdup(300, &yylval.ptr.str, yytext); /* these things are freed after use in expandlabel.y */
if(dbg_var >= 3) fprintf(errfp, "yylex(): B_NAME: %s\n", yytext);
return B_NAME;
}
\[ {
bracket++;
if(dbg_var >= 3) fprintf(errfp, "yylex(): open bracket: %s\n", yytext);
return yytext[0];
}
\] {
bracket--;
if(dbg_var >= 3) fprintf(errfp, "yylex(): close bracket: %s\n", yytext);
return yytext[0];
}
[^ ] {
if(dbg_var >= 3) fprintf(errfp, "yylex(): returning character: %s\n", yytext);
return yytext[0];
}
} /* end <label> */
<rest>{ /* treat rest of line as a single LINE token */
(.|\n)* {
yylval.ptr.str=NULL; /*19102004 */
my_strdup(301, &yylval.ptr.str, yytext); /* these things are freed after use in expandlabel.y */
if(dbg_var >= 3) fprintf(errfp, "yylex(): <rest> B_LINE: %s\n",yytext);
BEGIN(INITIAL);
return B_LINE;
}
} /* end rest */
<*><<EOF>> {
BEGIN(INITIAL);
return 0;
}
%%