Changeset dc0b964 in mainline for tools/autotool.py


Ignore:
Timestamp:
2010-11-24T14:23:14Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
85369b1, b89e1d3
Parents:
8b3bff5
Message:
  • do not hardwire PRI??? formatting macros in the sources, use autotool to detect the correct values
  • use autotool to detect correct values for integer literal macros (UINT32_C, etc.)
  • start using portable UINT??_C style macros for integer constants
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/autotool.py

    r8b3bff5 rdc0b964  
    4949
    5050PACKAGE_BINUTILS = "usually part of binutils"
    51 PACKAGE_GCC = "preferably version 4.4.3 or newer"
     51PACKAGE_GCC = "preferably version 4.5.1 or newer"
    5252PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
    5353
    5454COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
    5555
    56 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, value) \\
     56PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
    5757        asm volatile ( \\
    58                 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t%[val]\\n" \\
     58                "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
    5959                : \\
    6060                : [val] "n" (value) \\
    6161        )
    6262
    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))
     63#define DECLARE_INTSIZE(tag, type, strc, conc) \\
     64        AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
     65        AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type));
    6666
    6767int main(int argc, char *argv[])
     
    195195       
    196196        for typedef in sizes:
    197                 outf.write("\tDECLARE_INTSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
     197                outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
    198198       
    199199        outf.write(PROBE_TAIL)
     
    231231        signed_tags = {}
    232232       
     233        unsigned_strcs = {}
     234        signed_strcs = {}
     235       
     236        unsigned_concs = {}
     237        signed_concs = {}
     238       
    233239        for j in range(len(lines)):
    234240                tokens = lines[j].strip().split("\t")
     
    236242                if (len(tokens) > 0):
    237243                        if (tokens[0] == "AUTOTOOL_DECLARE"):
    238                                 if (len(tokens) < 5):
     244                                if (len(tokens) < 7):
    239245                                        print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
    240246                               
     
    243249                                tag = tokens[3]
    244250                                name = tokens[4]
    245                                 value = tokens[5]
     251                                strc = tokens[5]
     252                                conc = tokens[6]
     253                                value = tokens[7]
    246254                               
    247255                                if (category == "intsize"):
     
    263271                                                unsigned_sizes[name] = value_int
    264272                                                unsigned_tags[tag] = value_int
     273                                                if (strc != ""):
     274                                                        unsigned_strcs[strc] = value_int
     275                                                if (conc != ""):
     276                                                        unsigned_concs[conc] = value_int
    265277                                        elif (subcategory == "signed"):
    266278                                                signed_sizes[name] = value_int
    267279                                                signed_tags[tag] = value_int
     280                                                if (strc != ""):
     281                                                        signed_strcs[strc] = value_int
     282                                                if (conc != ""):
     283                                                        signed_concs[conc] = value_int
    268284                                        else:
    269285                                                print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
    270286       
    271         return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags}
     287        return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs}
    272288
    273289def detect_uints(probe, bytes):
     
    279295        for b in bytes:
    280296                fnd = False
    281                 newtype = "uint%s_t" % (b * 8)
    282                
    283297                for name, value in probe['unsigned_sizes'].items():
    284298                        if (value == b):
    285                                 oldtype = "unsigned %s" % name
    286                                 typedefs.append({'oldtype' : oldtype, 'newtype' : newtype})
    287                                 fnd = True
    288                                 break
    289                
    290                 if (not fnd):
    291                         print_error(['Unable to find appropriate integer type for %s' % newtype,
     299                                typedefs.append({'oldtype': "unsigned %s" % name, 'newtype': "uint%u_t" % (b * 8)})
     300                                fnd = True
     301                                break
     302               
     303                if (not fnd):
     304                        print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
    292305                                     COMPILER_FAIL])
    293306               
    294307               
    295308                fnd = False
    296                 newtype = "int%s_t" % (b * 8)
    297                
    298309                for name, value in probe['signed_sizes'].items():
    299310                        if (value == b):
    300                                 oldtype = "signed %s" % name
    301                                 typedefs.append({'oldtype' : oldtype, 'newtype' : newtype})
    302                                 fnd = True
    303                                 break
    304                
    305                 if (not fnd):
    306                         print_error(['Unable to find appropriate integer type for %s' % newtype,
     311                                typedefs.append({'oldtype': "signed %s" % name, 'newtype': "int%u_t" % (b * 8)})
     312                                fnd = True
     313                                break
     314               
     315                if (not fnd):
     316                        print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
    307317                                     COMPILER_FAIL])
     318               
     319               
     320                fnd = False
     321                for name, value in probe['unsigned_strcs'].items():
     322                        if (value == b):
     323                                macros.append({'oldmacro': "\"%so\"" % name, 'newmacro': "PRIo%u" % (b * 8)})
     324                                macros.append({'oldmacro': "\"%su\"" % name, 'newmacro': "PRIu%u" % (b * 8)})
     325                                macros.append({'oldmacro': "\"%sx\"" % name, 'newmacro': "PRIx%u" % (b * 8)})
     326                                macros.append({'oldmacro': "\"%sX\"" % name, 'newmacro': "PRIX%u" % (b * 8)})
     327                                fnd = True
     328                                break
     329               
     330                if (not fnd):
     331                        macros.append({'oldmacro': "\"o\"", 'newmacro': "PRIo%u" % (b * 8)})
     332                        macros.append({'oldmacro': "\"u\"", 'newmacro': "PRIu%u" % (b * 8)})
     333                        macros.append({'oldmacro': "\"x\"", 'newmacro': "PRIx%u" % (b * 8)})
     334                        macros.append({'oldmacro': "\"X\"", 'newmacro': "PRIX%u" % (b * 8)})
     335               
     336               
     337                fnd = False
     338                for name, value in probe['signed_strcs'].items():
     339                        if (value == b):
     340                                macros.append({'oldmacro': "\"%sd\"" % name, 'newmacro': "PRId%u" % (b * 8)})
     341                                fnd = True
     342                                break
     343               
     344                if (not fnd):
     345                        macros.append({'oldmacro': "\"d\"", 'newmacro': "PRId%u" % (b * 8)})
     346               
     347               
     348                fnd = False
     349                for name, value in probe['unsigned_concs'].items():
     350                        if (value == b):
     351                                macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
     352                                fnd = True
     353                                break
     354               
     355                if (not fnd):
     356                        macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
     357               
     358               
     359                fnd = False
     360                for name, value in probe['signed_concs'].items():
     361                        if (value == b):
     362                                macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
     363                                fnd = True
     364                                break
     365               
     366                if (not fnd):
     367                        macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
    308368       
    309369        for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']:
     
    508568                probe = probe_compiler(common,
    509569                        [
    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'}
     570                                {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '""'},
     571                                {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '""'},
     572                                {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
     573                                {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
     574                                {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'}
    515575                        ]
    516576                )
Note: See TracChangeset for help on using the changeset viewer.