106 lines
3.6 KiB
C++
106 lines
3.6 KiB
C++
|
#include <libregexis024vm/libregexis024vm_interface.h>
|
||
|
#include <libregexis024vm/libregexis024vm.h>
|
||
|
#include <libregexis024vm/instruction_implementation.h>
|
||
|
|
||
|
bool REGEX_IS024_CAEvent::operator==(const REGEX_IS024_CAEvent &other) const {
|
||
|
return (key == other.key) && (value == other.value);
|
||
|
}
|
||
|
|
||
|
#define reveal ((REGEX_IS024_CONTEXT*)opaque)
|
||
|
|
||
|
REGEX_IS024_VirtualMachine::REGEX_IS024_VirtualMachine(size_t programSize, const uint8_t *data,
|
||
|
uint64_t caTreeLimit, regex_tai_t saLenLimit,
|
||
|
regex_sslot_id_t readSsLimit, regex_sslot_id_t forkSsLimit,
|
||
|
uint64_t timeTickLimit) {
|
||
|
opaque = new REGEX_IS024_CONTEXT(programSize, data, caTreeLimit, saLenLimit,
|
||
|
readSsLimit, forkSsLimit, timeTickLimit);
|
||
|
}
|
||
|
|
||
|
regex024_error_code REGEX_IS024_VirtualMachine::initialize() {
|
||
|
if (gave_SOF)
|
||
|
exitf("double feedSOF\n");
|
||
|
gave_SOF = true;
|
||
|
return reveal->feedSOF();
|
||
|
}
|
||
|
|
||
|
bool REGEX_IS024_VirtualMachine::isInitialized() {
|
||
|
return reveal->initialized;
|
||
|
}
|
||
|
|
||
|
bool REGEX_IS024_VirtualMachine::isUsable() {
|
||
|
return isInitialized() && reveal->error == regex024_error_codes::stable;
|
||
|
}
|
||
|
|
||
|
REGEX_IS024_VirtualMachine::~REGEX_IS024_VirtualMachine() {
|
||
|
delete reveal;
|
||
|
}
|
||
|
|
||
|
regex_tai_t REGEX_IS024_VirtualMachine::getSelectionArrayLength() {
|
||
|
return isUsable() ? reveal->selection_array_len : 0;
|
||
|
}
|
||
|
|
||
|
bool REGEX_IS024_VirtualMachine::isAllowMultistart() {
|
||
|
return isUsable() ? reveal->allows_multistart : false;
|
||
|
}
|
||
|
|
||
|
uint8_t REGEX_IS024_VirtualMachine::getInputLeftExtensionSize() {
|
||
|
return isUsable() ? reveal->fed_input_extends_left : 0;
|
||
|
}
|
||
|
|
||
|
uint8_t REGEX_IS024_VirtualMachine::getInputRightExtensionSize() {
|
||
|
return isUsable() ? reveal->fed_input_extends_right : 0;
|
||
|
}
|
||
|
|
||
|
regex024_error_code REGEX_IS024_VirtualMachine::getErrno() {
|
||
|
return reveal->error;
|
||
|
}
|
||
|
|
||
|
/* Stupid kinda function. Checks if somebody is ready to continue reading the actual string */
|
||
|
bool REGEX_IS024_VirtualMachine::haveSurvivors() {
|
||
|
return isUsable() && (reveal->READ_halted_stack_new_first.non_empty());
|
||
|
}
|
||
|
|
||
|
bool REGEX_IS024_VirtualMachine::isMatched() {
|
||
|
return isUsable() && static_cast<bool>((reveal->matched_thread.slot_occupation_status & SLOT_OCCUPIED));
|
||
|
}
|
||
|
|
||
|
std::vector<REGEX_IS024_CAEvent> REGEX_IS024_VirtualMachine::getMatchedThreadCABranchReverse() {
|
||
|
if (!isMatched())
|
||
|
return {};
|
||
|
std::vector<REGEX_IS024_CAEvent> res;
|
||
|
REGEX024_CollectionArrayNode* cur = reveal->matched_thread.CAHptr;
|
||
|
while (cur != NULL){
|
||
|
res.push_back({cur->key, cur->value});
|
||
|
cur = cur->prev;
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
uint64_t REGEX_IS024_VirtualMachine::getMatchedThreadSAValue(uint16_t key) {
|
||
|
if (key >= getSelectionArrayLength())
|
||
|
return 0;
|
||
|
if (!isMatched())
|
||
|
return 0;
|
||
|
return reveal->matched_thread.SAptr ? reveal->matched_thread.SAptr[key + 1] : 0;
|
||
|
}
|
||
|
|
||
|
regex024_error_code REGEX_IS024_VirtualMachine::addNewMatchingThread() {
|
||
|
if (!isUsable())
|
||
|
exitf("unusable\n");
|
||
|
// if (started_first_thread && !isAllowMultistart())
|
||
|
// exitf("Multistart is forbidden, bad usage of program\n");
|
||
|
return reveal->startThread();
|
||
|
}
|
||
|
|
||
|
regex024_error_code REGEX_IS024_VirtualMachine::extendedFeedCharacter(uint64_t input) {
|
||
|
if (!isUsable())
|
||
|
exitf("unusable\n");
|
||
|
return reveal->extendedFeedCharacter(input);
|
||
|
}
|
||
|
|
||
|
regex024_error_code REGEX_IS024_VirtualMachine::feedCharacter(uint64_t input, uint64_t bytesResembled) {
|
||
|
if (!isUsable())
|
||
|
exitf("unusable\n");
|
||
|
return reveal->feedCharacter(input, bytesResembled);
|
||
|
}
|