Esempio n. 1
0
void encode_native_ref( native_ref_node *ref )
{
  char *s = ref->name;
  while( putc( *s++, fp ) );
  /* *4 to get to the right word and +2 to get to the right byte */
  outputWord( ref->addr*4 + 2 );
}
Esempio n. 2
0
void encode_func( func_node *func )
{
  char *name = func->name;
  while( putc( *name++, fp ) );
  /* annotations */
  outputWord( 0 );
  outputWord( 2 );
  /* frame size */
  outputWord( 0 );
  /* contents length */
  outputWord( func->length*4 );
  encode_stmt_list( func->stmt_list );
  /* number exception handlers */
  outputWord( func->num_handlers );
  encode_handler_list( func->handler_list );
  /* number outsymbol references */
  outputWord( 0 );
  /* number native functions references */
  outputWord( func->num_native_refs );
  encode_native_ref_list( func->native_ref_list );
  /* auxiliary data length */
  outputWord( 0 );
}
Esempio n. 3
0
static void encode_stmt( stmt_node *stmt )
{
  // if there is not an instruction then we are done
  if (stmt->instr->format == 0)
  {
    return;
  }

  if (!strcmp(stmt->instr->opcode, "ldblkid") && stmt->instr->format == 5 )
  {
    stmt->instr->format = 4;
    /* This is a wicked hack :):):) */
    stmt->instr->u.format4.constant = get_blk_id( stmt->instr->u.format5.addr );
  } 

  if ( !strcmp(stmt->instr->opcode, "ldnative") )
  {
    char encodedOpcode = getOpcodeEncoding(stmt->instr->opcode);
    /* Output the opcode, register and ZERO. This native reference is listed
     * in the header of the object file and will have the correct const16
     * filled in by the VM. */
    outputWord((encodedOpcode << 24) |
               (stmt->instr->u.format5.reg << 16) |
               0x0000);
    return;
  }

  // also can skip the import and export directives
  if (!strcmp(stmt->instr->opcode, "export") || !strcmp(stmt->instr->opcode, "import"))
  {
    return;
  }

  // now handle the remaining directives
  if (!strcmp(stmt->instr->opcode, "alloc"))
  {
    // need to add to currentLength
    int len = (stmt->instr->u.format9.constant);
    currentLength += len;
    int i;
    for (i = 0; i < len; i += 1)
    {
      outputWord(0);
    }
    return;
  }
  if (!strcmp(stmt->instr->opcode, "word"))
  {
    currentLength += 1;
    outputWord(stmt->instr->u.format9.constant);
    return;
  }

  // now handle the instructions
  // go ahead and count the word to be encoded
  //   so currentLength will be equal to what PC will be when it executes
  currentLength += 1;

  // get the opcode encoding
  char encodedOpcode = getOpcodeEncoding(stmt->instr->opcode);

  // now handle the different instruction formats
  int encodedAddr;
  switch (stmt->instr->format)
  {
    case 1:
      outputWord(encodedOpcode);
      break;
    case 2:
      encodedAddr = encodeAddr20(stmt->instr->u.format2.addr, currentLength);
      outputWord((encodedAddr << 12) |
                 (encodedOpcode));
      break;
    case 3:
      outputWord((stmt->instr->u.format3.reg << 16) |
                 (encodedOpcode << 24));
      break;
    case 4:
      outputWord((stmt->instr->u.format4.constant & 0xFFFF) |
                 (stmt->instr->u.format4.reg << 16) |
                 (encodedOpcode << 24));
      break;
    case 5:
      encodedAddr = encodeAddr20(stmt->instr->u.format5.addr, currentLength);
      outputWord((encodedAddr << 12) |
                 (stmt->instr->u.format5.reg << 8) |
                 (encodedOpcode));
      break;
    case 6:
      outputWord((encodedOpcode << 24) |
                 (stmt->instr->u.format6.reg1 << 16) |
                 (stmt->instr->u.format6.reg2 << 8));
      break;
    case 7:
      outputWord((encodedOpcode << 24) |
                 (stmt->instr->u.format7.reg1 << 16) |
                 (stmt->instr->u.format7.reg2 << 8) |
                 (stmt->instr->u.format7.const8));
      break;
    case 8:
      encodedAddr = encodeAddr16(stmt->instr->u.format8.addr, currentLength);
      outputWord((encodedOpcode << 24) |
                 (stmt->instr->u.format8.reg1 << 16) |
                 (stmt->instr->u.format8.reg2 << 8) |
                 (encodedAddr));
      break;
    case 10:
      outputWord((encodedOpcode << 24) |
                 (stmt->instr->u.format10.reg1 << 16) |
                 (stmt->instr->u.format10.reg2 << 8) |
                 (stmt->instr->u.format10.reg3));
      break;
    default:
      bug("unexpected format (%d) seen in encode_stmt", stmt->instr->format);
  }

}
Esempio n. 4
0
void encode_handler( handler_node *handler )
{
  outputWord( handler->start_addr*4 );
  outputWord( handler->end_addr*4 );
  outputWord( handler->handle_addr*4 );
}
Esempio n. 5
0
/*
  Creates a file containing iterat * numPatterns patterns.
  Patterns from       0 <= i < numPatterns are not repeated 
  				numPatterns	<= i < 2*numPatterns		...are not repeated 
*/
void generateFile(int iterat, int numPatterns, char *preffix ) {
		unsigned int *chosenPos;

		unsigned int i,z;
		unsigned int pos;
		unsigned int iterActual =1;
				
		FILE *fout;
		char outFile[100];
		char tmp[10];

		chosenPos = (unsigned int *) malloc(1*4*numPatterns);

		outFile[0]='\0';
		strcat(outFile,"./tmp/");
		strcat(outFile,preffix);
		strcat(outFile,"_");
		sprintf(tmp,"Iter%ld_",(long)iterat);
		strcat(outFile,tmp);
		sprintf(tmp,"Pats%ld", (long)numPatterns);
		strcat(outFile,tmp);
		
		remove(outFile);
		
		if ((fout = fopen(outFile,"w")) == NULL){
		  fprintf(stderr,
			  "Error en la apertura del fichero %s\n",
			  "frequencias,txt");
		  exit(0);
		}		

		outputNumPatterns(fout, iterat);

		// MAIN LOOP OF CHOOSNING RND PATTERNS******************
		
		fprintf(stderr, "\n Generating %d file with %dx%d random patterns: ",1,numPatterns,iterat);
		for (;iterActual <= iterat; iterActual++) {
				
				//generates the random patterns.
				for (i=0;i<numPatterns;i++) {
					pos=int_rand(numPalabras);
					chosenPos[i]=pos;  //the random positions inside "lista"

					//avoids repeated random patterns							
					for (z=0;z<i;z++) {
							if (pos == chosenPos[z]) {   //a new iteration "i" will search for other word
								i--;
							}
					}
 				}
	

				//writes the random patterns to the output file.				
				for (i=0; i< numPatterns; i++) {
						outputWord(fout, lista[chosenPos[i]].palabra,lista[chosenPos[i]].numBytesPalabra) ;

					   /*#ifdef OPTION_ONLY_WORDS
							fprintf(fout,"%s\n",lista[chosenPos[i]].palabra);
						#endif
						
						#ifdef OPTION_FREQ_AND_WORDS
							fprintf(fout,"%9ld %9ld %s\n",lista[chosenPos[i]].frecuencia,lista[chosenPos[i]].numBytesPalabra , lista[chosenPos[i]].palabra);
						#endif
						*/
				}
		}
				
		fclose(fout);	 
		free(chosenPos);
		//MAIN LOOP OF CHOOSNING RND PATTERNS ENDS ***********************	
}