Beispiel #1
0
void io_module()
{
    uint8_t buf8[4096];
    while(1)
    {

	// number of bytes to be read..
       	uint32_t len8 = read_uint32("inpipe");

	// read the uint32_t's and stuff them into buf.
	int i;
	for(i=0; i < len8; i=i+4)
		*((uint32_t*)(buf8 + i)) = read_uint32("inpipe");

	// reverse bytes.
	reverse(buf8,len8);
			
 
	// send the packet as uint8_t's..
	// first the length.
	uint8_t* lenptr = (uint8_t*) (&len8);
	// least-significant byte first.
	for(i=0; i < 4; i++)
		write_uint8("outpipe",lenptr[i]);

	// then the packet.
	for(i=0; i < len8; i++)
		write_uint8("outpipe", buf8[i]);

    }
}
Beispiel #2
0
void correlator()
{
	uint32_t i,j,k;

	float bc;
	uint32_t bi;

	while(1)
	{
		float best_corr;
		uint32_t best_index;
		get_input();

		write_uint8("start_slave_0",1);
#ifdef USE2
		write_uint8("start_slave_1",1);
		float bc0 = read_float32("best_correlation_0_pipe");
		uint32_t bi0 = read_uint32("best_index_0_pipe");

		float bc1 = read_float32("best_correlation_1_pipe");
		uint32_t bi1 = read_uint32("best_index_1_pipe");

		uint32_t cr = (bc0 < bc1);
		bc = (cr ? bc1 : bc0);
		bi = (cr ? bi1 : bi0);

#else
		bc = read_float32("best_correlation_0_pipe");
		bi = read_uint32("best_index_0_pipe");
#endif
		write_float32("best_correlation_pipe", bc);
		write_uint32("best_index_pipe", bi);
	}
}
Beispiel #3
0
static void write_as_tag(ios_t *s, uint8_t tag)
{
    if (tag < VALUE_TAGS) {
        write_uint8(s, 0);
    }
    write_uint8(s, tag);
}
Beispiel #4
0
void *write_pipe_(void *args)
{
    uint16_t len = (uint16_t)(((FnArgs *)args)->len);
    uint8_t *buf = (uint8_t *)(((FnArgs *)args)->buf);

    // Construct and write out the IOQ.
    ioq_t ioq;
    ioq.v = 0;

    uint16_t words = len >> 3;
    if ((len & 7) != 0)
        words++;

    ioq.f.srcp = htons(1);
    ioq.f.wlen = htons(words);
    ioq.f.dstp = htons(1);
    ioq.f.blen = htons(len);

    uint8_t outctrl = 0xff;
    uint64_t outdata = ioq.v;
    write_uint64("in_data", outdata);
    write_uint8("in_ctrl", outctrl);

    printf("Wrote the IOQ (%llx).\n", outdata);

    // Write out full 64-bit words of data.
    outctrl = 0;
    uint16_t i;
    for (i = 0; i < words - 1; ++i) {
        word_t w;
        w.v = 0;
        int j;
        for (j = 0; j < 8; ++j)
            w.s.b[j] = buf[i * 8 + j];
        write_uint64("in_data", w.v);
        write_uint8("in_ctrl", outctrl);
        printf("Wrote data word %u (%llx).\n", i, w.v);
    }

    // Write out the last (partial) word.
    // Control bus has one bit set to mark the last byte.
    // E.g. 2 bytes in the last word, outctrl = 01000000.
    outctrl = ((uint8_t)0x80) >> ((len & 7) - 1);
    word_t w;
    w.v = 0;
    int j;
    for (j = 0; j < 8; ++j)
        w.s.b[j] = buf[i * 8 + j];

    write_uint64("in_data", w.v);
    write_uint8("in_ctrl", outctrl);

    printf("Wrote the last data word, #%u (%llx).\n", i, w.v);
}
Beispiel #5
0
void sendConstants()
{
	int I;
	for(I = 0; I < 256; I++)
		write_uint8("byte_constants_pipe", __E[I]);
	for(I = 0; I < 256; I++)
		write_uint8("byte_constants_pipe", __L[I]);
	for(I = 0; I < 256; I++)
		write_uint8("byte_constants_pipe", __fbsub[I]);
	for(I = 0; I < 15; I++)
		write_uint32("word_constants_pipe", __Rcon[I]);
}
Beispiel #6
0
void
Squeezer_chunk_header_t::write_to_file(FILE * out) const
{
    write_uint8(out, chunk_mark[0]);
    write_uint8(out, chunk_mark[1]);
    write_uint8(out, chunk_mark[2]);
    write_uint8(out, chunk_mark[3]);

    write_uint64(out, number_of_bytes);
    write_uint32(out, number_of_samples);

    write_uint32(out, chunk_type);

    compression_error.write_to_file(out);
}
Beispiel #7
0
static void write_int32(ios_t *s, int32_t i)
{
    write_uint8(s, i       & 0xff);
    write_uint8(s, (i>> 8) & 0xff);
    write_uint8(s, (i>>16) & 0xff);
    write_uint8(s, (i>>24) & 0xff);
}
Beispiel #8
0
void *spice_marshaller_add_uint8(SpiceMarshaller *m, uint8_t v)
{
    uint8_t *ptr;

    ptr = spice_marshaller_reserve_space(m, sizeof(uint8_t));
    write_uint8(ptr, v);
    return (void *)ptr;
}
Beispiel #9
0
static void jl_serialize_tag_type(ios_t *s, jl_value_t *v)
{
    if (jl_is_struct_type(v)) {
        writetag(s, (jl_value_t*)jl_struct_kind);
        jl_serialize_value(s, jl_struct_kind);
        write_uint16(s, jl_tuple_len(((jl_struct_type_t*)v)->names));
        write_int32(s, ((jl_struct_type_t*)v)->uid);
        write_int32(s, ((jl_struct_type_t*)v)->size);
        write_int32(s, ((jl_struct_type_t*)v)->alignment);
        size_t nf = jl_tuple_len(((jl_struct_type_t*)v)->names);
        ios_write(s, (char*)&((jl_struct_type_t*)v)->fields[0], nf*sizeof(jl_fielddesc_t));
        jl_serialize_value(s, ((jl_struct_type_t*)v)->name);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->super);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->names);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->types);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->env);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo);
        jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr);
    }
    else if (jl_is_bits_type(v)) {
        writetag(s, jl_struct_kind);
        jl_serialize_value(s, jl_bits_kind);
        if (v == (jl_value_t*)jl_int32_type)
            write_uint8(s, 2);
        else if (v == (jl_value_t*)jl_bool_type)
            write_uint8(s, 3);
        else if (v == (jl_value_t*)jl_int64_type)
            write_uint8(s, 4);
        else
            write_uint8(s, 0);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters);
        write_int32(s, ((jl_bits_type_t*)v)->nbits);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->super);
        write_int32(s, ((jl_bits_type_t*)v)->uid);
    }
    else {
        assert(jl_is_tag_type(v));
        writetag(s, jl_tag_kind);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->super);
    }
}
Beispiel #10
0
void write_uint8_n(const char *id, uint8_t* buf, int buf_len)
{
  int i;
  for(i = 0; i < buf_len; i++)
    {
      write_uint8((char*) id,buf[i]);
    }
}
Beispiel #11
0
static int write_uint8_array(FILE *fp, uint8_t *array, size_t n)
{
    size_t i;
    int ret = 0;
    for (i = 0;i < n;++i) {
        ret |= write_uint8(fp, array[i]);
    }
    return ret;
}
Beispiel #12
0
static int writer_uint8(lua_State* L)
{
	writer_t* writer	= lua_touserdata(L, 1);
	lua_Integer integer = luaL_checkinteger(L, 2);
	
	if(integer < 0 || integer > UINT8_MAX)
		luaL_error(L, "unsigned overflow");
	
	write_uint8(writer, (uint8_t)integer);
	return 0;
}
Beispiel #13
0
static void jl_serialize_tag_type(ios_t *s, jl_value_t *v)
{
    if (jl_is_struct_type(v)) {
        writetag(s, (jl_value_t*)jl_struct_kind);
        jl_serialize_value(s, jl_struct_kind);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->name);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->super);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->names);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->types);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->env);
        jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo);
        jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr);
        write_int32(s, ((jl_struct_type_t*)v)->uid);
    }
    else if (jl_is_bits_type(v)) {
        writetag(s, jl_struct_kind);
        jl_serialize_value(s, jl_bits_kind);
        if (v == (jl_value_t*)jl_int32_type)
            write_uint8(s, 2);
        else if (v == (jl_value_t*)jl_bool_type)
            write_uint8(s, 3);
        else if (v == (jl_value_t*)jl_int64_type)
            write_uint8(s, 4);
        else
            write_uint8(s, 0);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters);
        write_int32(s, ((jl_bits_type_t*)v)->nbits);
        jl_serialize_value(s, ((jl_bits_type_t*)v)->super);
        write_int32(s, ((jl_bits_type_t*)v)->uid);
    }
    else {
        assert(jl_is_tag_type(v));
        writetag(s, jl_tag_kind);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->name);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters);
        jl_serialize_value(s, ((jl_tag_type_t*)v)->super);
    }
}
Beispiel #14
0
static int
write_nonterminal_v1(struct save_data *save_data,
                     serialized_id serialized_node,
                     ipset_variable variable,
                     serialized_id serialized_low,
                     serialized_id serialized_high)
{
    rii_check(write_uint8(save_data->stream, variable));
    rii_check(write_uint32(save_data->stream, serialized_low));
    rii_check(write_uint32(save_data->stream, serialized_high));
    return 0;
}
Beispiel #15
0
void CMp4_trak_box::write_trak(FILE *fin,FILE * fout,uint32_t trak_size,CMp4_trak_box trak,std::string str) 
{
	unsigned int cur=_ftelli64(fin);
	uint32_t cur_size=0;
	write_uint32_lit(fout,trak.size);
	fwrite(&trak.type,sizeof(trak.type),1,fout);		
	do 
	{
		_fseeki64(fin,cur,SEEK_SET);
		uint32_t buf_size  = read_uint32_lit(fin);
		unsigned char p[5];
		fread(p, 4, 1, fin);
		p[4]= 0;
		std::string name= (char*)p;
		if (name=="tkhd")
		{
			write_uint32_lit(fout,trak.tkhd.size);
			fwrite(&trak.tkhd.type,sizeof(trak.tkhd.type),1,fout);
			write_uint8(fout,trak.tkhd.version);
			fwrite(&trak.tkhd.flags,sizeof(trak.tkhd.flags),1,fout);
			write_uint32_lit(fout,trak.tkhd.creation_time);
			write_uint32_lit(fout,trak.tkhd.modification_time);
			write_uint32_lit(fout,trak.tkhd.track_ID);
			write_uint32_lit(fout,trak.tkhd.reserved1);
			write_uint32_lit(fout,trak.tkhd.duration);
			fwrite(&trak.tkhd.reserved2,sizeof(trak.tkhd.reserved2),1,fout);
			write_uint16_big(fout,trak.tkhd.layer);
			write_uint16_big(fout,trak.tkhd.alternate_group);
			write_uint16_big(fout,trak.tkhd.volume);
			write_uint16_big(fout,trak.tkhd.reserved3);
			fwrite(&trak.tkhd.matrix,sizeof(trak.tkhd.matrix),1,fout);
			write_uint32_lit(fout,trak.tkhd.width);
			write_uint32_lit(fout,trak.tkhd.height);
		} 
		else if (name=="mdia")
		{
			CMp4_mdia_box mdia;
			mdia.write_mdia(fin,fout,buf_size,trak.mdia,str);	
		}
		else
		{
			write_uint32_lit(fout,buf_size);
			fwrite(&p,4,1,fout);
			int buf=buf_size-8;
			char *ptr=new char [buf];
			fread(ptr, buf, 1, fin);
			fwrite(ptr, buf, 1, fout);
			delete [] ptr;
		}
		cur_size+=buf_size+8;
		cur+=buf_size;
	} while (cur_size<=trak_size);
}
int key_value_write_lines(FILE *f, struct key_value_specification *kvs, void *base_address[])
{
	struct key_value_specification *k;
	int rc;
	int errs = 0;

	for (k = kvs; k->key; k++) {
		switch (k->type) {
		case KVS_STRING:
			rc = write_string(f, k, base_address);
			break;
		case KVS_INT64:
			rc = write_int64(f, k, base_address);
			break;
		case KVS_INT32:
			rc = write_int32(f, k, base_address);
			break;
		case KVS_INT16:
			rc = write_int16(f, k, base_address);
			break;
		case KVS_INT8:
			rc = write_int8(f, k, base_address);
			break;
		case KVS_UINT64:
			rc = write_uint64(f, k, base_address);
			break;
		case KVS_UINT32:
			rc = write_uint32(f, k, base_address);
			break;
		case KVS_UINT16:
			rc = write_uint16(f, k, base_address);
			break;
		case KVS_UINT8:
			rc = write_uint8(f, k, base_address);
			break;
		case KVS_DOUBLE:
			rc = write_double(f, k, base_address);
			break;
		case KVS_FLOAT:
			rc = write_float(f, k, base_address);
			break;
		default:
			fprintf(stderr, "%s:%d: unknown key type '%c' for key '%s'\n",
				__func__, __LINE__, k->type, k->key);
			rc = -1;
			break;
		}
		if (rc)
			errs++;
	}
	return errs;
}
Beispiel #17
0
		void write_address(address const& a, OutIt&& out)
		{
#if TORRENT_USE_IPV6
			if (a.is_v4())
			{
#endif
				write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
			}
			else if (a.is_v6())
			{
				for (auto b : a.to_v6().to_bytes())
					write_uint8(b, out);
			}
#endif
		}
