nsbaci 1.0
Loading...
Searching...
No Matches
program.h
Go to the documentation of this file.
1
12
13#ifndef NSBACI_SERVICES_RUNTIME_PROGRAM_H
14#define NSBACI_SERVICES_RUNTIME_PROGRAM_H
15
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20#include "compilerTypes.h"
21#include "instruction.h"
22#include "semaphore.h"
23
28namespace nsbaci::types {
29
31using StackValue = int32_t;
32
34using Stack = std::vector<StackValue>;
35
37using Memory = std::vector<int32_t>;
38
39} // namespace nsbaci::types
40
46
54class Program {
55 public:
56 Program() = default;
57 explicit Program(nsbaci::compiler::InstructionStream i);
59 ~Program() = default;
60
61 Program(const Program&) = delete;
62 Program& operator=(const Program&) = delete;
63
64 Program(Program&&) = default;
65 Program& operator=(Program&&) = default;
66
72 const nsbaci::compiler::Instruction& getInstruction(uint32_t addr) const;
73
78 size_t instructionCount() const;
79
85 const nsbaci::types::Memory& memory() const;
86
92
98
104 int32_t readMemory(nsbaci::types::MemoryAddr addr) const;
105
111 void writeMemory(nsbaci::types::MemoryAddr addr, int32_t value);
112
118 void createSemaphore(nsbaci::types::MemoryAddr addr, int32_t initialCount);
119
127 nsbaci::types::ThreadID threadId);
128
134 nsbaci::types::ThreadID semaphoreSignal(nsbaci::types::MemoryAddr addr);
135
142
143
144
145 private:
146 // Instruction stream - read-only after construction
148 // Global symbol table
149 nsbaci::types::SymbolTable symbolTable;
150 // Global memory
151 nsbaci::types::Memory globalMemory;
152 // Semaphores
154};
155
156} // namespace nsbaci::services::runtime
157
158#endif // NSBACI_SERVICES_RUNTIME_PROGRAM_H
const nsbaci::compiler::Instruction & getInstruction(uint32_t addr) const
Gets instruction at the given address.
Definition program.cpp:23
size_t instructionCount() const
Gets the total number of instructions.
Definition program.cpp:31
void writeMemory(nsbaci::types::MemoryAddr addr, int32_t value)
Write a value to memory.
Definition program.cpp:52
void createSemaphore(nsbaci::types::MemoryAddr addr, int32_t initialCount)
Create a semaphore at the given address.
Definition program.cpp:59
bool hasSemaphore(nsbaci::types::MemoryAddr addr) const
Check if a semaphore exists at the given address.
Definition program.cpp:81
int32_t readMemory(nsbaci::types::MemoryAddr addr) const
Read a value from memory.
Definition program.cpp:45
nsbaci::types::Memory & memory()
Access to global memory.
Definition program.cpp:33
void addSymbol(nsbaci::types::SymbolInfo info)
Add a symbol to the symbol table.
Definition program.cpp:41
nsbaci::types::ThreadID semaphoreSignal(nsbaci::types::MemoryAddr addr)
Signal (V operation) on a semaphore.
Definition program.cpp:73
const nsbaci::types::SymbolTable & symbols() const
Access to symbol table.
Definition program.cpp:37
bool semaphoreWait(nsbaci::types::MemoryAddr addr, nsbaci::types::ThreadID threadId)
Wait (P operation) on a semaphore.
Definition program.cpp:64
Type definitions for compiler-related operations.
Instruction definitions for nsbaci compiler.
std::vector< Instruction > InstructionStream
Vector of instructions representing a compiled program.
Definition instruction.h:210
Runtime services namespace for nsbaci.
Type definitions namespace for nsbaci (runtime-specific).
uint32_t MemoryAddr
Type alias for memory addresses.
Definition compilerTypes.h:31
std::unordered_map< MemoryAddr, nsbaci::services::runtime::Semaphore > SemaphoreTable
Maps memory addresses to semaphores.
Definition semaphore.h:58
std::vector< int32_t > Memory
Memory block for runtime data.
Definition program.h:37
std::vector< StackValue > Stack
Runtime stack.
Definition program.h:34
int32_t StackValue
Stack value type (can hold int or address).
Definition program.h:31
std::unordered_map< VarName, SymbolInfo > SymbolTable
Lookup table mapping variable names to their symbol info.
Definition compilerTypes.h:42
Semaphore implementation for process synchronization.
Represents a single instruction in the virtual machine.
Definition instruction.h:184
Information about a variable/symbol.
Definition compilerTypes.h:34