stdarg.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _STDARG_H
  2. #define _STDARG_H
  3. #ifdef __x86_64__
  4. #ifndef _WIN64
  5. //This should be in sync with the declaration on our lib/libtcc1.c
  6. /* GCC compatible definition of va_list. */
  7. typedef struct {
  8. unsigned int gp_offset;
  9. unsigned int fp_offset;
  10. union {
  11. unsigned int overflow_offset;
  12. char *overflow_arg_area;
  13. };
  14. char *reg_save_area;
  15. } __va_list_struct;
  16. typedef __va_list_struct va_list[1];
  17. void __va_start(__va_list_struct *ap, void *fp);
  18. void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
  19. #define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
  20. #define va_arg(ap, type) \
  21. (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
  22. #define va_copy(dest, src) (*(dest) = *(src))
  23. #define va_end(ap)
  24. /* avoid conflicting definition for va_list on Macs. */
  25. #define _VA_LIST_T
  26. #else /* _WIN64 */
  27. typedef char *va_list;
  28. #define va_start(ap,last) __builtin_va_start(ap,last)
  29. #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
  30. ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
  31. #define va_copy(dest, src) ((dest) = (src))
  32. #define va_end(ap)
  33. #endif
  34. #elif __arm__
  35. typedef char *va_list;
  36. #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
  37. #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
  38. & ~(_tcc_alignof(type) - 1))
  39. #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
  40. #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
  41. &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
  42. #define va_copy(dest, src) (dest) = (src)
  43. #define va_end(ap)
  44. #elif defined(__aarch64__)
  45. typedef struct {
  46. void *__stack;
  47. void *__gr_top;
  48. void *__vr_top;
  49. int __gr_offs;
  50. int __vr_offs;
  51. } va_list;
  52. #define va_start(ap, last) __va_start(ap, last)
  53. #define va_arg(ap, type) __va_arg(ap, type)
  54. #define va_end(ap)
  55. #define va_copy(dest, src) ((dest) = (src))
  56. #else /* __i386__ */
  57. typedef char *va_list;
  58. /* only correct for i386 */
  59. #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
  60. #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
  61. #define va_copy(dest, src) (dest) = (src)
  62. #define va_end(ap)
  63. #endif
  64. /* fix a buggy dependency on GCC in libio.h */
  65. typedef va_list __gnuc_va_list;
  66. #define _VA_LIST_DEFINED
  67. #endif /* _STDARG_H */