Example #1
0
CrossCompiler::Spirv CrossCompiler::hlslToSpirv(std::string hlslText)
{
    auto program = glslang::TProgram();

    auto entryPoints = getEntryPoints(hlslText);
    for (auto& stageEntries : entryPoints)
    {
        auto stage = toEShLanguage(stageEntries.first);
        for (auto name : stageEntries.second)
        {
            addShader(program, hlslText, stage, name);
        }
    }

    if (!program.link(messagesType))
        throw std::exception(program.getInfoLog());

    Spirv spirv;
    if (entryPoints["vs"].size() > 0)
        spirv.vs = getBinary(program, EShLanguage::EShLangVertex);

    if (entryPoints["ps"].size() > 0)
        spirv.ps = getBinary(program, EShLanguage::EShLangFragment);
    return spirv;
}
Example #2
0
File: D.cpp Project: sorcererXW/ACM
int main() {
    int T;
    scanf("%d", &T);
    getchar();
    while (T--) {
        scanf("%s", cipher);
        scanf("%d", &n);
        getchar();
        scanf("%s", key);

        int len = strlen(cipher);

        int binary[10000] = {0};
        int k = 0;
        for (int i = 0; i < len; i++) {
            int t = int(cipher[i]);
            getBinary(t);
            for (int j = 0; j < 8; j++) {
                binary[k] = b[j];
                k++;
            }
        }

        char sCipher[2000];
        for (int l = 0; l < k; l += 6) {

        }
    }
    return 0;
}
Example #3
0
static TOKEN getToken( REWRITE *r, REWRITE_TOKENS **rt, uint_8 **stop )
{
    TOKEN       token;

    if( getBinary( r, rt, stop, (uint_8 *)&token, sizeof( token ) ) )
        return( r->last_token );
    return( token );
}
Example #4
0
std::string Term::getExpression() const {
    std::string expression = getBinary();
    expression.insert(0, _literals_count - expression.length(), '0');

    for (std::vector<size_t>::const_iterator it = _dashes.begin();
         it < _dashes.end(); ++it)
    {
        expression.replace(expression.length() - (*it), 1, "-");
    }

    return expression;
}
void HuffmanCompressor::getHuffmanCode(Node *node, std::string code, std::string &encodedHuffmanTree)
{
  if (node->left == NULL && node->right == NULL) {
    // Leaf node
    encodedHuffmanTree += "1";
    encodedHuffmanTree += getBinary(node->value);
    huffmanCodes[node->value] = code;
  } else {
    // Internal node
    encodedHuffmanTree += "0";
    if (node->left != NULL) 
      getHuffmanCode(node->left, code + "0", encodedHuffmanTree);
    if (node->right != NULL)
      getHuffmanCode(node->right, code + "1", encodedHuffmanTree);
  }
}
Example #6
0
int main (int argc, char *argv[]){

int tracing = 0;

/* checking for correct number of parameters */	
if (argc != 5){
	printf("Incorrect number of parameters\n");
	exit(-1);	
}		

/* Cache size  */
int cachesize = atoi(argv[1]);
if (cachesize < 1) {
	printf("Cache size must be greater than 0\n");
	exit(-1);
}

/* Block size  */
int blocksize = atoi(argv[2]);
if (blocksize < 1){
	printf("Block size must be greater than 0\n");
	exit(-1);
}

/* checking to see if the block size is greater than the cache size */
if (blocksize > cachesize){
	printf("Block size cannot be greater than Cache size\n");
	exit(-1);
}

/* Checking 3rd parameter  */
if ( (strlen(argv[3]) < 2) || (strlen(argv[3]) > 3) ){
	printf("Please enter on or off for the 3rd parameter\n");
	exit(-1);
}

/* Checking for On  */
if ( strlen(argv[3]) == 2   ){
	if ((argv[3][0] != 'o') && (argv[3][0] != 'O') && (argv[3][0] != 'n') && (argv[3][1] != 'N')   ){
		printf("Please enter on or off for the 3rd parameter\n");
		exit(-1);
	}
	tracing = 1;
}

/* Checking for Off  */
if ( strlen(argv[3]) == 3 ) {
	if ( (argv[3][0] != 'o') && (argv[3][0] != 'O') && (argv[3][1] != 'f') && (argv[3][1] != 'F') && (argv[3][2] != 'f') && ( argv[3][2] != 'F' )  ) {
		printf("Please enter on or off for the 3rd parameter\n");
		exit(-1);
	}
	tracing = 0;
}

/* Read in file */
FILE *filelinecount;
FILE *file;
char buffer[11];
int lines = 0;

filelinecount = fopen( argv[4], "r" );
if ( filelinecount == NULL ){
	fprintf(stderr, "Error: Could not open file.\n");
	return 1;
}

while ( fgets( buffer, 11, filelinecount  ) != NULL   ){
		
	lines++;
}

int i = 0;
int i2 = 0;
file = fopen( argv[4], "r");
char addressvalues[11][lines];
int hexvalues[lines];
int temphex;

double t = (5.0/6.0);
//printf("\n%lf\n",t);

int intval = 0;
char hexval[11];
sprintf(hexval,"%0x",intval);
//printf("\n\n hexval : %s\n\n ",hexval); 


while (fgets(buffer,11, file) != NULL ){
	
	i2 = 0;
	if ( (buffer[0] != '0') && (buffer[1] != 'x') ){
		intval = atoi(buffer);
		sprintf(hexval,"%0x",intval);		
		
		temphex = strtol(hexval,NULL,16);
		hexvalues[i] = temphex;		
		while((hexval[i2] != '\0')){
			if (hexval[i2] != '\n'){		
				addressvalues[i2][i] = hexval[i2];		
			}
			i2++;
		}		
		addressvalues[i2][i] = '\0';		
	}else {	
		
		temphex = strtol(buffer,NULL,16);	
		hexvalues[i] = 	temphex;
		//printf("%s",buffer);
        
		while((buffer[i2] != '\0')){
			if (buffer[i2] != '\n'){		
				addressvalues[i2][i] = buffer[i2];		
			}
			i2++;
		}
		addressvalues[i2-1][i] = '\0';
	}	
	
	
	
	i2 = 0;
	i++;
	
}
//printf("\n");

int csize =(int) pow((double)2,(double)cachesize);
int bsize =(int) pow((double)2,(double)blocksize);

int totalblocks = csize/bsize;
int index = log2(totalblocks);
int tag = (32 - index - blocksize);

//printf("cache size in bytes : %d\n", csize);
//printf("block size in bytes : %d\n", bsize);
//printf("Blocks in cache : %d\n",totalblocks);
//printf("Offset : %d\n", blocksize);
//printf("Index : %d\n", index);

struct block blocks[totalblocks];
for (i = 0; i < totalblocks; i++){ 
	blocks[i].valid = 0;
	blocks[i].tag = 0;
}
int tags[lines];
int indexes[lines];

int ta;
int in;

char *testbin;
char *formatbin;
testbin = getBinary(hexvalues[5]);
//printf("\n");
for ( i = 0; i < 32; i++){
	//printf("%c",testbin[i]);
}
//printf("\n");
formatbin = formatBinary(testbin, tag, index, blocksize );
//printf("\n");
for ( i = 0; i < 34; i++){
	//printf("%c",formatbin[i]);
}
//printf("\n");
parseMemoryAddress(formatbin,tag,index,blocksize,&ta,&in);

//printf("tag value :%d\n", ta);
//printf("index value :%d\n", in);


char *tempbin;
char *tempformattedbin;

for (i = 0; i < lines; i++){
	tempbin = getBinary(hexvalues[i]);
	tempformattedbin = formatBinary(tempbin,tag,index,blocksize);
	
	parseMemoryAddress(tempformattedbin, tag, index, blocksize, &tags[i], &indexes[i]);
	
	
}


double missratio = 0.0;
double accesses = 0.0;
double misses = 0.0;
int hits = 0;
char hit[4];
char miss[5];
int oldtag = 0;
hit[0] = 'h';
hit[1] = 'i';
hit[2] = 't';
hit[3] = '\0';

miss[0] = 'm';
miss[1] = 'i';
miss[2] = 's';
miss[3] = 's';
miss[4] = '\0';

int hitflag = 0;
int missflag = 0;

	if (tracing) {	
		printf("address\ttag\tblock\tmem tag\th/m \thits\tmisses\taccesses\tmiss ratio\n");
	}
	for ( i = 0; i < lines; i++){				
		//printf("tags : %d , indexes : %d \n",tags[i], indexes[i]);	
		
		if (blocks[indexes[i]].valid == 0){
			blocks[indexes[i]].valid = 1;
			blocks[indexes[i]].tag = tags[i];		
			missflag = 1;
			misses += 1.0;				
			//printf("here");		
		}
		 else if (blocks[indexes[i]].valid == 1){
			if (blocks[indexes[i]].tag == tags[i]){
				oldtag = blocks[indexes[i]].tag;				
				blocks[indexes[i]].tag = tags[i];
				hits += 1;
				hitflag = 1;
			} else {
				misses += 1.0;
				missflag = 1;
				oldtag = blocks[indexes[i]].tag;
				blocks[indexes[i]].tag = tags[i];
							
			}
		
		}
		accesses += 1.0;		
		missratio = (misses/accesses);
		
		if (tracing) {
		i2 = 0;
		
			while (addressvalues[i2][i] != '\0'){
				if ( (i2 == 0) && (addressvalues[i2][i] == '0') && (addressvalues[i2+1][i] == 'x') ){
				
				} else if ( ( i2 == 1 ) && (addressvalues[i2][i] == 'x') ){ 

				} else {				
					printf("%c" ,addressvalues[i2][i]); 
				}				
				i2++;		
			}
		i2 = 0;	
		}
		if ( tracing ){

			printf("\t %x \t %x \t", tags[i], indexes[i]);
				
			if (oldtag > 0){
				printf(" %x \t", oldtag);
			} else {
				printf("   \t");
			}
			if (hitflag == 1){
				printf("%s \t", hit);
			} else if (missflag == 1){
				printf("%s \t", miss);
			}
			
			printf(" %d \t %d \t %d \t     %.8f" , hits , (int)misses , (int)accesses , missratio ); 

		}
				
		
		if (tracing){			
			printf("\n");
		}
		hitflag = 0;
		missflag = 0;		
		oldtag = 0;
		
	}
	printf("Ivan Capistran\n");
	printf("%s %s %s %s\n", argv[1], argv[2], argv[3], argv[4]);
	printf("memory accesses: %d\n" , (int) accesses);
	printf("hits: %d\n" , hits);
	printf("misses: %d\n", (int)misses);
	printf("miss ratio: %.8f\n", missratio);


	return 0;
}
Example #7
0
int CppSQLite3Binary::getBinaryLength()
{
	getBinary();
	return mnBinaryLen;
}
Example #8
0
int main(void)
{
	int i;
	for (i = 0; i <= 31; i++)
		printf("%05d\n", getBinary(i));
}
Example #9
0
void RewriteToken( void )
/***********************/
{
    REWRITE *r;
    REWRITE_TOKENS *rt;
    uint_8 *stop;
    uint_32 srcfile_index;
    SRCFILE srcfile;
    uint_32 absolute;
    int code_byte;
    unsigned len;

    r = currRewrite;
    rt = r->curr;
    stop = &(rt->stream[rt->count]);
    CurToken = getToken( r, &rt, &stop );
    if( CurToken == T_REWRITE_MODS ) {
        code_byte = getByte( r, &rt, &stop );
        if( code_byte == CODE_FILE ) {
            getBinary( r, &rt, &stop, (uint_8*)&srcfile_index, sizeof( srcfile_index ) );
            srcfile = accessSrcFile( r, srcfile_index );
            SrcFilePoint( srcfile );
            TokenLine = 0;
            TokenColumn = 0;
            CurToken = getToken( r, &rt, &stop );
            if( CurToken == T_REWRITE_MODS ) {
                code_byte = getByte( r, &rt, &stop );
            }
        }
    }
    if( CurToken == T_REWRITE_MODS ) {
        for( ;; ) {
            if( code_byte == CODE_ABS ) {
                getBinary( r, &rt, &stop, (uint_8*)&absolute, sizeof( absolute ) );
                if( MASK_ABS_LINE & absolute ) {
                    TokenLine = absolute & ~MASK_ABS_LINE;
                    TokenColumn = 0;
                } else {
                    TokenColumn = absolute;
                    break;
                }
            } else if( MASK_DELTA_LINE & code_byte ) {
                TokenLine += code_byte & ~MASK_DELTA_LINE;
            } else {
                TokenColumn += code_byte;
                break;
            }
            code_byte = getByte( r, &rt, &stop );
        }
        CurToken = getToken( r, &rt, &stop );
    }
    switch( CurToken ) {
    case T_ID:
    case T_BAD_CHAR:
        len = getString( r, &rt, &stop, Buffer );
        TokenLen = len;
        break;
    case T_BAD_TOKEN:
        getBinary( r, &rt, &stop, (uint_8*)&BadTokenInfo, sizeof( BadTokenInfo ) );
        break;
    case T_STRING:
    case T_LSTRING:
        len = getString( r, &rt, &stop, Buffer );
        TokenLen = len + 1;
        break;
    case T_CONSTANT:
        getBinary( r, &rt, &stop, (uint_8*)&ConstType, sizeof( ConstType ) );
        switch( ConstType ) {
        case TYP_LONG_DOUBLE:
        case TYP_DOUBLE:
        case TYP_FLOAT:
            len = getString( r, &rt, &stop, Buffer );
            TokenLen = len;
            break;
        default:
            getBinary( r, &rt, &stop, (uint_8*)&Constant64, sizeof( Constant64 ) );
            break;
        }
        break;
    default:
        break;
    }
#ifndef NDEBUG
    CtxScanToken();
    DumpToken();
#endif
}
Example #10
0
double Packet::getDouble(){
	return *static_cast<double*>(getBinary(NULL));
}
Example #11
0
float Packet::getFloat(){
	return *static_cast<float*>(getBinary(NULL));
}
Example #12
0
char* Packet::getString(){
	return static_cast<char*>(getBinary(NULL));
}
Example #13
0
char Packet::getChar(){
	return *static_cast<char*>(getBinary(NULL));
}
Example #14
0
int Packet::getInt(){
	return *static_cast<int*>(getBinary(NULL));
}