/* Copyright (C) 2000 Analog Devices Inc., All Rights Reserved.
** This contains Development IP as
** defined in the ADI/Intel Collaboration Agreement.
** ADI/Intel Confidential
*/

/* this is for machine-independent prototypes. Please use Reg, OpCode and 
** RegClass for the register, opcode and regclass enumeration types (which
** currently differ between platforms.
*/

#ifndef EMACHINE_PROTOTYPES_H
#define EMACHINE_PROTOTYPES_H

/* machine independent prototypes.
*/

struct procfmt;
struct Stkfmt;
struct instrfmt;
struct Exdatafmt;
struct RegSet;
struct paramfm;

/* from outside */
void mc_set_area_offset(int, signed long);
int ememoverlap(void *, void *);
const char *get_memory_bank(void *);
int get_memory_bank_no(void *);
int epermspace( int ,int );
void bytemove( int ,int ,int );
int etempspace( int ,int );
int epermreservespace( int ,int );
void epushlocctr(int);
void epoplocctr(void);
int opt_for_space(double, double);
int opt_for_speed(double, double);
double exec_ratio(double);
void *pgo_derive_counter(void *, long, char *);
void *pgo_unique_counter(void *, long);
double pgo_counter_count(void *, const char *);
void place_pgo_counter(void *);
char *pgo_counter_name(void *);
int plant_pgo_counters(void);

/* from eprocs.c */
void eop( int );
void estkdir( int ,int ,char * ,int );
void Gladir( struct Stkfmt *,int ,int );
void cnstdir( struct Stkfmt *,int ,int );
void estkaddr(int Area,int Offset,char *AdId,int Props);
void estkpar( int ,int ,char * ,int );
void epredictjump(int);
void enotedomain(int);
int ecuntypedname(char *);
extern int FirstTarget;
void estklit(int);
void estkrconst(int Len,int Ad);
void eplabel(int Id);
void enotecc(int val);
void erefer( int ,int );
void estkresult(int Class,int Type,int Bytes);
void esetstructresult(int offset,int size,int align);
void eprecall2(int Id,int Aparamprops);
int ecxname(int type,char * Xref);
void StkTemp(struct Stkfmt *,int,int);
char * egivename(int);
int egiveareaid(int Key);
int egiveareaprops(int Key);
int ereadcc(void);
void enoteestcc(int val);
int ereadestcc(void);
void epromote(int Level);
void edemote(int );
void Stkdir(struct Stkfmt *,int,int);
void Stkreg(struct Stkfmt *,int,int);
void Stkfreg(struct Stkfmt *,int,int);
int etempspace( int ,int );
void PrintEStackFlags( int );

/* from mprocs.c */
void Minitialise( int ,int *);
int MInTraceRegion( void );
void MReinitialise( void );
void Msetoptions2( int );
void Mtidyend( int *);
void MPrintLine( int ,int );
void Mline( int ,int );
int MAddLinePrefix( int ,int );
void MAdjustPar( struct Stkfmt *,int );
void Mgetprocaddr( char * );
void Mgetprocref( int ,int );
int Msetprocref( int ,int ,char * ,int );
void Mswitch( int ,int ,int ,int ,int );
void Mfswitch( int ,int ,int ,int ,struct Stkfmt *);
void Mswitchjump( int ,struct Stkfmt *);
void Mswitchentry( int ,int );
void Mswitchlabel( int ,int ,int );
void Maddrlabel( int ,int ,int );
int Mbrac( int ,int );
void MEndProcs( void );
void Mlinedebug( int );
int Mgetprockey( int ,char * );
struct instrfmt *MDiagnosticMarker(char *);
int Mswtabad(int);
void Mabort2( const char* );
void Mabort( int );
struct Exdatafmt *exrecad(int);
char *Mexname(char *);
char *Mgetname2(int id);
char *Mgetname3(int id, int offset);
int Maddressedlabel(int labkey);
void Mexpcall(int );
void Mspcall(int);
void Mparaminfo2(int *len,int *parindex,int *type,int *offset,int *align,
int *reg);
int Mprivatelabel(void);
void Mlabel(int label);
extern void Mfrlabel( int ,int );
void Msetconst(int Ad,int Len,int *Area,int *Offset);
struct instrfmt *Mmarker(void);
void Msetopd(struct instrfmt *Markerinstr,int NewValue);
int Mgetloadedpars(void);
void Mprecall( int );
void Mcall(int,int,int,int,int);
void Mtrampcall(int Id,int extlevel,int numpars,int paramsize,int proctype);
void MCurrentvalue( struct Stkfmt *,int );
void Mstartproc( int ,int ,int ,int );
int Mtidyproc( int ,int ,int );
void Msideentry( int ,int ,int ,int ,int );
void Mnoteentry( char * ,int );
void Mstartproc( int ,int ,int ,int );
void Mplabel(int) ;
struct Swtabfmt *Mswitchtab(int Mode,int Entries,int Switchid);
void Mintegratecontexts(struct fragfmt *procfrag);
void McheckProfilerCall(int);
void Msetoptstyle(int style);
void Msetinitandfinalexeccounts(double, double);
void Msetexeccount(double);
void Msetloopcountinfo(int lcmin, int lcmax, int lcmodulo);
void MDeriveAllCountersInFrag(struct fragfmt *, long, char *);
double MGetFragCount(struct fragfmt *f);
void MRegenerateFragCounts(void);
struct instrfmt *MPGOCounter(void *);
struct instrfmt *MNextPGOCounter(struct instrfmt *);
void MMovePGOCounters(void);
int MSetEntityProps( int ,int ,int );
void Mareaalign( int ,int );

