1 /**
2  * Inline assembler for the D programming language compiler.
3  *
4  * Specification: $(LINK2 https://dlang.org/spec/iasm.html, Inline Assembler)
5  *
6  *              Copyright (C) 2018-2021 by The D Language Foundation, All Rights Reserved
7  * Authors:     $(LINK2 http://www.digitalmars.com, Walter Bright)
8  * License:     $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9  * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/iasm.d, _iasm.d)
10  * Documentation:  https://dlang.org/phobos/dmd_iasm.html
11  * Coverage:    https://codecov.io/gh/dlang/dmd/src/master/src/dmd/iasm.d
12  */
13 
14 module dmd.iasm;
15 
16 import dmd.dscope;
17 import dmd.func;
18 import dmd.statement;
19 
version(MARS)20 version (MARS)
21 {
22     import dmd.iasmdmd;
23 }
version(IN_GCC)24 else version (IN_GCC)
25 {
26     import dmd.iasmgcc;
27 }
28 
29 /************************ AsmStatement ***************************************/
30 
asmSemantic(AsmStatement s,Scope * sc)31 extern(C++) Statement asmSemantic(AsmStatement s, Scope *sc)
32 {
33     //printf("AsmStatement.semantic()\n");
34 
35     FuncDeclaration fd = sc.parent.isFuncDeclaration();
36     assert(fd);
37 
38     if (!s.tokens)
39         return null;
40 
41     // Assume assembler code takes care of setting the return value
42     sc.func.hasReturnExp |= 8;
43 
44     version (MARS)
45     {
46         auto ias = new InlineAsmStatement(s.loc, s.tokens);
47         return inlineAsmSemantic(ias, sc);
48     }
49     else version (IN_GCC)
50     {
51         auto eas = new GccAsmStatement(s.loc, s.tokens);
52         return gccAsmSemantic(eas, sc);
53     }
54     else
55     {
56         s.error("D inline assembler statements are not supported");
57         return new ErrorStatement();
58     }
59 }
60