本文整理汇总了C++中ExecutionEngine类的典型用法代码示例。如果您正苦于以下问题:C++ ExecutionEngine类的具体用法?C++ ExecutionEngine怎么用?C++ ExecutionEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExecutionEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: property
/*!
Sets the value of this QJSValue's property with the given \a name to
the given \a value.
If this QJSValue is not an object, this function does nothing.
If this QJSValue does not already have a property with name \a name,
a new property is created.
\sa property(), deleteProperty()
*/
void QJSValue::setProperty(const QString& name, const QJSValue& value)
{
ExecutionEngine *engine = d->engine;
if (!engine)
return;
Scope scope(engine);
Scoped<Object> o(scope, d->value);
if (!o)
return;
if (!value.d->checkEngine(o->engine())) {
qWarning("QJSValue::setProperty(%s) failed: cannot set value created in a different engine", name.toUtf8().constData());
return;
}
ScopedString s(scope, engine->newString(name));
uint idx = s->asArrayIndex();
if (idx < UINT_MAX) {
setProperty(idx, value);
return;
}
QV4::ExecutionContext *ctx = engine->currentContext();
s->makeIdentifier();
QV4::ScopedValue v(scope, value.d->getValue(engine));
o->put(s, v);
if (scope.hasException())
ctx->catchException();
}
示例2: run
int run(unique_ptr<Module> module, Chars_const fnName, const vector<string> args) {
check(module, "no module");
Function* entryFn = module->getFunction(fnName);
check(entryFn, "Source file does not contain a function of the given name");
// Use an EngineBuilder to configure and construct an MCJIT ExecutionEngine.
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
EngineBuilder builder(module.release());
builder.setUseMCJIT(true);
#else
const EngineBuilder builder(move(module));
const SectionMemoryManager mm;
builder.setMCJITMemoryManager(&mm);
#endif
string errorStr;
builder.setErrorStr(&errorStr);
builder.setEngineKind(EngineKind::JIT);
builder.setOptLevel(CodeGenOpt::None);
ExecutionEngine* engine = builder.create();
// Call 'finalizeObject' to notify the JIT that we're ready to execute the jitted code,
// then run the static constructors.
engine->finalizeObject();
engine->runStaticConstructorsDestructors(false);
// Pass the args to the jitted function, and capture the result.
const int result = engine->runFunctionAsMain(entryFn, args, nullptr);
engine->runStaticConstructorsDestructors(true); // Run the static destructors.
return result;
}
示例3: callAsConstructor
/*!
Creates a new \c{Object} and calls this QJSValue as a
constructor, using the created object as the `this' object and
passing \a args as arguments. If the return value from the
constructor call is an object, then that object is returned;
otherwise the default constructed object is returned.
If this QJSValue is not a function, callAsConstructor() does
nothing and returns an undefined QJSValue.
Calling this function can cause an exception to occur in the
script engine; in that case, the value that was thrown
(typically an \c{Error} object) is returned. You can call
isError() on the return value to determine whether an
exception occurred.
\sa call(), QJSEngine::newObject()
*/
QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
{
FunctionObject *f = d->value.asFunctionObject();
if (!f)
return QJSValue();
ExecutionEngine *engine = d->engine;
assert(engine);
Scope scope(engine);
ScopedCallData callData(scope, args.size());
for (int i = 0; i < args.size(); ++i) {
if (!args.at(i).d->checkEngine(engine)) {
qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
return QJSValue();
}
callData->args[i] = args.at(i).d->getValue(engine);
}
ScopedValue result(scope);
QV4::ExecutionContext *ctx = engine->currentContext();
result = f->construct(callData);
if (scope.hasException())
result = ctx->catchException();
return new QJSValuePrivate(engine, result);
}
示例4: function
/*!
Returns the value of this QJSValue's property with the given \a name.
If no such property exists, an undefined QJSValue is returned.
If the property is implemented using a getter function (i.e. has the
PropertyGetter flag set), calling property() has side-effects on the
script engine, since the getter function will be called (possibly
resulting in an uncaught script exception). If an exception
occurred, property() returns the value that was thrown (typically
an \c{Error} object).
\sa setProperty(), hasProperty(), QJSValueIterator
*/
QJSValue QJSValue::property(const QString& name) const
{
ExecutionEngine *engine = d->engine;
if (!engine)
return QJSValue();
QV4::Scope scope(engine);
ScopedObject o(scope, d->value);
if (!o)
return QJSValue();
ScopedString s(scope, engine->newString(name));
uint idx = s->asArrayIndex();
if (idx < UINT_MAX)
return property(idx);
s->makeIdentifier();
QV4::ExecutionContext *ctx = engine->currentContext();
QV4::ScopedValue result(scope);
result = o->get(s);
if (scope.hasException())
result = ctx->catchException();
return new QJSValuePrivate(engine, result);
}
示例5: lookup
ReturnedValue Lookup::lookup(Object *thisObject, PropertyAttributes *attrs)
{
Heap::Object *obj = thisObject->d();
ExecutionEngine *engine = thisObject->engine();
Identifier *name = engine->currentContext()->compilationUnit->runtimeStrings[nameIndex]->identifier;
int i = 0;
while (i < Size && obj) {
classList[i] = obj->internalClass;
index = obj->internalClass->find(name);
if (index != UINT_MAX) {
level = i;
*attrs = obj->internalClass->propertyData.at(index);
return !attrs->isAccessor() ? obj->memberData->data[index].asReturnedValue() : thisObject->getValue(obj->propertyAt(index), *attrs);
}
obj = obj->prototype;
++i;
}
level = Size;
while (obj) {
index = obj->internalClass->find(name);
if (index != UINT_MAX) {
*attrs = obj->internalClass->propertyData.at(index);
return !attrs->isAccessor() ? obj->memberData->data[index].asReturnedValue() : thisObject->getValue(obj->propertyAt(index), *attrs);
}
obj = obj->prototype;
}
return Primitive::emptyValue().asReturnedValue();
}
示例6: main
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 10;
InitializeNativeTarget();
LLVMContext Context;
Module *M = new Module("test", Context);
ExecutionEngine* EE = llvm::EngineBuilder(M).setEngineKind(EngineKind::JIT).create();
for (int i = 0; i < n; ++i) {
SMDiagnostic error;
ParseAssemblyString(function_assembly,
M,
error,
Context);
Function *func = M->getFunction( "factorial" );
typedef int(*func_t)(int);
func_t f = (func_t)(uintptr_t)(EE->getPointerToFunction(func));
EE->freeMachineCodeForFunction(func);
func->eraseFromParent();
}
delete EE;
llvm_shutdown();
return 0;
}
示例7: main
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 24;
LLVMContext Context;
// Create some module to put our function into it.
Module *M = new Module("test", Context);
// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M, Context);
// Now we going to create JIT
ExecutionEngine *EE = EngineBuilder(M).create();
errs() << "verifying... ";
if (verifyModule(*M)) {
errs() << argv[0] << ": Error constructing function!\n";
return 1;
}
errs() << "OK\n";
errs() << "We just constructed this LLVM module:\n\n---------\n" << *M;
errs() << "---------\nstarting fibonacci(" << n << ") with JIT...\n";
// Call the Fibonacci function with argument n:
std::vector<GenericValue> Args(1);
Args[0].IntVal = APInt(32, n);
GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution
outs() << "Result: " << GV.IntVal << "\n";
return 0;
}
示例8: caseFoldCodeGen
casefoldFunctionType caseFoldCodeGen(void) {
Module * M = new Module("casefold", getGlobalContext());
IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
kernel::PipelineBuilder pipelineBuilder(M, idb);
Encoding encoding(Encoding::Type::UTF_8, 8);
pablo::PabloFunction * function = casefold2pablo(encoding);
pipelineBuilder.CreateKernels(function);
pipelineBuilder.ExecuteKernels();
//std::cerr << "ExecuteKernels(); done\n";
llvm::Function * main_IR = M->getFunction("Main");
ExecutionEngine * mEngine = JIT_to_ExecutionEngine(M);
mEngine->finalizeObject();
//std::cerr << "finalizeObject(); done\n";
delete idb;
return reinterpret_cast<casefoldFunctionType>(mEngine->getPointerToFunction(main_IR));
}
示例9: getPointerToFunction
void* getPointerToFunction(Module * mod, Function * func)
{
ExecutionEngine * execEngine = createExecutionEngine(mod);
if (!execEngine) exit(-1);
return execEngine->getPointerToFunction(func);
}
示例10: engine
void Object::defineDefaultProperty(const QString &name, const Value &value)
{
ExecutionEngine *e = engine();
Scope scope(e);
ScopedString s(scope, e->newIdentifier(name));
defineDefaultProperty(s, value);
}
示例11: main
int main()
{
InitializeNativeTarget();
llvm_start_multithreaded();
LLVMContext context;
string error;
OwningPtr<llvm::MemoryBuffer> fileBuf;
MemoryBuffer::getFile("hw.bc", fileBuf);
ErrorOr<Module*> m = parseBitcodeFile(fileBuf.get(), context);
ExecutionEngine *ee = ExecutionEngine::create(m.get());
Function* func = ee->FindFunctionNamed("main");
std::cout << "hop " << m.get() << " ee " << ee << " f " << func << std::endl;
typedef void (*PFN)();
PFN pfn = reinterpret_cast<PFN>(ee->getPointerToFunction(func));
pfn();
Function* f = ee->FindFunctionNamed("fib");
std::cout << "big " << f << std::endl;
// typedef std::function<int(int)> fibType;
typedef int (*fibType)(int);
fibType ffib = reinterpret_cast<fibType>(ee->getPointerToFunction(f));
std::cout << "fib " << ffib(7) << std::endl;
delete ee;
}
示例12: ReturnedValue
void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *))
{
ExecutionEngine *e = engine();
Scope scope(e);
Scoped<String> s(scope, e->newIdentifier(name));
defineAccessorProperty(s, getter, setter);
}
示例13: main
int main(int argc, char **argv)
{
using namespace llvm;
std::cout << "hello_world_ir: " << std::endl;
std::cout << std::endl;
std::cout << hello_world_ir << std::endl;
std::cout << std::endl;
InitializeNativeTarget();
LLVMContext context;
SMDiagnostic error;
Module *m = ParseIR(MemoryBuffer::getMemBuffer(StringRef(hello_world_ir)), error, context);
if(!m)
{
error.print(argv[0], errs());
}
ExecutionEngine *ee = ExecutionEngine::create(m);
Function *func = ee->FindFunctionNamed("hello_world");
typedef void (*fcn_ptr)();
fcn_ptr hello_world = reinterpret_cast<fcn_ptr>(ee->getPointerToFunction(func));
hello_world();
delete ee;
return 0;
}
示例14: allocateArray
ArrayObject<T>* allocateArray(ArrayType type, size_t arraySize)
{
ExecutionEngine * eng = new ExecutionEngine();
eng->heap = new Heap();
eng->objectTable = new ObjectTable();
Method m = getMethod();
m.byteCode = new Instruction[2];
m.byteCode[0] = (Instruction)InstructionSet::NEWARRAY;
m.byteCode[1] = (Instruction)type;
m.byteCodeLength = 2;
MethodFrame frm(2, 2);
frm.operandStack->push(arraySize);
frm.pc = 0;
frm.method = &m;
eng->execute(&frm);
int result = frm.operandStack->pop();
Assert::AreNotEqual(0, result);
Assert::AreEqual(1, result);
ArrayObject<T> * objectPtr = (ArrayObject<T> *) eng->objectTable->get(result);
return objectPtr;
}
示例15: llvm_init
static void llvm_init(){
ExecutionEngine *ee = tcg_llvm_ctx->getExecutionEngine();
FunctionPassManager *fpm = tcg_llvm_ctx->getFunctionPassManager();
Module *mod = tcg_llvm_ctx->getModule();
LLVMContext &ctx = mod->getContext();
// Link logging function in with JIT
Function *logFunc;
std::vector<Type*> argTypes;
// DynValBuffer*
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(uintptr_t)));
// DynValEntryType
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(DynValEntryType)));
// LogOp
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(LogOp)));
// Dynamic value
argTypes.push_back(IntegerType::get(ctx, 8*sizeof(uintptr_t)));
logFunc = Function::Create(
FunctionType::get(Type::getVoidTy(ctx), argTypes, false),
Function::ExternalLinkage, "log_dynval", mod);
logFunc->addFnAttr(Attribute::AlwaysInline);
ee->addGlobalMapping(logFunc, (void*) &log_dynval);
// Create instrumentation pass and add to function pass manager
llvm::FunctionPass *instfp = createPandaInstrFunctionPass(mod);
fpm->add(instfp);
PIFP = static_cast<PandaInstrFunctionPass*>(instfp);
}