Changeset 434 for proto/Compiler


Ignore:
Timestamp:
Jul 3, 2010, 6:22:42 PM (9 years ago)
Author:
eamiri
Message:

-t option added.

Location:
proto/Compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/README

    r351 r434  
    1 This directory contains code for Bit Stream Compiler. This compiler transforms high level python code to C code. The input python file must be written using Parallel Bit Stream idea and only operations on parallel bit streams can be used in the input file. The compiler can be run useing the following command
     1This directory contains code for Bit Stream Compiler. This compiler transforms high level python code to C code. The input python file must be written using Parallel Bit Stream idea and only operations on parallel bit streams can be used in the input file. The compiler can be run using the following command
    22
    3 python bitstream_compiler.py <input file> [output file]
     3python bitstream_compiler.py <input file> [output file] [options]
    44
    55User must input an input file name. This must be a valid python file that only includes operations defined for parallel bit streams. The input file must contain a function named "main".
     
    88
    99
     10=====================================
     11OPTIONS:
     12
     13-simd-carry: In generated C code, carry and borrows of addition and subtraction operations is saved in a vector. The default behaviour (-int-carry) saves these variable in integers.
     14
     15-t template_name: To specify a template different from the default template. By default, template name is template.c and it is assumed to be in the current directory.
     16=====================================
     17SUB-DIRECTORIES:
     18
     19Currently the compiler directory contains two subdirectories. Each directory contains a template file. Users can put their python input files in each of the directories and run compiler to generate C code. The differece is that template file of workspace directory is simpler and compileable by gcc and llvm-gcc. Template of the p-workspace is more complicated with code for performance measuring and requires a C++ compiler like g++ or llvm-g++.
     20
     21
     22=====================================
    1023=====================================
    1124Variables:
  • proto/Compiler/bitstream_compiler.py

    r429 r434  
    1010
    1111class Program:
    12     def __init__(self, out_file):
     12    def __init__(self, out_file, template_name = "template.c"):
    1313        pass
    14         self.templ_name = "template.c"
     14        self.templ_name = template_name
    1515        self.outfile_name = out_file
    1616
     
    6262        return s
    6363
     64OPTION_TEMPLATE_NAME = '-t'
     65OPTION_INT_CARRY = '-int_carry'
     66OPTION_SIMD_CARRY = '-simd-carry'
     67
    6468
    6569def read_flags (params):
    6670    flags = []
    6771    non_flags = []
     72    last_one_continues = False
    6873    l = len(params)
    6974    for i in range(l):
    70         if params[i][0] == '-':
     75        if params[i][0] == '-' or last_one_continues:
    7176            flags.append(params[i])
     77            if params[i]  == OPTION_TEMPLATE_NAME:
     78                last_one_continues = True
     79            else:
     80                last_one_continues = False
    7281        else:
    7382            non_flags.append(params[i])
     
    7584    return flags, non_flags
    7685
    77 def int_carry(flags):
     86def option_carry(flags):
    7887    l = len(flags)
    7988    for i in range(l):
    80         if flags[i] == '-simd-carry':
    81             return False
    82         if flags[i] == '-int-carry':
    83             return True
    84     return True #default carry type is int
     89        if flags[i] == OPTION_SIMD_CARRY:
     90            return False, i
     91        if flags[i] == OPTION_INT_CARRY:
     92            return True, i
     93    return True, -1 #default carry type is int
     94
     95def option_template(flags):
     96    t_name = "template.c"
     97    l = len(flags)
     98    for i in range(l):
     99        if flags[i] == '-t':
     100            if len(flags) == i+1:
     101                print flags
     102                print "WARNING: -t flag used but no template name is given. Default name is used."
     103            else:
     104                t_name = flags[i+1]
     105                return t_name, i
     106
     107    return t_name, -1
    85108
    86109def read_input(inp_file_name):
     
    91114    inp_file.close()
    92115    return mycode
     116
     117def read_options(flags):
     118    carry_option, index = option_carry(flags)
     119    if index >= 0:
     120        del flags[index]
     121   
     122    template_name, index = option_template(flags)
     123    if index >= 0:
     124        del flags[index+1]
     125        del flags[index]
     126   
     127    if len(flags) > 0:
     128        print "WARNING: Unrecognized/duplicated options found!"
     129   
     130    return carry_option, template_name
    93131###############################################################
    94132
     
    99137
    100138        flags, non_flags = read_flags(sys.argv)
     139        print non_flags
    101140        last_slash = non_flags[1].rfind("/")
    102141        file_path = non_flags[1][:last_slash+1]
     
    106145            out_file = non_flags[2]
    107146       
    108         s = Program(out_file).generate_code(read_input(non_flags[1]), file_path, int_carry(flags))
     147        carry_option, template_name = read_options(flags)
     148       
     149        s = Program(out_file, template_name).generate_code(read_input(non_flags[1]), file_path, carry_option)
Note: See TracChangeset for help on using the changeset viewer.