@@ -315,6 +315,7 @@ def groupby(index, seq):
315
315
"CMPLX" ,
316
316
"CMPLXF" ,
317
317
"GB_PUBLIC" ,
318
+ "GB_restrict" ,
318
319
"GRAPHBLAS_H" ,
319
320
"GrB_INVALID_HANDLE" ,
320
321
"GrB_NULL" ,
@@ -426,6 +427,23 @@ def get_groups(ast):
426
427
seen .update (vals )
427
428
groups ["GxB typedef funcs" ] = sorted (vals , key = sort_key )
428
429
430
+ vals = []
431
+ next_i = - 1
432
+ for i , line in enumerate (lines ):
433
+ if i < next_i or line in seen :
434
+ continue
435
+ if "inline static" in line and ("GB" in line or "GrB" in line or "GxB" in line ):
436
+ val = [line ]
437
+ i += 1
438
+ while lines [i ] != "}" :
439
+ val .append (lines [i ])
440
+ i += 1
441
+ val .append (lines [i ])
442
+ next_i = i + 1
443
+ seen .update (val )
444
+ vals .append ("\n " .join (val ))
445
+ groups ["static inline" ] = vals
446
+
429
447
vals = {x for x in lines if "typedef" in x and "GrB" in x } - seen
430
448
assert not vals , ", " .join (sorted (vals ))
431
449
groups ["not seen" ] = sorted (set (lines ) - seen , key = sort_key )
@@ -579,6 +597,19 @@ def visit_Decl(self, node):
579
597
if isinstance (node .type , c_ast .FuncDecl ) and node .storage == ["extern" ]:
580
598
self .functions .append (node )
581
599
600
+ class FuncDefVisitorStaticInline (c_ast .NodeVisitor ):
601
+ def __init__ (self ):
602
+ self .functions = []
603
+
604
+ def visit_FuncDef (self , node ):
605
+ decl = node .decl
606
+ if (
607
+ isinstance (decl .type , c_ast .FuncDecl )
608
+ and decl .storage == ["static" ]
609
+ and decl .funcspec == ["inline" ]
610
+ ):
611
+ self .functions .append (node )
612
+
582
613
def handle_function_node (node ):
583
614
if generator .visit (node .type .type ) != "GrB_Info" :
584
615
raise ValueError (generator .visit (node ))
@@ -599,6 +630,7 @@ def handle_function_node(node):
599
630
group = {
600
631
# Apply our naming scheme
601
632
"GrB_Matrix" : "matrix" ,
633
+ "Matrix" : "matrix" ,
602
634
"GrB_Vector" : "vector" ,
603
635
"GxB_Scalar" : "scalar" ,
604
636
"SelectOp" : "selectop" ,
@@ -610,6 +642,7 @@ def handle_function_node(node):
610
642
"Type" : "type" ,
611
643
"UnaryOp" : "unary" ,
612
644
"IndexUnaryOp" : "indexunary" ,
645
+ "Iterator" : "iterator" ,
613
646
# "everything else" is "core"
614
647
"getVersion" : "core" ,
615
648
"Global" : "core" ,
@@ -636,16 +669,42 @@ def handle_function_node(node):
636
669
assert len (gxb_nodes ) == len (groups ["GxB methods" ])
637
670
assert len (gb_nodes ) == len (groups ["GB methods" ])
638
671
672
+ visitor = FuncDefVisitorStaticInline ()
673
+ visitor .visit (ast )
674
+ static_inline_nodes = visitor .functions
675
+ assert len (static_inline_nodes ) == len (groups ["static inline" ])
676
+ for node in static_inline_nodes :
677
+ # Sanity check
678
+ text = generator .visit (node ).strip ()
679
+ assert text in groups ["static inline" ]
680
+
681
+ def handle_static_inline (node ):
682
+ decl = node .decl
683
+ if decl .name in DEPRECATED :
684
+ return
685
+ text = generator .visit (node ).strip ()
686
+ if skip_complex and has_complex (text ):
687
+ return
688
+ return {
689
+ "name" : decl .name ,
690
+ "group" : "static inline" ,
691
+ "node" : node ,
692
+ "text" : text + "\n " ,
693
+ }
694
+
639
695
grb_funcs = (handle_function_node (node ) for node in grb_nodes )
640
696
gxb_funcs = (handle_function_node (node ) for node in gxb_nodes )
641
697
gb_funcs = (handle_function_node (node ) for node in gb_nodes )
698
+ si_funcs = (handle_static_inline (node ) for node in static_inline_nodes )
642
699
grb_funcs = [x for x in grb_funcs if x is not None ]
643
700
gxb_funcs = [x for x in gxb_funcs if x is not None ]
644
701
gb_funcs = [x for x in gb_funcs if x is not None ]
702
+ si_funcs = [x for x in si_funcs if x is not None ]
645
703
646
704
rv ["GrB methods" ] = sorted (grb_funcs , key = lambda x : sort_key (x ["text" ]))
647
705
rv ["GxB methods" ] = sorted (gxb_funcs , key = lambda x : sort_key (x ["text" ]))
648
706
rv ["GB methods" ] = sorted (gb_funcs , key = lambda x : sort_key (x ["text" ]))
707
+ rv ["static inline" ] = si_funcs # Should we sort these?
649
708
for key in groups .keys () - rv .keys ():
650
709
rv [key ] = groups [key ]
651
710
return rv
@@ -732,6 +791,10 @@ def handle_funcs(group):
732
791
text .append ("****************/" )
733
792
text .extend (handle_funcs (groups ["GxB methods" ]))
734
793
794
+ # Cython doesn't like compiling this; add to source.c instead (may work?)
795
+ # text.append("")
796
+ # text.extend(handle_funcs(groups["static inline"]))
797
+
735
798
text .append ("" )
736
799
text .append ("/* int DEFINES */" )
737
800
for item in sorted (defines , key = sort_key ):
@@ -744,7 +807,7 @@ def handle_funcs(group):
744
807
return text
745
808
746
809
747
- def create_source_text (* , char_defines = None ):
810
+ def create_source_text (groups , * , char_defines = None ):
748
811
if char_defines is None :
749
812
char_defines = CHAR_DEFINES
750
813
text = [
@@ -753,6 +816,9 @@ def create_source_text(*, char_defines=None):
753
816
]
754
817
for item in sorted (char_defines , key = sort_key ):
755
818
text .append (f"char *{ item } _STR = { item } ;" )
819
+ text .append ("" )
820
+ for node in groups ["static inline" ]:
821
+ text .append (node ["text" ])
756
822
return text
757
823
758
824
@@ -780,6 +846,7 @@ def main():
780
846
final_h = os .path .join (thisdir , "suitesparse_graphblas.h" )
781
847
final_no_complex_h = os .path .join (thisdir , "suitesparse_graphblas_no_complex.h" )
782
848
source_c = os .path .join (thisdir , "source.c" )
849
+ source_no_complex_c = os .path .join (thisdir , "source_no_complex.c" )
783
850
784
851
# Copy original file
785
852
print (f"Step 1: copy { args .graphblas } to { graphblas_h } " )
@@ -814,12 +881,18 @@ def main():
814
881
815
882
# Create source
816
883
print (f"Step 5: create { source_c } " )
817
- text = create_source_text ()
884
+ text = create_source_text (groups )
818
885
with open (source_c , "w" ) as f :
819
886
f .write ("\n " .join (text ))
820
887
888
+ # Create source (no complex)
889
+ print (f"Step 6: create { source_no_complex_c } " )
890
+ text = create_source_text (groups_no_complex )
891
+ with open (source_no_complex_c , "w" ) as f :
892
+ f .write ("\n " .join (text ))
893
+
821
894
# Check defines
822
- print ("Step 6 : check #define definitions" )
895
+ print ("Step 7 : check #define definitions" )
823
896
with open (graphblas_h ) as f :
824
897
text = f .read ()
825
898
define_lines = re .compile (r".*?#define\s+\w+\s+" )
0 commit comments