Move main implementation of AsmStatement to InlineAsmStatement

This commit is contained in:
Iain Buclaw 2018-08-05 18:46:58 +02:00
parent 50625d9441
commit b3c08210e1
12 changed files with 118 additions and 26 deletions

View file

@ -62,5 +62,5 @@ subPackage {
versions "MARS"
sourcePaths "src/dmd"
excludedSourceFiles "src/dmd/backend/*"
excludedSourceFiles "src/dmd/{e2ir,eh,glue,iasmdmd,objc_glue,s2ir,tocsym,toctype,toobj,todt,toir}.d"
excludedSourceFiles "src/dmd/{e2ir,eh,glue,iasm,iasmdmd,objc_glue,s2ir,tocsym,toctype,toobj,todt,toir}.d"
}

View file

@ -2424,7 +2424,7 @@ struct ASTBase
}
}
extern (C++) final class AsmStatement : Statement
extern (C++) class AsmStatement : Statement
{
Token* tokens;
@ -2440,6 +2440,19 @@ struct ASTBase
}
}
extern (C++) final class InlineAsmStatement : AsmStatement
{
extern (D) this(const ref Loc loc, Token* tokens)
{
super(loc, tokens);
}
override void accept(Visitor v)
{
v.visit(this);
}
}
extern (C++) class ExpStatement : Statement
{
Expression exp;

52
src/dmd/iasm.d Normal file
View file

@ -0,0 +1,52 @@
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright (C) 2018 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/iasm.d, _iasm.d)
* Documentation: https://dlang.org/phobos/dmd_iasm.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/iasm.d
*/
/* Inline assembler for the D programming language compiler
*/
module dmd.iasm;
import dmd.dscope;
import dmd.func;
import dmd.statement;
version (MARS)
{
import dmd.iasmdmd;
}
/************************ AsmStatement ***************************************/
extern(C++) Statement asmSemantic(AsmStatement s, Scope *sc)
{
//printf("AsmStatement.semantic()\n");
FuncDeclaration fd = sc.parent.isFuncDeclaration();
assert(fd);
if (!s.tokens)
return null;
// Assume assembler code takes care of setting the return value
sc.func.hasReturnExp |= 8;
version (MARS)
{
auto ias = new InlineAsmStatement(s.loc, s.tokens);
return inlineAsmSemantic(ias, sc);
}
else
{
error("D inline assembler statements are not supported");
return new ErrorStatement();
}
}

View file

