cga.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_sym(i : tasmop;s : topsize;op : tasmsymbol);
  35. implementation
  36. uses
  37. cutils,
  38. systems,verbose,
  39. cgobj,cgx86;
  40. {*****************************************************************************
  41. Emit Assembler
  42. *****************************************************************************}
  43. procedure emit_none(i : tasmop;s : topsize);
  44. begin
  45. current_asmdata.CurrAsmList.concat(Taicpu.Op_none(i,s));
  46. end;
  47. procedure emit_reg(i : tasmop;s : topsize;reg : tregister);
  48. begin
  49. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg(i,s,reg));
  50. end;
  51. procedure emit_ref(i : tasmop;s : topsize;ref : treference);
  52. begin
  53. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  54. current_asmdata.CurrAsmList.concat(Taicpu.Op_ref(i,s,ref));
  55. end;
  56. procedure emit_const_reg(i : tasmop;s : topsize;c : aint;reg : tregister);
  57. begin
  58. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg(i,s,c,reg));
  59. end;
  60. procedure emit_const_ref(i : tasmop;s : topsize;c : aint;ref : treference);
  61. begin
  62. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  63. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_ref(i,s,c,ref));
  64. end;
  65. procedure emit_ref_reg(i : tasmop;s : topsize;ref : treference;reg : tregister);
  66. begin
  67. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  68. current_asmdata.CurrAsmList.concat(Taicpu.Op_ref_reg(i,s,ref,reg));
  69. end;
  70. procedure emit_reg_ref(i : tasmop;s : topsize;reg : tregister;ref : treference);
  71. begin
  72. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  73. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_ref(i,s,reg,ref));
  74. end;
  75. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  76. var instr:Taicpu;
  77. begin
  78. if not ((reg1=reg2) and (i=A_MOV)) then
  79. begin
  80. instr:=Taicpu.op_reg_reg(i,s,reg1,reg2);
  81. current_asmdata.CurrAsmList.concat(instr);
  82. if i=A_MOV then
  83. cg.add_move_instruction(instr);
  84. end;
  85. end;
  86. procedure emit_const_reg_reg(i : tasmop;s : topsize;c : longint;reg1,reg2 : tregister);
  87. begin
  88. current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg_reg(i,s,c,reg1,reg2));
  89. end;
  90. procedure emit_reg_reg_reg(i : tasmop;s : topsize;reg1,reg2,reg3 : tregister);
  91. begin
  92. current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_reg_reg(i,s,reg1,reg2,reg3));
  93. end;
  94. procedure emit_sym(i : tasmop;s : topsize;op : tasmsymbol);
  95. begin
  96. current_asmdata.CurrAsmList.concat(Taicpu.Op_sym(i,s,op));
  97. end;
  98. end.