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