ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
CompilerPlugin::CIBinaryOp Struct Reference

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 388 of file compilerplugin.hpp.

#include <compilerplugin.hpp>

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

Public Field Index:

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

Public Method Index:

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

Field Details:

◆ LhsIsConst

bool LhsIsConst

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

Definition at line 393 of file compilerplugin.hpp.

◆ NonConstArgIsResult

bool NonConstArgIsResult

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

Definition at line 399 of file compilerplugin.hpp.

◆ Operator

String& Operator

Input/Output: The binary operator symbol.

Definition at line 390 of file compilerplugin.hpp.

◆ RhsIsConst

bool RhsIsConst

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

Definition at line 396 of file compilerplugin.hpp.

Constructor(s) / Destructor Details::

◆ 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 410 of file compilerplugin.hpp.


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