bionic/libc/tools/bionic_utils.py

168 lines
4.7 KiB
Python
Raw Normal View History

2008-10-21 16:00:00 +02:00
# common python utility routines for the Bionic tool scripts
import sys, os, commands, string
all_arches = [ "arm", "mips", "x86", "x86_64" ]
2008-10-21 16:00:00 +02:00
# basic debugging trace support
# call D_setlevel to set the verbosity level
# and D(), D2(), D3(), D4() to add traces
#
verbose = 0
2008-10-21 16:00:00 +02:00
def D(msg):
global verbose
if verbose > 0:
print msg
def D2(msg):
global verbose
if verbose >= 2:
print msg
def D3(msg):
global verbose
if verbose >= 3:
print msg
def D4(msg):
global verbose
if verbose >= 4:
print msg
def D_setlevel(level):
global verbose
verbose = level
# parser for the SYSCALLS.TXT file
#
class SysCallsTxtParser:
def __init__(self):
self.syscalls = []
self.lineno = 0
def E(self, msg):
2008-10-21 16:00:00 +02:00
print "%d: %s" % (self.lineno, msg)
def parse_line(self, line):
""" parse a syscall spec line.
line processing, format is
return type func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
"""
2008-10-21 16:00:00 +02:00
pos_lparen = line.find('(')
E = self.E
if pos_lparen < 0:
E("missing left parenthesis in '%s'" % line)
return
pos_rparen = line.rfind(')')
if pos_rparen < 0 or pos_rparen <= pos_lparen:
E("missing or misplaced right parenthesis in '%s'" % line)
return
return_type = line[:pos_lparen].strip().split()
if len(return_type) < 2:
E("missing return type in '%s'" % line)
return
syscall_func = return_type[-1]
return_type = string.join(return_type[:-1],' ')
socketcall_id = -1
2008-10-21 16:00:00 +02:00
pos_colon = syscall_func.find(':')
if pos_colon < 0:
syscall_name = syscall_func
else:
if pos_colon == 0 or pos_colon+1 >= len(syscall_func):
E("misplaced colon in '%s'" % line)
return
# now find if there is a socketcall_id for a dispatch-type syscall
# after the optional 2nd colon
pos_colon2 = syscall_func.find(':', pos_colon + 1)
if pos_colon2 < 0:
syscall_name = syscall_func[pos_colon+1:]
syscall_func = syscall_func[:pos_colon]
else:
if pos_colon2+1 >= len(syscall_func):
E("misplaced colon2 in '%s'" % line)
return
syscall_name = syscall_func[(pos_colon+1):pos_colon2]
socketcall_id = int(syscall_func[pos_colon2+1:])
syscall_func = syscall_func[:pos_colon]
2008-10-21 16:00:00 +02:00
alias_delim = syscall_func.find('|')
if alias_delim > 0:
alias_list = syscall_func[alias_delim+1:].strip()
syscall_func = syscall_func[:alias_delim]
alias_delim = syscall_name.find('|')
if alias_delim > 0:
syscall_name = syscall_name[:alias_delim]
syscall_aliases = string.split(alias_list, ',')
else:
syscall_aliases = []
2008-10-21 16:00:00 +02:00
if pos_rparen > pos_lparen+1:
syscall_params = line[pos_lparen+1:pos_rparen].split(',')
params = string.join(syscall_params,',')
else:
syscall_params = []
params = "void"
t = {
"name" : syscall_name,
"func" : syscall_func,
"aliases" : syscall_aliases,
"params" : syscall_params,
"decl" : "%-15s %s (%s);" % (return_type, syscall_func, params),
"socketcall_id" : socketcall_id
}
# Parse the architecture list.
arch_list = line[pos_rparen+1:].strip()
if arch_list == "custom":
pass
elif arch_list == "all":
for arch in all_arches:
t[arch] = True
2008-10-21 16:00:00 +02:00
else:
for arch in string.split(arch_list, ','):
if arch in all_arches:
t[arch] = True
else:
E("invalid syscall architecture list in '%s'" % line)
return
2008-10-21 16:00:00 +02:00
self.syscalls.append(t)
global verbose
libc: Update auto-gen scripts Make the scripts use external/kernel-headers/original by default. clean_header.py: Document -k<path>, add -d<path> find_headers.py: Make kernel config files optional update_all.py: Allow setting the path to kernel headers on the command-line update_all.py: Better formatting of output on ttys update_all.py: Automatically perform "git add/rm" on affected files. SYSCALLS.TXT: Fix typo in __socketcall definition. checksyscalls.py: Add support for superH architecture in the checks. gensyscalls.py: Automatically perform "git add/rm" on affected files. cpp.py: Fixed a bug that prevented certain type definitions to be kept in the generated clean header (e.g. struct ethtool_drvinfo in <linux/ethtool.h>) All scripts will use the content of external/kernel-headers/original by default now. The generated code removes all empty lines and trailing whitespace. This is useful to ensure a unified output even if we change the parser again in the future. The top-level disclaimer has been edited with update instructions to regenerate the headers when needed. Also, a warning is now inserted every 8th line in the final output: /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ Changes under kernel/arch-arm and kernel/arch-x86 should correspond to whitespace differences and additionnal struct definitions that were missed by the previous parser implementation. Change-Id: Icd1c056bacd766759f3e9b7bb5d63a246f3d656a WARNING: If you run these script, do not submit the result to gerrit for now. It seems there are discrepancies between the content of original headers and those currently commited under bionic/libc/kernel/. (This problem is the main motivation to insert the warning repeatedly). Current list of issues: - Missing SuperH headers (i.e. external/kernel-headers/original/asm-sh)
2010-10-11 22:11:06 +02:00
if verbose >= 2:
print t
2008-10-21 16:00:00 +02:00
def parse_file(self, file_path):
D2("parse_file: %s" % file_path)
fp = open(file_path)
for line in fp.xreadlines():
self.lineno += 1
line = line.strip()
if not line: continue
if line[0] == '#': continue
self.parse_line(line)
fp.close()
class StringOutput:
def __init__(self):
self.line = ""
def write(self,msg):
self.line += msg
D2("write '%s'" % msg)
def get(self):
return self.line