view dmd/VolatileStatement.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children c77e9f4f1793
line wrap: on
line source

module dmd.VolatileStatement;

import dmd.common;
import dmd.Statement;
import dmd.ArrayTypes;
import dmd.Scope;
import dmd.Loc;
import dmd.OutBuffer;
import dmd.HdrGenState;
import dmd.InlineScanState;
import dmd.IRState;
import dmd.BE;

import dmd.backend.block;
import dmd.backend.Blockx;
import dmd.backend.Util;
import dmd.backend.BC;
//import dmd.backend.BFL;

class VolatileStatement : Statement
{
    Statement statement;

    this(Loc loc, Statement statement)
	{
		super(loc);
		this.statement = statement;
	}
	
    override Statement syntaxCopy()
	{
		assert(false);
	}
	
    override Statement semantic(Scope sc)
	{
		if (statement)
			statement = statement.semantic(sc);
		return this;
	}
	
    override Statements flatten(Scope sc)
	{
		Statements a = statement ? statement.flatten(sc) : null;
		if (a)
		{	
			for (int i = 0; i < a.dim; i++)
			{   
				Statement s = cast(Statement)a.data[i];

				s = new VolatileStatement(loc, s);
				a.data[i] = cast(void*)s;
			}
		}

		return a;
	}
	
    override BE blockExit()
	{
		return statement ? statement.blockExit() : BE.BEfallthru;
	}
	
    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		assert(false);
	}

    override Statement inlineScan(InlineScanState* iss)
	{
		if (statement)
			statement = statement.inlineScan(iss);
		return this;
	}

    override void toIR(IRState* irs)
	{
		block* b;

		if (statement)
		{
			Blockx* blx = irs.blx;

			block_goto(blx, BCgoto, null);
			b = blx.curblock;

			statement.toIR(irs);

			block_goto(blx, BCgoto, null);

			// Mark the blocks generated as volatile
			for (; b != blx.curblock; b = b.Bnext)
			{   
				b.Bflags |= BFL.BFLvolatile;
				if (b.Belem)
					el_setVolatile(b.Belem);
			}
		}
	}
}