debuggers.hg

changeset 22077:e2aa1eaa7bf5

libxl: autogenerate _libxl_types.h

The libxl interface types are represented by a simple python data
structure (which could be parsed from a bespoke language in the
future).

This will allow the autogeneration of functions to free the component
members of the libxl types. In the future it may also enable auto
generation of type marshalling code for language bindings.

The generated file should be identical to before with the exception of
the "DO NOT EDIT" header.

It was unfortunately necessary to add explcit an dependency on
_libxl_types.h (indirectly via libxl.h) to all C files since the
autogenerated dependencies are not available in time.

[PATCH 04 of 16 of
libxl: autogenerate type definitions and destructor functions]

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Aug 19 15:15:55 2010 +0100 (2010-08-19)
parents a05a2d559931
children fa82b0540e8c
files tools/libxl/Makefile tools/libxl/_libxl_types.h tools/libxl/gentypes.py tools/libxl/idl.txt tools/libxl/libxl.idl tools/libxl/libxltypes.py
line diff
     1.1 --- a/tools/libxl/Makefile	Thu Aug 19 14:46:32 2010 +0100
     1.2 +++ b/tools/libxl/Makefile	Thu Aug 19 15:15:55 2010 +0100
     1.3 @@ -60,6 +60,14 @@ genpath-target = $(call buildmakevars2fi
     1.4  
     1.5  libxl_paths.c: _libxl_paths.h
     1.6  
     1.7 +libxl.h: _libxl_types.h
     1.8 +
     1.9 +$(LIBXL_OBJS:%.o=%.c) $(LIBXLU_OBJS:%.o=%.c) $(XL_OBJS:%.o=%.c): libxl.h
    1.10 +
    1.11 +_libxl_types.h: libxl.idl gentypes.py libxltypes.py
    1.12 +	python gentypes.py libxl.idl  __libxl_types.h
    1.13 +	mv __libxl_types.h _libxl_types.h
    1.14 +
    1.15  libxenlight.so: libxenlight.so.$(MAJOR)
    1.16  	ln -sf $< $@
    1.17  
    1.18 @@ -107,10 +115,7 @@ install: all
    1.19  
    1.20  .PHONY: clean
    1.21  clean:
    1.22 -	# XXX Preserve during transition to autogeneration
    1.23 -	cp _libxl_types.h SAVED__libxl_types.h
    1.24  	$(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS)
    1.25 -	mv SAVED__libxl_types.h _libxl_types.h 
    1.26  #	$(RM) -f $(AUTOSRCS) $(AUTOINCS)
    1.27  
    1.28  distclean: clean
     2.1 --- a/tools/libxl/_libxl_types.h	Thu Aug 19 14:46:32 2010 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,425 +0,0 @@
     2.4 -#ifndef __LIBXL_TYPES_H
     2.5 -#define __LIBXL_TYPES_H
     2.6 -
     2.7 -typedef struct {
     2.8 -    libxl_uuid uuid;
     2.9 -    uint32_t domid;
    2.10 -    uint8_t running:1;
    2.11 -    uint8_t blocked:1;
    2.12 -    uint8_t paused:1;
    2.13 -    uint8_t shutdown:1;
    2.14 -    uint8_t dying:1;
    2.15 -    /*
    2.16 -     * Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying).
    2.17 -     *
    2.18 -     * Otherwise set to a value guaranteed not to clash with any valid
    2.19 -     * SHUTDOWN_* constant.
    2.20 -     */
    2.21 -    unsigned int shutdown_reason;
    2.22 -    uint64_t max_memkb;
    2.23 -    uint64_t cpu_time;
    2.24 -    uint32_t vcpu_max_id;
    2.25 -    uint32_t vcpu_online;
    2.26 -} libxl_dominfo;
    2.27 -
    2.28 -typedef struct {
    2.29 -    uint32_t poolid;
    2.30 -} libxl_poolinfo;
    2.31 -
    2.32 -typedef struct {
    2.33 -    libxl_uuid uuid;
    2.34 -    uint32_t domid;
    2.35 -} libxl_vminfo;
    2.36 -
    2.37 -typedef struct {
    2.38 -    int xen_version_major;
    2.39 -    int xen_version_minor;
    2.40 -    char * xen_version_extra;
    2.41 -    char * compiler;
    2.42 -    char * compile_by;
    2.43 -    char * compile_domain;
    2.44 -    char * compile_date;
    2.45 -    char * capabilities;
    2.46 -    char * changeset;
    2.47 -    unsigned long virt_start;
    2.48 -    unsigned long pagesize;
    2.49 -    char * commandline;
    2.50 -} libxl_version_info;
    2.51 -
    2.52 -typedef struct {
    2.53 -    bool hvm;
    2.54 -    bool hap;
    2.55 -    bool oos;
    2.56 -    int ssidref;
    2.57 -    char * name;
    2.58 -    libxl_uuid uuid;
    2.59 -    libxl_key_value_list xsdata;
    2.60 -    libxl_key_value_list platformdata;
    2.61 -    uint32_t poolid;
    2.62 -    char * poolname;
    2.63 -} libxl_domain_create_info;
    2.64 -
    2.65 -typedef struct {
    2.66 -    /*
    2.67 -     * Path is always set if the file reference is valid. However if
    2.68 -     * mapped is true then the actual file may already be unlinked.
    2.69 -     */
    2.70 -    char * path;
    2.71 -    int mapped;
    2.72 -    void * data;
    2.73 -    size_t size;
    2.74 -} libxl_file_reference;
    2.75 -
    2.76 -/*
    2.77 - * Instances of libxl_file_reference contained in this struct which
    2.78 - * have been mapped (with libxl_file_reference_map) will be unmapped
    2.79 - * by libxl_domain_build/restore. If either of these are never called
    2.80 - * then the user is responsible for calling
    2.81 - * libxl_file_reference_unmap.
    2.82 - */
    2.83 -typedef struct {
    2.84 -    int max_vcpus;
    2.85 -    int cur_vcpus;
    2.86 -    int tsc_mode;
    2.87 -    uint32_t max_memkb;
    2.88 -    uint32_t target_memkb;
    2.89 -    uint32_t video_memkb;
    2.90 -    uint32_t shadow_memkb;
    2.91 -    bool disable_migrate;
    2.92 -    libxl_file_reference kernel;
    2.93 -    int hvm;
    2.94 -    union {
    2.95 -        struct {
    2.96 -            bool pae;
    2.97 -            bool apic;
    2.98 -            bool acpi;
    2.99 -            bool nx;
   2.100 -            bool viridian;
   2.101 -            char * timeoffset;
   2.102 -            bool hpet;
   2.103 -            bool vpt_align;
   2.104 -            int timer_mode;
   2.105 -        } hvm;
   2.106 -        struct {
   2.107 -            uint32_t slack_memkb;
   2.108 -            const char * bootloader;
   2.109 -            const char * bootloader_args;
   2.110 -            char * cmdline;
   2.111 -            libxl_file_reference ramdisk;
   2.112 -            const char * features;
   2.113 -        } pv;
   2.114 -    } u;
   2.115 -} libxl_domain_build_info;
   2.116 -
   2.117 -typedef struct {
   2.118 -    uint32_t store_port;
   2.119 -    unsigned long store_mfn;
   2.120 -    uint32_t console_port;
   2.121 -    unsigned long console_mfn;
   2.122 -} libxl_domain_build_state;
   2.123 -
   2.124 -/*
   2.125 - * Device Model information.
   2.126 - *
   2.127 - * Network is missing
   2.128 - */
   2.129 -typedef struct {
   2.130 -    int domid;
   2.131 -    /*
   2.132 -     * this is use only with stubdom, and must be different from the domain uuid
   2.133 -     */
   2.134 -    libxl_uuid uuid;
   2.135 -    char * dom_name;
   2.136 -    char * device_model;
   2.137 -    char * saved_state;
   2.138 -    libxl_qemu_machine_type type;
   2.139 -    /*
   2.140 -     * size of the videoram in MB
   2.141 -     */
   2.142 -    int videoram;
   2.143 -    /*
   2.144 -     * stdvga enabled or disabled
   2.145 -     */
   2.146 -    bool stdvga;
   2.147 -    /*
   2.148 -     * vnc enabled or disabled
   2.149 -     */
   2.150 -    bool vnc;
   2.151 -    /*
   2.152 -     * address:port that should be listened on for the VNC server if vnc is set
   2.153 -     */
   2.154 -    char * vnclisten;
   2.155 -    /*
   2.156 -     * the VNC password
   2.157 -     */
   2.158 -    char * vncpasswd;
   2.159 -    /*
   2.160 -     * set VNC display number
   2.161 -     */
   2.162 -    int vncdisplay;
   2.163 -    /*
   2.164 -     * try to find an unused port for the VNC server
   2.165 -     */
   2.166 -    bool vncunused;
   2.167 -    /*
   2.168 -     * set keyboard layout, default is en-us keyboard
   2.169 -     */
   2.170 -    char * keymap;
   2.171 -    /*
   2.172 -     * sdl enabled or disabled
   2.173 -     */
   2.174 -    bool sdl;
   2.175 -    /*
   2.176 -     * opengl enabled or disabled (if enabled requires sdl enabled)
   2.177 -     */
   2.178 -    bool opengl;
   2.179 -    /*
   2.180 -     * no graphics, use serial port
   2.181 -     */
   2.182 -    bool nographic;
   2.183 -    /*
   2.184 -     * serial port re-direct to pty deivce
   2.185 -     */
   2.186 -    char * serial;
   2.187 -    /*
   2.188 -     * boot order, for example dca
   2.189 -     */
   2.190 -    char * boot;
   2.191 -    /*
   2.192 -     * usb support enabled or disabled
   2.193 -     */
   2.194 -    bool usb;
   2.195 -    /*
   2.196 -     * enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse
   2.197 -     */
   2.198 -    char * usbdevice;
   2.199 -    /*
   2.200 -     * enable sound hardware
   2.201 -     */
   2.202 -    char * soundhw;
   2.203 -    /*
   2.204 -     * apic enabled or disabled
   2.205 -     */
   2.206 -    bool apic;
   2.207 -    /*
   2.208 -     * max number of vcpus
   2.209 -     */
   2.210 -    int vcpus;
   2.211 -    /*
   2.212 -     * vcpus actually available
   2.213 -     */
   2.214 -    int vcpu_avail;
   2.215 -    /*
   2.216 -     * enable/disable the xen platform pci device
   2.217 -     */
   2.218 -    int xen_platform_pci;
   2.219 -    /*
   2.220 -     * extra parameters pass directly to qemu, NULL terminated
   2.221 -     */
   2.222 -    libxl_string_list extra;
   2.223 -} libxl_device_model_info;
   2.224 -
   2.225 -typedef struct {
   2.226 -    uint32_t backend_domid;
   2.227 -    uint32_t domid;
   2.228 -    int devid;
   2.229 -    /*
   2.230 -     * vnc enabled or disabled
   2.231 -     */
   2.232 -    bool vnc;
   2.233 -    /*
   2.234 -     * address:port that should be listened on for the VNC server if vnc is set
   2.235 -     */
   2.236 -    char * vnclisten;
   2.237 -    /*
   2.238 -     * the VNC password
   2.239 -     */
   2.240 -    char * vncpasswd;
   2.241 -    /*
   2.242 -     * set VNC display number
   2.243 -     */
   2.244 -    int vncdisplay;
   2.245 -    /*
   2.246 -     * try to find an unused port for the VNC server
   2.247 -     */
   2.248 -    bool vncunused;
   2.249 -    /*
   2.250 -     * set keyboard layout, default is en-us keyboard
   2.251 -     */
   2.252 -    char * keymap;
   2.253 -    /*
   2.254 -     * sdl enabled or disabled
   2.255 -     */
   2.256 -    bool sdl;
   2.257 -    /*
   2.258 -     * opengl enabled or disabled (if enabled requires sdl enabled)
   2.259 -     */
   2.260 -    bool opengl;
   2.261 -    char * display;
   2.262 -    char * xauthority;
   2.263 -} libxl_device_vfb;
   2.264 -
   2.265 -typedef struct {
   2.266 -    uint32_t backend_domid;
   2.267 -    uint32_t domid;
   2.268 -    int devid;
   2.269 -} libxl_device_vkb;
   2.270 -
   2.271 -typedef struct {
   2.272 -    uint32_t backend_domid;
   2.273 -    uint32_t domid;
   2.274 -    int devid;
   2.275 -    libxl_console_consback consback;
   2.276 -    libxl_domain_build_state * build_state;
   2.277 -    char * output;
   2.278 -} libxl_device_console;
   2.279 -
   2.280 -typedef struct {
   2.281 -    uint32_t backend_domid;
   2.282 -    uint32_t domid;
   2.283 -    char * physpath;
   2.284 -    libxl_disk_phystype phystype;
   2.285 -    char * virtpath;
   2.286 -    int unpluggable;
   2.287 -    int readwrite;
   2.288 -    int is_cdrom;
   2.289 -} libxl_device_disk;
   2.290 -
   2.291 -typedef struct {
   2.292 -    uint32_t backend_domid;
   2.293 -    uint32_t domid;
   2.294 -    int devid;
   2.295 -    int mtu;
   2.296 -    char * model;
   2.297 -    libxl_mac mac;
   2.298 -    struct in_addr ip;
   2.299 -    char * bridge;
   2.300 -    char * ifname;
   2.301 -    char * script;
   2.302 -    libxl_nic_type nictype;
   2.303 -} libxl_device_nic;
   2.304 -
   2.305 -typedef struct {
   2.306 -    int devid;
   2.307 -    libxl_mac front_mac;
   2.308 -    libxl_mac back_mac;
   2.309 -    uint32_t backend_domid;
   2.310 -    uint32_t domid;
   2.311 -    uint32_t trusted:1;
   2.312 -    uint32_t back_trusted:1;
   2.313 -    uint32_t filter_mac:1;
   2.314 -    uint32_t front_filter_mac:1;
   2.315 -    uint32_t pdev;
   2.316 -    uint32_t max_bypasses;
   2.317 -    char * bridge;
   2.318 -} libxl_device_net2;
   2.319 -
   2.320 -typedef struct {
   2.321 -    union {
   2.322 -        unsigned int value;
   2.323 -        struct {
   2.324 -            unsigned int reserved1:2;
   2.325 -            unsigned int reg:6;
   2.326 -            unsigned int func:3;
   2.327 -            unsigned int dev:5;
   2.328 -            unsigned int bus:8;
   2.329 -            unsigned int reserved2:7;
   2.330 -            unsigned int enable:1;
   2.331 -        };
   2.332 -    };
   2.333 -    unsigned int domain;
   2.334 -    unsigned int vdevfn;
   2.335 -    unsigned int vfunc_mask;
   2.336 -    bool msitranslate;
   2.337 -    bool power_mgmt;
   2.338 -} libxl_device_pci;
   2.339 -
   2.340 -typedef struct {
   2.341 -    char * backend;
   2.342 -    uint32_t backend_id;
   2.343 -    char * frontend;
   2.344 -    uint32_t frontend_id;
   2.345 -    int devid;
   2.346 -    int state;
   2.347 -    int evtch;
   2.348 -    int rref;
   2.349 -} libxl_diskinfo;
   2.350 -
   2.351 -typedef struct {
   2.352 -    char * backend;
   2.353 -    uint32_t backend_id;
   2.354 -    char * frontend;
   2.355 -    uint32_t frontend_id;
   2.356 -    int devid;
   2.357 -    int state;
   2.358 -    char * script;
   2.359 -    libxl_mac mac;
   2.360 -    int evtch;
   2.361 -    int rref_tx;
   2.362 -    int rref_rx;
   2.363 -} libxl_nicinfo;
   2.364 -
   2.365 -typedef struct {
   2.366 -    /*
   2.367 -     * vcpu's id
   2.368 -     */
   2.369 -    uint32_t vcpuid;
   2.370 -    /*
   2.371 -     * current mapping
   2.372 -     */
   2.373 -    uint32_t cpu;
   2.374 -    /*
   2.375 -     * currently online (not hotplugged)?
   2.376 -     */
   2.377 -    uint8_t online:1;
   2.378 -    /*
   2.379 -     * blocked waiting for an event?
   2.380 -     */
   2.381 -    uint8_t blocked:1;
   2.382 -    /*
   2.383 -     * currently scheduled on its CPU?
   2.384 -     */
   2.385 -    uint8_t running:1;
   2.386 -    /*
   2.387 -     * total vcpu time ran (ns)
   2.388 -     */
   2.389 -    uint64_t vcpu_time;
   2.390 -    /*
   2.391 -     * current cpu's affinities
   2.392 -     */
   2.393 -    libxl_cpumap cpumap;
   2.394 -} libxl_vcpuinfo;
   2.395 -
   2.396 -typedef struct {
   2.397 -    uint32_t threads_per_core;
   2.398 -    uint32_t cores_per_socket;
   2.399 -    uint32_t max_cpu_id;
   2.400 -    uint32_t nr_cpus;
   2.401 -    uint32_t cpu_khz;
   2.402 -    uint64_t total_pages;
   2.403 -    uint64_t free_pages;
   2.404 -    uint64_t scrub_pages;
   2.405 -    uint32_t nr_nodes;
   2.406 -    libxl_hwcap hw_cap;
   2.407 -    uint32_t phys_cap;
   2.408 -} libxl_physinfo;
   2.409 -
   2.410 -typedef struct {
   2.411 -    int weight;
   2.412 -    int cap;
   2.413 -} libxl_sched_credit;
   2.414 -
   2.415 -typedef struct {
   2.416 -    char * backend;
   2.417 -    uint32_t backend_id;
   2.418 -    char * frontend;
   2.419 -    uint32_t frontend_id;
   2.420 -    int devid;
   2.421 -    int state;
   2.422 -    libxl_mac mac;
   2.423 -    int trusted;
   2.424 -    libxl_mac back_mac;
   2.425 -    int filter_mac;
   2.426 -} libxl_net2info;
   2.427 -
   2.428 -#endif /* __LIBXL_TYPES_H */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxl/gentypes.py	Thu Aug 19 15:15:55 2010 +0100
     3.3 @@ -0,0 +1,91 @@
     3.4 +#!/usr/bin/python
     3.5 +
     3.6 +import sys
     3.7 +import re
     3.8 +
     3.9 +import libxltypes
    3.10 +
    3.11 +def format_comment(level, comment):
    3.12 +    indent = reduce(lambda x,y: x + " ", range(level), "")
    3.13 +    s  = "%s/*\n" % indent
    3.14 +    s += "%s * " % indent
    3.15 +    comment = comment.replace("\n", "\n%s * " % indent)
    3.16 +    x = re.compile(r'^%s \* $' % indent, re.MULTILINE)
    3.17 +    comment = x.sub("%s *" % indent, comment)
    3.18 +    s += comment
    3.19 +    s += "\n"
    3.20 +    s += "%s */" % indent
    3.21 +    s += "\n"
    3.22 +    return s
    3.23 +
    3.24 +def libxl_C_type_of(ty):
    3.25 +    return ty.typename
    3.26 +
    3.27 +def libxl_C_instance_of(ty, instancename):
    3.28 +    if isinstance(ty, libxltypes.BitField):
    3.29 +        return libxl_C_type_of(ty) + " " + instancename + ":%d" % ty.width
    3.30 +    elif isinstance(ty, libxltypes.Aggregate) and ty.typename is None:
    3.31 +        if instancename is None:
    3.32 +            return libxl_C_type_define(ty)
    3.33 +        else:
    3.34 +            return libxl_C_type_define(ty) + " " + instancename
    3.35 +    else:
    3.36 +        return libxl_C_type_of(ty) + " " + instancename
    3.37 +
    3.38 +def libxl_C_type_define(ty, indent = ""):
    3.39 +    s = ""
    3.40 +    if isinstance(ty, libxltypes.Aggregate):
    3.41 +        if ty.comment is not None:
    3.42 +            s += format_comment(0, ty.comment)
    3.43 +
    3.44 +        if ty.typename is None:
    3.45 +            s += "%s {\n" % ty.kind
    3.46 +        else:
    3.47 +            s += "typedef %s {\n" % ty.kind
    3.48 +
    3.49 +        for f in ty.fields:
    3.50 +            if f.comment is not None:
    3.51 +                s += format_comment(4, f.comment)
    3.52 +            x = libxl_C_instance_of(f.type, f.name)
    3.53 +            if f.const:
    3.54 +                x = "const " + x
    3.55 +            x = x.replace("\n", "\n    ")
    3.56 +            s += "    " + x + ";\n"
    3.57 +        if ty.typename is None:
    3.58 +            s += "}"
    3.59 +        else:
    3.60 +            s += "} %s" % ty.typename
    3.61 +    else:
    3.62 +        raise NotImplementedError("%s" % type(ty))
    3.63 +    return s.replace("\n", "\n%s" % indent)
    3.64 +
    3.65 +if __name__ == '__main__':
    3.66 +    if len(sys.argv) < 3:
    3.67 +        print >>sys.stderr, "Usage: gentypes.py <idl> <header>"
    3.68 +        sys.exit(1)
    3.69 +
    3.70 +    idl = sys.argv[1]
    3.71 +    (_,types) = libxltypes.parse(idl)
    3.72 +                    
    3.73 +    header = sys.argv[2]
    3.74 +    print "outputting libxl types to %s" % header
    3.75 +
    3.76 +    f = open(header, "w")
    3.77 +    
    3.78 +    f.write("""#ifndef __LIBXL_TYPES_H
    3.79 +#define __LIBXL_TYPES_H
    3.80 +
    3.81 +/*
    3.82 + * DO NOT EDIT.
    3.83 + *
    3.84 + * This file is autogenerated by
    3.85 + * "%s"
    3.86 + */
    3.87 + 
    3.88 +""" % " ".join(sys.argv))
    3.89 +        
    3.90 +    for t in types:
    3.91 +        f.write(libxl_C_type_define(t) + ";\n")
    3.92 +        f.write("\n")
    3.93 +
    3.94 +    f.write("""#endif /* __LIBXL_TYPES_H */\n""")
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/libxl/idl.txt	Thu Aug 19 15:15:55 2010 +0100
     4.3 @@ -0,0 +1,147 @@
     4.4 +libxltypes IDL
     4.5 +--------------
     4.6 +
     4.7 +Each type in the libxl interface is represented by an object of type
     4.8 +libxltypes.Type (or a subclass thereof). Every local variable defined
     4.9 +by the .idl file must be an instance of libxltypes.Type (e.g. you may
    4.10 +not define Python functions or any other construct other than defining
    4.11 +variables)
    4.12 +
    4.13 +The name of the type must be passed as the first argument to the
    4.14 +constructor when defining a new type. The name given should not
    4.15 +contain the initial namespace element (e.g. "libxl_"). See below for
    4.16 +how to specify a namespace.
    4.17 +
    4.18 +The Type.typename contains the C name of the type _including_ the
    4.19 +namespace element.
    4.20 +
    4.21 +The libxltypes.Type base class has several other properties which
    4.22 +apply to all types. The properties are set by passing a named
    4.23 +parameter to the constructor.
    4.24 +
    4.25 +Type.comment:
    4.26 +
    4.27 +  A free text comment which describes the type.
    4.28 +
    4.29 +Type.namespace: (default: "libxl_")
    4.30 +
    4.31 + The namespace in which the type resides. Usually this is "libxl_" but
    4.32 + system defined and builtin types may differ.
    4.33 +
    4.34 + If the typename is not None then the namespace is prepended to the
    4.35 + type.
    4.36 + 
    4.37 +Type.passby: (default: libxltypes.PASS_BY_VALUE)
    4.38 +
    4.39 + Defines the manner in which a type should be passed to C
    4.40 + functions. Valid values for this fields are:
    4.41 +   libxltypes.PASS_BY_VALUE
    4.42 +   libxltypes.PASS_BY_REFERENCE
    4.43 +
    4.44 +Type.destructor_fn: (default: typename + "_destroy" or None if type == None)
    4.45 +
    4.46 + The name of the C function which will free all dynamically allocated
    4.47 + memory contained within this type (but not the type itself).
    4.48 +
    4.49 +Type.autogenerate_destructor: (default: True)
    4.50 +
    4.51 + Indicates if the above named Type.destructor_fn should be
    4.52 + autogenerated.
    4.53 +
    4.54 +Other simple type-Classes
    4.55 +-------------------------
    4.56 +
    4.57 +libxltype.Builtin
    4.58 +
    4.59 + Instances of this class represent types which are predefined within
    4.60 + the system.
    4.61 +
    4.62 +libxltype.UInt
    4.63 +
    4.64 + Instances of this class represent the standard uint<N>_t types.
    4.65 +
    4.66 + The <N> for a given instance must be passed to the constructor and is
    4.67 + then available in UInt.width
    4.68 +
    4.69 +libxltype.BitField
    4.70 +
    4.71 + Instances of this class represent bitfield type classes.
    4.72 +
    4.73 + The base type and desired width for a given instance must be passed
    4.74 + to the contructor. The base type becomes the type of the instance and
    4.75 + width is contained in BitField.width
    4.76 +
    4.77 +libxltype.Reference
    4.78 +
    4.79 + Instances of this type represent a reference to another type
    4.80 +
    4.81 + The referant type must be passed to the constructor and is then
    4.82 + available in Reference.ref_type
    4.83 +
    4.84 +Complex type-Classes
    4.85 +--------------------
    4.86 +
    4.87 +libxltype.Aggregate
    4.88 +
    4.89 + Base class for type-Classes which contain a number of other types
    4.90 + (e.g. structs and unions).
    4.91 +
    4.92 + The contained types are available in the list Aggregate.fields. Each
    4.93 + element in the list is of type libxltype.Field representing a member
    4.94 + of the aggregate.
    4.95 +
    4.96 + Each field has the following properties:
    4.97 +
    4.98 +  Field.type	The type of the member (a libxltypes.Type).
    4.99 +  Field.name    The name of the member (can be None for anonymous
   4.100 +		fields).
   4.101 +  Field.const	Boolean, true if the member is const.
   4.102 +  Field.comment	A free text comment which describes the member.
   4.103 +
   4.104 +libxltype.Struct
   4.105 +
   4.106 + A subclass of libxltype.Aggregate representing the C struct type.
   4.107 +
   4.108 + Struct.kind == "struct"
   4.109 +
   4.110 +libxltype.Union
   4.111 +
   4.112 + A subclass of libxltype.Aggregate representing the C union type.
   4.113 +
   4.114 + Union.kind == "union"
   4.115 +
   4.116 +libxltype.KeyedUnion
   4.117 +
   4.118 + A subclass of libxltype.Aggregate which represents the C union type
   4.119 + where the currently valid member of the union can be determined based
   4.120 + upon another member in the containing type.
   4.121 +
   4.122 + The KeyedUnion.keyvar_name must contain the name of the member of the
   4.123 + containing type which determines the valid member of the union
   4.124 +
   4.125 + The fields in a KeyedUnion have an extra Field.keyvar_expr
   4.126 + property. This must be a string containing a single "%s" format
   4.127 + specifier such that when "%s" is substited by an instance of
   4.128 + KeyedUnion.keyvar_name it becomes a C expression which evaluates to
   4.129 + True IFF this field currently contains valid data.
   4.130 +
   4.131 +Standard Types
   4.132 +--------------
   4.133 +
   4.134 +Several standard types a predefined. They are
   4.135 +
   4.136 +void			(void pointer type)
   4.137 +bool
   4.138 +size_t
   4.139 +integer			(C int type)
   4.140 +unsigned_integer	(C unsigned int type) 
   4.141 +unsigned		(C unsigned int type) 
   4.142 +unsigned_long		(C unsigned long type)
   4.143 +
   4.144 +uint{8,16,32,64}	uint{8,16,32,64}_t
   4.145 +
   4.146 +domid			Domain ID
   4.147 +
   4.148 +string			NULL terminated string
   4.149 +
   4.150 +inaddr_ip		struct in_addr
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/libxl/libxl.idl	Thu Aug 19 15:15:55 2010 +0100
     5.3 @@ -0,0 +1,329 @@
     5.4 +# -*- python -*-
     5.5 +#
     5.6 +# Builtin libxl types
     5.7 +#
     5.8 +
     5.9 +libxl_ctx = Builtin("ctx")
    5.10 +libxl_uuid = Builtin("uuid")
    5.11 +libxl_mac = Builtin("mac")
    5.12 +libxl_qemu_machine_type = Builtin("qemu_machine_type")
    5.13 +libxl_console_consback = Builtin("console_consback")
    5.14 +libxl_console_constype = Builtin("console_constype")
    5.15 +libxl_disk_phystype = Builtin("disk_phystype")
    5.16 +libxl_nic_type = Builtin("nic_type")
    5.17 +
    5.18 +libxl_string_list = Builtin("string_list")
    5.19 +libxl_key_value_list = Builtin("key_value_list")
    5.20 +
    5.21 +libxl_cpumap = Builtin("cpumap")
    5.22 +
    5.23 +libxl_hwcap = Builtin("hwcap")
    5.24 +
    5.25 +#
    5.26 +# Complex libxl types
    5.27 +#
    5.28 +libxl_dominfo = Struct("dominfo",[
    5.29 +    ("uuid",        libxl_uuid),
    5.30 +    ("domid",       domid),
    5.31 +    ("running",     BitField(uint8, 1)),
    5.32 +    ("blocked",     BitField(uint8, 1)),
    5.33 +    ("paused",      BitField(uint8, 1)),
    5.34 +    ("shutdown",    BitField(uint8, 1)),
    5.35 +    ("dying",       BitField(uint8, 1)),
    5.36 +    
    5.37 +    ("shutdown_reason", unsigned, False, 
    5.38 +"""Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying).
    5.39 +
    5.40 +Otherwise set to a value guaranteed not to clash with any valid
    5.41 +SHUTDOWN_* constant."""),
    5.42 +    ("max_memkb",   uint64),
    5.43 +    ("cpu_time",    uint64),
    5.44 +    ("vcpu_max_id", uint32),
    5.45 +    ("vcpu_online", uint32),
    5.46 +    ])
    5.47 +
    5.48 +libxl_poolinfo = Struct("poolinfo", [
    5.49 +    ("poolid", uint32)
    5.50 +    ])
    5.51 +
    5.52 +libxl_vminfo = Struct("vminfo", [
    5.53 +    ("uuid", libxl_uuid),
    5.54 +    ("domid", domid),
    5.55 +    ])
    5.56 +
    5.57 +libxl_version_info = Struct("version_info", [
    5.58 +    ("xen_version_major", integer),
    5.59 +    ("xen_version_minor", integer),
    5.60 +    ("xen_version_extra", string),
    5.61 +    ("compiler",          string),
    5.62 +    ("compile_by",        string),
    5.63 +    ("compile_domain",    string),
    5.64 +    ("compile_date",      string),
    5.65 +    ("capabilities",      string),
    5.66 +    ("changeset",         string),
    5.67 +    ("virt_start",        unsigned_long),
    5.68 +    ("pagesize",          unsigned_long),
    5.69 +    ("commandline",       string),
    5.70 +    ])
    5.71 +                                             
    5.72 +libxl_domain_create_info = Struct("domain_create_info",[
    5.73 +    ("hvm",          bool),
    5.74 +    ("hap",          bool),
    5.75 +    ("oos",          bool),
    5.76 +    ("ssidref",      integer),
    5.77 +    ("name",         string),
    5.78 +    ("uuid",         libxl_uuid),
    5.79 +    ("xsdata",       libxl_key_value_list),
    5.80 +    ("platformdata", libxl_key_value_list),
    5.81 +    ("poolid",       uint32),
    5.82 +    ("poolname",     string),
    5.83 +    ])
    5.84 +
    5.85 +libxl_file_reference = Struct("file_reference",[
    5.86 +    ("path", string, False,
    5.87 +"""Path is always set if the file reference is valid. However if
    5.88 +mapped is true then the actual file may already be unlinked."""),
    5.89 +    ("mapped", integer),
    5.90 +    ("data", void),
    5.91 +    ("size", size_t)])
    5.92 +
    5.93 +libxl_domain_build_info = Struct("domain_build_info",[
    5.94 +    ("max_vcpus",       integer),
    5.95 +    ("cur_vcpus",       integer),
    5.96 +    ("tsc_mode",        integer),
    5.97 +    ("max_memkb",       uint32),
    5.98 +    ("target_memkb",    uint32),
    5.99 +    ("video_memkb",     uint32),
   5.100 +    ("shadow_memkb",    uint32),
   5.101 +    ("disable_migrate", bool),
   5.102 +    ("kernel",          libxl_file_reference),
   5.103 +    ("hvm",             integer),
   5.104 +    ("u", KeyedUnion(None, "hvm",
   5.105 +                [("hvm", "%s", Struct(None,
   5.106 +                                       [("pae", bool),
   5.107 +                                        ("apic", bool),
   5.108 +                                        ("acpi", bool),
   5.109 +                                        ("nx", bool),
   5.110 +                                        ("viridian", bool),
   5.111 +                                        ("timeoffset", string),
   5.112 +                                        ("hpet", bool),
   5.113 +                                        ("vpt_align", bool),
   5.114 +                                        ("timer_mode", integer),
   5.115 +                                        ])),
   5.116 +                 ("pv", "!%s", Struct(None,
   5.117 +                                       [("slack_memkb", uint32),
   5.118 +                                        ("bootloader", string, True),
   5.119 +                                        ("bootloader_args", string, True),
   5.120 +                                        ("cmdline", string),
   5.121 +                                        ("ramdisk", libxl_file_reference),
   5.122 +                                        ("features", string, True),
   5.123 +                                        ])),
   5.124 +                 ])),
   5.125 +    ],
   5.126 +    comment =
   5.127 +"""Instances of libxl_file_reference contained in this struct which
   5.128 +have been mapped (with libxl_file_reference_map) will be unmapped
   5.129 +by libxl_domain_build/restore. If either of these are never called
   5.130 +then the user is responsible for calling
   5.131 +libxl_file_reference_unmap.""")
   5.132 +
   5.133 +libxl_domain_build_state = Struct("domain_build_state",[
   5.134 +    ("store_port",   uint32),
   5.135 +    ("store_mfn",    unsigned_long),
   5.136 +    ("console_port", uint32),
   5.137 +    ("console_mfn",  unsigned_long),
   5.138 +    ])
   5.139 +
   5.140 +libxl_device_model_info = Struct("device_model_info",[
   5.141 +    ("domid",            integer),
   5.142 +    ("uuid",             libxl_uuid,  False, "this is use only with stubdom, and must be different from the domain uuid"),
   5.143 +    ("dom_name",         string),
   5.144 +    ("device_model",     string),
   5.145 +    ("saved_state",      string),
   5.146 +    ("type",             libxl_qemu_machine_type),
   5.147 +    ("videoram",         integer,           False, "size of the videoram in MB"),
   5.148 +    ("stdvga",           bool,              False, "stdvga enabled or disabled"),
   5.149 +    ("vnc",              bool,              False, "vnc enabled or disabled"),
   5.150 +    ("vnclisten",        string,            False, "address:port that should be listened on for the VNC server if vnc is set"),
   5.151 +    ("vncpasswd",        string,            False, "the VNC password"),
   5.152 +    ("vncdisplay",       integer,           False, "set VNC display number"),
   5.153 +    ("vncunused",        bool,              False, "try to find an unused port for the VNC server"),
   5.154 +    ("keymap",           string,            False, "set keyboard layout, default is en-us keyboard"),
   5.155 +    ("sdl",              bool,              False, "sdl enabled or disabled"),
   5.156 +    ("opengl",           bool,              False, "opengl enabled or disabled (if enabled requires sdl enabled)"),
   5.157 +    ("nographic",        bool,              False, "no graphics, use serial port"),
   5.158 +    ("serial",           string,            False, "serial port re-direct to pty deivce"),
   5.159 +    ("boot",             string,            False, "boot order, for example dca"),
   5.160 +    ("usb",              bool,              False, "usb support enabled or disabled"),
   5.161 +    ("usbdevice",        string,            False, "enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse"),
   5.162 +    ("soundhw",          string,            False, "enable sound hardware"),
   5.163 +    ("apic",             bool,              False, "apic enabled or disabled"),
   5.164 +    ("vcpus",            integer,           False, "max number of vcpus"),
   5.165 +    ("vcpu_avail",       integer,           False, "vcpus actually available"),
   5.166 +    ("xen_platform_pci", integer,           False, "enable/disable the xen platform pci device"),
   5.167 +    ("extra",            libxl_string_list, False, "extra parameters pass directly to qemu, NULL terminated"),
   5.168 +    ],
   5.169 +    comment=
   5.170 +"""Device Model information.
   5.171 +
   5.172 +Network is missing""")
   5.173 +
   5.174 +libxl_device_vfb = Struct("device_vfb", [
   5.175 +    ("backend_domid", uint32),
   5.176 +    ("domid",         uint32),
   5.177 +    ("devid",         integer),
   5.178 +    ("vnc",           bool,     False, "vnc enabled or disabled"),
   5.179 +    ("vnclisten",     string,   False, "address:port that should be listened on for the VNC server if vnc is set"),
   5.180 +    ("vncpasswd",     string,   False, "the VNC password"),
   5.181 +    ("vncdisplay",    integer,  False, "set VNC display number"),
   5.182 +    ("vncunused",     bool,     False, "try to find an unused port for the VNC server"),
   5.183 +    ("keymap",        string,   False, "set keyboard layout, default is en-us keyboard"),
   5.184 +    ("sdl",           bool,     False, "sdl enabled or disabled"),
   5.185 +    ("opengl",        bool,     False, "opengl enabled or disabled (if enabled requires sdl enabled)"),
   5.186 +    ("display",       string),
   5.187 +    ("xauthority",    string),
   5.188 +    ])
   5.189 +
   5.190 +libxl_device_vkb = Struct("device_vkb", [
   5.191 +    ("backend_domid", uint32),
   5.192 +    ("domid", domid),
   5.193 +    ("devid", integer),
   5.194 +    ])
   5.195 +
   5.196 +libxl_device_console = Struct("device_console", [
   5.197 +    ("backend_domid", uint32),
   5.198 +    ("domid", domid),
   5.199 +    ("devid", integer),
   5.200 +    ("consback", libxl_console_consback),
   5.201 +    ("build_state", Reference(libxl_domain_build_state)),
   5.202 +    ("output", string),
   5.203 +    ])
   5.204 +
   5.205 +libxl_device_disk = Struct("device_disk", [
   5.206 +    ("backend_domid", uint32),
   5.207 +    ("domid", domid),
   5.208 +    ("physpath", string),
   5.209 +    ("phystype", libxl_disk_phystype),
   5.210 +    ("virtpath", string),
   5.211 +    ("unpluggable", integer),
   5.212 +    ("readwrite", integer),
   5.213 +    ("is_cdrom", integer),
   5.214 +    ])
   5.215 +
   5.216 +libxl_device_nic = Struct("device_nic", [
   5.217 +    ("backend_domid", uint32),
   5.218 +    ("domid", domid),
   5.219 +    ("devid", integer),
   5.220 +    ("mtu", integer),
   5.221 +    ("model", string),
   5.222 +    ("mac", libxl_mac),
   5.223 +    ("ip", inaddr_ip),
   5.224 +    ("bridge", string),
   5.225 +    ("ifname", string),
   5.226 +    ("script", string),
   5.227 +    ("nictype", libxl_nic_type),
   5.228 +    ])
   5.229 +
   5.230 +libxl_device_net2 = Struct("device_net2", [
   5.231 +    ("devid", integer),
   5.232 +    ("front_mac", libxl_mac),
   5.233 +    ("back_mac", libxl_mac),
   5.234 +    ("backend_domid", uint32),
   5.235 +    ("domid", domid),
   5.236 +    ("trusted", BitField(uint32, 1)),
   5.237 +    ("back_trusted", BitField(uint32, 1)),
   5.238 +    ("filter_mac", BitField(uint32, 1)),
   5.239 +    ("front_filter_mac", BitField(uint32, 1)),
   5.240 +    ("pdev", uint32),
   5.241 +    ("max_bypasses", uint32),
   5.242 +    ("bridge", string),
   5.243 +    ])
   5.244 +
   5.245 +libxl_device_pci = Struct("device_pci", [
   5.246 +    (None, Union(None, [("value", unsigned_integer),
   5.247 +                        (None, Struct(None,[("reserved1", BitField(unsigned_integer, 2)),
   5.248 +                                            ("reg",       BitField(unsigned_integer, 6)),
   5.249 +                                            ("func",      BitField(unsigned_integer, 3)),
   5.250 +                                            ("dev",       BitField(unsigned_integer, 5)),
   5.251 +                                            ("bus",       BitField(unsigned_integer, 8)),
   5.252 +                                            ("reserved2", BitField(unsigned_integer, 7)),
   5.253 +                                            ("enable",    BitField(unsigned_integer, 1)),
   5.254 +                                             ])),
   5.255 +                        ])
   5.256 +     ),
   5.257 +    ("domain", unsigned_integer),
   5.258 +    ("vdevfn", unsigned_integer),
   5.259 +    ("vfunc_mask", unsigned_integer),
   5.260 +    ("msitranslate", bool),
   5.261 +    ("power_mgmt", bool),
   5.262 +    ])
   5.263 +
   5.264 +libxl_diskinfo = Struct("diskinfo", [
   5.265 +    ("backend", string),
   5.266 +    ("backend_id", uint32),
   5.267 +    ("frontend", string),
   5.268 +    ("frontend_id", uint32),
   5.269 +    ("devid", integer),
   5.270 +    ("state", integer),
   5.271 +    ("evtch", integer),
   5.272 +    ("rref", integer),
   5.273 +    ])
   5.274 +
   5.275 +libxl_nicinfo = Struct("nicinfo", [
   5.276 +    ("backend", string),
   5.277 +    ("backend_id", uint32),
   5.278 +    ("frontend", string),
   5.279 +    ("frontend_id", uint32),
   5.280 +    ("devid", integer),
   5.281 +    ("state", integer),
   5.282 +    ("script", string),
   5.283 +    ("mac", libxl_mac),
   5.284 +    ("evtch", integer),
   5.285 +    ("rref_tx", integer),
   5.286 +    ("rref_rx", integer),
   5.287 +    ])
   5.288 +
   5.289 +libxl_vcpuinfo = Struct("vcpuinfo", [
   5.290 +    ("vcpuid", uint32,              False, "vcpu's id"),
   5.291 +    ("cpu", uint32,                 False, "current mapping"),
   5.292 +    ("online", BitField(uint8, 1),  False, "currently online (not hotplugged)?"),
   5.293 +    ("blocked", BitField(uint8, 1), False, "blocked waiting for an event?"),
   5.294 +    ("running", BitField(uint8, 1), False, "currently scheduled on its CPU?"),
   5.295 +    ("vcpu_time", uint64,           False, "total vcpu time ran (ns)"),
   5.296 +    ("cpumap", libxl_cpumap,        False, "current cpu's affinities"),
   5.297 +    ])
   5.298 +
   5.299 +libxl_physinfo = Struct("physinfo", [
   5.300 +    ("threads_per_core", uint32),
   5.301 +    ("cores_per_socket", uint32),
   5.302 +
   5.303 +    ("max_cpu_id", uint32),
   5.304 +    ("nr_cpus", uint32),
   5.305 +    ("cpu_khz", uint32),
   5.306 +
   5.307 +    ("total_pages", uint64),
   5.308 +    ("free_pages", uint64),
   5.309 +    ("scrub_pages", uint64),
   5.310 +
   5.311 +    ("nr_nodes", uint32),
   5.312 +    ("hw_cap", libxl_hwcap),
   5.313 +    ("phys_cap", uint32),
   5.314 +    ])
   5.315 +
   5.316 +libxl_sched_credit = Struct("sched_credit", [
   5.317 +    ("weight", integer),
   5.318 +    ("cap", integer),
   5.319 +    ])
   5.320 +
   5.321 +libxl_net2info = Struct("net2info", [
   5.322 +    ("backend", string),
   5.323 +    ("backend_id", uint32),
   5.324 +    ("frontend", string),
   5.325 +    ("frontend_id", uint32),
   5.326 +    ("devid", integer),
   5.327 +    ("state", integer),
   5.328 +    ("mac", libxl_mac),
   5.329 +    ("trusted", integer),
   5.330 +    ("back_mac", libxl_mac),
   5.331 +    ("filter_mac", integer),
   5.332 +    ])
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxl/libxltypes.py	Thu Aug 19 15:15:55 2010 +0100
     6.3 @@ -0,0 +1,168 @@
     6.4 +import sys
     6.5 +
     6.6 +class Type(object):
     6.7 +    def __init__(self, typename, **kwargs):
     6.8 +        self.comment = kwargs.setdefault('comment', None)
     6.9 +        self.namespace = kwargs.setdefault('namespace', "libxl_")
    6.10 +
    6.11 +        if typename is None: # Anonymous type
    6.12 +            self.typename = None
    6.13 +        elif self.namespace is None: # e.g. system provided types
    6.14 +            self.typename = typename
    6.15 +        else:
    6.16 +            self.typename = self.namespace + typename
    6.17 +
    6.18 +class Builtin(Type):
    6.19 +    """Builtin type"""
    6.20 +    def __init__(self, typename, **kwargs):
    6.21 +        Type.__init__(self, typename, **kwargs)
    6.22 +
    6.23 +class UInt(Type):
    6.24 +    def __init__(self, w, **kwargs):
    6.25 +        kwargs.setdefault('namespace', None)
    6.26 +        Type.__init__(self, "uint%d_t" % w, **kwargs)
    6.27 +
    6.28 +        self.width = w
    6.29 +
    6.30 +class BitField(Type):
    6.31 +    def __init__(self, ty, w, **kwargs):
    6.32 +        kwargs.setdefault('namespace', None)
    6.33 +        Type.__init__(self, ty.typename, **kwargs)
    6.34 +
    6.35 +        self.width = w
    6.36 +
    6.37 +class Field(object):
    6.38 +    """An element of an Aggregate type"""
    6.39 +    def __init__(self, type, name, **kwargs):
    6.40 +        self.type = type
    6.41 +        self.name = name
    6.42 +        self.const = kwargs.setdefault('const', False)
    6.43 +        self.comment = kwargs.setdefault('comment', None)
    6.44 +        self.keyvar_expr = kwargs.setdefault('keyvar_expr', None)
    6.45 +
    6.46 +class Aggregate(Type):
    6.47 +    """A type containing a collection of other types"""
    6.48 +    def __init__(self, kind, typename, fields, **kwargs):
    6.49 +        Type.__init__(self, typename, **kwargs)
    6.50 +
    6.51 +        self.kind = kind
    6.52 +
    6.53 +        self.fields = []
    6.54 +        for f in fields:
    6.55 +            # (name, type[, const=False[, comment=None]])
    6.56 +            if len(f) == 2:
    6.57 +                n,t = f
    6.58 +                const = False
    6.59 +                comment = None
    6.60 +            elif len(f) == 3:
    6.61 +                n,t,const = f
    6.62 +                comment = None
    6.63 +            else:
    6.64 +                n,t,const,comment = f
    6.65 +            self.fields.append(Field(t,n,const=const,comment=comment))
    6.66 +
    6.67 +class Struct(Aggregate):
    6.68 +    def __init__(self, name, fields, **kwargs):
    6.69 +        Aggregate.__init__(self, "struct", name, fields, **kwargs)
    6.70 +
    6.71 +class Union(Aggregate):
    6.72 +    def __init__(self, name, fields, **kwargs):
    6.73 +        Aggregate.__init__(self, "union", name, fields, **kwargs)
    6.74 +
    6.75 +class KeyedUnion(Aggregate):
    6.76 +    """A union which is keyed of another variable in the parent structure"""
    6.77 +    def __init__(self, name, keyvar_name, fields, **kwargs):
    6.78 +        Aggregate.__init__(self, "union", name, [], **kwargs)
    6.79 +
    6.80 +        self.keyvar_name = keyvar_name
    6.81 +
    6.82 +        for f in fields:
    6.83 +            # (name, keyvar_expr, type)
    6.84 +
    6.85 +            # keyvar_expr must contain exactly one %s which will be replaced with the keyvar_name
    6.86 +
    6.87 +            n, kve, ty = f
    6.88 +            self.fields.append(Field(ty, n, keyvar_expr=kve))
    6.89 +
    6.90 +class Reference(Type):
    6.91 +    """A reference to another type"""
    6.92 +    def __init__(self, ty, **kwargs):
    6.93 +        # Ugh
    6.94 +        kwargs.setdefault('namespace', ty.namespace)
    6.95 +        typename = ty.typename[len(kwargs['namespace']):]
    6.96 +        Type.__init__(self, typename + " *", **kwargs)
    6.97 +
    6.98 +#
    6.99 +# Standard Types
   6.100 +#
   6.101 +
   6.102 +void = Builtin("void *", namespace = None)
   6.103 +bool = Builtin("bool", namespace = None)
   6.104 +size_t = Builtin("size_t", namespace = None)
   6.105 +
   6.106 +integer = Builtin("int", namespace = None)
   6.107 +unsigned_integer = Builtin("unsigned int", namespace = None)
   6.108 +unsigned = Builtin("unsigned int", namespace = None)
   6.109 +unsigned_long = Builtin("unsigned long", namespace = None)
   6.110 +
   6.111 +uint8 = UInt(8)
   6.112 +uint16 = UInt(16)
   6.113 +uint32 = UInt(32)
   6.114 +uint64 = UInt(64)
   6.115 +
   6.116 +domid = UInt(32)
   6.117 +
   6.118 +string = Builtin("char *", namespace = None)
   6.119 +
   6.120 +inaddr_ip = Builtin("struct in_addr", namespace = None)
   6.121 +
   6.122 +class OrderedDict(dict):
   6.123 +    """A dictionary which remembers insertion order.
   6.124 +
   6.125 +       push to back on duplicate insertion"""
   6.126 +
   6.127 +    def __init__(self):
   6.128 +        dict.__init__(self)
   6.129 +        self.__ordered = []
   6.130 +
   6.131 +    def __setitem__(self, key, value):
   6.132 +        try:
   6.133 +            self.__ordered.remove(key)
   6.134 +        except ValueError:
   6.135 +            pass
   6.136 +
   6.137 +        self.__ordered.append(key)
   6.138 +        dict.__setitem__(self, key, value)
   6.139 +
   6.140 +    def ordered_keys(self):
   6.141 +        return self.__ordered
   6.142 +    def ordered_values(self):
   6.143 +        return [self[x] for x in self.__ordered]
   6.144 +    def ordered_items(self):
   6.145 +        return [(x,self[x]) for x in self.__ordered]
   6.146 +
   6.147 +def parse(f):
   6.148 +    print >>sys.stderr, "Parsing %s" % f
   6.149 +
   6.150 +    globs = {}
   6.151 +    locs = OrderedDict()
   6.152 +
   6.153 +    for n,t in globals().items():
   6.154 +        if isinstance(t, Type):
   6.155 +            globs[n] = t
   6.156 +        elif isinstance(t,type(object)) and issubclass(t, Type):
   6.157 +            globs[n] = t
   6.158 +
   6.159 +    try:
   6.160 +        execfile(f, globs, locs)
   6.161 +    except SyntaxError,e:
   6.162 +        raise SyntaxError, \
   6.163 +              "Errors were found at line %d while processing %s:\n\t%s"\
   6.164 +              %(e.lineno,f,e.text)
   6.165 +
   6.166 +    types = [t for t in locs.ordered_values() if isinstance(t,Type)]
   6.167 +
   6.168 +    builtins = [t for t in types if isinstance(t,Builtin)]
   6.169 +    types = [t for t in types if not isinstance(t,Builtin)]
   6.170 +
   6.171 +    return (builtins,types)