static StrBuf* GenArrayType (StrBuf* Type, unsigned SpanSize,
- unsigned char ElementType)
+ const char* ElementType,
+ unsigned ElementTypeLen)
/* Create an array (or single data) of the given type. SpanSize is the size
- * of the span, Type is the element data type. The function returns Type.
+ * of the span, ElementType is a string that encodes the element data type.
+ * The function returns Type.
*/
{
/* Get the size of the element type */
- unsigned ElementSize = GT_GET_SIZE (ElementType);
+ unsigned ElementSize = GT_GET_SIZE (ElementType[0]);
/* Get the number of array elements */
unsigned ElementCount = SpanSize / ElementSize;
/* The span size must be divideable by the element size */
CHECK ((SpanSize % ElementSize) == 0);
- /* Encoding an array needs 6 bytes. So if the array count is less, it
- * is cheaper to build the array with single items.
- */
- if (ElementCount >= 6) {
- GT_AddArray (Type, ElementCount);
- SB_AppendChar (Type, ElementType);
- } else {
- while (ElementCount--) {
- SB_AppendChar (Type, ElementType);
- }
- }
+ /* Encode the array */
+ GT_AddArray (Type, ElementCount);
+ SB_AppendBuf (Type, ElementType, ElementTypeLen);
/* Return the pointer to the created array type */
return Type;
static void DoAddr (void)
/* Define addresses */
{
+ /* Element type for the generated array */
+ static const char EType[2] = { GT_PTR, GT_VOID };
+
/* Record type information */
Span* S = OpenSpan ();
StrBuf Type = STATIC_STRBUF_INITIALIZER;
/* Close the span, then add type information to it */
S = CloseSpan (S);
- SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), GT_PTR));
+ SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), EType, sizeof (EType)));
- /* Free the type string */
+ /* Free the strings */
SB_Done (&Type);
}
static void DoByte (void)
/* Define bytes */
{
+ /* Element type for the generated array */
+ static const char EType[1] = { GT_BYTE };
+
/* Record type information */
Span* S = OpenSpan ();
StrBuf Type = STATIC_STRBUF_INITIALIZER;
/* Close the span, then add type information to it */
S = CloseSpan (S);
- SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), GT_BYTE));
+ SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), EType, sizeof (EType)));
/* Free the type string */
SB_Done (&Type);
static void DoDByt (void)
/* Output double bytes */
{
+ /* Element type for the generated array */
+ static const char EType[1] = { GT_DBYTE };
+
/* Record type information */
Span* S = OpenSpan ();
StrBuf Type = STATIC_STRBUF_INITIALIZER;
/* Close the span, then add type information to it */
S = CloseSpan (S);
- SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), GT_DBYTE));
+ SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), EType, sizeof (EType)));
/* Free the type string */
SB_Done (&Type);
static void DoFarAddr (void)
/* Define far addresses (24 bit) */
{
+ /* Element type for the generated array */
+ static const char EType[2] = { GT_FAR_PTR, GT_VOID };
+
/* Record type information */
Span* S = OpenSpan ();
StrBuf Type = STATIC_STRBUF_INITIALIZER;
/* Close the span, then add type information to it */
S = CloseSpan (S);
- SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), GT_FAR_PTR));
+ SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), EType, sizeof (EType)));
/* Free the type string */
SB_Done (&Type);
static void DoWord (void)
/* Define words */
{
+ /* Element type for the generated array */
+ static const char EType[1] = { GT_WORD };
+
/* Record type information */
Span* S = OpenSpan ();
StrBuf Type = STATIC_STRBUF_INITIALIZER;
/* Close the span, then add type information to it */
S = CloseSpan (S);
- SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), GT_WORD));
+ SetSpanType (S, GenArrayType (&Type, GetSpanSize (S), EType, sizeof (EType)));
/* Free the type string */
SB_Done (&Type);