void write_asm(Syntax* complete_syntax,Stack* string_stack){
	 tablevar = list_new();
	openf("output.s"); //open file.
	emit_format();
	emit_str(string_stack);
	emit_header();	//print .text
	function_declare("main"); //declare .globl main
	emit_init(); //alloc for main.
	if(complete_syntax->type == BLOCK){
		emitblock(complete_syntax);
	}else
		printf("invalid syntax");
	emit_footer(); //ralloc for main
	closef(fp); //close file.
	free(tablevar);
}
Пример #2
0
int
main(int argc, char *argv[]) 
{
  int rc = 1;
  int i;
  int parsers_count = 0;
  int serializers_count = 0;
  int mime_types_count = 0;
  raptor_syntax_description** parsers = NULL;
  raptor_syntax_description** serializers = NULL;
  raptor_iostream* iostr = NULL;
  type_syntax* type_syntaxes = NULL;
  int type_syntaxes_count = 0;
  
  if(argc != 1) {
    fprintf(stderr, "%s: USAGE: %s\n", program, program);
    return 1;
  }

  world = raptor_new_world();
  if(!world)
    goto tidy;


  for(i = 0; 1; i++) {
    raptor_syntax_description* sd;
    sd = (raptor_syntax_description*)raptor_world_get_parser_description(world, i);
    if(!sd)
      break;
    parsers_count++;
    mime_types_count += sd->mime_types_count;
  }
  for(i = 0; 1; i++) {
    raptor_syntax_description* sd;
    sd = (raptor_syntax_description*)raptor_world_get_serializer_description(world, i);
    if(!sd)
      break;
    serializers_count++;
    mime_types_count += sd->mime_types_count;
  }

  parsers = (raptor_syntax_description**)calloc(parsers_count,
    sizeof(raptor_syntax_description*));
  if(!parsers)
    goto tidy;

  serializers = (raptor_syntax_description**)calloc(serializers_count,
    sizeof(raptor_syntax_description*));
  if(!serializers)
    goto tidy;

  type_syntaxes = (type_syntax*)calloc(mime_types_count,
    sizeof(type_syntax));
  if(!type_syntaxes)
    goto tidy;

  type_syntaxes_count = 0;

  for(i = 0; 1; i++) {
    raptor_syntax_description* sd;
    unsigned int m;
    
    sd = (raptor_syntax_description*)raptor_world_get_parser_description(world, i);
    if(!sd)
      break;
    parsers[i] = sd;

    for(m = 0; m < sd->mime_types_count; m++) {
      type_syntaxes[type_syntaxes_count].mime_type = sd->mime_types[m].mime_type;
      type_syntaxes[type_syntaxes_count].q = sd->mime_types[m].q;
      type_syntaxes[type_syntaxes_count].parser_sd = sd;
      type_syntaxes_count++;
    }
  }

  qsort(parsers, parsers_count, sizeof(raptor_syntax_description*),
        sort_sd_by_name);
  
  for(i = 0; 1; i++) {
    raptor_syntax_description* sd;
    unsigned int m;
    
    sd = (raptor_syntax_description*)raptor_world_get_serializer_description(world, i);
    if(!sd)
      break;
    serializers[i] = sd;

    for(m = 0; m < sd->mime_types_count; m++) {
      type_syntaxes[type_syntaxes_count].mime_type = sd->mime_types[m].mime_type;
      type_syntaxes[type_syntaxes_count].q = sd->mime_types[m].q;
      type_syntaxes[type_syntaxes_count].serializer_sd = sd;
      type_syntaxes_count++;
    }
  }

  qsort(serializers, serializers_count, sizeof(raptor_syntax_description*),
        sort_sd_by_name);
  

  iostr = raptor_new_iostream_to_file_handle(world, stdout);
  if(!iostr)
    goto tidy;
  

  /* MIME Types by parser */
  emit_header("raptor-formats", iostr);

  emit_start_section("raptor-formats-intro",
                     "Introduction",
                     iostr);
  raptor_iostream_string_write(
"<para>\n"
"The parsers and serializers in raptor can handle different MIME Types with different levels of quality (Q).  A Q of 1.0 indicates that the parser or serializer will be able to read or write the full format with high quality, and it should be the prefered parser or serializer for that mime type.  Lower Q values indicate either additional mime type support (for parsing) or less-preferred mime types (for serializing).  A serializer typically has just 1 mime type of Q 1.0; the preferred type."
"</para>\n"
,
    iostr);
  emit_end_section(iostr);

  emit_start_section("raptor-formats-types-by-parser",
                     "MIME Types by Parser",
                     iostr);
  emit_start_desc_list(NULL, iostr);
  for(i = 0; i < parsers_count; i++) {
    emit_format_description(NULL, parsers[i],
                            iostr);
  }
  emit_end_desc_list(iostr);
  emit_end_section(iostr);


  /* MIME Types by serializer */
  emit_start_section("raptor-formats-types-by-serializer", 
                     "MIME Types by Serializer",
                     iostr);
  emit_start_desc_list(NULL, iostr);
  for(i = 0; i < serializers_count; i++) {
    emit_format_description(NULL, serializers[i],
                            iostr);
  }
  emit_end_desc_list(iostr);
  emit_end_section(iostr);


  /* MIME Types index */
  qsort(type_syntaxes, type_syntaxes_count, sizeof(type_syntax),
        sort_type_syntax_by_mime_type);

  emit_start_section("raptor-formats-types-index", 
                     "MIME Types Index",
                     iostr);
  emit_start_desc_list(NULL, iostr);
  if(1) {
    const char* last_mime_type = NULL;
    int last_start_index = -1;
    for(i = 0; i < type_syntaxes_count; i++) {
      const char *this_mime_type = type_syntaxes[i].mime_type;
      
      if(last_start_index < 0) {
        last_mime_type = this_mime_type;
        last_start_index = i;
        continue;
      }
      /* continue if same mime type */
      if(!strcmp(last_mime_type, this_mime_type))
        continue;

      emit_format_to_syntax_list(iostr, type_syntaxes,
                                 last_mime_type, last_start_index, i-1);

      last_mime_type = type_syntaxes[i].mime_type;
      last_start_index = i;
    }

    emit_format_to_syntax_list(iostr, type_syntaxes,
                               last_mime_type, last_start_index, i-1);
  }
  emit_end_desc_list(iostr);
  emit_end_section(iostr);



  emit_footer(iostr);

  raptor_free_iostream(iostr);
  iostr = NULL;
            
  /* success */
  rc = 0;

  tidy:
  if(iostr)
    raptor_free_iostream(iostr);
  
  if(parsers)
    free(parsers);

  if(serializers)
    free(serializers);
  
  if(type_syntaxes)
    free(type_syntaxes);
  
  if(world)
    raptor_free_world(world);
  
  return rc;
}
Пример #3
0
void block_writer::close_segment(size_t segment_id) {
  emit_footer(segment_id);
  m_output_files[segment_id].reset();
}