Commit db3a21d7 authored by Kai Backman's avatar Kai Backman

5a 5c 5l from inferno distribution

R=rsc
APPROVED=rsc
DELTA=19042  (19042 added, 0 deleted, 0 changed)
OCL=26268
CL=26270
parent b260916a
// Inferno utils/5a/a.h
// http://code.google.com/p/inferno-os/source/browse/utils/5a/a.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <lib9.h>
#include <bio.h>
#include "../5c/5.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io;
typedef struct Hist Hist;
#define MAXALIGN 7
#define FPCHIP 1
#define NSYMB 8192
#define BUFSIZ 8192
#define HISTSZ 20
#define NINCLUDE 10
#define NHUNK 10000
#define EOF (-1)
#define IGN (-2)
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
#define NHASH 503
#define STRINGSZ 200
#define NMACRO 10
struct Sym
{
Sym* link;
char* macro;
long value;
ushort type;
char *name;
char sym;
};
#define S ((Sym*)0)
EXTERN struct
{
char* p;
int c;
} fi;
struct Io
{
Io* link;
char b[BUFSIZ];
char* p;
short c;
short f;
};
#define I ((Io*)0)
EXTERN struct
{
Sym* sym;
short type;
} h[NSYM];
struct Gen
{
Sym* sym;
long offset;
short type;
short reg;
short name;
double dval;
char sval[8];
};
struct Hist
{
Hist* link;
char* name;
long line;
long offset;
};
#define H ((Hist*)0)
enum
{
CLAST,
CMACARG,
CMACRO,
CPREPROC,
Always = 14,
};
EXTERN char debug[256];
EXTERN Sym* hash[NHASH];
EXTERN char* Dlist[30];
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;
EXTERN int pass;
EXTERN char* pathname;
EXTERN long pc;
EXTERN int peekc;
EXTERN int sym;
EXTERN char symb[NSYMB];
EXTERN int thechar;
EXTERN char* thestring;
EXTERN long thunk;
EXTERN Biobuf obuf;
void* alloc(long);
void* allocn(void*, long, long);
void errorexit(void);
void pushio(void);
void newio(void);
void newfile(char*, int);
Sym* slookup(char*);
Sym* lookup(void);
void syminit(Sym*);
long yylex(void);
int getc(void);
int getnsc(void);
void unget(int);
int escchar(int);
void cinit(void);
void pinit(char*);
void cclean(void);
int isreg(Gen*);
void outcode(int, int, Gen*, int, Gen*);
void zname(char*, int, int);
void zaddr(Gen*, int);
void ieeedtod(Ieee*, double);
int filbuf(void);
Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
void macexpand(Sym*, char*);
void macinc(void);
void maclin(void);
void macprag(void);
void macif(int);
void macend(void);
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);
This diff is collapsed.
This diff is collapsed.
// Inferno utils/5c/5.out.h
// http://code.google.com/p/inferno-os/source/browse/utils/5c/5.out.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#define NSNAME 8
#define NSYM 50
#define NREG 16
#define NOPROF (1<<0)
#define DUPOK (1<<1)
#define ALLTHUMBS (1<<2)
#define REGRET 0
#define REGARG 0
/* compiler allocates R1 up as temps */
/* compiler allocates register variables R3 up */
#define REGEXT 10
/* compiler allocates external registers R10 down */
#define REGTMP 11
#define REGSB 12
#define REGSP 13
#define REGLINK 14
#define REGPC 15
#define REGTMPT 7 /* used by the loader for thumb code */
#define NFREG 8
#define FREGRET 0
#define FREGEXT 7
/* compiler allocates register variables F0 up */
/* compiler allocates external registers F7 down */
enum as
{
AXXX,
AAND,
AEOR,
ASUB,
ARSB,
AADD,
AADC,
ASBC,
ARSC,
ATST,
ATEQ,
ACMP,
ACMN,
AORR,
ABIC,
AMVN,
AB,
ABL,
/*
* Do not reorder or fragment the conditional branch
* opcodes, or the predication code will break
*/
ABEQ,
ABNE,
ABCS,
ABHS,
ABCC,
ABLO,
ABMI,
ABPL,
ABVS,
ABVC,
ABHI,
ABLS,
ABGE,
ABLT,
ABGT,
ABLE,
AMOVWD,
AMOVWF,
AMOVDW,
AMOVFW,
AMOVFD,
AMOVDF,
AMOVF,
AMOVD,
ACMPF,
ACMPD,
AADDF,
AADDD,
ASUBF,
ASUBD,
AMULF,
AMULD,
ADIVF,
ADIVD,
ASRL,
ASRA,
ASLL,
AMULU,
ADIVU,
AMUL,
ADIV,
AMOD,
AMODU,
AMOVB,
AMOVBU,
AMOVH,
AMOVHU,
AMOVW,
AMOVM,
ASWPBU,
ASWPW,
ANOP,
ARFE,
ASWI,
AMULA,
ADATA,
AGLOBL,
AGOK,
AHISTORY,
ANAME,
ARET,
ATEXT,
AWORD,
ADYNT,
AINIT,
ABCASE,
ACASE,
AEND,
AMULL,
AMULAL,
AMULLU,
AMULALU,
ABX,
ABXRET,
ADWORD,
ASIGNAME,
ALAST,
};
/* scond byte */
#define C_SCOND ((1<<4)-1)
#define C_SBIT (1<<4)
#define C_PBIT (1<<5)
#define C_WBIT (1<<6)
#define C_FBIT (1<<7) /* psr flags-only */
#define C_UBIT (1<<7) /* up bit */
/* type/name */
#define D_GOK 0
#define D_NONE 1
/* type */
#define D_BRANCH (D_NONE+1)
#define D_OREG (D_NONE+2)
#define D_CONST (D_NONE+7)
#define D_FCONST (D_NONE+8)
#define D_SCONST (D_NONE+9)
#define D_PSR (D_NONE+10)
#define D_REG (D_NONE+12)
#define D_FREG (D_NONE+13)
#define D_FILE (D_NONE+16)
#define D_OCONST (D_NONE+17)
#define D_FILE1 (D_NONE+18)
#define D_SHIFT (D_NONE+19)
#define D_FPCR (D_NONE+20)
#define D_REGREG (D_NONE+21)
/* name */
#define D_EXTERN (D_NONE+3)
#define D_STATIC (D_NONE+4)
#define D_AUTO (D_NONE+5)
#define D_PARAM (D_NONE+6)
/*
* this is the ranlib header
*/
#define SYMDEF "__.SYMDEF"
/*
* this is the simulated IEEE floating point
*/
typedef struct ieee Ieee;
struct ieee
{
long l; /* contains ls-man 0xffffffff */
long h; /* contains sign 0x80000000
exp 0x7ff00000
ms-man 0x000fffff */
};
This diff is collapsed.
// Inferno utils/5c/gc.h
// http://code.google.com/p/inferno-os/source/browse/utils/5c/gc.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "../cc/cc.h"
#include "../5c/5.out.h"
/*
* 5c/arm
* Arm 7500
*/
#define SZ_CHAR 1
#define SZ_SHORT 2
#define SZ_INT 4
#define SZ_LONG 4
#define SZ_IND 4
#define SZ_FLOAT 4
#define SZ_VLONG 8
#define SZ_DOUBLE 8
#define FNX 100
typedef struct Adr Adr;
typedef struct Prog Prog;
typedef struct Case Case;
typedef struct C1 C1;
typedef struct Multab Multab;
typedef struct Hintab Hintab;
typedef struct Var Var;
typedef struct Reg Reg;
typedef struct Rgn Rgn;
#define R0ISZERO 0
struct Adr
{
long offset;
double dval;
char sval[NSNAME];
Ieee ieee;
Sym* sym;
char type;
char reg;
char name;
char etype;
};
#define A ((Adr*)0)
#define INDEXED 9
struct Prog
{
Adr from;
Adr to;
Prog* link;
long lineno;
char as;
char reg;
uchar scond;
};
#define P ((Prog*)0)
struct Case
{
Case* link;
long val;
long label;
char def;
};
#define C ((Case*)0)
struct C1
{
long val;
long label;
};
struct Multab
{
long val;
char code[20];
};
struct Hintab
{
ushort val;
char hint[10];
};
struct Var
{
long offset;
Sym* sym;
char name;
char etype;
};
struct Reg
{
long pc;
long rpo; /* reverse post ordering */
Bits set;
Bits use1;
Bits use2;
Bits refbehind;
Bits refahead;
Bits calbehind;
Bits calahead;
Bits regdiff;
Bits act;
long regu;
long loop; /* could be shorter */
Reg* log5;
long active;
Reg* p1;
Reg* p2;
Reg* p2link;
Reg* s1;
Reg* s2;
Reg* link;
Prog* prog;
};
#define R ((Reg*)0)
#define NRGN 600
struct Rgn
{
Reg* enter;
short cost;
short varno;
short regno;
};
EXTERN long breakpc;
EXTERN Case* cases;
EXTERN Node constnode;
EXTERN Node fconstnode;
EXTERN long continpc;
EXTERN long curarg;
EXTERN long cursafe;
EXTERN Prog* firstp;
EXTERN Prog* lastp;
EXTERN long maxargsafe;
EXTERN int mnstring;
EXTERN Multab multab[20];
EXTERN int retok;
EXTERN int hintabsize;
EXTERN Node* nodrat;
EXTERN Node* nodret;
EXTERN Node* nodsafe;
EXTERN long nrathole;
EXTERN long nstring;
EXTERN Prog* p;
EXTERN long pc;
EXTERN Node regnode;
EXTERN char string[NSNAME];
EXTERN Sym* symrathole;
EXTERN Node znode;
EXTERN Prog zprog;
EXTERN char reg[NREG+NFREG];
EXTERN long exregoffset;
EXTERN long exfregoffset;
EXTERN int suppress;
#define BLOAD(r) band(bnot(r->refbehind), r->refahead)
#define BSTORE(r) band(bnot(r->calbehind), r->calahead)
#define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
#define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z])
#define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32))
#define CLOAD 4
#define CREF 5
#define CINF 1000
#define LOOP 3
EXTERN Rgn region[NRGN];
EXTERN Rgn* rgp;
EXTERN int nregion;
EXTERN int nvar;
EXTERN Bits externs;
EXTERN Bits params;
EXTERN Bits consts;
EXTERN Bits addrs;
EXTERN long regbits;
EXTERN long exregbits;
EXTERN int change;
EXTERN Reg* firstr;
EXTERN Reg* lastr;
EXTERN Reg zreg;
EXTERN Reg* freer;
EXTERN Var var[NVAR];
EXTERN long* idom;
EXTERN Reg** rpo2r;
EXTERN long maxnr;
extern char* anames[];
extern Hintab hintab[];
/*
* sgen.c
*/
void codgen(Node*, Node*);
void gen(Node*);
void noretval(int);
void usedset(Node*, int);
void xcom(Node*);
int bcomplex(Node*, Node*);
/*
* cgen.c
*/
void cgen(Node*, Node*, int);
void reglcgen(Node*, Node*, Node*);
void lcgen(Node*, Node*);
void bcgen(Node*, int);
void boolgen(Node*, int, Node*);
void sugen(Node*, Node*, long);
void layout(Node*, Node*, int, int, Node*);
/*
* txt.c
*/
void ginit(void);
void gclean(void);
void nextpc(void);
void gargs(Node*, Node*, Node*);
void garg1(Node*, Node*, Node*, int, Node**);
Node* nodconst(long);
Node* nod32const(vlong);
Node* nodfconst(double);
void nodreg(Node*, Node*, int);
void regret(Node*, Node*);
int tmpreg(void);
void regalloc(Node*, Node*, Node*);
void regfree(Node*);
void regialloc(Node*, Node*, Node*);
void regsalloc(Node*, Node*);
void regaalloc1(Node*, Node*);
void regaalloc(Node*, Node*);
void regind(Node*, Node*);
void gprep(Node*, Node*);
void raddr(Node*, Prog*);
void naddr(Node*, Adr*);
void gmovm(Node*, Node*, int);
void gmove(Node*, Node*);
void gmover(Node*, Node*);
void gins(int a, Node*, Node*);
void gopcode(int, Node*, Node*, Node*);
int samaddr(Node*, Node*);
void gbranch(int);
void patch(Prog*, long);
int sconst(Node*);
int sval(long);
void gpseudo(int, Sym*, Node*);
/*
* swt.c
*/
int swcmp(const void*, const void*);
void doswit(Node*);
void swit1(C1*, int, long, Node*, Node*);
void cas(void);
void bitload(Node*, Node*, Node*, Node*, Node*);
void bitstore(Node*, Node*, Node*, Node*, Node*);
long outstring(char*, long);
int mulcon(Node*, Node*);
Multab* mulcon0(long);
void nullwarn(Node*, Node*);
void sextern(Sym*, Node*, long, long);
void gextern(Sym*, Node*, long, long);
void outcode(void);
void ieeedtod(Ieee*, double);
/*
* list
*/
void listinit(void);
int Pconv(Fmt*);
int Aconv(Fmt*);
int Dconv(Fmt*);
int Sconv(Fmt*);
int Nconv(Fmt*);
int Bconv(Fmt*);
int Rconv(Fmt*);
/*
* reg.c
*/
Reg* rega(void);
int rcmp(const void*, const void*);
void regopt(Prog*);
void addmove(Reg*, int, int, int);
Bits mkvar(Adr*, int);
void prop(Reg*, Bits, Bits);
void loopit(Reg*, long);
void synch(Reg*, Bits);
ulong allreg(ulong, Rgn*);
void paint1(Reg*, int);
ulong paint2(Reg*, int);
void paint3(Reg*, int, long, int);
void addreg(Adr*, int);
/*
* peep.c
*/
void peep(void);
void excise(Reg*);
Reg* uniqp(Reg*);
Reg* uniqs(Reg*);
int regtyp(Adr*);
int regzer(Adr*);
int anyvar(Adr*);
int subprop(Reg*);
int copyprop(Reg*);
int shiftprop(Reg*);
void constprop(Adr*, Adr*, Reg*);
int copy1(Adr*, Adr*, Reg*, int);
int copyu(Prog*, Adr*, Adr*);
int copyas(Adr*, Adr*);
int copyau(Adr*, Adr*);
int copyau1(Prog*, Adr*);
int copysub(Adr*, Adr*, Adr*, int);
int copysub1(Prog*, Adr*, Adr*, int);
long RtoB(int);
long FtoB(int);
int BtoR(long);
int BtoF(long);
void predicate(void);
int isbranch(Prog *);
int predicable(Prog *p);
int modifiescpsr(Prog *p);
#pragma varargck type "A" int
#pragma varargck type "B" Bits
#pragma varargck type "D" Adr*
#pragma varargck type "N" Adr*
#pragma varargck type "R" Adr*
#pragma varargck type "P" Prog*
#pragma varargck type "S" char*
// Inferno utils/5c/list.c
// http://code.google.com/p/inferno-os/source/browse/utils/5c/list.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#define EXTERN
#include "gc.h"
void
listinit(void)
{
fmtinstall('A', Aconv);
fmtinstall('P', Pconv);
fmtinstall('S', Sconv);
fmtinstall('N', Nconv);
fmtinstall('B', Bconv);
fmtinstall('D', Dconv);
fmtinstall('R', Rconv);
}
int
Bconv(Fmt *fp)
{
char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
str[0] = 0;
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
if(str[0])
strcat(str, " ");
if(var[i].sym == S) {
sprint(ss, "$%ld", var[i].offset);
s = ss;
} else
s = var[i].sym->name;
if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
break;
strcat(str, s);
bits.b[i/32] &= ~(1L << (i%32));
}
return fmtstrcpy(fp, str);
}
char *extra [] = {
".EQ", ".NE", ".CS", ".CC",
".MI", ".PL", ".VS", ".VC",
".HI", ".LS", ".GE", ".LT",
".GT", ".LE", "", ".NV",
};
int
Pconv(Fmt *fp)
{
char str[STRINGSZ], sc[20];
Prog *p;
int a, s;
p = va_arg(fp->args, Prog*);
a = p->as;
s = p->scond;
strcpy(sc, extra[s & C_SCOND]);
if(s & C_SBIT)
strcat(sc, ".S");
if(s & C_PBIT)
strcat(sc, ".P");
if(s & C_WBIT)
strcat(sc, ".W");
if(s & C_UBIT) /* ambiguous with FBIT */
strcat(sc, ".U");
if(a == AMOVM) {
if(p->from.type == D_CONST)
sprint(str, " %A%s %R,%D", a, sc, &p->from, &p->to);
else
if(p->to.type == D_CONST)
sprint(str, " %A%s %D,%R", a, sc, &p->from, &p->to);
else
sprint(str, " %A%s %D,%D", a, sc, &p->from, &p->to);
} else
if(a == ADATA)
sprint(str, " %A %D/%d,%D", a, &p->from, p->reg, &p->to);
else
if(p->as == ATEXT)
sprint(str, " %A %D,%d,%D", a, &p->from, p->reg, &p->to);
else
if(p->reg == NREG)
sprint(str, " %A%s %D,%D", a, sc, &p->from, &p->to);
else
if(p->from.type != D_FREG)
sprint(str, " %A%s %D,R%d,%D", a, sc, &p->from, p->reg, &p->to);
else
sprint(str, " %A%s %D,F%d,%D", a, sc, &p->from, p->reg, &p->to);
return fmtstrcpy(fp, str);
}
int
Aconv(Fmt *fp)
{
char *s;
int a;
a = va_arg(fp->args, int);
s = "???";
if(a >= AXXX && a < ALAST)
s = anames[a];
return fmtstrcpy(fp, s);
}
int
Dconv(Fmt *fp)
{
char str[STRINGSZ];
Adr *a;
char *op;
int v;
a = va_arg(fp->args, Adr*);
switch(a->type) {
default:
sprint(str, "GOK-type(%d)", a->type);
break;
case D_NONE:
str[0] = 0;
if(a->name != D_NONE || a->reg != NREG || a->sym != S)
sprint(str, "%N(R%d)(NONE)", a, a->reg);
break;
case D_CONST:
if(a->reg != NREG)
sprint(str, "$%N(R%d)", a, a->reg);
else
sprint(str, "$%N", a);
break;
case D_SHIFT:
v = a->offset;
op = "<<>>->@>" + (((v>>5) & 3) << 1);
if(v & (1<<4))
sprint(str, "R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15);
else
sprint(str, "R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31);
if(a->reg != NREG)
sprint(str+strlen(str), "(R%d)", a->reg);
break;
case D_OREG:
if(a->reg != NREG)
sprint(str, "%N(R%d)", a, a->reg);
else
sprint(str, "%N", a);
break;
case D_REG:
sprint(str, "R%d", a->reg);
if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(R%d)(REG)", a, a->reg);
break;
case D_FREG:
sprint(str, "F%d", a->reg);
if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(R%d)(REG)", a, a->reg);
break;
case D_PSR:
sprint(str, "PSR");
if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(PSR)(REG)", a);
break;
case D_BRANCH:
sprint(str, "%ld(PC)", a->offset-pc);
break;
case D_FCONST:
sprint(str, "$%.17e", a->dval);
break;
case D_SCONST:
sprint(str, "$\"%S\"", a->sval);
break;
}
return fmtstrcpy(fp, str);
}
int
Rconv(Fmt *fp)
{
char str[STRINGSZ];
Adr *a;
int i, v;
a = va_arg(fp->args, Adr*);
sprint(str, "GOK-reglist");
switch(a->type) {
case D_CONST:
if(a->reg != NREG)
break;
if(a->sym != S)
break;
v = a->offset;
strcpy(str, "");
for(i=0; i<NREG; i++) {
if(v & (1<<i)) {
if(str[0] == 0)
strcat(str, "[R");
else
strcat(str, ",R");
sprint(strchr(str, 0), "%d", i);
}
}
strcat(str, "]");
}
return fmtstrcpy(fp, str);
}
int
Sconv(Fmt *fp)
{
int i, c;
char str[STRINGSZ], *p, *a;
a = va_arg(fp->args, char*);
p = str;
for(i=0; i<NSNAME; i++) {
c = a[i] & 0xff;
if(c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z' ||
c >= '0' && c <= '9' ||
c == ' ' || c == '%') {
*p++ = c;
continue;
}
*p++ = '\\';
switch(c) {
case 0:
*p++ = 'z';
continue;
case '\\':
case '"':
*p++ = c;
continue;
case '\n':
*p++ = 'n';
continue;
case '\t':
*p++ = 't';
continue;
case '\r':
*p++ = 'r';
continue;
case '\f':
*p++ = 'f';
continue;
}
*p++ = (c>>6) + '0';
*p++ = ((c>>3) & 7) + '0';
*p++ = (c & 7) + '0';
}
*p = 0;
return fmtstrcpy(fp, str);
}
int
Nconv(Fmt *fp)
{
char str[STRINGSZ];
Adr *a;
Sym *s;
a = va_arg(fp->args, Adr*);
s = a->sym;
if(s == S) {
sprint(str, "%ld", a->offset);
goto out;
}
switch(a->name) {
default:
sprint(str, "GOK-name(%d)", a->name);
break;
case D_NONE:
sprint(str, "%ld", a->offset);
break;
case D_EXTERN:
sprint(str, "%s+%ld(SB)", s->name, a->offset);
break;
case D_STATIC:
sprint(str, "%s<>+%ld(SB)", s->name, a->offset);
break;
case D_AUTO:
sprint(str, "%s-%ld(SP)", s->name, -a->offset);
break;
case D_PARAM:
sprint(str, "%s+%ld(FP)", s->name, a->offset);
break;
}
out:
return fmtstrcpy(fp, str);
}
# Inferno utils/5c/mkenam
# http://code.google.com/p/inferno-os/source/browse/utils/5c/mkenam
#
# Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
# Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
# Portions Copyright © 1997-1999 Vita Nuova Limited
# Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
# Portions Copyright © 2004,2006 Bruce Ellis
# Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
# Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
# Portions Copyright © 2009 The Go Authors. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ed - ../5c/5.out.h <<'!'
v/^ A/d
,s/^ A/ "/
g/ .*$/s///
,s/,*$/",/
1i
char* anames[] =
{
.
$a
};
.
w enam.c
Q
!
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Inferno utils/5l/l.h
// http://code.google.com/p/inferno-os/source/browse/utils/5l/l.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <lib9.h>
#include <bio.h>
#include "../5c/5.out.h"
#ifndef EXTERN
#define EXTERN extern
#endif
/* do not undefine this - code will be removed eventually */
#define CALLEEBX
typedef struct Adr Adr;
typedef struct Sym Sym;
typedef struct Autom Auto;
typedef struct Prog Prog;
typedef struct Optab Optab;
typedef struct Oprang Oprang;
typedef uchar Opcross[32][2][32];
typedef struct Count Count;
typedef struct Use Use;
#define P ((Prog*)0)
#define S ((Sym*)0)
#define U ((Use*)0)
#define TNAME (curtext&&curtext->from.sym?curtext->from.sym->name:noname)
struct Adr
{
union
{
long u0offset;
char* u0sval;
Ieee* u0ieee;
} u0;
union
{
Auto* u1autom;
Sym* u1sym;
} u1;
char type;
char reg;
char name;
char class;
};
#define offset u0.u0offset
#define sval u0.u0sval
#define ieee u0.u0ieee
#define autom u1.u1autom
#define sym u1.u1sym
struct Prog
{
Adr from;
Adr to;
union
{
long u0regused;
Prog* u0forwd;
} u0;
Prog* cond;
Prog* link;
long pc;
long line;
uchar mark;
uchar optab;
uchar as;
uchar scond;
uchar reg;
uchar align;
};
#define regused u0.u0regused
#define forwd u0.u0forwd
struct Sym
{
char *name;
short type;
short version;
short become;
short frame;
uchar subtype;
ushort file;
long value;
long sig;
uchar used;
uchar thumb; // thumb code
uchar foreign; // called by arm if thumb, by thumb if arm
uchar fnptr; // used as fn ptr
Use* use;
Sym* link;
};
#define SIGNINTERN (1729*325*1729)
struct Autom
{
Sym* asym;
Auto* link;
long aoffset;
short type;
};
struct Optab
{
char as;
char a1;
char a2;
char a3;
char type;
char size;
char param;
char flag;
};
struct Oprang
{
Optab* start;
Optab* stop;
};
struct Count
{
long count;
long outof;
};
struct Use
{
Prog* p; /* use */
Prog* ct; /* curtext */
Use* link;
};
enum
{
STEXT = 1,
SDATA,
SBSS,
SDATA1,
SXREF,
SLEAF,
SFILE,
SCONST,
SSTRING,
SUNDEF,
SREMOVED,
SIMPORT,
SEXPORT,
LFROM = 1<<0,
LTO = 1<<1,
LPOOL = 1<<2,
V4 = 1<<3, /* arm v4 arch */
C_NONE = 0,
C_REG,
C_REGREG,
C_SHIFT,
C_FREG,
C_PSR,
C_FCR,
C_RCON, /* 0xff rotated */
C_NCON, /* ~RCON */
C_SCON, /* 0xffff */
C_BCON, /* thumb */
C_LCON,
C_FCON,
C_GCON, /* thumb */
C_RACON,
C_SACON, /* thumb */
C_LACON,
C_GACON, /* thumb */
C_RECON,
C_LECON,
C_SBRA,
C_LBRA,
C_GBRA, /* thumb */
C_HAUTO, /* halfword insn offset (-0xff to 0xff) */
C_FAUTO, /* float insn offset (0 to 0x3fc, word aligned) */
C_HFAUTO, /* both H and F */
C_SAUTO, /* -0xfff to 0xfff */
C_LAUTO,
C_HEXT,
C_FEXT,
C_HFEXT,
C_SEXT,
C_LEXT,
C_HOREG,
C_FOREG,
C_HFOREG,
C_SOREG,
C_ROREG,
C_SROREG, /* both S and R */
C_LOREG,
C_GOREG, /* thumb */
C_PC,
C_SP,
C_HREG,
C_OFFPC, /* thumb */
C_ADDR, /* relocatable address */
C_GOK,
/* mark flags */
FOLL = 1<<0,
LABEL = 1<<1,
LEAF = 1<<2,
BIG = (1<<12)-4,
STRINGSZ = 200,
NHASH = 10007,
NHUNK = 100000,
MINSIZ = 64,
NENT = 100,
MAXIO = 8192,
MAXHIST = 20, /* limit of path elements for history symbols */
Roffset = 22, /* no. bits for offset in relocation address */
Rindex = 10, /* no. bits for index in relocation address */
};
EXTERN union
{
struct
{
uchar obuf[MAXIO]; /* output buffer */
uchar ibuf[MAXIO]; /* input buffer */
} u;
char dbuf[1];
} buf;
#define cbuf u.obuf
#define xbuf u.ibuf
#define setarch(p) if((p)->as==ATEXT) thumb=(p)->reg&ALLTHUMBS
#define setthumb(p) if((p)->as==ATEXT) seenthumb|=(p)->reg&ALLTHUMBS
#ifndef COFFCVT
EXTERN long HEADR; /* length of header */
EXTERN int HEADTYPE; /* type of header */
EXTERN long INITDAT; /* data location */
EXTERN long INITRND; /* data round above text location */
EXTERN long INITTEXT; /* text location */
EXTERN char* INITENTRY; /* entry point */
EXTERN long autosize;
EXTERN Biobuf bso;
EXTERN long bsssize;
EXTERN int cbc;
EXTERN uchar* cbp;
EXTERN int cout;
EXTERN Auto* curauto;
EXTERN Auto* curhist;
EXTERN Prog* curp;
EXTERN Prog* curtext;
EXTERN Prog* datap;
EXTERN long datsize;
EXTERN char debug[128];
EXTERN Prog* etextp;
EXTERN Prog* firstp;
EXTERN char fnuxi4[4];
EXTERN char fnuxi8[8];
EXTERN char* noname;
EXTERN Sym* hash[NHASH];
EXTERN Sym* histfrog[MAXHIST];
EXTERN int histfrogp;
EXTERN int histgen;
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];
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];
EXTERN Oprang thumboprange[ALAST];
EXTERN char* outfile;
EXTERN long pc;
EXTERN uchar repop[ALAST];
EXTERN long symsize;
EXTERN Prog* textp;
EXTERN long textsize;
EXTERN long thunk;
EXTERN int version;
EXTERN char xcmp[C_GOK+1][C_GOK+1];
EXTERN Prog zprg;
EXTERN int dtype;
EXTERN int armv4;
EXTERN int thumb;
EXTERN int seenthumb;
EXTERN int armsize;
EXTERN int doexp, dlm;
EXTERN int imports, nimports;
EXTERN int exports, nexports;
EXTERN char* EXPTAB;
EXTERN Prog undefp;
#define UP (&undefp)
extern char* anames[];
extern Optab optab[];
extern Optab thumboptab[];
void addpool(Prog*, Adr*);
EXTERN Prog* blitrl;
EXTERN Prog* elitrl;
void initdiv(void);
EXTERN Prog* prog_div;
EXTERN Prog* prog_divu;
EXTERN Prog* prog_mod;
EXTERN Prog* prog_modu;
#pragma varargck type "A" int
#pragma varargck type "C" int
#pragma varargck type "D" Adr*
#pragma varargck type "N" Adr*
#pragma varargck type "P" Prog*
#pragma varargck type "S" char*
int Aconv(Fmt*);
int Cconv(Fmt*);
int Dconv(Fmt*);
int Nconv(Fmt*);
int Pconv(Fmt*);
int Sconv(Fmt*);
int aclass(Adr*);
int thumbaclass(Adr*, Prog*);
void addhist(long, int);
void append(Prog*, Prog*);
void asmb(void);
void asmdyn(void);
void asmlc(void);
void asmthumbmap(void);
void asmout(Prog*, Optab*);
void thumbasmout(Prog*, Optab*);
void asmsym(void);
long atolwhex(char*);
Prog* brloop(Prog*);
void buildop(void);
void thumbbuildop(void);
void buildrep(int, int);
void cflush(void);
void ckoff(Sym*, long);
int chipfloat(Ieee*);
int cmp(int, int);
int compound(Prog*);
double cputime(void);
void datblk(long, long, int);
void diag(char*, ...);
void divsig(void);
void dodata(void);
void doprof1(void);
void doprof2(void);
void dynreloc(Sym*, long, int);
long entryvalue(void);
void errorexit(void);
void exchange(Prog*);
void export(void);
int find1(long, int);
void follow(void);
void gethunk(void);
void histtoauto(void);
void hputl(int);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
void import(void);
int isnop(Prog*);
void ldobj(int, long, char*);
void loadlib(void);
void listinit(void);
Sym* lookup(char*, int);
void cput(int);
void hput(long);
void lput(long);
void lputl(long);
void mkfwd(void);
void* mysbrk(ulong);
void names(void);
void nocache(Prog*);
void nuxiinit(void);
void objfile(char*);
int ocmp(const void*, const void*);
long opirr(int);
Optab* oplook(Prog*);
long oprrr(int, int);
long olr(long, int, int, int);
long olhr(long, int, int, int);
long olrr(int, int, int, int);
long olhrr(int, int, int, int);
long osr(int, int, long, int, int);
long oshr(int, long, int, int);
long ofsr(int, int, long, int, int, Prog*);
long osrr(int, int, int, int);
long oshrr(int, int, int, int);
long omvl(Prog*, Adr*, int);
void patch(void);
void prasm(Prog*);
void prepend(Prog*, Prog*);
Prog* prg(void);
int pseudo(Prog*);
void putsymb(char*, int, long, int);
void readundefs(char*, int);
long regoff(Adr*);
int relinv(int);
long rnd(long, long);
void span(void);
void strnput(char*, int);
void undef(void);
void undefsym(Sym*);
void wput(long);
void xdefine(char*, int, long);
void xfol(Prog*);
void zerosig(char*);
void noops(void);
long immrot(ulong);
long immaddr(long);
long opbra(int, int);
int brextra(Prog*);
int isbranch(Prog*);
int fnpinc(Sym *);
int fninc(Sym *);
void thumbcount(void);
void reachable(void);
void fnptrs(void);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment