Value* emitAssignSymbolInCompiledFrame(Value* symbol, Value* environment, int position, Value* value, Compiler* compiler) { Function* assign_symbol_in_compiled_frame = getDeclaration(ASSIGN_SYMBOL_IN_COMPILED_FRAME, compiler); return compiler->emitCallOrInvoke( assign_symbol_in_compiled_frame, { symbol, environment, compiler->getInt32(position), value }); }
void emitError(const char* error_msg, llvm::ArrayRef<llvm::Value*> extra_args, Compiler* compiler) { std::vector<llvm::Value*> args; args.push_back(compiler->emitConstantPointer(error_msg)); args.insert(args.end(), extra_args.begin(), extra_args.end()); Function* error = getDeclaration("Rf_error", compiler); compiler->emitCallOrInvoke(error, args); compiler->CreateUnreachable(); }
void emitWarning(const char* warning_msg, llvm::ArrayRef<llvm::Value*> extra_args, Compiler* compiler) { std::vector<llvm::Value*> args; args.push_back(compiler->emitConstantPointer(warning_msg)); args.insert(args.end(), extra_args.begin(), extra_args.end()); Function* warning = getDeclaration("Rf_warning", compiler); compiler->emitCallOrInvoke(warning, args); }
void ASTUserType::setLLVMType(llvm::Type *t) { if(!getDeclaration()) return; getDeclaration()->cgType = t; }
Value* emitLookupSymbol(Value* value, Value* environment, Compiler* compiler) { Function* lookup_symbol = getDeclaration(LOOKUP_SYMBOL, compiler); return compiler->emitCallOrInvoke(lookup_symbol, { value, environment }); }
llvm::Type *ASTUserType::getLLVMType() { if(!getDeclaration()) return NULL; return (llvm::Type*) getDeclaration()->cgType; }
static llvm::Function* getDeclaration(const std::string& name, Compiler* compiler) { return getDeclaration(name, getModule(compiler)); }
Value* emitEvaluate(Value* value, Value* environment, Compiler* compiler) { Function* evaluate = getDeclaration(EVALUATE, compiler); return compiler->emitCallOrInvoke(evaluate, { value, environment }); }
llvm::Value* emitNext(llvm::Value* environment, Compiler* compiler) { Function* do_next = getDeclaration(DO_NEXT, compiler); compiler->emitCallOrInvoke(do_next, { environment }); return compiler->CreateUnreachable(); }
Value* emitLookupFunction(Value* value, Value* environment, Compiler* compiler) { Function* lookup_function = getDeclaration(LOOKUP_FUNCTION, compiler); return compiler->emitCallOrInvoke(lookup_function, { value, environment }); }
ASTScope *ASTUserType::getScope() { return getDeclaration()->getScope(); }
Declaration *ASTUserType::getMember(size_t i) { return getDeclaration()->members[i]; }
void emitRethrow(Compiler* compiler) { Function* cxa_rethrow = getDeclaration("__cxa_rethrow", compiler); compiler->CreateCall(cxa_rethrow); compiler->CreateUnreachable(); }
Value* emitIsAFunction(llvm::Value* object, Compiler* compiler) { Function* is_a_function = getDeclaration( "cxxr_runtime_is_function", compiler); return compiler->emitCallOrInvoke(is_a_function, object); }
void emitMaybeCheckForUserInterrupt(Compiler* compiler) { Function* maybe_check_for_interrupt = getDeclaration("cxxr_runtime_maybeCheckForUserInterrupts", compiler); compiler->emitCallOrInvoke(maybe_check_for_interrupt, {}); }
void emitIncrementNamed(llvm::Value* value, Compiler* compiler) { Function* incrementNamed = getDeclaration(INCREMENT_NAMED, compiler); compiler->CreateCall(incrementNamed, value); }
void emitSetVisibility(llvm::Value* visible, Compiler* compiler) { Function* setVisibility = getDeclaration(SET_VISIBILITY, compiler); compiler->CreateCall(setVisibility, visible); }
FunctionDeclaration *ASTUserType::getDestructor() { return getDeclaration()->destructor; }
size_t ASTUserType::getAlign() { return getDeclaration()->getAlign(); }
bool ASTUserType::is(ASTType *t) { if(t->isUserType()) { return getDeclaration() == t->getDeclaration(); } return false; }
llvm::Value* emitBreak(llvm::Value* environment, Compiler* compiler) { Function* do_break = getDeclaration(DO_BREAK, compiler); compiler->emitCallOrInvoke(do_break, { environment }); return compiler->CreateUnreachable(); }
bool ASTUserType::isOpaque() { return !getDeclaration()->length() && !getBaseType(); // XXX should be if type does not have body }
llvm::Function* getDeclaration(FunctionId function, llvm::Module* module) { return getDeclaration(getName(function), module); }
size_t ASTUserType::length() { return getDeclaration()->length(); }
static llvm::Function* getDeclaration(FunctionId fun, Compiler* compiler) { return getDeclaration(fun, getModule(compiler)); }
long ASTUserType::getMemberIndex(std::string member){ UserTypeDeclaration *utd = getDeclaration(); if(!utd) return -1; return utd->getMemberIndex(member); }
//Attribute map: //ATTR0 - POSITION0 //ATTR1 - POSITION1 //ATTR2 - NORMAL //ATTR3 - COLOR0 //ATTR4 - COLOR1 //ATTR5 - FOGCOORD //ATTR6 - //ATTR7 - //ATTR8 - TEXCOORD0 //ATTR9 - TEXCOORD1 //ATTR10 - TEXCOORD2 //ATTR11 - TEXCOORD3 //ATTR12 - TEXCOORD4 //ATTR13 - TEXCOORD5 //ATTR14 - TEXCOORD6 //ATTR15 - TEXCOORD7 bool VertexDataOpenGL::generateStreamInfo() { if (!mVertexArray) glGenVertexArrays(1, &mVertexArray); glBindVertexArray(mVertexArray); VertexDeclaration* decl = getDeclaration(); RavAssert(decl); ushort size = getStreamCount(); for (ushort stream = 0; stream < size; ++stream) { //TODO: dynamic_cast VertexBufferOpenGL* buffer = (VertexBufferOpenGL*)getStream(stream); RavAssert(buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer->getBufferID()); //TODO: Check reenabling already enabled states. unsigned offset = 0; unsigned stride = decl->getStreamVertexSize(stream); unsigned streamSize = decl->getElementsCount(stream); for (unsigned elementID = 0; elementID < streamSize; ++elementID) { VertexDeclaration::Element* element = decl->getElement(stream, elementID); GLint size = 0; GLenum type = 0; switch (element->type) { case VertexDeclaration::TYPE_BYTE3: size = 3; type = GL_BYTE; break; case VertexDeclaration::TYPE_BYTE4: size = 4; type = GL_BYTE; break; case VertexDeclaration::TYPE_REAL1: size = 1; type = GL_FLOAT; break; case VertexDeclaration::TYPE_REAL2: size = 2; type = GL_FLOAT; break; case VertexDeclaration::TYPE_REAL3: size = 3; type = GL_FLOAT; break; case VertexDeclaration::TYPE_REAL4: size = 4; type = GL_FLOAT; break; } switch (element->usage) { case VertexDeclaration::USAGE_POSITION: RavAssert(element->usageIndex <= 1); glEnableVertexAttribArray(element->usageIndex); glVertexAttribPointer(element->usageIndex, size, type, GL_FALSE, stride, (char*)0 + offset); break; case VertexDeclaration::USAGE_NORMAL: RavAssert(size == 3); glEnableVertexAttribArray(2); glVertexAttribPointer(2, size, type, GL_FALSE, stride, (char*)0 + offset); break; case VertexDeclaration::USAGE_COLOR: RavAssert(element->usageIndex <= 1); glEnableVertexAttribArray(3 + element->usageIndex); glVertexAttribPointer(3 + element->usageIndex, size, type, GL_FALSE, stride, (char*)0 + offset); break; case VertexDeclaration::USAGE_TEXCOORD: RavAssert(element->usageIndex <= 8); glEnableVertexAttribArray(8 + element->usageIndex); glVertexAttribPointer(8 + element->usageIndex, size, type, GL_FALSE, stride, (char*)0 + offset); break; } offset += decl->getTypeSize(element->type); } } glBindVertexArray(0); return true; }