Example #1
0
const struct tgsi_token *ureg_finalize( struct ureg_program *ureg )
{
   const struct tgsi_token *tokens;

   emit_header( ureg );
   emit_decls( ureg );
   copy_instructions( ureg );
   fixup_header_size( ureg );
   
   if (ureg->domain[0].tokens == error_tokens ||
       ureg->domain[1].tokens == error_tokens) {
      debug_printf("%s: error in generated shader\n", __FUNCTION__);
      assert(0);
      return NULL;
   }

   tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token;

   if (0) {
      debug_printf("%s: emitted shader %d tokens:\n", __FUNCTION__, 
                   ureg->domain[DOMAIN_DECL].count);
      tgsi_dump( tokens, 0 );
   }

#if DEBUG
   if (tokens && !tgsi_sanity_check(tokens)) {
      debug_printf("tgsi_ureg.c, sanity check failed on generated tokens:\n");
      tgsi_dump(tokens, 0);
      assert(0);
   }
#endif

   
   return tokens;
}
Example #2
0
File: emit_m.c Project: cd127/lcm-1
int emit_m(lcmgen_t *lcm)
{
    // iterate through all defined message types
    for (unsigned int i = 0; i < g_ptr_array_size(lcm->structs); i++) {
        lcm_struct_t *ls = (lcm_struct_t *) g_ptr_array_index(lcm->structs, i);

		// generate code if needed
		{
            emit_header(lcm, ls);
            emit_encode(lcm, ls);
            emit_decode(lcm, ls);
            emit_encoded_size(lcm, ls);
            emit_get_hash(lcm, ls);
//            emit(0, "const char* %s::getTypeName()", sn);
//            emit(0, "{");
//            emit(1,     "return \"%s\";", sn);
//            emit(0, "}");
//            emit(0, "");

            emit_encode_nohash(lcm, ls);
            emit_decode_nohash(lcm, ls);
            emit_encoded_size_nohash(lcm, ls);
            emit_compute_hash(lcm, ls);
        }
    }

    return 0;
}
 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);
}
Example #4
0
int main(int argc, char *argv[]) {
    int byte_count = 0;
    char tmpstr[512];
    uint8_t *buffer; /* Memory buffer */
    FILE *input_file; /* Input file */
    uint16_t pc; /* Program counter */
    options_t options; /* Command-line options parsing results */

    parse_args(argc, argv, &options);

    buffer = calloc(1, 65536);
    if (NULL == buffer) {
        usage_and_exit(3, "Could not allocate disassembly memory buffer.");
    }

    /* Read file into memory buffer */
    input_file = fopen(options.filename, "rb");

    if (NULL == input_file) {
        version();
        fprintf(stderr, "File not found or invalid filename : %s\n", options.filename);
        exit(2);
    }

    byte_count = 0;
    while(!feof(input_file) && ((options.org + byte_count) <= 0xFFFFu) && (byte_count < options.max_num_bytes)) {
        fread(&buffer[options.org + byte_count], 1, 1, input_file);
        byte_count++;
    }

    fclose(input_file);

    /* Disassemble contents of buffer */
    emit_header(&options, byte_count);
    pc = options.org;
    while((pc <= 0xFFFFu) && ((pc - options.org) < byte_count)) {
        disassemble(tmpstr, buffer, &options, &pc);
        fprintf(stdout, "%s\n", tmpstr);
        pc++;
    }

    free(buffer);

    return 0;
}
Example #5
0
/**
 * Emit GLX DrawArrays protocol using a GLXRender packet.
 */
static void   
emit_Render_DrawArrays(__GLXcontext * gc, const struct array_info * arrays,
		       GLsizei first, GLsizei count, GLsizei num_arrays, GLenum mode,
		       GLsizei cmdlen, GLsizei total_vertex_size)
{
    GLubyte * pc = gc->pc;
    GLsizei offset;
    GLsizei i;

    __GLX_BEGIN_VARIABLE(X_GLrop_DrawArrays, cmdlen);
    emit_header(pc + 4, arrays, num_arrays, count, mode);


    /* Write the actual array data.
     */

    offset = __GLX_DRAWARRAYS_CMD_HDR_SIZE 
	+ (num_arrays * __GLX_COMPONENT_HDR_SIZE);
    for ( i = 0 ; i < count ; i++ ) {
	offset = emit_vertex(pc, arrays, num_arrays, i + first, offset);
    }

    __GLX_END(cmdlen);
}
Example #6
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;
}
Example #7
0
    logpool_string_close(logpool);
}

