Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  cerr << "SLICC v0.3" << endl;

  if (argc < 4) {
    cerr << "  Usage: generator.exec <code path> <html path> <ident> files ... " << endl;
    exit(1);
  }

  // The path we should place the generated code
  string code_path(argv[1]);
  code_path += "/";

  // The path we should place the generated html
  string html_path(argv[2]);
  html_path += "/";

  string ident(argv[3]);

  Vector<DeclListAST*> decl_list_vec;

  // Parse
  cerr << "Parsing..." << endl;
  for(int i=4; i<argc; i++) {
    cerr << "  " << argv[i] << endl;
    DeclListAST* decl_list_ptr = parse(argv[i]);
    decl_list_vec.insertAtBottom(decl_list_ptr);
  }

  // Find machines
  cerr << "Generator pass 1..." << endl;
  int size = decl_list_vec.size();
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->findMachines();    
  }

  // Generate Code
  cerr << "Generator pass 2..." << endl;
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->generate();    
    delete decl_list_ptr;
  }
  
  generate_files(code_path, html_path, ident);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  cerr << "SLICC v0.3" << endl;

  if (argc < 5) {
    cerr << "  Usage: generator.exec <code path> <html path> <ident> <html direction> files ... " << endl;
    exit(1);
  }

  // The path we should place the generated code
  string code_path(argv[1]);
  code_path += "/";

  // The path we should place the generated html
  string html_path(argv[2]);
  html_path += "/";

  string ident(argv[3]);

  string html_generate(argv[4]);

  Vector<DeclListAST*> decl_list_vec;

  // Parse
  cerr << "Parsing..." << endl;
  for(int i=5; i<argc; i++) {
    cerr << "  " << argv[i] << endl;
    DeclListAST* decl_list_ptr = parse(argv[i]);
    decl_list_vec.insertAtBottom(decl_list_ptr);
  }

  // Find machines
  cerr << "Generator pass 1..." << endl;
  int size = decl_list_vec.size();
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->findMachines();    
  }

  // Generate Code
  cerr << "Generator pass 2..." << endl;
  for(int i=0; i<size; i++) {
    DeclListAST* decl_list_ptr = decl_list_vec[i];
    decl_list_ptr->generate();    
    delete decl_list_ptr;
  }

  // Generate C/C++ files
  cerr << "Writing C files..." << endl;

  {
    // Generate the name of the protocol
    ostringstream sstr;
    sstr << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<<endl;
    sstr << endl;
    sstr << "#ifndef PROTOCOL_NAME_H" << endl;
    sstr << "#define PROTOCOL_NAME_H" << endl;
    sstr << endl;
    sstr << "const char CURRENT_PROTOCOL[] = \"";
    sstr << ident << "\";\n";
    sstr << "#endif // PROTOCOL_NAME_H" << endl;
    conditionally_write_file(code_path + "/protocol_name.h", sstr);
  }

  g_sym_table.writeCFiles(code_path);

  // Generate HTML files
  if (html_generate == "html") {
    cerr << "Writing HTML files..." << endl;
    g_sym_table.writeHTMLFiles(html_path);
  } else if (html_generate == "no_html") {
    cerr << "No HTML files generated" << endl;
  } else {
    cerr << "ERROR, unidentified html direction" << endl;
  }

  cerr << "Done..." << endl;

  // Generate MIF files
  cerr << "Writing MIF files..." << endl;
  g_sym_table.writeMIFFiles(html_path);

  cerr << "Done..." << endl;

}