Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Duncan White
C-datadec
Commits
f52c95b7
Commit
f52c95b7
authored
Apr 10, 1992
by
dcw
Browse files
added tail_optimize code
parent
cdc38a23
Changes
1
Show whitespace changes
Inline
Side-by-side
optimize.c
View file @
f52c95b7
...
...
@@ -2,6 +2,7 @@
#include
<dcw.h>
#include
<string.h>
#include
"struct.h"
...
...
@@ -9,10 +10,19 @@ BOOL opt; /* opt == perform optimizations */
BOOL
verbose
;
/* verbose == be verbose - diagnostics */
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS
static
void
optimize_decln
(
declnlist
);
static
void
optimize_decln
(
decln
);
static
BOOL
tail_optimize
(
decln
);
#else
static
void
optimize_decln
();
static
BOOL
tail_optimize
();
#endif
...
...
@@ -35,7 +45,7 @@ void optimize( d ) declnlist d;
}
static
void
optimize_decln
(
d
)
decln
list
d
;
/* JUST THE FIRST */
static
void
optimize_decln
(
d
)
decln
d
;
{
int
t
,
e
,
ne
;
shapelist
s
;
...
...
@@ -61,7 +71,8 @@ static void optimize_decln( d ) declnlist d; /* JUST THE FIRST */
d
->
TagField
=
ne
>
1
||
(
ne
>
0
&&
t
>
2
);
d
->
Union
=
ne
>
1
;
d
->
UseNull
=
ne
>
0
&&
firstempty
;
d
->
PutLoop
=
TRUE
;
d
->
PutLoop
=
tail_optimize
(
d
);
if
(
verbose
)
{
...
...
@@ -88,3 +99,41 @@ static void optimize_decln( d ) declnlist d; /* JUST THE FIRST */
ASSERT
(
implies
(
d
->
Union
,
d
->
TagField
),
(
"optimizer error: type %s has Union&!TagField
\n
"
,
d
->
name
)
);
}
/*
Given a data decln, check if a tail recursion optimization is possible.
This is when the last print item of any shape is a number corresponding
to a field that is the same type as the decln itself.
Return TRUE if the optimization is possible.
*/
static
BOOL
tail_optimize
(
d
)
decln
d
;
{
shapelist
s
;
printlist
pl
;
param
p
;
int
n
;
for
(
s
=
d
->
shapes
;
s
!=
NULL
;
s
=
s
->
next
)
{
if
(
s
->
pl
!=
NULL
)
{
/* find the last print item */
for
(
pl
=
s
->
pl
;
pl
->
next
!=
NULL
;
pl
=
pl
->
next
);
if
(
pl
->
item
->
tag
==
printitem_is_num
)
{
p
=
findnthparam
(
pl
->
item
->
num
,
s
->
params
,
s
->
name
,
d
->
name
);
if
(
streq
(
p
->
type
,
d
->
name
)
)
{
return
TRUE
;
}
}
}
}
return
FALSE
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment