Skip to content

Commit 141d2e1

Browse files
committed
Change ncgg so it puts output files where it's told rather than the
current directory.
1 parent 7468a4f commit 141d2e1

File tree

7 files changed

+96
-65
lines changed

7 files changed

+96
-65
lines changed

util/ncgg/build.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def ncgg(self, name, srcs: Targets = [], deps: Targets = [], cflags=[]):
3939
ins=["util/ncgg", cpptable],
4040
outs=["=tables.c", "=tables.h"],
4141
commands=[
42-
"$[ins]",
43-
"mv tables.h $[dir]/tables.h",
44-
"mv tables.c $[dir]/tables.c",
42+
"$[ins[0]] -o $[dir] $[ins[1:]]"
4543
],
4644
label="NCGG",
4745
)

util/ncgg/extern.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5-
/* $Id$ */
65

76
extern int wordsize;
87
extern int pointersize;
@@ -31,7 +30,7 @@ extern int allsetno;
3130
extern int inproc;
3231
extern int callproc;
3332
extern int procarg[];
34-
extern int fc1,fc2,fc3,fc4;
33+
extern int fc1, fc2, fc3, fc4;
3534
extern int maxmembers;
3635
extern int regclass;
3736
extern int maxtokensize;
@@ -48,7 +47,7 @@ extern void initemhash(void);
4847
/* error.c */
4948
extern void fatal(const char* s, ...);
5049
extern void error(const char* s, ...);
51-
extern int tabovf(char *string);
50+
extern int tabovf(char* string);
5251

5352
/* output.c */
5453
extern void errorexit(void);
@@ -57,4 +56,11 @@ extern void finishio(void);
5756
extern void statistics(void);
5857

5958
/* strlookup.c */
60-
extern int strlookup(char *str);
59+
extern int strlookup(char* str);
60+
61+
/* Global parameters */
62+
extern int nerrors;
63+
extern int code_in_c;
64+
extern int tabledebug;
65+
extern int verbose;
66+
extern const char* outputdir;

util/ncgg/main.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5-
#ifndef NORCSID
6-
static char rcsid[] = "$Id$";
7-
#endif
85

96
#include <stdlib.h>
107
#include <stdio.h>
118
#include "param.h"
129
#include "hall.h"
1310
#include "expr.h"
1411
#include "extern.h"
15-
#include "lookup.h"
1612

17-
char *filename;
13+
char* filename;
1814

19-
int main(int argc, char **argv)
15+
int main(int argc, char** argv)
2016
{
21-
extern int nerrors;
22-
extern int code_in_c;
23-
extern int tabledebug;
24-
extern int verbose;
25-
2617
while (argc > 1 && argv[1][0] == '-')
2718
{
2819
switch (argv[1][1])
@@ -36,6 +27,11 @@ int main(int argc, char **argv)
3627
case 'v':
3728
verbose++;
3829
break;
30+
case 'o':
31+
outputdir = argv[2];
32+
argv++;
33+
argc--;
34+
break;
3935
default:
4036
error("Unknown flag -%c", argv[1][1]);
4137
}

util/ncgg/ncgg.6

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cgg \- Code table translating utility
66
.SH SYNOPSIS
77
.B ~em/lib.bin/cgg
8-
[-c] [-d] [-v] table
8+
[-c] [-d] [-v] [-o outputdir] table
99
.SH DESCRIPTION
1010
cgg translates a machine description table into the internal
1111
structures needed by em_cg.
@@ -25,6 +25,8 @@ bittable described under the -u option of em_ncg(6).
2525
Give statistics about table usage at end of program.
2626
Normally only the tables that have been used more than 75%
2727
are reported.
28+
.IP -o outputdir
29+
Write the output files to the specified directory.
2830
.SH FILES
2931
tables.h, tables.c
3032
.br

util/ncgg/output.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,14 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5-
/* #define CODEDEBUG *//* print readable code */
6-
#ifdef CODEDEBUG
7-
int code_in_c=0; /* put readable code in "code" */
8-
int tabledebug=1; /* generate code for table debugging */
9-
#else
10-
int code_in_c = 1; /* put code in "tables.c" */
11-
int tabledebug = 0; /* do not generate code for table debugging */
12-
#endif
13-
int verbose = 0; /* print all statistics */
14-
int use_tes; /* use top element size information */
15-
char *c_file = "tables.c";
16-
char *h_file = "tables.h";
17-
char *cd_file = "code";
18-
19-
#ifndef NORCSID
20-
static char rcsid[] = "$Id$";
21-
#endif
5+
/* #define CODEDEBUG */ /* print readable code */
226

7+
#include <errno.h>
8+
#include <stdlib.h>
239
#include <assert.h>
2410
#include <stdio.h>
2511
#include <ctype.h>
12+
#include <unistd.h>
2613
#include "varinfo.h"
2714
#include "param.h"
2815
#include "reg.h"
@@ -36,7 +23,21 @@ static char rcsid[] = "$Id$";
3623
#include "pseudo.h"
3724
#include "regvar.h"
3825
#include "extern.h"
26+
#include "subr.h"
3927

28+
#ifdef CODEDEBUG
29+
int code_in_c=0; /* put readable code in "code" */
30+
int tabledebug=1; /* generate code for table debugging */
31+
#else
32+
int code_in_c = 1; /* put code in "tables.c" */
33+
int tabledebug = 0; /* do not generate code for table debugging */
34+
#endif
35+
int verbose = 0; /* print all statistics */
36+
int use_tes; /* use top element size information */
37+
char *c_file = "tables.c";
38+
char *h_file = "tables.h";
39+
char *cd_file = "code";
40+
const char* outputdir = ".";
4041
#define BMASK 0xFF
4142
#define BSHIFT 8
4243

@@ -105,6 +106,12 @@ void unlfile(FILE *f, char *s)
105106

106107
void initio(void)
107108
{
109+
char* oldcwd = mygetcwd();
110+
111+
errno = 0;
112+
chdir(outputdir);
113+
if (errno)
114+
perror("output directory inaccessible");
108115

109116
opnfile(&ctable, c_file);
110117
opnfile(&htable, h_file);
@@ -114,7 +121,10 @@ void initio(void)
114121
opnfile(&code, cd_file);
115122
patbyte(0);
116123
if (tabledebug)
117-
lineset = (short *) myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short));
124+
lineset = (short*)myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short));
125+
126+
chdir(oldcwd);
127+
free(oldcwd);
118128
}
119129

120130
void finishcode(void)

util/ncgg/subr.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
33
* See the copyright notice in the ACK home directory, in the file "Copyright".
44
*/
5+
#include <errno.h>
6+
#include <unistd.h>
57
#ifndef NORCSID
68
static char rcsid[] = "$Id$";
79
#endif
@@ -515,3 +517,20 @@ int vilength(struct varinfo *vip)
515517
}
516518
return (l);
517519
}
520+
521+
char* mygetcwd(void)
522+
{
523+
size_t size = 100;
524+
525+
while (1)
526+
{
527+
char* buffer = malloc(size);
528+
if (getcwd(buffer, size) == buffer)
529+
return buffer;
530+
free(buffer);
531+
if (errno != ERANGE)
532+
return NULL;
533+
size *= 2;
534+
}
535+
}
536+

util/ncgg/subr.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Copyright (c) 2019 ACK Project.
2-
* See the copyright notice in the ACK home directory,
2+
* See the copyright notice in the ACK home directory,
33
* in the file "Copyright".
44
*
55
* Created on: 2019-05-02
6-
*
6+
*
77
*/
88
#ifndef SUBR_H_
99
#define SUBR_H_
@@ -12,31 +12,31 @@
1212

1313
struct varinfo;
1414

15-
16-
void n_proc(char *name);
17-
struct varinfo * make_erase(char *name);
18-
void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist,
19-
struct varinfo *cost);
20-
void n_set(char *name, int number);
21-
void n_tok(char *name, struct varinfo *atts, int size,
22-
struct varinfo *cost, struct varinfo *format);
23-
void checkprintformat(int n);
24-
void n_prop(char *name, int size);
25-
void prophall(int n);
26-
int n_reg(char *name, char *printstring, int nmemb, int member1, int member2);
27-
void make_const(void);
28-
int cmustbeset(char *ident);
29-
void n_const(char *ident, int val);
30-
void n_sconst(char *ident, char *val);
31-
void regline(struct varinfo *rl, struct varinfo *pl, int rv);
32-
void check_reglap(void);
33-
void setallreg(struct varinfo *vi);
34-
void freevi(struct varinfo *vip);
35-
int myatoi(char *s);
36-
char *mystrcpy(char *s);
37-
char *myalloc(int n);
38-
int chkincl(int value, int lwb, int upb);
39-
int subset(short *sp1, short *sp2, int setsize);
40-
int vilength(struct varinfo *vip);
15+
extern void n_proc(char* name);
16+
extern struct varinfo* make_erase(char* name);
17+
extern void
18+
n_instr(char* name, char* asname, operand* oplist, struct varinfo* eraselist, struct varinfo* cost);
19+
extern void n_set(char* name, int number);
20+
extern void
21+
n_tok(char* name, struct varinfo* atts, int size, struct varinfo* cost, struct varinfo* format);
22+
extern void checkprintformat(int n);
23+
extern void n_prop(char* name, int size);
24+
extern void prophall(int n);
25+
extern int n_reg(char* name, char* printstring, int nmemb, int member1, int member2);
26+
extern void make_const(void);
27+
extern int cmustbeset(char* ident);
28+
extern void n_const(char* ident, int val);
29+
extern void n_sconst(char* ident, char* val);
30+
extern void regline(struct varinfo* rl, struct varinfo* pl, int rv);
31+
extern void check_reglap(void);
32+
extern void setallreg(struct varinfo* vi);
33+
extern void freevi(struct varinfo* vip);
34+
extern int myatoi(char* s);
35+
extern char* mystrcpy(char* s);
36+
extern char* myalloc(int n);
37+
extern int chkincl(int value, int lwb, int upb);
38+
extern int subset(short* sp1, short* sp2, int setsize);
39+
extern int vilength(struct varinfo* vip);
40+
extern char* mygetcwd(void);
4141

4242
#endif /* SUBR_H_ */

0 commit comments

Comments
 (0)