/* from bprocs.c */
void BInitialise( void );
void BReinitialise( void );
void BSetGISOptions( int ,int ,int ,int ,int ,int ,int ,int );
void BSetOptions( int ,int ,int ,int ,int );
 void BTerminate( void );
int BDifferentMemoryBanks(void *mem1, void *mem2);
void BSetPI(int PIaddr);
struct instrfmt *BMachineInstr( struct instrfmt * ,int );
void BFree(void *);
void BFreeAllocation(void);
void BNewFrag(void);
struct fragfmt *BFragFor(struct instrfmt *);
struct fragfmt *BInsertFrag(struct fragfmt *);
struct instrfmt *BInsertInstr(struct fragfmt *,struct instrfmt *);
struct instrfmt *BObtainInstr();
struct fragfmt *BCurFrag(void);
struct fragfmt *BObtainFrag();
void BCopyInstr(struct instrfmt *source,struct instrfmt *dest);
struct instrfmt *BNewInstr(void);
struct instrfmt *BCurInstr(void);
struct lrecfmt* BLabRecAd(int);
int BLocateLabel(int labnum,int mode);
void BResetProcLabels(int procnum);
void BBreakFrag(int label);
void * BMalloc(int size,int exempt,int areaid);
void BDeleteInstr(struct instrfmt *instr,int physicaldelete);
void BTerminateFrag(int labindex,int dsinstr);
void BSetArchVariant(int variant);
int BGetTraceProc(void);
void BPrintFrags(char * message);
void BPrintProcBanner();
void BPrintOneFrag(struct fragfmt *);
void BMoveAfter(struct fragfmt *,struct fragfmt *,
  struct instrfmt *,struct instrfmt *);
void BMoveBefore(struct fragfmt *,struct fragfmt *,
  struct instrfmt *,struct instrfmt *);
void BCopyCurInstr(struct instrfmt *);
int BLiveRegAfterInstr(struct fragfmt *,struct instrfmt *, int );
void BLiveSetAfterInstr( struct fragfmt *,struct instrfmt *,int *,int *,int *,int *);
char *Bstralloc(int);
char *Bstrdup(const char *);
void BUpdateLiveRegs(struct fragfmt *);
int BIsAnnotated(void);
void BReconvergeLiveness(void);
#if Target == ZP
void BReorganiseFragments(int);
#else
void BReorganiseFragments(void);
#endif
void BSchBasicBlock(struct fragfmt *);
void BInvalidatePreds(void);
void BBasicBlockSchProc(int);
int BRotateLoop(struct fragfmt *, int peepopt(struct fragfmt *f));
int BWorthUnrolling(struct fragfmt *, void peepopt(struct fragfmt *f));

/* from cprocs.c */
int Shiftval(int);
int GetExtFlag(int);
void CChip0(int);

