Changeset bd48f4c in mainline for tools


Ignore:
Timestamp:
2010-07-12T10:53:30Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bd11d3e
Parents:
c40e6ef (diff), bee2d4c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
tools
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • tools/autotool.py

    rc40e6ef rbd48f4c  
    5454COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
    5555
    56 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, name, value) \\
     56PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, value) \\
    5757        asm volatile ( \\
    58                 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" name "\\t%[val]\\n" \\
     58                "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t%[val]\\n" \\
    5959                : \\
    6060                : [val] "n" (value) \\
    6161        )
    6262
    63 #define DECLARE_INTSIZE(type) \\
    64         AUTOTOOL_DECLARE("intsize", "unsigned", #type, sizeof(unsigned type)); \\
    65         AUTOTOOL_DECLARE("intsize", "signed", #type, sizeof(signed type))
     63#define DECLARE_INTSIZE(tag, type) \\
     64        AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, sizeof(unsigned type)); \\
     65        AUTOTOOL_DECLARE("intsize", "signed", tag, #type, sizeof(signed type))
    6666
    6767int main(int argc, char *argv[])
     
    195195       
    196196        for typedef in sizes:
    197                 outf.write("\tDECLARE_INTSIZE(%s);\n" % typedef)
     197                outf.write("\tDECLARE_INTSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
    198198       
    199199        outf.write(PROBE_TAIL)
     
    228228        signed_sizes = {}
    229229       
     230        unsigned_tags = {}
     231        signed_tags = {}
     232       
    230233        for j in range(len(lines)):
    231234                tokens = lines[j].strip().split("\t")
     
    238241                                category = tokens[1]
    239242                                subcategory = tokens[2]
    240                                 name = tokens[3]
    241                                 value = tokens[4]
     243                                tag = tokens[3]
     244                                name = tokens[4]
     245                                value = tokens[5]
    242246                               
    243247                                if (category == "intsize"):
     
    258262                                        if (subcategory == "unsigned"):
    259263                                                unsigned_sizes[name] = value_int
     264                                                unsigned_tags[tag] = value_int
    260265                                        elif (subcategory == "signed"):
    261266                                                signed_sizes[name] = value_int
     267                                                signed_tags[tag] = value_int
    262268                                        else:
    263269                                                print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
    264270       
    265         return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes}
    266 
    267 def detect_uints(unsigned_sizes, signed_sizes, bytes):
     271        return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags}
     272
     273def detect_uints(probe, bytes):
    268274        "Detect correct types for fixed-size integer types"
    269275       
     276        macros = []
    270277        typedefs = []
    271278       
     
    274281                newtype = "uint%s_t" % (b * 8)
    275282               
    276                 for name, value in unsigned_sizes.items():
     283                for name, value in probe['unsigned_sizes'].items():
    277284                        if (value == b):
    278285                                oldtype = "unsigned %s" % name
     
    289296                newtype = "int%s_t" % (b * 8)
    290297               
    291                 for name, value in signed_sizes.items():
     298                for name, value in probe['signed_sizes'].items():
    292299                        if (value == b):
    293300                                oldtype = "signed %s" % name
     
    300307                                     COMPILER_FAIL])
    301308       
    302         return typedefs
     309        for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']:
     310                fnd = False;
     311                newmacro = "U%s" % tag
     312               
     313                for name, value in probe['unsigned_tags'].items():
     314                        if (name == tag):
     315                                oldmacro = "UINT%s" % (value * 8)
     316                                macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
     317                                macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
     318                                fnd = True
     319                                break
     320               
     321                if (not fnd):
     322                        print_error(['Unable to find appropriate size macro for %s' % newmacro,
     323                                     COMPILER_FAIL])
     324               
     325                fnd = False;
     326                newmacro = tag
     327               
     328                for name, value in probe['signed_tags'].items():
     329                        if (name == tag):
     330                                oldmacro = "INT%s" % (value * 8)
     331                                macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
     332                                macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
     333                                fnd = True
     334                                break
     335               
     336                if (not fnd):
     337                        print_error(['Unable to find appropriate size macro for %s' % newmacro,
     338                                     COMPILER_FAIL])
     339       
     340        return {'macros': macros, 'typedefs': typedefs}
    303341
    304342def create_makefile(mkname, common):
     
    316354        outmk.close()
    317355
    318 def create_header(hdname, typedefs):
     356def create_header(hdname, maps):
    319357        "Create header output"
    320358       
     
    328366        outhd.write('#define %s\n\n' % GUARD)
    329367       
    330         for typedef in typedefs:
     368        for macro in maps['macros']:
     369                outhd.write('#define %s  %s\n' % (macro['newmacro'], macro['oldmacro']))
     370       
     371        outhd.write('\n')
     372       
     373        for typedef in maps['typedefs']:
    331374                outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
    332375       
     
    465508                probe = probe_compiler(common,
    466509                        [
    467                                 "char",
    468                                 "short int",
    469                                 "int",
    470                                 "long int",
    471                                 "long long int",
     510                                {'type': 'char', 'tag': 'CHAR'},
     511                                {'type': 'short int', 'tag': 'SHORT'},
     512                                {'type': 'int', 'tag': 'INT'},
     513                                {'type': 'long int', 'tag': 'LONG'},
     514                                {'type': 'long long int', 'tag': 'LLONG'}
    472515                        ]
    473516                )
    474517               
    475                 typedefs = detect_uints(probe['unsigned_sizes'], probe['signed_sizes'], [1, 2, 4, 8])
     518                maps = detect_uints(probe, [1, 2, 4, 8])
    476519               
    477520        finally:
     
    479522       
    480523        create_makefile(MAKEFILE, common)
    481         create_header(HEADER, typedefs)
     524        create_header(HEADER, maps)
    482525       
    483526        return 0
  • tools/checkers/vcc.py

    rc40e6ef rbd48f4c  
    3636import subprocess
    3737import jobfile
     38import re
    3839
    3940jobs = [
    40         "kernel/kernel.job",
    41         "uspace/srv/clip/clip.job"
     41        "kernel/kernel.job"
    4242]
     43
     44re_attribute = re.compile("__attribute__\s*\(\(.*\)\)")
     45re_va_list = re.compile("__builtin_va_list")
     46
     47specification = ""
    4348
    4449def usage(prname):
    4550        "Print usage syntax"
    46         print prname + " <ROOT>"
     51        print prname + " <ROOT> [VCC_PATH]"
    4752
    4853def cygpath(upath):
     
    5459        "Preprocess source using GCC preprocessor and compatibility tweaks"
    5560       
     61        global specification
     62       
    5663        args = ['gcc', '-E']
    5764        args.extend(options.split())
    58         args.append(srcfname)
     65        args.extend(['-DCONFIG_VERIFY_VCC=1', srcfname])
    5966       
    6067        # Change working directory
     
    6673       
    6774        tmpf = file(tmpfname, "w")
     75        tmpf.write(specification)
    6876       
    6977        for line in preproc.splitlines():
     78               
    7079                # Ignore preprocessor directives
     80               
    7181                if (line.startswith('#')):
    7282                        continue
    7383               
     84                # Remove __attribute__((.*)) GCC extension
     85               
     86                line = re.sub(re_attribute, "", line)
     87               
     88                # Ignore unsupported __builtin_va_list type
     89                # (a better solution replacing __builrin_va_list with
     90                # an emulated implementation is needed)
     91               
     92                line = re.sub(re_va_list, "void *", line)
     93               
    7494                tmpf.write("%s\n" % line)
    7595       
     
    80100        return True
    81101
    82 def vcc(root, job):
     102def vcc(vcc_path, root, job):
    83103        "Run Vcc on a jobfile"
    84104       
     
    120140                tmpfqname = os.path.join(base, tmpfname)
    121141               
     142                vccfname = "%s.i" % srcfname
     143                vccfqname = os.path.join(base, vccfname);
     144               
    122145                # Only C files are interesting for us
    123146                if (tool != "cc"):
     
    130153               
    131154                # Run Vcc
    132                
    133                 retval = subprocess.Popen(['vcc', cygpath(tmpfqname)]).wait()
    134                
    135                 # Cleanup
     155                print " -- %s --" % srcfname           
     156                retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
     157               
     158                if (retval != 0):
     159                        return False
     160               
     161                # Cleanup, but only if verification was successful
     162                # (to be able to examine the preprocessed file)
    136163               
    137164                if (os.path.isfile(tmpfqname)):
    138165                        os.remove(tmpfqname)
    139                
    140                 if (retval != 0):
    141                         return False
     166                        os.remove(vccfqname)
    142167       
    143168        return True
    144169
    145170def main():
     171        global specification
     172       
    146173        if (len(sys.argv) < 2):
    147174                usage(sys.argv[0])
     
    149176       
    150177        rootdir = os.path.abspath(sys.argv[1])
     178        if (len(sys.argv) > 2):
     179                vcc_path = sys.argv[2]
     180        else:
     181                vcc_path = "/cygdrive/c/Program Files (x86)/Microsoft Research/Vcc/Binaries/vcc"
     182       
     183        if (not os.path.isfile(vcc_path)):
     184                print "%s is not a binary." % vcc_path
     185                print "Please supply the full Cygwin path to Vcc as the second argument."
     186                return
     187       
    151188        config = os.path.join(rootdir, "HelenOS.config")
    152189       
     
    156193                return
    157194       
     195        specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
     196        if (not os.path.isfile(specpath)):
     197                print "%s not found." % config
     198                return
     199       
     200        specfile = file(specpath, "r")
     201        specification = specfile.read()
     202        specfile.close()
     203       
    158204        for job in jobs:
    159                 if (not vcc(rootdir, job)):
     205                if (not vcc(vcc_path, rootdir, job)):
    160206                        print
    161207                        print "Failed job: %s" % job
Note: See TracChangeset for help on using the changeset viewer.