Replace AsmBlockStatement with CompoundAsmStatement.

This commit is contained in:
kai 2015-03-01 16:38:02 +01:00
parent 6c71eb16bb
commit f61327c149
9 changed files with 35 additions and 113 deletions

View file

@ -636,18 +636,6 @@ public:
buf->writenl();
}
#if IN_LLVM
void visit(AsmBlockStatement *s)
{
for (size_t i = 0; i < s->statements->dim; i++)
{
Statement *sx = (*s->statements)[i];
if (sx)
sx->accept(this);
}
}
#endif
void visit(ImportStatement *s)
{
for (size_t i = 0; i < s->imports->dim; i++)

View file

@ -702,14 +702,6 @@ int Statement::blockExit(FuncDeclaration *func, bool mustNotThrow)
if (!(s->stc & STCnothrow)) result |= BEthrow;
}
#if IN_LLVM
void visit(AsmBlockStatement *s)
{
// Assume the worst
result = BEany;
}
#endif
void visit(ImportStatement *s)
{
result = BEfallthru;
@ -1170,7 +1162,7 @@ Statement *CompoundStatement::semantic(Scope *sc)
}
if (statements->dim == 1
#if IN_LLVM
&& !isAsmBlockStatement()
&& !isCompoundAsmBlockStatement()
#endif
)
{
@ -5157,6 +5149,12 @@ CompoundAsmStatement::CompoundAsmStatement(Loc loc, Statements *s, StorageClass
: CompoundStatement(loc, s)
{
this->stc = stc;
#if IN_LLVM
enclosingFinally = NULL;
enclosingScopeExit = NULL;
abiret = NULL;
#endif
}
CompoundAsmStatement *CompoundAsmStatement::syntaxCopy()
@ -5178,6 +5176,9 @@ Statements *CompoundAsmStatement::flatten(Scope *sc)
CompoundAsmStatement *CompoundAsmStatement::semantic(Scope *sc)
{
#if IN_LLVM
enclosingFinally = sc->tf;
#endif
for (size_t i = 0; i < statements->dim; i++)
{
Statement *s = (*statements)[i];

View file

@ -142,8 +142,8 @@ public:
virtual void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
virtual AsmBlockStatement *isAsmBlockStatement() { return NULL; }
virtual AsmBlockStatement* endsWithAsm();
virtual CompoundAsmStatement *isCompoundAsmBlockStatement() { return NULL; }
virtual CompoundAsmStatement* endsWithAsm();
#endif
};
@ -233,7 +233,7 @@ public:
void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
virtual AsmBlockStatement* endsWithAsm();
virtual CompoundAsmStatement* endsWithAsm();
#endif
};
@ -824,6 +824,10 @@ class CompoundAsmStatement : public CompoundStatement
{
public:
StorageClass stc; // postfix attributes like nothrow/pure/@trusted
#if IN_LLVM
TryFinallyStatement* enclosingFinally;
Statement* enclosingScopeExit;
#endif
CompoundAsmStatement(Loc loc, Statements *s, StorageClass stc);
CompoundAsmStatement *syntaxCopy();
@ -831,6 +835,13 @@ public:
Statements *flatten(Scope *sc);
void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
CompoundStatement *isCompoundStatement() { return NULL; }
CompoundAsmStatement *isCompoundAsmBlockStatement() { return this; }
CompoundAsmStatement* endsWithAsm();
llvm::Value* abiret;
#endif
};
class ImportStatement : public Statement
@ -845,26 +856,4 @@ public:
void accept(Visitor *v) { v->visit(this); }
};
#if IN_LLVM
class AsmBlockStatement : public CompoundStatement
{
public:
TryFinallyStatement* enclosingFinally;
Statement* enclosingScopeExit;
AsmBlockStatement(Loc loc, Statements *s);
Statements *flatten(Scope *sc);
Statement *syntaxCopy();
Statement *semantic(Scope *sc);
CompoundStatement *isCompoundStatement() { return NULL; }
AsmBlockStatement *isAsmBlockStatement() { return this; }
void accept(Visitor *v) { v->visit(this); }
AsmBlockStatement* endsWithAsm();
llvm::Value* abiret;
};
#endif
#endif /* DMD_STATEMENT_H */

View file

@ -342,9 +342,6 @@ public:
virtual void visit(GotoStatement *s) { visit((Statement *)s); }
virtual void visit(LabelStatement *s) { visit((Statement *)s); }
virtual void visit(AsmStatement *s) { visit((Statement *)s); }
#if IN_LLVM
virtual void visit(AsmBlockStatement *s) { visit((Statement *)s); }
#endif
virtual void visit(CompoundAsmStatement *s) { visit((CompoundStatement *)s); }
virtual void visit(ImportStatement *s) { visit((Statement *)s); }

View file

@ -430,15 +430,6 @@ void AsmStatement_toIR(AsmStatement *stmt, IRState * irs)
//////////////////////////////////////////////////////////////////////////////
AsmBlockStatement::AsmBlockStatement(Loc loc, Statements* s)
: CompoundStatement(loc, s)
{
enclosingFinally = NULL;
enclosingScopeExit = NULL;
abiret = NULL;
}
// rewrite argument indices to the block scope indices
static void remap_outargs(std::string& insnt, size_t nargs, size_t idx)
{
@ -489,7 +480,7 @@ static void remap_inargs(std::string& insnt, size_t nargs, size_t idx)
}
}
void AsmBlockStatement_toIR(AsmBlockStatement *stmt, IRState* p)
void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p)
{
IF_LOG Logger::println("AsmBlockStatement::toIR(): %s", stmt->loc.toChars());
LOG_SCOPE;
@ -766,44 +757,15 @@ void AsmBlockStatement_toIR(AsmBlockStatement *stmt, IRState* p)
}
}
// the whole idea of this statement is to avoid the flattening
Statements* AsmBlockStatement::flatten(Scope* sc)
{
return NULL;
}
Statement *AsmBlockStatement::syntaxCopy()
{
Statements *a = new Statements();
a->setDim(statements->dim);
for (size_t i = 0; i < statements->dim; i++)
{
Statement *s = (*statements)[i];
if (s)
s = s->syntaxCopy();
a->data[i] = s;
}
AsmBlockStatement *cs = new AsmBlockStatement(loc, a);
return cs;
}
// necessary for in-asm branches
Statement *AsmBlockStatement::semantic(Scope *sc)
{
enclosingFinally = sc->tf;
return CompoundStatement::semantic(sc);
}
//////////////////////////////////////////////////////////////////////////////
AsmBlockStatement* Statement::endsWithAsm()
CompoundAsmStatement* Statement::endsWithAsm()
{
// does not end with inline asm
return NULL;
}
AsmBlockStatement* CompoundStatement::endsWithAsm()
CompoundAsmStatement* CompoundStatement::endsWithAsm()
{
// make the last inner statement decide
if (statements && statements->dim)
@ -815,7 +777,7 @@ AsmBlockStatement* CompoundStatement::endsWithAsm()
return NULL;
}
AsmBlockStatement* AsmBlockStatement::endsWithAsm()
CompoundAsmStatement* CompoundAsmStatement::endsWithAsm()
{
// yes this is inline asm
return this;

View file

@ -1048,7 +1048,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
llvm::ReturnInst::Create(gIR->context(), gIR->scopebb());
}
else if (!fd->isMain()) {
AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
CompoundAsmStatement* asmb = fd->fbody->endsWithAsm();
if (asmb) {
assert(asmb->abiret);
llvm::ReturnInst::Create(gIR->context(), asmb->abiret, bb);

View file

@ -105,13 +105,13 @@ struct IRAsmBlock
// stores the labels within the asm block
std::vector<Identifier*> internalLabels;
AsmBlockStatement* asmBlock;
CompoundAsmStatement* asmBlock;
LLType* retty;
unsigned retn;
bool retemu; // emulate abi ret with a temporary
LLValue* (*retfixup)(IRBuilderHelper b, LLValue* orig); // Modifies retval
IRAsmBlock(AsmBlockStatement* b)
IRAsmBlock(CompoundAsmStatement* b)
: outputcount(0), asmBlock(b), retty(NULL), retn(0), retemu(false),
retfixup(NULL)
{}

View file

@ -55,21 +55,6 @@ public:
//////////////////////////////////////////////////////////////////////////
void visit(AsmBlockStatement *stmt) LLVM_OVERRIDE {
IF_LOG Logger::println("AsmBlockStatement::toNakedIR(): %s", stmt->loc.toChars());
LOG_SCOPE;
for (Statements::iterator I = stmt->statements->begin(),
E = stmt->statements->end();
I != E; ++I)
{
Statement *s = *I;
if (s) s->accept(this);
}
}
//////////////////////////////////////////////////////////////////////////
void visit(CompoundStatement *stmt) LLVM_OVERRIDE {
IF_LOG Logger::println("CompoundStatement::toNakedIR(): %s", stmt->loc.toChars());
LOG_SCOPE;

View file

@ -45,7 +45,7 @@
//////////////////////////////////////////////////////////////////////////////
// FIXME: Integrate these functions
void AsmStatement_toIR(AsmStatement *stmt, IRState * irs);
void AsmBlockStatement_toIR(AsmBlockStatement *stmt, IRState* p);
void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState* p);
//////////////////////////////////////////////////////////////////////////////
@ -325,7 +325,7 @@ public:
StatementVisitor::visit(s);
}
void visit(AsmBlockStatement *s)
void visit(CompoundAsmStatement *s)
{
s->enclosingScopeExit = enclosingTryFinally();
StatementVisitor::visit(s);
@ -1777,8 +1777,8 @@ public:
//////////////////////////////////////////////////////////////////////////
void visit(AsmBlockStatement *stmt) LLVM_OVERRIDE {
AsmBlockStatement_toIR(stmt, irs);
void visit(CompoundAsmStatement *stmt) LLVM_OVERRIDE{
CompoundAsmStatement_toIR(stmt, irs);
}
//////////////////////////////////////////////////////////////////////////