示例#1
0
/**
  * Module生成メソッド
  * @param  TranslationUnitAST Module名(入力ファイル名)
  * @return 成功時:true 失敗時:false 
  */
bool CodeGen::generateTranslationUnit(TranslationUnitAST &tunit, std::string name){
	Mod = new llvm::Module(name, llvm::getGlobalContext());
	//funtion declaration
	for(int i=0; ; i++){
		PrototypeAST *proto=tunit.getPrototype(i);
		if(!proto)
			break;
		else if(!generatePrototype(proto, Mod)){
			SAFE_DELETE(Mod);
			return false;
		}
	}

	//function definition
	for(int i=0; ; i++){
		FunctionAST *func=tunit.getFunction(i);
		if(!func)
			break;
		else if(!(generateFunctionDefinition(func, Mod))){
			SAFE_DELETE(Mod);
			return false;
		}
	}

	return true;
}
示例#2
0
PointGroup_sptr PointGroupGenerator::getPrototype() {
  if (!hasValidPrototype()) {
    m_prototype = generatePrototype();
  }

  return m_prototype;
}
示例#3
0
/**
  * 関数定義生成メソッド
  * @param  FunctionAST Module
  * @return 生成したFunctionのポインタ
  */
llvm::Function *CodeGen::generateFunctionDefinition(FunctionAST *func_ast,
		llvm::Module *mod){
	llvm::Function *func=generatePrototype(func_ast->getPrototype(), mod);
	if(!func){
		return NULL;
	}
	CurFunc = func;
	llvm::BasicBlock *bblock=llvm::BasicBlock::Create(llvm::getGlobalContext(),
									"entry",func);
	Builder->SetInsertPoint(bblock);
	generateFunctionStatement(func_ast->getBody());

	return func;
}