Generating Source Code from a Knowledge Base

by The Scientific Programming Group

UCO / Lick Observatory


In both the ADASS and Tcl97 papers I made optimistic remarks about being able to "generate source code" from the knowledge base, claiming that this was a logical next step and would be fairly trivial. Now I I have some tangible proof of concept. A Tcl application called "CodeGen" (about 20 hours of work so far) generates useful source modules from information in the online database.

See the directory esi for sample files. The most interesting files are fiord_table.h and the inst_kw_ids and float/int/string .h files. Some of the .h files are not really C source, but are Galil motor controller source for use with cpp.

These files were generated from the existing Memes schema, augmented by a few new tables storing realtime controller and device parameters (the stuff you see in Areset.h and so forth). There are many cross references between the files, in nomenclature and value. When they were maintained manually by multiple developers, confusion and inconsistency were constant hazards.

The generated versions offer guaranteed consistency of content and format, low-cost "frills" like abundant inline documentation (tedious and sometimes overlooked during manual maintenance), and regeneration on demand whenever the underlying data change. Generation time for the 20 files is about 2 wallclock minutes on a fairly slow Sparcstation.

We are still finding more code from the realtime tree which looks susceptible to generation. Our goal is to reduce the repetitive drudgework to nearly nil, so our programmers can focus on the interesting problems.

At this time our method is as follows: the generated files are inclusions into standard or slightly customized "wrapper" files, which live in the CVS source tree with the rest of the code for specific instruments. The CodeGen application places the generated files in a universally-visible location like /opt/share/KTL/Generated, using one subdirectory per instrument (Generated/pfcam, for example). The Makefiles for the individual instruments copy the Generated files down to the local source location, where it is checked in and tagged with the rest of a release. This enables us to roll back releases without having to recapture past states of the online database.

The Lick Prime Focus Camera was controlled using generated code in September 1997 during a mixed engineering/science run.


A Public Service of UCO/Lick Observatory
Courtesy of the Scientific Programming Group
Using Sybase Server, Tcl, HTML
webmaster@ucolick.org