Dehydra API
This is an attempt to document the functions for writing scripts for Dehydra GCC. It is incomplete, as is dehydra-gcc itself, so things are in constant flux.
Callback Functions
Dehydra works by calling functions in your Javascript for elements of the source code file. You are not required to have any of these functions in your script: if a function is not there, Dehydra will know and will not try to call it. Here are the functions Dehydra will call:
process_class(cls)
Dehydra calls this for each class/struct. process_class is called after process_function is called for all the member functions. cls is a JS object representing the class, with the following properties:
- .kind
- "class" or "struct"
- .bases
- An array representing the base classes of this class.
- .members
- An array of member variables and functions.
process_function(func)
Dehydra calls this for each top-level function or class member function. func is a JS object with the function name, type, location, and isStatic property.
process_var(decl)
decl is a JS object representing a variable declaration outside of a function body.
process_tree(func, body)
func is a function declaration. body is a JS object representing the CFG for a function body. NOT YET FULLY IMPLEMENTED
input_end()
Called once at the end of the C++ source file.
Type objects
Dehydra provides detailed type objects. A Dehydra type object can represent a primitive type (with name attribute), a class type (with name, members attributes, etc.), a pointer type (with isPointer=true and a type attribute), a reference type (with isReference=true and a type attribute), or a function pointer type (with parameters attribute, etc).
Builtin functions
The following functions are provided by dehydra and may be called by the user:
warning(msg, ...)
Print one or more warning messages using the GCC warning mechanism. If -Werror is specified this will cause compilation to fail.
error(msg, ...)
Print one or more error messages using the GCC error mechanism. This will cause compilation to fail.
print(msg)
Print a string to stdout (or stderr if the compiler is piping output). If the current callback is associated with a particular location, the location will be printed first.
_print(msg, ...)
Like print() but the location will not be printed.
read_file(filename)
Read a file a return it as a string.
write_file(filename, data)
Write a string to a file.