-
Notifications
You must be signed in to change notification settings - Fork 148
/
xed_mbuild.py
executable file
·2989 lines (2625 loc) · 113 KB
/
xed_mbuild.py
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
############################################################################
#See the execute() and work() functions down at the bottom of the file
#for the main routine.
############################################################################
## START OF IMPORTS SETUP
from __future__ import print_function
from pathlib import Path
import sys
import os
import re
import shutil
import copy
import time
import collections
import stat
def _fatal(m):
sys.stderr.write("\n\nXED ERROR: %s\n\n" % (m) )
sys.exit(1)
try:
import mbuild
except:
_fatal("xed_mbuild.py could not find/import mbuild." +
" Should be a sibling of the xed directory.")
import xed_build_common as xbc
try:
import xed_build_common as xbc
except:
_fatal("xed_mbuild.py could not import xed_build_common.py")
from pysrc import genutil
## END OF IMPORTS SETUP
############################################################################
def aq(s):
return mbuild.escape_string(s)
def check_mbuild_file(mbuild_file, sig_file):
if os.path.exists(sig_file):
old_hash = open(sig_file,"r").readline().strip()
else:
old_hash = ''
hash = mbuild.hash_list(open(sys.argv[0],'r').readlines())
f = open(sig_file, 'w')
f.write(hash)
f.close()
if hash == old_hash:
retval = False
mbuild.msgb("MBUILD INPUT FILE", "does not appear to have changes.")
else:
retval = True
mbuild.msgb("MBUILD INPUT FILE", "appears to have changes.")
return retval
###########################################################################
# generators
class generator_inputs_t(object):
def __init__(self, build_dir,
amd_enabled=True,
limit_strings=False,
encoder_chip='ALL'):
self.fields = ['dec-spine',
'dec-instructions',
'enc2-instructions',
'enc-instructions',
'dec-patterns',
'enc-patterns',
'enc-dec-patterns', # decode patterns used for encode
'fields',
'state',
'registers',
'widths',
'extra-widths',
'pointer-names',
'element-types',
'element-type-base',
'chip-models',
'conversion-table',
'cpuid',
'map-descriptions',
'errors',
]
self.encoder_chip = encoder_chip
self.files = {} # lists of input files per field type
self.priority = {} # field type -> int
# output file names. We concatenate all the input files of a
# given type. These get used in the command are internal to the
# execution of the generator.
self.file_name = {}
for fld in self.fields:
self.files[fld] = [] # list of input files
self.file_name[fld] = 'all-' + fld + '.txt'
self.renamed = False
self.intermediate_dir = None
self.set_intermediate_dir(build_dir)
self.use_intermediate_files()
self.amd_enabled = amd_enabled
self.limit_strings = limit_strings
def add_file(self, file_type, file_name, priority=1):
"""Add a specific type of file to the right list"""
curp = 1
if file_type in self.priority:
curp = self.priority[file_type]
if curp > priority:
mbuild.msgb("Skipping low priority file for type %s: %s" %
(file_type, file_name))
return
elif curp < priority:
# new higher priority file blows away the list of files for
# this file type.
mbuild.vmsgb(1, "Clearing file list for type %s: [ %s ]" %
(file_type,
", ".join(self.files[file_type])))
self.files[file_type] = []
self.priority[file_type]=priority
if file_name in self.files[file_type]:
xbc.cdie('duplicate line: {}:{}'.format(file_type,file_name))
self.files[file_type].append(file_name)
def remove_file(self, file_type, file_name):
"""Remove a specific file"""
found = False
for f in list(self.files[file_type]):
if os.path.samefile(f, file_name):
mbuild.vmsgb(1, f"REMOVE FILE ({file_type})", f)
self.files[file_type].remove(f)
found = True
if not found:
xbc.cdie("Invalid type of file " +
"(%s) or file name (%s) not found in: %s" % (file_type,
file_name, self.files[file_type]) )
def clear_files(self,file_type):
"""Remove a specific type of file"""
try:
self.files[file_type] = []
mbuild.msgb("REMOVING FILE TYPE", file_type)
except:
xbc.cdie("Invalid type of file (%s) not found: " %
(file_type))
def all_input_files(self):
"""Return a list of all the input file names so we can hook up
the dependences"""
fnames = []
for flist in iter(self.files.values()):
fnames.extend(flist)
fnames.sort()
return fnames
def set_intermediate_dir(self, build_dir):
self.intermediate_dir = mbuild.join(build_dir,'dgen')
mbuild.cmkdir(self.intermediate_dir)
def use_intermediate_files(self):
"""Prefix al the files by the intermediate directory name"""
# just do this once
if self.renamed:
return
self.renamed = True
for f in self.fields:
ofn = mbuild.join(self.intermediate_dir,self.file_name[f])
self.file_name[f] = ofn # update file name-- only call once!
def concatenate_input_files(self,env):
"""Concatenate all the files of each type"""
for f in self.fields:
self.concatenate_one_set_of_files(env,
self.file_name[f],
self.files[f])
def decode_command(self, xedsrc, extra_args=None):
"""Produce a decoder generator command"""
s = []
s.append( '%(pythonarg)s' )
# s.append("-3") # python3.0 compliance checking using python2.6
s.append(aq(mbuild.join(xedsrc,'pysrc','generator.py')))
if self.limit_strings:
s.append('--limit-enum-strings')
s.append('--spine ' + aq(self.file_name['dec-spine']))
s.append('--isa ' + aq(self.file_name['dec-instructions']))
s.append('--patterns ' + aq(self.file_name['dec-patterns']))
s.append('--input-fields ' + aq(self.file_name['fields']))
s.append('--input-state ' + aq(self.file_name['state']))
s.append('--chip-models ' + aq(self.file_name['chip-models']))
s.append('--ctables ' + aq(self.file_name['conversion-table']))
s.append('--input-regs ' + aq(self.file_name['registers']))
s.append('--input-widths ' + aq(self.file_name['widths']))
s.append('--input-extra-widths ' +
aq(self.file_name['extra-widths']))
s.append('--input-element-types ' +
aq(self.file_name['element-types']))
s.append('--input-element-type-base ' +
aq(self.file_name['element-type-base']))
s.append('--input-pointer-names ' +
aq(self.file_name['pointer-names']))
s.append('--cpuid ' +
aq(self.file_name['cpuid']))
s.append('--map-descriptions ' +
aq(self.file_name['map-descriptions']))
s.append('--input-errors ' +
aq(self.file_name['errors']))
if extra_args:
s.append(extra_args)
return ' '.join(s)
def encode_command(self, env, xedsrc, extra_args=None):
"""Produce an encoder generator command"""
s = []
s.append( env['pythonarg'] )
# s.append("-3") # python3.0 compliance checking using python2.6
s.append( aq(mbuild.join(xedsrc,'pysrc', 'read-encfile.py')))
s.append('--isa %s' % aq(self.file_name['enc-instructions']))
s.append('--enc-patterns %s' % aq(self.file_name['enc-patterns']))
s.append('--enc-dec-patterns %s' %
aq(self.file_name['enc-dec-patterns']))
s.append('--input-fields %s' % aq(self.file_name['fields']))
s.append('--input-state %s' % aq(self.file_name['state']))
s.append('--input-regs %s' % aq(self.file_name['registers']))
s.append('--map-descriptions ' + aq(self.file_name['map-descriptions']))
s.append('--chip-models ' + aq(self.file_name['chip-models']))
s.append('--chip ' + aq(self.encoder_chip))
if not env['amd_enabled']:
s.append('--no-amd')
if extra_args:
s.append( extra_args)
ext = Path(env['xedext_dir']).resolve()
if ext.exists():
s.append('--xedext-dir ' + str(ext))
return ' '.join(s)
def concatenate_one_set_of_files(self, env, target, inputs):
"""Concatenate input files creating the target file."""
try:
mbuild.vmsgb(2, "CONCAT", "%s <-\n\t\t%s" % (target ,
'\n\t\t'.join(inputs)))
output = open(target,"w")
for f in inputs:
if os.path.exists(f):
output.write("\n\n###FILE: %s\n\n" % (f))
for line in open(f,'r').readlines():
line = line.rstrip()
#replace the possible symbolic path %(cur_dir)s
#FIXME: could have used env's expand_string method,
#for src_dir and cur_dir.
file_dir = os.path.dirname(f)
line = line.replace('%(cur_dir)s', file_dir)
line = line.replace('%(xed_dir)s', env['src_dir'])
output.write(line + "\n")
else:
xbc.cdie("Could not read input file: " + f)
output.close()
except xbc.xed_exception_t as e:
raise # re-raise exception
except:
xbc.cdie("Could not write file %s from inputs: %s" %
( target, ', '.join(inputs)))
def run_generator_preparation(gc, env):
"""Prepare to run the encode and decode table generators"""
if env == None:
return (1, ['no env!'])
xedsrc = env['src_dir']
build_dir = env['build_dir']
gc.concatenate_input_files(env)
mbuild.touch(env.build_dir_join('dummy-prep'))
return (0, [] )
def read_file_list(fn):
a = []
for f in open(fn,'r').readlines():
a.append(f.rstrip())
return a
def run_decode_generator(gc, env):
"""Run the decode table generator. This function is executed as
required by the work_queue."""
if env == None:
return (1, ['no env!'])
xedsrc = aq(env['src_dir'])
build_dir = aq(env['build_dir'])
debug = ""
other_args = " ".join(env['generator_options'])
gen_extra_args = "--gendir %s --xeddir %s %s %s" % (build_dir,
xedsrc, debug,
other_args)
if env['compress_operands']:
gen_extra_args += " --compress-operands"
if env['add_orphan_inst_to_future_chip']:
gen_extra_args += " --add-orphan-inst-to-future-chip"
cmd = env.expand(gc.decode_command(xedsrc, gen_extra_args))
mbuild.vmsgb(3, "DEC-GEN", cmd)
(retval, output, error_output) = mbuild.run_command(cmd,
separate_stderr=True)
oo = env.build_dir_join('DEC-OUT.txt')
oe = env.build_dir_join('DEC-ERR.txt')
xbc.write_file(oo, output)
xbc.write_file(oe, error_output)
if retval == 0:
list_of_files = read_file_list(gc.dec_output_file)
mbuild.hash_files(list_of_files, gc.dec_hash_file)
mbuild.vmsgb(1, "DEC-GEN", "Return code: " + str(retval))
return (retval, error_output )
def run_encode_generator(gc, env):
"""Run the encoder table generator. This function is executed as
required by the work_queue."""
if env == None:
return (1, ['no env!'])
xedsrc = aq(env['src_dir'])
build_dir = aq(env['build_dir'])
gen_extra_args = "--gendir %s --xeddir %s" % (build_dir, xedsrc)
cmd = gc.encode_command(env, xedsrc, gen_extra_args)
mbuild.vmsgb(3, "ENC-GEN", cmd)
(retval, output, error_output) = mbuild.run_command(cmd,
separate_stderr=True)
oo = env.build_dir_join('ENC-OUT.txt')
oe = env.build_dir_join('ENC-ERR.txt')
xbc.write_file(oo, output)
xbc.write_file(oe, error_output)
if retval == 0:
list_of_files = read_file_list(gc.enc_output_file)
mbuild.hash_files(list_of_files, gc.enc_hash_file)
mbuild.vmsgb(1, "ENC-GEN", "Return code: " + str(retval))
return (retval, [] )
def _encode_command2(args):
"""Produce an encoder2 generator command."""
s = []
s.append( '%(pythonarg)s' )
s.append( aq(mbuild.join(args.xeddir, 'pysrc', 'enc2gen.py')))
s.append('--xeddir %s' % aq(args.xeddir))
s.append('--gendir %s' % aq(args.gendir))
s.extend( args.config.as_args() )
if args.test_checked_interface:
s.append('-chk' )
if args.operand_check:
s.append('-operand-check')
s.append('--output-file-list %s' % aq(args.enc2_output_file))
return ' '.join(s)
def run_encode_generator2(args, env):
"""Run the encoder2 table generator. This function is executed as
required by the work_queue."""
if env == None:
return (1, ['no env!'])
args.xeddir = aq(env['src_dir'])
# we append our own paths in the generator
args.gendir = aq(env['libxed_build_dir'])
cmd = env.expand( _encode_command2(args) )
mbuild.vmsgb(3, "ENC2-GEN", cmd)
(retval, output, error_output) = mbuild.run_command(cmd,
separate_stderr=True)
oo = env.build_dir_join('ENC2-OUT.txt')
oe = env.build_dir_join('ENC2-ERR.txt')
xbc.write_file(oo, output)
xbc.write_file(oe, error_output)
if retval == 0:
list_of_files = read_file_list(args.enc2_output_file)
mbuild.hash_files(list_of_files, args.enc2_hash_file)
mbuild.vmsgb(1, "ENC2-GEN", "Return code: " + str(retval))
return (retval, [] )
def need_to_rebuild(fn,sigfile):
rebuild = False
if not os.path.exists(fn):
return True
list_of_files = read_file_list(fn)
if mbuild.file_hashes_are_valid(list_of_files, sigfile):
return False
return True
###########################################################################
# legal header tagging
def legal_header_tagging(env):
if 'apply-header' not in env['targets']:
return
source_files = [
mbuild.join(env['src_dir'],'examples','*.cpp'),
mbuild.join(env['src_dir'],'examples','*.c'),
mbuild.join(env['src_dir'],'examples','*.[hH]'),
mbuild.join(mbuild.join(env['build_dir'],'*.h')),
mbuild.join(env['src_dir'],'src','*','*.c'),
mbuild.join(env['src_dir'],'include', 'private','*.h'),
mbuild.join(env['src_dir'],'include', 'public', 'xed', '*.h') ]
data_files = [
mbuild.join(env['src_dir'],'examples','*.py'),
mbuild.join(env['src_dir'],'scripts','*.py'),
mbuild.join(env['src_dir'],'pysrc','*.py'),
mbuild.join(env['src_dir'],'*.py') ]
# find and classify the files in datafiles directories
for root,dirs,files in os.walk( mbuild.join(env['src_dir'],'datafiles') ):
for f in files :
fn = mbuild.join(root,f)
if 'test' not in fn:
if re.search(r'[~]$',fn):
# skip backup files
continue
elif re.search(r'[.][ch]$',fn):
source_files.append(fn)
else:
data_files.append(fn)
if env.on_windows():
xbc.cdie("[ERROR], TAGGING THE IN-USE PYTHON FILES DOES " +
"NOT WORK ON WINDOWS.")
with open(mbuild.join(env['src_dir'],'misc',
'legal-header.txt'), 'r') as f:
legal_header = f.readlines()
header_tag_files(env, source_files, legal_header, script_files=False)
header_tag_files(env, data_files, legal_header, script_files=True)
mbuild.msgb("STOPPING", "after %s" % 'header tagging')
xbc.cexit(0)
def header_tag_files(env, files, legal_header, script_files=False):
"""Apply the legal_header to the list of files"""
try:
import apply_legal_header
except:
xbc.cdie("XED ERROR: mfile.py could not find scripts directory")
for g in files:
print("G: ", g)
for f in mbuild.glob(g):
print("F: ", f)
if script_files:
apply_legal_header.apply_header_to_data_file(legal_header, f)
else:
apply_legal_header.apply_header_to_source_file(legal_header, f)
###########################################################################
# Doxygen build
def get_kit(env):
if xbc.installing(env):
return env['ikit'].kit
return env['wkit'].kit
def doxygen_subs(env,api_ref=True):
'''Create substitutions dictionary for customizing doxygen run'''
subs = {}
subs['XED_TOPSRCDIR'] = aq(env['src_dir'])
dir = get_kit(env)
if not os.path.exists(dir):
xbc.cdie("Cannot find kit directory ({}) when building docs.".format(dir))
subs['XED_KITDIR'] = aq(dir)
subs['XED_GENDOC'] = aq(env['doxygen_install'])
if api_ref:
subs['XED_INPUT_TOP'] = aq(env.src_dir_join(mbuild.join('docsrc',
'xed-doc-top.txt')))
else:
subs['XED_INPUT_TOP'] = aq(env.src_dir_join(mbuild.join('docsrc',
'xed-build.txt')))
#subs['XED_HTML_HEADER'] = aq(env.src_dir_join(mbuild.join('docsrc',
# 'xed-doxygen-header.txt')))
if env['doxygen_internal']:
subs['XED_EXTERNAL'] = ''
else:
subs['XED_EXTERNAL'] = 'EXTERNAL'
return subs
def make_doxygen_build(env, work_queue):
"""Make the doxygen how-to-build-xed manual"""
if 'doc-build' not in env['targets']:
return
mbuild.msgb("XED BUILDING 'build' DOCUMENTATION")
e2 = copy.deepcopy(env)
e2['doxygen_cmd']= e2['doxygen']
if e2['doxygen_install'] == '':
d= mbuild.join(e2['build_dir'],'doc')
else:
d = env['doxygen_install']
e2['doxygen_install'] = mbuild.join(d, 'build-manual')
mbuild.msgb("BUILDING BUILD MANUAL", e2['doxygen_install'])
mbuild.cmkdir(e2['doxygen_install'])
e2['doxygen_config'] = e2.src_dir_join(mbuild.join('docsrc',
'Doxyfile.build'))
subs = doxygen_subs(e2,api_ref=False)
e2['doxygen_top_src'] = subs['XED_INPUT_TOP']
inputs = [ subs['XED_INPUT_TOP'] ]
inputs.append( e2['mfile'] )
mbuild.doxygen_run(e2, inputs, subs, work_queue, 'dox-build')
def create_doxygen_api_documentation(env, work_queue):
# After applying the legal header, create the doxygen from the kit
# files, and place the output right in the kit.
if 'doc' in env['targets']:
if xbc.installing(env):
kitdoc = env['ikit'].doc
else:
kitdoc = env['wkit'].doc
make_doxygen_api(env, work_queue, kitdoc)
if env['doxygen_install']:
make_doxygen_api(env, work_queue, env['doxygen_install'])
def make_doxygen_api(env, work_queue, install_dir):
"""We may install in the kit or elsewhere using files from the kit"""
mbuild.msgb("XED BUILDING 'api' DOCUMENTATION")
e2 = copy.deepcopy(env)
e2['doxygen_cmd']= e2['doxygen']
e2['doxygen_install'] = mbuild.join(install_dir,'ref-manual')
mbuild.cmkdir(e2['doxygen_install'])
e2['doxygen_config'] = e2.src_dir_join(mbuild.join('docsrc','Doxyfile'))
subs = doxygen_subs(e2,api_ref=True)
e2['doxygen_top_src'] = subs['XED_INPUT_TOP']
inputs = []
inputs.append(subs['XED_INPUT_TOP'])
kitdir = get_kit(e2)
inputs.extend( mbuild.glob(kitdir,'include', 'xed', '*'))
inputs.extend( mbuild.glob(kitdir,'examples','*.c'))
inputs.extend( mbuild.glob(kitdir,'examples','*.cpp'))
inputs.extend( mbuild.glob(kitdir,'examples','*.[Hh]'))
inputs.append( e2['mfile'] )
mbuild.doxygen_run(e2, inputs, subs, work_queue, 'dox-ref')
def setup_hooks(env):
"""replaces XED/MBUILD local git hook scripts with scripts scripted hooks"""
xed_path = env['src_dir']
xed_pre_commit = Path(xed_path, 'scripts', 'git-hooks', 'pre-commit.py').resolve(strict=True)
pre_commit = Path(xed_path, '.git', 'hooks', 'pre-commit').resolve()
mbuild.msgb('setup xed pre-commit hook', f'copy {xed_pre_commit} to {pre_commit}')
shutil.copyfile(xed_pre_commit, pre_commit)
shutil.copymode(xed_pre_commit, pre_commit)
mbuild_path = genutil.find_dir('mbuild')
pre_commit = Path(mbuild_path, '.git', 'hooks', 'pre-commit').resolve()
mbuild.msgb('setup mbuild pre-commit hook', f'copy {xed_pre_commit} to {pre_commit}')
shutil.copyfile(xed_pre_commit, pre_commit)
shutil.copymode(xed_pre_commit, pre_commit)
def mkenv():
"""External entry point: create the environment"""
mbuild.check_python_version(3,9)
# create an environment, parse args
env = mbuild.env_t()
standard_defaults = dict( doxygen_install='',
doxygen='',
doxygen_internal=False,
clean=False,
die_on_errors=True,
xed_messages=False,
xed_asserts=False,
pedantic=True,
clr=False,
use_werror=True,
security_level=2,
show_dag=False,
ext=[],
extf=[],
xedext_dir='%(xed_dir)s/../xedext',
tests_ext=[],
default_isa='',
avx=True,
avx512=True,
ivb=True,
hsw=True,
mpx=True,
cet=True,
skl=True,
skx=True,
clx=True,
cpx=True,
cnl=True,
icl=True,
tgl=True,
adl=True,
spr=True,
srf=True, # sierra forest
gnr=True, # granite rapids
dmr=True, # Diamond rapids
arl=True, # arrow lake
lnl=True, # lunar lake
cwf=True, # clearwater forest
ptl=True, # panther lake
emr=True, # emerald rapids
future=True,
knl=True,
knm=True,
lakefield=True,
bdw=True,
dbghelp=False,
install_dir=None,
prefix_dir='',
prefix_lib_dir='lib',
kit_kind='base',
win=False,
amd_enabled=True,
encoder_chip='ALL',
via_enabled=True,
encoder=True,
decoder=True,
dev=False,
generator_options=[],
legal_header=None,
pythonarg=None,
ld_library_path=[],
ld_library_path_for_tests=[],
use_elf_dwarf=False,
use_elf_dwarf_precompiled=False,
limit_strings=False,
strip='strip',
pti_test=False,
verbose = 1,
compress_operands=False,
add_orphan_inst_to_future_chip=False,
test_perf=False,
example_linkflags='',
example_flags='',
example_rpaths=[],
android=False,
copy_libc=False,
static_stripped=False,
set_copyright=False,
asan=False,
enc2=False,
enc2_test=False,
enc2_test_checked=False,
enc2_operands_checked=False,
py_export=False,
first_lib=None,
last_lib=None,
setup_hooks=False)
env['xed_defaults'] = standard_defaults
env.set_defaults(env['xed_defaults'])
return env
def xed_args(env):
"""For command line invocation: parse the arguments"""
env.parser.add_option("--android",
dest="android",
action="store_true",
help="Android build (avoid rpath for examples)")
env.parser.add_option("--copy-runtime-libs",
dest="copy_libc",
action="store_true",
help="Copy the libc to the kit." +
" Rarely necessary if building on old linux " +
"dev systems. Default: false")
env.parser.add_option("--example-linkflags",
dest="example_linkflags",
action="store",
help="Extra link flags for the examples")
env.parser.add_option("--example-flags",
dest="example_flags",
action="store",
help="Extra compilation flags for the examples")
env.parser.add_option("--example-rpath",
dest="example_rpaths",
action="append",
help="Extra rpath dirs for examples")
env.parser.add_option("--doxygen-install",
dest="doxygen_install",
action="store",
help="Doxygen installation directory")
env.parser.add_option("--doxygen",
dest="doxygen",
action="store",
help="Doxygen command name")
env.parser.add_option("--doxygen-internal",
dest="doxygen_internal",
action="store_true",
help="Create internal version of build documentation (just changes paths for git repos)")
env.parser.add_option("-c","--clean",
dest="clean",
action="store_true",
help="Clean targets")
env.parser.add_option("--keep-going", '-k',
action="store_false",
dest="die_on_errors",
help="Keep going after errors occur when building")
env.parser.add_option("--messages",
action="store_true",
dest="xed_messages",
help="Enable use xed's debug messages")
env.parser.add_option("--no-pedantic",
action="store_false",
dest="pedantic",
help="Disable -pedantic (gnu/clang compilers).")
env.parser.add_option("--asserts",
action="store_true",
dest="xed_asserts",
help="Enable use xed's asserts")
env.parser.add_option("--clr",
action="store_true",
dest="clr",
help="Compile for Microsoft CLR")
env.parser.add_option("--no-werror",
action="store_false",
dest="use_werror",
help="Disable use of -Werror on GNU compiles")
env.parser.add_option("--security-level",
dest="security_level",
action="store",
type=int,
help="Security build level: 1(Medium), 2(High), 3(Highest)")
env.parser.add_option("--show-dag",
action="store_true",
dest="show_dag",
help="Show the dependence DAG")
env.parser.add_option("--ext",
action="append",
dest="ext",
help="Add extension files of the form " +
"pattern-name:file-name.txt")
env.parser.add_option("--extf",
action="append",
dest="extf",
help="Add extension configuration files " +
"that contain lines of form pattern-name:file-name.txt. All files " +
"references will be made relative to the directory in which the " +
"config file is located.")
env.parser.add_option("--xedext-dir",
action="store",
dest="xedext_dir",
help="XED extension dir")
env.parser.add_option("--tests-extension",
action="append",
dest="tests_ext",
help="Tests directories extension")
env.parser.add_option("--default-isa-extf",
action="store",
dest="default_isa",
help="Override the default ISA files.cfg file")
env.parser.add_option("--no-avx",
action="store_false",
dest="avx",
help="Do not include AVX (nor down-stream unrelated technologies).")
env.parser.add_option("--no-avx512",
action="store_false",
dest="avx512",
help="Do not include AVX512 (nor down-stream unrelated technologies).")
env.parser.add_option("--no-ivb",
action="store_false",
dest="ivb",
help="Do not include IVB.")
env.parser.add_option("--no-hsw",
action="store_false",
dest="hsw",
help="Do not include HSW.")
env.parser.add_option("--no-mpx",
action="store_false",
dest="mpx",
help="Do not include MPX.")
env.parser.add_option("--no-cet",
action="store_false",
dest="cet",
help="Do not include CET.")
env.parser.add_option("--no-knl",
action="store_false",
dest="knl",
help="Do no include KNL AVX512{PF,ER}.")
env.parser.add_option("--no-knm",
action="store_false",
dest="knm",
help="Do not include KNM.")
env.parser.add_option("--no-skl",
action="store_false",
dest="skl",
help="Do not include SKL (Skylake Client).")
env.parser.add_option("--no-skx",
action="store_false",
dest="skx",
help="Do not include SKX (Skylake Server).")
env.parser.add_option("--no-clx",
action="store_false",
dest="clx",
help="Do not include CLX (Cascade Lake Server).")
env.parser.add_option("--no-cpx",
action="store_false",
dest="cpx",
help="Do not include CPX (Cooper Lake Server).")
env.parser.add_option("--no-cnl",
action="store_false",
dest="cnl",
help="Do not include CNL.")
env.parser.add_option("--no-icl",
action="store_false",
dest="icl",
help="Do not include ICL.")
env.parser.add_option("--no-tgl",
action="store_false",
dest="tgl",
help="Do not include TGL.")
env.parser.add_option("--no-adl",
action="store_false",
dest="adl",
help="Do not include ADL.")
env.parser.add_option("--no-spr",
action="store_false",
dest="spr",
help="Do not include SPR.")
env.parser.add_option("--no-future",
action="store_false",
dest="future",
help="Do not include future NI.")
env.parser.add_option("--no-amd",
action="store_false",
dest="amd_enabled",
help="Disable AMD public instructions")
env.parser.add_option("--no-via",
action="store_false",
dest="via_enabled",
help="Disable VIA public instructions")
env.parser.add_option("--no-lakefield",
action="store_false",
dest="lakefield",
help="Disable lakefield public instructions")
env.parser.add_option("--no-gnr",
action="store_false",
dest="gnr",
help="Disable Granite Rapids public instructions")
env.parser.add_option("--no-dmr",
action="store_false",
dest="dmr",
help="Disable Diamond Rapids public instructions")
env.parser.add_option("--no-srf",
action="store_false",
dest="srf",
help="Disable Sierra Forest public instructions")
env.parser.add_option("--no-cwf",
action="store_false",
dest="cwf",
help="Disable Clearwater Forest public instructions")
env.parser.add_option("--no-ptl",
action="store_false",
dest="ptl",
help="Disable Panther Lake public instructions")
env.parser.add_option("--no-emr",
action="store_false",
dest="emr",
help="Disable Emerald Rapids public instructions")
env.parser.add_option("--no-arl",
action="store_false",
dest="arl",
help="Disable Arrow Lake public instructions")
env.parser.add_option("--no-lnl",
action="store_false",
dest="lnl",
help="Disable Lunar Lake public instructions")
env.parser.add_option("--dbghelp",
action="store_true",
dest="dbghelp",
help="Use dbghelp.dll on windows.")
env.parser.add_option("--prefix",
dest="prefix_dir",
action="store",
help="XED System install directory.")
env.parser.add_option("--prefix-lib-dir",
dest="prefix_lib_dir",
action="store",
help="library subdirectory name. Default: lib")
env.parser.add_option("--install-dir",
dest="install_dir",
action="store",
help="XED Install directory. " +
"Default: kits/xed-install-date-os-cpu")
env.parser.add_option("--kit-kind",
dest="kit_kind",
action="store",
help="Kit version string. " +
"The default is 'base'")
env.parser.add_option("--limit-strings",
action="store_true",
dest="limit_strings",
help="Remove some strings to save space.")
env.parser.add_option("--no-encoder",
action="store_false",
dest="encoder",
help="Disable the encoder")
env.parser.add_option("--no-decoder",
action="store_false",
dest="decoder",
help="Disable the decoder")
env.parser.add_option("--generator-options",
action="append",
dest="generator_options",
help="Options to pass through for " +
"the decode generator")
env.parser.add_option("--legal-header",
action="store",
dest="legal_header",
help="Use this special legal header " +
"on public header files and examples.")
env.parser.add_option("--python",
action="store",
dest="pythonarg",
help="Use a specific version of python " +
"for subprocesses.")
env.parser.add_option("--ld-library-path",
action="append",
dest="ld_library_path",
help="Specify additions to LD_LIBRARY_PATH " +
"for use when running ldd and making kits")
env.parser.add_option("--ld-library-path-for-tests",
action="append",
dest="ld_library_path_for_tests",
help="Specify additions to LD_LIBRARY_PATH " +
"for use when running the tests")
# elf.h is different than libelf.h.
env.parser.add_option("--elf-dwarf", "--dwarf",
action="store_true",
dest="use_elf_dwarf",
help="Use libelf/libdwarf. (Linux only)")
env.parser.add_option("--elf-dwarf-precompiled",
action="store_true",
dest="use_elf_dwarf_precompiled",
help="Use precompiled libelf/libdwarf from " +
" the XED source distribution." +
" This is the currently required" +
" if you are installing a kit." +
" Implies the --elf-dwarf knob."
" (Linux only)")
env.parser.add_option("--strip",
action="store",
dest="strip",
help="Path to strip binary. (Linux only)")
env.parser.add_option("--pti-test",
action="store_true",
dest="pti_test",
help="INTERNAL TESTING OPTION.")
env.parser.add_option("--compress-operands",
action="store_true",
dest="compress_operands",
help="use bit-fields to compress the "+
"operand storage.")
env.parser.add_option("--add-orphan-inst-to-future-chip",