On Fri, Sep 27, 2013 at 12:43 PM, Jonathan S. Shapiro <[email protected]>wrote:
>
> The catch is readability. Speaking for myself, I find:
>
> package IA32;
>
> struct PTE 32 {
> bit V 0; /* present (a.k.a. valid) */
> bit W 1; /* writable */
> bit USER 2; /* user-accessable */
> bit PWT 3; /* page write through */
> bit PCD 4; /* page cache disable */
> bit ACC 5; /* accessed */
> bit DRTY 6; /* dirty */
> bit PGSZ 7; /* large page (PDE only, only if CR4.PSE) */
> bit PAT 7; /* page attribute table */
> bit GLBL 8; /* global page (PDE, PTE, only if CR4.PGE) */
> field SW 9 11; /* software defined */
> bit PAT4M 12; /* page attribute table, 4M pages */
>
> field FRAME 12 31; /* page frame number */
> field FRAME4M 22 31; /* page frame number, 4M page */
> }
>
>
> To be infinitely more readable than something like:
>
> <package name="IA32"/>
>
> <struct name="PTE" width="32">
> <bit name="V" bit="31"/>
> ...
>
> <field name=SW" from="9" to="11"/>
> ...
>
> </reg>
>
>
There's Google's protocol
buffer<https://developers.google.com/protocol-buffers/>format (which I
wind up using a lot, given that I'm at Google). The text
format of this structure might look something like:
name: "IA32"
structs {
name: "PTE_32"
bits {
name: "V"
bit: 0
comment: "present (a.k.a. valid)"
}
bits {
name: "W"
bit: 1
comment: "writable"
}
}
Still not all that readable, but it compares pretty well to JSON. The
definition would look something like this:
message Package {
optional string name = 1;
repeated Struct structs = 2;
}
message Struct {
optional string name = 1;
repeated Bit bits = 2;
repeated Field fields = 3;
}
message Bit {
optional string name = 1;
optional int32 bit = 2;
optional string comment = 3;
}
There're compilers which take the definitions and build parsers and
accessors. In C++, you get code like:
Package* package;
for (Struct* s : package->structs()) {
for (Bit* b : s->bits()) {
cout << "Saw a comment: " << b->comment() << endl;
}
}
It's essentially an AST -- no semantic validation, but the syntax is
checked.
(Don't use required fields -- IMHO, that was a mistake in the original
spec.)
)Rob
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev