view gen/elem.c @ 54:28e99b04a132 trunk

[svn r58] Fixed cond expression resulting in a non-basic type. Fixed identity expression for dynamic arrays. Revamped the system to keep track of lvalues and rvalues and their relations. Typedef declaration now generate the custom typeinfo. Other bugfixes.
author lindquist
date Wed, 24 Oct 2007 01:37:34 +0200
parents 0c77619e803b
children 339422268de1
line wrap: on
line source

#include <iostream>

#include "gen/llvm.h"

#include "gen/elem.h"
#include "gen/irstate.h"
#include "gen/logger.h"

//////////////////////////////////////////////////////////////////////////////////////////

elem::elem()
{
    mem = 0;
    val = 0;
    arg = 0;

    type = NONE;
    inplace = false;
    field = false;
    callconv = (unsigned)-1;
    isthis = false;
    istypeinfo = false;

    vardecl = 0;
    funcdecl = 0;
}

llvm::Value* elem::getValue()
{
    assert(val || mem);
    switch(type)
    {
    case NONE:
        assert(0 && "type == NONE");
        break;

    case VAR:
    case REF:
    case ARRAYLEN:
        if (val) {
            return val;
        }
        else {
            if (!llvm::isa<llvm::PointerType>(mem->getType()))
            {
                Logger::cout() << "unexpected type: " << *mem->getType() << '\n';
                assert(0);
            }
            const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType());
            if (!pt->getElementType()->isFirstClassType()) {
                return mem;
            }
            else {
                return gIR->ir->CreateLoad(mem, "tmp");
            }
        }

    case VAL:
    case NUL:
    case FUNC:
    case CONST:
    case SLICE:
        return val ? val : mem;
    }
    assert(0 && "type == invalid value");
    return 0;
}