0% found this document useful (0 votes)
203 views2 pages

Using Copt with LCC Compiler

The document discusses using the copt peephole optimizer with the lcc compiler by adding command line and code changes to lcc to optionally call copt on the generated assembly output before compilation. Modifications are made to the main compile function and hostfile.c to support passing the input and output files to copt using its -I and -O options when the -O flag is specified for lcc.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views2 pages

Using Copt with LCC Compiler

The document discusses using the copt peephole optimizer with the lcc compiler by adding command line and code changes to lcc to optionally call copt on the generated assembly output before compilation. Modifications are made to the main compile function and hostfile.c to support passing the input and output files to copt using its -I and -O options when the -O flag is specified for lcc.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Using copt with lcc

From: Lennie - view profile


Date: Thurs, Jan 30 2003 9:20 pm
Email: lar...@[Link] (Lennie)
Groups: [Link]
/*
* Note: copt is available on the lcc website under Contributed software:
*
* [Link] Source code and documentation for copt, the simple
* peephole optimizer mentioned on p. 534 of "A Retargetable
* C Compiler: Design and Implementation". This file is
* a shell archive; unload it with sh <[Link].
* Chris Fraser / cwfra...@[Link]
*
* Added command line options -I and -O to copt to support input and output
* files rather than using stdin/stdout.
*/
/*===== copt.c: replaced main() with =====*/
/* main - peephole optimizer */
main(argc, argv) int argc; char **argv; {
FILE *fp;
FILE *finp = stdin;
FILE *fout = stdout;
int i;
struct lnode head, *p, *opt(), tail;
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "-D") == 0)
debug = 1;
else if (strcmp(argv[i], "-I") == 0)
finp = fopen(argv[++i], "r");
else if (strcmp(argv[i], "-O") == 0)
fout = fopen(argv[++i], "w");
else if ((fp=fopen(argv[i], "r")) == NULL)
error("copt: can't open patterns file\n");
else
init(fp);
getlst(finp, "", &head, &tail);
head.l_text = tail.l_text = "";
for (p = head.l_next; p != &tail; p = opt(p))
;
for (p = head.l_next; p != &tail; p = p->l_next)
fputs(p->l_text, fout);
}
/*
* Optionally invoke copt (using -O command line option in lcc). It would
* be nice if this was added to the next version (4.3) of lcc...
*/
/*===== Inserted before line 54 =====*/
extern char *peep[];
/*===== Inserted before line 60 =====*/
static int Oflag; /* -O specified */
/*===== Replaced compile() =====*/
/* compile - compile src into dst, return status */
static int compile(char *src, char *dst) {
int status;
if (!Oflag) {
compose(com, clist, append(src, 0), append(dst, 0));
status = callsys(av);
} else {
char* nonoptname = Oflag ? tempname(".n") : dst;
/* compile source into non-optimized assembly code */
compose(com, clist, append(src, 0), append(nonoptname, 0));
status = callsys(av);
if (status >= 0 && Oflag) {
/* call peephole optimizer */
compose(peep, clist, append(nonoptname, 0), append(dst,
0));
status = callsys(av);
}
}
return status;
}
/*===== Replaced line 488 with =====*/
"-O use peephole optimizer\n",
/*===== Replaced line 669 with =====*/
Oflag++;
/*===== Added line to etc/hostfile.c =====*/
char *peep[] = { LCCDIR "bin/copt", "[Link]", "-I", "$2", "-O", "$3", 0 };

You might also like