Skip to content

facade

Classes:

Builder

Builder()

Bases: Builder

Methods:

Source code in src/irx/builders/llvmliteir/facade.py
54
55
56
57
58
59
def __init__(self) -> None:
    """
    title: Initialize Builder.
    """
    super().__init__()
    self.translator = self._new_translator()

activate_runtime_feature

activate_runtime_feature(feature_name: str) -> None
Source code in src/irx/builders/base.py
248
249
250
251
252
253
254
255
def activate_runtime_feature(self, feature_name: str) -> None:
    """
    title: Activate a native runtime feature for this compilation unit.
    parameters:
      feature_name:
        type: str
    """
    self.runtime_feature_names.add(feature_name)

build

build(node: AST, output_file: str) -> None
Source code in src/irx/builders/llvmliteir/facade.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def build(self, node: astx.AST, output_file: str) -> None:
    """
    title: Build.
    parameters:
      node:
        type: astx.AST
      output_file:
        type: str
    """
    result = self.translate(node)
    result_mod = llvm.parse_assembly(result)
    result_object = self.translator.target_machine.emit_object(result_mod)

    with tempfile.TemporaryDirectory() as temp_dir:
        self.tmp_path = temp_dir
        file_path_o = Path(temp_dir) / "irx_module.o"

        with open(file_path_o, "wb") as handle:
            handle.write(result_object)

        self.output_file = output_file
        link_executable(
            primary_object=file_path_o,
            output_file=Path(self.output_file),
            artifacts=self.translator.runtime_features.native_artifacts(),
            linker_flags=self.translator.runtime_features.linker_flags(),
        )

    os.chmod(self.output_file, 0o755)

module

module() -> Module
Source code in src/irx/builders/base.py
229
230
231
232
233
234
235
def module(self) -> astx.Module:
    """
    title: Create a new ASTx Module.
    returns:
      type: astx.Module
    """
    return astx.Module()

run

run(
    *,
    capture_stderr: bool = True,
    raise_on_error: bool = True,
    debug: bool = False,
) -> CommandResult
Source code in src/irx/builders/base.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
def run(
    self,
    *,
    capture_stderr: bool = True,
    raise_on_error: bool = True,
    debug: bool = False,
) -> CommandResult:
    """
    title: Run the generated executable.
    parameters:
      capture_stderr:
        type: bool
        default: true
      raise_on_error:
        type: bool
        default: true
      debug:
        type: bool
        default: false
    returns:
      type: CommandResult
    """
    return run_command(
        [self.output_file],
        capture_stderr=capture_stderr,
        raise_on_error=raise_on_error,
        debug=debug,
    )

translate

translate(expr: AST) -> str
Source code in src/irx/builders/llvmliteir/facade.py
69
70
71
72
73
74
75
76
77
78
79
def translate(self, expr: astx.AST) -> str:
    """
    title: Translate.
    parameters:
      expr:
        type: astx.AST
    returns:
      type: str
    """
    self.translator = self._new_translator()
    return self.translator.translate(expr)