-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_snippets.py
137 lines (118 loc) · 3.82 KB
/
generate_snippets.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
import os
import string
import re
# encoding=utf8
# Device_Management
# Error_Handling
# Event_Management
# Execution_Control
# Memory_Management
# Occupancy
# Peer_Device_Memory_Access
# Stream_Management
# Thread_Management
# Unified_Addressing
# Double_Precision_Intrinsics
# Double_Precision_Mathematical_Functions
# Half Arithmetic Functions
# Integer_Intrinsics
# SIMD_Intrinsics
# Single_Precision_Intrinsics
# Single_Precision_Mathematical_Functions
# Type_Casting_Intrinsics
dirs=[
'CUDA_Runtime_API/Device_Management/',
'CUDA_Runtime_API/Error_Handling/',
'CUDA_Runtime_API/Event_Management/',
'CUDA_Runtime_API/Execution_Control/',
'CUDA_Runtime_API/Memory_Management/',
'CUDA_Runtime_API/Occupancy/',
'CUDA_Runtime_API/Peer_Device_Memory_Access/',
'CUDA_Runtime_API/Stream_Management/',
'CUDA_Runtime_API/Unified_Addressing/',
'CUDA_Math_API/Double_Precision_Intrinsics/',
'CUDA_Math_API/Double_Precision_Mathematical_Functions/',
'CUDA_Math_API/Integer_Intrinsics/',
'CUDA_Math_API/SIMD_Intrinsics/',
'CUDA_Math_API/Single_Precision_Mathematical_Functions/',
'CUDA_Math_API/Type_Casting_Intrinsics/',
'CUDA_Math_API/Single_Precision_Intrinsics/'
]
def keywords():
filename='func'
dir = 'keywords/'
file_buffer = open(dir + filename)
alllines = file_buffer.readlines()
for line in alllines:
# print line
line=line.strip('\n')
out_buffer = open(os.path.join(dir,line+'.sublime-snippet'), 'w')
out_buffer.write(
'<snippet> \n\
<content><![CDATA[\n' +
line +
'\n]]></content> \n\
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> \n\
<tabTrigger>'+ line +'</tabTrigger> \n\
<!-- Optional: Set a scope to limit where the snippet will trigger --> \n\
<scope>source.cuda-c++</scope> \n\
</snippet>')
out_buffer.close()
file_buffer.close()
keywords()
# <snippet>
# <content><![CDATA[
# __dadd_rd(${1:double x}, ${2:double y})
# ]]></content>
# <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
# <tabTrigger>__dadd_rd</tabTrigger>
# <!-- Optional: Set a scope to limit where the snippet will trigger -->
# <scope>source.cuda-c++</scope>
# </snippet>
# filename='func'
# for dir in dirs:
# # print d
# file_buffer = open(dir + filename)
# print 'open '+dir+filename
# # delete all files
# for f in os.listdir(dir):
# if f.find('snippet') != -1:
# os.remove(dir + f)
# # exit()
# alllines = file_buffer.readlines()
# for ln in xrange(0,len(alllines)):
# if re.search('(__.*__) .*', alllines[ln]):
# # print alllines[ln]
# reResult = re.search('(__.*__) (.*) (.*) \( (.*) \)', alllines[ln], re.U)
# if reResult:
# Zuoyongyu = reResult.group(1)
# Return = reResult.group(2)
# Funname = reResult.group(3)
# Params = reResult.group(4)
# NewParams = ''
# Params_split = Params.split(', ')
# # print len(Params_split)
# # cudaChooseDevice(${1:int* device}, ${2:const cudaDeviceProp* prop})
# for x in xrange(0,len(Params_split)):
# Params_split[x].strip()
# Params_split[x].replace(' ', ' ')
# for x in xrange(1,len(Params_split)):
# NewParams += '${' + str(x) + ':' + Params_split[x-1] + '}, '
# NewParams += '${' + str(len(Params_split)) + ':' + Params_split[len(Params_split) - 1] + '}'
# # NewParams +=
# # print NewParams
# out_buffer = open(dir+Funname + '.sublime-snippet', 'w')
# out_buffer.write(
# '<snippet> \n\
# <content><![CDATA[\n' +
# Funname + '(' + NewParams + ')' +
# # '${' + str(len(Params_split)+1) + ':/*' + alllines[ln + 1].strip() + '*/}' +
# '\n]]></content> \n\
# <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> \n\
# <tabTrigger>'+ Funname +'</tabTrigger> \n\
# <!-- Optional: Set a scope to limit where the snippet will trigger --> \n\
# <scope>source.cuda-c++</scope> \n\
# </snippet>')
# out_buffer.close()
# # exit()
# file_buffer.close()