本文整理汇总了C++中CodeGenContext类的典型用法代码示例。如果您正苦于以下问题:C++ CodeGenContext类的具体用法?C++ CodeGenContext怎么用?C++ CodeGenContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CodeGenContext类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: codeGen
void FunctionDeclaration::codeGen(CodeGenContext& context)
{
BasicBlock *bblock = new BasicBlock();
Function *f = new Function();
context.push_block(bblock);
VariableList::const_iterator it;
for (it = m_arguments->begin(); it != m_arguments->end(); it++) {
if (debug)
cout << "Argument : " << (**it).m_type->m_name ;
Value *v = (*it)->value();
(**it).codeGen(context);
if (debug)
cout << " at: " << v->addr << endl;
f->arguments.push_back(v->addr);
}
m_block->codeGen(context, true);
f->pm_addr = context.getCurrent();
m_block->codeGen(context, false);
context.vret();
context.pop_block();
context.functions().insert(std::make_pair(m_id->m_name, f));
if (debug)
std::cout << "Creating function: " << m_id->m_name << endl;
}
示例2: main
int main(int argc, char *argv[])
{
auto compileOnly = false;
auto logLevel = 4;
for(auto i = 0; i < argc; ++i) {
if(std::string(argv[i]).compare("-c") == 0 || std::string(argv[i]).compare("--compile") == 0) {
compileOnly = true;
}
if(std::string(argv[i]).find("--log") == 0) {
if(argv[i][5] < '0' || argv[i][5] > '4') {
std::cerr << "Bad level" << std::endl;
exit(2);
}
logLevel = argv[i][5] - '0';
}
}
yyparse();
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
CodeGenContext context;
context.dclog.max_level = debug_stream::level(logLevel);
createCoreFunctions(context);
context.generateCode(*programBlock);
if (!compileOnly) {
auto val = context.runCode();
(context.llclog << val.IntVal.getSExtValue() << "\n").flush();
}
return 0;
}
示例3: main
int main(int argc, char **argv)
{
yyparse();
std::cout << programBlock << std::endl;
CodeGenContext context;
context.generateCode(*programBlock);
context.runCode();
return 0;
}
示例4: main
int main(int argc, char **argv)
{
yyparse();
std::cout << programBlock << endl;
// see http://comments.gmane.org/gmane.comp.compilers.llvm.devel/33877
InitializeNativeTarget();
CodeGenContext context;
createCoreFunctions(context);
context.generateCode(*programBlock);
context.runCode();
return 0;
}
示例5: CreateWriteAccessor
void CVariableDeclaration::CreateWriteAccessor(CodeGenContext& context, BitVariable& var, const std::string& moduleName, const std::string& name, bool impedance)
{
std::vector<llvm::Type*> argTypes;
argTypes.push_back(context.getIntType(var.size));
llvm::FunctionType *ftype = llvm::FunctionType::get(context.getVoidType(), argTypes, false);
llvm::Function* function;
if (context.isRoot)
{
function = context.makeFunction(ftype, llvm::GlobalValue::ExternalLinkage, context.moduleName + context.getSymbolPrefix() + "PinSet" + id.name);
}
else
{
function = context.makeFunction(ftype, llvm::GlobalValue::PrivateLinkage, context.moduleName + context.getSymbolPrefix() + "PinSet" + id.name);
}
function->onlyReadsMemory(); // Mark input read only
context.StartFunctionDebugInfo(function, declarationLoc);
llvm::BasicBlock *bblock = context.makeBasicBlock("entry", function);
context.pushBlock(bblock, declarationLoc);
llvm::Function::arg_iterator args = function->arg_begin();
llvm::Value* setVal = &*args;
setVal->setName("InputVal");
llvm::LoadInst* load = new llvm::LoadInst(var.value, "", false, bblock);
if (impedance)
{
llvm::LoadInst* loadImp = new llvm::LoadInst(var.impedance, "", false, bblock);
llvm::CmpInst* check = llvm::CmpInst::Create(llvm::Instruction::ICmp, llvm::ICmpInst::ICMP_NE, loadImp, context.getConstantZero(var.size.getLimitedValue()), "impedance", bblock);
setVal = llvm::SelectInst::Create(check, setVal, load, "impOrReal", bblock);
}
llvm::Value* stor = CAssignment::generateAssignmentActual(var, id/*moduleName, name*/, setVal, context, false); // we shouldn't clear impedance on write via pin (instead should ignore write if impedance is set)
var.priorValue = load;
var.writeInput = setVal;
var.writeAccessor = &writeAccessor;
writeAccessor = context.makeReturn(bblock);
context.popBlock(declarationLoc);
context.EndFunctionDebugInfo();
}
示例6: createEchoFunction
void createEchoFunction(CodeGenContext& context, llvm::Function* printfFn)
{
std::vector<llvm::Type*> echo_arg_types;
echo_arg_types.push_back(llvm::Type::getInt64Ty(getGlobalContext()));
llvm::FunctionType* echo_type =
llvm::FunctionType::get(
llvm::Type::getVoidTy(getGlobalContext()), echo_arg_types, false);
llvm::Function *func = llvm::Function::Create(
echo_type, llvm::Function::InternalLinkage,
llvm::Twine("echo"),
context.module
);
llvm::BasicBlock *bblock = llvm::BasicBlock::Create(getGlobalContext(), "entry", func, 0);
context.pushBlock(bblock);
const char *constValue = "%d\n";
llvm::Constant *format_const = llvm::ConstantDataArray::getString(getGlobalContext(), constValue);
llvm::GlobalVariable *var =
new llvm::GlobalVariable(
*context.module, llvm::ArrayType::get(llvm::IntegerType::get(getGlobalContext(), 8), strlen(constValue)+1),
true, llvm::GlobalValue::PrivateLinkage, format_const, ".str");
llvm::Constant *zero =
llvm::Constant::getNullValue(llvm::IntegerType::getInt32Ty(getGlobalContext()));
std::vector<llvm::Constant*> indices;
indices.push_back(zero);
indices.push_back(zero);
llvm::Constant *var_ref = llvm::ConstantExpr::getGetElementPtr(
llvm::ArrayType::get(llvm::IntegerType::get(getGlobalContext(), 8), strlen(constValue+1)),
var, indices);
std::vector<Value*> args;
args.push_back(var_ref);
Function::arg_iterator argsValues = func->arg_begin();
Value* toPrint = argsValues++;
toPrint->setName("toPrint");
args.push_back(toPrint);
CallInst *call = CallInst::Create(printfFn, makeArrayRef(args), "", bblock);
ReturnInst::Create(getGlobalContext(), bblock);
context.popBlock();
}
示例7: autoUpgradeType
bool NBinaryOperator::autoUpgradeType(CodeGenContext& context,
Value *lhs, Value *rhs)
{
bool isConverted = false;
// conversion if it exists a float type
if (lhs->getType()->isDoubleTy() || rhs->getType()->isDoubleTy()) {
if (!lhs->getType()->isDoubleTy()) {
lhs = new SIToFPInst(lhs, Type::getFloatTy(context.module->getContext()),
"conv", context.currentBlock());
isConverted = true;
}
if (!rhs->getType()->isDoubleTy()) {
rhs = new SIToFPInst(rhs, Type::getFloatTy(context.module->getContext()),
"conv", context.currentBlock());
isConverted = true;
}
}
return isConverted;
}
示例8: main
int main(int argc, char **argv)
{
if (argc > 1) {
extern FILE* yyin;
if(!(yyin = fopen(argv[1], "r"))) {
perror(argv[1]);
return (1);
}
}
yyparse();
std::cout << programBlock << std::endl;
CodeGenContext context;
context.generateCode(*programBlock);
context.runCode();
return 0;
}
示例9: yyparse
void CInstance::prePass(CodeGenContext& context)
{
// On the prepass, we need to generate the code for this module
std::string includeName = filename.quoted.substr(1, filename.quoted.length() - 2);
if (resetFileInput(includeName.c_str()) != 0)
{
context.gContext.ReportError(nullptr, EC_ErrorAtLocation, filename.quotedLoc, "Unable to instance module %s", includeName.c_str());
return;
}
yyparse();
if (g_ProgramBlock == 0)
{
context.gContext.ReportError(nullptr, EC_ErrorAtLocation, filename.quotedLoc, "Unable to parse module %s", includeName.c_str());
return;
}
CodeGenContext* includefile;
includefile = new CodeGenContext(context.gContext, &context);
includefile->moduleName = ident.name + ".";
if (context.gContext.opts.generateDebug)
{
context.gContext.scopingStack.push(context.gContext.CreateNewDbgFile(includeName.c_str()));
}
includefile->generateCode(*g_ProgramBlock);
if (context.gContext.opts.generateDebug)
{
context.gContext.scopingStack.pop();
}
if (includefile->isErrorFlagged())
{
context.gContext.ReportError(nullptr , EC_ErrorAtLocation, filename.quotedLoc, "Unable to parse module %s", includeName.c_str());
return;
}
context.m_includes[ident.name + "."] = includefile;
}
示例10: main
int main(int argc, char **argv)
{
FILE *inpFile = fopen(argv[1], "r");
if (!inpFile)
{
cout << "Error opening File" << endl;
return -1;
}
yyin = inpFile;
yyparse();
std::cout << programBlock << endl;
// see http://comments.gmane.org/gmane.comp.compilers.llvm.devel/33877
llvm::InitializeNativeTarget();
CodeGenContext context;
context.generateCode(*programBlock);
context.runCode();
system("pause");
return 0;
}
示例11: main
int main(void)
{
/* object to interface with llvm API (defined in codegen.cpp) */
CodeGenContext context;
/*
* Lexing and Parsing
* ------------------
* lexer feeds tokens to parser
* parser builds an AST stored in programBlock
*/
yyparse();
/* prints out root address of AST root */
std::cout << "=================================" << std::endl
<< "Address of root AST node: " << programBlock
<< std::endl << std::endl;
/*
* Code Generation
* ---------------
*/
/* establish host target & link target libraries JIT uses */
llvm::InitializeNativeTarget();
coreFuncs(context);
context.generateCode(*programBlock);
context.runCode();
return EXIT_SUCCESS;
}
示例12: CreateReadAccessor
void CVariableDeclaration::CreateReadAccessor(CodeGenContext& context, BitVariable& var, bool impedance)
{
std::vector<llvm::Type*> argTypes;
llvm::FunctionType *ftype = llvm::FunctionType::get(context.getIntType(var.size), argTypes, false);
llvm::Function* function;
if (context.isRoot)
{
function = context.makeFunction(ftype, llvm::GlobalValue::ExternalLinkage, context.moduleName + context.getSymbolPrefix() + "PinGet" + id.name);
}
else
{
function = context.makeFunction(ftype, llvm::GlobalValue::PrivateLinkage, context.moduleName + context.getSymbolPrefix() + "PinGet" + id.name);
}
function->setOnlyReadsMemory();
context.StartFunctionDebugInfo(function, declarationLoc);
llvm::BasicBlock *bblock = context.makeBasicBlock("entry", function);
context.pushBlock(bblock, declarationLoc);
llvm::Value* load = new llvm::LoadInst(var.value, "", false, bblock);
if (impedance)
{
llvm::LoadInst* loadImp = new llvm::LoadInst(var.impedance, "", false, bblock);
llvm::CmpInst* check = llvm::CmpInst::Create(llvm::Instruction::ICmp, llvm::ICmpInst::ICMP_EQ, loadImp, context.getConstantZero(var.size.getLimitedValue()), "impedance", bblock);
load = llvm::SelectInst::Create(check, load, loadImp, "impOrReal", bblock);
}
context.makeReturnValue(load, bblock);
context.popBlock(declarationLoc);
context.EndFunctionDebugInfo();
}