static void logpool_io_flush(logpool_t *logpool, void **args __UNUSED__)
{
    struct io_plugin *lp = cast(struct io_plugin *, logpool->connection);
    char *buf_orig = lp->buf;
    size_t size, bufsize;
    struct logfmt *fmt, *fmte;
    int ret;
    uint16_t *loginfo;

    size = logpool->logfmt_size + 1;
    fmt = cast(struct logpool *, logpool)->fmt;
    fmte = fmt + size - 1;
    loginfo = emit_header(lp->buf, LOGPOOL_EVENT_WRITE, size);
    lp->buf = (char *)(loginfo + size * 2);
    char *p = lp->buf;
    logpool->fn_key(logpool, logpool->logkey.v.u,
            logpool->logkey.k.seq, logpool->logkey.klen);
    *loginfo++ = strlen("TraceID");
    *loginfo++ = lp->buf - p - strlen("TraceID");
    assert(size > 0);

    while(fmt < fmte) {
        char *_buf = lp->buf;
        fmt->fn(logpool, fmt->k.key, fmt->v.u, fmt->klen, fmt->vlen);
        *loginfo++ = fmt->klen;
        *loginfo++ = (lp->buf - _buf) - fmt->klen;
        ++fmt;
    }
Example #8
0
void write_header(FILE *out){
	emit_header(out, ".data\n.LC0:    .ascii \"%d\\n\\0\"\n.LC1:    .ascii \"%x\\n\\0\"\n.text\n    .global _main\n_main:\n");
    	emit_instr(out, "pushl", "%ebp");
    	emit_instr(out, "movl", "%esp, %ebp");
	emit_instr(out, "sub", "$104, %esp");
}
Example #9
0
/**
 * Emit GLX DrawArrays protocol using a GLXRenderLarge packet.
 */
static void   
emit_RenderLarge_DrawArrays(__GLXcontext * gc, const struct array_info * arrays,
		       GLsizei first, GLsizei count, GLsizei num_arrays, GLenum mode,
		       GLsizei cmdlen, GLsizei total_vertex_size)
{
    GLubyte * pc = gc->pc;
    GLsizei offset;
    GLsizei i;
    GLint maxSize;
    GLint totalRequests;
    GLint requestNumber;
    GLsizei elements_per_request;


    /* Calculate the maximum amount of data can be stuffed into a single
     * packet.  sz_xGLXRenderReq is added because bufSize is the maximum
     * packet size minus sz_xGLXRenderReq.
     * 
     * The important value here is elements_per_request.  This is the number
     * of complete array elements that will fit in a single buffer.  There
     * may be some wasted space at the end of the buffer, but splitting
     * elements across buffer boundries would be painful.
     */

    maxSize = (gc->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq;

    elements_per_request = maxSize / total_vertex_size;

    totalRequests = ((count + (elements_per_request - 1))
		     / elements_per_request) + 1;


    /* Fill in the header data and send it away.
     */

    __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_DrawArrays, cmdlen+4);
    emit_header(pc + 8, arrays, num_arrays, count, mode);

    gc->pc = pc + (__GLX_DRAWARRAYS_CMD_HDR_SIZE + 4)
	    + (__GLX_COMPONENT_HDR_SIZE * num_arrays);
    __glXSendLargeChunk(gc, 1, totalRequests, gc->buf, gc->pc - gc->buf);


    /* Write the actual array data.
     */
    offset = 0;
    requestNumber = 2;
    for ( i = 0 ; i < count ; i++ ) {
	if ( i == elements_per_request ) {
	    __glXSendLargeChunk(gc, requestNumber, totalRequests, 
				gc->buf, offset);
	    requestNumber++;
	    offset = 0;

	    count -= i;
	    first += i;
	    i = 0;
	}

	offset = emit_vertex(gc->buf, arrays, num_arrays, i + first, offset);
    }

    /* If the buffer isn't empty, emit the last, partial request.
     */
    if ( offset != 0 ) {
	assert(requestNumber == totalRequests);
	__glXSendLargeChunk(gc, requestNumber, totalRequests, gc->buf, offset);
    }

    gc->pc = gc->buf;
}