AutoPas  3.0.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
autopas::RuleVM Class Reference

A VM that is capable of executing a program with simple instructions on a stack of MemoryCells. More...

#include <RuleVM.h>

Classes

struct  Instruction
 An instruction to execute in the VM. More...
 
struct  Program
 A program that can be executed by this VM. More...
 

Public Types

enum  CMD {
  LOADC , LOADA , STOREA , RESERVE ,
  LESS , GREATER , EQUAL , JUMPZERO ,
  OUTPUTC , CONDOUTPUTC , HALT , AND ,
  OR , POP , MUL , DIV ,
  ADD , SUB , NOT
}
 An enum with all commands that this VM supports. More...
 
using MemoryCell = std::variant< bool, double, size_t, ContainerOption, TraversalOption, LoadEstimatorOption, DataLayoutOption, Newton3Option >
 The type of a memory cell in the stack the VM operates on.
 

Public Member Functions

std::vector< size_t > execute (const Program &program, const std::vector< MemoryCell > &initialStack)
 Executes a program on a given initial stack.
 

Detailed Description

A VM that is capable of executing a program with simple instructions on a stack of MemoryCells.

The result of the program is produced using a special output instruction CMD::OUTPUTC. A vector of numbers produced by executing these instructions is returned in the execute() method.

The VM is used to execute generated code by RuleBasedProgramTree. In this generated code, each configuration order is assigned a number. If this number is output using OUTPUTC, the configuration order should be applied in the current tuning phase.

Member Enumeration Documentation

◆ CMD

An enum with all commands that this VM supports.

Enumerator
LOADC 

Load a constant on top of the stack (payload).

LOADA 

Payload is absolute stack address.

Loads the value of the stack at this address on top of the stack.

STOREA 

Payload is absolute stack address.

Stores the top of the stack into the stack at the given address. Pops top.

RESERVE 

Payload is number of stack cells to reserve.

Increases stack pointer by this value.

LESS 

Binary comparison.

Consumes two stack cells and puts True on top if stack[SP-1] < stack[SP], False otherwise.

GREATER 

Binary comparison.

Consumes two stack cells and puts True on top if stack[SP-1] > stack[SP], False otherwise.

EQUAL 

Binary comparison.

Consumes two stack cells and puts True on top if stack[SP-1] == stack[SP], False otherwise.

JUMPZERO 

Payload is program address.

Jumps to this address if value of top of the stack is False. Consumes this value.

OUTPUTC 

Outputs payload.

All output values are returned as result from the program execution.

CONDOUTPUTC 

Executes OUTPUTC if top of the stack is True.

Does not consume this condition value.

HALT 

Halts program execution.

AND 

Binary operator.

Consumes two stack cells and puts True on top if stack[SP-1] && stack[SP], False otherwise.

OR 

Binary operator.

Consumes two stack cells and puts True on top if stack[SP-1] || stack[SP], False otherwise.

POP 

Pops one value from the stack.

MUL 

Binary operator.

Consumes two stack cells and puts stack[SP-1] * stack[SP] on top.

DIV 

Binary operator.

Consumes two stack cells and puts stack[SP-1] / stack[SP] on top.

ADD 

Binary operator.

Consumes two stack cells and puts stack[SP-1] + stack[SP] on top.

SUB 

Binary operator.

Consumes two stack cells and puts stack[SP-1] - stack[SP] on top.

NOT 

Unary operator.

Changes the value of top of the stack to !stack[SP].

Member Function Documentation

◆ execute()

std::vector< size_t > autopas::RuleVM::execute ( const Program program,
const std::vector< MemoryCell > &  initialStack 
)
inline

Executes a program on a given initial stack.

Parameters
programThe program to execute.
initialStackThe stack to use when executing the program. (Can already contain some data).
Returns
A vector of output values produced by CMD::OUTPUTC instructions executed.

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