@ -28,7 +28,6 @@ import dmd.dsymbol;
import dmd.errors;
import dmd.expression;
import dmd.expressionsem;
import dmd.func;
import dmd.globals;
import dmd.id;
import dmd.identifier;
@ -113,7 +112,7 @@ struct ASM_STATE
LabelDsymbol psDollar;
Dsymbol psLocalsize;
bool bReturnax;
AsmStatement statement;
InlineAsmStatement statement;
Scope* sc;
Token* tok;
TOK tokValue;
@ -4357,23 +4356,17 @@ extern (C++) public regm_t iasm_regs(block *bp)
}
/************************ AsmStatement ***************************************/
/************************ InlineAsmStatement *********************************/
extern (C++) public Statement asmSemantic(AsmStatement s, Scope *sc)
public Statement inlineAsmSemantic(InlineAsmStatement s, Scope *sc)
{
//printf("AsmStatement.semantic()\n");
//printf("InlineAsmStatement.semantic()\n");
OP *o;
OPND opnd1, opnd2, opnd3, opnd4;
OPND* o1, o2, o3, o4;
PTRNTAB ptb;
int usNumops;
FuncDeclaration fd = sc.parent.isFuncDeclaration();
assert(fd);
if (!s.tokens)
return null;
asmstate.ucItype = 0;
asmstate.bReturnax = false;
@ -4394,9 +4387,6 @@ version (none) // don't use bReturnax anymore, and will fail anyway if we use re
asmstate.bReturnax = false;
}
// Assume assembler code takes care of setting the return value
sc.func.hasReturnExp |= 8;
if (!asmstate.bInit)
{
asmstate.bInit = true;

View file

@ -126,6 +126,9 @@ public:
void visit(AST.CompoundDeclarationStatement s) { visit(cast(AST.CompoundStatement)s); }
void visit(AST.CompoundAsmStatement s) { visit(cast(AST.CompoundStatement)s); }
// AsmStatements
void visit(AST.InlineAsmStatement s) { visit(cast(AST.AsmStatement)s); }
//=========================================================================================
// Types
void visit(AST.TypeBasic t) { visit(cast(AST.Type)t); }

View file

@ -1512,7 +1512,7 @@ private extern (C++) class S2irVisitor : Visitor
/****************************************
*/
override void visit(AsmStatement s)
override void visit(InlineAsmStatement s)
// { .visit(irs, s); }
{
block *bpre;

View file

@ -2379,14 +2379,9 @@ extern (C++) final class LabelDsymbol : Dsymbol
/***********************************************************
*/
extern (C++) final class AsmStatement : Statement
extern (C++) class AsmStatement : Statement
{
Token* tokens;
code* asmcode;
uint asmalign; // alignment of this statement
uint regs; // mask of registers modified (must match regm_t in back end)
bool refparam; // true if function parameter is referenced
bool naked; // true if function is to be naked
extern (D) this(const ref Loc loc, Token* tokens)
{
@ -2405,6 +2400,33 @@ extern (C++) final class AsmStatement : Statement
}
}
/***********************************************************
* https://dlang.org/spec/iasm.html
*/
extern (C++) final class InlineAsmStatement : AsmStatement
{
code* asmcode;
uint asmalign; // alignment of this statement
uint regs; // mask of registers modified (must match regm_t in back end)
bool refparam; // true if function parameter is referenced
bool naked; // true if function is to be naked
extern (D) this(const ref Loc loc, Token* tokens)
{
super(loc, tokens);
}
override Statement syntaxCopy()
{
return new InlineAsmStatement(loc, tokens);
}
override void accept(Visitor v)
{
v.visit(this);
}
}
/***********************************************************
* a complete asm {} block
*/

View file

@ -677,6 +677,14 @@ class AsmStatement : public Statement
{
public:
Token *tokens;
Statement *syntaxCopy();
void accept(Visitor *v) { v->visit(this); }
};
class InlineAsmStatement : public AsmStatement
{
public:
code *asmcode;
unsigned asmalign; // alignment of this statement
unsigned regs; // mask of registers modified (must match regm_t in back end)
@ -684,7 +692,6 @@ public:
bool naked; // true if function is to be naked
Statement *syntaxCopy();
void accept(Visitor *v) { v->visit(this); }
};

View file

@ -100,6 +100,7 @@ extern(C++) class StrictVisitor(AST) : ParseTimeVisitor!AST
override void visit(AST.CompoundStatement) { assert(0); }
override void visit(AST.CompoundDeclarationStatement) { assert(0); }
override void visit(AST.CompoundAsmStatement) { assert(0); }
override void visit(AST.InlineAsmStatement) { assert(0); }
override void visit(AST.Type) { assert(0); }
override void visit(AST.TypeBasic) { assert(0); }
override void visit(AST.TypeError) { assert(0); }

View file

@ -53,6 +53,7 @@ class DebugStatement;
class GotoStatement;
class LabelStatement;
class AsmStatement;
class InlineAsmStatement;
class CompoundAsmStatement;
class ImportStatement;
@ -411,6 +412,9 @@ public:
virtual void visit(CompoundDeclarationStatement *s) { visit((CompoundStatement *)s); }
virtual void visit(CompoundAsmStatement *s) { visit((CompoundStatement *)s); }
// AsmStatements
virtual void visit(InlineAsmStatement *s) { visit((AsmStatement *)s); }
// Types
virtual void visit(TypeBasic *t) { visit((Type *)t); }
virtual void visit(TypeError *t) { visit((Type *)t); }

View file

@ -323,7 +323,7 @@ GLUE_OBJS =
G_GLUE_OBJS = $(addprefix $G/, $(GLUE_OBJS))
GLUE_SRCS=$(addsuffix .d, $(addprefix $D/,irstate toctype glue gluelayer todt tocsym toir dmsc \
tocvdebug s2ir toobj e2ir eh iasmdmd objc_glue))
tocvdebug s2ir toobj e2ir eh iasm iasmdmd objc_glue))
DMD_SRCS=$(FRONT_SRCS) $(GLUE_SRCS) $(BACK_HDRS) $(TK_HDRS)

View file

@ -175,7 +175,7 @@ LEXER_ROOT=$(ROOT)/array.d $(ROOT)/ctfloat.d $(ROOT)/file.d $(ROOT)/filename.d \
PARSER_SRCS=$D/astbase.d $D/parsetimevisitor.d $D/parse.d $D/transitivevisitor.d $D/permissivevisitor.d $D/strictvisitor.d
GLUE_SRCS=$D/irstate.d $D/toctype.d $D/glue.d $D/gluelayer.d $D/todt.d $D/tocsym.d $D/toir.d $D/dmsc.d \
$D/tocvdebug.d $D/s2ir.d $D/toobj.d $D/e2ir.d $D/objc_glue.d $D/eh.d $D/iasmdmd.d
$D/tocvdebug.d $D/s2ir.d $D/toobj.d $D/e2ir.d $D/objc_glue.d $D/eh.d $D/iasm.d $D/iasmdmd.d
BACK_HDRS=$C/cc.d $C/cdef.d $C/cgcv.d $C/code.d $C/cv4.d $C/dt.d $C/el.d $C/global.d \
$C/obj.d $C/oper.d $C/outbuf.d $C/rtlsym.d $C/code_x86.d $C/iasm.d \