Implemented a build system that generates offset header files for ARM assembly files, in Android.

The original CL was separated into two. Please refer to https://webrtc-codereview.appspot.com/860005 on how the build system and python script being used.
Review URL: https://webrtc-codereview.appspot.com/754005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3059 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kma@webrtc.org
2012-11-07 22:34:16 +00:00
parent 055663be0a
commit 31eae47444
2 changed files with 98 additions and 15 deletions

View File

@ -8,34 +8,53 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
"""This script generates a C header file of offsets from an ARM assembler file.
"""This script is a tool to generate special header files from input
C source files.
It parses an ARM assembler generated .S file, finds declarations of variables
It first assembles the input source files to generate intermediate assembly
files (*.s). Then it parses the .s files and finds declarations of variables
whose names start with the string specified as the third argument in the
command-line, translates the variable names and values into constant defines and
writes them into a header file.
command-line, translates the variable names and values into constant defines
and writes them into header files.
"""
import os
import sys
def usage():
print("Usage: generate_asm_header.py " +
"<input filename> <output filename> <variable name pattern>")
sys.exit(1)
import subprocess
from optparse import OptionParser
def main(argv):
if len(argv) != 3:
usage()
parser = OptionParser()
usage = 'Usage: %prog [options] input_file'
parser.set_usage(usage)
parser.add_option('--compiler', default = 'gcc', help = 'compiler name')
parser.add_option('--options', default = '-S', help = 'compiler options')
parser.add_option('--pattern', default = 'offset_', help = 'A match pattern'
' used for searching the relevant constants.')
parser.add_option('--dir', default = '.', help = 'output directory')
(options, args) = parser.parse_args()
infile = open(argv[0])
outfile = open(argv[1], 'w')
# Generate complete intermediate and header file names.
input_file_name = os.path.basename(args[0])
file_base_name = os.path.splitext(input_file_name)[0]
interim_file = options.dir + "/" + file_base_name + '.s'
out_file = interim_file.replace('.s', '.h')
# Set the shell command with the compiler and options inputs.
compiler_command = (options.compiler + " " + options.options + " " + args[0]
+ " -o " + interim_file)
# Run the shell command and generate the intermediate file.
subprocess.check_call(compiler_command, shell=True)
infile = open(interim_file) # The intermediate file.
outfile = open(out_file, 'w') # The output header file.
# Generate the output header file.
for line in infile: # Iterate though all the lines in the input file.
if line.startswith(argv[2]):
if line.startswith(options.pattern):
outfile.write('#define ')
outfile.write(line.split(':')[0]) # Write the constant name.
outfile.write(' ')
if line.find('.word') >= 0:
outfile.write(line.split('.word')[1]) # Write the constant value.