Skip to content

Commit

Permalink
refactor(frontend): change location format
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Aug 30, 2023
1 parent 54daaf5 commit 8b74e25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Compilation feedback."""

import re
from typing import Dict, Set

# pylint: disable=no-name-in-module,import-error,too-many-instance-attributes
Expand All @@ -19,6 +20,10 @@
from .wrapper import WrapperCpp


# matches (@tag, separator( | ), filename)
REGEX_LOCATION = r"loc\(\"(@[\w\.]+)?( \| )?(.+)\""


class CompilationFeedback(WrapperCpp):
"""CompilationFeedback is a set of hint computed by the compiler engine."""

Expand Down Expand Up @@ -130,8 +135,9 @@ def count_per_tag(self, *, operations: Set[PrimitiveOperation]) -> Dict[str, int
if statistic.operation not in operations:
continue

file_and_maybe_tag = statistic.location.split("@")
tag = "" if len(file_and_maybe_tag) == 1 else file_and_maybe_tag[1].strip()
tag, _, _ = re.match(REGEX_LOCATION, statistic.location).groups()
# remove the @
tag = tag[1:] if tag else ""

tag_components = tag.split(".")
for i in range(1, len(tag_components) + 1):
Expand Down Expand Up @@ -176,8 +182,9 @@ def count_per_tag_per_parameter(
if statistic.operation not in operations:
continue

file_and_maybe_tag = statistic.location.split("@")
tag = "" if len(file_and_maybe_tag) == 1 else file_and_maybe_tag[1].strip()
tag, _, _ = re.match(REGEX_LOCATION, statistic.location).groups()
# remove the @
tag = tag[1:] if tag else ""

tag_components = tag.split(".")
for i in range(1, len(tag_components) + 1):
Expand Down
12 changes: 9 additions & 3 deletions frontends/concrete-python/concrete/fhe/mlir/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ def location(self) -> MlirLocation:
"""
Create an MLIR location from the node that is being converted.
"""

tag = "" if self.converting.tag == "" else f" @ {self.converting.tag}"
return MlirLocation.name(f"{self.converting.location}{tag}", context=self.context)
filename, lineno = self.converting.location.rsplit(":", maxsplit=1)

tag = "" if self.converting.tag == "" else f"@{self.converting.tag} | "
return MlirLocation.file(
f"{tag}{self.converting.location}",
line=int(lineno),
col=0,
context=self.context,
)

def attribute(self, resulting_type: ConversionType, value: Any) -> MlirAttribute:
"""
Expand Down

0 comments on commit 8b74e25

Please sign in to comment.