void PrintFuncSig (FILE* F, const char* Name, Type* T) /* Print a function signature. */ { /* Get the function descriptor */ const FuncDesc* D = GetFuncDesc (T); /* Print a comment with the function signature */ PrintType (F, GetFuncReturn (T)); if (IsQualNear (T)) { fprintf (F, " __near__"); } if (IsQualFar (T)) { fprintf (F, " __far__"); } if (IsQualFastcall (T)) { fprintf (F, " __fastcall__"); } if (IsQualCDecl (T)) { fprintf (F, " __cdecl__"); } fprintf (F, " %s (", Name); /* Parameters */ if (D->Flags & FD_VOID_PARAM) { fprintf (F, "void"); } else { unsigned I; SymEntry* E = D->SymTab->SymHead; for (I = 0; I < D->ParamCount; ++I) { if (I > 0) { fprintf (F, ", "); } if (SymIsRegVar (E)) { fprintf (F, "register "); } PrintType (F, E->Type); E = E->NextSym; } } /* End of parameter list */ fprintf (F, ")"); }
static Function* NewFunction (struct SymEntry* Sym) /* Create a new function activation structure and return it */ { /* Allocate a new structure */ Function* F = (Function*) xmalloc (sizeof (Function)); /* Initialize the fields */ F->FuncEntry = Sym; F->ReturnType = GetFuncReturn (Sym->Type); F->Desc = GetFuncDesc (Sym->Type); F->Reserved = 0; F->RetLab = GetLocalLabel (); F->TopLevelSP = 0; F->RegOffs = RegisterSpace; F->Flags = IsTypeVoid (F->ReturnType) ? FF_VOID_RETURN : FF_NONE; /* Return the new structure */ return F; }
CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func) /* Create a new code segment, initialize and return it */ { unsigned I; const Type* RetType; /* Allocate memory */ CodeSeg* S = xmalloc (sizeof (CodeSeg)); /* Initialize the fields */ S->SegName = xstrdup (SegName); S->Func = Func; InitCollection (&S->Entries); InitCollection (&S->Labels); for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) { S->LabelHash[I] = 0; } /* If we have a function given, get the return type of the function. * Assume ANY return type besides void will use the A and X registers. */ if (S->Func && !IsTypeVoid ((RetType = GetFuncReturn (Func->Type)))) { if (SizeOf (RetType) == SizeOf (type_long)) { S->ExitRegs = REG_EAX; } else { S->ExitRegs = REG_AX; } } else { S->ExitRegs = REG_NONE; } /* Copy the global optimization settings */ S->Optimize = (unsigned char) IS_Get (&Optimize); S->CodeSizeFactor = (unsigned) IS_Get (&CodeSizeFactor); /* Return the new struct */ return S; }