cc.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * Copyright (C) 2020 deesix <deesix@tuta.io>
  3. * This file is part of M2-Planet.
  4. *
  5. * M2-Planet is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * M2-Planet is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. // CONSTANT FALSE 0
  22. #define FALSE 0
  23. // CONSTANT TRUE 1
  24. #define TRUE 1
  25. // CONSTANT KNIGHT_NATIVE 1
  26. #define KNIGHT_NATIVE 1
  27. // CONSTANT KNIGHT_POSIX 2
  28. #define KNIGHT_POSIX 2
  29. // CONSTANT X86 3
  30. #define X86 3
  31. // CONSTANT AMD64 4
  32. #define AMD64 4
  33. // CONSTANT ARMV7L 5
  34. #define ARMV7L 5
  35. // CONSTANT AARCH64 6
  36. #define AARCH64 6
  37. // CONSTANT RISCV32 7
  38. #define RISCV32 7
  39. // CONSTANT RISCV64 8
  40. #define RISCV64 8
  41. // CONSTANT NO_STRUCT_DEFINITION 0
  42. #define NO_STRUCT_DEFINITION 0
  43. int copy_string(char* target, char* source, int max);
  44. int string_length(char* a);
  45. int in_set(int c, char* s);
  46. int match(char* a, char* b);
  47. void require(int bool, char* error);
  48. void reset_hold_string(void);
  49. char* int2str(int x, int base, int signed_p);
  50. #define REGISTER_ZERO 0
  51. // CONSTANT REGISTER_ZERO 0
  52. #define REGISTER_ONE 1
  53. // CONSTANT REGISTER_ONE 1
  54. #define REGISTER_TEMP 2
  55. // CONSTANT REGISTER_TEMP 2
  56. #define REGISTER_BASE 3
  57. // CONSTANT REGISTER_BASE 3
  58. /* AARCH64 and RISCV32/RISCV64 have return pointers. */
  59. #define REGISTER_RETURN 4
  60. // CONSTANT REGISTER_RETURN 4
  61. #define REGISTER_STACK 5
  62. // CONSTANT REGISTER_STACK 5
  63. void emit_push(int, char*);
  64. void emit_pop(int, char*);
  65. struct type
  66. {
  67. struct type* next;
  68. int size;
  69. int offset;
  70. int is_signed;
  71. struct type* indirect;
  72. struct type* members;
  73. struct type* type;
  74. char* name;
  75. };
  76. /* TLO = Token List Option */
  77. // CONSTANT TLO_LOCAL_ARRAY 1
  78. #define TLO_LOCAL_ARRAY 1
  79. struct token_list
  80. {
  81. struct token_list* next;
  82. struct token_list* locals;
  83. struct token_list* prev;
  84. char* s;
  85. struct type* type;
  86. char* filename;
  87. struct token_list* arguments;
  88. int depth;
  89. int linenumber;
  90. int array_modifier;
  91. int options;
  92. };
  93. struct case_list
  94. {
  95. struct case_list* next;
  96. char* value;
  97. };
  98. struct static_variable_list
  99. {
  100. struct static_variable_list* next;
  101. char* local_variable_name;
  102. struct token_list* global_variable;
  103. };
  104. struct token_list* sym_declare(char *s, struct type* t, struct token_list* list);
  105. #include "cc_globals.h"