예제 #1
0
void CCodeGenerator::operator()(Assignment* expr) {
    // Handle all types of assignment, including member assignment
    Expression::Ptr init = expr->initializer();
    if (dynamic_cast<Empty*>(init.pointer())) {
        return_ = Operand(env_->integer("0"));
    } else {
        return_ = emit(init);
    }

    String::Ptr id = expr->identifier();
    Variable::Ptr var = variable(id);
    Attribute::Ptr attr = class_ ? class_->attribute(id) : 0;

    if (var) {
        // Assignment to a local var that has already been initialized once in
        // the current scope.
        Type::Ptr type = var->type();
        if (!type->is_value()) {
            refcount_dec(Operand(var->name()));
        }
        line();
        out_ << id->string() << " = " << return_ << ";\n";
        if (!type->is_value()) {
            refcount_inc(Operand(var->name()));
        }
    } else if (attr) {
        // Assignment to an attribute within a class
/*
        Type::Ptr type = expr->type(); 
        Variable::Ptr self = variable(env_->name("__self"));
        Operand addr = Operand::addr(, attr->slot());  
        Operand old = load(addr);
        if (!type->is_value() && !attr->is_weak()) {
            refcount_dec(old);
        } 
        store(addr, return_);
        if (!type->is_value() && !attr->is_weak()) {
            refcount_inc(return_);
        }
*/
        assert(!"not impl");
    } else {
        // Assignment to a local var that has not yet been initialized in the
        // current scope.
        Type::Ptr declared = expr->declared_type();
        if (declared->is_top()) {
            declared = expr->type();
        }
        line();
        brace();
        operator()(declared);
        out_ << " " << id->string() << " = " << return_ << "; ";
        out_ << "(void)" << id->string()  << ";\n";
        variable(new Variable(id, declared));
        if (!declared->is_value()) {
            refcount_inc(return_);
        }
    }
}
예제 #2
0
Operand CCodeGenerator::alloc_temp(Type* type) {
    line();
    brace();
    operator()(type);
    op_ = Operand(RegisterId(op_.reg().id()+1, 0));
    out_ << " " << op_ << " = ";
    return op_;
}
예제 #3
0
macro_line|#include &lt;linux/ioport.h&gt;
macro_line|#include &lt;asm/page.h&gt;
macro_line|#include &lt;asm/oplib.h&gt;
macro_line|#include &lt;asm/system.h&gt;
macro_line|#include &lt;asm/smp.h&gt;
DECL|variable|__initdata
r_struct
id|prom_cpuinfo
id|linux_cpus
(braket
l_int|64
)braket
id|__initdata
op_assign
(brace
(brace
l_int|0
)brace
)brace
suffix:semicolon
DECL|variable|prom_cpu_nodes
r_int
id|prom_cpu_nodes
(braket
l_int|64
)braket
suffix:semicolon
DECL|variable|linux_num_cpus
r_int
id|linux_num_cpus
op_assign
l_int|0
예제 #4
0
macro_line|#include &lt;asm/iSeries/HvCallHpt.h&gt;
macro_line|#include &lt;asm/abs_addr.h&gt;
macro_line|#include &lt;linux/spinlock.h&gt;
DECL|variable|__cacheline_aligned_in_smp
r_static
id|spinlock_t
id|iSeries_hlocks
(braket
l_int|64
)braket
id|__cacheline_aligned_in_smp
op_assign
(brace
(braket
l_int|0
dot
dot
dot
l_int|63
)braket
op_assign
id|SPIN_LOCK_UNLOCKED
)brace
suffix:semicolon
multiline_comment|/*&n; * Very primitive algorithm for picking up a lock&n; */
DECL|function|iSeries_hlock
r_static
r_inline
r_void
id|iSeries_hlock
c_func
(paren