navrinl.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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;
  22. type
  23. tavrinlinenode = class(tcginlinenode)
  24. function pass_typecheck_cpu:tnode;override;
  25. function first_cpu : tnode;override;
  26. procedure pass_generate_code_cpu;override;
  27. end;
  28. implementation
  29. uses
  30. compinnr,
  31. aasmdata,
  32. aasmcpu,
  33. symdef,
  34. hlcgobj,
  35. pass_2,
  36. cgbase, cgobj, cgutils,
  37. cpubase;
  38. function tavrinlinenode.pass_typecheck_cpu : tnode;
  39. begin
  40. Result:=nil;
  41. case inlinenumber of
  42. in_avr_nop,
  43. in_avr_sleep,
  44. in_avr_sei,
  45. in_avr_wdr,
  46. in_avr_cli:
  47. begin
  48. CheckParameters(0);
  49. resultdef:=voidtype;
  50. end;
  51. in_avr_save:
  52. begin
  53. CheckParameters(0);
  54. resultdef:=u8inttype;
  55. end;
  56. in_avr_restore:
  57. begin
  58. CheckParameters(1);
  59. resultdef:=voidtype;
  60. end;
  61. else
  62. Result:=inherited pass_typecheck_cpu;
  63. end;
  64. end;
  65. function tavrinlinenode.first_cpu : tnode;
  66. begin
  67. Result:=nil;
  68. case inlinenumber of
  69. in_avr_nop,
  70. in_avr_sleep,
  71. in_avr_sei,
  72. in_avr_wdr,
  73. in_avr_cli,
  74. in_avr_restore:
  75. begin
  76. expectloc:=LOC_VOID;
  77. resultdef:=voidtype;
  78. end;
  79. in_avr_save:
  80. begin
  81. expectloc:=LOC_REGISTER;
  82. resultdef:=u8inttype;
  83. end;
  84. else
  85. Result:=inherited first_cpu;
  86. end;
  87. end;
  88. procedure tavrinlinenode.pass_generate_code_cpu;
  89. begin
  90. case inlinenumber of
  91. in_avr_nop:
  92. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_NOP));
  93. in_avr_sleep:
  94. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_SLEEP));
  95. in_avr_sei:
  96. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_SEI));
  97. in_avr_wdr:
  98. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_WDR));
  99. in_avr_cli:
  100. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLI));
  101. in_avr_save:
  102. begin
  103. location_reset(location,LOC_CREGISTER,OS_8);
  104. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_8);
  105. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_IN, location.register, NIO_SREG));
  106. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLI));
  107. end;
  108. in_avr_restore:
  109. begin
  110. secondpass(left);
  111. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  112. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_OUT, NIO_SREG, left.location.register));
  113. end;
  114. else
  115. inherited pass_generate_code_cpu;
  116. end;
  117. end;
  118. begin
  119. cinlinenode:=tavrinlinenode;
  120. end.