Beispiel #18
0
int test_enc () {
  char buf[1024];
  char *buf_ptr = (char *) &buf;
  char *res_enc = NULL;
  char *res_dec = NULL;

  uint8_t v8;
  res_enc = write_uint8(buf_ptr, 42);
  res_dec = read_uint8(buf_ptr, &v8);
  assert(buf_ptr - res_dec == buf_ptr - res_enc);
  assert(v8 == 42);

  uint16_t v16;
  res_enc = write_uint16(buf_ptr, 4200);
  res_dec = read_uint16(buf_ptr, &v16);
  assert(buf_ptr - res_dec == buf_ptr - res_enc);
  assert(v16 == 4200);

  uint32_t v32;
  res_enc = write_uint32(buf_ptr, 420000);
  res_dec = read_uint32(buf_ptr, &v32);
  assert(buf_ptr - res_dec == buf_ptr - res_enc);
  assert(v32 == 420000);

  int32_t i32;
  res_enc = write_int32(buf_ptr, -420000);
  res_dec = read_int32(buf_ptr, &i32);
  assert(buf_ptr - res_dec == buf_ptr - res_enc);
  assert(i32 == -420000);

  char* str = "hello world";
  uint16_t str_len;
  res_enc = write_string(buf_ptr, str, strlen(str));
  res_dec = read_string(buf_ptr, &str, &str_len);
  assert(buf_ptr - res_dec == buf_ptr - res_enc);
  assert(!strcmp(str, "hello world"));
  assert(strlen(str) == str_len);

  char *tmp = "1234512345";
  res_enc = write_buffer(buf_ptr, tmp, 10);
  assert(res_enc - buf_ptr == 10);
  for (int i = 0; i < 10; i++) assert(*(buf + i) == *(tmp + i));

  return 0;
}
Beispiel #19
0
		void write_address(address const& a, OutIt& out)
		{
#if TORRENT_USE_IPV6
			if (a.is_v4())
			{
#endif
				write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
			}
			else if (a.is_v6())
			{
				typedef address_v6::bytes_type bytes_t;
				bytes_t bytes = a.to_v6().to_bytes();
				for (bytes_t::iterator i = bytes.begin()
					, end(bytes.end()); i != end; ++i)
					write_uint8(*i, out);
			}
#endif
		}
