extern void ObjInit( void ) { //*************************** CurrAlignment = 0; // alignment disabled // Here we add a label marking the beginning of the code stream. // Relocs to this label can be done by ObjEmitMetaReloc(). doStackLabel( SymAdd( ASMCODESTART, SYM_LABEL ) ); }
void addSymbol(pSymTabEntry pEntry) { if (SymFind(symTab, pEntry) != NULL) { reportError(CERR_REDEFN_IGNORED, pEntry->name); } else { if (!SymAdd(symTab, pEntry)) { outOfMemory(); } g_numSymbols++; // Number of symbols in symbol table } }
static void FormalParam(void) { SymPtr sym; Pointer param; MatchToken(tVARIABLE); param = GetIdent(); sym = SymAdd(param); sym->kind = LOCAL_KIND; NextToken(); }
static void MethodDefinition(void) { Pointer name; SymPtr sym; Int32 l1,shift; SkipToken(tDEF); /* MatchToken(tVARIABLE); */ name = GetIdent(); /* maybe check for duplicates here? */ sym = SymAdd(name); sym->kind = FUNCTION_KIND; sym->object.u.ival = vm_addr(); sym->flags |= cur_scope; if( in_class && base_class!=NULL ) sym->clas=base_class; if( in_class && super_class!=NULL ) sym->super=super_class; NextToken(); SymEnterScope(); in_method=TRUE; l1 = vm_genI(op_link,0); /* check for any formal parameters */ if( Token==tLPAREN ) { FormalParamList(sym); } /* function statements */ local_num=0; StatementList(); sym->nlocs = local_num; /* backpatch any return statements */ CheckReturn(sym); /* implicit return */ shift = in_class ? 2 : 1; vm_genI(op_rts,sym->nlocs+sym->nargs+shift); /* reserve space for locals */ vm_patch(l1,sym->nlocs); SymExitScope(sym); in_method=FALSE; /* end of function */ SkipToken(tEND); if( Token==tSEMI ) NextToken(); }
extern void DirInit( void ) //************************* { dir_table *curr; sym_handle sym; int i, n; n = sizeof( asm_directives ) / sizeof( asm_directives[0] ); for( i = 0; i < n; i++ ) { curr = &asm_directives[i]; sym = SymAdd( curr->name, SYM_DIRECTIVE ); SymSetLink( sym, curr ); } autoAlignment = TRUE; AsDirSetOptions = NONE; _DirSet( AT ); _DirSet( MACRO ); _DirSet( REORDER ); }
extern sym_handle AsNumLabelSymLookup( int_32 *label_num ) { //********************************************************** // Look/Cook up symbol handles for both forward and backward references for // each label_num. sym_handle sym; char *sym_name; if( *label_num > 0 ) { ++numLabelCounts[ *label_num - 1 ]; // flip "e"/"o" if forward } sym_name = AsNumLabelMakeName( *label_num ); if( *label_num > 0 ) { --numLabelCounts[ *label_num - 1 ]; // change back "e"/"o" } sym = SymLookup( sym_name ); if( sym ) return( sym ); return( SymAdd( sym_name, SYM_LABEL ) ); }
// Saves all of the Team Data into the External File "hockteam" void Save_Teams(void) { short Size = sizeof(Names[g->No_Teams[0]]) + sizeof(Names[g->No_Teams[1]]) + 11; char *Base; HANDLE h; /* "hockteam" File Layout: unsigned short Size; unsigned char No1; unsigned char No2; Names Western[g->No_Teams[0]]; Names Eastern[g->No_Teams[1]]; char Zero1; char Type[4]; char Zero2; char Tag; */ UnArchive(SYMSTR_CONST("hockteam")); // Make sure that before writing to the file, it is not archived if ((h = HeapAlloc(Size)) == H_NULL) { Archive(SYMSTR_CONST("hockteam")); return; } if ((Base = HeapDeref(DerefSym(SymAdd(SYMSTR_CONST("hockteam")))->handle = h)) == (void*)0xFFFFFFFF) { HeapFree(h); return; } // Write data to "hockteam" file *(short*)Base = Size - 2; Base += 2; *Base++ = g->No_Teams[0]; *Base++ = g->No_Teams[1]; memcpy(Base, Western, sizeof(Names[g->No_Teams[0]])); Base += sizeof(Names[g->No_Teams[0]]); memcpy(Base, Eastern, sizeof(Names[g->No_Teams[1]])); Base += sizeof(Names[g->No_Teams[1]]); *Base++ = 0; strcpy(Base, "Team"); *(Base + 5) = OTH_TAG; Archive(SYMSTR_CONST("hockteam")); // Automatically Archive the team file in case of a crash }
// Saves the Difficulty and Time Limit Settings void Save_Config(void) { //unsigned char Extension[] = { 0, 'c', 'f', 'g', 0, OTH_TAG }; unsigned short Size = 11 + sizeof(RowKey[8]); char *Base; HANDLE h; if (g->Speed < 1 || g->Speed > 15) g->Speed = 7; /* "hockycfg" File Layout: unsigned short Size; char Config[3 + sizeof(RowKey[11])]; char Zero1; char Type[3]; char Zero2; char Tag; */ UnArchive(SYMSTR_CONST("hockycfg")); // Make sure that before writing to the file, it is not archived if ((h = HeapAlloc(Size)) == H_NULL) return; // Note: HeapDeref(H_NULL) == 0xFFFFFFFF. if ((Base = HeapDeref(DerefSym(SymAdd(SYMSTR_CONST("hockycfg")))->handle = h)) == (void*)0xFFFFFFFF) { HeapFree(h); return; } // Write data to "hockycfg" file *(short*)Base = Size - 2; Base += 2; memcpy(Base, &g->Keys, 3 + sizeof(RowKey[8])); Base += 3 + sizeof(RowKey[8]); *Base++ = 0; strcpy(Base, "cfg"); *(Base + 4) = OTH_TAG; Archive(SYMSTR_CONST("hockycfg")); // Automatically Archive the config file in case of a crash }
static void AddParms( void ) { PARMPTR parm; PARMPTR prev_parm; SYM_HANDLE sym_handle; SYM_HANDLE prev_sym_handle; SYM_HANDLE new_sym_handle; TYPEPTR typ = NULL; int parm_count; id_hash_idx h; parm_list *parmlist; SYM_ENTRY new_sym; CurFunc->u.func.locals = SYM_NULL; CurFunc->u.func.parms = SYM_NULL; parmlist = NULL; prev_sym_handle = SYM_NULL; parm_count = 0; prev_parm = NULL; for( parm = ParmList; parm != NULL; parm = parm->next_parm ) { new_sym_handle = SYM_NULL; parm->sym.flags |= SYM_DEFINED | SYM_ASSIGNED; parm->sym.attribs.is_parm = true; h = parm->sym.info.hash; if( parm->sym.name[0] == '\0' ) { /* no name ==> ... */ parm->sym.sym_type = GetType( TYPE_DOT_DOT_DOT ); parm->sym.attribs.stg_class = SC_AUTO; } else if( parm->sym.sym_type == NULL ) { parm->sym.sym_type = TypeDefault(); parm->sym.attribs.stg_class = SC_AUTO; } else { /* go through ParmList again, looking for FLOAT parms change the name to ".P" and duplicate the symbol with type float and generate an assignment statement. */ typ = parm->sym.sym_type; SKIP_TYPEDEFS( typ ); switch( typ->decl_type ) { case TYPE_CHAR: case TYPE_UCHAR: case TYPE_SHORT: if( CompFlags.strict_ANSI ) { parm->sym.sym_type = GetType( TYPE_INT ); } break; case TYPE_USHORT: if( CompFlags.strict_ANSI ) { #if TARGET_SHORT == TARGET_INT parm->sym.sym_type = GetType( TYPE_UINT ); #else parm->sym.sym_type = GetType( TYPE_INT ); #endif } break; case TYPE_FLOAT: memcpy( &new_sym, &parm->sym, sizeof( SYM_ENTRY ) ); new_sym.handle = CurFunc->u.func.locals; new_sym_handle = SymAdd( h, &new_sym ); CurFunc->u.func.locals = new_sym_handle; SymReplace( &new_sym, new_sym_handle ); parm->sym.name = ".P"; parm->sym.flags |= SYM_REFERENCED; parm->sym.sym_type = GetType( TYPE_DOUBLE ); break; default: break; } } sym_handle = SymAdd( h, &parm->sym ); if( new_sym_handle != SYM_NULL ) { TREEPTR tree; tree = ExprNode( VarLeaf( &new_sym, new_sym_handle ), OPR_EQUALS, RValue( VarLeaf( &parm->sym, sym_handle ) ) ); tree->op.u2.result_type = typ; tree->u.expr_type = typ; AddStmt( tree ); } if( prev_parm == NULL ) { CurFunc->u.func.parms = sym_handle; } else { prev_parm->sym.handle = sym_handle; SymReplace( &prev_parm->sym, prev_sym_handle ); CMemFree( prev_parm ); } prev_parm = parm; prev_sym_handle = sym_handle; ++parm_count; parmlist = NewParm( parm->sym.sym_type, parmlist ); } if( prev_parm != NULL ) { prev_parm->sym.handle = SYM_NULL; SymReplace( &prev_parm->sym, prev_sym_handle ); CMemFree( prev_parm ); } typ = CurFunc->sym_type; // TODO not following my scheme CurFunc->sym_type = FuncNode( typ->object, FLAG_NONE, MakeParmList( parmlist, ParmsToBeReversed( CurFunc->mods, NULL ) ) ); if( PrevProtoType != NULL ) { ChkProtoType(); } }
static void ClassDefinition(void) { char *name; Int32 label,l1; Int32 field_num=0; SymPtr clas,clas_init; SkipToken(tCLASS); MatchToken(tCONST); name = GetIdent(); clas = SymAdd(name); clas->kind = CLASS_KIND; NextToken(); in_class=TRUE; base_class=clas; cur_scope=SYM_PUBLIC; /* clas->super=NULL; */ /* super_class=NULL; */ clas->super=SymFind("Object"); super_class=clas->super; if( Token==tLSS ) { SkipToken(tLSS); MatchToken(tCONST); name = GetIdent(); clas->super = SymFind(name); if( clas->super==NULL ) { compileError("super class not found"); return; } super_class = clas->super; field_num = clas->super->nlocs; NextToken(); } SymEnterScope(); /* default class constructor prologue */ l1 = vm_genI(op_link,0); clas_init = SymAdd(NEW); clas_init->kind = FUNCTION_KIND; clas_init->object.u.ival = l1; clas_init->flags |= SYM_PUBLIC; /* class fields and functions */ while( TokenIn(class_statements) ) { if( Token==tPUBLIC ) { PublicStatement(); } else if( Token==tPROTECTED ) { ProtectedStatement(); } else if( Token==tPRIVATE ) { PrivateStatement(); } else if( Token==tDEF ) { label = vm_genI(op_jmp,0); MethodDefinition(); vm_patch(label,vm_addr()); } else { local_num = field_num++; AssignmentStatement(); } if( Token==tSEMI ) SkipToken(tSEMI); } clas->nlocs = field_num; /* default class constructor epilogue */ vm_gen0(op_nop); vm_genI(op_rts,2); SymExitScope(clas); /* end of class */ in_class=FALSE; base_class=NULL; super_class=NULL; SkipToken(tEND); if( Token==tSEMI ) SkipToken(tSEMI); }
static SymPtr Lhs(void) { char *name=NULL; SymPtr sym,clas=NULL; sym = LookupIdent(&name); if( sym==COMPILE_ERROR ) { return NULL; } NextToken(); /* if a field has the same name as a global, it will override */ if( in_class && SymGetScope()==2 && sym!=NULL ) { if( sym->kind==GLOBAL_KIND ) { sym=NULL; } } if( sym==NULL ) { sym = SymAdd(name); if( Token==tCONST ) { sym->flags |= SYM_CONSTANT; } if( SymGetScope()==1 ) { sym->kind = GLOBAL_KIND; sym->num = global_num++; } else { /* MCC */ if(in_class && !in_method) { sym->kind = FIELD_KIND; sym->flags |= cur_scope; sym->clas = base_class; } else { sym->kind = LOCAL_KIND; sym->flags = 0; sym->clas = NULL; } sym->num = local_num++; } return sym; } /* check for field access */ if( Token==tPERIOD ) { clas = sym; sym = FieldReference(clas); if( sym==NULL ) { return NULL; } } /* check for function call */ if( is_func_kind(sym) ) { FunctionCall(sym,clas); vm_gen0(op_pop); return NULL; } /* check for array access */ if( Token==tLBRACK ) { switch(sym->kind) { case GLOBAL_KIND: vm_genI(op_getglobal,sym->num); break; case LOCAL_KIND: vm_genI(op_getlocal,sym->num); break; case CONSTANT_KIND: switch(sym->object.type) { case INT_TYPE: vm_genI(op_pushint,sym->object.u.ival); break; case REAL_TYPE: vm_genR(op_pushreal,sym->object.u.rval); break; case STRING_TYPE: vm_genS(op_pushstring,sym->object.u.pval); break; default: /* TODO: error */ break; } break; case FIELD_KIND: CheckClassMember(sym); vm_genI(op_getfield,sym->num); break; default: compileError("invalid assignment"); break; } if( Token==tLBRACK ) /* array */ { SkipToken(tLBRACK); Expr(); SkipToken(tRBRACK); while( Token==tLBRACK ) { /* handle multi-dimension arrays */ vm_gen0(op_getarray); SkipToken(tLBRACK); Expr(); SkipToken(tRBRACK); } SkipToken(tEQUALS); Expr(); vm_gen0(op_setarray); return NULL; } } return sym; }
local void ChkParms( void ) { PARMPTR parm; PARMPTR prev_parm; SYM_HANDLE sym_handle; SYM_HANDLE prev_sym_handle = 0; TYPEPTR typ; CurFunc->u.func.locals = 0; CurFunc->u.func.parms = 0; parm = ParmList; prev_parm = NULL; typ = *(CurFunc->sym_type->u.fn.parms); SKIP_TYPEDEFS( typ ); if( typ->decl_type != TYPE_VOID ) { while( parm != NULL ) { if( parm->sym.name == NULL ) { /* 03-may-93 */ parm->sym.name = ".J"; parm->sym.flags |= SYM_REFERENCED; } if( parm->sym.name[0] == '\0' ) { parm->sym.name = ".I"; InvDecl(); } if( parm->sym.sym_type == NULL ) { parm->sym.sym_type = TypeDefault(); } /* make sure name not already defined in this SymLevel */ sym_handle = SymAdd( parm->sym.info.hash_value, &parm->sym ); if( prev_parm == NULL ) { CurFunc->u.func.parms = sym_handle; } else { prev_parm->sym.handle = sym_handle; SymReplace( &prev_parm->sym, prev_sym_handle ); CMemFree( prev_parm ); } prev_parm = parm; prev_sym_handle = sym_handle; parm->sym.flags |= SYM_DEFINED | SYM_ASSIGNED; parm->sym.is_parm = TRUE; parm = parm->next_parm; } if( prev_parm != NULL ) { #if _CPU == 370 /* 24-oct-91 */ { SYM_ENTRY var_parm; if( VarParm( CurFunc ) ) { typ = ArrayNode( GetType( TYPE_CHAR ) ); typ->u.array->dimension = 160; sym_handle = GetNewSym( &var_parm, 'V', typ, SC_AUTO ); SymReplace( &var_parm, sym_handle ); prev_parm->sym.handle = sym_handle; } } #endif SymReplace( &prev_parm->sym, prev_sym_handle ); CMemFree( prev_parm ); } } }