Changeset 865


Ignore:
Timestamp:
Jan 3, 2011, 6:20:24 PM (9 years ago)
Author:
cameron
Message:

Add @global declaration template facility; use for struct types.

Location:
proto/Compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • proto/Compiler/compiler2.py

    r811 r865  
    1717        self.output_file = output_file
    1818
    19     def output(self, decl, stream_stmts , block_stmts, any_carry_expr, template_string):
    20         template_string = string.replace(template_string, '@decl', decl)
     19    def output(self, globaldecl, localdecl, stream_stmts , block_stmts, any_carry_expr, template_string):
     20        template_string = string.replace(template_string, '@global', globaldecl)
     21        template_string = string.replace(template_string, '@decl', localdecl)
    2122        template_string = string.replace(template_string, '@stream_stmts', stream_stmts)
    2223        template_string = string.replace(template_string, '@block_stmts', block_stmts)
     
    4849        # BACK END
    4950        template_contents = self.read_template()
    50         template_contents = self.output(xfrmr.getCdecls(),
     51        template_contents = self.output(xfrmr.getCglobals(),
     52                            xfrmr.getCdecls(),
    5153                            xfrmr.getCinits(),
    5254                            xfrmr.getCstmts(),
  • proto/Compiler/pablo.py

    r863 r865  
    308308    self.generic_visit(tree)
    309309    return self.Ccode
     310  def gen_struct_types(self, tree):
     311    self.asType = True
     312    self.Ccode=""
     313    self.generic_visit(tree)
     314    return self.Ccode
     315  def gen_struct_vars(self, tree):
     316    self.asType = False
     317    self.Ccode=""
     318    self.generic_visit(tree)
     319    return self.Ccode
    310320  def visit_ClassDef(self, node):
    311321    class_name = node.name[0].upper() + node.name[1:]
    312322    instance_name = node.name[0].lower() + node.name[1:]
    313     self.Ccode += "struct " + class_name + " {\n"
    314     for stmt in node.body:
    315       if isinstance(stmt, ast.Assign):
    316         for v in stmt.targets:
    317           if isinstance(v, ast.Name):
    318             self.Ccode += "  BitBlock " + v.id + ";\n"
    319     self.Ccode += "}"
    320     if not self.asType: self.Ccode += " " + instance_name
     323    self.Ccode += "struct " + class_name
     324    if self.asType:
     325            self.Ccode += " {\n"
     326            for stmt in node.body:
     327              if isinstance(stmt, ast.Assign):
     328                for v in stmt.targets:
     329                  if isinstance(v, ast.Name):
     330                    self.Ccode += "  BitBlock " + v.id + ";\n"
     331            self.Ccode += "}"
     332    else: self.Ccode += " " + instance_name
    321333    self.Ccode += ";\n\n"
    322334 
     
    371383def main(infilename, outfile = sys.stdout):
    372384  t = ast.parse(file(infilename).read())
    373   outfile.write(StreamStructGen().gen(t))
     385  outfile.write(StreamStructGen(True).gen(t))
    374386  outfile.write(FunctionXlator().xlat(t))
    375387
     
    391403    else: return "CarryTest(%s, 0, %i)\n" % (self.carry_var, self.carry_count)
    392404  def gen_declarations(self):
    393     self.Cdecls = StreamStructGen().gen(self.main_module)
     405    self.Cglobals = StreamStructGen().gen_struct_types(self.main_module)
     406    self.Cdecls = StreamStructGen().gen_struct_vars(self.main_module)
    394407    self.Cdecls += BitBlock_decls_of_fn(self.main_fn)
    395408    if self.carry_count > 0: self.Cdecls += "CarryDeclare(%s, %i);\n" % (self.carry_var, self.carry_count)
     
    405418  def add_loop_carryQ_adjust(self):
    406419    self.main_fn.body += [mkCallStmt('CarryQ_Adjust', [ast.Name(self.carry_var, ast.Load()), ast.Num(self.carry_count)])]
     420  def getCglobals(self):
     421    return self.Cglobals
    407422  def getCdecls(self):
    408423    return self.Cdecls
  • proto/Compiler/workspace/pablo_template.c

    r823 r865  
    3030        void * perf_timer;
    3131#endif
     32
     33@global
    3234
    3335void do_process(FILE *infile, FILE *outfile) {
Note: See TracChangeset for help on using the changeset viewer.