Beispiel #20
0
int main(int argc, char* argv[])
{
	uint8_t result, expected_result;
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

	uint8_t idx;
	for(idx = 0; idx < ORDER; idx++)
	{
		uint8_t val = rand();
		expected_result = 3*val;
		write_uint8("in_data",val);
		result = read_uint8("out_data");
		fprintf(stdout,"Result = %x, expected = %x.\n", result,expected_result);
		
	}

	return(0);
}
Beispiel #21
0
int main(void)
{
    BYTE init[16] = {
	0, 1, 2, 3,
	4, 5, 6, 7,
	8, 9, 10, 11,
	12, 13, 14, 15
    };

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(Daemon);
	PTHREAD_CREATE(Daemon);
#endif

    sendConstants();

    int i, run;
    long long t1[10], t2[10];

    for (run = 0; run < 10; run++) {
	fprintf(stderr," run %d.\n", run);
	for (i = 0; i < 16; i++) {
	    write_uint8("input_block_pipe", init[i]);
	    fprintf(stderr," wrote %x \n", init[i]);
	}

	for (i = 0; i < 16; i++) {
		uint8_t rV = read_uint8("output_block_pipe");
		fprintf(stderr," read-back %x \n", rV);
	}
    }

#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(Daemon);
#endif
    return 0;
}
Beispiel #22
0
int start(void)
#endif
{
  int i;
  uint32_t apl;
  float ong;
  uint64_t apl64;
  uint16_t apl16;
  uint8_t apl8;
  void* ptr;
  double ong64;
  
  for (i = 0; i < 10; ++i) {
    apl64 = read_uint64("apples64");
    #ifdef RUN
    fprintf(stderr, "\n(%d.a) got a 64 bit apple: %llu..", i, apl64);
    #endif
    
    ong64 = (double)apl64;
    write_float64("oranges64", ong64);
    #ifdef RUN
    fprintf(stderr, "\nsent a (double) orange: %le.", ong64);
    #endif

    apl = read_uint32("apples32");
    #ifdef RUN
    fprintf(stderr, "\n(%d.b) got a 32-bit apple: %d.", i, apl);
    #endif
    
    ong = (float)apl;
    write_float32("oranges32", ong);
    #ifdef RUN
    fprintf(stderr, "\nsent a (float) orange: %f.", ong);
    #endif

    apl16 = read_uint16("apples16");
    #ifdef RUN
    fprintf(stderr, "\n(%d.c) got a 16-bit apple: %d.", i, apl16);
    #endif
    
    apl8 = (uint8_t)apl;
    write_uint8("oranges8", apl8);
    #ifdef RUN
    fprintf(stderr, "\nsent an 8-bit orange: %d.", apl8);
    #endif

    ptr = read_pointer("apples32");
    #ifdef RUN
    fprintf(stderr, "\n(%d.d) got a pointer apple: %d.", i, (unsigned int) ptr);
    #endif
    
    write_pointer("oranges32", ptr);
    #ifdef RUN
    fprintf(stderr, "\nsent a pointer orange: %d.", (unsigned int) ptr);
    #endif
  }

  #ifdef RUN
  fprintf(stderr, "\n");
  #endif
  return 0;
}
Beispiel #23
0
void 
Squeezer_file_header_t::write_to_file(FILE * out) const
{
    write_uint8(out, file_type_mark[0]);
    write_uint8(out, file_type_mark[1]);
    write_uint8(out, file_type_mark[2]);
    write_uint8(out, file_type_mark[3]);

    write_double(out, floating_point_check);

    write_uint16(out, date_year);
    write_uint8(out, date_month);
    write_uint8(out, date_day);

    write_uint8(out, time_hour);
    write_uint8(out, time_minute);
    write_uint8(out, time_second);

    write_uint8(out, radiometer.horn);
    write_uint8(out, radiometer.arm);
    write_uint16(out, od);
    write_double(out, first_obt);
    write_double(out, last_obt);
    write_double(out, first_scet_in_ms);
    write_double(out, last_scet_in_ms);
    write_uint32(out, number_of_chunks);
}
Beispiel #24
0
	void fwriter::write_binstring(const std::string & value)
	{
		assert(value.length() < 256);
		write_uint8((uint8_t)value.length());
		write(value);
	}
