-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.cpp
More file actions
75 lines (65 loc) · 2.21 KB
/
Copy pathexecute.cpp
File metadata and controls
75 lines (65 loc) · 2.21 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @copyright Copyright (c) 2025-2026
* UK Research and Innovation,
* Science and Technology Facilities Council,
* Hartree Centre
**/
#include "collectErrorStrategy.h"
#include "compiler.h"
#include "qasm3Lexer.h"
#include "qasm3Parser.h"
#include "utils.h"
#include <chrono>
#include <format>
#include <fstream>
#include <string>
void run(const std::string& cppCompiler,
const std::string& cppFlags,
const std::string& srcFile,
const std::string& outFile,
const std::string& libPath,
const std::string& libs,
const std::string& includePath,
const std::string& rpaths,
const bool isFormatting,
const bool isVerbose) {
using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;
using namespace antlr4;
using namespace antlr4cpp;
auto t1 = high_resolution_clock::now();
std::ifstream stream(srcFile);
if (!stream.is_open()) {
throw std::runtime_error(
std::format("Failed to open source qasm file: {}.", srcFile));
}
ANTLRInputStream input(stream);
qasm3Lexer lexer(&input);
CommonTokenStream tokens(&lexer);
qasm3Parser parser(&tokens);
stream.close();
auto error_strat = std::make_shared<CollectErrorStrategy>();
parser.setErrorHandler(error_strat);
qasm3Parser::ProgramContext* tree = nullptr;
tree = parser.program();
CollectErrorStrategy* errorStrat
= dynamic_cast<CollectErrorStrategy*>(parser.getErrorHandler().get());
errorStrat->reportErrors();
Compiler compiler(srcFile, outFile);
compiler.visitProgram(tree);
auto t2 = high_resolution_clock::now();
duration<double, std::milli> ms_double = t2 - t1;
if (isVerbose) {
Utils::print(std::format("Frontend timing: {}ms", ms_double.count()));
}
t1 = high_resolution_clock::now();
compiler.compile(cppCompiler, cppFlags, outFile, libPath, libs, includePath,
rpaths, isFormatting, isVerbose);
t2 = high_resolution_clock::now();
ms_double = t2 - t1;
if (isVerbose) {
Utils::print(std::format("Backend timing: {}ms", ms_double.count()));
}
}