3 # Copyright (C) 2011 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
26 $
: << File
.dirname(__FILE__
)
63 result
= "// #{@comment}"
80 raise unless @state == :asm
81 @outp.puts("\"\\t" + line
.join('') +
"\\n\" #{lastComment}")
85 raise unless @state == :asm
86 @outp.print("\"" + line +
"\"")
89 def putsLabel(labelName
)
90 raise unless @state == :asm
91 @outp.puts("OFFLINE_ASM_GLOBAL_LABEL(#{labelName}) #{lastComment}")
94 def putsLocalLabel(labelName
)
95 raise unless @state == :asm
96 @outp.puts("LOCAL_LABEL_STRING(#{labelName}) \":\\n\" #{lastComment}")
99 def self.labelReference(labelName
)
100 "\" SYMBOL_STRING(#{labelName}) \""
103 def self.localLabelReference(labelName
)
104 "\" LOCAL_LABEL_STRING(#{labelName}) \""
113 @outp.puts
"// #{@comment}"
114 @outp.puts
"// #{text}"
116 @commentState = :many
118 @outp.puts
"// #{text}"
126 offsetsFile
= ARGV.shift
127 outputFlnm
= ARGV.shift
129 $stderr.puts
"offlineasm: Parsing #{asmFile} and #{offsetsFile} and creating assembly file #{outputFlnm}."
132 configurationList
= offsetsAndConfigurationIndex(offsetsFile
)
133 rescue MissingMagicValuesException
134 $stderr.puts
"offlineasm: No magic values found. Skipping assembly file generation assuming the classic interpreter is enabled."
139 "// offlineasm input hash: " +
parseHash(asmFile
) +
140 " " + Digest
::SHA1.hexdigest(configurationList
.map
{|v
| (v
[0] +
[v
[1]]).join(' ')}.join(' ')) +
143 if FileTest
.exist
? outputFlnm
144 File
.open(outputFlnm
, "r") {
147 if firstLine
and firstLine
.chomp
== inputHash
148 $stderr.puts
"offlineasm: Nothing changed."
154 File
.open(outputFlnm
, "w") {
157 $output.puts inputHash
159 $asm = Assembler
.new($output)
163 configurationList
.each
{
165 offsetsList
= configuration
[0]
166 configIndex
= configuration
[1]
167 forSettings(computeSettingsCombinations(ast
)[configIndex
], ast
) {
168 | concreteSettings
, lowLevelAST
, backend
|
169 lowLevelAST
= lowLevelAST
.resolve(*buildOffsetsMap(lowLevelAST
, offsetsList
))
171 emitCodeInConfiguration(concreteSettings
, lowLevelAST
, backend
) {
173 lowLevelAST
.lower(backend
)
180 $stderr.puts
"offlineasm: Assembly file #{outputFlnm} successfully generated."