]> git.saurik.com Git - apple/javascriptcore.git/blob - offlineasm/backends.rb
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / offlineasm / backends.rb
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
24 require "config"
25 require "arm64"
26 require "arm"
27 require "arm64"
28 require "ast"
29 require "x86"
30 require "mips"
31 require "sh4"
32 require "cloop"
33
34 BACKENDS =
35 [
36 "X86",
37 "X86_64",
38 "ARM",
39 "ARMv7",
40 "ARMv7_TRADITIONAL",
41 "ARM64",
42 "MIPS",
43 "SH4",
44 "C_LOOP"
45 ]
46
47 # Keep the set of working backends separate from the set of backends that might be
48 # supported. This is great because the BACKENDS list is almost like a reserved
49 # words list, in that it causes settings resolution to treat those words specially.
50 # Hence this lets us set aside the name of a backend we might want to support in
51 # the future while not actually supporting the backend yet.
52 WORKING_BACKENDS =
53 [
54 "X86",
55 "X86_64",
56 "ARM",
57 "ARMv7",
58 "ARMv7_TRADITIONAL",
59 "ARM64",
60 "MIPS",
61 "SH4",
62 "C_LOOP"
63 ]
64
65 BACKEND_PATTERN = Regexp.new('\\A(' + BACKENDS.join(')|(') + ')\\Z')
66
67 class Node
68 def lower(name)
69 begin
70 $activeBackend = name
71 send("lower" + name)
72 rescue => e
73 e.message << "At #{codeOriginString}"
74 raise e
75 end
76 end
77 end
78
79 # Overrides for lower() for those nodes that are backend-agnostic
80
81 class Label
82 def lower(name)
83 $asm.putsLabel(self.name[1..-1])
84 end
85 end
86
87 class LocalLabel
88 def lower(name)
89 $asm.putsLocalLabel "_offlineasm_#{self.name[1..-1]}"
90 end
91 end
92
93 class LabelReference
94 def asmLabel
95 Assembler.labelReference(name[1..-1])
96 end
97 def cLabel
98 Assembler.cLabelReference(name[1..-1])
99 end
100 end
101
102 class LocalLabelReference
103 def asmLabel
104 Assembler.localLabelReference("_offlineasm_"+name[1..-1])
105 end
106 def cLabel
107 Assembler.cLocalLabelReference("_offlineasm_"+name[1..-1])
108 end
109 end
110
111 class Skip
112 def lower(name)
113 end
114 end
115
116 class Sequence
117 def lower(name)
118 $activeBackend = name
119 if respond_to? "getModifiedList#{name}"
120 newList = send("getModifiedList#{name}")
121 newList.each {
122 | node |
123 node.lower(name)
124 }
125 elsif respond_to? "lower#{name}"
126 send("lower#{name}")
127 else
128 @list.each {
129 | node |
130 node.lower(name)
131 }
132 end
133 end
134 end
135