Example #1
0
SYMBOL *gen_mp_virtual_thunk(SYMBOL *vsp)
{

        QUAD *oi = intermed_head, *ot = intermed_tail;
        LIST *v = mpthunklist;
        SYMBOL *sp;
        IMODE *ap1,  *ap2;
        char buf[256];
        while (v)
        {
            sp = (SYMBOL*)v->data;
            if (sp->value.i == vsp->value.classdata.vtabindex)
                if (isstructured(vsp->tp->btp) == isstructured(sp->tp->btp))
                    return sp;
            v = v->link;
        }
        intermed_head = intermed_tail = NULL;
        blockMax = 0;
        blockCount = tempCount = 0;
        exitBlock = 0;
        IncGlobalFlag();
        sp = Alloc(sizeof(SYMBOL));
        sp->storage_class = sc_static;
        sp->tp = vsp->tp;
        sp->value.i = vsp->value.classdata.vtabindex;
        //sprintf(buf, "@$mpt$%d$%d", sp->value.i, isstructured(sp->tp->btp));
        sp->name = sp->decoratedName = litlate(buf);
        sp->errname = sp->decoratedName;
        sp->staticlabel = FALSE;
        sp->gennedvirtfunc = TRUE;
        v = (LIST *)Alloc(sizeof(LIST));
        v->data = sp;
        v->link = mpthunklist;
        mpthunklist = v;
        DecGlobalFlag();

        gen_virtual(sp, FALSE);
        addblock(i_goto);
        gen_icode(i_substack, NULL, ap2 = tempreg(ISZ_ADDR, 0), NULL);
        gen_icode(i_add, ap2, ap2 , make_immed(ISZ_NONE, isstructured(sp->tp->btp) ? ISZ_ADDR * 2 : ISZ_ADDR));
        ap1 = indnode(ap2, ISZ_ADDR);
        gen_icode(i_assn, ap2 = tempreg(ISZ_ADDR, 0), ap1, 0);
        if (sp->value.classdata.baseofs)
            gen_icode(i_add, ap2, ap2, make_immed(ISZ_NONE, sp->value.classdata.baseofs));
        ap1 = indnode(ap2, ISZ_ADDR);
        gen_icode(i_assn, ap2 = tempreg(ISZ_ADDR, 0), ap1, 0);
        gen_icode(i_add, ap2, ap2, make_immed(ISZ_NONE, sp->value.i));
        ap1 = indnode(ap2, ISZ_ADDR);
        gen_icode(i_directbranch, 0, ap1, 0);
        addblock(i_ret);
        optimize();
        rewrite_icode(); /* Translate to machine code & dump */
        if (chosenAssembler->gen->post_function_gen)
            chosenAssembler->gen->post_function_gen(intermed_head);
        gen_endvirtual(sp);
        intermed_head = oi;
        intermed_tail = ot;
        return sp;
}
Example #2
0
/*
 * NAME:	shift()
 * DESCRIPTION:	shift a line left or right
 */
