backends.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Copyright (C) 2011 Apple Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  13. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  14. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  15. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  16. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  17. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  18. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  21. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  22. # THE POSSIBILITY OF SUCH DAMAGE.
  23. require "config"
  24. require "arm"
  25. require "ast"
  26. require "x86"
  27. require "mips"
  28. require "sh4"
  29. require "cloop"
  30. BACKENDS =
  31. [
  32. "X86",
  33. "X86_64",
  34. "ARM",
  35. "ARMv7",
  36. "ARMv7_TRADITIONAL",
  37. "MIPS",
  38. "SH4",
  39. "C_LOOP"
  40. ]
  41. # Keep the set of working backends separate from the set of backends that might be
  42. # supported. This is great because the BACKENDS list is almost like a reserved
  43. # words list, in that it causes settings resolution to treat those words specially.
  44. # Hence this lets us set aside the name of a backend we might want to support in
  45. # the future while not actually supporting the backend yet.
  46. WORKING_BACKENDS =
  47. [
  48. "X86",
  49. "X86_64",
  50. "ARM",
  51. "ARMv7",
  52. "ARMv7_TRADITIONAL",
  53. "MIPS",
  54. "SH4",
  55. "C_LOOP"
  56. ]
  57. BACKEND_PATTERN = Regexp.new('\\A(' + BACKENDS.join(')|(') + ')\\Z')
  58. class Node
  59. def lower(name)
  60. begin
  61. $activeBackend = name
  62. send("lower" + name)
  63. rescue => e
  64. e.message << "At #{codeOriginString}"
  65. raise e
  66. end
  67. end
  68. end
  69. # Overrides for lower() for those nodes that are backend-agnostic
  70. class Label
  71. def lower(name)
  72. $asm.putsLabel(self.name[1..-1])
  73. end
  74. end
  75. class LocalLabel
  76. def lower(name)
  77. $asm.putsLocalLabel "_offlineasm_#{self.name[1..-1]}"
  78. end
  79. end
  80. class LabelReference
  81. def asmLabel
  82. Assembler.labelReference(name[1..-1])
  83. end
  84. def cLabel
  85. Assembler.cLabelReference(name[1..-1])
  86. end
  87. end
  88. class LocalLabelReference
  89. def asmLabel
  90. Assembler.localLabelReference("_offlineasm_"+name[1..-1])
  91. end
  92. def cLabel
  93. Assembler.cLocalLabelReference("_offlineasm_"+name[1..-1])
  94. end
  95. end
  96. class Skip
  97. def lower(name)
  98. end
  99. end
  100. class Sequence
  101. def lower(name)
  102. $activeBackend = name
  103. if respond_to? "getModifiedList#{name}"
  104. newList = send("getModifiedList#{name}")
  105. newList.each {
  106. | node |
  107. node.lower(name)
  108. }
  109. elsif respond_to? "lower#{name}"
  110. send("lower#{name}")
  111. else
  112. @list.each {
  113. | node |
  114. node.lower(name)
  115. }
  116. end
  117. end
  118. end