summaryrefslogtreecommitdiff
path: root/devtools/tablegen.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-05-31 07:49:00 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-05-31 07:49:00 -0400
commit4e4ac8884e5469d3843f4a775559f22ff7c8d292 (patch)
treec57964f522e6ff392c81894ffefc9c6f956f8cae /devtools/tablegen.py
parent0e98bf00b5a63798e30026d9198892b7c24c4c71 (diff)
downloadgpsd-4e4ac8884e5469d3843f4a775559f22ff7c8d292.tar.gz
In AIS, partial support for VTS-Generated/Synthetic Targets.
JSON parsing of string IDs won't work yet; code generator needs some extension.
Diffstat (limited to 'devtools/tablegen.py')
-rwxr-xr-xdevtools/tablegen.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/devtools/tablegen.py b/devtools/tablegen.py
index 7351a87c..4a68b8df 100755
--- a/devtools/tablegen.py
+++ b/devtools/tablegen.py
@@ -105,7 +105,7 @@ def make_driver_code(wfp):
offset = "a + " + offset
else:
target = "%s.%s" % (structname, name)
- if ftype[0].lower() in ('u', 'i'):
+ if ftype[0].lower() in ('u', 'i', 'e'):
print >>wfp, indent + "%s\t= %sBITS(%s, %s);" % \
(target, {'u':'U', 'e':'U', 'i':'S'}[ftype[0].lower()], offset, width)
elif ftype == 't':
@@ -267,13 +267,22 @@ def make_json_dumper(wfp):
inarray = var
base = " " * 12
startspan = i+1
- continue
+ continue
# At end of tuples, or if scaled flag changes, or if next op is array,
- # flush out dump code for a span of fields
- if i+1 == len(tuples) or scaled(i) != scaled(i+1) or tuples[i+1][1] == None:
+ # flush out dump code for a span of fields.
+ if tuples[i+1][1] == None:
+ endit = r',\"%s\":['
+ elif i+1 == len(tuples):
+ if not inarray:
+ endit = '}\r\n'
+ elif scaled(i) != scaled(i+1):
+ endit = '.",'
+ else:
+ endit = None
+ if endit:
if not scaled(i):
print >>wfp, base + header
- print >>wfp, base + step + '"'+','.join(tslice(i,1))+'",'
+ print >>wfp, base + step + '"'+','.join(tslice(i,1)) + endit
for (j, t) in enumerate(tuples[startspan:i+1]):
if inarray:
ref = structname + "." + inarray + "[i]." + t[0]
@@ -287,7 +296,7 @@ def make_json_dumper(wfp):
else:
print >>wfp, base + "if (scaled)"
print >>wfp, base + step + header
- print >>wfp, base + step*2 + '"'+','.join(tslice(i,3))+'",'
+ print >>wfp, base + step*2 + '"'+','.join(tslice(i,3)) + endit
for (j, t) in enumerate(tuples[startspan:i+1]):
if inarray:
ref = structname + "." + inarray + "[i]." + t[0]
@@ -300,7 +309,7 @@ def make_json_dumper(wfp):
wfp.write(",\n")
print >>wfp, base + "else"
print >>wfp, base + step + header
- print >>wfp, base + step*2 + '"'+','.join(tslice(i,1))+'",'
+ print >>wfp, base + step*2 + '"'+','.join(tslice(i,1)) + endit
for (j, t) in enumerate(tuples[startspan:i+1]):
if inarray:
ref = structname + "." + inarray + "[i]." + t[0]
@@ -314,8 +323,11 @@ def make_json_dumper(wfp):
startspan = i+1
# If we were looking at a trailing array, close scope
if inarray:
- base = " " * 8 # Not necessary, really.
+ base = " " * 8
print >>wfp, base + "}"
+ print >>wfp, base + "if (buf[strlen(buf) - 1] == ',')"
+ print >>wfp, base + step + "buf[strlen(buf)-1] = '\0';"
+ print >>wfp, base + "(void)strlcat(buf, ']}\r\n,', buflen - strlen(buf));"
def make_json_generator(wfp):
# Write a stanza for jsongen.py.in describing how to generate a