/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "dextern.h"
static void gin(int);
static void stin(int);
static void osummary(void);
static void aoutput(void);
static int nxti(void);
static int gtnm(void);
static int *ggreed;
static int *pgo;
static int *yypgo;
int *optimmem;
static int *maxa;
static int nxdb = 0;
static int adb = 0;
void
callopt()
{
int i, *p, j, k, *q;
/* read the arrays from tempfile and set parameters */
/*
* TRANSLATION_NOTE -- This is a message from yacc.
* This message is passed to error() function.
* tempfile can be translated as temporary file.
*/
"optimizer cannot open tempfile"));
pgo[0] = 0;
temp1[0] = 0;
nstate = 0;
nnonter = 0;
for (;;) {
switch (gtnm()) {
case L'\n':
/* FALLTHRU */
case L',':
continue;
case L'$':
break;
default:
error("bad tempfile");
}
break;
}
for (;;) {
switch (gtnm()) {
case L'\n':
/* FALLTHRU */
case L',':
continue;
case EOF:
break;
default:
/*
* TRANSLATION_NOTE -- This is a message from yacc.
* This message is passed to error() function.
* tempfile can be translated as 'temporary file'.
*/
"bad tempfile"));
}
break;
}
for (i = 0; i < nstate; ++i) {
k = 32000000;
j = 0;
if (*p > j)
j = *p;
if (*p < k)
k = *p;
}
if (k <= j) {
/*
* nontrivial situation
* temporarily, kill this for compatibility
*/
/* j -= k; j is now the range */
if (k > maxoff)
maxoff = k;
}
if (j > maxspr)
maxspr = j;
}
/* initialize ggreed table */
for (i = 1; i <= nnonter; ++i) {
ggreed[i] = 1;
j = 0;
/* minimum entry index is always 0 */
ggreed[i] += 2;
if (*p > j)
j = *p;
}
if (j > maxoff)
maxoff = j;
}
/* now, prepare to put the shift actions into the amem array */
for (i = 0; i < new_actsize; ++i)
amem[i] = 0;
for (i = 0; i < nstate; ++i) {
}
if (i >= 0)
stin(i);
else
gin(-i);
}
for (i = 0; i < 10; ++i)
}
}
/* write out the output appropriate to the language */
aoutput();
osummary();
}
static void
gin(int i)
{
int *p;
/* enter gotos on nonterminal i into array amem */
ggreed[i] = 0;
/* now, find a place for it */
/* for( p=amem; p < &amem[new_actsize]; ++p ){ */
p = amem;
for (;;) {
while (p >= &amem[new_actsize])
exp_act(&p);
if (*p)
goto nextgp;
s = p + *r + 1;
/*
* Check if action table needs to
* be expanded or not. If so,
* expand it.
*/
while (s >= &amem[new_actsize]) {
exp_act(&p);
s = p + *r + 1;
}
if (*s)
goto nextgp;
if (s > maxa) {
/* error( "amem array overflow" ); */
exp_act(&p);
}
}
/* we have found a spot */
*p = *q2;
if (p > maxa) {
/* error("amem array overflow"); */
exp_act(&p);
}
s = p + *r + 1;
/*
* Check if action table needs to
* be expanded or not. If so,
* expand it.
*/
while (s >= &amem[new_actsize]) {
exp_act(&p);
s = p + *r + 1;
}
*s = r[1];
}
if (adb > 1)
"Nonterminal %d, entry at %d\n", i, pgo[i]);
goto nextgi;
++p;
}
/* error( "cannot place goto %d\n", i ); */
nextgi:;
}
static void
stin(int i)
{
int *s;
tystate[i] = 0;
/* Enter state i into the amem array */
/* Find an acceptable place */
more:
for (n = nn; n < new_actsize; ++n) {
flag = 0;
s = *r + n + amem;
if (s < amem)
goto nextn;
/*
* Check if action table needs to
* be expanded or not. If so,
* expand it.
*/
while (s >= &amem[new_actsize]) {
s = *r + n + amem;
}
if (*s == 0)
++flag;
else if (*s != r[1])
goto nextn;
}
/*
* check that the position equals another
* only if the states are identical
*/
for (j = 0; j < nstate; ++j) {
if (indgo[j] == n) {
if (flag)
/*
* we have some disagreement.
*/
goto nextn;
/* states are equal */
indgo[i] = n;
if (adb > 1)
"State %d: entry at"
" %d equals state %d\n",
i, n, j);
return;
}
goto nextn; /* we have some disagreement */
}
}
/*
* error( "out of space");
*/
}
if (s > maxa)
maxa = s;
if (*s != 0 && *s != r[1])
/*
* TRANSLATION_NOTE -- This is a message from yacc.
* This message is passed to error() function.
* Leave this untrasnlated. Yacc internal error.
*/
"clobber of amem array, pos'n %d, by %d"),
s-amem, r[1]);
*s = r[1];
}
indgo[i] = n;
if (adb > 1)
"State %d: entry at %d\n", i, indgo[i]);
return;
nextn:;
}
/* error( "Error; failure to place state %d\n", i ); */
goto more;
/* NOTREACHED */
}
static int
nxti()
{
/* finds the next i */
max = 0;
for (i = 1; i <= nnonter; ++i)
maxi = -i;
}
for (i = 0; i < nstate; ++i)
maxi = i;
}
if (nxdb)
if (max == 0)
return (NOMORE);
else
return (maxi);
}
static void
osummary()
{
/* write summary */
int i, *p;
return;
i = 0;
if (*p == 0)
++i;
}
"Optimizer space used: input %" PRIdPTR
}
static void
aoutput()
{
/* this version is for C */
/* write out the optimized parser */
}
static void
arout(s, v, n)
wchar_t *s;
int *v, n;
{
int i;
for (i = 0; i < n; ) {
if (i % 10 == 0)
if (++i == n)
else
}
}
static int
gtnm()
{
int s, val, c;
/* read and convert an integer from the standard input */
/* return the terminating character */
/* blanks, tabs, and newlines are ignored */
s = 1;
val = 0;
if (iswdigit(c))
else if (c == L'-')
s = -1;
else
break;
}
exp_mem(0);
return (c);
}
void
int **ptr;
{
static int *actbase;
int i;
new_actsize += ACTSIZE;
/*
* TRANSLATION_NOTE -- This is a message from yacc.
* This message is passed to error() function.
*
* You may just translate this as:
* 'Could not allocate internally used memory.'
*/
"couldn't expand action table"));
amem[i] = 0;
}