<commit_before>#!/usr/bin/env python

"""\
Test File generator.

This tool generates a hex file, of given size, ending on address
0xffff if no start address is given.

USAGE: generate.py -l size_in_bytes

(C) 2004-2010 <NAME> <<EMAIL>>
this is distributed under a free software license, see LICENSE.txt.
"""

from msp430 import memory
import sys
import struct

from optparse import OptionParser


parser = OptionParser(usage="""\
%prog [options]

Test File generator.

This tool generates a hex file, of given size, ending on address
0xffff if no start address is given.""")

parser.add_option("-o", "--output",
        dest="output",
        help="write result to given file",
        metavar="DESTINATION")

parser.add_option("-f", "--output-format",
        dest="output_format",
        help="output format name (%s)" % (', '.join(memory.save_formats),),
        default="titext",
        metavar="TYPE")

parser.add_option("-l", "--length",
        dest="size",
        help="number of bytes to generate",
        default=1024,
        type="int")

parser.add_option("-s", "--start-address",
        dest="start_address",
        help="start address of data generated",
        default=None,
        type="int")

parser.add_option("-c", "--count",
        dest="count",
        help="use address as data",
        action="store_true",
        default=False)

parser.add_option("--const",
        dest="const",
        help="use given 16 bit number as data (default=0x3fff)",
        default=0x3fff, # JMP $
        type="int")

(options, args) = parser.parse_args()

if options.output_format not in memory.save_formats:
    parser.error('Output format %s not supported.' % (options.output_format))

if args:
    parser.error('no arguments expected')

# prepare output
if options.output is None:
    out = sys.stdout
else:
    out = file(options.output, 'wb')

# get input
mem = memory.Memory()          # prepare downloaded data

# if no start address is given, align the data towards the end of the 64k
# address room
if options.start_address is None:
    options.start_address = 0x10000 - options.size

# create data
if options.count:
    data = ''.join([struct.pack("<H", x) for x in xrange(options.start_address, options.start_address + options.size, 2)])
else:
    data = ''.join([struct.pack("<H", options.const) for x in xrange(options.start_address, options.start_address + options.size, 2)])

mem.append(memory.Segment(options.start_address, data))

# write ihex file
memory.save(mem, out, options.output_format)
<commit_msg>fix warning for addresses > 0xffff<commit_after>#!/usr/bin/env python

"""\
Test File generator.

This tool generates a hex file, of given size, ending on address
0xffff if no start address is given.

USAGE: generate.py -l size_in_bytes

(C) 2004-2010 <NAME> <<EMAIL>>
this is distributed under a free software license, see LICENSE.txt.
"""

from msp430 import memory
import sys
import struct

from optparse import OptionParser


parser = OptionParser(usage="""\
%prog [options]

Test File generator.

This tool generates a hex file, of given size, ending on address
0xffff if no start address is given.""")

parser.add_option("-o", "--output",
        dest="output",
        help="write result to given file",
        metavar="DESTINATION")

parser.add_option("-f", "--output-format",
        dest="output_format",
        help="output format name (%s)" % (', '.join(memory.save_formats),),
        default="titext",
        metavar="TYPE")

parser.add_option("-l", "--length",
        dest="size",
        help="number of bytes to generate",
        default=1024,
        type="int")

parser.add_option("-s", "--start-address",
        dest="start_address",
        help="start address of data generated",
        default=None,
        type="int")

parser.add_option("-c", "--count",
        dest="count",
        help="use address as data",
        action="store_true",
        default=False)

parser.add_option("--const",
        dest="const",
        help="use given 16 bit number as data (default=0x3fff)",
        default=0x3fff, # JMP $
        type="int")

(options, args) = parser.parse_args()

if options.output_format not in memory.save_formats:
    parser.error('Output format %s not supported.' % (options.output_format))

if args:
    parser.error('no arguments expected')

# prepare output
if options.output is None:
    out = sys.stdout
else:
    out = file(options.output, 'wb')

# get input
mem = memory.Memory()          # prepare downloaded data

# if no start address is given, align the data towards the end of the 64k
# address room
if options.start_address is None:
    options.start_address = 0x10000 - options.size

# create data
if options.count:
    data = ''.join([struct.pack("<H", x & 0xffff) 
            for x in xrange(options.start_address, options.start_address + options.size, 2)])
else:
    data = ''.join([struct.pack("<H", options.const) 
            for x in xrange(options.start_address, options.start_address + options.size, 2)])

mem.append(memory.Segment(options.start_address, data))

# write ihex file
memory.save(mem, out, options.output_format)

{'fraction_non_alphanumeric': 0.1328398909232567, 'fraction_numerical': 0.013245033112582781, 'mean_word_length': 3.3006700167504186, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7216481', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1551, 'n_words': 477}