Example #1
0
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 });
}
Example #2
0
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();
}
Example #3
0
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);
}
Example #4
0
void ASTUserType::setLLVMType(llvm::Type *t) {
    if(!getDeclaration()) return;
    getDeclaration()->cgType = t;
}
Example #5
0
Value* emitLookupSymbol(Value* value, Value* environment, Compiler* compiler)
{
    Function* lookup_symbol = getDeclaration(LOOKUP_SYMBOL, compiler);
    return compiler->emitCallOrInvoke(lookup_symbol, { value, environment });
}
Example #6
0
llvm::Type *ASTUserType::getLLVMType() {
    if(!getDeclaration()) return NULL;
    return (llvm::Type*) getDeclaration()->cgType;
}
Example #7
0
static llvm::Function* getDeclaration(const std::string& name,
				      Compiler* compiler)
{
    return getDeclaration(name, getModule(compiler));
}
Example #8
0
Value* emitEvaluate(Value* value, Value* environment, Compiler* compiler)
{
    Function* evaluate = getDeclaration(EVALUATE, compiler);
    return compiler->emitCallOrInvoke(evaluate, { value, environment });
}
Example #9
0
llvm::Value* emitNext(llvm::Value* environment, Compiler* compiler) {
    Function* do_next = getDeclaration(DO_NEXT, compiler);
    compiler->emitCallOrInvoke(do_next, { environment });
    return compiler->CreateUnreachable();
}
Example #10
0
Value* emitLookupFunction(Value* value, Value* environment,
			  Compiler* compiler)
{
    Function* lookup_function = getDeclaration(LOOKUP_FUNCTION, compiler);
    return compiler->emitCallOrInvoke(lookup_function, { value, environment });
}
Example #11
0
ASTScope *ASTUserType::getScope() {
    return getDeclaration()->getScope();
}
Example #12
0
Declaration *ASTUserType::getMember(size_t i) {
    return getDeclaration()->members[i];
}
Example #13
0
void emitRethrow(Compiler* compiler)
{
    Function* cxa_rethrow = getDeclaration("__cxa_rethrow", compiler);
    compiler->CreateCall(cxa_rethrow);
    compiler->CreateUnreachable();
}
Example #14
0
Value* emitIsAFunction(llvm::Value* object, Compiler* compiler)
{
    Function* is_a_function = getDeclaration(
	"cxxr_runtime_is_function", compiler);
     return compiler->emitCallOrInvoke(is_a_function, object);
}
Example #15
0
void emitMaybeCheckForUserInterrupt(Compiler* compiler)
{
    Function* maybe_check_for_interrupt
	= getDeclaration("cxxr_runtime_maybeCheckForUserInterrupts", compiler);
    compiler->emitCallOrInvoke(maybe_check_for_interrupt, {});
}
Example #16
0
void emitIncrementNamed(llvm::Value* value, Compiler* compiler)
{
    Function* incrementNamed = getDeclaration(INCREMENT_NAMED, compiler);
    compiler->CreateCall(incrementNamed, value);
}
Example #17
0
void emitSetVisibility(llvm::Value* visible, Compiler* compiler)
{
    Function* setVisibility = getDeclaration(SET_VISIBILITY, compiler);
    compiler->CreateCall(setVisibility, visible);
}
Example #18
0
FunctionDeclaration *ASTUserType::getDestructor() {
    return getDeclaration()->destructor;
}
Example #19
0
size_t ASTUserType::getAlign() {
    return getDeclaration()->getAlign();
}
Example #20
0
bool ASTUserType::is(ASTType *t) {
    if(t->isUserType()) {
        return getDeclaration() == t->getDeclaration();
    }
    return false;
}
Example #21
0
llvm::Value* emitBreak(llvm::Value* environment, Compiler* compiler) {
    Function* do_break = getDeclaration(DO_BREAK, compiler);
    compiler->emitCallOrInvoke(do_break, { environment });
    return compiler->CreateUnreachable();
}
Example #22
0
bool ASTUserType::isOpaque() {
    return !getDeclaration()->length() && !getBaseType(); // XXX should be if type does not have body
}
Example #23
0
llvm::Function* getDeclaration(FunctionId function, llvm::Module* module)
{
    return getDeclaration(getName(function), module);
}
Example #24
0
size_t ASTUserType::length() {
    return getDeclaration()->length();
}
Example #25
0
static llvm::Function* getDeclaration(FunctionId fun, Compiler* compiler)
{
    return getDeclaration(fun, getModule(compiler));
}
Example #26
0
long ASTUserType::getMemberIndex(std::string member){
    UserTypeDeclaration *utd = getDeclaration();
    if(!utd) return -1;
    return utd->getMemberIndex(member);
}
Example #27
0
	//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;
	}