cgcpu.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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,cpuinfo,cpubase;
  22. type
  23. pcg386 = ^tcg386;
  24. tcg386 = object(tcg)
  25. procedure a_push_reg(list : paasmoutput;r : tregister);virtual;
  26. procedure a_call_name(list : paasmoutput;const s : string;
  27. offset : longint);virtual;
  28. procedure a_load_const8_ref(list : paasmoutput;b : byte;const ref : treference);virtual;
  29. procedure a_load_const16_ref(list : paasmoutput;w : word;const ref : treference);virtual;
  30. procedure a_load_const32_ref(list : paasmoutput;l : longint;const ref : treference);virtual;
  31. procedure a_load_const64_ref(list : paasmoutput;q : qword;const ref : treference);virtual;
  32. procedure g_stackframe_entry(list : paasmoutput;localsize : longint);virtual;
  33. procedure g_restore_frame_pointer(list : paasmoutput);virtual;
  34. procedure g_ret_from_proc(list : paasmoutput;parasize : aword);
  35. constructor init;
  36. end;
  37. implementation
  38. uses
  39. globtype,globals,cpuasm,symconst,symtable,cgbase,verbose;
  40. constructor tcg386.init;
  41. begin
  42. inherited init;
  43. end;
  44. procedure tcg386.g_stackframe_entry(list : paasmoutput;localsize : longint);
  45. begin
  46. if localsize<>0 then
  47. begin
  48. if (cs_littlesize in aktglobalswitches) and (localsize<=65535) then
  49. list^.insert(new(paicpu,op_const_const(A_ENTER,S_NO,localsize,0)))
  50. else
  51. begin
  52. list^.concat(new(paicpu,op_reg(A_PUSH,S_L,R_EBP)));
  53. list^.concat(new(paicpu,op_reg_reg(A_MOV,S_L,R_ESP,R_EBP)));
  54. list^.concat(new(paicpu,op_const_reg(A_SUB,S_L,localsize,R_ESP)));
  55. end;
  56. end
  57. else
  58. begin
  59. list^.concat(new(paicpu,op_reg(A_PUSH,S_L,R_EBP)));
  60. list^.concat(new(paicpu,op_reg_reg(A_MOV,S_L,R_ESP,R_EBP)));
  61. end;
  62. end;
  63. procedure tcg386.a_call_name(list : paasmoutput;const s : string;
  64. offset : longint);
  65. begin
  66. list^.concat(new(paicpu,op_sym(A_CALL,S_NO,newasmsymbol(s))));
  67. {!!!!!!!!!1 offset is ignored }
  68. end;
  69. procedure tcg386.a_push_reg(list : paasmoutput;r : tregister);
  70. begin
  71. list^.concat(new(paicpu,op_reg(A_PUSH,regsize(r),r)));
  72. end;
  73. procedure tcg386.a_load_const8_ref(list : paasmoutput;b : byte;const ref : treference);
  74. begin
  75. abstract;
  76. end;
  77. procedure tcg386.a_load_const16_ref(list : paasmoutput;w : word;const ref : treference);
  78. begin
  79. abstract;
  80. end;
  81. procedure tcg386.a_load_const32_ref(list : paasmoutput;l : longint;const ref : treference);
  82. begin
  83. abstract;
  84. end;
  85. procedure tcg386.a_load_const64_ref(list : paasmoutput;q : qword;const ref : treference);
  86. begin
  87. abstract;
  88. end;
  89. procedure tcg386.g_restore_frame_pointer(list : paasmoutput);
  90. begin
  91. list^.concat(new(paicpu,op_none(A_LEAVE,S_NO)));
  92. end;
  93. procedure tcg386.g_ret_from_proc(list : paasmoutput;parasize : aword);
  94. begin
  95. { parameters are limited to 65535 bytes because }
  96. { ret allows only imm16 }
  97. if (parasize>65535) and not(pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  98. CGMessage(cg_e_parasize_too_big);
  99. { Routines with the poclearstack flag set use only a ret.}
  100. { also routines with parasize=0 }
  101. if (parasize=0) or (pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  102. list^.concat(new(paicpu,op_none(A_RET,S_NO)))
  103. else
  104. list^.concat(new(paicpu,op_const(A_RET,S_NO,parasize)));
  105. end;
  106. end.
  107. {
  108. $Log$
  109. Revision 1.1 2000-07-13 06:30:10 michael
  110. + Initial import
  111. Revision 1.9 2000/01/07 01:14:57 peter
  112. * updated copyright to 2000
  113. Revision 1.8 1999/11/09 22:57:09 peter
  114. * compiles again both i386,alpha both with optimizer
  115. Revision 1.7 1999/09/15 20:35:47 florian
  116. * small fix to operator overloading when in MMX mode
  117. + the compiler uses now fldz and fld1 if possible
  118. + some fixes to floating point registers
  119. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  120. * .... ???
  121. Revision 1.6 1999/09/10 18:48:11 florian
  122. * some bug fixes (e.g. must_be_valid and procinfo.funcret_is_valid)
  123. * most things for stored properties fixed
  124. Revision 1.5 1999/08/25 12:00:21 jonas
  125. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  126. Revision 1.4 1999/08/06 14:15:56 florian
  127. * made the alpha version compilable
  128. Revision 1.3 1999/08/06 13:26:54 florian
  129. * more changes ...
  130. Revision 1.2 1999/08/01 23:19:59 florian
  131. + make a new makefile using the old compiler makefile
  132. Revision 1.1 1999/08/01 23:11:24 florian
  133. + renamed ot tp cgcpu.pas
  134. Revision 1.1 1999/08/01 22:08:26 florian
  135. * reorganisation of directory structure
  136. Revision 1.3 1999/08/01 18:22:31 florian
  137. * made it again compilable
  138. Revision 1.2 1999/01/23 23:29:43 florian
  139. * first running version of the new code generator
  140. * when compiling exceptions under Linux fixed
  141. Revision 1.1 1998/12/15 22:17:02 florian
  142. * first version
  143. }