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.

58 lines
2.1KB

  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 describes the tables so they can be printed
  8. as a header file.
  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. The .c file
  15. This file should include the *_tablegen.h and tableprint.h files and
  16. anything else it needs as long as it does not depend on config.h or
  17. avconfig.h.
  18. In addition to that it must contain a void tableinit(void) function
  19. which initializes all tables by calling the init functions from the .h
  20. file.
  21. It must also contain a "const struct tabledef tables[]" array describing
  22. the tables to be generated.
  23. Its entries consist of (in order):
  24. - a string suitable for declaring the table, up to but not including the =
  25. NULL terminates the table
  26. - a function to print the table - tableprint.h defines some defaults,
  27. e.g. write_uint8_array to print a uint8_t array.
  28. - a pointer to the table
  29. - the size of the first dimension of the array
  30. - if applicable, the size of the second dimension of the array
  31. The .h file
  32. This file should contain:
  33. - one or more initialization functions
  34. - the table variable declarations
  35. If CONFIG_HARDCODED_TABLES is set, the initialization functions should
  36. not do anything, and instead of the variable declarations the
  37. generated *_tables.h file should be included.
  38. Since that will be generated in the build directory, the path must be
  39. included, i.e.
  40. #include "libavcodec/example_tables.h"
  41. not
  42. #include "example_tables.h"
  43. Makefile changes
  44. To make the automatic table creation work, you must manually declare the
  45. new dependency.
  46. For this add a line similar to this:
  47. $(SUBDIR)example.o: $(SUBDIR)example_tables.h
  48. under the "ifdef CONFIG_HARDCODED_TABLES" section in the Makefile.