cgcpu.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. This unit implements the code generator for the i386
  5. This program 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 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. interface
  20. uses
  21. cgobj,aasm
  22. {$i cpuunit.inc}
  23. ;
  24. type
  25. pcg386 = ^tcg386;
  26. tcg386 = object(tcg)
  27. procedure a_push_reg(list : paasmoutput;r : tregister);virtual;
  28. procedure a_call_name(list : paasmoutput;const s : string;
  29. offset : longint);virtual;
  30. procedure a_load_const8_ref(list : paasmoutput;b : byte;const ref : treference);virtual;
  31. procedure a_load_const16_ref(list : paasmoutput;w : word;const ref : treference);virtual;
  32. procedure a_load_const32_ref(list : paasmoutput;l : longint;const ref : treference);virtual;
  33. procedure a_load_const64_ref(list : paasmoutput;q : qword;const ref : treference);virtual;
  34. procedure g_stackframe_entry(list : paasmoutput;localsize : longint);virtual;
  35. procedure g_restore_frame_pointer(list : paasmoutput);virtual;
  36. procedure tcg386.g_ret_from_proc(list : paasmoutput;para size : aword);
  37. constructor init;
  38. end;
  39. implementation
  40. uses
  41. globtype,globals;
  42. constructor tcg386.init;
  43. begin
  44. inherited init;
  45. end;
  46. procedure tcg386.g_stackframe_entry(list : paasmoutput;localsize : longint);
  47. begin
  48. if localsize<>0 then
  49. begin
  50. if (cs_littlesize in aktglobalswitches) and (localsize<=65535) then
  51. list^.insert(new(paicpu,op_const_const(A_ENTER,S_NO,localsize,0)))
  52. else
  53. begin
  54. list^.concat(new(paicpu,op_reg(A_PUSH,S_L,R_EBP)));
  55. list^.concat(new(paicpu,op_reg_reg(A_MOV,S_L,R_ESP,R_EBP)));
  56. list^.concat(new(paicpu,op_const_reg(A_SUB,S_L,localsize,R_ESP)));
  57. end;
  58. end
  59. else
  60. begin
  61. list^.concat(new(paicpu,op_reg(A_PUSH,S_L,R_EBP)));
  62. list^.concat(new(paicpu,op_reg_reg(A_MOV,S_L,R_ESP,R_EBP)));
  63. end;
  64. end;
  65. procedure tcg386.a_call_name(list : paasmoutput;const s : string;
  66. offset : longint);
  67. begin
  68. list^.concat(new(paicpu,op_sym(A_CALL,S_NO,newasmsymbol(s))));
  69. {!!!!!!!!!1 offset is ignored }
  70. end;
  71. procedure tcg386.a_push_reg(list : paasmoutput;r : tregister);
  72. begin
  73. list^.concat(new(paicpu,op_reg(A_PUSH,regsize(r),r)));
  74. end;
  75. procedure tcg386.a_load_const8_ref(list : paasmoutput;b : byte;const ref : treference);
  76. begin
  77. abstract;
  78. end;
  79. procedure tcg386.a_load_const16_ref(list : paasmoutput;w : word;const ref : treference);
  80. begin
  81. abstract;
  82. end;
  83. procedure tcg386.a_load_const32_ref(list : paasmoutput;l : longint;const ref : treference);
  84. begin
  85. abstract;
  86. end;
  87. procedure tcg386.a_load_const64_ref(list : paasmoutput;q : qword;const ref : treference);
  88. begin
  89. abstract;
  90. end;
  91. procedure tcg386.g_restore_frame_pointer(list : paasmoutput);
  92. begin
  93. list^.concat(new(paicpu,op_none(A_LEAVE,S_NO)));
  94. end;
  95. procedure tcg386.g_ret_from_proc(list : paasmoutput;para size : aword);
  96. begin
  97. { parameters are limited to 65535 bytes because }
  98. { ret allows only imm16 }
  99. if (parasize>65535) and not(pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  100. CGMessage(cg_e_parasize_too_big);
  101. { Routines with the poclearstack flag set use only a ret.}
  102. { also routines with parasize=0 }
  103. if (parasize=0) or (pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  104. list^.concat(new(paicpu,op_none(A_RET,S_NO)))
  105. else
  106. list^.concat(new(paicpu,op_const(A_RET,S_NO,parasize)));
  107. end;
  108. end.
  109. {
  110. $Log$
  111. Revision 1.5 1999-08-25 12:00:21 jonas
  112. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  113. Revision 1.4 1999/08/06 14:15:56 florian
  114. * made the alpha version compilable
  115. Revision 1.3 1999/08/06 13:26:54 florian
  116. * more changes ...
  117. Revision 1.2 1999/08/01 23:19:59 florian
  118. + make a new makefile using the old compiler makefile
  119. Revision 1.1 1999/08/01 23:11:24 florian
  120. + renamed ot tp cgcpu.pas
  121. Revision 1.1 1999/08/01 22:08:26 florian
  122. * reorganisation of directory structure
  123. Revision 1.3 1999/08/01 18:22:31 florian
  124. * made it again compilable
  125. Revision 1.2 1999/01/23 23:29:43 florian
  126. * first running version of the new code generator
  127. * when compiling exceptions under Linux fixed
  128. Revision 1.1 1998/12/15 22:17:02 florian
  129. * first version
  130. }