diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-27 13:55:36 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-27 13:55:36 +0000 |
| commit | a91bd145008432fb8c5d91d94ab6f50473a277f5 (patch) | |
| tree | 87af3ebcd2888e129bad9863574567e1c97bb18b /tools | |
| parent | 24f410430b33aaf1f288b83ea37e18fa959e9d3e (diff) | |
feat(preprocessor): add file-local conditional switches
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/driver/main.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tools/driver/main.cc b/tools/driver/main.cc index d1dda81..e3d4c28 100644 --- a/tools/driver/main.cc +++ b/tools/driver/main.cc @@ -1,4 +1,5 @@ #include "cps/Lexer.h" +#include "cps/Preprocessor.h" #include "cps/Diagnostics.h" #include "cps/Parser.h" #include "cps/CodeGen.h" @@ -17,6 +18,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <fstream> +#include <sstream> #include <string> #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -187,13 +189,16 @@ bool parseUnits(const std::vector<std::string> &InputPaths, size_t UserInputCoun return false; } cps::DiagnosticSource = InputPath; - cps::Lexer Lex(Input); - cps::Parser Parser(Lex); - Programs[I] = Parser.Parse(); + auto Source = cps::preprocess(Input); if (Input.bad()) { llvm::errs() << cps::diagnosticPrefix(cps::Severity::Fatal) << "cannot read source file '" << InputPath << "'\n"; return false; } + if (Source.HadError) return false; + std::istringstream Processed(Source.Text); + cps::Lexer Lex(Processed); + cps::Parser Parser(Lex); + Programs[I] = Parser.Parse(); if (Lex.hadError() || Parser.hadError()) return false; Units.push_back({InputPath, Programs[I], std::vector<bool>(InputPaths.size(), false), Lex.isLibrary()}); Units.back().Visible[I] = true; |
