Refactor the code logic to reduce code size for debug tip.

The original switch case statements does not generate space efficient size when optimization is disabled. 

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9221 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-09-01 15:05:34 +00:00
parent 8e2978b4ad
commit 3d747a890f
1 changed files with 33 additions and 59 deletions

View File

@ -53,7 +53,6 @@ DebugPrint (
BASE_LIST BaseListMarker; BASE_LIST BaseListMarker;
CHAR8 *FormatString; CHAR8 *FormatString;
BOOLEAN Long; BOOLEAN Long;
BOOLEAN Done;
// //
// If Format is NULL, then ASSERT(). // If Format is NULL, then ASSERT().
@ -73,7 +72,7 @@ DebugPrint (
// the following layout: // the following layout:
// //
// Buffer->|------------------------| // Buffer->|------------------------|
// | Pading | 4 bytes // | Padding | 4 bytes
// DebugInfo->|------------------------| // DebugInfo->|------------------------|
// | EFI_DEBUG_INFO | sizeof(EFI_DEBUG_INFO) // | EFI_DEBUG_INFO | sizeof(EFI_DEBUG_INFO)
// BaseListMarker->|------------------------| // BaseListMarker->|------------------------|
@ -99,7 +98,7 @@ DebugPrint (
// Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is
// 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause
// exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO)) // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))
// just makes addess of BaseListMarker, which follows DebugInfo, 64-bit aligned. // just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned.
// //
DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1; DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1;
DebugInfo->ErrorLevel = (UINT32)ErrorLevel; DebugInfo->ErrorLevel = (UINT32)ErrorLevel;
@ -128,91 +127,66 @@ DebugPrint (
// //
// Parse Flags and Width // Parse Flags and Width
// //
for (Done = FALSE; !Done; ) { for (Format++; TRUE; Format++) {
Format++; if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {
switch (*Format) {
case '.':
case '-':
case '+':
case ' ':
case ',':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
// //
// These characters in format field are omitted. // These characters in format field are omitted.
// //
break; continue;
case 'L': }
case 'l': if (*Format >= '0' && *Format <= '9') {
//
// These characters in format field are omitted.
//
continue;
}
if (*Format == 'L' || *Format == 'l') {
// //
// 'L" or "l" in format field means the number being printed is a UINT64 // 'L" or "l" in format field means the number being printed is a UINT64
// //
Long = TRUE; Long = TRUE;
break; continue;
case '*': }
if (*Format == '*') {
// //
// '*' in format field means the precision of the field is specified by // '*' in format field means the precision of the field is specified by
// a UINTN argument in the argument list. // a UINTN argument in the argument list.
// //
BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN); BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
break; continue;
case '\0': }
if (*Format == '\0') {
// //
// Make no output if Format string terminates unexpectedly when // Make no output if Format string terminates unexpectedly when
// looking up for flag, width, precision and type. // looking up for flag, width, precision and type.
// //
Format--; Format--;
//
// break skipped on purpose.
//
default:
//
// When valid argument type detected or format string terminates unexpectedly,
// the inner loop is done.
//
Done = TRUE;
break;
} }
//
// When valid argument type detected or format string terminates unexpectedly,
// the inner loop is done.
//
break;
} }
// //
// Pack variable arguments into the storage area following EFI_DEBUG_INFO. // Pack variable arguments into the storage area following EFI_DEBUG_INFO.
// //
switch (*Format) { if ((*Format == 'p') && (sizeof (VOID *) > 4)) {
case 'p': Long = TRUE;
if (sizeof (VOID *) > 4) { }
Long = TRUE; if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd') {
}
case 'X':
case 'x':
case 'd':
if (Long) { if (Long) {
BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64); BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
} else { } else {
BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int); BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
} }
break; } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {
case 's':
case 'S':
case 'a':
case 'g':
case 't':
BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *); BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
break; } else if (*Format == 'c') {
case 'c':
BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN); BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
break; } else if (*Format == 'r') {
case 'r':
BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS); BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
break;
} }
// //