static void shift(const char *text)
{
    cmdbuf *cb;
    int idx;

    cb = ccb;

    /* first determine the number of leading spaces */
    idx = 0;
    while (*text == ' ' || *text == HT) {
	if (*text++ == ' ') {
	    idx++;
	} else {
	    idx = (idx + 8) & ~7;
	}
    }

    if (*text == '\0') {
	/* don't shift lines with ws only */
	addblock(cb, text);
	cb->lineno++;
    } else {
	idx += cb->shift;
	if (idx < MAX_LINE_SIZE) {
	    char buffer[MAX_LINE_SIZE];
	    char *p;

	    p = buffer;
	    /* fill with leading ws */
	    while (idx >= 8) {
		*p++ = HT;
		idx -= 8;
	    }
	    while (idx > 0) {
		*p++ = ' ';
		--idx;
	    }
	    if (p - buffer + strlen(text) < MAX_LINE_SIZE) {
		strcpy(p, text);
		addblock(cb, buffer);
		cb->lineno++;
		return;
	    }
	}

	/* Error: line too long. Finish block of lines already shifted. */
	cb->last = cb->lineno;
	endblock(cb);
	error("Result of shift would be too long");
    }
}
Example #3
0
int eIOBuffer::fromfile(int fd, int len)
{
	int re=0;
	while (len)
	{
		int tc=len;
		int r=0;
		if (buffer.empty() || (allocationsize == buffer.back().len))
			addblock();
		if (tc > allocationsize-buffer.back().len)
			tc=allocationsize-buffer.back().len;
		r=::read(fd, buffer.back().data+buffer.back().len, tc);
		buffer.back().len+=r;
		if (r < 0)
		{
			if (errno != EWOULDBLOCK && errno != EBUSY && errno != EINTR)
				eDebug("couldn't read: %m");
		}
		else
		{
			len-=r;
			re+=r;
			if (r != tc)
				break;
		}
	}
	return re;
}
Example #4
0
int main()
{
	// block : current block, block_prev: previous block header
	block_type block;
	block_header block_prev;
	//va chercher le prvious block header dans la db 
	export_bloc("../database",&block_prev); 
	//rempli le block avec les info du header precedent
	block.version=block_prev.version;

	// test pour le 2eme bloc  
//	block.timestamp=1231469665;
// 	hash_digest merkl{0x0e,0x3e,0x23,0x57,0xe8,0x06,0xb6,0xcd,0xb1,0xf7,0x0b,0x54,0xc3,0xa3,0xa1,0x7b,0x67,0x14,0xee,0x1f,0x0e,0x68,0xbe,0xbb,0x44,0xa7,0x4b,0x1e,0xfd,0x51,0x20,0x98};
//	block.nonce=2573394688;
//	block.merkle=merkl;

	block.previous_block_hash = calcul_hash(block_prev);
	// Ici calcul_hash va etre la fonction couteuse en temps de calcul
	block.merkle=generate_sha256_hash(uncast_type(block.previous_block_hash));
	block.timestamp=block_prev.timestamp;
	block.bits=block_prev.bits;
	block.nonce=0;
	// une fois toutes les info prisent, on peut inserer le block dans la db
	return addblock("../database", block);
}
Example #5
0
int main(int argc, char* argv[])
{
    diy::mpi::environment     env(argc, argv);         // diy equivalent of MPI_Init
    diy::mpi::communicator    world;                   // diy equivalent of MPI communicator

    int                       size    = 8;             // total number of MPI processes
    int                       nblocks = 32;            // total number of blocks in global domain
    diy::ContiguousAssigner   assigner(size, nblocks);

    Bounds domain;                                     // global data size
    domain.min[0] = domain.min[1] = domain.min[2] = 0;
    domain.max[0] = domain.max[1] = domain.max[2] = 255;

    int rank = world.rank();                           // MPI rank of this process
    std::cout << "Rank " << rank << ":" << std::endl;
    diy::Master master(world,
                       1,                              // one thread
                       -1,                             // all blocks in memory
                       &Block::create,
                       &Block::destroy);
    AddBlock     addblock(master);                     // object for adding new blocks to master

    // share_face is an n-dim (size 3 in this example) vector of bools
    // indicating whether faces are shared in each dimension
    // uninitialized values default to false
    diy::RegularDecomposer<Bounds>::BoolVector          share_face;
    share_face.push_back(true);

    // wrap is an n-dim (size 3 in this example) vector of bools
    // indicating whether boundary conditions are periodic in each dimension
    // uninitialized values default to false
    diy::RegularDecomposer<Bounds>::BoolVector          wrap;
    wrap.push_back(true);
    wrap.push_back(true);

    // ghosts is an n-dim (size 3 in this example) vector of ints
    // indicating number of ghost cells per side in each dimension
    // uninitialized values default to 0
    diy::RegularDecomposer<Bounds>::CoordinateVector    ghosts;
    ghosts.push_back(1); ghosts.push_back(2);

    // either create the regular decomposer and call its decompose function
    // (having the decomposer available is useful for its other member functions
    diy::RegularDecomposer<Bounds> decomposer(3,
                                              domain,
                                              assigner,
                                              share_face,
                                              wrap,
                                              ghosts);
    decomposer.decompose(rank, addblock);

    // or combine the two lines above into the following helper function
    // but the decomposer gets destroyed afterwards
    // diy::decompose(3, rank, domain, assigner, addblock, share_face, wrap, ghosts);

    // display the decomposition
    master.foreach(&Block::show_link);
}
Example #6
0
SYMBOL *gen_vsn_virtual_thunk(SYMBOL *func, int ofs)
{
        QUAD *oi = intermed_head, *ot = intermed_tail;		
        SYMBOL *sp;
        IMODE *ap1,  *ap2;
        char buf[256];
        //sprintf(buf, "@$vsn%s$%d", func->decoratedName, ofs);
        sp = search(buf, gsyms);
        if (sp)
            return sp;
        intermed_head = intermed_tail = NULL;
        blockMax = 0;
        blockCount = tempCount = 0;
        exitBlock = 0;
        IncGlobalFlag();
        sp = Alloc(sizeof(SYMBOL));
        sp->storage_class = sc_static;
        sp->value.i = ofs;
        sp->name = sp->decoratedName = litlate(buf);
        sp->errname = sp->decoratedName;
        sp->staticlabel = FALSE;
        sp->tp = func->tp;
        sp->gennedvirtfunc = TRUE;
        insert(sp, gsyms);
        DecGlobalFlag();
        gen_virtual(sp, FALSE);
        addblock(i_goto);
        gen_icode(i_substack, NULL, ap2 = tempreg(ISZ_ADDR, 0), NULL );
        gen_icode(i_add, ap1 = tempreg(ISZ_ADDR, 0), ap2, make_immed(ISZ_NONE, getSize(bt_pointer)));
        ap1 = indnode(ap1, ISZ_ADDR);
        gen_icode(i_add, ap1, ap1 , make_immed(ISZ_NONE, - ofs));
        ap1 = make_imaddress(varNode(en_napccon, func), ISZ_ADDR);
        gen_icode(i_directbranch, 0, ap1, 0);
        addblock(i_ret);
        optimize();
        rewrite_icode(); /* Translate to machine code & dump */
        if (chosenAssembler->gen->post_function_gen)
            chosenAssembler->gen->post_function_gen(intermed_head);
        gen_endvirtual(sp);
        intermed_head = oi;
        intermed_tail = ot;
        return sp;
}
Example #7
0
void eIOBuffer::write(const void *source, int len)
{
	const __u8 *src=(const __u8*)source;
	while (len)
	{
		int tc=len;
		if (buffer.empty() || (allocationsize == buffer.back().len))
			addblock();
		if (tc > allocationsize-buffer.back().len)
			tc=allocationsize-buffer.back().len;
		memcpy(buffer.back().data+buffer.back().len, src, tc);
		src+=tc;
		buffer.back().len+=tc;
		len-=tc;
	}
}
Example #8
0
/*
 * NAME:	cmdbuf->join()
 * DESCRIPTION:	join a range of lines in the edit buffer
 */
