Commit 957d90b7 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixed a bug in PyXASM token collector



If 'for' is the very *first* token, the check for `kw_for` may be missed hence causing tokens to be cramped.

Hence, processing the loop from the first token rather than the next.

Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent fbe1ccf3
......@@ -55,9 +55,8 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP,
std::vector<std::pair<std::string, int>> lines;
std::string line = "";
auto current_line_number = sm.getSpellingLineNumber(Toks[0].getLocation());
line += PP.getSpelling(Toks[0]);
int last_col_number = 0;
for (int i = 1; i < Toks.size(); i++) {
for (int i = 0; i < Toks.size(); i++) {
// std::cout << PP.getSpelling(Toks[i]) << "\n";
auto location = Toks[i].getLocation();
auto col_number = sm.getSpellingColumnNumber(location);
......
......@@ -119,6 +119,17 @@ class TestSimpleKernelJIT(unittest.TestCase):
# Validate exp_i_theta expansion
comp = kernelExpVar.extract_composite(q, theta)
self.assertEqual(comp.nInstructions(), 14)
# Test of edge case where the first statement is a for loop
def test_for_loop(self):
@qjit
def testFor(q : qreg):
for i in range(q.size()):
H(q[i])
q = qalloc(5)
comp = testFor.extract_composite(q)
self.assertEqual(comp.nInstructions(), 5)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment