changeset 11980:263b4ef7ad87 libavcodec

tablegen: implement and use WRITE_ARRAY macros Two macros (WRITE_ARRAY and WRITE_ARRAY_2D) take the prefix (modifiers) (not all tables are static, and they might not be constant either), the type, and the name of the array. It'll be copied with same name and type, and with the correct size of the currently-defined object.
author flameeyes
date Sun, 27 Jun 2010 12:21:12 +0000
parents 59f399926c12
children d3551fcf4c1c
files aac_tablegen.c cbrt_tablegen.c mpegaudio_tablegen.c pcm_tablegen.c qdm2_tablegen.c tableprint.h
diffstat 6 files changed, 35 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/aac_tablegen.c	Sun Jun 27 12:20:39 2010 +0000
+++ b/aac_tablegen.c	Sun Jun 27 12:21:12 2010 +0000
@@ -31,9 +31,7 @@
 
     write_fileheader();
 
-    printf("const float ff_aac_pow2sf_tab[428] = {\n");
-    write_float_array(ff_aac_pow2sf_tab, 428);
-    printf("};\n");
+    WRITE_ARRAY("const", float, ff_aac_pow2sf_tab);
 
     return 0;
 }
--- a/cbrt_tablegen.c	Sun Jun 27 12:20:39 2010 +0000
+++ b/cbrt_tablegen.c	Sun Jun 27 12:21:12 2010 +0000
@@ -31,9 +31,7 @@
 
     write_fileheader();
 
-    printf("static const uint32_t cbrt_tab[1<<13] = {\n");
-    write_uint32_t_array(cbrt_tab, 1 << 13);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint32_t, cbrt_tab);
 
     return 0;
 }
--- a/mpegaudio_tablegen.c	Sun Jun 27 12:20:39 2010 +0000
+++ b/mpegaudio_tablegen.c	Sun Jun 27 12:21:12 2010 +0000
@@ -31,29 +31,12 @@
 
     write_fileheader();
 
-    printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
-    write_int8_t_array(table_4_3_exp, TABLE_4_3_SIZE);
-    printf("};\n");
-
-    printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n");
-    write_uint32_t_array(table_4_3_value, TABLE_4_3_SIZE);
-    printf("};\n");
-
-    printf("static const uint32_t exp_table[512] = {\n");
-    write_uint32_t_array(exp_table, 512);
-    printf("};\n");
-
-    printf("static const float exp_table_float[512] = {\n");
-    write_float_array(exp_table_float, 512);
-    printf("};\n");
-
-    printf("static const uint32_t expval_table[512][16] = {\n");
-    write_uint32_t_2d_array(expval_table, 512, 16);
-    printf("};\n");
-
-    printf("static const float expval_table_float[512][16] = {\n");
-    write_float_2d_array(expval_table_float, 512, 16);
-    printf("};\n");
+    WRITE_ARRAY("static const", int8_t, table_4_3_exp);
+    WRITE_ARRAY("static const", uint32_t, table_4_3_value);
+    WRITE_ARRAY("static const", uint32_t, exp_table);
+    WRITE_ARRAY("static const", float, exp_table_float);
+    WRITE_2D_ARRAY("static const", uint32_t, expval_table);
+    WRITE_2D_ARRAY("static const", float, expval_table_float);
 
     return 0;
 }
--- a/pcm_tablegen.c	Sun Jun 27 12:20:39 2010 +0000
+++ b/pcm_tablegen.c	Sun Jun 27 12:21:12 2010 +0000
@@ -32,13 +32,8 @@
 
     write_fileheader();
 
-    printf("static const uint8_t linear_to_alaw[1 << 14] = {\n");
-    write_uint8_t_array(linear_to_alaw, 1 << 14);
-    printf("};\n");
-
-    printf("static const uint8_t linear_to_ulaw[1 << 14] = {\n");
-    write_uint8_t_array(linear_to_ulaw, 1 << 14);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint8_t, linear_to_alaw);
+    WRITE_ARRAY("static const", uint8_t, linear_to_ulaw);
 
     return 0;
 }
--- a/qdm2_tablegen.c	Sun Jun 27 12:20:39 2010 +0000
+++ b/qdm2_tablegen.c	Sun Jun 27 12:21:12 2010 +0000
@@ -33,25 +33,12 @@
 
     write_fileheader();
 
-    printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
-    write_uint16_t_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1);
-    printf("};\n");
-
-    printf("static const float noise_table[4096] = {\n");
-    write_float_array(noise_table, 4096);
-    printf("};\n");
+    WRITE_ARRAY("static const", uint16_t, softclip_table);
+    WRITE_ARRAY("static const", float, noise_table);
+    WRITE_ARRAY("static const", float, noise_samples);
 
-    printf("static const uint8_t random_dequant_index[256][5] = {\n");
-    write_uint8_t_2d_array(random_dequant_index, 256, 5);
-    printf("};\n");
-
-    printf("static const uint8_t random_dequant_type24[128][3] = {\n");
-    write_uint8_t_2d_array(random_dequant_type24, 128, 3);
-    printf("};\n");
-
-    printf("static const float noise_samples[128] = {\n");
-    write_float_array(noise_samples, 128);
-    printf("};\n");
+    WRITE_2D_ARRAY("static const", uint8_t, random_dequant_index);
+    WRITE_2D_ARRAY("static const", uint8_t, random_dequant_type24);
 
     return 0;
 }
--- a/tableprint.h	Sun Jun 27 12:20:39 2010 +0000
+++ b/tableprint.h	Sun Jun 27 12:21:12 2010 +0000
@@ -25,6 +25,7 @@
 
 #include <stdint.h>
 #include <stdio.h>
+#include "libavutil/common.h"
 
 #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\
 void write_##type##_array(const type *data, int len)\
@@ -72,4 +73,23 @@
 /** Write a standard file header */
 void write_fileheader(void);
 
+#define WRITE_ARRAY(prefix, type, name)                 \
+    do {                                                \
+        const size_t array_size = FF_ARRAY_ELEMS(name); \
+        printf(prefix" "#type" "#name"[%zu] = {\n",     \
+               array_size);                             \
+        write_##type##_array(name, array_size);         \
+        printf("};\n");                                 \
+    } while(0)
+
+#define WRITE_2D_ARRAY(prefix, type, name)                              \
+    do {                                                                \
+        const size_t array_size1 = FF_ARRAY_ELEMS(name);                \
+        const size_t array_size2 = FF_ARRAY_ELEMS(name[0]);             \
+        printf(prefix" "#type" "#name"[%zu][%zu] = {\n",                \
+               array_size1, array_size2 );                              \
+        write_##type##_2d_array(name, array_size1, array_size2);        \
+        printf("};\n");                                                 \
+    } while(0)
+
 #endif /* AVCODEC_TABLEPRINT_H */