Changeset 760 for proto/Compiler


Ignore:
Timestamp:
Dec 1, 2010, 9:13:36 PM (9 years ago)
Author:
cameron
Message:

Handling stream_stmts initializations

Location:
proto/Compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/compiler2.py

    r756 r760  
    4545
    4646        # BACK END
     47        templ = self.read_template(file_path)
     48        stream_stmts = pablo.stream_stmts(s)
    4749        declarations = pablo.gen_declarations(s, self.mainfn)
    48         templ = self.read_template(file_path)
    49 
     50 
    5051        templ = self.output(declarations,
    51                             pablo.stream_stmts(self.mainfn),
     52                            stream_stmts,
    5253                            pablo.block_stmts(self.mainfn),
    5354                            pablo.any_carry_expr(self.mainfn),
    54                            
    5555                            templ)
    5656        self.write_final_code(templ)
  • proto/Compiler/pablo.py

    r756 r760  
    134134  Ccode += ")"
    135135  return Ccode
     136
     137
     138
     139#
     140#  Stream Initialization Statement Extraction
     141#
     142#  streamvar = 1 ==> streamvar = sisd_from_int(1) initially.
     143class StreamInitializations(ast.NodeTransformer):
     144  def xfrm(self, node):
     145    self.stream_stmts = []
     146    self.loop_post_inits = []
     147    self.generic_visit(node)
     148    return Cgen.py2C().gen(self.stream_stmts)
     149  def visit_Assign(self, node):
     150    if isinstance(node.value, ast.Num):
     151      if node.value.n == 0: return node
     152      elif node.value.n == -1: return node
     153      else:
     154        stream_init = copy.deepcopy(node)
     155        stream_init.value = mkCall('sisd_from_int', [node.value])
     156        loop_init = copy.deepcopy(node)
     157        loop_init.value.n = 0
     158        self.stream_stmts.append(stream_init)
     159        self.loop_post_inits.append(loop_init)
     160        return None
     161    else: return node
     162  def visit_FunctionDef(self, node):
     163    self.generic_visit(node)
     164    node.body = node.body + self.loop_post_inits
     165    return node
    136166
    137167
     
    340370
    341371def stream_stmts(main_fn):
    342   return ""
     372  return StreamInitializations().xfrm(main_fn)
    343373
    344374def block_stmts(main_fn):
Note: See TracChangeset for help on using the changeset viewer.