forked from Xandaros/ic10lsp
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
407 lines (329 loc) · 12.7 KB
/
Copy pathbuild.rs
File metadata and controls
407 lines (329 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
use std::{
env,
fs::{self, File},
io::BufWriter,
io::Write,
path::Path,
};
fn write_stationpedia() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("stationpedia.rs");
let mut name_map_builder = ::phf_codegen::Map::new();
let mut desc_map_builder = ::phf_codegen::Map::new();
let mut name_set_builder = ::phf_codegen::Set::new();
let mut check_set = std::collections::HashSet::new();
let infile = Path::new("data/stationpedia.txt");
let contents = fs::read_to_string(infile).unwrap();
for line in contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(3, ' ');
let hash = it.next().unwrap();
let name = it.next().unwrap();
let desc = it.next().unwrap_or("");
name_map_builder.entry(hash, &format!("\"{}\"", name));
desc_map_builder.entry(hash, &format!("\"{}\"", desc));
if !check_set.contains(name) {
name_set_builder.entry(name);
check_set.insert(name);
}
}
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
write!(
&mut writer,
"pub(crate) const HASH_NAME_LOOKUP: phf::Map<&'static str, &'static str> = {};\n",
name_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const HASH_DESC_LOOKUP: phf::Map<&'static str, &'static str> = {};\n",
desc_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const HASH_NAMES: phf::Set<&'static str> = {};\n",
name_set_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/stationpedia.txt");
}
fn write_instructions() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("instructions.rs");
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
let mut instruction_map_builder = ::phf_codegen::Map::new();
let infile = Path::new("data/instructions.txt");
let contents = fs::read_to_string(infile).unwrap();
for line in contents.lines() {
let mut it = line.split(' ');
let instruction = it.next().unwrap();
let ops: Vec<&str> = it.map(|s| s.trim()).collect();
instruction_map_builder.entry(instruction, &format!("InstructionSignature(&[{}])", ops.join(",")));
}
let mut help_map_builder = ::phf_codegen::Map::new();
let h_infile = Path::new("data/instructions_help.txt");
let h_contents = fs::read_to_string(h_infile).unwrap();
for line in h_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(2, ' ');
let instruction = it.next().unwrap();
let help = it.next().unwrap_or("").replace("\\n", "\n");
help_map_builder.entry(instruction, &format!("\"{}\"", help));
}
write!(
&mut writer,
"pub(crate) const INSTRUCTIONS: phf::Map<&'static str, InstructionSignature> = {};\n",
instruction_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/instructions.txt");
write!(
&mut writer,
"pub(crate) const INSTRUCTION_DOCS: phf::Map<&'static str, &'static str> = {};\n",
help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/instructions_help.txt");
}
fn write_logictypes() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("logictypes.rs");
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
let mut logictype_set = ::phf_codegen::Set::new();
let mut logictype_lookup_map_builder = ::phf_codegen::Map::new();
let mut logictype_help_map_builder = ::phf_codegen::Map::new();
let l_infile = Path::new("data/logictypes.txt");
let l_contents = fs::read_to_string(l_infile).unwrap();
for line in l_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(3, ' ');
let name = it.next().unwrap();
let val_str = it.next().unwrap();
let val: Option<u16> = val_str.parse().ok();
let help = it.next().unwrap_or("").replace("\\n", "\n");
logictype_set.entry(name);
if let Some(v) = val {
logictype_lookup_map_builder.entry(v, &format!("\"{}\"", name));
}
logictype_help_map_builder.entry(name, &format!("\"{}\"", help));
}
let mut slotlogictype_set = ::phf_codegen::Set::new();
let mut slotlogictype_lookup_map_builder = ::phf_codegen::Map::new();
let mut slotlogictype_help_map_builder = ::phf_codegen::Map::new();
let sl_infile = Path::new("data/slotlogictypes.txt");
let sl_contents = fs::read_to_string(sl_infile).unwrap();
for line in sl_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(3, ' ');
let name = it.next().unwrap();
let val_str = it.next().unwrap();
let val: Option<u16> = val_str.parse().ok();
let help = it.next().unwrap_or("").replace("\\n", "\n");
slotlogictype_set.entry(name);
if let Some(v) = val {
slotlogictype_lookup_map_builder.entry(v, &format!("\"{}\"", name));
}
slotlogictype_help_map_builder.entry(name, &format!("\"{}\"", help));
}
write!(
&mut writer,
"pub(crate) const LOGIC_TYPES: phf::Set<&'static str> = {};\n",
logictype_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const LOGIC_TYPE_LOOKUP: phf::Map<u16, &'static str> = {};\n",
logictype_lookup_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const LOGIC_TYPE_DOCS: phf::Map<&'static str, &'static str> = {};\n",
logictype_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/logictypes.txt");
write!(
&mut writer,
"pub(crate) const SLOT_LOGIC_TYPES: phf::Set<&'static str> = {};\n",
slotlogictype_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const SLOT_TYPE_LOOKUP: phf::Map<u16, &'static str> = {};\n",
slotlogictype_lookup_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const SLOT_TYPE_DOCS: phf::Map<&'static str, &'static str> = {};\n",
slotlogictype_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/slotlogictypes.txt");
}
fn write_modes() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("modes.rs");
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
let mut batchmode_set = ::phf_codegen::Set::new();
let mut batchmode_lookup_map_builder = ::phf_codegen::Map::new();
let mut batchmode_help_map_builder = ::phf_codegen::Map::new();
let b_infile = Path::new("data/batchmodes.txt");
let b_contents = fs::read_to_string(b_infile).unwrap();
for line in b_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(3, ' ');
let name = it.next().unwrap();
let val_str = it.next().unwrap();
let val: Option<u16> = val_str.parse().ok();
let help = it.next().unwrap_or("").replace("\\n", "\n");
batchmode_set.entry(name);
if let Some(v) = val {
batchmode_lookup_map_builder.entry(v, &format!("\"{}\"", name));
}
batchmode_help_map_builder.entry(name, &format!("\"{}\"", help));
}
let mut reagentmode_set = ::phf_codegen::Set::new();
let mut reagentmode_lookup_map_builder = ::phf_codegen::Map::new();
let mut reagentmode_help_map_builder = ::phf_codegen::Map::new();
let r_infile = Path::new("data/reagentmodes.txt");
let r_contents = fs::read_to_string(r_infile).unwrap();
for line in r_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(3, ' ');
let name = it.next().unwrap();
let val_str = it.next().unwrap();
let val: Option<u16> = val_str.parse().ok();
let help = it.next().unwrap_or("").replace("\\n", "\n");
reagentmode_set.entry(name);
if let Some(v) = val {
reagentmode_lookup_map_builder.entry(v, &format!("\"{}\"", name));
}
reagentmode_help_map_builder.entry(name, &format!("\"{}\"", help));
}
write!(
&mut writer,
"pub(crate) const BATCH_MODES: phf::Set<&'static str> = {};\n",
batchmode_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const BATCH_MODE_LOOKUP: phf::Map<u16, &'static str> = {};\n",
batchmode_lookup_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const BATCH_MODE_DOCS: phf::Map<&'static str, &'static str> = {};\n",
batchmode_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/batchmodes.txt");
write!(
&mut writer,
"pub(crate) const REAGENT_MODES: phf::Set<&'static str> = {};\n",
reagentmode_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const REAGENT_MODE_LOOKUP: phf::Map<u16, &'static str> = {};\n",
reagentmode_lookup_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const REAGENT_MODE_DOCS: phf::Map<&'static str, &'static str> = {};\n",
reagentmode_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/reagentmodes.txt");
}
fn write_constants() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("constants.rs");
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
let mut constants_set = ::phf_codegen::Set::new();
let mut constants_help_map_builder = ::phf_codegen::Map::new();
let infile = Path::new("data/constants.txt");
let contents = fs::read_to_string(infile).unwrap();
for line in contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(2, ' ');
let name = it.next().unwrap();
let help = it.next().unwrap_or("").replace("\\n", "\n");
constants_set.entry(name);
constants_help_map_builder.entry(name, &format!("\"{}\"", help));
}
write!(
&mut writer,
"pub(crate) const CONSTANTS: phf::Set<&'static str> = {};\n",
constants_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const CONSTANTS_DOCS: phf::Map<&'static str, &'static str> = {};\n",
constants_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/constants.txt");
}
fn write_enums() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("enums.rs");
let output_file = File::create(dest_path).unwrap();
let mut writer = BufWriter::new(&output_file);
let mut enums_set = ::phf_codegen::Set::new();
let mut enums_help_map_builder = ::phf_codegen::Map::new();
let mut enums_lookup_map_builder = ::phf_codegen::Map::new();
let mut check_set = std::collections::HashSet::new();
let e_infile = Path::new("data/enums.txt");
let e_contents = fs::read_to_string(e_infile).unwrap();
for line in e_contents.lines().filter(|l| !l.trim().is_empty()) {
let mut it = line.splitn(2, ' ');
let name = it.next().unwrap();
let val_str = it.next().unwrap();
let val: Option<u16> = val_str.parse().ok();
let help = it.next().unwrap_or("").replace("\\n", "\n");
if !check_set.contains(name) {
enums_set.entry(name);
check_set.insert(name);
}
if let Some(v) = val {
enums_lookup_map_builder.entry(name, &format!("{}u16", v));
}
enums_help_map_builder.entry(name, &format!("\"{}\"", help));
}
write!(
&mut writer,
"pub(crate) const ENUMS: phf::Set<&'static str> = {};\n",
enums_set.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const ENUM_LOOKUP: phf::Map<&'static str, u8> = {};\n",
enums_lookup_map_builder.build()
)
.unwrap();
write!(
&mut writer,
"pub(crate) const ENUM_DOCS: phf::Map<&'static str, &'static str> = {};\n",
enums_help_map_builder.build()
)
.unwrap();
println!("cargo:rerun-if-changed=data/enums.txt");
println!("cargo:rerun-if-changed=data/enum_help.txt");
}
fn main() {
write_stationpedia();
write_instructions();
write_logictypes();
write_modes();
write_constants();
write_enums();
}