Exemple #1
0
void Aa::write_type_declaration(llvm::Type *T, llvm::Module& tst)
{
	std::string type_name = to_aa(tst.getTypeName(T));
	if(type_name == "")
		return;

	if(!T->isStructTy())
		return;

	std::cout << "$record [" << type_name << "] ";
	const llvm::StructType *ptr_struct = dyn_cast<llvm::StructType>(T);
	for(int idx = 0; idx < ptr_struct->getNumElements(); idx++)
	{
		std::cout << "< " ;
		std::cout << get_aa_type_name(ptr_struct->getElementType(idx),tst);
		std::cout << " > ";
	}
	std::cout << std::endl;
}
Exemple #2
0
std::string Aa::get_aa_type_name(const llvm::Type* ptr, llvm::Module& tst)
{

	if(ptr->isVoidTy())
		return("$void");
	std::string ret_string = tst.getTypeName(ptr);
	if(ret_string != "")
		return(to_aa(ret_string));



	if(isa<PointerType>(ptr))
	{
		ret_string = "$pointer< ";
		const llvm::PointerType *ptr_pointer = dyn_cast<llvm::PointerType>(ptr);
		const llvm::Type* el_type = ptr_pointer->getElementType();
		ret_string += get_aa_type_name(el_type,tst);
		ret_string += " >"; 
	}
	else if(isa<ArrayType>(ptr) || isa<VectorType>(ptr))
	{

		const llvm::SequentialType *ptr_seq = dyn_cast<llvm::SequentialType>(ptr);
		const llvm::Type* el_type = ptr_seq->getElementType();

		int dim = 0;
		const llvm::ArrayType* ptr_array = dyn_cast<llvm::ArrayType>(ptr);
		if(ptr_array != NULL)
			dim = ptr_array->getNumElements();
		else
		{
			const llvm::VectorType* ptr_vec = dyn_cast<llvm::VectorType>(ptr);
			dim = ptr_vec->getNumElements();
		}

		ret_string = "$array [" + int_to_str(dim) + "] $of ";
		ret_string += get_aa_type_name(el_type,tst);
	}
	else if(isa<StructType>(ptr))
	{
		const llvm::StructType *ptr_struct = dyn_cast<llvm::StructType>(ptr);
		ret_string = "$record ";
		for(int idx = 0; idx < ptr_struct->getNumElements(); idx++)
		{
			ret_string += "< " ;
			ret_string += get_aa_type_name(ptr_struct->getElementType(idx),tst);
			ret_string += " > ";
		}
	}
	else if(isa<IntegerType>(ptr))
	{
		ret_string = "$uint<";
		const llvm::IntegerType*   ptr_int = dyn_cast<llvm::IntegerType>(ptr);
		ret_string += int_to_str(ptr_int->getBitWidth()) + ">";
	}
	else if(ptr->isFloatTy())
	{
		ret_string = "$float<8,23>";
	}
	else if(ptr->isDoubleTy())
	{
		ret_string = "$float<11,52>";
	}
	else if(ptr->isVoidTy())
	{
		ret_string = "$void";
	}
	else if(ptr->isFunctionTy())
	{
		std::cerr << "Warning: function type converted to void*" << std::endl;
		ret_string = "$pointer < $void > ";
	} 
	else
	{
		std::cerr << "Error: unsupported type" << std::endl;
		ret_string = "Unsupported_Type";
	}
	return(ret_string);
}