void Ctestmaskbits( struct Stkfmt *,struct Stkfmt *,int );
void Cmakedouble( struct Stkfmt *,struct Stkfmt *);
void Csplitdouble( struct Stkfmt *);
void Caddsub(int,struct Stkfmt *,struct Stkfmt *);
void Cdmult( struct Stkfmt *,struct Stkfmt *);
void Cdmac(struct Stkfmt *,struct Stkfmt *,struct Stkfmt *, int);
void CcmplxMac(struct Stkfmt *,struct Stkfmt *,struct Stkfmt *, int);
void CvectopOp(int ,struct Stkfmt *,struct Stkfmt *);
char * Cgetlabelname(int lab,int procno);
void CSetUserReservedRegs(int[]);
void CPrintUserReservedRegs(void);
void Cresetreguse(int, int);
void Cstackr(int, int);
void Cstackfr(int, int);
void Cpushoperand(struct Stkfmt *);
int Cdividelongint(struct Stkfmt *, struct Stkfmt *, struct Stkfmt *);
#if Target==SHARC
int claimtgtreg(RegClass);
#else
int claimtgtreg(void);
#endif
int claimtgtfreg(void);
void Cstkregvar(int, int, int);
void Cstkfregvar(int, int);
void CregSTop(int, int, struct Stkfmt *, struct Stkfmt *);
void CFregSTop(int, int, struct Stkfmt *, struct Stkfmt *);
void CChangeContexts(int, int);
void ConvertRR(struct Stkfmt *, int);
void ConvertRI(struct Stkfmt *, int, int);
void ConvertRU(struct Stkfmt *, int);
void ConvertRIR(struct Stkfmt *, int);
void ConvertIR(struct Stkfmt *, int);
void ConvertUR(struct Stkfmt *, int);
void ConvertII(struct Stkfmt *, int);
void ConvertSBI(struct Stkfmt *, int);
void ConvertIU(struct Stkfmt *, int);
void ConvertUI(struct Stkfmt *, int);
void ConvertUU(struct Stkfmt *, int);
int LoadIntRO(struct Stkfmt *);
int LoadIntValueRO(int);
int LoadIntRONoExt(struct Stkfmt *);
int LoadIntRW(struct Stkfmt *, int);
int LoadIntRWNoExt(struct Stkfmt *, int);
int LoadRealRO(struct Stkfmt *, int); 
int LoadRealRW(struct Stkfmt *, int, int);
#if Target==ZP
int LoadRealGeneral(RegClass, struct Stkfmt *, int, int, int);
void Cautostackop(int, struct Stkfmt *, struct Stkfmt *);
#else
int LoadRealGeneral(struct Stkfmt *, int, int, int);
void Cautostackop(int, struct Stkfmt *);
#endif
int Cstoreop(struct Stkfmt *, struct Stkfmt *, int);
void Cpushparam(struct Stkfmt *);
void Cpushbytes(int, struct Stkfmt *);
void Cgeneratenop(void);
void Cjump(int, int, int);
int CinvertCC(int);
void Creversedjump(int, int, int);
void Cjumpcond(int, struct Stkfmt *, struct Stkfmt *, int);
void Cestablishlogical(void);
void Cgjump(int, int);
void Cglabelcode(void);
void Ctestval(int, struct Stkfmt *);
void Cswitch(int, int);
void Cswitchjump(int, int, struct Stkfmt *);
void Cfswitchjump(int, struct Stkfmt *);
void Cshift(int, struct Stkfmt *, struct Stkfmt *);
void Creturn(void);
void Cduplicate(void);
void Cdiscardopnd(struct Stkfmt *);
void Cdiscard(struct Stkfmt *);
void CCopyAsm(char *, int);
void Cboundcheck(struct Stkfmt *, struct Stkfmt *, struct Stkfmt *, int);
void Ccomparebytes(int, struct Stkfmt *, struct Stkfmt *, struct Stkfmt *);
void Ccopybytes(struct Stkfmt *, struct Stkfmt *, struct Stkfmt *, int);
void Cunasscheck(struct Stkfmt *, int);
void Cevaluate(struct Stkfmt *, int);
void CStructRes(struct Stkfmt *, int, int);
void Cnoteresult(int, struct Stkfmt *);
void CnoteIOres(void);
void CstkIOres(void);
void Cgetauxsf(void);
void Cadjustauxsf(struct Stkfmt *);
void Cresetauxsf(struct Stkfmt *);
void Cfillbytes(struct Stkfmt *, struct Stkfmt *, struct Stkfmt *);
void Cstkoldframe(void);
void CSetStructResult(int, int, int);
void Cassertaligned(struct Stkfmt *, int);
void Cstkresult(int, int);
void Cstkvr(void);
void Ccall(int, int, int, int);
void Ctrampcall(int, int, int, int);
void CIntBinaryOp(int, struct Stkfmt *, struct Stkfmt *, int);
void CIntUnaryOp(int, struct Stkfmt *);
void CRealBinaryOp(int, struct Stkfmt *, struct Stkfmt *);
void CRealUnaryOp(int, int, struct Stkfmt *);
void CsetFPUtraps(void);
void CDoCharop(int, struct Stkfmt *, struct Stkfmt *, struct Stkfmt *, struct Stkfmt *, int);
void Cnoteindex(int, struct Stkfmt *, struct Stkfmt *);
void Crefer(struct Stkfmt *, int, int);
void Caddress(struct Stkfmt *);
void Cinitialise(int, int, int);
void Creinitialise(int);
void Cstartproc(int);
void Csideentry(int);
void Ccountparams(int *, int);
void GenerateGnuAsm(void);
void Eproccode(int, int*);
void Creport(int);
void CsetParI(struct paramfmt *);
struct paramfmt *GetParI(void);
struct procfmt *GetPI(void);
void CsetPI(struct procfmt *);
void evolatile(int, int, int);
void Cstkreg(int, int);
void Cstkfreg(int, int);
void Cstkbaseindex(int, int, int, int, int, int);
void Cinitreg(int);
void Cincregbylit(int, int, int, int);
void Cincreg(int);
void Cdecreg(int);
void CpassFregMask(int);
void CpassGregMask(int);
void CPrintRegClaimMask(void);
void CTarget(int);
void CQCcontrol(int, int);
void CLogStk(int, int);
void Cstrlen (struct Stkfmt *);
void CLDBits(struct Stkfmt *, int, int);
void CSTBits(struct Stkfmt *, struct Stkfmt *, int, int, int);
void Cmerge1(int,struct Stkfmt *,struct Stkfmt *,struct Stkfmt *);
int CPartWord(struct Stkfmt *Stk);
extern struct procfmt *pi;
extern int Report;
extern struct paramfmt *ParI;

