mirror of https://git.wuffs.org/MWCC
495 lines
14 KiB
C
495 lines
14 KiB
C
#include "compiler/common.h"
|
|
|
|
// THESE TYPES ARE NOT YET SORTED
|
|
#include "compiler/tokens.h"
|
|
#include "compiler/CompilerTools.h"
|
|
|
|
#ifdef __MWERKS__
|
|
#pragma options align=mac68k
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
struct DefArgCtorInfo {
|
|
Object *default_func;
|
|
ENode *default_arg;
|
|
};
|
|
|
|
typedef struct XRefOffset {
|
|
UInt32 xrefoffset;
|
|
SInt32 offset;
|
|
} XRefOffset;
|
|
|
|
struct InlineXRef {
|
|
InlineXRef *next;
|
|
Object *object;
|
|
UInt16 xrefmode;
|
|
UInt16 numxrefs;
|
|
XRefOffset xref[1];
|
|
};
|
|
|
|
|
|
|
|
typedef enum ExceptionActionType {
|
|
EAT_NOP,
|
|
EAT_DESTROYLOCAL,
|
|
EAT_DESTROYLOCALCOND,
|
|
EAT_DESTROYLOCALOFFSET,
|
|
EAT_DESTROYLOCALPOINTER,
|
|
EAT_DESTROYLOCALARRAY,
|
|
EAT_DESTROYPARTIALARRAY,
|
|
EAT_DESTROYMEMBER,
|
|
EAT_DESTROYMEMBERCOND,
|
|
EAT_DESTROYMEMBERARRAY,
|
|
EAT_DELETEPOINTER,
|
|
EAT_DELETELOCALPOINTER,
|
|
EAT_DELETEPOINTERCOND,
|
|
EAT_CATCHBLOCK,
|
|
EAT_ACTIVECATCHBLOCK,
|
|
EAT_SPECIFICATION,
|
|
EAT_TERMINATE,
|
|
EAT_DESTROYBASE,
|
|
EAT_NACTIONS
|
|
} ExceptionActionType;
|
|
|
|
struct ExceptionAction {
|
|
ExceptionAction *prev;
|
|
union {
|
|
struct {
|
|
Object *local;
|
|
Object *dtor;
|
|
} destroy_local;
|
|
struct {
|
|
Object *local;
|
|
Object *cond;
|
|
Object *dtor;
|
|
} destroy_local_cond;
|
|
struct {
|
|
Object *local;
|
|
Object *dtor;
|
|
SInt32 offset;
|
|
} destroy_local_offset;
|
|
struct {
|
|
Object *pointer;
|
|
Object *dtor;
|
|
} destroy_local_pointer;
|
|
struct {
|
|
Object *localarray;
|
|
Object *dtor;
|
|
SInt32 elements;
|
|
SInt32 element_size;
|
|
} destroy_local_array;
|
|
struct {
|
|
Object *arraypointer;
|
|
Object *arraycounter;
|
|
Object *dtor;
|
|
Object *element_size;
|
|
} destroy_partial_array;
|
|
struct {
|
|
Object *objectptr;
|
|
Object *dtor;
|
|
SInt32 offset;
|
|
} destroy_member;
|
|
struct {
|
|
Object *objectptr;
|
|
Object *cond;
|
|
Object *dtor;
|
|
SInt32 offset;
|
|
} destroy_member_cond;
|
|
struct {
|
|
Object *objectptr;
|
|
Object *dtor;
|
|
SInt32 offset;
|
|
SInt32 elements;
|
|
SInt32 element_size;
|
|
} destroy_member_array;
|
|
struct {
|
|
Object *pointerobject;
|
|
Object *deletefunc;
|
|
} delete_pointer;
|
|
struct {
|
|
Object *pointerobject;
|
|
Object *deletefunc;
|
|
Object *cond;
|
|
} delete_pointer_cond;
|
|
struct {
|
|
Object *catch_object;
|
|
Object *catch_info_object;
|
|
CLabel *catch_label;
|
|
Object *catch_typeid;
|
|
Type *catch_type;
|
|
UInt32 catch_qual;
|
|
} catch_block;
|
|
struct {
|
|
Object *catch_info_object;
|
|
Boolean call_dtor;
|
|
} active_catch_block;
|
|
struct {
|
|
SInt32 unexp_ids;
|
|
Object **unexp_id;
|
|
CLabel *unexp_label;
|
|
Object *unexp_info_object;
|
|
} specification;
|
|
struct {
|
|
Object *object;
|
|
Boolean is_dep;
|
|
} local;
|
|
} data;
|
|
ExceptionActionType type;
|
|
};
|
|
|
|
struct MemInitializer {
|
|
MemInitializer *next;
|
|
union {
|
|
ENodeList *nodes;
|
|
ENode *expr;
|
|
} e;
|
|
union {
|
|
ObjMemberVar *ivar;
|
|
Type *type;
|
|
} u;
|
|
Boolean is_ivar;
|
|
Boolean is_expr;
|
|
};
|
|
|
|
|
|
typedef enum DepNameType {
|
|
DNT_NAME,
|
|
DNT_CONVERSION,
|
|
DNT_DTOR,
|
|
DNT_NAMESPACE,
|
|
DNT_QUALNAME,
|
|
DNT_TEMPLATE,
|
|
DNT_TYPENAME
|
|
} DepNameType;
|
|
|
|
struct DepName {
|
|
DepName *next;
|
|
union {
|
|
HashNameNode *name;
|
|
NameSpace *nspace;
|
|
struct {
|
|
Type *type;
|
|
UInt32 qual;
|
|
} conv;
|
|
struct {
|
|
HashNameNode *name;
|
|
TemplArg *args;
|
|
} templ;
|
|
struct {
|
|
HashNameNode *name;
|
|
Type *type;
|
|
} tname;
|
|
} u;
|
|
DepNameType type;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum SubKind {
|
|
SUBKIND_NAMESPACE,
|
|
SUBKIND_TYPE,
|
|
SUBKIND_OBJECT
|
|
} SubKind;
|
|
|
|
typedef struct Substitution {
|
|
struct Substitution *next;
|
|
union {
|
|
NameSpace *nspace;
|
|
struct {
|
|
Type *type;
|
|
UInt32 qual;
|
|
} type;
|
|
Object *obj;
|
|
} u;
|
|
int id;
|
|
SubKind kind;
|
|
} Substitution;
|
|
|
|
// Registers.c
|
|
enum {
|
|
RegisterMax = 32
|
|
};
|
|
const char RegClass_SPR = 0;
|
|
const char RegClass_CRFIELD = 1;
|
|
const char RegClass_VR = 2;
|
|
const char RegClass_FPR = 3;
|
|
const char RegClass_GPR = 4;
|
|
const char RegClassMax = 5;
|
|
/*enum RegClass {
|
|
RegClass_SPR,
|
|
RegClass_CRFIELD,
|
|
RegClass_VR,
|
|
RegClass_FPR,
|
|
RegClass_GPR,
|
|
RegClassMax
|
|
};*/
|
|
|
|
enum {
|
|
RegState0 = 0,
|
|
RegState1 = 1,
|
|
RegState2 = 2
|
|
};
|
|
|
|
extern int used_virtual_registers[RegClassMax];
|
|
extern int used_nonvolatile_registers[RegClassMax];
|
|
extern int assignable_registers[RegClassMax];
|
|
extern int n_real_registers[RegClassMax];
|
|
extern int n_scratch_registers[RegClassMax];
|
|
extern int scratch_registers[RegClassMax][RegisterMax];
|
|
extern int n_nonvolatile_registers[RegClassMax];
|
|
extern int nonvolatile_registers[RegClassMax][RegisterMax];
|
|
extern UInt8 reg_state[RegClassMax][RegisterMax];
|
|
extern int first_temporary_register[RegClassMax];
|
|
extern int last_temporary_register[RegClassMax];
|
|
extern char *register_class_name[RegClassMax];
|
|
extern char *register_class_format[RegClassMax];
|
|
extern int coloring;
|
|
extern int optimizing;
|
|
|
|
extern void init_registers();
|
|
extern void assign_register_to_variable(Object *obj, char rclass);
|
|
extern void retain_register_for_argument(Object *obj, char rclass, short reg);
|
|
extern int available_registers(char rclass);
|
|
extern UInt32 volatile_registers(char rclass);
|
|
extern short obtain_nonvolatile_register(char rclass);
|
|
extern void open_temp_registers();
|
|
extern void check_temp_registers();
|
|
extern void close_temp_registers();
|
|
extern int count_scratch_registers();
|
|
extern void init_modified_registers();
|
|
extern void note_modified_registers(Object *obj);
|
|
extern void find_modified_registers(Object *obj, UInt32 *masks);
|
|
|
|
// RegisterInfo.c
|
|
extern short last_exception_register[RegClassMax];
|
|
extern short first_fe_temporary_register[RegClassMax];
|
|
extern short last_argument_register[RegClassMax];
|
|
extern short _FP_;
|
|
extern short _CALLER_SP_;
|
|
extern char *special_register_names[RegClassMax][RegisterMax];
|
|
extern short spr_to_sysreg[4];
|
|
|
|
extern void asm_used_register(char rclass, short reg);
|
|
extern void retain_register(Object *obj, char rclass, short reg);
|
|
extern void retain_GPR_pair(Object *obj, short reg, short regHi);
|
|
extern int is_register_object(Object *obj);
|
|
extern int GetABIFirstNonVolatile(char rclass);
|
|
extern char GetRegisterClassName(char rclass);
|
|
extern void setup_diagnostic_reg_strings();
|
|
extern void init_target_registers();
|
|
extern void assign_register_by_type(Object *obj);
|
|
extern void assign_GPR_pair(Object *obj);
|
|
extern void open_fe_temp_registers();
|
|
extern void set_last_exception_registers();
|
|
extern VarInfo *Registers_GetVarInfo(Object *obj);
|
|
extern int used_vrstate_VRs();
|
|
extern UInt32 colored_vrs_as_vrsave(PCodeBlock *block);
|
|
extern void save_before_coloring_nonvolatile_registers(char rclass);
|
|
extern void reset_nonvolatile_registers(char rclass);
|
|
extern int is_nonvolatile_register(char rclass, int reg);
|
|
extern void init_endian();
|
|
extern void update_asm_nonvolatile_registers();
|
|
|
|
// LOOSE DECLS
|
|
extern short high_offset;
|
|
extern short low_offset;
|
|
extern short high_reg;
|
|
extern short low_reg;
|
|
extern short high_reg2;
|
|
extern short low_reg2;
|
|
extern void PrecompilerRead(short refnum, void *buffer);
|
|
extern void PrecompilerWrite();
|
|
extern void CodeGen_InitCompiler();
|
|
extern void CodeGen_TermCompiler();
|
|
extern void CodeGen_InitBackEndOptions();
|
|
extern void CodeGen_UpdateOptimizerOptions();
|
|
extern void CodeGen_UpdateBackEndOptions();
|
|
extern void MWUnmangle(const char *name, char *buf, int size);
|
|
//extern COpts copts;
|
|
extern CParams *cparamblkptr;
|
|
extern FuncArg elipsis;
|
|
extern FuncArg oldstyle;
|
|
extern jmp_buf errorreturn;
|
|
extern Boolean cprep_nomem_exit;
|
|
extern Boolean anyerrors;
|
|
extern Boolean fatalerrors;
|
|
extern SInt32 lines;
|
|
extern char string[256];
|
|
extern TemplStack *ctempl_curinstance;
|
|
//extern ParserTryBlock *trychain;
|
|
extern Boolean in_assembler;
|
|
extern Boolean preprocessing_only;
|
|
extern void AssemblerError();
|
|
#include "compiler/types.h"
|
|
extern short tk;
|
|
extern HashNameNode *tkidentifier;
|
|
extern short lex();
|
|
extern short notendofline();
|
|
extern short lookahead();
|
|
extern Object *CClass_Constructor(TypeClass *tclass);
|
|
extern Object *CClass_Destructor(TypeClass *tclass);
|
|
extern int CClass_CheckPures(TypeClass *tclass);
|
|
extern Boolean CClass_IsConstructor(Object *func);
|
|
extern short CABI_GetStructResultArgumentIndex();
|
|
extern Boolean CParser_HasInternalLinkage(Object *obj);
|
|
extern HashNameNode *CParser_GetUniqueName();
|
|
extern SInt32 CParser_GetUniqueID();
|
|
extern Boolean CParserIsVolatileExpr(ENode *expr);
|
|
extern Boolean CParserIsConstExpr(ENode *expr);
|
|
extern Boolean CParser_IsPublicRuntimeObject(Object *obj);
|
|
extern Boolean CParser_ParseOperatorName(short *token, Boolean flag1, Boolean flag2);
|
|
extern Boolean CTemplTool_EqualArgs(TemplArg *a, TemplArg *b);
|
|
extern Boolean CTemplTool_IsTemplateArgumentDependentType(Type *type);
|
|
extern TypeTemplDep *CDecl_NewTemplDepType(TypeTemplDepType tdtype);
|
|
extern Type *CDecl_NewPointerType(Type *type);
|
|
extern Type *CDecl_NewStructType(SInt32 size, SInt32 align);
|
|
extern Type *CDecl_NewArrayType(Type *type, SInt32 num);
|
|
extern GList name_mangle_list;
|
|
extern void CPrep_UnLex();
|
|
extern Type *CTempl_ClassGetType(TypeClass *tclass);
|
|
//extern short is_typesame(Type *t1, Type *t2);
|
|
extern Boolean is_unsigned(Type *type);
|
|
extern void CDecl_CompleteType(Type *type);
|
|
extern TemplArg *CTempl_ParseUncheckTemplArgs(void *fixmelater, Boolean flag);
|
|
extern SInt32 CClass_VirtualBaseOffset(TypeClass *tclass, TypeClass *base);
|
|
extern Boolean CClass_IsMoreAccessiblePath(BClassList *a, BClassList *b);
|
|
extern Boolean CClass_ClassDominates(TypeClass *a, TypeClass *b);
|
|
extern Boolean CParser_CheckTemplateClassUsage(TemplClass *tmclass, Boolean flag);
|
|
extern Type *CTempl_ParseTemplTemplParam(Type *t);
|
|
extern void CClass_CheckPathAccess(BClassList *bcl, void *unk, AccessType access);
|
|
extern BClassList *CClass_GetPathCopy(BClassList *path, Boolean flag);
|
|
extern Object *CClass_ThisSelfObject();
|
|
extern AccessType global_access;
|
|
extern HashNameNode *this_name_node;
|
|
extern void CParser_Setup();
|
|
extern Boolean CParser_IsConst(Type *type, UInt32 qual);
|
|
extern void CParser_Cleanup();
|
|
extern void SetupPrecompiler(Boolean flag);
|
|
extern void CleanupPrecompiler();
|
|
extern void SetupAssembler();
|
|
extern void CleanupAssembler();
|
|
extern void ObjGen_Setup();
|
|
extern void ObjGen_Finish();
|
|
extern void ObjGen_Cleanup();
|
|
extern void ObjGen_CodeCleanup();
|
|
extern void ObjGen_DeclareFloatConst(Object *obj);
|
|
extern void ObjGen_DeclareVectorConst(Object *obj);
|
|
extern void ObjGen_DeclareCodeLabel(Object *labelobj, SInt32 offset, Object *funcobj);
|
|
extern Boolean ObjGen_IsExported(Object *obj);
|
|
extern void PointerAnalysis_Setup();
|
|
extern void PointerAnalysis_Cleanup();
|
|
extern Boolean CPrep_Preprocess();
|
|
extern void cparser();
|
|
extern void CBrowse_Setup(CParams *param);
|
|
extern void CBrowse_Finish(CParams *param);
|
|
extern void CBrowse_Cleanup(CParams *param);
|
|
extern UInt32 CParser_GetTypeQualifiers(Type *type, UInt32 qual);
|
|
extern void CTemplClass_RegisterUsingDecl(TemplClass *tclass, Type *target, AccessType access);
|
|
extern void CodeGen_InsertSpecialMacros();
|
|
extern void CPrep_PreprocessDumpFileInfo(Boolean flag);
|
|
extern void CPrep_PreprocessDumpNewLine();
|
|
extern Boolean gForceSourceLoc;
|
|
extern void ObjGen_SegmentName(); // might take an arg, not sure since it's empty
|
|
extern void ObjGen_SrcBreakName(HashNameNode *name, SInt32 modDate, Boolean flag);
|
|
extern char *precomp_target_str;
|
|
extern Object *CParser_ParseObject();
|
|
extern void PointerAnalysis_PragmaMode();
|
|
extern void CExcept_Terminate();
|
|
extern void CExcept_ArrayInit();
|
|
extern void CExcept_Magic();
|
|
extern void CSOM_PragmaReleaseOrder();
|
|
extern void CSOM_PragmaClassVersion();
|
|
extern void CSOM_PragmaMetaClass();
|
|
extern void CSOM_PragmaCallStyle();
|
|
extern short GetPrec(short t);
|
|
extern short localcount;
|
|
extern Boolean InlineAsm_gccmode;
|
|
extern void initialize_aliases();
|
|
extern Statement *current_statement;
|
|
extern int pclist_bad_operand;
|
|
extern int n_real_registers[];
|
|
extern short pic_base_reg;
|
|
extern Object pic_base;
|
|
extern ObjectList *exceptionlist;
|
|
extern ObjectList *arguments;
|
|
extern ObjectList *locals;
|
|
extern ObjectList *toclist;
|
|
extern Boolean uses_globals;
|
|
extern Boolean requires_frame;
|
|
extern void assign_locals_to_memory(ObjectList *locals);
|
|
extern PCodeLabel *pic_base_pcodelabel;
|
|
extern void *make_alias(Object *obj, SInt32 offset, SInt32 size);
|
|
extern Boolean is_volatile_object(Object *obj);
|
|
extern Boolean is_pascal_object(Object *obj);
|
|
extern Boolean local_is_16bit_offset(Object *obj);
|
|
extern Boolean can_add_displ_to_local(Object *obj, SInt32 displ);
|
|
extern int local_base_register(Object *obj);
|
|
extern int disable_optimizer;
|
|
extern Boolean IsTempName(HashNameNode *name);
|
|
extern void assign_local_memory(Object *obj);
|
|
extern void move_varargs_to_memory();
|
|
extern Type stvoid;
|
|
extern TypePointer void_ptr;
|
|
extern int countexceptionactionregisters(ExceptionAction *exc);
|
|
extern void noteexceptionactionregisters(ExceptionAction *exc, PCodeArg *);
|
|
extern void recordexceptionactions(PCode *pc, ExceptionAction *exc);
|
|
extern SInt32 functionbodyoffset;
|
|
extern Object *CParser_NewRTFunc(Type *returntype, HashNameNode *name, Boolean unkflag, int argcount, ...);
|
|
extern SInt32 curstmtvalue;
|
|
extern Object *__memcpy_object;
|
|
extern void CInit_RewriteString(ENode *expr, Boolean flag);
|
|
extern int is_intrinsic_function_call(ENode *expr);
|
|
extern SInt32 I8_log2n(SInt64 value);
|
|
extern void PPCError_Error(int code);
|
|
|
|
enum {
|
|
INTRINSIC_8 = 8,
|
|
INTRINSIC_35 = 35,
|
|
INTRINSIC_36 = 36
|
|
};
|
|
|
|
enum {
|
|
CPU_PPC401,
|
|
CPU_PPC403,
|
|
CPU_PPC505,
|
|
CPU_PPC509,
|
|
CPU_PPC555,
|
|
CPU_PPC601,
|
|
CPU_PPC602,
|
|
CPU_PPC603,
|
|
CPU_PPC603e,
|
|
CPU_PPC604,
|
|
CPU_PPC604e,
|
|
CPU_PPC740,
|
|
CPU_PPC750,
|
|
CPU_PPC801,
|
|
CPU_PPC821,
|
|
CPU_PPC823,
|
|
CPU_PPC850,
|
|
CPU_PPC860,
|
|
CPU_PPC8240,
|
|
CPU_PPC8260,
|
|
CPU_PPC7400 = 0x15,
|
|
CPU_PPCGEKKO,
|
|
CPU_PPCELF,
|
|
CPU_PPC7450,
|
|
CPU_PPC556,
|
|
CPU_PPC565
|
|
};
|
|
|
|
extern char *ScanFloat(char *input, double *output, Boolean *fail);
|
|
|
|
#define FITS_IN_SHORT(value) ( (value) == ((short) (value)) )
|
|
// should HIGH_PART have (short) around it?
|
|
#define HIGH_PART(value) ( (((value) >> 16) + (((value) & 0x8000) >> 15)) )
|
|
#define LOW_PART(value) ( (short) (value) )
|
|
|
|
#ifdef __MWERKS__
|
|
#pragma options align=reset
|
|
#endif
|