Changeset 4012 for proto


Ignore:
Timestamp:
Aug 16, 2014, 6:12:46 PM (5 years ago)
Author:
ksherdy
Message:

Added cast support to demo lib.

Location:
proto/s2k/trunk/demo/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/s2k/trunk/demo/lib/bitutil.py

    r3610 r4012  
    163163#
    164164#  Align and delimit binary string.
    165 def format_fields(bstr, delim_offset=1, ralign=0, delim_char='|'):
     165def format_fields(bstr, delim_offset=1, ralign=0, delim_char=' '):
    166166  format_bstr = delim_char
    167167  for i in range(0, len(bstr), delim_offset):
  • proto/s2k/trunk/demo/lib/cast.py

    r3610 r4012  
    1111#
    1212
    13 import bitutil
     13from bitutil import *
    1414
    15 #
    16 # widening casts any zero-extend a partial final field
    17 #
    18 def bitcast(fw, bstr): # s2k syntax: bitcast<fw2>(s), 're-interprecast'
    19   return bitutil.zfill(bstr,fw)
     15def sext(fw1, strm, fw2, lgth):
     16        a_bstr = strm_to_bstr(strm,lgth)
     17        strm = zext_bstr(fw1, a_bstr, fw2)
     18        return bstr_to_strm(strm)
    2019
     20def sext_bstr(fw1, a_bstr, fw2):
     21        s = ""
     22        for i in range(0,len(a_bstr),fw):
     23                sign = a_bstr[i+fw-1]
     24                s += sign * (fw2-fw1)
     25                s += a_bstr[i:i+(fw2-fw1)]
     26        return s
    2127
     28def zext(fw1, strm, fw2, lgth):
     29        a_bstr = strm_to_bstr(strm,lgth)
     30        strm = zext_bstr(fw1, a_bstr, fw2)
     31        return bstr_to_strm(strm)
     32
     33def zext_bstr(fw1, a_bstr, fw2):
     34        s = ""
     35        for i in range(0,len(a_bstr),fw1):
     36                s += '0' * (fw2-fw1)
     37                s += a_bstr[i:i+(fw2-fw1)]
     38        return s
     39
     40def bitcast(fw1, bstr, fw2):
     41  return bstr
Note: See TracChangeset for help on using the changeset viewer.