25 std::println(std::cerr,
"Error: No input file provided");
39 std::println(std::cerr,
"Error: Cannot compile a bytecode file");
50 std::stringstream buffer;
51 buffer << file.rdbuf();
52 std::string source = buffer.str();
58 auto program = parser.
parse();
60 auto bytecode = codegen.
generate(*program);
66 path.replace_extension(
".phsb");
73 std::println(std::cerr,
"Failed to save bytecode to: {}",
m_args.
outputFile);
81 catch (
const std::exception &e)
83 std::println(std::cerr,
"Compilation Error: {}", e.what());
92 std::println(std::cerr,
"Error: Cannot compile a Phasor IR file");
103 std::stringstream buffer;
104 buffer << file.rdbuf();
105 std::string source = buffer.str();
111 auto program = parser.
parse();
113 auto bytecode = codegen.
generate(*program);
119 path.replace_extension(
".phir");
125 std::println(std::cerr,
"Failed to save Phasor IR to: {}",
m_args.
outputFile);
132 catch (
const std::exception &e)
134 std::println(std::cerr,
"Compilation Error: {}", e.what());
141 int defaultArgLocation = 1;
142 for (
int i = 1; i < argc; i++)
144 std::string arg = argv[i];
146 if (arg ==
"-v" || arg ==
"--verbose")
150 else if (arg ==
"-o" || arg ==
"--output")
158 std::println(std::cerr,
"Error: {} requires an argument", arg);
162 else if (arg ==
"-i" || arg ==
"--ir")
166 else if (arg ==
"-h" || arg ==
"--help")
173 defaultArgLocation = i;
184 std::string filename = std::filesystem::path(programName).filename().string();
185 std::println(
"Pulsar Compiler (Phasor v{})\n"
186 "(C) 2026 Daniel McGuire - Licensed under Apache 2.0\n\n"
188 " {} [options] <file>\n\n"
190 " -o, --output FILE Specify output file\n"
191 " -i, --ir Compile to IR format (.phir) instead of bytecode\n"
192 " -v, --verbose Enable verbose output\n"
193 " -h, --help Show this help message",
194 PHASOR_VERSION_STRING, filename);
Bytecode binary format serializer.
bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phsb file.
Code generator for Phasor VM.
Bytecode generate(const AST::Program &program, const std::unordered_map< std::string, int > &existingVars={}, int nextVarIdx=0, bool replMode=false)
Generate bytecode from program.
struct Phasor::Compiler::Args m_args
void parseArguments(int argc, char *argv[])
static void showHelp(const std::string &programName)
std::vector< Token > tokenize()
std::unique_ptr< AST::Program > parse()
static bool saveToFile(const Bytecode &bytecode, const std::filesystem::path &filename)
Save bytecode to .phir file.
Compiler(int argc, char *argv[])
The Pulsar Scripting Language.