VirtualBox

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

Last change on this file since 76474 was 69392, checked in by vboxsync, 7 years ago

GuestHost/OpenGL: scm updates

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