You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.5KB

  1. Writing a table generator
  2. This documentation is preliminary.
  3. Parts of the API are not good and should be changed.
  4. Basic concepts
  5. A table generator consists of two files, *_tablegen.c and *_tablegen.h.
  6. The .h file will provide the variable declarations and initialization
  7. code for the tables, the .c calls the initialization code and then prints
  8. the tables as a header file using the tableprint.h helpers.
  9. Both of these files will be compiled for the host system, so to avoid
  10. breakage with cross-compilation neither of them may include, directly
  11. or indirectly, config.h or avconfig.h.
  12. Due to this, the .c file or Makefile may have to provide additional defines
  13. or stubs, though if possible this should be avoided.
  14. In particular, CONFIG_HARDCODED_TABLES should always be defined to 0.
  15. The .c file
  16. This file should include the *_tablegen.h and tableprint.h files and
  17. anything else it needs as long as it does not depend on config.h or
  18. avconfig.h.
  19. In addition to that it must contain a main() function which initializes
  20. all tables by calling the init functions from the .h file and then prints
  21. them.
  22. The printing code typically looks like this:
  23. write_fileheader();
  24. printf("static const uint8_t my_array[100] = {\n");
  25. write_uint8_array(my_array, 100);
  26. printf("};\n");
  27. write_fileheader() adds some minor things like a "this is a generated file"
  28. comment and some standard includes.
  29. tablegen.h defines some write functions for one- and two-dimensional arrays
  30. for standard types - they print only the "core" parts so they are easier
  31. to reuse for multi-dimensional arrays so the outermost {} must be printed
  32. separately.
  33. If there's no standard function for printing the type you need, the
  34. WRITE_1D_FUNC_ARGV macro is a very quick way to create one.
  35. See libavcodec/dv_tablegen.c for an example.
  36. The .h file
  37. This file should contain:
  38. - one or more initialization functions
  39. - the table variable declarations
  40. If CONFIG_HARDCODED_TABLES is set, the initialization functions should
  41. not do anything, and instead of the variable declarations the
  42. generated *_tables.h file should be included.
  43. Since that will be generated in the build directory, the path must be
  44. included, i.e.
  45. #include "libavcodec/example_tables.h"
  46. not
  47. #include "example_tables.h"
  48. Makefile changes
  49. To make the automatic table creation work, you must manually declare the
  50. new dependency.
  51. For this add a line similar to this:
  52. $(SUBDIR)example.o: $(SUBDIR)example_tables.h
  53. under the "ifdef CONFIG_HARDCODED_TABLES" section in the Makefile.