3 # Copyright (C) 2011-2018 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__)
37 IncludeFile.processIncludeOptions()
39 inputFlnm = ARGV.shift
40 settingsFlnm = ARGV.shift
41 outputFlnm = ARGV.shift
43 validBackends = canonicalizeBackendNames(ARGV.shift.split(/[,\s]+/))
44 includeOnlyBackends(validBackends)
47 configurationList = configurationIndices(settingsFlnm)
48 rescue MissingMagicValuesException
49 $stderr.puts "OffsetExtractor: No magic values found. Skipping offsets extractor file generation."
54 OFFSET_MAGIC_NUMBERS.each {
56 $output.puts "unsigned(#{number}),"
60 configurationHash = Digest::SHA1.hexdigest(configurationList.join(' '))
61 inputHash = "// OffsetExtractor input hash: #{parseHash(inputFlnm)} #{configurationHash} #{selfHash}"
63 if FileTest.exist? outputFlnm
64 File.open(outputFlnm, "r") {
67 if firstLine and firstLine.chomp == inputHash
68 $stderr.puts "OffsetExtractor: Nothing changed."
74 ast = parse(inputFlnm)
75 settingsCombinations = computeSettingsCombinations(ast)
77 File.open(outputFlnm, "w") {
82 outp.puts "static const int64_t offsetExtractorTable[] = {"
83 configurationList.each {
85 forSettings(settingsCombinations[configIndex], ast) {
86 | concreteSettings, lowLevelAST, backend |
88 offsetsList = offsetsList(lowLevelAST)
89 sizesList = sizesList(lowLevelAST)
90 constsList = constsList(lowLevelAST)
92 emitCodeInConfiguration(concreteSettings, lowLevelAST, backend) {
93 OFFSET_HEADER_MAGIC_NUMBERS.each {
95 outp.puts "unsigned(#{number}),"
99 outp.puts "#{configIndex},"
103 outp.puts "OFFLINE_ASM_OFFSETOF(#{offset.struct}, #{offset.field}),"
108 outp.puts "sizeof(#{sizeof.struct}),"
113 outp.puts "static_cast<int64_t>(#{const.value}),"