navrinl.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. {
  2. Copyright (c) 1998-2017 by Florian Klaempfl
  3. Generates AVR inline nodes
  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 navrinl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl, aasmbase;
  22. type
  23. tavrinlinenode = class(tcginlinenode)
  24. procedure second_abs_long; override;
  25. function pass_typecheck_cpu:tnode;override;
  26. function first_cpu : tnode;override;
  27. procedure pass_generate_code_cpu;override;
  28. end;
  29. implementation
  30. uses
  31. compinnr,
  32. aasmdata,
  33. aasmcpu,
  34. symdef,
  35. defutil,
  36. hlcgobj,
  37. pass_2,
  38. cgbase, cgobj, cgutils,
  39. cpubase;
  40. procedure tavrinlinenode.second_abs_long;
  41. var
  42. hl: TAsmLabel;
  43. size: TCgSize;
  44. begin
  45. secondpass(left);
  46. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  47. location:=left.location;
  48. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  49. size:=def_cgsize(left.resultdef);
  50. current_asmdata.getjumplabel(hl);
  51. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,size,OC_GTE,0,left.location.register,hl);
  52. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,size,left.location.register,location.register);
  53. cg.a_label(current_asmdata.CurrAsmList,hl);
  54. end;
  55. function tavrinlinenode.pass_typecheck_cpu : tnode;
  56. begin
  57. Result:=nil;
  58. case inlinenumber of
  59. in_avr_nop,
  60. in_avr_sleep,
  61. in_avr_sei,
  62. in_avr_wdr,
  63. in_avr_cli:
  64. begin
  65. CheckParameters(0);
  66. resultdef:=voidtype;
  67. end;
  68. in_avr_save:
  69. begin
  70. CheckParameters(0);
  71. resultdef:=u8inttype;
  72. end;
  73. in_avr_restore:
  74. begin
  75. CheckParameters(1);
  76. resultdef:=voidtype;
  77. end;
  78. else
  79. Result:=inherited pass_typecheck_cpu;
  80. end;
  81. end;
  82. function tavrinlinenode.first_cpu : tnode;
  83. begin
  84. Result:=nil;
  85. case inlinenumber of
  86. in_avr_nop,
  87. in_avr_sleep,
  88. in_avr_sei,
  89. in_avr_wdr,
  90. in_avr_cli,
  91. in_avr_restore:
  92. begin
  93. expectloc:=LOC_VOID;
  94. resultdef:=voidtype;
  95. end;
  96. in_avr_save:
  97. begin
  98. expectloc:=LOC_REGISTER;
  99. resultdef:=u8inttype;
  100. end;
  101. else
  102. Result:=inherited first_cpu;
  103. end;
  104. end;
  105. procedure tavrinlinenode.pass_generate_code_cpu;
  106. begin
  107. case inlinenumber of
  108. in_avr_nop:
  109. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_NOP));
  110. in_avr_sleep:
  111. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_SLEEP));
  112. in_avr_sei:
  113. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_SEI));
  114. in_avr_wdr:
  115. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_WDR));
  116. in_avr_cli:
  117. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLI));
  118. in_avr_save:
  119. begin
  120. location_reset(location,LOC_CREGISTER,OS_8);
  121. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_8);
  122. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_IN, location.register, NIO_SREG));
  123. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLI));
  124. end;
  125. in_avr_restore:
  126. begin
  127. secondpass(left);
  128. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  129. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_OUT, NIO_SREG, left.location.register));
  130. end;
  131. else
  132. inherited pass_generate_code_cpu;
  133. end;
  134. end;
  135. begin
  136. cinlinenode:=tavrinlinenode;
  137. end.