int cb_join(cmdbuf *cb)
{
    char buf[MAX_LINE_SIZE + 1];
    Int *m;

    if (cb->edbuf->lines == 0) {
	error("No lines in buffer");
    }
    if (cb->first < 0) {
	cb->first = cb->cthis;
    }
    if (cb->last < 0) {
	cb->last = (cb->first == cb->edbuf->lines) ? cb->first : cb->first + 1;
    }

    cb_do(cb, cb->first);

    cb->cthis = cb->othis = cb->first;
    buf[0] = '\0';
    cb->buffer = buf;
    cb->buflen = 0;
    eb_range(cb->edbuf, cb->first, cb->last, join, FALSE);

    /* erase marks for joined lines */
    for (m = cb->mark; m < &cb->mark[26]; m++) {
	if (*m > cb->first && *m <= cb->last) {
	    *m = 0;
	}
    }

    cb->flags |= CB_CHANGE;
    startblock(cb);
    addblock(cb, buf);
    endblock(cb);

    return RET_FLAGS;
}
Example #9
0
void genfunc(SYMBOL *funcsp)
/*
 *      generate a function body and dump the icode
 */
{
    IMODE *allocaAP = NULL;
    SYMBOL *oldCurrentFunc;
    EXPRESSION *funcexp = varNode(en_global, funcsp);
    if (total_errors)
        return;
//	//printf("%s\n", funcsp->name);
    contlab = breaklab =  - 1;
    structret_imode = 0 ;
    tempCount = 0;
    blockCount = 0;
    blockMax = 0;
    exitBlock = 0;
    oldCurrentFunc = theCurrentFunc;
    theCurrentFunc = funcsp;
    iexpr_func_init();
    /*      firstlabel = nextLabel;*/
    cseg();
    gen_line(funcsp->linedata);
    gen_func(funcexp, 1);
    /* in C99 inlines can clash if declared 'extern' in multiple modules */
    /* in C++ we introduce virtual functions that get coalesced at link time */
    if (cparams.prm_cplusplus && funcsp->linkage == lk_inline)
        gen_virtual(funcsp, FALSE);
    else
    {
        if (funcsp->storage_class == sc_global)
                globaldef(funcsp);
        else
            localdef(funcsp);
        gen_strlab(funcsp); /* name of function */
    }
    addblock( - 1);
       if (funcsp->linkage == lk_interrupt || funcsp->linkage == lk_fault) {
        gen_icode(i_pushcontext, 0,0,0);
/*		if (funcsp->loadds) */
/*	        gen_icode(i_loadcontext, 0,0,0); */
    }
    gen_icode(i_prologue,0,0,0);
    gen_label(startlab);
/*    if (funcsp->loadds && funcsp->farproc) */
/*	        gen_icode(i_loadcontext, 0,0,0); */
    AllocateLocalContext(NULL, funcsp);
    if (funcsp->allocaUsed)
    {
            EXPRESSION *allocaExp = varNode(en_auto, anonymousVar(sc_auto, &stdpointer));
            allocaAP = gen_expr(funcsp, allocaExp, 0, ISZ_ADDR);
            gen_icode(i_savestack, 0, allocaAP, 0);
    }
    /* Generate the icode */
    /* LCSE is done while code is generated */
    genstmt(funcsp->inlineFunc.stmt->lower, funcsp);
    if (funcsp->inlineFunc.stmt->blockTail)
    {
        gen_icode(i_functailstart, 0, 0, 0);
        genstmt(funcsp->inlineFunc.stmt->blockTail, funcsp);
        gen_icode(i_functailend, 0, 0, 0);
    }
    genreturn(0, funcsp, 1, 0, allocaAP);
    gen_func(funcexp, 0);
    tFree();
    InsertParameterThunks(funcsp, blockArray[1]);
    optimize(funcsp);
    FreeLocalContext(NULL, funcsp);
        
    AllocateStackSpace(funcsp);
    FillInPrologue(intermed_head, funcsp);
    /* Code gen from icode */
    rewrite_icode(); /* Translate to machine code & dump */
    if (chosenAssembler->gen->post_function_gen)
        chosenAssembler->gen->post_function_gen(funcsp, intermed_head);
    if (cparams.prm_cplusplus && funcsp->linkage == lk_inline)
        gen_endvirtual(funcsp);
    intermed_head = NULL;
    dag_rundown();
    oFree();
    theCurrentFunc = oldCurrentFunc;
    if (blockCount > maxBlocks)
        maxBlocks = blockCount;
    if (tempCount > maxTemps)
        maxTemps = tempCount;
}
Example #10
0
void
bufinsert(Buffer *b, uint q0, Rune *s, uint n)
{
	uint i, m, t, off;

	if(q0 > b->nc)
		panic("internal error: bufinsert");

	while(n > 0){
		setcache(b, q0);
		off = q0-b->cq;
		if(b->cnc+n <= Maxblock){
			/* Everything fits in one block. */
			t = b->cnc+n;
			m = n;
			if(b->bl == nil){	/* allocate */
				if(b->cnc != 0)
					panic("internal error: bufinsert1 cnc!=0");
				addblock(b, 0, t);
				b->cbi = 0;
			}
			sizecache(b, t);
			runemove(b->c+off+m, b->c+off, b->cnc-off);
			runemove(b->c+off, s, m);
			b->cnc = t;
			goto Tail;
		}
		/*
		 * We must make a new block.  If q0 is at
		 * the very beginning or end of this block,
		 * just make a new block and fill it.
		 */
		if(q0==b->cq || q0==b->cq+b->cnc){
			if(b->cdirty)
				flush(b);
			m = min(n, Maxblock);
			if(b->bl == nil){	/* allocate */
				if(b->cnc != 0)
					panic("internal error: bufinsert2 cnc!=0");
				i = 0;
			}else{
				i = b->cbi;
				if(q0 > b->cq)
					i++;
			}
			addblock(b, i, m);
			sizecache(b, m);
			runemove(b->c, s, m);
			b->cq = q0;
			b->cbi = i;
			b->cnc = m;
			goto Tail;
		}
		/*
		 * Split the block; cut off the right side and
		 * let go of it.
		 */
		m = b->cnc-off;
		if(m > 0){
			i = b->cbi+1;
			addblock(b, i, m);
			diskwrite(disk, &b->bl[i], b->c+off, m);
			b->cnc -= m;
		}
		/*
		 * Now at end of block.  Take as much input
		 * as possible and tack it on end of block.
		 */
		m = min(n, Maxblock-b->cnc);
		sizecache(b, b->cnc+m);
		runemove(b->c+b->cnc, s, m);
		b->cnc += m;
  Tail:
		b->nc += m;
		q0 += m;
		s += m;
		n -= m;
		b->cdirty = TRUE;
	}
}
Example #11
0
/*
 * NAME:	subst()
 * DESCRIPTION:	do substitutions in a line. If something is substituted on line
 *		N, and the next substitution happens on line N + 2, line N + 1
 *		is joined in the new block also.
 */
