☰

PART III - CiaoPP Internals

CiaoPP can be loaded into the top-level shell as a module and can also be imported into a user program module. There are predicates that activate each option, a predicate to load the file(s) to be processed, and predicates to perform each CiaoPP task. There is also a command line interface that can be used to start a CiaoPP interactive shell or to process files in batch mode.

This document describes the structure of CiaoPP's code, its components, and their functionality, from the point of view of the implementer, rather than that of the user.

How to use CiaoPP in your own preprocessor

If you implement a program for preprocessing (Ciao) Prolog programs, you can take advantage of the facilities provided by CiaoPP. The basic facilities are described in the following chapters. In particular, the chapter on module driver explains how to integrate your tool and CiaoPP to make them work together.

One particularly useful feature of CiaoPP is that it provides for the correct reading of an input program to be preprocessed (this is more tricky than it seems, because of all of the language features that the program might be using). Once a program is read in by CiaoPP, your tool can process it as plain Prolog. The chapter on module p_unit explains how a program is (correctly) read in, and provides an interface so that you can retrieve information about that program.

Depending on the kind of preprocessing you want to do, you may want to use other parts of CiaoPP. If your program is doing program transformations, then the chapters on program_keys and tr_syntax might be helpful. If you want to use analysis information to help the transformations, then the chapter on infer is the one to read. If your program is a program analyzer based on abstract interpretation, then have a look at the chapters on plai and domains. Program analyses not based on abstract interpretation (and other possible tools) may be a bit harder to incorporate: you might need to develop first your skills with the CiaoPP code.


Subparts

Other information

The work of CiaoPP is focused in principle on one-module-at-a-time (although there are also facilities for processing sets of modules). The file being preprocessed at a given time is called the current module . If the file is of the user module, it is considered as a module which exports all its predicates.

The preprocessing unit is the code of the current module together with the set of assertions / properties (also of related modules) which together allow a correct and complete interpretation of the assertions present for the current module. Assertions and properties are usually cached in auxiliary files, with .asr suffix.

Basic structure of the code

The code of CiaoPP is divided into components, each of which provides a particular functionality. The top-level organization of the main components is as follows:

Each component is addressed by a particular qualifier, which makes reference to modules independent of the particular library paths. These qualifiers are defined in file paths.pl. The qualifier for the top-level components is ciaopp.

The component p_unit is addressed by qualifier program and is in charge of processing the .asr files, gathering together the code for the preprocessing unit of the current module.

The component tr_syntax is addressed by qualifier syntax and implements simple source code syntactic transformations (like removing disjunctions and the like).

The component infer is addressed by qualifier infer and is in charge of serving all known semantic information on the current module, from any analysis and/or assertion.

The component plai is addressed by qualifier plai and implements abstract interpretation based analysis.

The component infernf is addressed by qualifier infernf and implements the non-failure analysis.

The component infercost is addressed by qualifier infercost and implements the cost analysis.