cc, ?[acl]: fix gethunk() and move common memory allocator code to cc/compat

for gethunk() to work, all allocators have to use it,
including allocations done by libc thru malloc(),
so the fake allocation functions are mandatory for
everyone.

to avoid duplication the code is moved to cc/compat
and prototypes provided in new cc/compat.h header.
This commit is contained in:
cinap_lenrek 2020-04-11 05:03:49 +02:00
parent 9d46360c9d
commit 1b8a569417
72 changed files with 228 additions and 1230 deletions

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Ref Ref;
@ -113,14 +110,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -132,11 +127,9 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
int assemble(char*);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -172,28 +165,7 @@ void macend(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../2c/2.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -15,6 +15,7 @@ OFILES=\
HFILES=\
gc.h\
../2c/2.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define P ((Prog*)0)
#define S ((Sym*)0)
@ -178,7 +175,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -187,7 +183,6 @@ EXTERN long lcsize;
EXTERN long relocsize;
EXTERN long ndata;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN short* op;
@ -200,7 +195,6 @@ EXTERN Sym* symlist;
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
@ -240,7 +234,6 @@ void errorexit(void);
int find1(long, int);
int find2(long, int);
void follow(void);
void gethunk(void);
int gnuxi(Ieee*, int, int);
void histtoauto(void);
double ieeedtod(Ieee*);
@ -254,7 +247,6 @@ Sym* lookup(char*, int);
void lput(long);
void main(int, char*[]);
void mkfwd(void);
void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
void patch(void);

View file

@ -14,9 +14,12 @@ OFILES=\
HFILES=\
l.h\
../2c/2.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
enam.$O: ../2c/enam.c
$CC $CFLAGS ../2c/enam.c
compat.$O: ../cc/compat

View file

@ -1082,28 +1082,6 @@ copyp(Prog *q)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Ref Ref;
@ -115,14 +112,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -134,10 +129,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -173,29 +166,7 @@ void macend(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
/*
* system-dependent stuff from ../cc/compat.c
*/
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../2c/2.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -15,6 +15,7 @@ OFILES=\
HFILES=\
gc.h\
2.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../2c/2.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define P ((Prog*)0)
#define S ((Sym*)0)
@ -168,7 +165,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -177,7 +173,6 @@ EXTERN long lcsize;
EXTERN long ncase;
EXTERN long ndata;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN short* op;
@ -190,7 +185,6 @@ EXTERN Sym* symlist;
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
@ -238,7 +232,6 @@ void errorexit(void);
int find1(long, int);
int find2(long, int);
void follow(void);
void gethunk(void);
int gnuxi(Ieee*, int, int);
void histtoauto(void);
double ieeedtod(Ieee*);
@ -250,7 +243,6 @@ Sym* lookup(char*, int);
void lput(long);
void main(int, char*[]);
void mkfwd(void);
void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
void patch(void);

View file

@ -14,9 +14,12 @@ OFILES=\
HFILES=\
l.h\
../2c/2.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
enam.$O: ../2c/enam.c
$CC $CFLAGS ../2c/enam.c
compat.$O: ../cc/compat

View file

@ -1104,28 +1104,6 @@ appendp(Prog *q)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../5c/5.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Gen Gen;
@ -96,14 +93,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -115,11 +110,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* alloc(long);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -160,20 +152,3 @@ void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
int myfork(void);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../5c/5.out.h\
../cc/compat.h\
y.tab.h\
a.h\
@ -16,4 +17,4 @@ BIN=/$objtype/bin
< /sys/src/cmd/mkone
YFLAGS=-D1 -d
lex.$O: ../cc/macbody ../cc/lexbody
lex.$O: ../cc/macbody ../cc/lexbody ../cc/compat

View file

@ -18,6 +18,7 @@ OFILES=\
HFILES=\
gc.h\
5.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../5c/5.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define LIBNAMELEN 300
@ -252,7 +249,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -260,7 +256,6 @@ EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long instoffset;
EXTERN Opcross opcross[8];
EXTERN Oprang oprange[ALAST];
@ -270,7 +265,6 @@ EXTERN uchar repop[ALAST];
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[C_GOK+1][C_GOK+1];
EXTERN Prog zprg;
@ -349,7 +343,6 @@ int fileexists(char*);
int find1(long, int);
char* findlib(char*);
void follow(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@ -363,7 +356,6 @@ void cput(int);
void lput(long);
void lputl(long);
void mkfwd(void);
void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void nuxiinit(void);

View file

@ -15,6 +15,7 @@ OFILES=\
HFILES=\
l.h\
../5c/5.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@ -25,5 +26,7 @@ BIN=/$objtype/bin
enam.$O: ../5c/enam.c
$CC $CFLAGS ../5c/enam.c
compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.5

View file

@ -1135,28 +1135,6 @@ prg(void)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -2,11 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../6c/6.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Ref Ref;
@ -109,14 +105,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -128,10 +122,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -168,28 +160,7 @@ void macend(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* Posix.c/Inferno.c/Nt.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../6c/6.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -19,6 +19,7 @@ OFILES=\
HFILES=\
gc.h\
6.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,55 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void*, ulong)
{
fprint(2, "realloc called\n");
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void*, uintptr)
{
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../6c/6.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define P ((Prog*)0)
#define S ((Sym*)0)
@ -279,7 +276,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN uchar inuxi1[1];
EXTERN uchar inuxi2[2];
EXTERN uchar inuxi4[4];
@ -293,7 +289,6 @@ EXTERN int regrex[D_NONE+1];
EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN char* outfile;
@ -303,7 +298,6 @@ EXTERN Sym* symlist;
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN vlong textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
@ -358,7 +352,6 @@ int find1(long, int);
int find1v(vlong, int);
int find2(long, int);
void follow(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@ -371,7 +364,6 @@ void lput(long);
void lputl(long);
void main(int, char*[]);
void mkfwd(void);
void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
int opsize(Prog*);

View file

@ -29,3 +29,4 @@ UPDATE=\
enam.$O: ../6c/enam.c
$CC $CFLAGS ../6c/enam.c
compat.$O: ../cc/compat

View file

@ -1205,28 +1205,6 @@ appendp(Prog *q)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -5,13 +5,10 @@
#include <libc.h>
#include <bio.h>
#include "../7c/7.out.h"
#include "../cc/compat.h"
typedef vlong int64;
#ifndef EXTERN
#define EXTERN extern
#endif
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
@ -101,14 +98,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -120,11 +115,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* alloc(long);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -161,25 +153,7 @@ void outhist(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
int myfork(void);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../7c/7.out.h\
../cc/compat.h\
y.tab.h\
a.h\
@ -16,4 +17,5 @@ BIN=/$objtype/bin
< /sys/src/cmd/mkone
YFLAGS=-D1 -d
lex.$O: ../cc/macbody ../cc/lexbody
lex.$O: ../cc/macbody ../cc/lexbody ../cc/compat

View file

@ -18,6 +18,7 @@ OFILES=\
HFILES=\
gc.h\
7.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../7c/7.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define LIBNAMELEN 300
@ -291,7 +288,6 @@ EXTERN Sym* hash[NHASH];
EXTERN Sym* histfrog[MAXHIST];
EXTERN int histfrogp;
EXTERN int histgen;
EXTERN char* hunk;
EXTERN char* library[50];
EXTERN char* libraryobj[50];
@ -300,7 +296,6 @@ EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN char* noname;
EXTERN vlong instoffset;
EXTERN Opcross opcross[8];
@ -310,7 +305,6 @@ EXTERN uchar repop[ALAST];
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN vlong textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int xrefresolv;
@ -378,7 +372,6 @@ vlong entryvalue(void);
void errorexit(void);
void export(void);
void follow(void);
void gethunk(void);
void histtoauto(void);
void* halloc(usize);
int isnop(Prog*);
@ -395,7 +388,6 @@ void lput(long);
void lputl(long);
void mkfwd(void);
int movcon(vlong);
void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void nuxiinit(void);

View file

@ -20,6 +20,7 @@ OFILES=\
HFILES=\
l.h\
../7c/7.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@ -33,5 +34,7 @@ cnam.c: l.h mkcname
enam.$O: ../7c/enam.c
$CC $CFLAGS ../7c/enam.c
compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.7

View file

@ -1161,28 +1161,6 @@ halloc(usize n)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../8c/8.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Ref Ref;
@ -109,14 +106,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Gen nullgen;
EXTERN char* outfile;
@ -128,10 +123,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -168,28 +161,7 @@ void macend(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../8c/8.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -20,6 +20,7 @@ OFILES=\
HFILES=\
gc.h\
8.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void*, ulong)
{
fprint(2, "realloc called\n");
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../8c/8.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
#define P ((Prog*)0)
#define S ((Sym*)0)
@ -255,7 +252,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -266,7 +262,6 @@ EXTERN char reg[D_XNONE];
EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long nsymbol;
EXTERN char* noname;
EXTERN char* outfile;
@ -276,7 +271,6 @@ EXTERN Sym* symlist;
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
@ -328,7 +322,6 @@ void export(void);
int find1(long, int);
int find2(long, int);
void follow(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
@ -341,7 +334,6 @@ void lput(long);
void lputl(long);
void main(int, char*[]);
void mkfwd(void);
void* mysbrk(ulong);
void nuxiinit(void);
void objfile(char*);
int opsize(Prog*);

View file

@ -13,6 +13,7 @@ OFILES=\
HFILES=\
l.h\
../cc/compat.h\
../8c/8.out.h\
BIN=/$objtype/bin
@ -29,3 +30,4 @@ UPDATE=\
enam.$O: ../8c/enam.c
$CC $CFLAGS ../8c/enam.c
compat.$O: ../cc/compat

View file

@ -1179,28 +1179,6 @@ appendp(Prog *q)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{

View file

@ -5,9 +5,7 @@
#pragma lib "../cc/cc.a$O"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Node Node;
typedef struct Sym Sym;
@ -184,13 +182,6 @@ enum
NALIGN,
};
enum /* also in ../{8a,0a}.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
enum
{
DMARK,
@ -437,7 +428,6 @@ EXTERN Decl* firstdcl;
EXTERN int fperror;
EXTERN Sym* hash[NHASH];
EXTERN int hasdoubled;
EXTERN char* hunk;
EXTERN char* include[20];
EXTERN Io* iofree;
EXTERN Io* ionext;
@ -451,7 +441,6 @@ EXTERN long lineno;
EXTERN long nearln;
EXTERN int nerrors;
EXTERN int newflag;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN Node* nodproto;
EXTERN Node* nodcast;
@ -471,7 +460,6 @@ EXTERN Type* tufield;
EXTERN int thechar;
EXTERN char* thestring;
EXTERN Type* thisfn;
EXTERN uintptr thunk;
EXTERN Type* types[NTYPE];
EXTERN Type* fntypes[NTYPE];
EXTERN Node* initlist;
@ -521,21 +509,6 @@ extern ulong thash2;
extern ulong thash3;
extern ulong thash[];
/*
* compat.c/unix.c/windows.c
*/
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
int myaccess(char*);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);
/*
* parser
*/
@ -545,8 +518,6 @@ int mpatov(char*, vlong*);
/*
* lex.c
*/
void* allocn(void*, long, long);
void* alloc(long);
void cinit(void);
int compile(char*, char**, int);
void errorexit(void);
@ -666,7 +637,6 @@ int castucom(Node*);
int deadheads(Node*);
Type* dotsearch(Sym*, Type*, Node*, long*);
long dotoffset(Type*, Type*, Node*);
void gethunk(void);
Node* invert(Node*);
int bitno(long);
void makedot(Node*, Type*, long);

View file

@ -1,4 +1,3 @@
int
myaccess(char *f)
{
@ -77,3 +76,117 @@ myfork(void)
{
return fork();
}
/*
* real allocs
*/
void
gethunk(void)
{
char *h;
ulong nh;
nh = NHUNK;
if(thunk >= 10L*NHUNK)
nh = 10L*NHUNK;
h = (char*)mysbrk(nh);
if(h == (char*)-1)
sysfatal("out of memory");
if(nhunk == 0)
hunk = h;
else
nh += (h - hunk) - nhunk;
nhunk += nh;
thunk += nh;
}
void*
alloc(long n)
{
void *p;
while((uintptr)hunk & 7) {
hunk++;
nhunk--;
}
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void*
allocn(void *p, long on, long n)
{
void *q;
q = (uchar*)p + on;
if(q != hunk || nhunk < n) {
while(nhunk < on+n)
gethunk();
memmove(hunk, p, on);
p = hunk;
hunk += on;
nhunk -= on;
}
hunk += n;
nhunk -= n;
return p;
}
/*
* fake mallocs
*/
void*
malloc(ulong n)
{
return alloc(n);
}
void*
calloc(ulong m, ulong n)
{
return alloc(m*n);
}
void*
realloc(void *o, ulong n)
{
ulong m;
void *a;
if(n == 0)
return nil;
if(o == nil)
return alloc(n);
a = alloc(n);
m = (char*)a - (char*)o;
if(m < n)
n = m;
memmove(a, o, n);
return a;
}
void
free(void*)
{
}
/* needed when profiling */
void*
mallocz(ulong size, int)
{
return alloc(size);
}
void
setmalloctag(void*, uintptr)
{
}
void
setrealloctag(void*, uintptr)
{
}

View file

@ -1,62 +1,2 @@
#include "cc.h"
#include "compat"
/*
* fake mallocs
*/
void*
malloc(ulong n)
{
return alloc(n);
}
void*
calloc(ulong m, ulong n)
{
return alloc(m*n);
}
void*
realloc(void *o, ulong n)
{
ulong m;
void *a;
if(n == 0)
return nil;
if(o == nil)
return alloc(n);
a = alloc(n);
m = (char*)a - (char*)o;
if(m < n)
n = m;
memmove(a, o, n);
return a;
}
void
free(void*)
{
}
/* needed when profiling */
void*
mallocz(ulong size, int clr)
{
void *v;
v = alloc(size);
if(clr && v != nil)
memset(v, 0, size);
return v;
}
void
setmalloctag(void*, uintptr)
{
}
void
setrealloctag(void*, uintptr)
{
}

35
sys/src/cmd/cc/compat.h Normal file
View file

@ -0,0 +1,35 @@
/*
* functions shared by compilers, linkers and assemblers.
*/
#ifndef EXTERN
#define EXTERN extern
#endif
enum
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
EXTERN int systemtype(int);
EXTERN int pathchar(void);
EXTERN int myaccess(char *);
EXTERN int mywait(int*);
EXTERN int mycreat(char*, int);
EXTERN char* mygetwd(char*, int);
EXTERN int myexec(char*, char*[]);
EXTERN int mydup(int, int);
EXTERN int myfork(void);
EXTERN int mypipe(int*);
EXTERN void* mysbrk(ulong);
EXTERN void gethunk(void);
EXTERN char* hunk;
EXTERN uintptr nhunk;
EXTERN uintptr thunk;
EXTERN void* alloc(long n);
EXTERN void* allocn(void *p, long on, long n);

View file

@ -1524,45 +1524,6 @@ VBconv(Fmt *fp)
return fmtstrcpy(fp, str);
}
/*
* real allocs
*/
void*
alloc(long n)
{
void *p;
while((uintptr)hunk & MAXALIGN) {
hunk++;
nhunk--;
}
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void*
allocn(void *p, long on, long n)
{
void *q;
q = (uchar*)p + on;
if(q != hunk || nhunk < n) {
while(nhunk < on+n)
gethunk();
memmove(hunk, p, on);
p = hunk;
hunk += on;
nhunk -= on;
}
hunk += n;
nhunk -= n;
return p;
}
void
setinclude(char *p)
{

View file

@ -37,45 +37,6 @@ pragincomplete(void)
;
}
/*
* real allocs
*/
void*
alloc(long n)
{
void *p;
while((uintptr)hunk & MAXALIGN) {
hunk++;
nhunk--;
}
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void*
allocn(void *p, long on, long n)
{
void *q;
q = (uchar*)p + on;
if(q != hunk || nhunk < n) {
while(nhunk < on+n)
gethunk();
memmove(hunk, p, on);
p = hunk;
hunk += on;
nhunk -= on;
}
hunk += n;
nhunk -= n;
return p;
}
void
setinclude(char *p)
{

View file

@ -1,3 +1,2 @@
#include "cc.h"
#include "macbody"

View file

@ -847,22 +847,3 @@ linehist(char *f, int offset)
ehist->link = h;
ehist = h;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 10L*NHUNK)
nh = 10L*NHUNK;
h = (char*)mysbrk(nh);
if(h == (char*)-1) {
yyerror("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}

View file

@ -19,6 +19,7 @@ OFILES=\
omachcap.$O\
HFILES=cc.h\
compat.h\
y.tab.h\
YFILES=cc.y\
@ -34,7 +35,9 @@ install:V: $LIB
$LIB: $LIBOBJ
ar vu $LIB $OFILES
mac.$O: macbody
mac.$O: macbody
compat.$O: compat
everything:V:
# mk the current compilers

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../kc/k.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Gen Gen;
@ -95,14 +92,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int ninclude;
EXTERN int nosched;
EXTERN Gen nullgen;
@ -115,11 +110,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* alloc(long);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -154,29 +146,7 @@ void dodefine(char*);
void prfile(long);
void outhist(void);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../kc/k.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -17,6 +17,7 @@ OFILES=\
HFILES=\
gc.h\
k.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../kc/k.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Adr Adr;
typedef struct Sym Sym;
@ -224,7 +221,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -232,7 +228,6 @@ EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN char* noname;
EXTERN long instoffset;
EXTERN char* outfile;
@ -241,7 +236,6 @@ EXTERN long symsize;
EXTERN long staticgen;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr tothunk;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int version;
EXTERN Prog zprg;
@ -290,7 +284,6 @@ void errorexit(void);
void exchange(Prog*);
int find1(long, int);
void follow(void);
void gethunk(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
int isnop(Prog*);
@ -301,7 +294,6 @@ void initmuldiv(void);
Sym* lookup(char*, int);
void lput(long);
void mkfwd(void);
void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void noops(void);

View file

@ -16,9 +16,13 @@ OFILES=\
HFILES=\
l.h\
../kc/k.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
enam.$O: ../kc/enam.c
$CC $CFLAGS ../kc/enam.c
compat.$O: ../cc/compat

View file

@ -194,7 +194,7 @@ main(int argc, char *argv[])
out:
if(debug['v']) {
Bprint(&bso, "%5.2f cpu time\n", cputime());
Bprint(&bso, "%zud memory used\n", tothunk);
Bprint(&bso, "%zud memory used\n", thunk);
Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
}
@ -976,29 +976,6 @@ prg(void)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(tothunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(tothunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char *)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
tothunk += nh;
}
void
doprof1(void)
{

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../qc/q.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Gen Gen;
@ -115,14 +112,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int nosched;
EXTERN int ninclude;
EXTERN Gen nullgen;
@ -135,7 +130,6 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void errorexit(void);
@ -173,28 +167,7 @@ void dodefine(char*);
void prfile(long);
void outhist(void);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../qc/q.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -18,6 +18,7 @@ OFILES=\
HFILES=\
gc.h\
q.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void*, ulong)
{
fprint(2, "realloc called\n");
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../qc/q.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Adr Adr;
typedef struct Sym Sym;
@ -216,7 +213,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -224,7 +220,6 @@ EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN char* noname;
EXTERN long instoffset;
EXTERN char* outfile;
@ -234,7 +229,6 @@ EXTERN long symsize;
EXTERN long staticgen;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr tothunk;
EXTERN char xcmp[C_NCLASS][C_NCLASS];
EXTERN int version;
EXTERN Prog zprg;
@ -289,7 +283,6 @@ void exchange(Prog*);
void export(void);
int find1(long, int);
void follow(void);
void gethunk(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
void import(void);
@ -301,7 +294,6 @@ void initmuldiv(void);
Sym* lookup(char*, int);
void lput(long);
void mkfwd(void);
void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void noops(void);

View file

@ -18,6 +18,7 @@ OFILES=\
HFILES=\
l.h\
../qc/q.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@ -26,3 +27,4 @@ enam.$O: ../qc/enam.c
$CC $CFLAGS ../qc/enam.c
cnam.c: l.h
rc mkcname
compat.$O: ../cc/compat

View file

@ -273,7 +273,7 @@ main(int argc, char *argv[])
out:
if(debug['v']) {
Bprint(&bso, "%5.2f cpu time\n", cputime());
Bprint(&bso, "%zud memory used\n", tothunk);
Bprint(&bso, "%zud memory used\n", thunk);
Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
}
@ -1110,29 +1110,6 @@ prg(void)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(tothunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(tothunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char *)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
tothunk += nh;
}
void
doprof1(void)
{

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../vc/v.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Sym Sym;
typedef struct Gen Gen;
@ -94,14 +91,12 @@ EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk;
EXTERN char* include[NINCLUDE];
EXTERN Io* iofree;
EXTERN Io* ionext;
EXTERN Io* iostack;
EXTERN long lineno;
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN int nosched;
EXTERN int ninclude;
EXTERN Gen nullgen;
@ -114,11 +109,8 @@ EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN uintptr thunk;
EXTERN Biobuf obuf;
void* alloc(long);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
@ -154,29 +146,7 @@ void outhist(void);
void dodefine(char*);
void prfile(long);
void linehist(char*, int);
void gethunk(void);
void yyerror(char*, ...);
int yyparse(void);
void setinclude(char*);
int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);

View file

@ -7,6 +7,7 @@ OFILES=\
HFILES=\
../vc/v.out.h\
../cc/compat.h\
y.tab.h\
a.h\

View file

@ -17,6 +17,7 @@ OFILES=\
HFILES=\
gc.h\
v.out.h\
../cc/compat.h\
../cc/cc.h\
LIB=../cc/cc.a$O

View file

@ -1,56 +1,2 @@
#include "l.h"
/*
* fake malloc
*/
void*
malloc(ulong n)
{
void *p;
while(n & 7)
n++;
while(nhunk < n)
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p;
}
void
free(void *p)
{
USED(p);
}
void*
calloc(ulong m, ulong n)
{
void *p;
n *= m;
p = malloc(n);
memset(p, 0, n);
return p;
}
void*
realloc(void *p, ulong n)
{
fprint(2, "realloc(0x%p %ld) called\n", p, n);
abort();
return 0;
}
void*
mysbrk(ulong size)
{
return sbrk(size);
}
void
setmalloctag(void *v, uintptr pc)
{
USED(v, pc);
}
#include "../cc/compat"

View file

@ -2,10 +2,7 @@
#include <libc.h>
#include <bio.h>
#include "../vc/v.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
#include "../cc/compat.h"
typedef struct Adr Adr;
typedef struct Sym Sym;
@ -215,7 +212,6 @@ EXTERN char* library[50];
EXTERN char* libraryobj[50];
EXTERN int libraryp;
EXTERN int xrefresolv;
EXTERN char* hunk;
EXTERN char inuxi1[1];
EXTERN char inuxi2[2];
EXTERN char inuxi4[4];
@ -223,7 +219,6 @@ EXTERN Prog* lastp;
EXTERN long lcsize;
EXTERN char literal[32];
EXTERN int nerrors;
EXTERN long nhunk;
EXTERN long instoffset;
EXTERN Opcross opcross[10];
EXTERN Oprang oprange[ALAST];
@ -233,7 +228,6 @@ EXTERN uchar repop[ALAST];
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN uintptr thunk;
EXTERN int version;
EXTERN char xcmp[32][32];
EXTERN Prog zprg;
@ -292,7 +286,6 @@ void errorexit(void);
void exchange(Prog*);
int find1(long, int);
void follow(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);

View file

@ -16,6 +16,7 @@ OFILES=\
HFILES=\
l.h\
../vc/v.out.h\
../cc/compat.h\
BIN=/$objtype/bin
</sys/src/cmd/mkone
@ -23,6 +24,8 @@ BIN=/$objtype/bin
enam.$O: ../vc/enam.c
$CC $CFLAGS ../vc/enam.c
compat.$O: ../cc/compat
x:V: $O.out
$O.out -la -o/dev/null x.v

View file

@ -1058,28 +1058,6 @@ prg(void)
return p;
}
void
gethunk(void)
{
char *h;
long nh;
nh = NHUNK;
if(thunk >= 5L*NHUNK) {
nh = 5L*NHUNK;
if(thunk >= 25L*NHUNK)
nh = 25L*NHUNK;
}
h = mysbrk(nh);
if(h == (char*)-1) {
diag("out of memory");
errorexit();
}
hunk = h;
nhunk = nh;
thunk += nh;
}
void
doprof1(void)
{