6
6
7
7
# # Nimony index generator.
8
8
9
- import std / [os, assertions, sets, tables]
9
+ import std / [os, assertions, sets, syncio, tables]
10
10
include " .." / lib / nifprelude
11
11
import " .." / lib / [nifindexes, symparser]
12
12
import decls, nimony_model, programs, vtables_frontend, semos
@@ -90,6 +90,8 @@ proc indexFromNif*(infile: string) =
90
90
var converterIndexMap = default seq [(SymId , SymId )]
91
91
var classIndexMap = default seq [ClassIndexEntry ]
92
92
var exports = default Table [string , HashSet [SymId ]] # Module suffix -> symbols to export in the module
93
+ var toBuild = createTokenBuf ()
94
+ let compileTag = pool.strings.getOrIncl (" compile" )
93
95
94
96
assert n.stmtKind == StmtsS
95
97
inc n
@@ -135,6 +137,37 @@ proc indexFromNif*(infile: string) =
135
137
exports.mgetOrPut (suffix).incl sym
136
138
inc n
137
139
inc n
140
+ of PragmasS :
141
+ var x = n
142
+ let root = n
143
+ skip n
144
+ inc x
145
+ if x.substructureKind == KvU :
146
+ inc x
147
+ if x.kind == Ident and x.litId == compileTag:
148
+ # In Nim 2, compile pragma can take three forms.
149
+ # `{.compile: ("file.c", "$1.o").}` form is not supported.
150
+ inc x
151
+ if x.kind == StringLit :
152
+ toBuild.buildTree TagId (TupX ), NoLineInfo :
153
+ toBuild.addStrLit " C"
154
+ toBuild.add x
155
+ toBuild.addStrLit " "
156
+ else :
157
+ error " Error: Unsupported compile pragma form." , root
158
+ elif x.stmtKind == CallS :
159
+ inc x
160
+ if x.kind == Ident and x.litId == compileTag:
161
+ inc x
162
+ assert x.kind == StringLit
163
+ toBuild.buildTree TagId (TupX ), NoLineInfo :
164
+ toBuild.addStrLit " C"
165
+ toBuild.add x
166
+ inc x
167
+ if x.kind == StringLit :
168
+ toBuild.add x
169
+ else :
170
+ toBuild.addStrLit " "
138
171
else :
139
172
skip n
140
173
else :
@@ -149,3 +182,10 @@ proc indexFromNif*(infile: string) =
149
182
converters: move converterIndexMap,
150
183
classes: move classIndexMap,
151
184
exportBuf: exportBuf)
185
+
186
+ var content = " (.nif24)\n "
187
+ if toBuild.len > 0 :
188
+ content.add " (build\n "
189
+ content.add toString (toBuild)
190
+ content.add " )"
191
+ writeFile changeFileExt (infile, " .deps.nif" ), content
0 commit comments