void ConstantArrayPropagationPass::CollectInitializations()
{
  if (!initializations.empty())
  {
    initializations.clear() ;
  }

  DefinitionBlock* procDefBlock = procDef->get_definition_block() ;
  assert(procDefBlock != NULL) ;
  Iter<VariableDefinition*> varDefIter = 
    procDefBlock->get_variable_definition_iterator() ;
  while (varDefIter.is_valid())
  {    
    VariableDefinition* varDef = varDefIter.current() ;
    assert(varDef != NULL) ;

    VariableSymbol* varSym = varDef->get_variable_symbol() ;
    ValueBlock* valBlock = varDef->get_initialization() ;
    assert(varSym != NULL) ;
    assert(valBlock != NULL) ;

    if (ValidSymbol(varSym)) 
    {
      initializations[varSym] = valBlock ;
      varSym->append_annote(create_brick_annote(theEnv, "ConstPropArray")) ;
    }

    varDefIter.next() ;
  }
}
Example #2
0
void SingleInheritanceVtbls::attach_vtbl( SingleInheritanceClassType* ctype,
					  VariableSymbol* vsym ) {
  VariableDefinition* vdef = get_vtbl( ctype );
  vdef->set_variable_symbol( vsym );
  vsym->set_definition( vdef );

  // Insert reference to vsym in ClassType
  ctype->set_vtbl_symbol( vsym );

  // Insert vdef in ClassType
  ctype->get_definition_block()->append_variable_definition( vdef );

  // Set type of vsym
  DataType* vtbl_type =
    vdef->get_initialization()->get_type();
  QualifiedType* q_vtbl_type =  _tb->get_qualified_type( vtbl_type );
  vsym->set_type( q_vtbl_type );
}
Example #3
0
/*
 * print_var_def() -- Generates assembly language data statements.
 * Data objects are put into the sdata section, data section, comm
 * section, or the lcomm section.  If the data object is global, I
 * also specify a .globl pseudo-op.
 */
void
PrinterX86::print_var_def(VarSym *vsym)
{
    int vsym_size = get_bit_size(get_type(vsym)) >> 3;	// in bytes
    VariableDefinition *vdef = vsym->get_definition();

    if (vdef == NULL
	|| (vdef->get_initialization() == NULL)	// FIXME: shouldn't be possible
	||  is_a<UndefinedValueBlock>(vdef->get_initialization())) {

	// Uninitialized data item.  If global symbol, append to
	// .comm, else static symbol to .lcomm.
	if (is_global(vsym) && !is_private(vsym))
	    fprintf(out, "\t%s\t", x86_opcode_names[COMM]);
	else
	    fprintf(out, "\t%s\t", x86_opcode_names[LCOMM]);
	print_sym(vsym);
	fprintf(out, ", %d\n", vsym_size);

    } else {		// initialized data item 

	// Specify data section to place data in. On x86, always use
	// .data section.
	fprintf(out, "\t%s\n", x86_opcode_names[DATA]);

	// If global symbol, add .globl pseudo-op.  Note that a variable
	// is considered global in SUIF if it is part of the global or
	// file symbol table.  For X86 assembly, a datum is global only
	// if it is part of the global symbol table (i.e. is_private()
	// checks for def in file symbol table).
	if (is_global(vsym) && !is_private(vsym)) {
	    fprintf(out, "\t%s\t", x86_opcode_names[GLOBL]);
	    print_sym(vsym);
	    fprintf(out, "\n");
	}

	// Determine alignment and align
	int bit_alignment = get_bit_alignment(vdef);
	// If vdef's alignment is zero (shouldn't be!), use that in vsym's type
	if (bit_alignment == 0)
	    bit_alignment = get_bit_alignment(get_type(vsym));
	int alignment_value;
	switch (bit_alignment) {
	  case 8:			// byte aligned
	    alignment_value = 0;
	    break;
	  case 16:			// halfword aligned
	    alignment_value = 1;
	    break;
	  case 32:			// word aligned
	    alignment_value = 2;
	    break;
	  case 64:			// double word aligned
	    alignment_value = 3;
	    break;
	  case 128:			// quad word aligned
	    alignment_value = 4;
	    break;
	  default:
	    claim(false, "bad alignment for %s", get_name(vsym).chars());
	}
	fprintf(out, "\t%s\t%d\n", x86_opcode_names[ALIGN], alignment_value);

	// Disable automatic alignment
	fprintf(out, "\t%s\t%d\t# %s\n", x86_opcode_names[ALIGN], 0,
		      "disable automatic alignment");

	// Write out the label
	print_sym(vsym);
	fprintf(out, ":");		// return added in process_value_block

	// initialize memory with values
	cur_opcode = opcode_null;
	cur_opnd_cnt = 0;
	process_value_block(vdef->get_initialization());
	fprintf(out, "\n");
   }
}