ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Fields | Public Methods | List of all members
CompilerPlugin::CIBinaryOp Struct Reference

#include <compilerplugin.hpp>

Inheritance diagram for CompilerPlugin::CIBinaryOp:
[legend]
Collaboration diagram for CompilerPlugin::CIBinaryOp:
[legend]

Class Description


Info struct for compiling a binary operator. This struct is used with method TryCompilation(CIBinaryOp&) to provide information to derived compiler plug-ins, as well as to receive information back.

Information about whether the arguments are constants is separately given for lhs and rhs with fields LhsIsConst and RhsIsConst.

If both flags evaluate to true, operator callback functions that do not use context information from the scope (or otherwise rely on external or random data), should calculate the - then constant - result at compile-time and return a constant value instead of the callback method.

If exactly one of the argument is constant, then some operators might detect further possibilities of optimization. Such optimization is operator-specific but goes along the lines of the following samples:

 term    +       0     -> term
 term    -       0     -> term
 term    *       0     -> 0
 term    *       1     -> term
 term    /       1     -> term
 term   &&   false     -> false
 term   &&    true     -> term
 term   ||    true     -> true
 term   ||   false     -> term

These cases have in common that the result of the operator is either a constant or equals the non-constant argument.

In both cases inherited field Callback is to be left nullptr. If the result is constant, inherited field TypeOrValue is to be set to the constant value. In the second case that the non-constant argument equals the result, this can be indicated by setting field NonConstArgIsResult to true. In this case, the compiler will choose the non-constant argument and drop the other.

Note
Class Calculus which specializes this plug-in class, provides a convenient way to define the optimization rules described here, along with its mechanics to support binary operator compilation.

Definition at line 387 of file compilerplugin.hpp.

Public Fields

bool LhsIsConst
 
bool NonConstArgIsResult
 
StringOperator
 Input/Output: The binary operator symbol.
 
bool RhsIsConst
 
- Public Fields inherited from CompilerPlugin::CompilationInfo
ArgIterator ArgsBegin
 
ArgIterator ArgsEnd
 
CallbackDecl Callback = nullptr
 
MonoAllocatorCompileTimeAllocator
 
ScopeCompileTimeScope
 
const ncharDbgCallbackName = nullptr
 
Box TypeOrValue = nullptr
 

Public Methods

 CIBinaryOp (Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool lhsIsConst, bool rhsIsConst)
 
- Public Methods inherited from CompilerPlugin::CompilationInfo
 CompilationInfo (Scope &scope, MonoAllocator &allocator)
 

Constructor & Destructor Documentation

◆ CIBinaryOp()

CIBinaryOp ( Scope scope,
MonoAllocator compileTimeAllocator,
String op,
bool  lhsIsConst,
bool  rhsIsConst 
)
inline

Constructor.

Parameters
scopePassed to parent.
compileTimeAllocatorPassed to parent.
opStored in Operator.
lhsIsConstStored in LhsIsConst.
rhsIsConstStored in RhsIsConst.

Definition at line 409 of file compilerplugin.hpp.

Member Data Documentation

◆ LhsIsConst

bool LhsIsConst

Input: Denotes if the lhs-argument is a constant value.

Definition at line 392 of file compilerplugin.hpp.

◆ NonConstArgIsResult

bool NonConstArgIsResult

Output: Used with optimization, see this struct's documentation for more information.

Definition at line 398 of file compilerplugin.hpp.

◆ RhsIsConst

bool RhsIsConst

Input: Denotes if the rhs-argument is a constant value.

Definition at line 395 of file compilerplugin.hpp.


The documentation for this struct was generated from the following file: