-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemitter.h
More file actions
41 lines (38 loc) · 1.71 KB
/
Copy pathemitter.h
File metadata and controls
41 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// =======================================================================================
// Made by: Rohit Yadav
// NIT Jalandhar
//
// File: emitter.h
// Purpose:
// - Declaration for the Emitter class responsible for writing compiled bytecode
// (i.e., vector of `Instruction`) into a valid C++ source file (like `prog.cpp`).
//
// - This output can be directly compiled and run using your virtual machine (RohitVM).
// =======================================================================================
#pragma once
#include "RohitVM.hpp" // Includes definitions for `Instruction` and `Opcode`
#include <vector>
#include <string>
// =======================================================================================
// Class: Emitter
// Role:
// - Static utility class with a single job: write a list of Instructions to a .cpp file.
//
// Usage:
// Emitter::writeToFile("prog.cpp", instructions);
// =======================================================================================
class Emitter {
public:
// -----------------------------------------------------------------------------------
// Function: writeToFile
// Description:
// - Serializes the list of compiled Instructions into a C++ source file
// - Each instruction is emitted in a readable, compilable format
// Parameters:
// - filename: destination C++ file path (e.g., "prog.cpp")
// - instructions: list of VM bytecode instructions to emit
// Returns:
// - true on success, false on file open failure
// -----------------------------------------------------------------------------------
static bool writeToFile(const std::string& filename, const std::vector<Instruction>& instructions);
};