static void subst(const char *text)
{
    char line[MAX_LINE_SIZE];
    cmdbuf *cb;
    int idx, size;
    char *p;
    Int *k, *l;
    Int newlines;
    bool found;

    cb = ccb;

    found = FALSE;
    newlines = 0;
    idx = 0;

    /*
     * Because the write buffer might be flushed, and the text would
     * not remain in memory, use a local copy.
     */
    text = strcpy(line, text);
    while (rx_exec(cb->regexp, text, idx, IGNORECASE(cb->vars)) > 0) {
	if (cb->flags & CB_SKIPPED) {
	    /*
	     * add the previous line, in which nothing was substituted, to
	     * the block. Has to be done here, before the contents of the buffer
	     * are changed.
	     */
	    addblock(cb, cb->buffer);
	    cb->flags &= ~CB_SKIPPED;
	    /*
	     * check if there were newlines in the last substitution. If there
	     * are, marks on the previous line (without substitutions) will
	     * also have to be changed.
	     */
	    if (cb->offset > 0) {
		for (k = cb->mark, l = cb->moffset; k < &cb->mark[26]; k++, l++)
		{
		    if (*k == cb->lineno - 1 && *l == 0) {
			*l = *k + cb->offset;
		    }
		}
	    }
	}
	found = TRUE;
	cb->flags &= ~(CB_UPPER | CB_LOWER | CB_TUPPER | CB_TLOWER);
	size = cb->regexp->start - text - idx;
	if (size > 0) {
	    /* copy first unchanged part of line to buffer */
	    sub(cb, text + idx, size);
	}
	p = cb->replace;
	while (*p != '\0') {
	    switch (*p) {
	    case '&':
		/* insert matching string */
		sub(cb, cb->regexp->start, cb->regexp->size);
		break;

	    case '\\':		/* special substitute characters */
		switch (*++p) {
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		    /* insert subexpression between \( \) */
		    if (cb->regexp->se[*p - '1'].start != (char*) NULL) {
			sub(cb, cb->regexp->se[*p - '1'].start,
			    cb->regexp->se[*p - '1'].size);
			break;
		    }
		    /* if no subexpression, fall though */
		default:
		    sub(cb, p, 1);	/* ignore preceding backslash */
		    break;

		case 'n':
		    cb->buffer[cb->buflen++] = '\0';
		    newlines++;		/* insert newline */
		    break;

		case 'U':
		    /* convert string to uppercase */
		    cb->flags |= CB_UPPER;
		    cb->flags &= ~(CB_LOWER | CB_TUPPER | CB_TLOWER);
		    break;

		case 'L':
		    /* convert string to lowercase */
		    cb->flags |= CB_LOWER;
		    cb->flags &= ~(CB_UPPER | CB_TUPPER | CB_TLOWER);
		    break;

		case 'e':
		case 'E':
		    /* end case conversion */
		    cb->flags &= ~(CB_UPPER | CB_LOWER | CB_TUPPER | CB_TLOWER);
		    break;

		case 'u':
		    /* convert char to uppercase */
		    cb->flags |= CB_TUPPER;
		    cb->flags &= ~CB_TLOWER;
		    break;

		case 'l':
		    /* convert char to lowercase */
		    cb->flags &= ~CB_TUPPER;
		    cb->flags |= CB_TLOWER;
		    break;

		case '\0':	/* sigh */
		    continue;
		}
		break;

	    default:		/* normal char */
		sub(cb, p, 1);
		break;
	    }
	    p++;
	}

	idx = cb->regexp->start + cb->regexp->size - text;
	if (!(cb->flags & CB_GLOBSUBST) || text[idx] == '\0' ||
	    (cb->regexp->size == 0 && text[++idx] == '\0')) {
	    break;
	}
    }

    if (found) {
	if (text[idx] != '\0') {
	    /* concatenate unchanged part of line after found pattern */
	    cb->flags &= ~(CB_UPPER | CB_LOWER | CB_TUPPER | CB_TLOWER);
	    sub(cb, text + idx, strlen(text + idx));
	}
	if (!(cb->flags & CB_CURRENTBLK)) {
	    /* start a new block of lines with substitutions in them */
	    cb->flags |= CB_CHANGE;
	    cb->first = cb->lineno;
	    startblock(cb);
	    cb->flags |= CB_CURRENTBLK;
	}
	/* add this changed line to block */
	cb->buffer[cb->buflen] = '\0';
	if (newlines == 0) {
	    addblock(cb, cb->buffer);
	} else {
	    /*
	     * There were newlines in the substituted string. Add all
	     * lines to the current block, and save the marks in range.
	     */
	    p = cb->buffer;
	    do {
		addblock(cb, p);
		p += strlen(p) + 1;
	    } while (p <= cb->buffer + cb->buflen);

	    for (k = cb->mark, l = cb->moffset; k < &cb->mark[26]; k++, l++) {
		if (*k == cb->lineno && *l == 0) {
		    *l = *k + cb->offset;
		}
	    }
	    cb->offset += newlines;
	}
	cb->buflen = 0;
	cb->last = cb->lineno;
    } else {
	if (cb->flags & CB_SKIPPED) {
	    /* two lines without substitutions now. Finish previous block. */
	    endblock(cb);
	    cb->lineno += cb->offset;
	    cb->offset = 0;
	    cb->flags &= ~(CB_CURRENTBLK | CB_SKIPPED);
	} else if (cb->flags & CB_CURRENTBLK) {
	    /*
	     * no substitution on this line, but there was one on the previous
	     * line. mark this line as skipped, so it can still be added to
	     * the block of changed lines if the next line has substitutions.
	     */
	    strcpy(cb->buffer, text);
	    cb->flags |= CB_SKIPPED;
	}
    }
    cb->lineno++;
}
Example #12
0
/*
 * NAME:	noshift()
 * DESCRIPTION:	add this line to the current block without shifting it
 */
static void noshift(cmdbuf *cb, const char *text)
{
    addblock(cb, text);
    cb->lineno++;
}