/opengles/src/codegen/emit.h

http://ftk.googlecode.com/ · C Header · 135 lines · 59 code · 29 blank · 47 comment · 1 complexity · 5514941af8e5898df4d7d77d5d14cac7 MD5 · raw file

  1. #ifndef CODEGEN_EMIT_H
  2. #define CODEGEN_EMIT_H 1
  3. /****************************************************************************/
  4. /* */
  5. /* Copyright (c) 2004, Hans-Martin Will. All rights reserved. */
  6. /* */
  7. /* Redistribution and use in source and binary forms, with or without */
  8. /* modification, are permitted provided that the following conditions are */
  9. /* met: */
  10. /* */
  11. /* * Redistributions of source code must retain the above copyright */
  12. /* notice, this list of conditions and the following disclaimer. */
  13. /* */
  14. /* * Redistributions in binary form must reproduce the above copyright */
  15. /* notice, this list of conditions and the following disclaimer in the */
  16. /* documentation and/or other materials provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
  19. /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
  20. /* LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
  21. /* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER */
  22. /* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
  23. /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, */
  24. /* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
  25. /* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  26. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
  27. /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
  28. /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  29. /* */
  30. /****************************************************************************/
  31. #include "codegen.h"
  32. #include "instruction.h"
  33. #include "heap.h"
  34. #include "segment.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /****************************************************************************/
  39. /* Symbolic labels */
  40. /****************************************************************************/
  41. #if defined(__GCC32__) && defined(__cplusplus)
  42. struct cg_label_t;
  43. struct cg_codegen_t;
  44. #else
  45. typedef struct cg_label_t cg_label_t;
  46. typedef struct cg_codegen_t cg_codegen_t;
  47. #endif
  48. typedef enum
  49. {
  50. cg_reference_offset12, /* LDR relative from code */
  51. cg_reference_branch24, /* branch relative from code */
  52. cg_reference_absolute32, /* absolute 32-bit address */
  53. }
  54. cg_reference_type_t;
  55. /****************************************************************************/
  56. /* Runtime function pointers */
  57. /* Accidentially, these methods signatures co-incide with the mathematical */
  58. /* functions defined in the Intel GPP... */
  59. /****************************************************************************/
  60. typedef struct cg_runtime_info_t
  61. {
  62. div_t (*div) (I32 numer, I32 denom); /* Std. C runtime */
  63. I32 (*div_HP_16_32s) (I32 num, I32 denom);
  64. I32 (*inv_HP_16_32s) (I32 src);
  65. I32 (*sqrt_HP_16_32s) (I32 src);
  66. I32 (*inv_sqrt_HP_16_32s) (I32 src);
  67. I32 (*div_LP_16_32s) (I32 num, I32 denom);
  68. I32 (*inv_LP_16_32s) (I32 src);
  69. I32 (*sqrt_LP_16_32s) (I32 src);
  70. I32 (*inv_sqrt_LP_16_32s) (I32 src);
  71. /*
  72. void (*sin_LP_16_32s) (I32 theta, I32* sin_theta);
  73. void (*cos_LP_16_32s) (I32 theta, I32* cos_theta);
  74. void (*sin_cos_LP_16_32s) (I32 theta, I32* sin_theta, I32* cos_theta);
  75. void (*sin_HP_16_32s) (I32 theta, I32* sin_theta);
  76. void (*cos_HP_16_32s) (I32 theta, I32* cos_theta);
  77. void (*sin_cos_HP_16_32s) (I32 theta, I32* sin_theta, I32* cos_theta);
  78. */
  79. }
  80. cg_runtime_info_t;
  81. typedef struct cg_processor_info_t
  82. {
  83. int useV5; /* can use instructions from V5 arch. */
  84. }
  85. cg_processor_info_t;
  86. /****************************************************************************/
  87. /* Code generator */
  88. /****************************************************************************/
  89. cg_codegen_t * cg_codegen_create(cg_heap_t * heap, cg_runtime_info_t * runtime,
  90. cg_processor_info_t * processor);
  91. void cg_codegen_destroy(cg_codegen_t * gen);
  92. void cg_codegen_emit_module(cg_codegen_t * gen, cg_module_t * module);
  93. void cg_codegen_emit_proc(cg_codegen_t * gen, cg_proc_t * proc);
  94. void cg_codegen_emit_block(cg_codegen_t * gen, cg_block_t * block, int reinit);
  95. void cg_codegen_emit_inst(cg_codegen_t * gen, cg_inst_t * inst);
  96. size_t cg_codegen_emit_literal(cg_codegen_t * gen, U32 literal, int distinct);
  97. void cg_codegen_fix_refs(cg_codegen_t * gen);
  98. cg_label_t * cg_codegen_create_label(cg_codegen_t * gen);
  99. void cg_codegen_define(cg_codegen_t * gen, cg_label_t * label);
  100. void cg_codegen_reference(cg_codegen_t * gen, cg_label_t * label,
  101. cg_reference_type_t ref_type);
  102. cg_segment_t * cg_codegen_segment(cg_codegen_t * gen);
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif //ndef CODEGEN_EMIT_H