/* Storage Tracking */
/*
 * these arrays track use of the first few locations in the stack
 * and parameter area which enables "dead store elimination"
 * - particularly useful to prevent storing parameters passed in registers
 *
 * Bit 0 - store flag
 * Bit 1 - load flag
 * Bit 2 - address taken flag
 * Bit 3 - allocated as temp
 */

#define ST_STORE  (1<<0)
#define ST_LOAD   (1<<1)
#define ST_ADDR   (1<<2)
#define ST_TEMP   (1<<3)
#define ST_DELETED  (1<<4)
#define ST_HASNEGDOM  (1<<5)

/* we are interested in tracking those memory locations
 * in which parameters passed in registers are saved
 */
#define PARAMST_MAP(x)  (x)
#define PARAMST_SIZE  (1)
extern unsigned char ParamSTflags [PARAMST_SIZE];
extern struct instrfmt *ParamSTmarkers[PARAMST_SIZE];

/* for stack offsets we are interested in the range -1024<=offset<-4
 * element 0 is also used for some special purpose
 */
#define STACKST_LO  (-1024)
#define STACKST_HI  (0)

/* from rprocs.c */
/*
 * these are the functions declared global in pete's new rprocs
 * I cannot beleive they are really all global
 */
void Rinitialise(void);
void RReinitialise(void);
void RInitregAllocation(void);
int CheckFixups(int Area,int Offset,int *TgtArea,int *TgtOffset);
void crecordfixup(int Area,int Offset,int TgtArea,int TgtOffset);
void CDiscardFixup(int area,int offset);
void rclearregs(int mode);
void rclearcallregs(void);
void rclearleafcallregs(int proctype);
void RClearTracking(void);
void ShowEntry(int I,struct Stkfmt *E);
void Cdumpestack(void);
void lockregister(int reg,int eitem,int size);
void unlockregister(int reg);
void unlockreg(int reg);
void forgetreg(int reg);
void setregmemory(int reg,int use,int primdata,int secdata,int size,int addit);
int NextCCField(void);
int NextSelCCField(int mask);
void CCsetimplicitly(int CCfield);
void lockreg(int);
void lockregpair(int);
void unlockregpair(int);
void resetreguse(int Old,int New);
int countunclaimedregs();
void CopyRegMemory(int Sreg,int Dreg);
void copyregmemorypair(int SourceReg,int DestinationReg);
void copyregmemoryquad(int SourceReg,int DestinationReg);
int checkconstantops(int OpReg1,int OpReg2,int *Const1,int *Const2);
int registerstatus(int);
void CleanRegister(int,int Bytes);
void notereguse( int ,int ,int );
 void NoteAddReguse( int ,int ,int );
