Library Support

This section contains definitions declared in the chpl::libraries namespace.

namespace libraries


static inline Region makeRegion(uint64_t startOffset, uint64_t endOffset)


static const uint64_t FILE_HEADER_MAGIC = 0x4c50484342494c7f
static const uint64_t MODULE_SECTION_MAGIC = 0x4d4dd01e5ec14d4d
static const uint64_t SYMBOL_TABLE_MAGIC = 0x4d59531e5ec110e0
static const uint64_t UAST_SECTION_MAGIC = 0x5453411e5ec110e0
static const uint32_t LONG_STRINGS_TABLE_MAGIC = 0x52545301
static const uint64_t LOCATION_SECTION_MAGIC = 0x434F4C075ec110e0
static const uint64_t GEN_CODE_SECTION_MAGIC = 0x4e4547075ec110e0
static const uint32_t FORMAT_VERSION_MAJOR = 0
static const uint32_t FORMAT_VERSION_MINOR = 1
static const int HASH_SIZE = 256 / 8
static const int MAX_NUM_MODULES = 100000000
static const int MAX_NUM_SYMBOLS = 100000000
static const int MAX_NUM_FILES = 100000000
static const int MAX_NUM_ASTS = 100000000
struct AstSectionHeader

Public Members

uint64_t magic
uint64_t nEntries
struct FileHeader

Public Members

uint64_t magic
uint32_t fileFormatVersionMajor
uint32_t fileFormatVersionMinor
uint32_t chplVersionMajor
uint32_t chplVersionMinor
uint32_t chplVersionUpdate
uint32_t nModules
uint8_t hash[HASH_SIZE]
struct GenCodeSectionHeader

Public Members

uint64_t magic
uint64_t len
class LibraryFile
#include <LibraryFile.h>

For reading a .dyno LibraryFile. Some data is read from the file on-demand. Uses mmap to keep the code simple and to support random-access well.

Public Functions

bool operator==(const LibraryFile &other) const
inline bool operator!=(const LibraryFile &other) const
size_t hash()
void mark(Context *context) const
void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const
void registerLibrary(Context *context) const

Register all of the paths supported by this library so that attempts to load a module contained in the library will use the library version.

std::vector<UniqueString> containedFilePaths() const

Returns a vector containing the paths stored in this module.

void summarize(Context *context, std::ostream &s) const

Print a summary of a LibraryFile.

const uast::BuilderResult &loadSourceAst(Context *context, UniqueString fromSourcePath) const

Load uAST from this LibraryFile for a particular source path.

const uast::Module *loadModuleAst(Context *context, UniqueString moduleSymPath) const

Load uAST from a this LibraryFile for a particular module path. For a toplevel module, the module path is just the module name. For a submodule M of a parent module P, it would be P.M.

Returns nullptr if no such module is found in this LibraryFile or if an error occurred.

const LocationMaps &loadLocations(Context *context, int moduleIndex, int symbolTableEntryIndex, const uast::AstNode *symbolTableEntryAst) const

Lookup the location for an Ast node stored in this library file. Assumes that ‘ast’ is stored within the Locations section found from module ‘moduleIndex’ and symbol entry ‘symbolTableEntryIndex’.

Public Static Functions

static bool update(owned<LibraryFile> &keep, owned<LibraryFile> &addin)
static const LibraryFile *load(Context *context, UniqueString libPath)

This query reads the file from the given path and produces a LibraryFile, which represents the contents of the library.

struct LocationMaps
#include <LibraryFile.h>

Helper type to be returned by loadLocations

Public Types

using MapType = std::unordered_map<const uast::AstNode*, Location>

Public Functions

void clear()
const MapType *getLocationMap(int tag) const
MapType *getLocationMap(int tag)
void swap(LocationMaps &other)
void mark(Context *context) const

Public Members

MapType astToLocation

Public Static Functions

static bool update(LocationMaps &keep, LocationMaps &addin)
class ModuleSection
#include <LibraryFile.h>

Helper object to represent a loaded Symbol Table from a module section.

Public Functions

inline bool operator==(const ModuleSection &other) const
inline bool operator!=(const ModuleSection &other) const
inline void mark(Context *context) const

Public Static Functions

static inline bool update(owned<ModuleSection> &keep, owned<ModuleSection> &addin)
class LibraryFileDeserializationHelper
#include <LibraryFile.h>

Helper object to interact with the Deserializer to: read long strings from a LibraryFile strings table register deserialized AstNodes for symbol table objects

Public Functions

std::pair<size_t, const char*> getString(int id) const

Given a long string index, returns the string size and the string data. The string won’t necessarily be null-terminated. Returns a 0-length string if the ID is out of bounds.

void registerAst(const uast::AstNode *ast, uint64_t startOffset)

When deserializing an AstNode, track some of the uast nodes to be able to map them back to symbol table id.

class LibraryFileSerializationHelper
#include <LibraryFileWriter.h>

Helper object for registering serialized uAST positions during serialization

Public Functions

void noteSymbolForTable(const uast::AstNode *ast)

Record that a symbol should be present in the symbol table.

void beginAst(const uast::AstNode *ast, std::ostream &os)
void endAst(const uast::AstNode *ast, std::ostream &os)
class LibraryFileWriter
#include <LibraryFileWriter.h>

For writing a .dyno library file

Public Functions

inline LibraryFileWriter(Context *context, std::string outputFilePath)

Construct a LibraryFileWriter to output to ‘outputFilePath’

void setSourcePaths(std::vector<UniqueString> paths)

Parse the uAST for the provided source paths and save the result.

void setGeneratedCode(UniqueString modName, std::string buffer, std::unordered_map<ID, std::vector<GenInfo>> genMap)

Set the buffer storing the generated LLVM IR byte code for the top-level module with the passed name.

Must be done after ‘setSourcePaths’.

bool writeAllSections()

Write the header and sections to the library file. Returns ‘true’ if everything is OK, or ‘false’ if there was an error in the process.

Public Static Functions

static std::vector<UniqueString> gatherTopLevelModuleNames(Context *context, std::vector<UniqueString> paths)

Gather the names of the top-level modules in the source code files from ‘paths’

struct GenInfo

Public Members

UniqueString cname
bool isInstantiation = false
struct LocationSectionHeader

Public Members

uint64_t magic
uint32_t nFilePaths
uint32_t nGroups
struct LongStringsTableHeader

Public Members

uint32_t magic
uint32_t nLongStrings
struct ModuleHeader

Public Members

uint64_t magic
uint64_t flags
Region symbolTable
Region astSection
Region longStringsTable
Region locationSection
Region genCodeSection
struct Region

Public Members

uint64_t start
uint64_t end
struct SymbolTableEntry

Public Members

uint32_t astEntry
uint32_t locationEntry
struct SymbolTableHeader

Public Members

uint64_t magic
uint32_t nEntries
uint32_t unused