Convert constant values in the code to constant values in the MLIR.
(self, node)
| 4519 | self.pushValue(self.__createStdvecWithKnownValues(listElementValues)) |
| 4520 | |
| 4521 | def visit_Constant(self, node): |
| 4522 | """Convert constant values in the code to constant values in the |
| 4523 | MLIR.""" |
| 4524 | if isinstance(node.value, bool): |
| 4525 | boolValue = 0 if node.value == 0 else 1 |
| 4526 | self.pushValue(self.getConstantInt(boolValue, 1)) |
| 4527 | return |
| 4528 | |
| 4529 | if isinstance(node.value, int): |
| 4530 | self.pushValue(self.getConstantInt(node.value)) |
| 4531 | return |
| 4532 | |
| 4533 | if isinstance(node.value, float): |
| 4534 | self.pushValue(self.getConstantFloat(node.value)) |
| 4535 | return |
| 4536 | |
| 4537 | if isinstance(node.value, str): |
| 4538 | # Do not process the function doc string |
| 4539 | if self.docstring != None: |
| 4540 | if node.value.strip() == self.docstring.strip(): |
| 4541 | return |
| 4542 | |
| 4543 | strLitTy = cc.PointerType.get( |
| 4544 | cc.ArrayType.get(self.getIntegerType(8), |
| 4545 | len(node.value) + 1)) |
| 4546 | self.pushValue( |
| 4547 | cc.CreateStringLiteralOp(strLitTy, |
| 4548 | StringAttr.get(node.value)).result) |
| 4549 | return |
| 4550 | |
| 4551 | if isinstance(node.value, type(1j)): |
| 4552 | self.pushValue( |
| 4553 | complex.CreateOp(ComplexType.get(self.getFloatType()), |
| 4554 | self.getConstantFloat(node.value.real), |
| 4555 | self.getConstantFloat(node.value.imag)).result) |
| 4556 | return |
| 4557 | |
| 4558 | self.emitFatalError("unhandled constant value", node) |
| 4559 | |
| 4560 | def visit_Subscript(self, node): |
| 4561 | """Convert element extractions (`__getitem__`, `operator[](idx)`, |
nothing calls this directly
no test coverage detected