mirror of
https://github.com/xenia-project/xenia.git
synced 2026-04-06 15:13:34 +00:00
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
/**
|
|
******************************************************************************
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
******************************************************************************
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
******************************************************************************
|
|
*/
|
|
|
|
#include <xenia/xenia.h>
|
|
|
|
#include <llvm/IR/DerivedTypes.h>
|
|
#include <llvm/IR/IRBuilder.h>
|
|
#include <llvm/IR/LLVMContext.h>
|
|
#include <llvm/IR/Module.h>
|
|
|
|
using namespace llvm;
|
|
|
|
int some_function(int xx) {
|
|
LLVMContext &context = getGlobalContext();
|
|
//IRBuilder<> builder(context);
|
|
Module *module = new Module("my cool jit", context);
|
|
|
|
Constant* c = module->getOrInsertFunction("mul_add",
|
|
/*ret type*/ IntegerType::get(context, 32),
|
|
/*args*/ IntegerType::get(context, 32),
|
|
IntegerType::get(context, 32),
|
|
IntegerType::get(context, 32),
|
|
/*varargs terminated with null*/ NULL);
|
|
|
|
Function* mul_add = cast<Function>(c);
|
|
mul_add->setCallingConv(CallingConv::C);
|
|
|
|
Function::arg_iterator args = mul_add->arg_begin();
|
|
Value* x = args++;
|
|
x->setName("x");
|
|
Value* y = args++;
|
|
y->setName("y");
|
|
Value* z = args++;
|
|
z->setName("z");
|
|
|
|
BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", mul_add);
|
|
IRBuilder<> builder(block);
|
|
|
|
Value* tmp = builder.CreateBinOp(Instruction::Mul,
|
|
x, y, "tmp");
|
|
Value* tmp2 = builder.CreateBinOp(Instruction::Add,
|
|
tmp, z, "tmp2");
|
|
|
|
builder.CreateRet(tmp2);
|
|
|
|
module->dump();
|
|
delete module;
|
|
return xx + 4;
|
|
}
|