pmOdDecoder.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # This file is Copyright 2009, 2010 Dean Hall.
00004 #
00005 # This file is part of the Python-on-a-Chip program.
00006 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00007 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00008 #
00009 # Python-on-a-Chip is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00012 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00013 # is seen in the file COPYING in this directory.
00014 
00015 """
00016 PyMite Object Descriptor Decoder
00017 ================================
00018 
00019 Decodes an object descriptor value into its bit fields.
00020 """
00021 
00022 ## @file
00023 #  @copybrief pmOldDecoder
00024 
00025 ## @package pmOldDecoder
00026 #  @brief PyMite Object Descriptor Decoder
00027 #
00028 #  Decodes an object descriptor value into its bit fields.
00029 
00030 
00031 import sys, pprint
00032 
00033 
00034 __usage__ = """USAGE:
00035     ./pmOdDecoder.py odvalue
00036 """
00037 
00038 
00039 TYPES = (
00040     'OBJ_TYPE_NON',
00041     'OBJ_TYPE_INT',
00042     'OBJ_TYPE_FLT',
00043     'OBJ_TYPE_STR',
00044     'OBJ_TYPE_TUP',
00045     'OBJ_TYPE_COB',
00046     'OBJ_TYPE_MOD',
00047     'OBJ_TYPE_CLO',
00048     'OBJ_TYPE_FXN',
00049     'OBJ_TYPE_CLI',
00050     'OBJ_TYPE_CIM',
00051     'OBJ_TYPE_NIM',
00052     'OBJ_TYPE_NOB',
00053     'OBJ_TYPE_THR',
00054     0x0E,
00055     'OBJ_TYPE_BOOL',
00056     'OBJ_TYPE_CIO',
00057     'OBJ_TYPE_MTH',
00058     'OBJ_TYPE_LST',
00059     'OBJ_TYPE_DIC',
00060     0x14,0x15,0x16,0x17,0x18,
00061     'OBJ_TYPE_FRM',
00062     'OBJ_TYPE_BLK',
00063     'OBJ_TYPE_SEG',
00064     'OBJ_TYPE_SGL',
00065     'OBJ_TYPE_SQI',
00066     'OBJ_TYPE_NFM',
00067 )
00068 
00069 
00070 def od_decode(odvalue):
00071     return {
00072         "val": odvalue,
00073         "size": (odvalue & 0x001F) * 4,
00074         "type": TYPES[(odvalue & 0x3E00) >> 9],
00075         "mark": (odvalue & 0x4000) >> 14,
00076         "free": (odvalue & 0x8000) >> 15,
00077     }
00078 
00079 
00080 def to_int(s):
00081     if s.startswith("0x"):
00082         return int(s, 16)
00083     return int(s)
00084 
00085 
00086 def main():
00087     odvalues = sys.argv[1:]
00088     odvalues = map(to_int, odvalues)
00089     ods = map(od_decode, odvalues)
00090     for od in ods:
00091         print("%d (0x%04x): %s[%d], f=%d, m=%d"
00092             % (od['val'], od['val'], od['type'], od['size'], od['free'], od['mark']))
00093 
00094 
00095 if __name__ == "__main__":
00096     main()

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9