VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/gendiffcode.py@ 78375

Last change on this file since 78375 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.0 KB
Line 
1# Copyright (c) 2001, Stanford University
2# All rights reserved.
3#
4# See the file LICENSE.txt for information on redistributing this software
5
6from __future__ import print_function
7import sys
8
9def main():
10 name = sys.argv[1]
11 Name = sys.argv[2]
12
13 print("""/* This code is AUTOGENERATED!!! */
14
15#include "state.h"
16#include "state_internals.h\"""")
17
18 print("""
19void crState%(Name)sDiff(CR%(Name)sBits *b, CRbitvalue *bitID,
20 CRContext *fromCtx, CRContext *toCtx)
21{
22 PCRStateTracker pState = fromCtx->pStateTracker;
23 CR%(Name)sState *from = &(fromCtx->%(name)s);
24 CR%(Name)sState *to = &(toCtx->%(name)s);"""%vars())
25 gendiffcode("state_%s.txt"%(name.lower()), name, docopy=1, doinvalid=0)
26 print("""}
27
28void crState%(Name)sSwitch(CR%(Name)sBits *b, CRbitvalue *bitID,
29 CRContext *fromCtx, CRContext *toCtx)
30{
31 PCRStateTracker pState = fromCtx->pStateTracker;
32 CR%(Name)sState *from = &(fromCtx->%(name)s);
33 CR%(Name)sState *to = &(toCtx->%(name)s);"""%vars())
34 gendiffcode("state_%s.txt"%(Name.lower()), Name, docopy=0, doinvalid=1)
35 print("}\n")
36
37def gendiffcode(fname, state_name, docopy, doinvalid):
38 target = "to"
39 current = "from"
40 bit = "b"
41 extrabit = ""
42 tab = "\t"
43 current_guard = ""
44 current_dependency = ""
45
46 v_types = {
47 'l': 'GLboolean',
48 'b': 'GLbyte',
49 'ub': 'GLubyte',
50 's': 'GLshort',
51 'us': 'GLushort',
52 'i': 'GLint',
53 'ui': 'GLuint',
54 'f': 'GLfloat',
55 'd': 'GLdouble'
56 }
57
58 FILE = open(sys.argv[3]+"/"+fname, "r")
59
60 print(""" unsigned int j, i;
61 CRbitvalue nbitID[CR_MAX_BITARRAY];
62 CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
63 for (j = 0; j<CR_MAX_BITARRAY; j++)
64 nbitID[j] = ~bitID[j];
65 i = 0; /* silence compiler */""")
66
67 import re
68 for line in FILE:
69 line = line.rstrip()
70
71 if re.match("#", line):
72 continue
73
74## Handle text dump
75 m = re.match("\+(.*)", line)
76 if m:
77 if doinvalid:
78 continue
79 line = m.group(1)
80
81 else:
82 m = re.match("-(.*)", line)
83 if m:
84 if docopy:
85 continue
86 line = m.group(1)
87
88 m = re.match(">(.*)", line)
89 if m:
90 text = m.group(1)
91 if re.search("}", line):
92 tab = tab[:-1]
93 print(tab+text)
94 if re.search("{", line):
95 tab = tab+"\t"
96 continue
97
98## Handle commands
99
100 m = re.search("%target=(\w*)", line)
101 if m:
102 target = m.group(1)
103 m = re.search("%current=(\w*)", line)
104 if m:
105 current = m.group(1)
106 m = re.search("%bit=(\w*)", line)
107 if m:
108 bit = m.group(1)
109 m = re.search("%extrabit=(\w*)", line)
110 if m:
111 extrabit = m.group(1)
112
113 if re.search("%flush", line):
114 if current_guard != "":
115 print(tab+"CLEARDIRTY(%(bit)s->%(current_guard)s, nbitID);"%vars())
116 tab = tab[:-1]
117 print(tab+"}")
118 if docopy and current_dependency != "":
119 tab = tab[:-1]
120 print(tab+"}")
121 current_guard = ""
122 current_dependency = ""
123 if re.search("%", line):
124 continue
125
126## Load the line
127 (dependency, guardbit, members, func) = \
128 (re.split(":", line) + ["", ""])[0:4]
129 func = func.rstrip()
130
131## Close the guardbit and dependency
132 if current_guard != "" and current_guard != guardbit:
133 print(tab+"CLEARDIRTY(%(bit)s->%(current_guard)s, nbitID);"%vars())
134 tab = tab[:-1]
135 print(tab+"}")
136 if docopy and current_dependency != "" and current_dependency != dependency:
137 tab = tab[:-1]
138 print(tab+"}")
139
140## Open the dependency if
141 if docopy and current_dependency != dependency and dependency != "":
142 print(tab+"if (%(target)s->%(dependency)s)\n%(tab)s{"%vars())
143 tab = tab+"\t"
144 current_dependency = dependency
145
146## Open the guard if
147 if docopy and current_dependency != dependency and dependency != "":
148 print(tab+"if ($(target)s->%(dependency)s)\n%(tab)s{"%vars())
149 tab = tab+"\t"
150
151 if current_guard != guardbit and guardbit != "":
152 print(tab+"if (CHECKDIRTY(%(bit)s->%(guardbit)s, bitID))\n%(tab)s{"%vars())
153 tab = tab+"\t"
154 if members[0] != "*" and guardbit[0:6] == "enable":
155 print(tab+"glAble able[2];")
156 print(tab+"able[0] = pState->diff_api.Disable;")
157 print(tab+"able[1] = pState->diff_api.Enable;")
158
159 current_dependency = dependency
160 current_guard = guardbit
161
162## Handle text dump
163 if members[0] == "*":
164 print(tab+members[1:])
165 else:
166 ## Parse the members variable
167 mainelem = re.split(",", members)
168 elems = re.split("\|", members)
169 if len(elems) > 1:
170 mainelem = [""]
171 mainelem[0] = elems[0]
172 elems = re.split(",", elems[1])
173 newelems = []
174 for elem in elems:
175 elem = mainelem[0] + "." + elem
176 newelems += [elem]
177 elems = newelems
178 else:
179 elems = re.split(",", members)
180
181 ## Check member values
182 if guardbit != "extensions":
183 sys.stdout.write(tab+"if (")
184 first = 1
185 for elem in elems:
186 if first != 1:
187 print(" ||\n"+tab+" ", end="")
188 first = 0
189 sys.stdout.write("%(current)s->%(elem)s != %(target)s->%(elem)s"%vars())
190 print(")\n"+tab+"{")
191 tab = tab+"\t"
192
193## Handle text function
194 if func[0] == "*":
195 func = func[1:]
196 print(tab+func)
197 else:
198 if func != "":
199## Call the glhw function
200 if guardbit[0:6] == "enable":
201 print(tab+"able["+target+"->"+elems[0]+"]("+func+");")
202 elif guardbit == "extensions":
203 print(tab+"crState$state_name",end="")
204 if docopy == 1:
205 print("Diff",end="")
206 else:
207 print("Switch",end="")
208 print("Extensions(from, to);")
209 else:
210 funcargs = re.split(",", func)
211 #print "// funcargs:",funcargs
212 func = funcargs.pop(0)
213
214 if func[-1] == "v":
215 v_type = func[-2:-1]
216 num_elems = len(elems)
217 print(tab+v_types[v_type]+" varg["+str(num_elems)+"];")
218 i = 0
219 for elem in elems:
220 print(tab+"varg["+str(i)+"] = "+target+"->"+elem+";")
221 i += 1
222 elif func[-3:] == "vNV":
223 v_type = func[-4:-3]
224 num_elems = len(elems)
225 print(tab+v_types[v_type]+" varg["+str(num_elems)+"];")
226 i = 0
227 for elem in elems:
228 print(tab+"varg["+str(i)+"] = "+target+"->"+elem+";")
229 i += 1
230
231 sys.stdout.write(tab+"pState->diff_api.%(func)s("%vars())
232 for funcarg in funcargs:
233 sys.stdout.write(funcarg+", ")
234
235## Handle vargs
236 if func[-1] == "v" or func[-3:] == "vNV":
237 sys.stdout.write("varg")
238 else:
239 first = 1
240 for elem in elems:
241 if first != 1:
242 sys.stdout.write(",\n"+tab+" ")
243 first = 0
244 sys.stdout.write(target+"->"+elem)
245 print(");")
246
247## Do the sync if necessary
248 if docopy and guardbit != "extensions":
249 for elem in mainelem:
250 print(tab+current+"->"+elem+" = "+target+"->"+elem+";")
251
252 ## Do the clear if necessary
253 if doinvalid:
254 if guardbit != "":
255 print(tab+"FILLDIRTY(%(bit)s->%(guardbit)s);"%vars())
256 print(tab+"FILLDIRTY(%(bit)s->dirty);"%vars())
257 if extrabit != "":
258 print(tab+"FILLDIRTY(%(extrabit)s->dirty);"%vars())
259
260 ## Close the compare
261 if guardbit != "extensions":
262 tab = tab[:-1]
263 print(tab+"}")
264
265## Do final closures
266 if current_guard != "":
267 print(tab+"CLEARDIRTY(%(bit)s->%(current_guard)s, nbitID);"%vars())
268 tab = tab[:-1]
269 print(tab+"}")
270 if docopy and current_dependency != "":
271 tab = tab[:-1]
272 print(tab+"} /*%(current_dependency)s*/"%vars())
273
274 print(tab+"CLEARDIRTY(%(bit)s->dirty, nbitID);"%vars())
275
276main()
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette