summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-03-11 22:20:04 -0700
committerOri Bernstein <ori@eigenstate.org>2018-03-11 22:21:14 -0700
commitc66524195111b82bbd1e78e0962ca71f65979755 (patch)
tree8e9a85c882bce550d9a94ed3d35477bde35cb26e
parent90cf9eaed8df2cf196c8979bc612596d0dacb68a (diff)
downloadlibxmyrb-c66524195111b82bbd1e78e0962ca71f65979755.tar.gz
Generate code for a few extensions.
-rw-r--r--bld.proj12
-rwxr-xr-xgen.py75
2 files changed, 64 insertions, 23 deletions
diff --git a/bld.proj b/bld.proj
index 62e7077..5f19e2d 100644
--- a/bld.proj
+++ b/bld.proj
@@ -7,10 +7,18 @@ lib xmyrb =
# generated
xproto-gen.myr
+ bigreq-gen.myr
+ render-gen.myr
+ events-gen.myr
;;
-gen xproto-gen.myr {dep=gen.py} =
- python ./gen.py xproto.xml
+gen
+ events-gen.myr
+ xproto-gen.myr
+ render-gen.myr
+ bigreq-gen.myr
+{dep=gen.py} =
+ python ./gen.py xproto render bigreq
;;
bin xevdump =
diff --git a/gen.py b/gen.py
index 525799e..9a58c9c 100755
--- a/gen.py
+++ b/gen.py
@@ -12,19 +12,25 @@ lentag = 0
isextension = False
indents = collections.defaultdict(int)
tymap = {
- 'char': 'byte',
- 'BYTE': 'byte',
- 'INT8': 'int8',
- 'INT16': 'int16',
- 'INT32': 'int32',
- 'INT64': 'int64',
- 'CARD8': 'byte',
- 'CARD16': 'uint16',
- 'CARD32': 'uint32',
- 'CARD64': 'uint64',
- 'BOOL': 'bool',
- 'xid': 'xid',
- 'void': 'void',
+ 'char': 'byte',
+ 'BYTE': 'byte',
+ 'INT8': 'int8',
+ 'INT16': 'int16',
+ 'INT32': 'int32',
+ 'INT64': 'int64',
+ 'CARD8': 'byte',
+ 'CARD16': 'uint16',
+ 'CARD32': 'uint32',
+ 'CARD64': 'uint64',
+ 'BOOL': 'bool',
+ 'xid': 'xid',
+ 'void': 'void',
+}
+
+renames = {
+ 'render': {
+ 'CreateCursor': 'RenderCreateCursor'
+ }
}
def writeln(f, s, *args):
@@ -52,7 +58,7 @@ def myrtype(ty):
def isprimitive(ty):
return ty in tymap
-def load(path):
+def load(mod, path):
with open(path) as f:
t = etree.parse(f)
@@ -60,6 +66,10 @@ def load(path):
for e in t.getroot():
if e.tag is etree.Comment:
continue
+ name = e.get('name')
+ if mod in renames and name in renames[mod]:
+ print('rename {} => {}'.format(name, renames[mod][name]))
+ e.set('name', renames[mod][name])
if e.tag == 'enum': elts['enums'][e.get('name')] = e
elif e.tag == 'error': elts['errors'][e.get('name')] = e
elif e.tag == 'errorcopy': elts['errors'][e.get('name')] = e
@@ -533,7 +543,15 @@ def genevent(name, elts):
writeln(iface, 'const {} : byte = {}', name, elts.get('number'))
genstruct(name, elts, isevent=True)
-def geneventunion(elts):
+def geneventunion(mods, elts):
+ writeln(iface, 'use std')
+ writeln(iface, '')
+ writeln(iface, 'use "types"')
+ writeln(iface, 'use "conn"')
+ for mod in mods:
+ writeln(iface, 'use "{}-gen"', mod)
+ writeln(iface, 'pkg xmyrb =')
+ indent(iface)
writeln(iface, 'type event = union')
indent(iface)
for (k, v) in elts.items():
@@ -564,6 +582,8 @@ def geneventunion(elts):
writeln(impl, 'unpackalign(dpy, 32)')
outdent(impl)
writeln(impl, '}}')
+ outdent(iface)
+ writeln(iface, ';;')
def generate(elts):
writeln(iface, 'use std')
@@ -587,31 +607,44 @@ def generate(elts):
genunion(k, v)
for (k, v) in elts['events'].items():
genevent(k, v)
- geneventunion(elts['events'])
outdent(iface)
writeln(iface, ';;')
+def addevents(events, elts):
+ for (k, v) in elts['events'].items():
+ if k in events:
+ raise Exception('event {} found in two modules'.format(k))
+ events[k] = v
+
def main():
global iface, impl
cmd = ['pkg-config', '--variable', 'xcbincludedir', 'xcb-proto']
xcbdir = subprocess.check_output(cmd).strip()
+ events = {}
for mod in sys.argv[1:]:
iface = io.BytesIO()
impl = io.BytesIO()
- module = os.path.splitext(mod)[0]
- path = os.path.join(xcbdir, mod)
- print('generate {}...'.format(module))
+ path = os.path.join(xcbdir, mod + '.xml')
+ print('generate {}...'.format(mod))
- t = load(path)
+ t = load(mod, path)
+ addevents(events, t)
generate(t)
- out = '{}-gen.myr'.format(module)
+ out = '{}-gen.myr'.format(mod)
with open(out, 'w') as f:
f.write(iface.getvalue())
f.write(impl.getvalue())
iface.close()
impl.close()
+ iface = io.BytesIO()
+ impl = io.BytesIO()
+ geneventunion(sys.argv[1:], events)
+ with open('events-gen.myr', 'w') as f:
+ f.write(iface.getvalue())
+ f.write(impl.getvalue())
+
if __name__ == '__main__':
main()