Ejemplo n.º 1
0
  def generate_constants_file(self, spec_path, defs):
    defs['constants'] = zcc_parser.generate_constants(spec_path + ".cons")
    defs['is_mapred_comp'] = zcc_parser.generate_mapred_header(self.class_name)
    
    #if (self.language == "c"):
    #  (defs['type_def'], defs['compute_func_definition']) =  self.extract_clean_compute_function(self.class_name)
    #else:
    #  (defs['type_def'], defs['compute_func_definition']) =  ("", "")

    t = Template(file=CONSTANTS_H_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + CONSTANTS_H, t.__str__())

    t = Template(file=CONSTANTS_IMPL_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + CONSTANTS_IMPL, t.__str__())
Ejemplo n.º 2
0
  def generate_code_from_template(self, spec):
    text = zcc_parser.read_file(spec)
    zcc_parser.parse_text(text)

    computation_name = os.path.splitext(os.path.split(spec)[1])[0]

    OUTPUT_PREFIX = re.sub(r'/',r'_',self.output_prefix).upper()

    defs = {}
    defs['computation_name'] = computation_name
    defs['computation_classname'] = self.class_name
    defs['OUTPUT_PREFIX'] = OUTPUT_PREFIX
    defs['output_prefix'] = self.output_prefix

    (defs['num_io_vars'], defs['num_z_vars'], defs['computation_worksheet']) = zcc_parser.generate_computation_worksheet(text) #leads to variable creation

    if (self.worksheetMode):
      defs['computation'] = zcc_parser.generate_computation_dynamic("bin/" + self.class_name + PROVER_WORKSHEET)
    else:
      defs['computation'] = zcc_parser.generate_computation_static(text)

    #number of variables, number of basic constraints (chi) fixed from this point onwards

    t = Template(file=PROVER_WORKSHEET_TMPL, searchList=[defs]) 
    self.write_to_file("bin/" + self.class_name +  PROVER_WORKSHEET, t.__str__())

    #Generate the variable shuffling
    (defs['F1_index'], shuffledIndices) = zcc_parser.generate_F1_index()
    t = Template(file=F1_INDEX_TMPL, searchList=[defs]) 
    self.write_to_file("bin/" + self.class_name+F1_INDEX, t.__str__())

    if (self.framework=="GINGER"):
      defs['NzA'] = "n/a"
      defs['NzB'] = "n/a"
      defs['NzC'] = "n/a"
    else:
      qap_file_name = os.path.join(self.output_dir, "bin/" + self.class_name + QAP);
      (defs['NzA'], defs['NzB'], defs['NzC'], defs['num_constraints']) = zcc_parser.generate_zaatar_matrices(text, shuffledIndices, qap_file_name)
    
    #Write the prover
    if (self.framework=="GINGER"):
      t = Template(file=PROVER_GINGER_H_TMPL, searchList=[defs]) 
    else:
      t = Template(file=PROVER_ZAATAR_H_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + PROVER_H, t.__str__())

    if (self.framework=="GINGER"):
      defs['gamma12_file_name'] = "bin/" + self.class_name + GAMMA12;
      t = Template(file=PROVER_GINGER_CC_TMPL, searchList=[defs]) 
    else:
      t = Template(file=PROVER_ZAATAR_CC_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + PROVER_IMPL, t.__str__())

    #Write the constants file
    defs['constants'] = zcc_parser.generate_constants(zcc_parser.read_file(spec+".cons"))
    t = Template(file=CONSTANTS_H_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + CONSTANTS_H, t.__str__())

    protectedFiles = {(PROVER_EXO_HW_H, PROVER_EXO_HW_H_TMPL), 
	(PROVER_EXO_HW_IMPL, PROVER_EXO_HW_CC_TMPL),
	(VERIFIER_INP_GEN_HW_H, VERIFIER_INP_GEN_HW_H_TMPL),
	(VERIFIER_INP_GEN_HW_IMPL, VERIFIER_INP_GEN_HW_CC_TMPL)}

    for (targetfile, tmplfile) in protectedFiles:
      filename = "apps_sfdl_hw/" + self.class_name + targetfile;
      try:
	filename_ = os.path.join(self.output_dir, filename)
	with file(filename_, 'r'):
	  os.utime(filename_, None) # Touch it if it exists
      except IOError as e:
	#The file doesn't exist, create it:
	t = Template(file=tmplfile, searchList=[defs]) 
	self.write_to_file(filename, t.__str__())

    #Create the input generator
    defs['create_input'] = zcc_parser.generate_create_input(text)
    t = Template(file=VERIFIER_INP_GEN_H_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + VERIFIER_INP_GEN_H, t.__str__())
    t = Template(file=VERIFIER_INP_GEN_CC_TMPL, searchList=[defs]) 
    self.write_to_file(self.output_prefix + VERIFIER_INP_GEN_IMPL, t.__str__())

    # Produce the verifier code (ginger) or A,B,C matrices (Zaatar) and drivers
    if (self.framework=="GINGER"):
      self.write_ginger(defs, text)
    else:
      self.write_zaatar(defs, text)
    def generate_code_from_template(self, spec):
        text = zcc_parser.read_file(spec)
        zcc_parser.parse_text(text)

        computation_name = os.path.splitext(os.path.split(spec)[1])[0]

        OUTPUT_PREFIX = re.sub(r'/', r'_', self.output_prefix).upper()

        defs = {}
        defs['computation_name'] = computation_name
        defs['computation_classname'] = self.class_name
        defs['OUTPUT_PREFIX'] = OUTPUT_PREFIX
        defs['output_prefix'] = self.output_prefix

        (defs['num_io_vars'], defs['num_z_vars'], defs['computation_worksheet']
         ) = zcc_parser.generate_computation_worksheet(
             text)  #leads to variable creation

        if (self.worksheetMode):
            defs['computation'] = zcc_parser.generate_computation_dynamic(
                "bin/" + self.class_name + PROVER_WORKSHEET)
        else:
            defs['computation'] = zcc_parser.generate_computation_static(text)

        #number of variables, number of basic constraints (chi) fixed from this point onwards

        t = Template(file=PROVER_WORKSHEET_TMPL, searchList=[defs])
        self.write_to_file("bin/" + self.class_name + PROVER_WORKSHEET,
                           t.__str__())

        #Generate the variable shuffling
        (defs['F1_index'], shuffledIndices) = zcc_parser.generate_F1_index()
        t = Template(file=F1_INDEX_TMPL, searchList=[defs])
        self.write_to_file("bin/" + self.class_name + F1_INDEX, t.__str__())

        if (self.framework == "GINGER"):
            defs['NzA'] = "n/a"
            defs['NzB'] = "n/a"
            defs['NzC'] = "n/a"
        else:
            qap_file_name = os.path.join(self.output_dir,
                                         "bin/" + self.class_name + QAP)
            (defs['NzA'], defs['NzB'], defs['NzC'],
             defs['num_constraints']) = zcc_parser.generate_zaatar_matrices(
                 text, shuffledIndices, qap_file_name)

        #Write the prover
        if (self.framework == "GINGER"):
            t = Template(file=PROVER_GINGER_H_TMPL, searchList=[defs])
        else:
            t = Template(file=PROVER_ZAATAR_H_TMPL, searchList=[defs])
        self.write_to_file(self.output_prefix + PROVER_H, t.__str__())

        if (self.framework == "GINGER"):
            defs['gamma12_file_name'] = "bin/" + self.class_name + GAMMA12
            t = Template(file=PROVER_GINGER_CC_TMPL, searchList=[defs])
        else:
            t = Template(file=PROVER_ZAATAR_CC_TMPL, searchList=[defs])
        self.write_to_file(self.output_prefix + PROVER_IMPL, t.__str__())

        #Write the constants file
        defs['constants'] = zcc_parser.generate_constants(
            zcc_parser.read_file(spec + ".cons"))
        t = Template(file=CONSTANTS_H_TMPL, searchList=[defs])
        self.write_to_file(self.output_prefix + CONSTANTS_H, t.__str__())

        protectedFiles = {(PROVER_EXO_HW_H, PROVER_EXO_HW_H_TMPL),
                          (PROVER_EXO_HW_IMPL, PROVER_EXO_HW_CC_TMPL),
                          (VERIFIER_INP_GEN_HW_H, VERIFIER_INP_GEN_HW_H_TMPL),
                          (VERIFIER_INP_GEN_HW_IMPL,
                           VERIFIER_INP_GEN_HW_CC_TMPL)}

        for (targetfile, tmplfile) in protectedFiles:
            filename = "apps_sfdl_hw/" + self.class_name + targetfile
            try:
                filename_ = os.path.join(self.output_dir, filename)
                with file(filename_, 'r'):
                    os.utime(filename_, None)  # Touch it if it exists
            except IOError as e:
                #The file doesn't exist, create it:
                t = Template(file=tmplfile, searchList=[defs])
                self.write_to_file(filename, t.__str__())

        #Create the input generator
        defs['create_input'] = zcc_parser.generate_create_input(text)
        t = Template(file=VERIFIER_INP_GEN_H_TMPL, searchList=[defs])
        self.write_to_file(self.output_prefix + VERIFIER_INP_GEN_H,
                           t.__str__())
        t = Template(file=VERIFIER_INP_GEN_CC_TMPL, searchList=[defs])
        self.write_to_file(self.output_prefix + VERIFIER_INP_GEN_IMPL,
                           t.__str__())

        # Produce the verifier code (ginger) or A,B,C matrices (Zaatar) and drivers
        if (self.framework == "GINGER"):
            self.write_ginger(defs, text)
        else:
            self.write_zaatar(defs, text)
Ejemplo n.º 4
0
 def generate_constants_file(self, spec_path, defs):
   defs['constants'] = zcc_parser.generate_constants(spec_path + ".cons")
   defs['is_mapred_comp'] = zcc_parser.generate_mapred_header(self.class_name)
Ejemplo n.º 5
0
 def generate_constants_file(self, spec_path, defs):
     defs['constants'] = zcc_parser.generate_constants(spec_path + ".cons")
     defs['is_mapred_comp'] = zcc_parser.generate_mapred_header(
         self.class_name)