void userlockreg(int);
void permlockreg(int);
void unlockpermreg(int);
int claimsafereg(void);
void releasereg(int);
void Conditionalreleasereg(int,struct Stkfmt *StkItem);
void freeregs(void);
void releasecallregs(void);
void releaseleafcallregs(int );
void allocregvar(int LogReg);
int alloccsereg(int Class,int Bytes,int Calls);
void freecsereg(int reg);
int findreg(void);
int claimreg(void);
int findregpair(void);
int claimregpair(void);
int claimbyteopreg();
int claimregquad(void);
int claimunusedreg(void);
int claimaddressreg(void);
int claimnamedreg(int);
int claimnamedregpair(int);
int claimnamedtgt(int);
int CheckConstantOp(int OpReg1,int *Const1);
int claimfreg(void);
void manipulateFS( int ,int );
int claimunusedfreg(void);
int claimfregpair(void);
int claimfregquad(void);
int claimmultifreg(int Size);
int CheckRegKey(int use,int primdata,int secdata,int size,int writeable);
int CheckRegKeyandExt( int ,int ,int ,int ,int ,int );
int checkareaaddr(int Area,int *Offset);
int CheckCloseConst(int Const,int *Disp);
int checkfregkey(int use,int primdata,int secdata,int writeable);
int checkfregpairkey(int primdata,int secdata,int writeable);
int checkfregpairkey2(int use,int primdata,int secdata,int writeable);
void CheckConflict(int Base,int Offset,int Size);
void checkregconflict(int);
void CheckIndConflict(struct Stkfmt *Stk);

/* from ARCHprocs.c */
 void SetExtFlag( int ,int );
void ResetReguse( int ,int );
int ParseRegName(const char *);
void *ARCHmalloc(unsigned long);
void CPrintLine(int, int);
void Cprocessproc(void);
int Cvalidatejumps(struct fragfmt *);
void Cestablishca(struct fragfmt *, int *);
void Cdisasfrag(struct fragfmt *);
void Cgeneratefrag(struct fragfmt *);
void COptimiseProc(void);

enum MemoryKind GetMemoryKind(struct Stkfmt *);

/* from ARCHcode.c */
int p5opcodesize(int ,int );
void p5enter(int ,int );
/* from ARCHtabs.c */

/***/
/*************************************/
/** Put Interface Massing of Data   **/
/*************************************/
int pgetbytes( int ,int ,int );
void pdbytes( int ,int ,int ,void *);
void pcbytes( int ,int ,unsigned char * );
void pd( int ,int ,int );
void pd2( int ,int ,int );
void pd4( int ,int ,int );
void pdpattern( int ,int ,int ,int ,int );
void pfiller( int ,int );
/***/
/************************************************/
/** Put Interface RELOCATION and REFERENCES    **/
/************************************************/

int pxname( int ,char * );
int pcommon2( int ,char * );
void pdataentry( char * ,int ,int ,int );
void pfix( int ,int ,int ,int );
void pfix2(int ,int ,int ,int , int);
void pdxref( int ,int ,int );
/***/
/************************************/
/** Put Interface - Miscellaneous  **/
/************************************/
void pendcommon2( int ,int ,int ,int );
int psetfiles2(char *,char*,int);
void pinitialise( int ,int ,int );
void psetoptions(int options);
void preinitialise( void );
void pterminate( int );
void pfaulty( void );
int pnextsymbol( void );
void plinestart( int ,int );
void ppushfile( void );
int ppopfile( void );
int pentry2( int ,int ,int ,char * );
 void pprocend( int ,int ,int );
void pproc( char * ,int ,int ,int *,int );
int pgivecurrentsize( int );
int getspace(int );
void freespace(int);
/***/

/* machine dependent prototypes.
*/

#if Target == FRIO
#include "../frio/prototypes.h"
#elif Target == SHARC
#include "../sharc/prototypes.h"
#elif Target == ZP
#include "../zp/prototypes.h"
#elif Target == 2180 || Target == 2190
#include "../21xx/prototypes.h"
#elif Target==PENTIUM
#include "p5prototypes.h"
#else
#error unknown target
#endif

#endif
