fixes #2335
This commit is contained in:
parent
3317faf80d
commit
c1730e1ead
2 changed files with 29 additions and 3 deletions
|
|
@ -1001,12 +1001,19 @@ proc genAsmStmt(p: BProc, t: PNode) =
|
||||||
else:
|
else:
|
||||||
lineF(p, cpsStmts, CC[cCompiler].asmStmtFrmt, [s])
|
lineF(p, cpsStmts, CC[cCompiler].asmStmtFrmt, [s])
|
||||||
|
|
||||||
|
proc determineSection(n: PNode): TCFileSection =
|
||||||
|
result = cfsProcHeaders
|
||||||
|
if n.len >= 1 and n.sons[0].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
|
if n.sons[0].strVal.startsWith("/*TYPESECTION*/"): result = cfsTypes
|
||||||
|
elif n.sons[0].strVal.startsWith("/*VARSECTION*/"): result = cfsVars
|
||||||
|
|
||||||
proc genEmit(p: BProc, t: PNode) =
|
proc genEmit(p: BProc, t: PNode) =
|
||||||
var s = genAsmOrEmitStmt(p, t.sons[1])
|
var s = genAsmOrEmitStmt(p, t.sons[1])
|
||||||
if p.prc == nil:
|
if p.prc == nil:
|
||||||
# top level emit pragma?
|
# top level emit pragma?
|
||||||
genCLineDir(p.module.s[cfsProcHeaders], t.info)
|
let section = determineSection(t[1])
|
||||||
add(p.module.s[cfsProcHeaders], s)
|
genCLineDir(p.module.s[section], t.info)
|
||||||
|
add(p.module.s[section], s)
|
||||||
else:
|
else:
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
line(p, cpsStmts, s)
|
line(p, cpsStmts, s)
|
||||||
|
|
|
||||||
19
doc/nimc.txt
19
doc/nimc.txt
|
|
@ -386,6 +386,25 @@ Example:
|
||||||
As can be seen from the example, to Nim symbols can be referred via backticks.
|
As can be seen from the example, to Nim symbols can be referred via backticks.
|
||||||
Use two backticks to produce a single verbatim backtick.
|
Use two backticks to produce a single verbatim backtick.
|
||||||
|
|
||||||
|
For a toplevel emit statement the section where in the generated C/C++ file
|
||||||
|
the code should be emitted can be influenced via the
|
||||||
|
prefixes ``/*TYPESECTION*/`` or ``/*VARSECTION*/``:
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
{.emit: """/*TYPESECTION*/
|
||||||
|
struct Vector3 {
|
||||||
|
public:
|
||||||
|
Vector3(): x(5) {}
|
||||||
|
Vector3(float x_): x(x_) {}
|
||||||
|
float x;
|
||||||
|
};
|
||||||
|
""".}
|
||||||
|
|
||||||
|
type Vector3 {.importcpp: "Vector3", nodecl} = object
|
||||||
|
x: cfloat
|
||||||
|
|
||||||
|
proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl}
|
||||||
|
|
||||||
|
|
||||||
ImportCpp pragma
|
ImportCpp pragma
|
||||||
----------------
|
----------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue