A DML source file describes both the structure of the modeled device and the actions to be taken when the device is accessed.
A DML source file defining a device starts with a language version declaration and a device declaration. After that, any number of parameter declarations, methods, data fields, object declarations, or global declarations can be written. A DML file intended to be imported (by an import statement in another DML file) has the same layout except for the device declaration.
Every DML source file should contain a version declaration, on the form "dml m.n;", where m and n are nonnegative integers denoting the major and minor version of DML, respectively, that the source file is written in. The version declaration allows the dmlc compiler to select the proper versions of the DML parser and standard libraries to be used for the file. (Note that each file has its own individual language version, even if it is imported by a file using another version.) A file should not import a file with a higher language version than its own.
The version declaration must be the first declaration in the file, possibly preceded by comments. For example:
// My Device dml 1.0; ...
A file that does not contain any version declaration is assumed to have the version DML 0.9, for reasons of backward compatibility with existing legacy code, but this feature will eventually be deprecated. All new code should use DML 1.0 or later, and all old code should at a minimum be given the version declaration "dml 0.9;", or preferably be rewritten in DML 1.0.
Every DML source file that contains a device declaration is a DML program, and defines a device class with the specified name. Such a file may import other files, but only the initial file may contain a device declaration.
The device declaration must be the first proper declaration in the file, only preceded by comments and the language version declaration. For example:
/* * My New Device */ dml 1.0; device my_device; ...
The following is an example of a small DML program defining a very simple device. This lacks many details that would appear in a real device.
dml 1.0; device excalibur; connect bus { interface pci; } bank config_registers { parameter function = 0; register cfg1 size 4 @ 0x0000 { field status { method read { ... } method write { ... } } field enable { method read { ... } method write { ... } } } } bank databank { parameter function = 1; register r1 size 4 @ 0x0000 { field f1 { method read { ... } method write { ... } } } register r2 size 4 @ 0x0004 { field f2 { method read { ... } method write { ... } } } }