cga.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Helper routines for the i386 code generator
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cga;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cpuinfo,cpubase,cgbase,cgutils,
  23. symconst,symtype,symdef,aasmbase,aasmtai,aasmdata,aasmcpu;
  24. procedure emit_none(i : tasmop;s : topsize);
  25. procedure emit_reg(i : tasmop;s : topsize;reg : tregister);
  26. procedure emit_ref(i : tasmop;s : topsize;ref : treference);
  27. procedure emit_const_reg(i : tasmop;s : topsize;c : aint;reg : tregister);
  28. procedure emit_const_ref(i : tasmop;s : topsize;c : aint;ref : treference);
  29. procedure emit_ref_reg(i : tasmop;s : topsize;ref : treference;reg : tregister);
  30. procedure emit_reg_ref(i : tasmop;s : topsize;reg : tregister;ref : treference);
  31. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  32. procedure emit_const_reg_reg(i : tasmop;s : topsize;c : longint;reg1,reg2 : tregister);
  33. procedure emit_reg_reg_reg(i : tasmop;s : topsize;reg1,reg2,reg3 : tregister);
  34. procedure emit_ref_reg_reg(i : tasmop;s : topsize;ref : treference;reg1,reg2 : tregister);
  35. procedure emit_sym(i : tasmop;s : topsize;op : tasmsymbol);
  36. implementation
  37. uses
  38. cutils,
  39. systems,verbose,
  40. cgobj,cgx86;
  41. {*****************************************************************************
  42. Emit Assembler
  43. *****************************************************************************}
  44. procedure emit_none(i : tasmop;s : topsize);
  45. begin
  46. current_asmdata.CurrAsmList.concat(Taicpu.Op_none(i,s));
  47. end;
  48. procedure emit_reg(i : tasmop;s : topsize;reg : tregister);
  49. begin
  50. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg(i,s,reg));
  51. end;
  52. procedure emit_ref(i : tasmop;s : topsize;ref : treference);
  53. begin
  54. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  55. current_asmdata.CurrAsmList.concat(Taicpu.Op_ref(i,s,ref));
  56. end;
  57. procedure emit_const_reg(i : tasmop;s : topsize;c : aint;reg : tregister);
  58. begin
  59. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg(i,s,c,reg));
  60. end;
  61. procedure emit_const_ref(i : tasmop;s : topsize;c : aint;ref : treference);
  62. begin
  63. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  64. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_ref(i,s,c,ref));
  65. end;
  66. procedure emit_ref_reg(i : tasmop;s : topsize;ref : treference;reg : tregister);
  67. begin
  68. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  69. current_asmdata.CurrAsmList.concat(Taicpu.Op_ref_reg(i,s,ref,reg));
  70. end;
  71. procedure emit_reg_ref(i : tasmop;s : topsize;reg : tregister;ref : treference);
  72. begin
  73. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  74. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_ref(i,s,reg,ref));
  75. end;
  76. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  77. var instr:Taicpu;
  78. begin
  79. if not ((reg1=reg2) and (i=A_MOV)) then
  80. begin
  81. instr:=Taicpu.op_reg_reg(i,s,reg1,reg2);
  82. current_asmdata.CurrAsmList.concat(instr);
  83. if i=A_MOV then
  84. cg.add_move_instruction(instr);
  85. end;
  86. end;
  87. procedure emit_const_reg_reg(i : tasmop;s : topsize;c : longint;reg1,reg2 : tregister);
  88. begin
  89. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg_reg(i,s,c,reg1,reg2));
  90. end;
  91. procedure emit_reg_reg_reg(i : tasmop;s : topsize;reg1,reg2,reg3 : tregister);
  92. begin
  93. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_reg_reg(i,s,reg1,reg2,reg3));
  94. end;
  95. procedure emit_ref_reg_reg(i : tasmop;s : topsize;ref : treference;reg1,reg2 : tregister);
  96. begin
  97. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  98. current_asmdata.CurrAsmList.concat(Taicpu.Op_ref_reg_reg(i,s,ref,reg1,reg2));
  99. end;
  100. procedure emit_sym(i : tasmop;s : topsize;op : tasmsymbol);
  101. begin
  102. current_asmdata.CurrAsmList.concat(Taicpu.Op_sym(i,s,op));
  103. end;
  104. end.