]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | require "armv7" | |
25 | require "ast" | |
26 | require "x86" | |
27 | ||
28 | BACKENDS = | |
29 | [ | |
30 | "X86", | |
31 | "X86_64", | |
32 | "ARMv7" | |
33 | ] | |
34 | ||
35 | # Keep the set of working backends separate from the set of backends that might be | |
36 | # supported. This is great because the BACKENDS list is almost like a reserved | |
37 | # words list, in that it causes settings resolution to treat those words specially. | |
38 | # Hence this lets us set aside the name of a backend we might want to support in | |
39 | # the future while not actually supporting the backend yet. | |
40 | WORKING_BACKENDS = | |
41 | [ | |
42 | "X86", | |
43 | "X86_64", | |
44 | "ARMv7" | |
45 | ] | |
46 | ||
47 | BACKEND_PATTERN = Regexp.new('\\A(' + BACKENDS.join(')|(') + ')\\Z') | |
48 | ||
49 | class Node | |
50 | def lower(name) | |
51 | begin | |
52 | $activeBackend = name | |
53 | send("lower" + name) | |
54 | rescue => e | |
55 | raise "Got error #{e} at #{codeOriginString}" | |
56 | end | |
57 | end | |
58 | end | |
59 | ||
60 | # Overrides for lower() for those nodes that are backend-agnostic | |
61 | ||
62 | class Label | |
63 | def lower(name) | |
64 | $asm.putsLabel(self.name[1..-1]) | |
65 | end | |
66 | end | |
67 | ||
68 | class LocalLabel | |
69 | def lower(name) | |
70 | $asm.putsLocalLabel "_offlineasm_#{self.name[1..-1]}" | |
71 | end | |
72 | end | |
73 | ||
74 | class LabelReference | |
75 | def asmLabel | |
76 | Assembler.labelReference(name[1..-1]) | |
77 | end | |
78 | end | |
79 | ||
80 | class LocalLabelReference | |
81 | def asmLabel | |
82 | Assembler.localLabelReference("_offlineasm_"+name[1..-1]) | |
83 | end | |
84 | end | |
85 | ||
86 | class Skip | |
87 | def lower(name) | |
88 | end | |
89 | end | |
90 | ||
91 | class Sequence | |
92 | def lower(name) | |
93 | $activeBackend = name | |
94 | if respond_to? "getModifiedList#{name}" | |
95 | newList = send("getModifiedList#{name}") | |
96 | newList.each { | |
97 | | node | | |
98 | node.lower(name) | |
99 | } | |
100 | elsif respond_to? "lower#{name}" | |
101 | send("lower#{name}") | |
102 | else | |
103 | @list.each { | |
104 | | node | | |
105 | node.lower(name) | |
106 | } | |
107 | end | |
108 | end | |
109 | end | |
110 |