Beispiel #25
0
static void writetag(ios_t *s, void *v)
{
    write_uint8(s, (uint8_t)(ptrint_t)ptrhash_get(&ser_tag, v));
}
Beispiel #26
0
static void write_uint16(ios_t *s, uint16_t i)
{
    write_uint8(s, i       & 0xff);
    write_uint8(s, (i>> 8) & 0xff);
}
Beispiel #27
0
void dispatcher()
{
	while(1)
	{
		// start reading the vectors 
		int vec_id, vec_index;
		int Ecount = 0;
		int chunk_id = 0;
		int I0=0, I1=0, I2=0, I3=0;
		for(vec_id = 0; vec_id < NUM_VECS; vec_id++)
		{
			for(vec_index = 0; vec_index < VEC_SIZE; vec_index++)
			{
				float val = read_float32("input_data_pipe");
				if(Ecount == CHUNK_SIZE)
				{
					chunk_id++;
					Ecount = 0;
				}

#ifdef SW
				fprintf(stderr,"Read vector %d, index %d, val=%f, chunk-id %d.\n", vec_id, vec_index, val, chunk_id);
#endif
				switch(chunk_id)
				{
					case 0:  
						X0[I0] = val; I0++; break;
					case 1:
						X1[I1] = val; I1++; break;
					case 2:
						X2[I2] = val; I2++; break;
					case 3:
						X3[I3] = val; I3++; break;
					default:
						break;

				}
				Ecount++;
			}
		}

		write_uint8("start_dc_00",1);
		write_uint8("start_dc_01",1);
		write_uint8("start_dc_02",1);
		write_uint8("start_dc_03",1);
		write_uint8("start_dc_11",1);
		write_uint8("start_dc_12",1);
		write_uint8("start_dc_13",1);
		write_uint8("start_dc_22",1);
		write_uint8("start_dc_23",1);
		write_uint8("start_dc_33",1);

		uint32_t r00 = read_uint32("result_dc_00");
		uint32_t r01 = read_uint32("result_dc_01");
		uint32_t r02 = read_uint32("result_dc_02");
		uint32_t r03 = read_uint32("result_dc_03");
		uint32_t r11 = read_uint32("result_dc_11");
		uint32_t r12 = read_uint32("result_dc_12");
		uint32_t r13 = read_uint32("result_dc_13");
		uint32_t r22 = read_uint32("result_dc_22");
		uint32_t r23 = read_uint32("result_dc_23");
		uint32_t r33 = read_uint32("result_dc_33");

		uint32_t result =( ((r00 + r01) + (r02 + r03))) + (((r11 + r12) + r13) + (r22 + r23) + r33);
		write_uint32("final_result_pipe",result);
	}
}
Beispiel #28
0
static void jl_serialize_value_(ios_t *s, jl_value_t *v)
{
    if (v == NULL) {
        write_uint8(s, Null_tag);
        return;
    }

    void **bp = ptrhash_bp(&ser_tag, v);
    if (*bp != HT_NOTFOUND) {
        write_as_tag(s, (uint8_t)(ptrint_t)*bp);
        return;
    }

    if (tree_literal_values) {
        // compressing tree
        if (!is_ast_node(v)) {
            writetag(s, (jl_value_t*)LiteralVal_tag);
            write_uint16(s, literal_val_id(v));
            return;
        }
    }
    else {
        bp = ptrhash_bp(&backref_table, v);
        if (*bp != HT_NOTFOUND) {
            write_uint8(s, BackRef_tag);
            write_int32(s, (ptrint_t)*bp);
            return;
        }
        ptrhash_put(&backref_table, v, (void*)(ptrint_t)ios_pos(s));
    }

    size_t i;
    if (jl_is_tuple(v)) {
        size_t l = ((jl_tuple_t*)v)->length;
        if (l <= 255) {
            writetag(s, jl_tuple_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongTuple_tag);
            write_int32(s, l);
        }
        for(i=0; i < l; i++) {
            jl_serialize_value(s, jl_tupleref(v, i));
        }
    }
    else if (jl_is_symbol(v)) {
        size_t l = strlen(((jl_sym_t*)v)->name);
        if (l <= 255) {
            writetag(s, jl_symbol_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongSymbol_tag);
            write_int32(s, l);
        }
        ios_write(s, ((jl_sym_t*)v)->name, l);
    }
    else if (jl_is_array(v)) {
        jl_array_t *ar = (jl_array_t*)v;
        writetag(s, (jl_value_t*)jl_array_type);
        jl_serialize_value(s, ar->type);
        jl_value_t *elty = jl_tparam0(ar->type);
        for (i=0; i < ar->ndims; i++)
            jl_serialize_value(s, jl_box_long(jl_array_dim(ar,i)));
        if (jl_is_bits_type(elty)) {
            size_t tot = ar->length * ar->elsize;
            ios_write(s, ar->data, tot);
        }
        else {
            for(i=0; i < ar->length; i++) {
                jl_serialize_value(s, jl_cellref(v, i));
            }
        }
    }
    else if (jl_is_expr(v)) {
        jl_expr_t *e = (jl_expr_t*)v;
        size_t l = e->args->length;
        if (l <= 255) {
            writetag(s, jl_expr_type);
            write_uint8(s, (uint8_t)l);
        }
        else {
            writetag(s, (jl_value_t*)LongExpr_tag);
            write_int32(s, l);
        }
        jl_serialize_value(s, e->head);
        jl_serialize_value(s, e->etype);
        for(i=0; i < l; i++) {
            jl_serialize_value(s, jl_exprarg(e, i));
        }
    }
    else if (jl_is_some_tag_type(v)) {
        jl_serialize_tag_type(s, v);
    }
    else if (jl_is_typevar(v)) {
        writetag(s, jl_tvar_type);
        jl_serialize_value(s, ((jl_tvar_t*)v)->name);
        jl_serialize_value(s, ((jl_tvar_t*)v)->lb);
        jl_serialize_value(s, ((jl_tvar_t*)v)->ub);
        write_int8(s, ((jl_tvar_t*)v)->bound);
    }
    else if (jl_is_function(v)) {
        writetag(s, jl_func_kind);
        jl_serialize_value(s, v->type);
        jl_function_t *f = (jl_function_t*)v;
        jl_serialize_value(s, (jl_value_t*)f->linfo);
        jl_serialize_value(s, f->env);
        if (f->linfo && f->linfo->ast &&
            (jl_is_expr(f->linfo->ast) || jl_is_tuple(f->linfo->ast)) &&
            f->fptr != &jl_trampoline) {
            write_int32(s, 0);
        }
        else {
            jl_serialize_fptr(s, f->fptr);
        }
    }
    else if (jl_is_lambda_info(v)) {
        writetag(s, jl_lambda_info_type);
        jl_lambda_info_t *li = (jl_lambda_info_t*)v;
        jl_serialize_value(s, li->ast);
        jl_serialize_value(s, (jl_value_t*)li->sparams);
        // don't save cached type info for code in the Base module, because
        // it might reference types in the old System module.
        if (li->module == jl_base_module)
            jl_serialize_value(s, (jl_value_t*)jl_null);
        else
            jl_serialize_value(s, (jl_value_t*)li->tfunc);
        jl_serialize_value(s, (jl_value_t*)li->name);
        jl_serialize_value(s, (jl_value_t*)li->specTypes);
        jl_serialize_value(s, (jl_value_t*)li->specializations);
        jl_serialize_value(s, (jl_value_t*)li->inferred);
        jl_serialize_value(s, (jl_value_t*)li->file);
        jl_serialize_value(s, (jl_value_t*)li->line);
        jl_serialize_value(s, (jl_value_t*)li->module);
    }
    else if (jl_typeis(v, jl_module_type)) {
        jl_serialize_module(s, (jl_module_t*)v);
    }
    else if (jl_typeis(v, jl_methtable_type)) {
        writetag(s, jl_methtable_type);
        jl_methtable_t *mt = (jl_methtable_t*)v;
        jl_serialize_methlist(s, mt->defs);
        jl_serialize_methlist(s, mt->cache);
        jl_serialize_value(s, mt->cache_1arg);
        write_int32(s, mt->max_args);
    }
    else if (jl_typeis(v, jl_task_type)) {
        jl_error("Task cannot be serialized");
    }
    else {
        jl_value_t *t = (jl_value_t*)jl_typeof(v);
        if (jl_is_bits_type(t)) {
            void *data = jl_bits_data(v);
            if (t == (jl_value_t*)jl_int64_type &&
                *(int64_t*)data >= S32_MIN && *(int64_t*)data <= S32_MAX) {
                writetag(s, (jl_value_t*)SmallInt64_tag);
                write_int32(s, (int32_t)*(int64_t*)data);
            }
            else {
                int nb = ((jl_bits_type_t*)t)->nbits;
                writetag(s, jl_bits_kind);
                jl_serialize_value(s, t);
                ios_write(s, data, nb/8);
            }
        }
        else if (jl_is_struct_type(t)) {
            writetag(s, jl_struct_kind);
            jl_serialize_value(s, t);
            size_t nf = ((jl_struct_type_t*)t)->names->length;
            size_t i;
            for(i=0; i < nf; i++) {
                jl_value_t *fld = ((jl_value_t**)v)[i+1];
                jl_serialize_value(s, fld);
            }
            if (t == jl_idtable_type) {
                jl_cell_1d_push(idtable_list, v);
            }
        }
        else {
            assert(0);
        }
    }
}
Beispiel #29
0
int main(int argc, char* argv[])
{
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

        int i;
	int32_t data;
	uint8_t op;

	if(argc > 11) 
	{
		fprintf(stderr,"Error: this toy accepts a maximum of 10 arguments\n");
		return(1);
	}

#ifdef SW

	// in the "software" case, we start a pipe-handler
	// to manage the pipes..  Earlier, we were using named
	// pipes, which were very flaky and difficult to debug.
	// the pipeHandler generates a log file (pipeHandler.log)
	// which is very useful for figuring out what happened.
	// one can also use gdb to trace activity.
	pthread_t phandler_t;
	pthread_create(&phandler_t,NULL,&pipeHandler__,NULL);

	usleep(100);
	
	// register FIFO
	register_pipe("in_data",10,32,0);

	// register FIFO..
	register_pipe("out_data",10,32,0);

	// stack 
	register_pipe("eval_stack",10,32,1);

	// operation
	register_pipe("in_op",10,8,0);

	pthread_t acc_t;
	pthread_create(&acc_t,NULL,&accumulate_,NULL);
#endif




	for(i=1; i < argc; i++)
	{
		if(strcmp(argv[i],"+") == 0)
		{
			write_uint8("in_op",_ADD);
			write_uint32("in_data",0);
		}
		else if(strcmp(argv[i],"-") == 0)
		{
			write_uint8("in_op",_SUB);
			write_uint32("in_data",0);
		}
		else if(strcmp(argv[i],"X") == 0)
		{
			write_uint8("in_op",_MUL);
			write_uint32("in_data",0);
		}
		else if(strcmp(argv[i],".") == 0)
		{
			write_uint8("in_op",_POP);
			write_uint32("in_data",0);
		}
		else
		{
			data = atoi(argv[i]);
			write_uint8("in_op",_PUSH);
			write_uint32("in_data",data);
		}
	}

	data = read_uint32("out_data");
	fprintf(stdout,"result: %d\n", data);

#ifdef SW
	pthread_cancel(acc_t);
	killPipeHandler();
#endif
}
Beispiel #30
0
int save_game (char* s, char* d)
{
	SINT16 i;
	struct image_stack_element* ptr = image_stack;
	FILE* f = fopen (s, "wb");

	if(!f)
		return err_BadFileOpen;

	write_bytes (f, strSig, 8);
	write_string (f, d);

	write_uint8 (f, (UINT8)SAVEGAME_VERSION);
	write_uint8 (f, (UINT8)game.state);
	/* game.name */
	write_string (f, game.id);
	/* game.crc */

	for (i = 0; i < MAX_FLAGS; i++)
		write_uint8 (f, game.flags[i]);
	for (i = 0; i < MAX_VARS; i++)
		write_uint8 (f, game.vars[i]);

	write_sint16 (f, (SINT8)game.horizon);
	write_sint16 (f, (SINT16)game.line_status);
	write_sint16 (f, (SINT16)game.line_user_input);
	write_sint16 (f, (SINT16)game.line_min_print);
	/* game.cursor_pos */
	/* game.input_buffer */
	/* game.echo_buffer */
	/* game.keypress */
	write_sint16 (f, (SINT16)game.input_mode);
	write_sint16 (f, (SINT16)game.lognum);

	write_sint16 (f, (SINT16)game.player_control);
	write_sint16 (f, (SINT16)game.quit_prog_now);
	write_sint16 (f, (SINT16)game.status_line);
	write_sint16 (f, (SINT16)game.clock_enabled);
	write_sint16 (f, (SINT16)game.exit_all_logics);
	write_sint16 (f, (SINT16)game.picture_shown);
	write_sint16 (f, (SINT16)game.has_prompt);
	write_sint16 (f, (SINT16)game.game_flags);

	/* Reversed to keep compatibility with old savegames */
	write_sint16 (f, (SINT16)!game.input_enabled);

	for (i = 0; i < _HEIGHT; i++)
		write_uint8 (f, game.pri_table[i]);

	/* game.msg_box_ticks */
	/* game.block */
	/* game.window */
	/* game.has_window */

	write_sint16 (f, (SINT16)game.gfx_mode);
	write_uint8 (f, game.cursor_char);
	write_sint16 (f, (SINT16)game.color_fg);
	write_sint16 (f, (SINT16)game.color_bg);

	/* game.hires (#ifdef USE_HIRES) */
	/* game.sbuf */
	/* game.ego_words */
	/* game.num_ego_words */

	write_sint16 (f, (SINT16)game.num_objects);
	for (i = 0; i < (SINT16)game.num_objects; i++)
		write_sint16 (f, (SINT16)object_get_location(i));

	/* game.ev_keyp */
	for (i = 0; i < MAX_STRINGS; i++)
		write_string (f, game.strings[i]);

	/* record info about loaded resources */
	for (i = 0; i < MAX_DIRS; i++) {
		write_uint8 (f, game.dir_logic[i].flags);
		write_sint16 (f, (SINT16)game.logics[i].sIP);
		write_sint16 (f, (SINT16)game.logics[i].cIP);
	}
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_pic[i].flags);
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_view[i].flags);
	for (i = 0; i < MAX_DIRS; i++)
		write_uint8(f, game.dir_sound[i].flags);

	/* game.pictures */
	/* game.logics */
	/* game.views */
	/* game.sounds */

	for(i = 0; i < MAX_VIEWTABLE; i++) {
		struct vt_entry* v = &game.view_table[i];

		write_uint8(f, v->step_time);
		write_uint8(f, v->step_time_count);
		write_uint8(f, v->entry);
		write_sint16(f, v->x_pos);
		write_sint16(f, v->y_pos);
		write_uint8(f, v->current_view);

		/* v->view_data */

		write_uint8(f, v->current_loop);
		write_uint8(f, v->num_loops);

		/* v->loop_data */

		write_uint8(f, v->current_cel);
		write_uint8(f, v->num_cels);

		/* v->cel_data */
		/* v->cel_data_2 */
		
		write_sint16(f, v->x_pos2);
		write_sint16(f, v->y_pos2);

		/* v->s */

		write_sint16(f, v->x_size);
		write_sint16(f, v->y_size);
		write_uint8(f, v->step_size);
		write_uint8(f, v->cycle_time);
		write_uint8(f, v->cycle_time_count);
		write_uint8(f, v->direction);

		write_uint8(f, v->motion);
		write_uint8(f, v->cycle);
		write_uint8(f, v->priority);

		write_uint16(f, v->flags);
		
		write_uint8(f, v->parm1);
		write_uint8(f, v->parm2);
		write_uint8(f, v->parm3);
		write_uint8(f, v->parm4);
	}

	/* Save image stack */
	
	for (i = 0; i < image_stack_pointer; i++) {
		ptr = &image_stack[i];
		write_uint8 (f, ptr->type);
		write_sint16 (f, ptr->parm1);
		write_sint16 (f, ptr->parm2);
		write_sint16 (f, ptr->parm3);
		write_sint16 (f, ptr->parm4);
		write_sint16 (f, ptr->parm5);
		write_sint16 (f, ptr->parm6);
		write_sint16 (f, ptr->parm7);
	}
	write_uint8(f, 0);

	fclose(f);

	return err_OK;
}