├── .clang-format ├── .github ├── dependabot.yml └── workflows │ ├── AV_Scan_McAfee_Checker.yml │ ├── pull-request.yml │ └── scorecard.yml ├── .gitignore ├── .gitmodules ├── .ocamlformat ├── CHANGES.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── Security.md ├── asli.opam ├── bin ├── asl2c.py ├── asli.ml ├── dune └── testlexer.ml ├── demo ├── .gitignore ├── Makefile ├── assembly.s ├── config.json ├── demo.asl ├── simulator.c ├── test.S └── test.prj ├── dune-project ├── editors ├── asl.vim └── asl.xml ├── libASL ├── asl_ast.ml ├── asl_fmt.ml ├── asl_fmt.mli ├── asl_parser.messages ├── asl_parser.mly ├── asl_utils.ml ├── asl_utils.mli ├── asl_visitor.ml ├── asl_visitor.mli ├── backend_c.ml ├── backend_c.mli ├── backend_mlir.ml ├── backend_mlir.mli ├── bin_file.ml ├── bin_file.mli ├── builtin_idents.ml ├── builtin_idents.mli ├── check_monomorphization.ml ├── commands.ml ├── commands.mli ├── configuration.ml ├── configuration.mli ├── cpu.ml ├── cpu.mli ├── dune ├── elf.ml ├── elf.mli ├── error.ml ├── error.mli ├── eval.ml ├── eval.mli ├── flags.ml ├── flags.mli ├── format_utils.ml ├── format_utils.mli ├── global_checks.ml ├── global_checks.mli ├── ident.ml ├── ident.mli ├── identset.ml ├── identset.mli ├── lattice.ml ├── lexer.mll ├── lexersupport.ml ├── loadASL.ml ├── loadASL.mli ├── loc.ml ├── loc.mli ├── metadata.ml ├── metadata.mli ├── primops.ml ├── runtime.ml ├── runtime.mli ├── runtime_ac.ml ├── runtime_ac.mli ├── runtime_c23.ml ├── runtime_c23.mli ├── runtime_fallback.ml ├── runtime_fallback.mli ├── runtime_sc.ml ├── runtime_sc.mli ├── scope.ml ├── scope.mli ├── scopeStack.ml ├── scopeStack.mli ├── tcheck.ml ├── utils.ml ├── utils.mli ├── value.ml ├── value.mli ├── visitor.ml ├── xform_bitslices.ml ├── xform_bitslices.mli ├── xform_bittuples.ml ├── xform_bittuples.mli ├── xform_bounded.ml ├── xform_bounded.mli ├── xform_case.ml ├── xform_case.mli ├── xform_constprop.ml ├── xform_constprop.mli ├── xform_desugar.ml ├── xform_desugar.mli ├── xform_getset.ml ├── xform_getset.mli ├── xform_hoist_lets.ml ├── xform_hoist_lets.mli ├── xform_int_bitslices.ml ├── xform_int_bitslices.mli ├── xform_lower.ml ├── xform_lower.mli ├── xform_mono.ml ├── xform_mono.mli ├── xform_named_type.ml ├── xform_named_type.mli ├── xform_simplify_expr.ml ├── xform_simplify_expr.mli ├── xform_tuples.ml ├── xform_tuples.mli ├── xform_valid.ml ├── xform_valid.mli ├── xform_wrap.ml └── xform_wrap.mli ├── mk_install.py ├── prelude.asl ├── requirements.txt ├── runtime ├── .gitignore ├── Makefile ├── dune ├── include │ └── asl │ │ ├── bits1024.h │ │ ├── bits128.h │ │ ├── bits256.h │ │ ├── bits512.h │ │ ├── bits64.h │ │ ├── bits_template.h │ │ ├── error.h │ │ ├── integer.h │ │ ├── print.h │ │ ├── print_template.h │ │ ├── ram.h │ │ ├── runtime.h │ │ ├── runtime.hpp │ │ ├── set_slice_template.h │ │ └── track_valid.h ├── lib │ ├── bits1024.c │ ├── bits128.c │ ├── bits256.c │ ├── bits512.c │ ├── bits64.c │ ├── bits_template_c.h │ ├── end_of_execution.c │ ├── error.c │ ├── ram.c │ ├── set_slice_template_c.h │ └── sign_extend_bits_template_c.h └── test │ ├── .gitignore │ ├── Makefile │ ├── bitint_maxwidth.c │ ├── bits_test.cc │ ├── bits_test_template.h │ ├── integer_test.cc │ ├── ram_test.cc │ └── sign_extend_bits_test_template.h └── tests ├── .gitignore ├── asl_test.ml ├── asl_utils_test.ml ├── backend_c_c23_test.ml ├── backend_c_fallback_test.ml ├── backends ├── asl_end_execution_00.asl ├── asl_end_execution_01.asl ├── bits_add_00.asl ├── bits_and_00.asl ├── bits_append_00.asl ├── bits_asr_00.asl ├── bits_cvt_sint_00.asl ├── bits_cvt_ssintN_00.asl ├── bits_cvt_uint_00.asl ├── bits_cvt_usintN_00.asl ├── bits_eq_00.asl ├── bits_get_slice_00.asl ├── bits_get_slice_01.asl ├── bits_get_slice_02.asl ├── bits_lsl_00.asl ├── bits_lsr_00.asl ├── bits_mk_mask_00.asl ├── bits_mul_00.asl ├── bits_ne_00.asl ├── bits_not_00.asl ├── bits_ones_00.asl ├── bits_or_00.asl ├── bits_print_hex_00.asl ├── bits_print_hex_01.asl ├── bits_replicate_00.asl ├── bits_set_slice_00.asl ├── bits_set_slice_01.asl ├── bits_set_slice_02.asl ├── bits_set_slice_03.asl ├── bits_sext_00.asl ├── bits_sext_01.asl ├── bits_sub_00.asl ├── bits_sub_01.asl ├── bits_xor_00.asl ├── bits_zeros_00.asl ├── bits_zext_00.asl ├── bool_and_00.asl ├── bool_eq_00.asl ├── bool_ne_00.asl ├── bool_not_00.asl ├── bool_or_00.asl ├── exceptions_00.asl ├── expr_IN_00.asl ├── expr_as_00.asl ├── expr_assert_00.asl ├── expr_assert_01.asl ├── expr_bitslice_00.asl ├── expr_if_00.asl ├── expr_if_01.asl ├── expr_intslice_00.asl ├── expr_let_00.asl ├── expr_var_00.asl ├── expr_with_00.asl ├── expr_with_01.asl ├── expr_with_02.asl ├── expr_with_03.asl ├── ffi_config_00.asl ├── ffi_config_00.c ├── ffi_export_00.asl ├── ffi_export_00.c ├── ffi_export_01.asl ├── ffi_export_01.c ├── ffi_export_01.json ├── ffi_import_00.asl ├── ffi_import_00.c ├── ffi_import_01.asl ├── ffi_import_01.c ├── ffi_import_01.json ├── int_add_00.asl ├── int_align_00.asl ├── int_cvt_bits_00.asl ├── int_cvt_bits_01.asl ├── int_eq_00.asl ├── int_exact_div_00.asl ├── int_fdiv_00.asl ├── int_frem_00.asl ├── int_ge_00.asl ├── int_gt_00.asl ├── int_is_pow2_00.asl ├── int_le_00.asl ├── int_lt_00.asl ├── int_mod_pow2_00.asl ├── int_mul_00.asl ├── int_ne_00.asl ├── int_neg_00.asl ├── int_pow2_00.asl ├── int_print_dec.asl ├── int_print_hex.asl ├── int_set_slice_00.asl ├── int_shl_00.asl ├── int_shr_00.asl ├── int_sub_00.asl ├── int_zdiv_00.asl ├── int_zrem_00.asl ├── print_char_00.asl ├── print_str_00.asl ├── sintN_add_00.asl ├── sintN_align_00.asl ├── sintN_array_00.asl ├── sintN_array_01.asl ├── sintN_array_02.asl ├── sintN_cvt_bits_00.asl ├── sintN_cvt_from_int_00.asl ├── sintN_cvt_to_int_00.asl ├── sintN_eq_00.asl ├── sintN_exact_div_00.asl ├── sintN_fdiv_00.asl ├── sintN_frem_00.asl ├── sintN_ge_00.asl ├── sintN_get_slice_00.asl ├── sintN_get_slice_01.asl ├── sintN_gt_00.asl ├── sintN_is_pow2_00.asl ├── sintN_le_00.asl ├── sintN_lt_00.asl ├── sintN_mod_pow2_00.asl ├── sintN_mul_00.asl ├── sintN_ne_00.asl ├── sintN_neg_00.asl ├── sintN_pow2_00.asl ├── sintN_print_dec.asl ├── sintN_print_hex.asl ├── sintN_resize_00.asl ├── sintN_set_slice_00.asl ├── sintN_shl_00.asl ├── sintN_shr_00.asl ├── sintN_sub_00.asl ├── sintN_zdiv_00.asl ├── sintN_zrem_00.asl ├── stmt_assert_00.asl ├── stmt_assert_01.asl ├── stmt_assign_00.asl ├── stmt_block_00.asl ├── stmt_case_00.asl ├── stmt_case_01.asl ├── stmt_case_02.asl ├── stmt_case_03.asl ├── stmt_case_04.asl ├── stmt_case_05.asl ├── stmt_for_00.asl ├── stmt_for_01.asl ├── stmt_for_02.asl ├── stmt_if_00.asl ├── stmt_if_01.asl ├── stmt_if_02.asl ├── stmt_let_00.asl ├── stmt_repeat_00.asl ├── stmt_return_00.asl ├── stmt_return_01.asl ├── stmt_return_02.asl ├── stmt_try_00.asl ├── stmt_try_01.asl ├── stmt_try_02.asl ├── stmt_var_00.asl ├── stmt_var_01.asl ├── stmt_while_00.asl ├── type_array_00.asl ├── type_array_01.asl ├── type_array_02.asl ├── type_array_03.asl ├── type_array_04.asl ├── type_array_05.asl ├── type_array_06.asl ├── type_bool_00.asl ├── type_enum_00.asl ├── type_ram_00.asl └── type_record_00.asl ├── dune ├── lit.cfg ├── lit ├── check_monomorphization │ ├── asli.prj │ ├── config.json │ └── test_00.asl ├── eval │ ├── slice_00.asl │ └── slice_01.asl ├── globalchecks │ ├── eval_order_00.asl │ ├── eval_order_01.asl │ ├── eval_order_02.asl │ ├── eval_order_03.asl │ ├── eval_order_04.asl │ ├── eval_order_05.asl │ ├── eval_order_06.asl │ ├── markers_00.asl │ ├── markers_01.asl │ ├── noreturn_00.asl │ ├── rethrow_00.asl │ ├── rethrow_01.asl │ ├── rethrow_02.asl │ ├── rethrow_03.asl │ └── rethrow_04.asl ├── monomorphize │ └── recurse_00.asl ├── parser │ ├── directive_line.asl │ └── fenced_code_block.asl ├── print │ └── print_00.asl ├── runtime_checks │ ├── array_read_00.asl │ ├── array_write_00.asl │ ├── bits_read_00.asl │ ├── bits_write_00.asl │ ├── conversion_00.asl │ ├── expr_with_00.asl │ └── int_divide_00.asl ├── tcheck │ ├── array_param_00.asl │ ├── conflicting_00.asl │ ├── conflicting_01.asl │ ├── funcall00.asl │ ├── funcall01.asl │ ├── funcall02.asl │ ├── funcall03.asl │ ├── funcall04.asl │ ├── funcall05.asl │ ├── funcall06.asl │ ├── funcall07.asl │ ├── funcall08.asl │ ├── funcall09.asl │ ├── function_arg_00.asl │ ├── immutable_00.asl │ ├── immutable_01.asl │ ├── immutable_02.asl │ ├── immutable_03.asl │ ├── immutable_04.asl │ ├── immutable_05.asl │ ├── immutable_06.asl │ ├── immutable_07.asl │ ├── immutable_08.asl │ ├── implicit_params_00.asl │ ├── implicit_params_01.asl │ ├── missing_00.asl │ ├── patterns_00.asl │ ├── record_init_00.asl │ ├── record_init_01.asl │ ├── record_init_02.asl │ ├── records_00.asl │ ├── records_01.asl │ ├── records_02.asl │ ├── return_type_01.asl │ ├── setter_00.asl │ ├── setter_01.asl │ ├── shadowing_00.asl │ ├── shadowing_01.asl │ ├── shadowing_02.asl │ ├── shadowing_03.asl │ ├── subtypes_00.asl │ ├── type_constants_00.asl │ ├── type_constraints_01.asl │ ├── type_constraints_02.asl │ ├── type_width_00.asl │ └── type_width_01.asl ├── xform_bounded │ ├── decl_fun_00.asl │ ├── expr_add_00.asl │ ├── expr_eq_00.asl │ ├── expr_ge_00.asl │ ├── expr_gt_00.asl │ ├── expr_if_00.asl │ ├── expr_if_01.asl │ ├── expr_le_00.asl │ ├── expr_lt_00.asl │ ├── expr_mul_00.asl │ ├── expr_ne_00.asl │ ├── expr_neg_00.asl │ ├── expr_sint_00.asl │ ├── expr_sub_00.asl │ ├── expr_uint_00.asl │ ├── stmt_for_00.asl │ └── stmt_let_00.asl └── xform_hoist_lets │ ├── test_00.asl │ ├── test_01.asl │ ├── test_02.asl │ └── test_03.asl ├── loadasl_test.ml ├── scripts └── not ├── test_cases_backend.ml ├── test_utils.ml ├── test_utils_backend.ml ├── xform_bitslices_test.ml ├── xform_bittuples_test.ml ├── xform_case_test.ml ├── xform_constprop_test.ml ├── xform_getset_test.ml ├── xform_int_bitslices_test.ml ├── xform_lower_test.ml ├── xform_mono_test.ml ├── xform_named_type_test.ml ├── xform_simplify_expr_test.ml ├── xform_tuples_test.ml ├── xform_valid_test.ml └── xform_wrap_test.ml /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "pip" # See documentation for possible values 4 | directory: "/" # Location of package manifests 5 | schedule: 6 | interval: "weekly" 7 | ignore: 8 | - dependency-name: "*" 9 | update-types: ["version-update:semver-major"] 10 | -------------------------------------------------------------------------------- /.github/workflows/AV_Scan_McAfee_Checker.yml: -------------------------------------------------------------------------------- 1 | name: McAfee Virus Scan 2 | on: 3 | workflow_dispatch: 4 | 5 | permissions: read-all 6 | 7 | jobs: 8 | virus: 9 | name: McAfee Virus Scan 10 | runs-on: [self-hosted, Linux, ubuntu-latest] 11 | steps: 12 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 13 | - name: Execute Scan 14 | uses: intel-innersource/frameworks.devops.github.actions.mcafee@main 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | .*.swo 3 | .*.un~ 4 | 5 | _build 6 | _opam 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ac_types"] 2 | path = runtime/external/ac_types 3 | url = https://github.com/hlslibs/ac_types.git 4 | [submodule "systemc"] 5 | path = runtime/external/systemc 6 | url = https://github.com/accellera-official/systemc.git 7 | [submodule "runtime/external/googletest"] 8 | path = runtime/external/googletest 9 | url = https://github.com/google/googletest.git 10 | -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | profile = default 2 | version = 0.21.0 3 | wrap-comments = true 4 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 1.0.0 (2024-12-19) 2 | ------------------ 3 | 4 | * Change ASLi to support most of ASL version 1.0 requiring significant 5 | changes to the AST, lexer, parser and typechecker. 6 | * Cleanup the "CPU" API that ASLi expects an ISA to implement. 7 | * Add support for compiling ASL specifications to C by adding 8 | many transformations and multiple runtimes. 9 | * Add a demo ISA to illustrate how to generate simulators from 10 | an ASL specification. 11 | 12 | 13 | 0.2.0 (2020-05-15) 14 | ------------------ 15 | 16 | * Handle more of Arm's specs (make grammar, etc. more flexible) 17 | * Split libASL out from ASLi to make it easier to reuse 18 | parts of ASLi in other tools. 19 | * Changed to semantic numbering system (i.e., 3-part format). 20 | * Internal change to using Dune build system. 21 | This replaces the ocamlfind dependency with a dune dependency. 22 | 23 | 24 | 0.1 (2020-01-01) 25 | ---------------- 26 | 27 | * Added support for loading ELF files and executing binaries. 28 | 29 | 30 | 0.0 (2019-08-30) 31 | ---------------- 32 | 33 | Initial release of ASLi supporting 34 | 35 | - loading ASL specifications 36 | - evaluating expressions and statements 37 | -------------------------------------------------------------------------------- /Security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project [utilizing the guidelines here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | 7 | -------------------------------------------------------------------------------- /bin/dune: -------------------------------------------------------------------------------- 1 | ; Copyright Arm Limited (c) 2017-2019 2 | ; Copyright (C) 2022-2025 Intel Corporation 3 | ; SPDX-Licence-Identifier: BSD-3-Clause 4 | 5 | (executable 6 | (name asli) 7 | (public_name asli) 8 | (modes exe) 9 | (modules asli sites) 10 | (flags 11 | (-cclib -lstdc++)) 12 | (libraries libASL linenoise dune-site dune-site.plugins)) 13 | 14 | (generate_sites_module 15 | (module sites) 16 | (sites asli) 17 | (plugins (asli plugins))) 18 | 19 | (executable 20 | (name testlexer) 21 | (modes exe) 22 | ; (public_name test_asl_lexer) 23 | (modules testlexer) 24 | (flags 25 | (-cclib -lstdc++)) 26 | (libraries libASL)) 27 | 28 | (install 29 | (section (site (asli stdlib))) 30 | (files 31 | (../prelude.asl as prelude.asl))) 32 | 33 | (install 34 | (section bin) 35 | (files 36 | (asl2c.py as asl2c))) 37 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | log.*.asl 2 | sim.prj 3 | sim_types.h 4 | sim_exceptions.h 5 | sim_vars.h 6 | sim_exceptions.c 7 | sim_vars.c 8 | sim_funs.c 9 | test.s 10 | test.o 11 | test.elf 12 | -------------------------------------------------------------------------------- /demo/assembly.s: -------------------------------------------------------------------------------- 1 | /* hack to define new assembly instructions */ 2 | 3 | .macro INC r 4 | .byte (1 << 4) | \r 5 | .endm 6 | 7 | .macro HALT 8 | .byte 0 9 | .endm 10 | 11 | /* hack to define register names */ 12 | #define R0 0 13 | #define R1 1 14 | #define R2 2 15 | #define R3 3 16 | -------------------------------------------------------------------------------- /demo/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "__comment": [ 3 | "Export the interface required by the simulator" 4 | ], 5 | "exports": [ 6 | "ASL_Reset", 7 | "ASL_Step", 8 | "ASL_IsHalted", 9 | "ASL_ReadReg64", 10 | "ASL_WriteReg64", 11 | "ASL_WriteMemory8", 12 | "PrintState" 13 | ], 14 | 15 | "__comment": [ 16 | "Split the variables into shared (global) and thread-local." 17 | ], 18 | "split_state": { 19 | "global_state": ["__Memory"], 20 | "threadlocal_state" : [".*"] 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /demo/test.S: -------------------------------------------------------------------------------- 1 | #include "assembly.s" 2 | 3 | .global _start 4 | 5 | .text 6 | _start: 7 | INC R1 8 | INC R3 9 | HALT 10 | -------------------------------------------------------------------------------- /demo/test.prj: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023-2025 Intel Corporation 2 | 3 | :elf test.elf 4 | // CHECK: Loading ELF file test.elf. 5 | // CHECK: Entry point = 6 | 7 | PrintState(); 8 | // CHECK: RUNNING PC=64'x{{[0-9a-fA-F]+}} R=[ 64'x0 64'x0 64'x0 64'x0 ] 9 | :step 10 | PrintState(); 11 | // CHECK: RUNNING PC=64'x{{[0-9a-fA-F]+}} R=[ 64'x0 64'x1 64'x0 64'x0 ] 12 | :step 13 | PrintState(); 14 | // CHECK: RUNNING PC=64'x{{[0-9a-fA-F]+}} R=[ 64'x0 64'x1 64'x0 64'x1 ] 15 | :step 16 | PrintState(); 17 | // CHECK: HALTED PC=64'x{{[0-9a-fA-F]+}} R=[ 64'x0 64'x1 64'x0 64'x1 ] 18 | 19 | print("End of demo\n"); 20 | :quit 21 | -------------------------------------------------------------------------------- /libASL/backend_c.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL to C backend 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | (** select which runtime library is used *) 9 | val set_runtime : string -> unit 10 | 11 | (** Supply of goto labels for exception implementation *) 12 | val catch_labels : Asl_utils.nameSupply 13 | 14 | val declarations : Format.formatter -> Asl_ast.declaration list -> unit 15 | 16 | val get_rt_header : unit -> string list 17 | 18 | (**************************************************************** 19 | * End 20 | ****************************************************************) 21 | -------------------------------------------------------------------------------- /libASL/backend_mlir.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL to MLIR backend 3 | * 4 | * Copyright (C) 2024-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | (**************************************************************** 9 | * End 10 | ****************************************************************) 11 | -------------------------------------------------------------------------------- /libASL/bin_file.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Binary file loader 3 | * 4 | * Simplistic binary file loader 5 | * 6 | * Copyright (C) 2023-2025 Intel Corporation 7 | * SPDX-Licence-Identifier: BSD-3-Clause 8 | ****************************************************************) 9 | 10 | (** load binary file *) 11 | val load_file : string -> (Int64.t -> char -> unit) -> Int64.t -> unit 12 | 13 | (**************************************************************** 14 | * End 15 | ****************************************************************) 16 | -------------------------------------------------------------------------------- /libASL/commands.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Commands registry 3 | * 4 | * Copyright (C) 2024-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | type command = Tcheck.Env.t -> Cpu.cpu -> bool 9 | type flag = (Stdlib.Arg.key * Stdlib.Arg.spec * Stdlib.Arg.doc) 10 | type arg = (string ref * Stdlib.Arg.doc) 11 | 12 | (** [registerCommand name args description cmd] registers a command 13 | @param name Command name 14 | @param flags Stdlib.Arg flag list 15 | @param args Mandatory argument list 16 | @param opt_args Optional argument list 17 | @param description Short description (used for :help command) 18 | @param cmd Function to parse the arguments and execute the command 19 | *) 20 | val registerCommand : string -> flag list -> arg list -> arg list -> string -> command -> unit 21 | 22 | val execute_command : string -> string list -> command 23 | 24 | val print_help : unit -> unit 25 | 26 | (** List of all declarations. 27 | * This list can be accessed and updated by commands 28 | *) 29 | val declarations : Asl_ast.declaration list ref 30 | 31 | (**************************************************************** 32 | * End 33 | ****************************************************************) 34 | -------------------------------------------------------------------------------- /libASL/configuration.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Configuration access 3 | * 4 | * This is used to manage configuration files 5 | * 6 | * Copyright (C) 2023-2025 Intel Corporation 7 | * SPDX-Licence-Identifier: BSD-3-Clause 8 | ****************************************************************) 9 | 10 | (** Read a JSON configuration file *) 11 | val read_configuration_file : string -> unit 12 | 13 | (** Read list of strings from all previously read configuration files *) 14 | val get_strings : string -> string list 15 | 16 | (** Read list of strings from all previously read configuration files *) 17 | val get_record_entries : string -> (string * string list) list 18 | 19 | (**************************************************************** 20 | * End 21 | ****************************************************************) 22 | -------------------------------------------------------------------------------- /libASL/cpu.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * CPU interface 3 | * 4 | * Copyright Arm Limited (c) 2017-2019 5 | * Copyright (C) 2022-2025 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | type cpu = { 10 | env : Eval.Env.t; 11 | setConfig : Ident.t -> Value.value -> unit; 12 | reset : unit -> unit; 13 | step : unit -> unit; 14 | getPC : unit -> Primops.bigint; 15 | setPC : Int64.t -> unit; 16 | elfwrite8 : Int64.t -> char -> unit; 17 | } 18 | 19 | val mkCPU : Eval.Env.t -> cpu 20 | 21 | (**************************************************************** 22 | * End 23 | ****************************************************************) 24 | -------------------------------------------------------------------------------- /libASL/elf.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ELF loader 3 | * 4 | * Currently only handles little-endian, 64-bit 5 | * 6 | * Copyright Alastair Reid (c) 2019-2020 7 | * SPDX-Licence-Identifier: BSD-3-Clause 8 | ****************************************************************) 9 | 10 | type uint64 = Int64.t 11 | 12 | (** load ELF file, returning entry address *) 13 | val load_file : string -> (uint64 -> char -> unit) -> uint64 14 | 15 | (**************************************************************** 16 | * End 17 | ****************************************************************) 18 | -------------------------------------------------------------------------------- /libASL/error.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Error 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | exception Unimplemented of (Loc.t * string * (Format.formatter -> unit)) 9 | exception UnknownObject of (Loc.t * string * string) 10 | exception DoesNotMatch of (Loc.t * string * string * string) 11 | exception IsNotA of (Loc.t * string * string) 12 | exception Ambiguous of (Loc.t * string * string) 13 | exception TypeError of (Loc.t * string) 14 | exception ParseError of Loc.t 15 | 16 | val print_exception : exn -> unit 17 | 18 | (**************************************************************** 19 | * End 20 | ****************************************************************) 21 | -------------------------------------------------------------------------------- /libASL/flags.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Control flag registry 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module FlagMap = Map.Make(String) 9 | 10 | let flags : (bool ref * string) FlagMap.t ref = ref FlagMap.empty 11 | 12 | let registerFlag (name : string) (flag : bool ref) (description : string) : unit = 13 | flags := FlagMap.add name (flag, description) !flags 14 | 15 | (**************************************************************** 16 | * End 17 | ****************************************************************) 18 | -------------------------------------------------------------------------------- /libASL/flags.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Control flag registry 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module FlagMap : Map.S with type key = string 9 | 10 | val flags : (bool ref * string) FlagMap.t ref 11 | 12 | val registerFlag : string -> bool ref -> string -> unit 13 | 14 | (**************************************************************** 15 | * End 16 | ****************************************************************) 17 | -------------------------------------------------------------------------------- /libASL/global_checks.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Global checks 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val check_defn_markers : bool ref 11 | val check_call_markers : bool ref 12 | 13 | val check_decls : AST.declaration list -> AST.declaration list 14 | 15 | (**************************************************************** 16 | * End 17 | ****************************************************************) 18 | -------------------------------------------------------------------------------- /libASL/loadASL.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Functions for processing ASL files 3 | * 4 | * Copyright Arm Limited (c) 2017-2019 5 | * Copyright (C) 2022-2025 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | module AST = Asl_ast 10 | module TC = Tcheck 11 | 12 | val read_file : string list -> string -> bool -> bool -> Asl_ast.declaration list 13 | (** Parse and typecheck ASL file *) 14 | 15 | val parse_spec : string list -> string -> bool -> Asl_ast.declaration list 16 | 17 | val parse_file : string list -> string -> bool -> Asl_ast.declaration list 18 | (** Parse ASL file, but do not typecheck *) 19 | 20 | val read_files : string list -> string list -> bool -> Asl_ast.declaration list 21 | (** Parse and typecheck ASL files. All files are first parsed then typechecked 22 | together.*) 23 | 24 | val read_config : TC.Env.t -> Loc.t -> string -> Ident.t * AST.expr * AST.ty 25 | val read_expr : TC.Env.t -> Loc.t -> string -> AST.expr 26 | val read_stmt : TC.Env.t -> string -> AST.stmt list 27 | val read_stmts : TC.Env.t -> string -> AST.stmt list 28 | val read_declarations_unsorted : TC.GlobalEnv.t -> string -> AST.declaration list 29 | 30 | (**************************************************************** 31 | * End 32 | ****************************************************************) 33 | -------------------------------------------------------------------------------- /libASL/loc.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Locations in source code 3 | * 4 | * Copyright Arm Limited (c) 2017-2019 5 | * Copyright (C) 2022-2025 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | type pos = Lexing.position 10 | 11 | (** Location tracking *) 12 | type t = 13 | | Unknown 14 | | Int of string * t option 15 | | Generated of t 16 | | Range of pos * pos 17 | 18 | val to_string : t -> string 19 | 20 | val pp : Format.formatter -> t -> unit 21 | 22 | (**************************************************************** 23 | * End 24 | ****************************************************************) 25 | -------------------------------------------------------------------------------- /libASL/metadata.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Metadata generator 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | (** Write metadata to a json file *) 9 | val generate_callgraph : string -> Asl_ast.declaration list -> unit 10 | 11 | (**************************************************************** 12 | * End 13 | ****************************************************************) 14 | -------------------------------------------------------------------------------- /libASL/runtime_ac.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Algorithmic C runtime library support 3 | * This uses the C++ "Algorithmic C" library "ac_int.h" 4 | * 5 | * Copyright (C) 2022-2025 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | (** ASL to C runtime library support (C++) *) 10 | 11 | module Runtime : Runtime.RuntimeLib 12 | 13 | (**************************************************************** 14 | * End 15 | ****************************************************************) 16 | -------------------------------------------------------------------------------- /libASL/runtime_c23.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Bit-precise runtime library support 3 | * This uses the C23 "Bit-precise integer" feature "_BitInt" 4 | * 5 | * Copyright (C) 2022-2025 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | (** ASL to C runtime library support (bit-precise) *) 10 | 11 | module Runtime : Runtime.RuntimeLib 12 | 13 | (**************************************************************** 14 | * End 15 | ****************************************************************) 16 | -------------------------------------------------------------------------------- /libASL/runtime_fallback.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Fallback runtime library support 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | (** ASL to C runtime library support (fallback) *) 9 | 10 | module Runtime : Runtime.RuntimeLib 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | -------------------------------------------------------------------------------- /libASL/runtime_sc.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Algorithmic C runtime library support 3 | * This uses the C++ "Algorithmic C" library "ac_int.h" 4 | * 5 | * Copyright (C) 2022-2024 Intel Corporation 6 | * SPDX-Licence-Identifier: BSD-3-Clause 7 | ****************************************************************) 8 | 9 | (** ASL to C runtime library support (C++) *) 10 | 11 | module Runtime : Runtime.RuntimeLib 12 | 13 | (**************************************************************** 14 | * End 15 | ****************************************************************) 16 | -------------------------------------------------------------------------------- /libASL/xform_bitslices.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL bitslice transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_expr : AST.expr -> AST.expr 11 | val xform_stmts : AST.stmt list -> AST.stmt list 12 | val xform_decls : AST.declaration list -> AST.declaration list 13 | 14 | (**************************************************************** 15 | * End 16 | ****************************************************************) 17 | -------------------------------------------------------------------------------- /libASL/xform_bittuples.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Transform bittuples to bitslice assignments. 3 | * Example: 4 | * var v1 :: bits(2); 5 | * var v2 :: bits(4); 6 | * var v3 :: bits(3); 7 | * 8 | * This lowering pass replaces: 9 | * [v1, v2, v3] = expr; 10 | * With: 11 | * let __a0 = expr; 12 | * v1 = __a0[7 +: 2]; 13 | * v2 = __a0[3 +: 4]; 14 | * v3 = __a0[0 +: 3]; 15 | * 16 | * Copyright (C) 2022-2025 Intel Corporation 17 | * SPDX-Licence-Identifier: BSD-3-Clause 18 | ****************************************************************) 19 | 20 | module AST = Asl_ast 21 | 22 | val xform_stmts : AST.stmt list -> AST.stmt list 23 | 24 | val xform_decls : AST.declaration list -> AST.declaration list 25 | -------------------------------------------------------------------------------- /libASL/xform_bounded.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL integer bounds transform 3 | * 4 | * Copyright (C) 2022-2024 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_decls : AST.declaration list -> AST.declaration list 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | -------------------------------------------------------------------------------- /libASL/xform_case.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL complex case elimination transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_expr : AST.expr -> AST.expr 11 | val xform_stmts : AST.stmt list -> AST.stmt list 12 | val xform_decls : AST.declaration list -> AST.declaration list 13 | 14 | (**************************************************************** 15 | * End 16 | ****************************************************************) 17 | -------------------------------------------------------------------------------- /libASL/xform_constprop.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL constant propagation transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | module Env : sig 11 | type t 12 | val pp : Format.formatter -> t -> unit 13 | end 14 | 15 | val unroll_loops : bool ref 16 | 17 | val mkEnv : Eval.GlobalEnv.t -> (Ident.t * Value.value) list -> Env.t 18 | 19 | val xform_ty : Env.t -> AST.ty -> AST.ty 20 | val xform_expr : Env.t -> AST.expr -> AST.expr 21 | val xform_stmts : Env.t -> AST.stmt list -> AST.stmt list 22 | 23 | val xform_decls : Eval.GlobalEnv.t -> AST.declaration list -> AST.declaration list 24 | 25 | (**************************************************************** 26 | * End 27 | ****************************************************************) 28 | -------------------------------------------------------------------------------- /libASL/xform_desugar.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL desugaring transformations 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_decls : AST.declaration list -> AST.declaration list 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | -------------------------------------------------------------------------------- /libASL/xform_getset.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL getters and setters elimination transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_decls : AST.declaration list -> AST.declaration list 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | -------------------------------------------------------------------------------- /libASL/xform_hoist_lets.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL let-hoisting transform 3 | * 4 | * Lifts let-bindings as high as possible out of expressions. 5 | * 6 | * The main restrictions on lifting let-bindings are 7 | * 8 | * - not lifting the let-binding out of a while guard condition 9 | * in case the let-binding depends on a variable that is modified 10 | * by the while loop or has side-effects. 11 | * 12 | * - not lifting the let-binding out of elsif conditions, case-alternative 13 | * guards or catcher-guards in case the let-binding is evaluated 14 | * earlier than other conditions/guards in the statement. 15 | * 16 | * - not lifting the let-binding out of the body of an if-expression 17 | * or out of the second argument of && or || in case the let-binding 18 | * contains a side-effect or can throw an exception or can 19 | * trigger a runtime error. 20 | * 21 | * When these restrictions do not limit how high a binding can be lifted, 22 | * they normally turn into assignments prior to the statement that 23 | * contains the expression. 24 | * 25 | * Copyright (C) 2025-2025 Intel Corporation 26 | * SPDX-Licence-Identifier: BSD-3-Clause 27 | ****************************************************************) 28 | 29 | (**************************************************************** 30 | * End 31 | ****************************************************************) 32 | -------------------------------------------------------------------------------- /libASL/xform_int_bitslices.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL integer bitslicing transform 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_expr : AST.expr -> AST.expr 11 | val xform_stmts : AST.stmt list -> AST.stmt list 12 | val xform_decls : AST.declaration list -> AST.declaration list 13 | 14 | (**************************************************************** 15 | * End 16 | ****************************************************************) 17 | -------------------------------------------------------------------------------- /libASL/xform_lower.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL lowering transform 3 | * 4 | * Transforms 5 | * - Slice_HiLo to Slice_LoWd 6 | * - Slice_Single to Slice_LoWd 7 | * 8 | * Copyright (C) 2023-2025 Intel Corporation 9 | * SPDX-Licence-Identifier: BSD-3-Clause 10 | ****************************************************************) 11 | 12 | module AST = Asl_ast 13 | 14 | val xform_decls : AST.declaration list -> AST.declaration list 15 | val xform_expr : AST.expr -> AST.expr 16 | val xform_stmts : AST.stmt list -> AST.stmt list 17 | 18 | (**************************************************************** 19 | * End 20 | ****************************************************************) 21 | -------------------------------------------------------------------------------- /libASL/xform_mono.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL function monomorphization transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val enable_auto_case_split : bool ref 11 | 12 | val monomorphize : AST.declaration list -> AST.declaration list 13 | 14 | (**************************************************************** 15 | * End 16 | ****************************************************************) 17 | 18 | 19 | -------------------------------------------------------------------------------- /libASL/xform_named_type.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL named type transform 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_decls : AST.declaration list -> AST.declaration list 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | -------------------------------------------------------------------------------- /libASL/xform_simplify_expr.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Expression simplifier 3 | * 4 | * This simplifies expressions such as 5 | * 6 | * x + 1 - x ==> 1 7 | * 2 * x - x ==> x 8 | * 9 | * which makes it easier for constant propagation, etc. 10 | * to eliminate expressions. 11 | * 12 | * Copyright (C) 2022-2025 Intel Corporation 13 | * SPDX-Licence-Identifier: BSD-3-Clause 14 | ****************************************************************) 15 | 16 | module AST = Asl_ast 17 | 18 | (** Simplify an expression by simplifying integer +,-,*,c,v *) 19 | val simplify : AST.expr -> AST.expr 20 | 21 | (** Add ints and simplify *) 22 | val mk_add_int : AST.expr -> AST.expr -> AST.expr 23 | 24 | (** Add ints and simplify *) 25 | val mk_add_ints : AST.expr list -> AST.expr 26 | 27 | (****************************************************************) 28 | (* End *) 29 | (****************************************************************) 30 | -------------------------------------------------------------------------------- /libASL/xform_tuples.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL tuple elimination transform 3 | * 4 | * Copyright (C) 2022-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | (* Used by FFI support in the code generator to support 11 | * import/export of functions that return tuples of results 12 | *) 13 | val isReturnTypeName : Ident.t -> bool 14 | 15 | val xform_stmts : AST.stmt list -> AST.stmt list 16 | 17 | val xform_decls : AST.declaration list -> AST.declaration list 18 | 19 | (**************************************************************** 20 | * End 21 | ****************************************************************) 22 | -------------------------------------------------------------------------------- /libASL/xform_valid.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL transform to track valid bits 3 | * 4 | * Copyright (C) 2024-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_stmts : Ident.t list -> AST.stmt list -> AST.stmt list 11 | val xform_decls : Ident.t list -> AST.declaration list -> AST.declaration list 12 | 13 | (**************************************************************** 14 | * End 15 | ****************************************************************) 16 | -------------------------------------------------------------------------------- /libASL/xform_wrap.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * ASL global variable wrapping transform 3 | * 4 | * Copyright (C) 2024-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | module AST = Asl_ast 9 | 10 | val xform_decls : AST.declaration list -> AST.declaration list 11 | 12 | (**************************************************************** 13 | * End 14 | ****************************************************************) 15 | 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | filecheck==1.0.1 \ 2 | --hash=sha256:2d1a0e8784b723a4b04a655cff3af09dd159a31f4e39d477186f5547553124ab 3 | lit==18.1.8 \ 4 | --hash=sha256:a873ff7acd76e746368da32eb7355625e2e55a2baaab884c9cc130f2ee0300f7 5 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /runtime/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | # ASL runtime Makefile 3 | # 4 | # Copyright (C) 2023-2025 Intel Corporation 5 | # SPDX-Licence-Identifier: BSD-3-Clause 6 | ################################################################ 7 | 8 | .PHONY: default all clean test 9 | 10 | BUILD_DIR ?= $(CURDIR)/build 11 | LIB := $(BUILD_DIR)/libASL.a 12 | 13 | default: $(LIB) 14 | 15 | AR ?= ar 16 | CC ?= gcc 17 | CPPFLAGS = -Iinclude 18 | CFLAGS = -g -Wall -Werror -Wconversion -std=c99 -fPIC 19 | OBJEXT ?= o 20 | 21 | C_FILES = bits1024.c \ 22 | bits128.c \ 23 | bits256.c \ 24 | bits512.c \ 25 | bits64.c \ 26 | error.c \ 27 | end_of_execution.c \ 28 | ram.c 29 | 30 | OBJ_FILES = $(C_FILES:%.c=$(BUILD_DIR)/%.$(OBJEXT)) 31 | DEP_FILES = $(OBJ_FILES:%.$(OBJEXT)=%.d) 32 | 33 | -include $(DEP_FILES) 34 | 35 | $(BUILD_DIR)/%.$(OBJEXT): lib/%.c | build_dir 36 | $(info CC $(@F)) 37 | $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -c $< -o $@ 38 | 39 | $(LIB): $(OBJ_FILES) 40 | $(RM) $@ 41 | $(info AR $(@F)) 42 | $(AR) cr $@ $^ 43 | 44 | build_dir: 45 | mkdir -p $(BUILD_DIR) 46 | 47 | clean: 48 | $(RM) -r $(BUILD_DIR) 49 | 50 | test: $(LIB) 51 | $(MAKE) -C test BUILD_DIR=$(BUILD_DIR)/test 52 | -------------------------------------------------------------------------------- /runtime/dune: -------------------------------------------------------------------------------- 1 | (rule 2 | (deps (source_tree includes) 3 | (source_tree lib) 4 | (file Makefile)) 5 | (targets libASL.a) 6 | (action 7 | (no-infer 8 | (progn 9 | (run make BUILD_DIR=build) 10 | (copy build/libASL.a libASL.a))))) 11 | 12 | (install 13 | (section (site (asli runtime))) 14 | (files libASL.a)) 15 | 16 | (install 17 | (section (site (asli runtime_include))) 18 | (files (glob_files (include/asl/*.h* with_prefix asl)))) 19 | -------------------------------------------------------------------------------- /runtime/include/asl/error.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime error support library for ASL's C backend 3 | // 4 | // Copyright (C) 2022-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #ifndef ASL_ERROR_H 9 | #define ASL_ERROR_H 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define ASL_NORETURN __attribute__((__noreturn__)) 18 | 19 | ASL_NORETURN void ASL_error(const char *loc, const char *msg); 20 | 21 | #define ASL_error_unmatched_case(loc) ASL_error(loc, "unmatched case statement") 22 | 23 | ASL_NORETURN void ASL_runtime_error(const char *msg); 24 | 25 | #define ASL_runtime_error_if(cond, msg) if (cond) ASL_runtime_error(msg); 26 | 27 | void ASL_assert(const char* loc, const char* expr, bool c); 28 | 29 | ASL_NORETURN void ASL_end_execution(bool success); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif // ASL_ERROR_H 36 | 37 | //////////////////////////////////////////////////////////////// 38 | // End 39 | //////////////////////////////////////////////////////////////// 40 | -------------------------------------------------------------------------------- /runtime/include/asl/print_template.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime print support for ASL's C backend 3 | // 4 | // Copyright (C) 2023-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #define ASL_BITS_LIMBS_64 (N >> 6) 9 | #define ASL_BITS_TYPE ASL_CC_INDIR(ASL_CC_INDIR(ASL_bits, N), _t) 10 | 11 | static inline void 12 | ASL_print_bits_hex(N, int width, ASL_BITS_TYPE x) 13 | { 14 | printf("%d'x", width); 15 | bool leading = true; // suppress leading zeros 16 | for (int i = ASL_BITS_LIMBS_64 - 1; i >= 0; --i) { 17 | if (leading) { 18 | if (i == 0 || x.u64[i]) { 19 | printf("%llx", (long long)x.u64[i]); 20 | leading = false; 21 | } 22 | } else { 23 | printf("%08llx", (long long)x.u64[i]); 24 | } 25 | } 26 | } 27 | 28 | #undef ASL_BITS_LIMBS_64 29 | #undef ASL_BITS_TYPE 30 | -------------------------------------------------------------------------------- /runtime/include/asl/ram.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime memory support library for ASL's C backend 3 | // 4 | // Copyright (C) 2022-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #ifndef ASL_RAM_H 9 | #define ASL_RAM_H 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct ASL_ram { 18 | uint8_t *p; 19 | uint64_t init_val; 20 | } *ASL_ram_t; 21 | 22 | ASL_ram_t ASL_ram_alloc(); 23 | 24 | void ASL_ram_free(struct ASL_ram **p); 25 | 26 | void ASL_ram_init(int64_t address_size, ASL_ram_t ram, uint64_t val); 27 | 28 | uint64_t ASL_ram_read(int64_t address_size, int64_t size, ASL_ram_t ram, 29 | uint64_t address); 30 | 31 | void ASL_ram_write(int64_t address_size, int64_t size, ASL_ram_t ram, 32 | uint64_t address, uint64_t val); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // ASL_RAM_H 39 | 40 | //////////////////////////////////////////////////////////////// 41 | // End 42 | //////////////////////////////////////////////////////////////// 43 | -------------------------------------------------------------------------------- /runtime/include/asl/set_slice_template.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Slice assignment support for ASL's C backend 3 | // 4 | // Copyright (C) 2023-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #if M <= N && N != 64 9 | 10 | #define ASL_BITS_TYPE_N ASL_CC_INDIR(ASL_CC_INDIR(ASL_bits, N), _t) 11 | #define ASL_BITS_TYPE_M ASL_CC_INDIR(ASL_CC_INDIR(ASL_bits, M), _t) 12 | 13 | // Set bits i..i+w-1 of *l to r 14 | void 15 | ASL_set_slice(N, M, int l_width, ASL_BITS_TYPE_N *l, ASL_int_t i, int r_width, ASL_BITS_TYPE_M r); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /runtime/include/asl/track_valid.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime library for ASL's C backend to support tracking 3 | // validity masks 4 | // 5 | // Copyright (C) 2024-2025 Intel Corporation 6 | // SPDX-Licence-Identifier: BSD-3-Clause 7 | //////////////////////////////////////////////////////////////// 8 | 9 | #ifndef ASL_TRACK_VALID_H 10 | #define ASL_TRACK_VALID_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /* 17 | Function for tracking validity mask of variables of bitvector 18 | type. 19 | 20 | var_name is the variable name, listed in the "track-valid" section 21 | of the input .json file. 22 | 23 | low and width denote bitvector field/slice that has an arbitrary 24 | (invalid) value. low is the number of the least significant bit 25 | in the slice and width is the width of the slice. 26 | */ 27 | void ASL_fuzz(const char *var_name, int low, int width); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif // ASL_TRACK_VALID_H 34 | 35 | //////////////////////////////////////////////////////////////// 36 | // End 37 | //////////////////////////////////////////////////////////////// 38 | -------------------------------------------------------------------------------- /runtime/lib/end_of_execution.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime error support library for ASL's C backend 3 | // 4 | // Note: these functions can (and usually are) overridden in the linker 5 | // command line by providing .o files that override both functions. 6 | // 7 | // Copyright (C) 2022-2025 Intel Corporation 8 | // SPDX-Licence-Identifier: BSD-3-Clause 9 | //////////////////////////////////////////////////////////////// 10 | 11 | #include "asl/error.h" 12 | 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | void 21 | ASL_end_execution(bool success) 22 | { 23 | exit(success ? 0 : 1); 24 | } 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | //////////////////////////////////////////////////////////////// 31 | // End 32 | //////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /runtime/lib/error.c: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Runtime error support library for ASL's C backend 3 | // 4 | // Note: these functions can (and usually are) overridden in the linker 5 | // command line by providing .o files that override both functions. 6 | // 7 | // Copyright (C) 2022-2025 Intel Corporation 8 | // SPDX-Licence-Identifier: BSD-3-Clause 9 | //////////////////////////////////////////////////////////////// 10 | 11 | #include "asl/error.h" 12 | 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | void 21 | ASL_error(const char* loc, const char* msg) 22 | { 23 | printf("%s: ASL error: %s\n\n", loc, msg); 24 | exit(1); 25 | } 26 | 27 | void 28 | ASL_runtime_error(const char *msg) 29 | { 30 | printf("Runtime error: %s\n", msg); 31 | exit(1); 32 | } 33 | 34 | void 35 | ASL_assert(const char* loc, const char* expr, bool c) 36 | { 37 | if (!c) { 38 | printf("%s: Evaluation error: assertion failure: %s\n\n", loc, expr); 39 | exit(1); 40 | } 41 | } 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | //////////////////////////////////////////////////////////////// 48 | // End 49 | //////////////////////////////////////////////////////////////// 50 | -------------------------------------------------------------------------------- /runtime/lib/set_slice_template_c.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Slice assignment support for ASL's C backend 3 | // 4 | // Copyright (C) 2023-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #if M <= N && N != 64 9 | 10 | #define ASL_BITS_TYPE_N ASL_CC_INDIR(ASL_CC_INDIR(ASL_bits, N), _t) 11 | #define ASL_BITS_TYPE_M ASL_CC_INDIR(ASL_CC_INDIR(ASL_bits, M), _t) 12 | 13 | // Set bits i..i+w-1 of *l to r 14 | void 15 | ASL_set_slice(N, M, int l_width, ASL_BITS_TYPE_N *l, ASL_int_t i, int r_width, ASL_BITS_TYPE_M r) 16 | { 17 | ASL_BITS_TYPE_N lsl = ASL_lsl_bits(N, l_width, ASL_zero_extend_bits(M, N, r_width, r, N), i); 18 | ASL_BITS_TYPE_N mask = ASL_lsl_bits(N, l_width, ASL_mk_mask(N, r_width), i); 19 | ASL_BITS_TYPE_N masked = ASL_and_bits(N, l_width, *l, ASL_not_bits(N, l_width, mask)); 20 | *l = ASL_or_bits(N, l_width, masked, lsl); 21 | } 22 | 23 | #undef LIMB_M 24 | #undef LIMB_N 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /runtime/test/.gitignore: -------------------------------------------------------------------------------- 1 | bitint_maxwidth 2 | -------------------------------------------------------------------------------- /runtime/test/bitint_maxwidth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("%d\n", BITINT_MAXWIDTH); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /runtime/test/integer_test.cc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Tests for C runtime integer support library 3 | // 4 | // Copyright (C) 2023-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #include 9 | 10 | #include "asl/integer.h" 11 | 12 | #include "gtest/gtest.h" 13 | 14 | class Integer : public ::testing::Test { 15 | protected: 16 | }; 17 | 18 | TEST_F(Integer, MaskInt) 19 | { 20 | EXPECT_EQ(1LL, ASL_mask_int(1LL)); 21 | #ifdef ASL_INT128 22 | EXPECT_EQ(ASL_int_128(0, UINT64_MAX), ASL_mask_int(64LL)); 23 | EXPECT_EQ(ASL_int_128(1LL, UINT64_MAX), ASL_mask_int(65LL)); 24 | EXPECT_EQ(-1LL, ASL_mask_int(128LL)); 25 | #else 26 | EXPECT_EQ(-1LL, ASL_mask_int(64LL)); 27 | #endif 28 | } 29 | -------------------------------------------------------------------------------- /runtime/test/ram_test.cc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////// 2 | // Tests for C runtime memory support library 3 | // 4 | // Copyright (C) 2023-2025 Intel Corporation 5 | // SPDX-Licence-Identifier: BSD-3-Clause 6 | //////////////////////////////////////////////////////////////// 7 | 8 | #include "asl/ram.h" 9 | 10 | #include "gtest/gtest.h" 11 | 12 | class Memory : public ::testing::Test { 13 | protected: 14 | ASL_ram_t memory = ASL_ram_alloc(); 15 | int64_t address_size = 0; // unused 16 | 17 | void TearDown() override { ASL_ram_free(&memory); } 18 | }; 19 | 20 | TEST_F(Memory, Init) 21 | { 22 | ASL_ram_init(address_size, memory, 0); 23 | ASL_ram_init(address_size, memory, 0xff); 24 | } 25 | 26 | TEST_F(Memory, Read) 27 | { 28 | uint64_t val = 0xf0ccac1adeadbeefUL; 29 | ASL_ram_init(address_size, memory, val); 30 | EXPECT_EQ(val & 0xff, ASL_ram_read(address_size, 1, memory, 0)); 31 | } 32 | 33 | TEST_F(Memory, Write) 34 | { 35 | int64_t size = 1; 36 | uint64_t address = 0; 37 | uint64_t val = 0xab; 38 | ASL_ram_write(address_size, size, memory, address, val); 39 | EXPECT_EQ(val, ASL_ram_read(address_size, size, memory, address)); 40 | } 41 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | Output 2 | .lit_test_times.txt 3 | -------------------------------------------------------------------------------- /tests/backends/asl_end_execution_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4)) 5 | begin 6 | asl_end_execution(x == '0000'); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // this will exit with success 12 | FUT('0000'); 13 | 14 | return 1; 15 | end 16 | -------------------------------------------------------------------------------- /tests/backends/asl_end_execution_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4)) 5 | begin 6 | asl_end_execution(x == '0000'); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // this will exit with failure 12 | FUT('0001'); 13 | 14 | return 1; 15 | end 16 | -------------------------------------------------------------------------------- /tests/backends/bits_add_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : bits(8)) => bits(8) 5 | begin 6 | return asl_add_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test(1[0 +: 8], 2[0 +: 8])); println(); 12 | // CHECK: 8'x3 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_and_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4), y : bits(4)) => bits(4) 5 | begin 6 | return x AND y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1100', '1010')); println(); 12 | // CHECK: 4'x8 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_append_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4), y : bits(4)) => bits(8) 5 | begin 6 | return asl_append_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1101', '0010')); println(); 12 | // CHECK: 8'xd2 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_asr_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : integer) => bits(8) 5 | begin 6 | return asl_asr_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1010 0101', 3)); println(); 12 | // CHECK: 8'xf4 13 | print_bits_hex(Test('0101 1010', 2)); println(); 14 | // CHECK: 8'x16 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_cvt_sint_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4)) => integer {-8..7} 5 | begin 6 | return asl_cvt_bits_sint(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test('0010')); println(); 12 | // CHECK: 2 13 | print_int_dec(Test('1010')); println(); 14 | // CHECK: -6 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_cvt_ssintN_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT4(x : bits(4)) => __sint(4) 5 | begin 6 | return asl_cvt_bits_ssintN(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT4('0010')); println(); 12 | // CHECK: i4'd2 13 | print_sintN_dec(FUT4('1010')); println(); 14 | // CHECK: -i4'd6 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_cvt_uint_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4)) => integer {0..15} 5 | begin 6 | return asl_cvt_bits_uint(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test('0010')); println(); 12 | // CHECK: 2 13 | print_int_dec(Test('1010')); println(); 14 | // CHECK: 10 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_cvt_usintN_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT4(x : bits(4)) => __sint(5) 5 | begin 6 | return asl_cvt_bits_usintN(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT4('0010')); println(); 12 | // CHECK: i5'd2 13 | print_sintN_dec(FUT4('1010')); println(); 14 | // CHECK: i5'd10 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_eq_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(8), y : bits(8)) => boolean 5 | begin 6 | return asl_eq_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(8'x1, 8'x1)); println(); 12 | // CHECK: TRUE 13 | print(FUT(8'x1, 8'x2)); println(); 14 | // CHECK: FALSE 15 | print(FUT(8'x2, 8'x1)); println(); 16 | // CHECK: FALSE 17 | print(FUT(8'x2, 8'x2)); println(); 18 | // CHECK: TRUE 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/bits_get_slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : integer) => bits(4) 5 | begin 6 | return x[i +: 4]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test_8_4('1010 0101', 0)); println(); 12 | // CHECK: 4'x5 13 | print_bits_hex(Test_8_4('1010 0101', 1)); println(); 14 | // CHECK: 4'x2 15 | print_bits_hex(Test_8_4('1010 0101', 2)); println(); 16 | // CHECK: 4'x9 17 | print_bits_hex(Test_8_4('1010 0101', 3)); println(); 18 | // CHECK: 4'x4 19 | print_bits_hex(Test_8_4('1010 0101', 4)); println(); 20 | // CHECK: 4'xa 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/backends/bits_get_slice_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8_4(x : bits(8), i : integer) => bits(4) 5 | begin 6 | return x[i +: 4]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(FUT_8_4('1010 0101', 5)); println(); 12 | // CHECK: Evaluation error: assertion failure 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_get_slice_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8_4(x : bits(8), i : integer) => bits(4) 5 | begin 6 | return x[i +: 4]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(FUT_8_4('1010 0101', -1)); println(); 12 | // CHECK: Evaluation error: assertion failure 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_lsl_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : integer) => bits(8) 5 | begin 6 | return asl_lsl_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1010 0101', 3)); println(); 12 | // CHECK: 8'x28 13 | print_bits_hex(Test('0101 1010', 2)); println(); 14 | // CHECK: 8'x68 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_lsr_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : integer) => bits(8) 5 | begin 6 | return asl_lsr_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1010 0101', 3)); println(); 12 | // CHECK: 8'x14 13 | print_bits_hex(Test('0101 1010', 2)); println(); 14 | // CHECK: 8'x16 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_mk_mask_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test0(w : integer) => bits(0) 5 | begin 6 | return asl_mk_mask(w, 0); 7 | end 8 | 9 | func Test8(w : integer) => bits(8) 10 | begin 11 | return asl_mk_mask(w, 8); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test0(0)); println(); 17 | // CHECK: 0'x0 18 | print_bits_hex(Test8(3)); println(); 19 | // CHECK: 8'x7 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/bits_mul_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : bits(8)) => bits(8) 5 | begin 6 | return asl_mul_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test(3[0 +: 8], 7[0 +: 8])); println(); 12 | // CHECK: 8'x15 13 | print_bits_hex(Test(255[0 +: 8], 255[0 +: 8])); println(); 14 | // CHECK: 8'x1 15 | return 0; 16 | end 17 | 18 | -------------------------------------------------------------------------------- /tests/backends/bits_ne_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(8), y : bits(8)) => boolean 5 | begin 6 | return asl_ne_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(8'x1, 8'x1)); println(); 12 | // CHECK: FALSE 13 | print(FUT(8'x1, 8'x2)); println(); 14 | // CHECK: TRUE 15 | print(FUT(8'x2, 8'x1)); println(); 16 | // CHECK: TRUE 17 | print(FUT(8'x2, 8'x2)); println(); 18 | // CHECK: FALSE 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/bits_not_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8)) => bits(8) 5 | begin 6 | return (NOT x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1011 0011')); println(); 12 | // CHECK: 8'x4c 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_ones_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test0() => bits(0) 5 | begin 6 | return asl_ones_bits(0); 7 | end 8 | 9 | func Test6() => bits(6) 10 | begin 11 | return asl_ones_bits(6); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test0()); println(); 17 | // CHECK: 0'x0 18 | print_bits_hex(Test6()); println(); 19 | // CHECK: 6'x3f 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/bits_or_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4), y : bits(4)) => bits(4) 5 | begin 6 | return x OR y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1100', '1010')); println(); 12 | // CHECK: 4'xe 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_print_hex_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_bits_hex(42[0 +: 8]); println(); 7 | // CHECK: 8'x2a 8 | print_bits_hex(0xcf[0 +: 8]); println(); 9 | // CHECK: 8'xcf 10 | print_bits_hex(0[0 +: 8]); println(); 11 | // CHECK: 8'x0 12 | print_bits_hex(''); println(); 13 | // CHECK: 0'x0 14 | print_bits_hex(16384[0 +: 70]); println(); 15 | // CHECK: 70'x4000 16 | print_bits_hex((-16384)[0 +: 70]); println(); 17 | // CHECK: 70'x3fffffffffffffc000 18 | 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/bits_print_hex_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // REQUIRES: !c23 || wide_bitint 3 | // Copyright (C) 2023-2025 Intel Corporation 4 | 5 | func main() => integer 6 | begin 7 | print_bits_hex(256'xff01020304050607_1011121314151617_2021222324252627_3031323334353637); println(); 8 | // CHECK: 256'xff01020304050607101112131415161720212223242526273031323334353637 9 | 10 | print_bits_hex(32'x0); println(); 11 | // CHECK: 32'x0 12 | print_bits_hex(32'x8000_0000); println(); 13 | // CHECK: 32'x80000000 14 | print_bits_hex(32'xffff_ffff); println(); 15 | // CHECK: 32'xffffffff 16 | 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/bits_replicate_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test0(x : bits(4)) => bits(0) 5 | begin 6 | return asl_replicate_bits(x, 0); 7 | end 8 | 9 | func Test1(x : bits(4)) => bits(4) 10 | begin 11 | return asl_replicate_bits(x, 1); 12 | end 13 | 14 | func Test5(x : bits(4)) => bits(20) 15 | begin 16 | return asl_replicate_bits(x, 5); 17 | end 18 | 19 | func main() => integer 20 | begin 21 | print_bits_hex(Test0('0001')); println(); 22 | // CHECK: 0'x0 23 | print_bits_hex(Test1('0001')); println(); 24 | // CHECK: 4'x1 25 | print_bits_hex(Test5('0001')); println(); 26 | // CHECK: 20'x11111 27 | 28 | print_bits_hex(Test0('0101')); println(); 29 | // CHECK: 0'x0 30 | print_bits_hex(Test1('0101')); println(); 31 | // CHECK: 4'x5 32 | print_bits_hex(Test5('0101')); println(); 33 | // CHECK: 20'x55555 34 | return 0; 35 | end 36 | -------------------------------------------------------------------------------- /tests/backends/bits_set_slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : integer, y : bits(4)) => bits(8) 5 | begin 6 | var r = x; 7 | r[i +: 4] = y; 8 | return r; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(Test_8_4('0000 0000', 0, '1111')); println(); 14 | // CHECK: 8'xf 15 | print_bits_hex(Test_8_4('0000 0000', 1, '1111')); println(); 16 | // CHECK: 8'x1e 17 | print_bits_hex(Test_8_4('0000 0000', 2, '1111')); println(); 18 | // CHECK: 8'x3c 19 | print_bits_hex(Test_8_4('0000 0000', 3, '1111')); println(); 20 | // CHECK: 8'x78 21 | print_bits_hex(Test_8_4('0000 0000', 4, '1111')); println(); 22 | // CHECK: 8'xf0 23 | 24 | print_bits_hex(Test_8_4('1111 1111', 0, '0000')); println(); 25 | // CHECK: 8'xf0 26 | print_bits_hex(Test_8_4('1111 1111', 1, '0000')); println(); 27 | // CHECK: 8'xe1 28 | print_bits_hex(Test_8_4('1111 1111', 2, '0000')); println(); 29 | // CHECK: 8'xc3 30 | print_bits_hex(Test_8_4('1111 1111', 3, '0000')); println(); 31 | // CHECK: 8'x87 32 | print_bits_hex(Test_8_4('1111 1111', 4, '0000')); println(); 33 | // CHECK: 8'xf 34 | 35 | return 0; 36 | end 37 | -------------------------------------------------------------------------------- /tests/backends/bits_set_slice_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2024 Intel Corporation 3 | 4 | func Test(x : bits(4), y : bits(4)) => bits(16) 5 | begin 6 | var result : bits(16); 7 | result = asl_zeros_bits(16); 8 | 9 | for i = 0 to 3 do 10 | if x[i +: 1] == '1' then 11 | result[i * 4 +: 4] = y; 12 | end 13 | end 14 | return result; 15 | end 16 | 17 | func main() => integer 18 | begin 19 | print_bits_hex(Test('1100', '1111')); println(); 20 | // CHECK: 16'xff00 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/bits_set_slice_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-check %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8_4(x : bits(8), i : integer, y : bits(4)) => bits(8) 5 | begin 6 | var r = x; 7 | r[i +: 4] = y; 8 | return r; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(FUT_8_4('0000 0000', 5, '1111')); println(); 14 | // CHECK: Evaluation error: assertion failure 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_set_slice_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8_4(x : bits(8), i : integer, y : bits(4)) => bits(8) 5 | begin 6 | var r = x; 7 | r[i +: 4] = y; 8 | return r; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(FUT_8_4('0000 0000', -1, '1111')); println(); 14 | // CHECK: Evaluation error: assertion failure 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_sext_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // REQUIRES: !c23 || wide_bitint 3 | // Copyright (C) 2023-2025 Intel Corporation 4 | 5 | func Test_70_140(x : bits(70)) => bits(140) 6 | begin 7 | return asl_sign_extend_bits(x, 140); 8 | end 9 | 10 | func main() => integer 11 | begin 12 | print_bits_hex(Test_70_140(16384[0 +: 70])); println(); 13 | // CHECK: 140'x4000 14 | print_bits_hex(Test_70_140((-16384)[0 +: 70])); println(); 15 | // CHECK: 140'xfffffffffffffffffffffffffffffffc000 16 | 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/bits_sub_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(8), y : bits(8)) => bits(8) 5 | begin 6 | return asl_sub_bits(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test(1[0 +: 8], 2[0 +: 8])); println(); 12 | // CHECK: 8'xff 13 | print_bits_hex(Test(2[0 +: 8], 1[0 +: 8])); println(); 14 | // CHECK: 8'x1 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_sub_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT(x : bits(16)) => bits(64) 5 | begin 6 | // This test used to fail in c23 backend due to the subtraction 7 | // being promoted to signed. 8 | return asl_zero_extend_bits(asl_sub_bits(x, 16'x1), 64); 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(FUT(16'x0)); println(); 14 | // CHECK: 64'xf 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bits_xor_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4), y : bits(4)) => bits(4) 5 | begin 6 | return x XOR y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('1100', '1010')); println(); 12 | // CHECK: 4'x6 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/bits_zeros_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test0() => bits(0) 5 | begin 6 | return asl_zeros_bits(0); 7 | end 8 | 9 | func Test6() => bits(6) 10 | begin 11 | return asl_zeros_bits(6); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test0()); println(); 17 | // CHECK: 0'x0 18 | print_bits_hex(Test6()); println(); 19 | // CHECK: 6'x0 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/bits_zext_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(3)) => bits(8) 5 | begin 6 | return asl_zero_extend_bits(x, 8); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test('110')); println(); 12 | // CHECK: 8'x6 13 | print_bits_hex(Test('011')); println(); 14 | // CHECK: 8'x3 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/bool_and_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x && y then 8 | '1001' 9 | else 10 | '1011' 11 | ); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test(TRUE, TRUE)); println(); 17 | // CHECK: 4'x9 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'xb 20 | print_bits_hex(Test(FALSE, TRUE)); println(); 21 | // CHECK: 4'xb 22 | print_bits_hex(Test(FALSE, FALSE)); println(); 23 | // CHECK: 4'xb 24 | 25 | return 0; 26 | end 27 | -------------------------------------------------------------------------------- /tests/backends/bool_eq_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x == y then 8 | '1001' 9 | else 10 | '1011' 11 | ); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test(TRUE, TRUE)); println(); 17 | // CHECK: 4'x9 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'xb 20 | print_bits_hex(Test(FALSE, TRUE)); println(); 21 | // CHECK: 4'xb 22 | print_bits_hex(Test(FALSE, FALSE)); println(); 23 | // CHECK: 4'x9 24 | 25 | return 0; 26 | end 27 | -------------------------------------------------------------------------------- /tests/backends/bool_ne_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x != y then 8 | '1001' 9 | else 10 | '1011' 11 | ); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test(TRUE, TRUE)); println(); 17 | // CHECK: 4'xb 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'x9 20 | print_bits_hex(Test(FALSE, TRUE)); println(); 21 | // CHECK: 4'x9 22 | print_bits_hex(Test(FALSE, FALSE)); println(); 23 | // CHECK: 4'xb 24 | 25 | return 0; 26 | end 27 | -------------------------------------------------------------------------------- /tests/backends/bool_not_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean) => bits(4) 5 | begin 6 | return 7 | (if !x then 8 | '1001' 9 | else 10 | '1011' 11 | ); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test(TRUE)); println(); 17 | // CHECK: 4'xb 18 | print_bits_hex(Test(FALSE)); println(); 19 | // CHECK: 4'x9 20 | 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/bool_or_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x || y then 8 | '1001' 9 | else 10 | '1011' 11 | ); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_bits_hex(Test(TRUE, TRUE)); println(); 17 | // CHECK: 4'x9 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'x9 20 | print_bits_hex(Test(FALSE, TRUE)); println(); 21 | // CHECK: 4'x9 22 | print_bits_hex(Test(FALSE, FALSE)); println(); 23 | // CHECK: 4'xb 24 | 25 | return 0; 26 | end 27 | -------------------------------------------------------------------------------- /tests/backends/exceptions_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func Test?(x : integer) => integer 7 | begin 8 | try 9 | if x < 0 then 10 | print("THROWING\n"); 11 | throw E; 12 | end 13 | catch 14 | when e : E => 15 | print("CAUGHT\n"); 16 | return -x; 17 | end 18 | return x; 19 | end 20 | 21 | func main() => integer 22 | begin 23 | print_int_dec(Test?(1)); println(); 24 | // CHECK: 1 25 | print_int_dec(Test?(-2)); println(); 26 | // CHECK: THROWING 27 | // CHECK: CAUGHT 28 | // CHECK: 2 29 | print_int_dec(Test?(3)); println(); 30 | // CHECK: 3 31 | 32 | return 0; 33 | end 34 | 35 | -------------------------------------------------------------------------------- /tests/backends/expr_IN_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(3)) => boolean 5 | begin 6 | return x IN '10x'; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test('000')); println(); 12 | // CHECK: FALSE 13 | print(Test('001')); println(); 14 | // CHECK: FALSE 15 | print(Test('010')); println(); 16 | // CHECK: FALSE 17 | print(Test('011')); println(); 18 | // CHECK: FALSE 19 | print(Test('100')); println(); 20 | // CHECK: TRUE 21 | print(Test('101')); println(); 22 | // CHECK: TRUE 23 | print(Test('110')); println(); 24 | // CHECK: FALSE 25 | print(Test('111')); println(); 26 | // CHECK: FALSE 27 | 28 | return 0; 29 | end 30 | 31 | -------------------------------------------------------------------------------- /tests/backends/expr_as_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test1(x : integer) => integer {0..255} 5 | begin 6 | return x as {0..255}; 7 | end 8 | 9 | func Test2(x : integer) => integer {0..255} 10 | begin 11 | return x as integer {0..255}; 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_int_dec(Test1(4)); println(); 17 | // CHECK: 4 18 | print_int_dec(Test2(5)); println(); 19 | // CHECK: 5 20 | 21 | return 0; 22 | end 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/backends/expr_assert_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(8), i : integer) => bit 5 | begin 6 | return __assert 0 <= i && i < 8 __in x[i +: 1]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // assertion that does fail 12 | print_bits_hex(FUT('0000 1111', 9)); println(); 13 | // CHECK: Evaluation error: assertion failure 14 | 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/expr_assert_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(8), i : integer) => bit 5 | begin 6 | return __assert 0 <= i && i < 8 __in x[i +: 1]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // assertion that do not fail 12 | print_bits_hex(FUT('1100 1111', 0)); println(); 13 | // CHECK: 1'x1 14 | print_bits_hex(FUT('1100 1111', 4)); println(); 15 | // CHECK: 1'x0 16 | print_bits_hex(FUT('1100 1111', 7)); println(); 17 | // CHECK: 1'x1 18 | 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/expr_bitslice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4), i : integer) => bit 5 | begin 6 | return x[i +: 1]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // Positive numbers 12 | print_bits_hex(FUT(4'x5, 3)); println(); 13 | // CHECK: 1'x0 14 | print_bits_hex(FUT(4'x5, 2)); println(); 15 | // CHECK: 1'x1 16 | print_bits_hex(FUT(4'x5, 1)); println(); 17 | // CHECK: 1'x0 18 | print_bits_hex(FUT(4'x5, 0)); println(); 19 | // CHECK: 1'x1 20 | 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/expr_if_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x then 8 | '1001' 9 | elsif y then 10 | '1010' 11 | else 12 | '1011' 13 | ); 14 | return '1100'; 15 | end 16 | 17 | func main() => integer 18 | begin 19 | print_bits_hex(Test(TRUE, FALSE)); println(); 20 | // CHECK: 4'x9 21 | print_bits_hex(Test(TRUE, TRUE)); println(); 22 | // CHECK: 4'x9 23 | print_bits_hex(Test(FALSE, TRUE)); println(); 24 | // CHECK: 4'xa 25 | print_bits_hex(Test(FALSE, FALSE)); println(); 26 | // CHECK: 4'xb 27 | 28 | return 0; 29 | end 30 | 31 | -------------------------------------------------------------------------------- /tests/backends/expr_if_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | return 7 | (if x then 8 | '1001' 9 | elsif y then 10 | '1010' 11 | else 12 | '1011' 13 | ); 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'x9 20 | print_bits_hex(Test(TRUE, TRUE)); println(); 21 | // CHECK: 4'x9 22 | print_bits_hex(Test(FALSE, TRUE)); println(); 23 | // CHECK: 4'xa 24 | print_bits_hex(Test(FALSE, FALSE)); println(); 25 | // CHECK: 4'xb 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/expr_intslice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : integer) => bit 5 | begin 6 | return x[0 +: 1]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(FUT(0)); println(); 12 | // CHECK: 1'x0 13 | print_bits_hex(FUT(1)); println(); 14 | // CHECK: 1'x1 15 | print_bits_hex(FUT(2)); println(); 16 | // CHECK: 1'x0 17 | print_bits_hex(FUT(3)); println(); 18 | // CHECK: 1'x1 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/expr_let_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | return __let r : integer = x*x __in r+r; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(5)); println(); 12 | // CHECK: 50 13 | 14 | return 0; 15 | end 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/backends/expr_var_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_arg(x : bits(4)) => bits(4) 5 | begin 6 | return x; 7 | end 8 | 9 | var G : bits(4); 10 | 11 | func Test_global() => bits(4) 12 | begin 13 | return G; 14 | end 15 | 16 | config C : bits(4) = '1000'; 17 | 18 | func Test_config() => bits(4) 19 | begin 20 | return C; 21 | end 22 | 23 | func main() => integer 24 | begin 25 | print_bits_hex(Test_arg('0001')); println(); 26 | // CHECK: 4'x1 27 | print_bits_hex(Test_arg('0010')); println(); 28 | // CHECK: 4'x2 29 | 30 | G = '0100'; 31 | print_bits_hex(Test_global()); println(); 32 | // CHECK: 4'x4 33 | G = '0101'; 34 | print_bits_hex(Test_global()); println(); 35 | // CHECK: 4'x5 36 | 37 | print_bits_hex(Test_config()); println(); 38 | // CHECK: 4'x8 39 | 40 | return 0; 41 | end 42 | 43 | -------------------------------------------------------------------------------- /tests/backends/expr_with_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-check %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT_8_4(x : bits(8), i : integer, y : bits(4)) => bits(8) 5 | begin 6 | return x with { [i +: 4] = y }; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(FUT_8_4('0000 0000', 5, '1111')); println(); 12 | // CHECK: Evaluation error: assertion failure 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/expr_with_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : integer, y : bits(4)) => bits(8) 5 | begin 6 | return x with { [i +: 4] = y }; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test_8_4('0000 0000', 0, '1111')); println(); 12 | // CHECK: 8'xf 13 | print_bits_hex(Test_8_4('0000 0000', 1, '1111')); println(); 14 | // CHECK: 8'x1e 15 | print_bits_hex(Test_8_4('0000 0000', 2, '1111')); println(); 16 | // CHECK: 8'x3c 17 | print_bits_hex(Test_8_4('0000 0000', 3, '1111')); println(); 18 | // CHECK: 8'x78 19 | print_bits_hex(Test_8_4('0000 0000', 4, '1111')); println(); 20 | // CHECK: 8'xf0 21 | 22 | print_bits_hex(Test_8_4('1111 1111', 0, '0000')); println(); 23 | // CHECK: 8'xf0 24 | print_bits_hex(Test_8_4('1111 1111', 1, '0000')); println(); 25 | // CHECK: 8'xe1 26 | print_bits_hex(Test_8_4('1111 1111', 2, '0000')); println(); 27 | // CHECK: 8'xc3 28 | print_bits_hex(Test_8_4('1111 1111', 3, '0000')); println(); 29 | // CHECK: 8'x87 30 | print_bits_hex(Test_8_4('1111 1111', 4, '0000')); println(); 31 | // CHECK: 8'xf 32 | 33 | return 0; 34 | end 35 | -------------------------------------------------------------------------------- /tests/backends/expr_with_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : integer, y : bits(4), j : integer, z : bit) => bits(8) 5 | begin 6 | return x with { [i +: 4] = y, [j +: 1] = z }; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test_8_4('0000 0000', 0, '1111', 7, '1')); println(); 12 | // CHECK: 8'x8f 13 | 14 | print_bits_hex(Test_8_4('0000 0000', 0, '1111', 6, '1')); println(); 15 | // CHECK: 8'x4f 16 | 17 | print_bits_hex(Test_8_4('0000 0000', 0, '1111', 5, '1')); println(); 18 | // CHECK: 8'x2f 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/expr_with_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | record R { 5 | f0 : bits(4); 6 | f1 : boolean; 7 | }; 8 | 9 | func FUT1(x : R, y : bits(4)) => R 10 | begin 11 | return x with { f0 = y }; 12 | end 13 | 14 | func FUT2(x : R, y : boolean) => R 15 | begin 16 | return x with { f1 = y }; 17 | end 18 | 19 | func printR(x : R) 20 | begin 21 | print("R{"); 22 | print("f0="); print_bits_hex(x.f0); 23 | print(", "); 24 | print("f1="); print(x.f1); 25 | print("}"); 26 | end 27 | 28 | func main() => integer 29 | begin 30 | let r = R{f0 = '0000', f1 = FALSE}; 31 | printR(FUT1(r, '1001')); println(); 32 | // CHECK: R{f0=4'x9, f1=FALSE} 33 | 34 | printR(FUT1(r, '1011')); println(); 35 | // CHECK: R{f0=4'xb, f1=FALSE} 36 | 37 | printR(FUT2(r, TRUE)); println(); 38 | // CHECK: R{f0=4'x0, f1=TRUE} 39 | 40 | return 0; 41 | end 42 | -------------------------------------------------------------------------------- /tests/backends/ffi_config_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s --extra-c=%S/ffi_config_00.c | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | // UNSUPPORTED: interpreter 5 | 6 | config ConfigBool : boolean = FALSE; 7 | config ConfigInt : integer {1, 2, 3, 4} = 1; 8 | 9 | func main() => integer 10 | begin 11 | // Any changes to configuration variables should be performed 12 | // before any ASL code is executed so this test depends on 13 | // the accompanying C file defining a function that is 14 | // executed before main that will change the values of the 15 | // configuration variables and is expected to produce the 16 | // following output. 17 | 18 | // CHECK: Changing ConfigBool from false to true 19 | // CHECK: Changing ConfigInt from 1 to 4 20 | 21 | print(ConfigBool); println(); 22 | // CHECK: TRUE 23 | print_int_dec(ConfigInt); println(); 24 | // CHECK: 4 25 | 26 | return 0; 27 | end 28 | -------------------------------------------------------------------------------- /tests/backends/ffi_config_00.c: -------------------------------------------------------------------------------- 1 | // FFI testing support functions for configuration variables 2 | // 3 | // Copyright (C) 2025-2025 Intel Corporation 4 | 5 | #include 6 | #include "asl_ffi.h" 7 | 8 | // The following function will be executed *before* main 9 | void __attribute__((constructor)) FFI_Init_Configs() 10 | { 11 | printf("Changing ConfigBool from %s to true\n", 12 | ASL_get_config_ConfigBool() ? "true" : "false"); 13 | ASL_set_config_ConfigBool(true); 14 | 15 | printf("Changing ConfigInt from %d to 4\n", 16 | ASL_get_config_ConfigInt()); 17 | ASL_set_config_ConfigInt(4); 18 | } 19 | -------------------------------------------------------------------------------- /tests/backends/ffi_export_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s --import=FFI_Call128 --export=FFI_Extract128_32 --extra-c=%S/ffi_export_00.c | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | // UNSUPPORTED: interpreter 5 | 6 | // Function imported from C 7 | func FFI_Call128(x : bits(128)) => bits(32); 8 | 9 | // Function exported to C 10 | func FFI_Extract128_32(x : bits(128), i : integer) => bits(32) 11 | begin 12 | return x[i +: 32]; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_bits_hex(FFI_Call128(128'xfedcba98765432100123456789abcdef)); println(); 18 | // CHECK: 32'x56789abc 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/ffi_export_00.c: -------------------------------------------------------------------------------- 1 | // FFI testing support functions to be imported/exported into ASL test programs 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | #include 5 | #include "asl_ffi.h" 6 | 7 | uint32_t FFI_Call128(uint64_t x[2]) 8 | { 9 | return FFI_Extract128_32(x, 12); 10 | } 11 | -------------------------------------------------------------------------------- /tests/backends/ffi_export_01.json: -------------------------------------------------------------------------------- 1 | { 2 | "__comment": [ 3 | "Export the interface required by ffi_export_01.c" 4 | ], 5 | "exports": [ 6 | "E", 7 | "FFI_bits8", 8 | "FFI_bits16", 9 | "FFI_bits32", 10 | "FFI_bits64", 11 | "FFI_bits17", 12 | "FFI_bits65", 13 | "FFI_bits127", 14 | "FFI_bits128", 15 | "FFI_string", 16 | "FFI_E", 17 | "FFI_boolean", 18 | "FFI_integer", 19 | "FFI_sint17", 20 | "FFI_int_bool" 21 | ], 22 | "imports": [ 23 | "FFI_test_exports" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /tests/backends/ffi_import_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s --import=FFI_Invert32 --import=FFI_Invert128 --extra-c=%S/ffi_import_00.c | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | // UNSUPPORTED: interpreter 5 | 6 | // The following functions will be replaced by 7 | // a version that is defined externally. 8 | // Normally, the internal and external version have 9 | // similar behaviour but, for testing purposes, the 10 | // internal version is the identity function 11 | // and the external version inverts its argument. 12 | func FFI_Invert32(x : bits(32)) => bits(32) 13 | begin 14 | return x; 15 | end 16 | 17 | func FFI_Invert128(x : bits(128)) => bits(128) 18 | begin 19 | return x; 20 | end 21 | 22 | func main() => integer 23 | begin 24 | print_bits_hex(FFI_Invert32(32'x3)); println(); 25 | // CHECK: 32'xfffffffc 26 | 27 | print_bits_hex(FFI_Invert128(128'x3)); println(); 28 | // CHECK: 128'xfffffffffffffffffffffffffffffffc 29 | 30 | return 0; 31 | end 32 | -------------------------------------------------------------------------------- /tests/backends/ffi_import_00.c: -------------------------------------------------------------------------------- 1 | // FFI testing support functions to be imported into ASL test programs 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | #include 4 | #include "asl_ffi.h" 5 | 6 | // 8, 16, 32 and 64-bit bitvectors are represented using uint*_t 7 | uint32_t FFI_Invert32(uint32_t x) 8 | { 9 | return ~x; 10 | } 11 | 12 | // Wide bitvectors are represented as arrays of uint64_t 13 | // If returning a wide bitvector, an extra array argument is 14 | // added as the last argument 15 | void FFI_Invert128(uint64_t x[2], uint64_t y[2]) 16 | { 17 | for(int i = 0; i < 2; ++i) { 18 | y[i] = ~x[i]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/backends/ffi_import_01.c: -------------------------------------------------------------------------------- 1 | // FFI testing support functions to be imported into ASL test programs 2 | // These functions are "null" functions (or "identity" functions): 3 | // they all return their argument. 4 | // 5 | // Copyright (C) 2025-2025 Intel Corporation 6 | 7 | #include "asl_ffi.h" 8 | #include 9 | 10 | uint8_t FFI_null_bits8(uint8_t x) { return x; } 11 | uint16_t FFI_null_bits16(uint16_t x) { return x; } 12 | uint32_t FFI_null_bits32(uint32_t x) { return x; } 13 | uint64_t FFI_null_bits64(uint64_t x) { return x; } 14 | 15 | void FFI_null_bits17(uint64_t x[1], uint64_t r[1]) { memcpy(r, x, 1*sizeof(uint64_t)); } 16 | void FFI_null_bits65(uint64_t x[2], uint64_t r[2]) { memcpy(r, x, 2*sizeof(uint64_t)); } 17 | void FFI_null_bits127(uint64_t x[2], uint64_t r[2]) { memcpy(r, x, 2*sizeof(uint64_t)); } 18 | void FFI_null_bits128(uint64_t x[2], uint64_t r[2]) { memcpy(r, x, 2*sizeof(uint64_t)); } 19 | 20 | const char* FFI_null_string(const char *x) { return x; } 21 | enum E FFI_null_E(enum E x) { return x; } 22 | bool FFI_null_boolean(bool x) { return x; } 23 | int FFI_null_integer(int x) { return x; } 24 | int FFI_null_sint17(int x) { return x; } 25 | 26 | void FFI_int_bool(int x, int* ret1, bool* ret2) 27 | { 28 | *ret1 = x; 29 | *ret2 = x > 3; 30 | } 31 | -------------------------------------------------------------------------------- /tests/backends/ffi_import_01.json: -------------------------------------------------------------------------------- 1 | { 2 | "__comment": [ 3 | "Import the interface required by ffi_import_01.asl" 4 | ], 5 | "exports": [ 6 | "E" 7 | ], 8 | "imports": [ 9 | "FFI_null_bits8", 10 | "FFI_null_bits16", 11 | "FFI_null_bits32", 12 | "FFI_null_bits64", 13 | "FFI_null_bits17", 14 | "FFI_null_bits65", 15 | "FFI_null_bits127", 16 | "FFI_null_bits128", 17 | "FFI_null_string", 18 | "FFI_null_E", 19 | "FFI_null_boolean", 20 | "FFI_null_integer", 21 | "FFI_null_sint17", 22 | "FFI_int_bool" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/backends/int_add_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x + y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(1, 2)); println(); 12 | // CHECK: 3 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/int_align_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return AlignDown(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(12, 2)); println(); 12 | // CHECK: 12 13 | print_int_dec(Test(13, 2)); println(); 14 | // CHECK: 12 15 | print_int_dec(Test(14, 2)); println(); 16 | // CHECK: 12 17 | print_int_dec(Test(15, 2)); println(); 18 | // CHECK: 12 19 | print_int_dec(Test(16, 2)); println(); 20 | // CHECK: 16 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_cvt_bits_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => bits(8) 5 | begin 6 | return asl_cvt_int_bits(x, 8); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test(42)); println(); 12 | // CHECK: 8'x2a 13 | print_bits_hex(Test(-1)); println(); 14 | // CHECK: 8'xff 15 | return 0; 16 | end 17 | 18 | -------------------------------------------------------------------------------- /tests/backends/int_cvt_bits_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func Test(x : integer) => bits(512) 5 | begin 6 | return asl_cvt_int_bits(x, 512); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test(42)); println(); 12 | // CHECK: 512'x2a 13 | print_bits_hex(Test(-1)); println(); 14 | // CHECK: 512'xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 15 | return 0; 16 | end 17 | 18 | -------------------------------------------------------------------------------- /tests/backends/int_eq_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x == y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: FALSE 13 | print(Test(1, 1)); println(); 14 | // CHECK: TRUE 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/int_exact_div_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x DIV y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(33, 3)); println(); 12 | // CHECK: 11 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/int_fdiv_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return asl_fdiv_int(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(6, 3)); println(); 12 | // CHECK: 2 13 | print_int_dec(Test(-6, 3)); println(); 14 | // CHECK: -2 15 | print_int_dec(Test(5, 3)); println(); 16 | // CHECK: 1 17 | print_int_dec(Test(-5, 3)); println(); 18 | // CHECK: -2 19 | print_int_dec(Test(6, -3)); println(); 20 | // CHECK: -2 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_frem_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return asl_frem_int(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(6, 3)); println(); 12 | // CHECK: 0 13 | print_int_dec(Test(-6, 3)); println(); 14 | // CHECK: 0 15 | print_int_dec(Test(5, 3)); println(); 16 | // CHECK: 2 17 | print_int_dec(Test(-5, 3)); println(); 18 | // CHECK: 1 19 | print_int_dec(Test(6, -3)); println(); 20 | // CHECK: 0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_ge_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x >= y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: FALSE 13 | print(Test(1, 1)); println(); 14 | // CHECK: TRUE 15 | print(Test(1, 0)); println(); 16 | // CHECK: TRUE 17 | print(Test(-1, 0)); println(); 18 | // CHECK: FALSE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/int_gt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x > y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: FALSE 13 | print(Test(1, 1)); println(); 14 | // CHECK: FALSE 15 | print(Test(1, 0)); println(); 16 | // CHECK: TRUE 17 | print(Test(-1, 0)); println(); 18 | // CHECK: FALSE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/int_is_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => boolean 5 | begin 6 | return IsPowerOfTwo(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(0)); println(); 12 | // CHECK: FALSE 13 | print(Test(1)); println(); 14 | // CHECK: TRUE 15 | print(Test(2)); println(); 16 | // CHECK: TRUE 17 | print(Test(3)); println(); 18 | // CHECK: FALSE 19 | print(Test(4)); println(); 20 | // CHECK: TRUE 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_le_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x <= y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: TRUE 13 | print(Test(1, 1)); println(); 14 | // CHECK: TRUE 15 | print(Test(1, 0)); println(); 16 | // CHECK: FALSE 17 | print(Test(-1, 0)); println(); 18 | // CHECK: TRUE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/int_lt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x < y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: TRUE 13 | print(Test(1, 1)); println(); 14 | // CHECK: FALSE 15 | print(Test(1, 0)); println(); 16 | // CHECK: FALSE 17 | print(Test(-1, 0)); println(); 18 | // CHECK: TRUE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/int_mod_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return asl_mod_pow2_int(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(12, 2)); println(); 12 | // CHECK: 0 13 | print_int_dec(Test(13, 2)); println(); 14 | // CHECK: 1 15 | print_int_dec(Test(14, 2)); println(); 16 | // CHECK: 2 17 | print_int_dec(Test(15, 2)); println(); 18 | // CHECK: 3 19 | print_int_dec(Test(16, 2)); println(); 20 | // CHECK: 0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_mul_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x * y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(4, 5)); println(); 12 | // CHECK: 20 13 | print_int_dec(Test(0, 2)); println(); 14 | // CHECK: 0 15 | print_int_dec(Test(3, -2)); println(); 16 | // CHECK: -6 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/int_ne_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => boolean 5 | begin 6 | return x != y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(Test(1, 2)); println(); 12 | // CHECK: TRUE 13 | print(Test(1, 1)); println(); 14 | // CHECK: FALSE 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/int_neg_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | return -x; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(4)); println(); 12 | // CHECK: -4 13 | print_int_dec(Test(-5)); println(); 14 | // CHECK: 5 15 | print_int_dec(Test(0)); println(); 16 | // CHECK: 0 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/int_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | return asl_pow2_int(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(3)); println(); 12 | // CHECK: 8 13 | print_int_dec(Test(7)); println(); 14 | // CHECK: 128 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/int_print_dec.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_int_dec(42); println(); 7 | // CHECK: 42 8 | print_int_dec(-42); println(); 9 | // CHECK: -42 10 | return 0; 11 | end 12 | -------------------------------------------------------------------------------- /tests/backends/int_set_slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_4(x : integer, i : integer, y : bits(4)) => integer 5 | begin 6 | var r = x; 7 | r[i +: 4] = y; 8 | return r; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_int_hex(Test_4(0, 0, '1111')); println(); 14 | // CHECK: 0xf 15 | print_int_hex(Test_4(0, 1, '1111')); println(); 16 | // CHECK: 0x1e 17 | print_int_hex(Test_4(0, 2, '1111')); println(); 18 | // CHECK: 0x3c 19 | print_int_hex(Test_4(0, 3, '1111')); println(); 20 | // CHECK: 0x78 21 | print_int_hex(Test_4(0, 4, '1111')); println(); 22 | // CHECK: 0xf0 23 | 24 | print_int_hex(Test_4(255, 0, '0000')); println(); 25 | // CHECK: 0xf0 26 | print_int_hex(Test_4(255, 1, '0000')); println(); 27 | // CHECK: 0xe1 28 | print_int_hex(Test_4(255, 2, '0000')); println(); 29 | // CHECK: 0xc3 30 | print_int_hex(Test_4(255, 3, '0000')); println(); 31 | // CHECK: 0x87 32 | print_int_hex(Test_4(255, 4, '0000')); println(); 33 | // CHECK: 0xf 34 | 35 | print_int_dec(Test_4(-1, 0, '0000')); println(); 36 | // CHECK: -16 37 | print_int_dec(Test_4(-1, 1, '0000')); println(); 38 | // CHECK: -31 39 | print_int_dec(Test_4(-1, 2, '0000')); println(); 40 | // CHECK: -61 41 | print_int_dec(Test_4(-1, 3, '0000')); println(); 42 | // CHECK: -121 43 | print_int_dec(Test_4(-1, 4, '0000')); println(); 44 | // CHECK: -241 45 | 46 | return 0; 47 | end 48 | -------------------------------------------------------------------------------- /tests/backends/int_shl_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x << y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(3, 0)); println(); 12 | // CHECK: 3 13 | print_int_dec(Test(3, 1)); println(); 14 | // CHECK: 6 15 | print_int_dec(Test(3, 2)); println(); 16 | // CHECK: 12 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/int_shr_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x >> y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(27, 0)); println(); 12 | // CHECK: 27 13 | print_int_dec(Test(27, 1)); println(); 14 | // CHECK: 13 15 | print_int_dec(Test(27, 2)); println(); 16 | // CHECK: 6 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/int_sub_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return x - y; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(1, 2)); println(); 12 | // CHECK: -1 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/int_zdiv_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return asl_zdiv_int(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(6, 3)); println(); 12 | // CHECK: 2 13 | print_int_dec(Test(-6, 3)); println(); 14 | // CHECK: -2 15 | print_int_dec(Test(5, 3)); println(); 16 | // CHECK: 1 17 | print_int_dec(Test(-5, 3)); println(); 18 | // CHECK: -1 19 | print_int_dec(Test(6, -3)); println(); 20 | // CHECK: -2 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/int_zrem_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer, y : integer) => integer 5 | begin 6 | return asl_zrem_int(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_dec(Test(6, 3)); println(); 12 | // CHECK: 0 13 | print_int_dec(Test(-6, 3)); println(); 14 | // CHECK: 0 15 | print_int_dec(Test(5, 3)); println(); 16 | // CHECK: 2 17 | print_int_dec(Test(-5, 3)); println(); 18 | // CHECK: -2 19 | print_int_dec(Test(6, -3)); println(); 20 | // CHECK: 0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/print_char_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_char(65); 7 | // CHECK: A 8 | print_char(66); 9 | // CHECK: B 10 | print_char(67); 11 | // CHECK: C 12 | 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/print_str_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_str("Hello, world!"); 7 | // CHECK: Hello, world! 8 | 9 | return 0; 10 | end 11 | 12 | -------------------------------------------------------------------------------- /tests/backends/sintN_add_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_add_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: i8'd3 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/sintN_align_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_align_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd12, i8'd2)); println(); 12 | // CHECK: i8'd12 13 | print_sintN_dec(FUT(i8'd13, i8'd2)); println(); 14 | // CHECK: i8'd12 15 | print_sintN_dec(FUT(i8'd14, i8'd2)); println(); 16 | // CHECK: i8'd12 17 | print_sintN_dec(FUT(i8'd15, i8'd2)); println(); 18 | // CHECK: i8'd12 19 | print_sintN_dec(FUT(i8'd16, i8'd2)); println(); 20 | // CHECK: i8'd16 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_array_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [4] of bits(32); 5 | 6 | func Test(i : __sint(3)) => bits(32) 7 | begin 8 | return R[asl_cvt_sintN_int(i)]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0] = 10[0 +: 32]; 14 | R[1] = 11[0 +: 32]; 15 | R[2] = 12[0 +: 32]; 16 | R[3] = 13[0 +: 32]; 17 | 18 | print_bits_hex(Test(i3'd0)); println(); 19 | // CHECK: 32'xa 20 | print_bits_hex(Test(i3'd1)); println(); 21 | // CHECK: 32'xb 22 | print_bits_hex(Test(i3'd2)); println(); 23 | // CHECK: 32'xc 24 | print_bits_hex(Test(i3'd3)); println(); 25 | // CHECK: 32'xd 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/sintN_array_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [2] of array [2] of bits(32); 5 | 6 | func Test(i : __sint(2), j : __sint(2)) => bits(32) 7 | begin 8 | return R[asl_cvt_sintN_int(i)][asl_cvt_sintN_int(j)]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0][0] = 10[0 +: 32]; 14 | R[0][1] = 11[0 +: 32]; 15 | R[1][0] = 12[0 +: 32]; 16 | R[1][1] = 13[0 +: 32]; 17 | 18 | print_bits_hex(Test(i2'd0,i2'd0)); println(); 19 | // CHECK: 32'xa 20 | print_bits_hex(Test(i2'd0,i2'd1)); println(); 21 | // CHECK: 32'xb 22 | print_bits_hex(Test(i2'd1,i2'd0)); println(); 23 | // CHECK: 32'xc 24 | print_bits_hex(Test(i2'd1,i2'd1)); println(); 25 | // CHECK: 32'xd 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/sintN_array_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | let R : array [3] of bits(32) = array(32'x3, 32'x4, 32'x5); 5 | 6 | func Test(i : __sint(3)) => bits(32) 7 | begin 8 | return R[asl_cvt_sintN_int(i)]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(Test(i3'd0)); println(); 14 | // CHECK: 32'x3 15 | print_bits_hex(Test(i3'd1)); println(); 16 | // CHECK: 32'x4 17 | print_bits_hex(Test(i3'd2)); println(); 18 | // CHECK: 32'x5 19 | 20 | return 0; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_cvt_bits_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8)) => bits(8) 5 | begin 6 | return asl_cvt_sintN_bits(x, 8); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(FUT(i8'd42)); println(); 12 | // CHECK: 8'x2a 13 | print_bits_hex(FUT(-i8'd1)); println(); 14 | // CHECK: 8'xff 15 | return 0; 16 | end 17 | 18 | -------------------------------------------------------------------------------- /tests/backends/sintN_cvt_from_int_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8(x : integer) => __sint(8) 5 | begin 6 | return asl_cvt_int_sintN(x, 8); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_hex(FUT_8(0x0)); println(); 12 | // CHECK: i8'x0 13 | print_sintN_hex(FUT_8(0x7f)); println(); 14 | // CHECK: i8'x7f 15 | print_sintN_hex(FUT_8(-0x1)); println(); 16 | // CHECK: -i8'x1 17 | print_sintN_hex(FUT_8(-0x80)); println(); 18 | // CHECK: -i8'x80 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/sintN_cvt_to_int_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8(x : __sint(8)) => integer 5 | begin 6 | return asl_cvt_sintN_int(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_int_hex(FUT_8(i8'd0)); println(); 12 | // CHECK: 0x0 13 | print_int_hex(FUT_8(i8'x7f)); println(); 14 | // CHECK: 0x7f 15 | print_int_hex(FUT_8(-i8'x1)); println(); 16 | // CHECK: -0x1 17 | print_int_hex(FUT_8(-i8'x80)); println(); 18 | // CHECK: -0x80 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/sintN_eq_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_eq_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: FALSE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: TRUE 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/sintN_exact_div_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_exact_div_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd33, i8'd3)); println(); 12 | // CHECK: i8'd11 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/sintN_fdiv_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_fdiv_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd6, i8'd3)); println(); 12 | // CHECK: i8'd2 13 | print_sintN_dec(FUT(-i8'd6, i8'd3)); println(); 14 | // CHECK: -i8'd2 15 | print_sintN_dec(FUT(i8'd5, i8'd3)); println(); 16 | // CHECK: i8'd1 17 | print_sintN_dec(FUT(-i8'd5, i8'd3)); println(); 18 | // CHECK: -i8'd2 19 | print_sintN_dec(FUT(i8'd6, -i8'd3)); println(); 20 | // CHECK: -i8'd2 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_frem_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_frem_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd6, i8'd3)); println(); 12 | // CHECK: i8'd0 13 | print_sintN_dec(FUT(-i8'd6, i8'd3)); println(); 14 | // CHECK: i8'd0 15 | print_sintN_dec(FUT(i8'd5, i8'd3)); println(); 16 | // CHECK: i8'd2 17 | print_sintN_dec(FUT(-i8'd5, i8'd3)); println(); 18 | // CHECK: i8'd1 19 | print_sintN_dec(FUT(i8'd6, -i8'd3)); println(); 20 | // CHECK: i8'd0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_ge_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_ge_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: FALSE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: TRUE 15 | print(FUT(i8'd1, i8'd0)); println(); 16 | // CHECK: TRUE 17 | print(FUT(-i8'd1, i8'd0)); println(); 18 | // CHECK: FALSE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/sintN_get_slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : __sint(4)) => bits(4) 5 | begin 6 | return x[asl_cvt_sintN_int(i) +: 4]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_bits_hex(Test_8_4('1010 0101', i4'd0)); println(); 12 | // CHECK: 4'x5 13 | print_bits_hex(Test_8_4('1010 0101', i4'd1)); println(); 14 | // CHECK: 4'x2 15 | print_bits_hex(Test_8_4('1010 0101', i4'd2)); println(); 16 | // CHECK: 4'x9 17 | print_bits_hex(Test_8_4('1010 0101', i4'd3)); println(); 18 | // CHECK: 4'x4 19 | print_bits_hex(Test_8_4('1010 0101', i4'd4)); println(); 20 | // CHECK: 4'xa 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/backends/sintN_get_slice_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4), i : __sint(3)) => bit 5 | begin 6 | return x[asl_cvt_sintN_int(i) +: 1]; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | // Positive numbers 12 | print_bits_hex(FUT(4'x5, i3'd3)); println(); 13 | // CHECK: 1'x0 14 | print_bits_hex(FUT(4'x5, i3'd2)); println(); 15 | // CHECK: 1'x1 16 | print_bits_hex(FUT(4'x5, i3'd1)); println(); 17 | // CHECK: 1'x0 18 | print_bits_hex(FUT(4'x5, i3'd0)); println(); 19 | // CHECK: 1'x1 20 | 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_gt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_gt_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: FALSE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: FALSE 15 | print(FUT(i8'd1, i8'd0)); println(); 16 | // CHECK: TRUE 17 | print(FUT(-i8'd1, i8'd0)); println(); 18 | // CHECK: FALSE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/sintN_is_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8)) => boolean 5 | begin 6 | return asl_is_pow2_sintN(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd0)); println(); 12 | // CHECK: FALSE 13 | print(FUT(i8'd1)); println(); 14 | // CHECK: TRUE 15 | print(FUT(i8'd2)); println(); 16 | // CHECK: TRUE 17 | print(FUT(i8'd3)); println(); 18 | // CHECK: FALSE 19 | print(FUT(i8'd4)); println(); 20 | // CHECK: TRUE 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_le_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_le_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: TRUE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: TRUE 15 | print(FUT(i8'd1, i8'd0)); println(); 16 | // CHECK: FALSE 17 | print(FUT(-i8'd1, i8'd0)); println(); 18 | // CHECK: TRUE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/sintN_lt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_lt_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: TRUE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: FALSE 15 | print(FUT(i8'd1, i8'd0)); println(); 16 | // CHECK: FALSE 17 | print(FUT(-i8'd1, i8'd0)); println(); 18 | // CHECK: TRUE 19 | return 0; 20 | end 21 | -------------------------------------------------------------------------------- /tests/backends/sintN_mod_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_mod_pow2_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd12, i8'd2)); println(); 12 | // CHECK: i8'd0 13 | print_sintN_dec(FUT(i8'd13, i8'd2)); println(); 14 | // CHECK: i8'd1 15 | print_sintN_dec(FUT(i8'd14, i8'd2)); println(); 16 | // CHECK: i8'd2 17 | print_sintN_dec(FUT(i8'd15, i8'd2)); println(); 18 | // CHECK: i8'd3 19 | print_sintN_dec(FUT(i8'd16, i8'd2)); println(); 20 | // CHECK: i8'd0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_mul_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_mul_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd4, i8'd5)); println(); 12 | // CHECK: i8'd20 13 | print_sintN_dec(FUT(i8'd0, i8'd2)); println(); 14 | // CHECK: i8'd0 15 | print_sintN_dec(FUT(i8'd3, -i8'd2)); println(); 16 | // CHECK: -i8'd6 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/sintN_ne_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => boolean 5 | begin 6 | return asl_ne_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: TRUE 13 | print(FUT(i8'd1, i8'd1)); println(); 14 | // CHECK: FALSE 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/sintN_neg_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8)) => __sint(8) 5 | begin 6 | return asl_neg_sintN(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd4)); println(); 12 | // CHECK: -i8'd4 13 | print_sintN_dec(FUT(-i8'd5)); println(); 14 | // CHECK: i8'd5 15 | print_sintN_dec(FUT(i8'd0)); println(); 16 | // CHECK: i8'd0 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/sintN_pow2_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8)) => __sint(8) 5 | begin 6 | return asl_pow2_sintN(x); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd3)); println(); 12 | // CHECK: i8'd8 13 | print_sintN_dec(FUT(i8'd6)); println(); 14 | // CHECK: i8'd64 15 | return 0; 16 | end 17 | -------------------------------------------------------------------------------- /tests/backends/sintN_print_dec.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_sintN_dec(i8'd42); println(); 7 | // CHECK: i8'd42 8 | print_sintN_dec(-i8'd42); println(); 9 | // CHECK: -i8'd42 10 | 11 | print_sintN_dec(i8'd127); println(); 12 | // CHECK: i8'd127 13 | print_sintN_dec(-i8'd127); println(); 14 | // CHECK: -i8'd127 15 | print_sintN_dec(-i8'd128); println(); 16 | // CHECK: -i8'd128 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/sintN_print_hex.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | print_int_hex(42); println(); 7 | // CHECK: 0x2a 8 | print_int_hex(-42); println(); 9 | // CHECK: -0x2a 10 | return 0; 11 | end 12 | 13 | -------------------------------------------------------------------------------- /tests/backends/sintN_resize_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT_8_16(x : __sint(8)) => __sint(16) 5 | begin 6 | return asl_resize_sintN(x, 16); 7 | end 8 | 9 | func FUT_16_8(x : __sint(16)) => __sint(8) 10 | begin 11 | return asl_resize_sintN(x, 8); 12 | end 13 | 14 | func main() => integer 15 | begin 16 | print_sintN_hex(FUT_8_16(i8'd0)); println(); 17 | // CHECK: i16'x0 18 | print_sintN_hex(FUT_8_16(i8'x7f)); println(); 19 | // CHECK: i16'x7f 20 | print_sintN_hex(FUT_8_16(-i8'x1)); println(); 21 | // CHECK: -i16'x1 22 | print_sintN_hex(FUT_8_16(-i8'x80)); println(); 23 | // CHECK: -i16'x80 24 | 25 | print_sintN_hex(FUT_16_8(i16'd0)); println(); 26 | // CHECK: i8'x0 27 | print_sintN_hex(FUT_16_8(i16'x7f)); println(); 28 | // CHECK: i8'x7f 29 | print_sintN_hex(FUT_16_8(-i16'x1)); println(); 30 | // CHECK: -i8'x1 31 | print_sintN_hex(FUT_16_8(-i16'x80)); println(); 32 | // CHECK: -i8'x80 33 | 34 | return 0; 35 | end 36 | 37 | -------------------------------------------------------------------------------- /tests/backends/sintN_set_slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test_8_4(x : bits(8), i : __sint(4), y : bits(4)) => bits(8) 5 | begin 6 | var r = x; 7 | r[asl_cvt_sintN_int(i) +: 4] = y; 8 | return r; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(Test_8_4('0000 0000', i4'd0, '1111')); println(); 14 | // CHECK: 8'xf 15 | print_bits_hex(Test_8_4('0000 0000', i4'd1, '1111')); println(); 16 | // CHECK: 8'x1e 17 | print_bits_hex(Test_8_4('0000 0000', i4'd2, '1111')); println(); 18 | // CHECK: 8'x3c 19 | print_bits_hex(Test_8_4('0000 0000', i4'd3, '1111')); println(); 20 | // CHECK: 8'x78 21 | print_bits_hex(Test_8_4('0000 0000', i4'd4, '1111')); println(); 22 | // CHECK: 8'xf0 23 | 24 | print_bits_hex(Test_8_4('1111 1111', i4'd0, '0000')); println(); 25 | // CHECK: 8'xf0 26 | print_bits_hex(Test_8_4('1111 1111', i4'd1, '0000')); println(); 27 | // CHECK: 8'xe1 28 | print_bits_hex(Test_8_4('1111 1111', i4'd2, '0000')); println(); 29 | // CHECK: 8'xc3 30 | print_bits_hex(Test_8_4('1111 1111', i4'd3, '0000')); println(); 31 | // CHECK: 8'x87 32 | print_bits_hex(Test_8_4('1111 1111', i4'd4, '0000')); println(); 33 | // CHECK: 8'xf 34 | 35 | return 0; 36 | end 37 | -------------------------------------------------------------------------------- /tests/backends/sintN_shl_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_shl_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd3, i8'd0)); println(); 12 | // CHECK: i8'd3 13 | print_sintN_dec(FUT(i8'd3, i8'd1)); println(); 14 | // CHECK: i8'd6 15 | print_sintN_dec(FUT(i8'd3, i8'd2)); println(); 16 | // CHECK: i8'd12 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/sintN_shr_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_shr_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd27, i8'd0)); println(); 12 | // CHECK: i8'd27 13 | print_sintN_dec(FUT(i8'd27, i8'd1)); println(); 14 | // CHECK: i8'd13 15 | print_sintN_dec(FUT(i8'd27, i8'd2)); println(); 16 | // CHECK: i8'd6 17 | return 0; 18 | end 19 | -------------------------------------------------------------------------------- /tests/backends/sintN_sub_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_sub_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd1, i8'd2)); println(); 12 | // CHECK: -i8'd1 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/backends/sintN_zdiv_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_zdiv_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd6, i8'd3)); println(); 12 | // CHECK: i8'd2 13 | print_sintN_dec(FUT(-i8'd6, i8'd3)); println(); 14 | // CHECK: -i8'd2 15 | print_sintN_dec(FUT(i8'd5, i8'd3)); println(); 16 | // CHECK: i8'd1 17 | print_sintN_dec(FUT(-i8'd5, i8'd3)); println(); 18 | // CHECK: -i8'd1 19 | print_sintN_dec(FUT(i8'd6, -i8'd3)); println(); 20 | // CHECK: -i8'd2 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/sintN_zrem_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : __sint(8), y : __sint(8)) => __sint(8) 5 | begin 6 | return asl_zrem_sintN(x, y); 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print_sintN_dec(FUT(i8'd6, i8'd3)); println(); 12 | // CHECK: i8'd0 13 | print_sintN_dec(FUT(-i8'd6, i8'd3)); println(); 14 | // CHECK: i8'd0 15 | print_sintN_dec(FUT(i8'd5, i8'd3)); println(); 16 | // CHECK: i8'd2 17 | print_sintN_dec(FUT(-i8'd5, i8'd3)); println(); 18 | // CHECK: -i8'd2 19 | print_sintN_dec(FUT(i8'd6, -i8'd3)); println(); 20 | // CHECK: i8'd0 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/stmt_assert_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4)) => bits(4) 5 | begin 6 | assert x != '1111'; 7 | return x; 8 | end 9 | 10 | func main() => integer 11 | begin 12 | // assertion that does fail 13 | print_bits_hex(FUT('1111')); println(); 14 | // CHECK: Evaluation error: assertion failure 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/stmt_assert_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : bits(4)) => bits(4) 5 | begin 6 | assert x != '1111'; 7 | return x; 8 | end 9 | 10 | func main() => integer 11 | begin 12 | // assertion that does not fail 13 | print_bits_hex(FUT('0001')); println(); 14 | // CHECK: 4'x1 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/stmt_assign_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4)) => bits(4) 5 | begin 6 | var A : array [1] of bits(4); 7 | A[0] = x; 8 | return A[0]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(Test('0001')); println(); 14 | // CHECK: 4'x1 15 | print_bits_hex(Test('0101')); println(); 16 | // CHECK: 4'x5 17 | 18 | return 0; 19 | end 20 | -------------------------------------------------------------------------------- /tests/backends/stmt_block_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | begin 7 | var r = x; 8 | return r; 9 | end 10 | end 11 | 12 | func main() => integer 13 | begin 14 | print_int_dec(Test(0)); println(); 15 | // CHECK: 0 16 | print_int_dec(Test(1)); println(); 17 | // CHECK: 1 18 | print_int_dec(Test(3)); println(); 19 | // CHECK: 3 20 | 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | case x of 7 | when -1 => return 2; 8 | when 1 => return 3; 9 | when 2 => return 4; 10 | when 3,4,5 => return 5; 11 | otherwise => return 10; 12 | end 13 | return 20; // unreachable 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(Test(-1)); println(); 19 | // CHECK: 2 20 | print_int_dec(Test(0)); println(); 21 | // CHECK: 10 22 | print_int_dec(Test(1)); println(); 23 | // CHECK: 3 24 | print_int_dec(Test(2)); println(); 25 | // CHECK: 4 26 | print_int_dec(Test(3)); println(); 27 | // CHECK: 5 28 | print_int_dec(Test(4)); println(); 29 | // CHECK: 5 30 | print_int_dec(Test(5)); println(); 31 | // CHECK: 5 32 | print_int_dec(Test(6)); println(); 33 | // CHECK: 10 34 | 35 | return 0; 36 | end 37 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | case x of 7 | when 1 => return 3; 8 | when 2 => return 4; 9 | when 3,4,5 => return 5; 10 | // missing otherwise - error if no match 11 | end 12 | return 20; // unreachable 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_int_dec(Test(0)); println(); 18 | // CHECK: unmatched case 19 | 20 | return 0; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean) => integer 5 | begin 6 | case x of 7 | when TRUE => return 3; 8 | otherwise => return 10; 9 | end 10 | return 20; // unreachable 11 | end 12 | 13 | func main() => integer 14 | begin 15 | print_int_dec(Test(FALSE)); println(); 16 | // CHECK: 10 17 | print_int_dec(Test(TRUE)); println(); 18 | // CHECK: 3 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : bits(4)) => integer 5 | begin 6 | case x of 7 | when '0001' => return 3; 8 | when '0010' => return 4; 9 | when '1111' => return 5; 10 | otherwise => return 10; 11 | end 12 | return 20; // unreachable 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_int_dec(Test('0000')); println(); 18 | // CHECK: 10 19 | print_int_dec(Test('0001')); println(); 20 | // CHECK: 3 21 | print_int_dec(Test('0010')); println(); 22 | // CHECK: 4 23 | print_int_dec(Test('0011')); println(); 24 | // CHECK: 10 25 | print_int_dec(Test('1111')); println(); 26 | // CHECK: 5 27 | 28 | return 0; 29 | end 30 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | // UNSUPPORTED: interpreter 5 | 6 | func Test(x : integer) => integer 7 | begin 8 | case x of 9 | when 0x1_0000_0000_0000_0000 => return 1; 10 | // CHECK: Unimplemented large (> 64 bit) integer pattern 11 | otherwise => return 10; 12 | end 13 | return 20; // unreachable 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(Test(-1)); println(); 19 | 20 | return 0; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tests/backends/stmt_case_05.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | // UNSUPPORTED: interpreter 5 | 6 | func Test(x : bits(65)) => integer 7 | begin 8 | case x of 9 | when 65'x0 => return 1; 10 | // CHECK: Unimplemented large (> 64 bit) bitvector pattern 11 | otherwise => return 10; 12 | end 13 | return 20; // unreachable 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(Test(65'x1)); println(); 19 | 20 | return 0; 21 | end 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/backends/stmt_for_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var s = 0; 7 | for i = 0 to x do 8 | s = s + i; 9 | end 10 | return s; 11 | end 12 | 13 | func main() => integer 14 | begin 15 | print_int_dec(Test(0)); println(); 16 | // CHECK: 0 17 | print_int_dec(Test(1)); println(); 18 | // CHECK: 1 19 | print_int_dec(Test(3)); println(); 20 | // CHECK: 6 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/backends/stmt_for_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var s = 0; 7 | for i = x downto 0 do 8 | s = s + i; 9 | end 10 | return s; 11 | end 12 | 13 | func main() => integer 14 | begin 15 | print_int_dec(Test(0)); println(); 16 | // CHECK: 0 17 | print_int_dec(Test(1)); println(); 18 | // CHECK: 1 19 | print_int_dec(Test(3)); println(); 20 | // CHECK: 6 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/backends/stmt_for_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : __sint(5)) => integer 5 | begin 6 | var s = 0; 7 | for i : __sint(5) = i5'd0 to x do 8 | s = s + asl_cvt_sintN_int(i); 9 | end 10 | return s; 11 | end 12 | 13 | func main() => integer 14 | begin 15 | print_int_dec(Test(i5'd0)); println(); 16 | // CHECK: 0 17 | print_int_dec(Test(i5'd1)); println(); 18 | // CHECK: 1 19 | print_int_dec(Test(i5'd3)); println(); 20 | // CHECK: 6 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/backends/stmt_if_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean) => bits(4) 5 | begin 6 | var r = '0000'; 7 | if x then 8 | r = '0001'; 9 | else 10 | r = '0011'; 11 | end 12 | return r; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_bits_hex(Test(TRUE)); println(); 18 | // CHECK: 4'x1 19 | print_bits_hex(Test(FALSE)); println(); 20 | // CHECK: 4'x3 21 | 22 | return 0; 23 | end 24 | 25 | -------------------------------------------------------------------------------- /tests/backends/stmt_if_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | if x then 7 | return '0001'; 8 | elsif y then 9 | return '0010'; 10 | else 11 | return '0011'; 12 | end 13 | return '0100'; 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print_bits_hex(Test(TRUE, FALSE)); println(); 19 | // CHECK: 4'x1 20 | print_bits_hex(Test(TRUE, TRUE)); println(); 21 | // CHECK: 4'x1 22 | print_bits_hex(Test(FALSE, TRUE)); println(); 23 | // CHECK: 4'x2 24 | print_bits_hex(Test(FALSE, FALSE)); println(); 25 | // CHECK: 4'x3 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/stmt_if_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : boolean, y : boolean) => bits(4) 5 | begin 6 | var r = '0000'; 7 | if x then 8 | r = '0001'; 9 | elsif y then 10 | r = '0010'; 11 | else 12 | r = '0011'; 13 | end 14 | return r; 15 | end 16 | 17 | func main() => integer 18 | begin 19 | print_bits_hex(Test(FALSE, FALSE)); println(); 20 | // CHECK: 4'x3 21 | print_bits_hex(Test(FALSE, TRUE)); println(); 22 | // CHECK: 4'x2 23 | print_bits_hex(Test(TRUE, FALSE)); println(); 24 | // CHECK: 4'x1 25 | print_bits_hex(Test(TRUE, TRUE)); println(); 26 | // CHECK: 4'x1 27 | 28 | return 0; 29 | end 30 | -------------------------------------------------------------------------------- /tests/backends/stmt_let_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | let y = x; 7 | let - = x; 8 | return x; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_int_dec(Test(3)); println(); 14 | // CHECK: 3 15 | 16 | return 0; 17 | end 18 | 19 | -------------------------------------------------------------------------------- /tests/backends/stmt_repeat_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var s = 0; 7 | var i = 1; 8 | repeat 9 | s = s + i; 10 | i = i + 1; 11 | until i > x; 12 | return s; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_int_dec(Test(0)); println(); 18 | // CHECK: 1 19 | print_int_dec(Test(1)); println(); 20 | // CHECK: 1 21 | print_int_dec(Test(3)); println(); 22 | // CHECK: 6 23 | 24 | return 0; 25 | end 26 | 27 | -------------------------------------------------------------------------------- /tests/backends/stmt_return_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : boolean) => boolean 5 | begin 6 | return x; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(FUT(TRUE)); println(); 12 | // CHECK: TRUE 13 | print(FUT(FALSE)); println(); 14 | // CHECK: FALSE 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/stmt_return_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : boolean) => boolean 5 | begin 6 | print("A"); println(); 7 | if x then 8 | return x; 9 | end 10 | // next statement not reached if x 11 | print("B"); println(); 12 | return !x; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print(FUT(TRUE)); println(); 18 | // CHECK: A 19 | // CHECK-NOT: B 20 | // CHECK: TRUE 21 | print(FUT(FALSE)); println(); 22 | // CHECK: A 23 | // CHECK: B 24 | // CHECK: TRUE 25 | 26 | return 0; 27 | end 28 | -------------------------------------------------------------------------------- /tests/backends/stmt_return_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func FUT(x : boolean) 5 | begin 6 | print("A"); println(); 7 | if x then 8 | return; 9 | end 10 | // next statement not reached if x 11 | print("B"); println(); 12 | return; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | FUT(TRUE); 18 | // CHECK: A 19 | // CHECK-NOT: B 20 | FUT(FALSE); 21 | // CHECK: A 22 | // CHECK: B 23 | 24 | return 0; 25 | end 26 | 27 | -------------------------------------------------------------------------------- /tests/backends/stmt_try_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E0 of exception; 5 | type E1 of exception{ payload : boolean }; 6 | 7 | func FUT?(x : integer) => integer 8 | begin 9 | if x == 0 then 10 | throw E0; 11 | elsif x == 1 then 12 | throw E1{ payload=TRUE }; 13 | elsif x == 2 then 14 | throw E1{ payload=FALSE }; 15 | else 16 | return 42; 17 | end 18 | return -1; 19 | end 20 | 21 | func main() => integer 22 | begin 23 | print_int_dec(FUT?(3)); println(); 24 | // CHECK: 42 25 | 26 | return 0; 27 | end 28 | -------------------------------------------------------------------------------- /tests/backends/stmt_try_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E0 of exception; 5 | type E1 of exception{ payload : boolean }; 6 | 7 | func FUT?(x : integer) => integer 8 | begin 9 | if x == 0 then 10 | throw E0; 11 | elsif x == 1 then 12 | throw E1{ payload=TRUE }; 13 | elsif x == 2 then 14 | throw E1{ payload=FALSE }; 15 | else 16 | return 42; 17 | end 18 | return -1; 19 | end 20 | 21 | func main() => integer 22 | begin 23 | print(FUT?(0)); println(); 24 | // CHECK: ASL error: uncaught exception 25 | 26 | return 0; 27 | end 28 | -------------------------------------------------------------------------------- /tests/backends/stmt_var_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var - = x + 1; 7 | - = x - 1; 8 | return x; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_int_dec(Test(3)); println(); 14 | // CHECK: 3 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/stmt_var_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var y = x; 7 | y = x + 1; 8 | return y; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_int_dec(Test(3)); println(); 14 | // CHECK: 4 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/stmt_while_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func Test(x : integer) => integer 5 | begin 6 | var s = 0; 7 | var i = 0; 8 | while i <= x do 9 | s = s + i; 10 | i = i + 1; 11 | end 12 | return s; 13 | end 14 | 15 | func main() => integer 16 | begin 17 | print_int_dec(Test(0)); println(); 18 | // CHECK: 0 19 | print_int_dec(Test(1)); println(); 20 | // CHECK: 1 21 | print_int_dec(Test(3)); println(); 22 | // CHECK: 6 23 | 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/backends/type_array_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [4] of bits(32); 5 | 6 | func Test(i : integer) => bits(32) 7 | begin 8 | return R[i]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0] = 10[0 +: 32]; 14 | R[1] = 11[0 +: 32]; 15 | R[2] = 12[0 +: 32]; 16 | R[3] = 13[0 +: 32]; 17 | 18 | print_bits_hex(Test(0)); println(); 19 | // CHECK: 32'xa 20 | print_bits_hex(Test(1)); println(); 21 | // CHECK: 32'xb 22 | print_bits_hex(Test(2)); println(); 23 | // CHECK: 32'xc 24 | print_bits_hex(Test(3)); println(); 25 | // CHECK: 32'xd 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/type_array_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [2] of array [2] of bits(32); 5 | 6 | func Test(i : integer, j : integer) => bits(32) 7 | begin 8 | return R[i][j]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0][0] = 10[0 +: 32]; 14 | R[0][1] = 11[0 +: 32]; 15 | R[1][0] = 12[0 +: 32]; 16 | R[1][1] = 13[0 +: 32]; 17 | 18 | print_bits_hex(Test(0,0)); println(); 19 | // CHECK: 32'xa 20 | print_bits_hex(Test(0,1)); println(); 21 | // CHECK: 32'xb 22 | print_bits_hex(Test(1,0)); println(); 23 | // CHECK: 32'xc 24 | print_bits_hex(Test(1,1)); println(); 25 | // CHECK: 32'xd 26 | 27 | return 0; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /tests/backends/type_array_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | let R : array [3] of bits(32) = array(32'x3, 32'x4, 32'x5); 5 | 6 | func Test(i : integer) => bits(32) 7 | begin 8 | return R[i]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | print_bits_hex(Test(0)); println(); 14 | // CHECK: 32'x3 15 | print_bits_hex(Test(1)); println(); 16 | // CHECK: 32'x4 17 | print_bits_hex(Test(2)); println(); 18 | // CHECK: 32'x5 19 | 20 | return 0; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tests/backends/type_array_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [4] of bits(32); 5 | 6 | func Test(i : integer {0..3}) => bits(32) 7 | begin 8 | return R[i]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0] = 10[0 +: 32]; 14 | R[1] = 11[0 +: 32]; 15 | R[2] = 12[0 +: 32]; 16 | R[3] = 13[0 +: 32]; 17 | 18 | print_bits_hex(Test(0)); println(); 19 | // CHECK: 32'xa 20 | print_bits_hex(Test(1)); println(); 21 | // CHECK: 32'xb 22 | print_bits_hex(Test(2)); println(); 23 | // CHECK: 32'xc 24 | print_bits_hex(Test(3)); println(); 25 | // CHECK: 32'xd 26 | 27 | return 0; 28 | end 29 | -------------------------------------------------------------------------------- /tests/backends/type_array_04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [4] of bits(32); 5 | 6 | func FUT(i : integer) => bits(32) 7 | begin 8 | return R[i]; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | R[0] = 10[0 +: 32]; 14 | R[1] = 11[0 +: 32]; 15 | R[2] = 12[0 +: 32]; 16 | R[3] = 13[0 +: 32]; 17 | 18 | print_bits_hex(FUT(-1)); println(); 19 | // CHECK: Evaluation error: assertion failure 20 | 21 | return 0; 22 | end 23 | -------------------------------------------------------------------------------- /tests/backends/type_array_05.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [3] of bits(32); 5 | 6 | func FUT(i : integer, x : bits(32)) 7 | begin 8 | R[i] = x; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | FUT(4, asl_zeros_bits(32)); 14 | // CHECK: Evaluation error: assertion failure 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/type_array_06.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %aslrun --runtime-checks %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var R : array [3] of bits(32); 5 | 6 | func FUT(i : integer, x : bits(32)) 7 | begin 8 | R[i] = x; 9 | end 10 | 11 | func main() => integer 12 | begin 13 | FUT(-1, asl_zeros_bits(32)); 14 | // CHECK: Evaluation error: assertion failure 15 | 16 | return 0; 17 | end 18 | -------------------------------------------------------------------------------- /tests/backends/type_enum_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | enumeration E { R, G, B }; 5 | 6 | func Test_eq(x : E) => boolean 7 | begin 8 | return x == R; 9 | end 10 | 11 | func Test_ne(x : E) => boolean 12 | begin 13 | return x != R; 14 | end 15 | 16 | func main() => integer 17 | begin 18 | print(Test_eq(R)); println(); 19 | // CHECK: TRUE 20 | print(Test_eq(G)); println(); 21 | // CHECK: FALSE 22 | print(Test_eq(B)); println(); 23 | // CHECK: FALSE 24 | 25 | print(Test_ne(R)); println(); 26 | // CHECK: FALSE 27 | print(Test_ne(G)); println(); 28 | // CHECK: TRUE 29 | print(Test_ne(B)); println(); 30 | // CHECK: TRUE 31 | 32 | return 0; 33 | end 34 | -------------------------------------------------------------------------------- /tests/backends/type_record_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record X { 5 | f : bits(4); 6 | g : bits(4); 7 | }; 8 | 9 | func Test(r : X) => bits(4) 10 | begin 11 | return r.f; 12 | end 13 | 14 | func main() => integer 15 | begin 16 | var r1 : X; 17 | r1.f = '0101'; 18 | r1.g = '0011'; 19 | 20 | print_bits_hex(Test(r1)); println(); 21 | // CHECK: 4'x5 22 | 23 | let r2 = X{ f='1000', g='1001' }; 24 | print_bits_hex(Test(r2)); println(); 25 | // CHECK: 4'x8 26 | 27 | return 0; 28 | end 29 | -------------------------------------------------------------------------------- /tests/dune: -------------------------------------------------------------------------------- 1 | ; Copyright Arm Limited (c) 2017-2019 2 | ; Copyright (C) 2022-2025 Intel Corporation 3 | ; SPDX-Licence-Identifier: BSD-3-Clause 4 | 5 | (tests 6 | (names 7 | asl_test 8 | asl_utils_test 9 | backend_c_c23_test 10 | backend_c_fallback_test 11 | loadasl_test 12 | xform_bitslices_test 13 | xform_bittuples_test 14 | xform_case_test 15 | xform_constprop_test 16 | xform_getset_test 17 | xform_int_bitslices_test 18 | xform_lower_test 19 | xform_mono_test 20 | xform_named_type_test 21 | xform_simplify_expr_test 22 | xform_tuples_test 23 | xform_valid_test 24 | xform_wrap_test) 25 | (modes exe) 26 | (flags 27 | (-cclib -lstdc++)) 28 | (libraries alcotest libASL) 29 | (deps 30 | ../bin/asli.exe 31 | ../prelude.asl 32 | (glob_files ../runtime/include/asl/*))) 33 | -------------------------------------------------------------------------------- /tests/lit/check_monomorphization/asli.prj: -------------------------------------------------------------------------------- 1 | :filter_reachable_from exports 2 | 3 | // :show --format=raw --output log.check_monomorphization.asl 4 | :check_monomorphization --verbose 5 | 6 | :quit 7 | -------------------------------------------------------------------------------- /tests/lit/check_monomorphization/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "exports": [ 3 | "A" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/lit/check_monomorphization/test_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --configuration=%S/config.json --project=%S/asli.prj %s | filecheck %s 2 | // Copyright (C) 2024-2025 Intel Corporation 3 | 4 | func C(x : bits(N)) => integer 5 | begin 6 | return N; 7 | end 8 | 9 | func B(x : bits(N)) => integer 10 | begin 11 | return C(x); 12 | end 13 | 14 | func A() => integer 15 | begin 16 | return B('0'); 17 | end 18 | 19 | // CHECK: WARNING: Bitwidth parameters are not statically known in the following definitions. 20 | // CHECK-NEXT: This will cause code generation to fail. 21 | // 22 | // CHECK: The bitwidth parameters in this call-graph are not statically known 23 | // CHECK-NEXT: A with bitwidth parameters {} 24 | // CHECK-NEXT: B with bitwidth parameters {N} 25 | // CHECK-NEXT: C with bitwidth parameters {N} 26 | // 27 | // CHECK: The simplest way to fix monomorphization issues is usually 28 | // CHECK-NEXT: to change the topmost function in the call-graph so that 29 | // CHECK-NEXT: the parameters to the function it calls are statically known. 30 | // 31 | // CHECK: For example, you might use an if-statement or case-statement to separate 32 | // CHECK-NEXT: the cases for different parameter sizes. 33 | // CHECK-NEXT: This is often easiest to do in machine generated code such as instruction decoders. 34 | -------------------------------------------------------------------------------- /tests/lit/eval/slice_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s '--exec=F()' | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type Flags of bits(4) { 5 | [0] A 6 | [1] B 7 | [2] C 8 | [3] D 9 | }; 10 | 11 | func F() => Flags 12 | begin 13 | var r : Flags = Zeros(4); 14 | // These assignments used to fail because the type of r is a 15 | // typedef instead of either bits(N) or integer 16 | r.A = '1'; 17 | r.C = '1'; 18 | return r; 19 | end 20 | 21 | // CHECK: 4'x5 22 | -------------------------------------------------------------------------------- /tests/lit/eval/slice_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s '--exec=main()' | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | let x = 24'xABCDEF; 7 | 8 | print_bits_hex(x[7:4]); println(); 9 | // CHECK: 4'xe 10 | 11 | print_bits_hex(x[8 +: 4]); println(); 12 | // CHECK: 4'xd 13 | 14 | print_bits_hex(x[15 -: 4]); println(); 15 | // CHECK: 4'xc 16 | 17 | print_bits_hex(x[4 *: 4]); println(); 18 | // CHECK: 4'xb 19 | 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | 6 | func WX() => integer 7 | begin 8 | X = 1; 9 | return 0; 10 | end 11 | 12 | func F() => integer 13 | begin 14 | return WX() + WX(); 15 | // CHECK: Type error: expression behaviour depends on evaluation order 16 | end 17 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | 6 | func WX() => integer 7 | begin 8 | X = 1; 9 | return 0; 10 | end 11 | 12 | func RX() => integer 13 | begin 14 | return X; 15 | end 16 | 17 | func F() => integer 18 | begin 19 | return WX() + RX(); 20 | // CHECK: Type error: expression behaviour depends on evaluation order 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | 6 | func WX() => integer 7 | begin 8 | X = 1; 9 | return 0; 10 | end 11 | 12 | type E of exception; 13 | 14 | func T?() => integer 15 | begin 16 | // Note: functions that return a value cannot be noreturn 17 | // so we add an if statement to make it look optional 18 | if TRUE then throw E; end 19 | return 0; 20 | end 21 | 22 | func F() => integer 23 | begin 24 | return WX() + T?(); 25 | // CHECK: Type error: expression behaviour depends on evaluation order 26 | end 27 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | var Y : integer; 6 | 7 | func WX() => integer 8 | begin 9 | X = 1; 10 | return 0; 11 | end 12 | 13 | func RX() => integer 14 | begin 15 | return X; 16 | end 17 | 18 | func WY() => integer 19 | begin 20 | Y = 1; 21 | return 0; 22 | end 23 | 24 | func RY() => integer 25 | begin 26 | return Y; 27 | end 28 | 29 | func F() => integer 30 | begin 31 | // writing different globals is ok 32 | let x = WX() + WY(); 33 | // reading and writing different globals is ok 34 | let y = WX() + RY(); 35 | // reading the same global is ok 36 | let z = RX() + RX(); 37 | return x + y + z; 38 | end 39 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var ram1 : __RAM(64); 5 | 6 | func I1() => integer 7 | begin 8 | asl_ram_init(64, ram1, Zeros(64)); 9 | return 0; 10 | end 11 | 12 | func R1() => bits(8) 13 | begin 14 | return asl_ram_read(64, 1, ram1, Zeros(64)); 15 | end 16 | 17 | func W1() => integer 18 | begin 19 | asl_ram_write(64, 1, ram1, Zeros(64), Zeros(8)); 20 | return 0; 21 | end 22 | 23 | var ram2 : __RAM(64); 24 | 25 | func I2() => integer 26 | begin 27 | asl_ram_init(64, ram2, Zeros(64)); 28 | return 0; 29 | end 30 | 31 | func R2() => bits(8) 32 | begin 33 | return asl_ram_read(64, 1, ram2, Zeros(64)); 34 | end 35 | 36 | func W2() => integer 37 | begin 38 | asl_ram_write(64, 1, ram2, Zeros(64), Zeros(8)); 39 | return 0; 40 | end 41 | 42 | func F() => integer 43 | begin 44 | return W1() + W2(); 45 | // CHECK: Type error: expression behaviour depends on evaluation order 46 | end 47 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_05.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var ram1 : __RAM(64); 5 | 6 | func I1() => integer 7 | begin 8 | asl_ram_init(64, ram1, Zeros(64)); 9 | return 0; 10 | end 11 | 12 | func R1() => bits(8) 13 | begin 14 | return asl_ram_read(64, 1, ram1, Zeros(64)); 15 | end 16 | 17 | func W1() => integer 18 | begin 19 | asl_ram_write(64, 1, ram1, Zeros(64), Zeros(8)); 20 | return 0; 21 | end 22 | 23 | var ram2 : __RAM(64); 24 | 25 | func I2() => integer 26 | begin 27 | asl_ram_init(64, ram2, Zeros(64)); 28 | return 0; 29 | end 30 | 31 | func R2() => bits(8) 32 | begin 33 | return asl_ram_read(64, 1, ram2, Zeros(64)); 34 | end 35 | 36 | func W2() => integer 37 | begin 38 | asl_ram_write(64, 1, ram2, Zeros(64), Zeros(8)); 39 | return 0; 40 | end 41 | 42 | func F() => integer 43 | begin 44 | return W1() + UInt(R2()); 45 | // CHECK: Type error: expression behaviour depends on evaluation order 46 | end 47 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/eval_order_06.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var ram1 : __RAM(64); 5 | 6 | func I1() => integer 7 | begin 8 | asl_ram_init(64, ram1, Zeros(64)); 9 | return 0; 10 | end 11 | 12 | func R1() => bits(8) 13 | begin 14 | return asl_ram_read(64, 1, ram1, Zeros(64)); 15 | end 16 | 17 | func W1() => integer 18 | begin 19 | asl_ram_write(64, 1, ram1, Zeros(64), Zeros(8)); 20 | return 0; 21 | end 22 | 23 | var ram2 : __RAM(64); 24 | 25 | func I2() => integer 26 | begin 27 | asl_ram_init(64, ram2, Zeros(64)); 28 | return 0; 29 | end 30 | 31 | func R2() => bits(8) 32 | begin 33 | return asl_ram_read(64, 1, ram2, Zeros(64)); 34 | end 35 | 36 | func W2() => integer 37 | begin 38 | asl_ram_write(64, 1, ram2, Zeros(64), Zeros(8)); 39 | return 0; 40 | end 41 | 42 | func F() => integer 43 | begin 44 | return I1() + UInt(R2()); 45 | // CHECK: Type error: expression behaviour depends on evaluation order 46 | end 47 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/markers_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --max-errors=10 --check-call-markers --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func NoThrow() => integer 7 | begin 8 | return 0; 9 | end 10 | 11 | func MayThrow?() => integer 12 | begin 13 | // Note: functions that return a value cannot be noreturn 14 | // so we add an if statement to make it look optional 15 | if TRUE then throw E; end 16 | return 0; 17 | end 18 | 19 | func AlwaysThrow!() 20 | begin 21 | throw E; 22 | end 23 | 24 | func F() => integer 25 | begin 26 | // All of the following calls are correctly marked and should not report an error. 27 | let x = NoThrow(); 28 | let y = MayThrow?(); 29 | AlwaysThrow!(); 30 | end 31 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/noreturn_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --check-exception-markers --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func T() => integer 5 | begin 6 | // CHECK: Type error: Function definition 'T.0' should return a value but does not 7 | end 8 | 9 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/rethrow_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func T?() => integer 7 | begin 8 | // Note: functions that return a value cannot be noreturn 9 | // so we add an if statement to make it look optional 10 | if TRUE then throw E; end 11 | return 0; 12 | end 13 | 14 | func F() => integer 15 | begin 16 | return T(); 17 | // CHECK: Type error: call to function `T.0` should be marked with `?` or `!` because it can throw an exception 18 | end 19 | 20 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/rethrow_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func T?() => integer 7 | begin 8 | // Note: functions that return a value cannot be noreturn 9 | // so we add an if statement to make it look optional 10 | if TRUE then throw E; end 11 | return 0; 12 | end 13 | 14 | func G() => integer 15 | begin 16 | return T?() + 1; 17 | end 18 | 19 | func F() => integer 20 | begin 21 | return G(); 22 | // CHECK: Type error: call to function `G.0` should be marked with `?` or `!` because it can throw an exception 23 | end 24 | 25 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/rethrow_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func T?() => integer 7 | begin 8 | // Note: functions that return a value cannot be noreturn 9 | // so we add an if statement to make it look optional 10 | if TRUE then throw E; end 11 | return 0; 12 | end 13 | 14 | func F() => integer 15 | begin 16 | return T?(); 17 | end 18 | 19 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/rethrow_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func T() => integer 7 | begin 8 | return 1; 9 | end 10 | 11 | func F() => integer 12 | begin 13 | return T?(); 14 | // CHECK: Type error: call to function `T.0` is incorrectly marked with `?` but it cannot throw an exception 15 | end 16 | 17 | -------------------------------------------------------------------------------- /tests/lit/globalchecks/rethrow_04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --max-errors=10 --check-exception-markers --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type E of exception; 5 | 6 | func T() 7 | begin 8 | throw E; 9 | // CHECK: Type error: Function definition 'T.0' always throws an exception but is not marked with '!' 10 | end 11 | 12 | func F() 13 | begin 14 | T(); 15 | // CHECK: Type error: call to procedure `T.0` should be marked with `?` or `!` because it can throw an exception 16 | end 17 | -------------------------------------------------------------------------------- /tests/lit/parser/directive_line.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s || filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | # 42 "foobar.asl" 5 | x == 0 6 | // CHECK: File "foobar.asl", line 42, characters 0-1: 7 | // CHECK: Syntax error before 'x'. 8 | -------------------------------------------------------------------------------- /tests/lit/parser/fenced_code_block.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s || filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | ```json 5 | name: main 6 | shortdesc: Main entrypoint 7 | longdesc: > 8 | Main entrypoint into the specification. 9 | ``` 10 | 11 | func main() => integer 12 | begin 13 | return 0; 14 | end 15 | -------------------------------------------------------------------------------- /tests/lit/print/print_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT1(x : bits(4), y : integer, z : string, b : boolean) 5 | begin 6 | Print("x={x} y={y} z={z} b={b}"); 7 | end 8 | 9 | // CHECK: func FUT1.0{}(x : bits(4), y : integer, z : string, b : boolean) 10 | // CHECK_NEXT: begin 11 | // CHECK_NEXT: print_str.0("x="); 12 | // CHECK_NEXT: print_bits_hex.0(x); 13 | // CHECK_NEXT: print_str.0(" y="); 14 | // CHECK_NEXT: print_int_dec.0(y); 15 | // CHECK_NEXT: print_str.0(" z="); 16 | // CHECK_NEXT: print_str.0(z); 17 | // CHECK_NEXT: print_str.0(" b="); 18 | // CHECK_NEXT: asl_print_bool.0(b); 19 | // CHECK_NEXT: end 20 | -------------------------------------------------------------------------------- /tests/lit/runtime_checks/array_read_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | var R : array [16] of bits(32); 5 | 6 | func FUT1(i : integer {0..15}) => bits(32) 7 | begin 8 | return R[i]; 9 | // CHECK: (__assert asl_lt_int.0{}(i, 16) __in (__assert asl_le_int.0{}(0, i) __in R[i])); 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/runtime_checks/array_write_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | var R : array [16] of bits(32); 5 | 6 | func FUT1(i : integer {0..15}, val : bits(32)) 7 | begin 8 | R[i] = val; 9 | // CHECK: assert asl_lt_int.0{}(i, 16); 10 | // CHECK: assert asl_le_int.0{}(0, i); 11 | end 12 | -------------------------------------------------------------------------------- /tests/lit/runtime_checks/conversion_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT1(i : integer {0..15}) => integer {0..7, 15} 5 | begin 6 | let r = if i < 8 then i else 15; 7 | return (r as {0..7, 15}); 8 | // CHECK: return (__assert asl_lazy_or_bool.0{}(asl_lazy_and_bool.0{}(asl_le_int.0{}(0, r), asl_le_int.0{}(r, 7)), asl_eq_int.0{}(r, 15)) __in (r as {0..7, 15})); 9 | end 10 | 11 | func FUT2(i : integer {0..15}) => integer {0..7, 15} 12 | begin 13 | let r = if i < 8 then i else 15; 14 | return (r as integer {0..7, 15}); 15 | // CHECK: return (__assert asl_lazy_or_bool.0{}(asl_lazy_and_bool.0{}(asl_le_int.0{}(0, r), asl_le_int.0{}(r, 7)), asl_eq_int.0{}(r, 15)) __in (r as integer{0..7, 15})); 16 | end 17 | -------------------------------------------------------------------------------- /tests/lit/runtime_checks/expr_with_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT1(x : bits(32), i : integer {0..31}) => bits(32) 5 | begin 6 | return x with { [i] = Ones(1) }; 7 | // CHECK: return (__assert asl_lt_int.0{}(i, 32) __in (__assert asl_le_int.0{}(0, i) __in 8 | end 9 | 10 | func FUT2(x : bits(32), h : integer {0..31}, l : integer {0..4}) => bits(32) 11 | begin 12 | return x with { [h:l] = Ones(h-l+1) }; 13 | // CHECK: return (__assert asl_lt_int.0{}(h, 32) __in (__assert asl_le_int.0{}(l, asl_add_int.0{}(h, 1)) __in (__assert asl_le_int.0{}(0, l) __in 14 | end 15 | 16 | 17 | func FUT3(x : bits(32), j : integer {0..15}, w : integer) => bits(32) 18 | begin 19 | return x with { [j+:w] = Ones(w) }; 20 | // CHECK: return (__assert asl_le_int.0{}(asl_add_int.0{}(j, w), 32) __in (__assert asl_le_int.0{}(0, w) __in (__assert asl_le_int.0{}(0, j) __in 21 | end 22 | 23 | func FUT4(x : bits(32), j : integer {0..8}, w : integer) => bits(32) 24 | begin 25 | return x with { [j*:w] = Ones(w) }; 26 | // CHECK: return (__assert asl_le_int.0{}(asl_mul_int.0{}(j, w), asl_sub_int.0{}(32, w)) __in (__assert asl_le_int.0{}(0, w) __in (__assert asl_le_int.0{}(0, j) __in 27 | end 28 | 29 | func FUT5(x : bits(32), j : integer {0..15}, w : integer) => bits(32) 30 | begin 31 | return x with { [j-:w] = Ones(w) }; 32 | // CHECK: return (__assert asl_le_int.0{}(w, asl_add_int.0{}(j, 1)) __in (__assert asl_le_int.0{}(0, w) __in (__assert asl_lt_int.0{}(j, 32) __in 33 | end 34 | -------------------------------------------------------------------------------- /tests/lit/runtime_checks/int_divide_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --runtime-checks --exec=":show --format=raw FUT*" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT1(x : integer, y : integer) => integer 5 | begin 6 | return x DIV y; 7 | // CHECK: (__assert asl_ne_int.0{}(0, y) __in asl_exact_div_int.0{}(x, y)); 8 | end 9 | 10 | func FUT2(x : integer, y : integer) => integer 11 | begin 12 | return x MOD y; 13 | // CHECK: (__assert asl_ne_int.0{}(0, y) __in asl_frem_int.0{}(x, y)); 14 | end 15 | 16 | func FUT3(x : integer, y : integer) => integer 17 | begin 18 | return x QUOT y; 19 | // CHECK: (__assert asl_ne_int.0{}(0, y) __in asl_zdiv_int.0{}(x, y)); 20 | end 21 | 22 | func FUT4(x : integer, y : integer) => integer 23 | begin 24 | return x REM y; 25 | // CHECK: (__assert asl_ne_int.0{}(0, y) __in asl_zrem_int.0{}(x, y)); 26 | end 27 | -------------------------------------------------------------------------------- /tests/lit/tcheck/array_param_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : array [size] of integer) => integer 5 | begin 6 | var sum = 0; 7 | for i = 0 to size-1 do 8 | sum = sum + x[i]; 9 | end 10 | return sum; 11 | end 12 | 13 | func main() => integer 14 | begin 15 | let x : integer = (F(array (1,2,3))); 16 | let y : integer = (F(array (1))); 17 | end 18 | -------------------------------------------------------------------------------- /tests/lit/tcheck/conflicting_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(); 5 | func F(); 6 | // CHECK: Type error: function `F` was previously defined 7 | -------------------------------------------------------------------------------- /tests/lit/tcheck/conflicting_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(); 5 | func F(x : integer); 6 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, y=1, 2); 9 | // CHECK: Type error: positional argument occurs after a named argument 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, y=1); 9 | // CHECK: Type error: missing argument 'z' 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, 1, 2, 3); 9 | // CHECK: Type error: too many arguments for function 'F' (3 expected) 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall03.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, 1, 2, z=3); 9 | // CHECK: Type error: multiple bindings for argument 'z' 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, 1, z=2, z=3); 9 | // CHECK: Type error: multiple bindings for argument 'z' 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall05.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 0, z : integer); 5 | 6 | func main() => integer 7 | begin 8 | F(0, 1, 2, p=3); 9 | // CHECK: Type error: named argument 'p' does not match any argument of function 'F(x, y, z)' 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall06.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslrun %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer, y : integer = 1, z : integer = 2) => integer 5 | begin 6 | return x * 0x100 + y * 0x10 + z; 7 | end 8 | 9 | func main() => integer 10 | begin 11 | print(F(9)); println(); 12 | // CHECK: 912 13 | print(F(9, y=4)); println(); 14 | // CHECK: 942 15 | print(F(9, z=5)); println(); 16 | // CHECK: 915 17 | print(F(9, y=4, z=5)); println(); 18 | // CHECK: 945 19 | print(F(9, z=4, y=5)); println(); 20 | // CHECK: 954 21 | 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall07.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func main() => integer 5 | begin 6 | F(0, 1, 2); 7 | // CHECK: Type error: Unknown procedure F 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall08.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : boolean, y : boolean, z : boolean); 5 | 6 | func main() => integer 7 | begin 8 | F(0, 1, 2); 9 | // CHECK: While typechecking a call to 'F' with arguments 10 | // CHECK: F(integer{0}, integer{1}, integer{2}) 11 | // CHECK: Type error in procedure arguments for call to 'F' 12 | // CHECK F{}(x : boolean, y : boolean, z : boolean) => () 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/funcall09.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func F(x : integer); 5 | func F(x : boolean); 6 | 7 | func main() => integer 8 | begin 9 | F('0'); 10 | // CHECK: While typechecking a call to 'F' with arguments 11 | // CHECK: F(bits(1)) 12 | // CHECK: Unable to decide which of the following definitions of 'F' to call 13 | // CHECK: F{}(x : boolean) => () 14 | // CHECK: F{}(x : integer) => () 15 | end 16 | -------------------------------------------------------------------------------- /tests/lit/tcheck/function_arg_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func IntFunction(x : integer) 5 | begin 6 | end 7 | 8 | func T() 9 | begin 10 | IntFunction(TRUE); 11 | // CHECK: Type error: function arguments 12 | end 13 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(x : integer) 5 | begin 6 | x = 1; 7 | // CHECK: Type error: assignment to immutable variable `x` declared at 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(x : bits(N)) 5 | begin 6 | N = 1; 7 | // CHECK: Type error: assignment to immutable variable `N` declared at 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F{N}(x : bits(N)) 5 | begin 6 | N = 1; 7 | // CHECK: Type error: assignment to immutable variable `N` declared at 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F() 5 | begin 6 | let x = 1; 7 | x = 2; 8 | // CHECK: Type error: assignment to immutable variable `x` declared at 9 | end 10 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_04.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F() 5 | begin 6 | constant x = 1; 7 | x = 2; 8 | // CHECK: Type error: assignment to immutable variable `x` declared at 9 | end 10 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_05.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F() 5 | begin 6 | var y : integer = 1; 7 | y = 2; 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_06.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | config CFG : integer = 1; 5 | 6 | func F() 7 | begin 8 | CFG = 2; 9 | // CHECK: Type error: assignment to immutable variable `CFG` declared at 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_07.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | 6 | func F() 7 | begin 8 | X = 2; 9 | end 10 | -------------------------------------------------------------------------------- /tests/lit/tcheck/immutable_08.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | constant C : integer = 1; 5 | 6 | func F() 7 | begin 8 | C = 2; 9 | // CHECK: Type error: assignment to immutable variable `C` declared at 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/implicit_params_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F() => bits(N); 5 | // CHECK: Type error: the width parameter(s) `N` of the return type cannot be determined from the function arguments 6 | -------------------------------------------------------------------------------- /tests/lit/tcheck/implicit_params_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | // Correct type parameters: N can be synthesized from the type of x 5 | func F1{N : integer}(x : bits(N)) => boolean; 6 | 7 | // Correct function type: we can synthesize N from the type of x 8 | func F2(x : bits(N)) => boolean; 9 | 10 | // Correct function type: N is an explicit argument 11 | func F3(N : integer, x : bits(N)) => boolean; 12 | 13 | // Correct function type: N is an explicit argument and argument order does not matter 14 | func F4(x : bits(N), N : integer) => boolean; 15 | 16 | // Correct function type: N is an explicit argument 17 | func F5(N : integer) => bits(N); 18 | 19 | // Correct function type: N is an explicit parameter and an explicit argument 20 | func F6{N : integer}(N : integer) => bits(N); 21 | 22 | // Correct function type: N is an explicit parameter and an explicit argument 23 | func F7{N : integer}(N : integer, x : bits(N)) => bits(N); 24 | -------------------------------------------------------------------------------- /tests/lit/tcheck/missing_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func T() 5 | begin 6 | UndefinedFunction(); 7 | // CHECK: Type error: Unknown procedure UndefinedFunction 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/patterns_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var X : integer; 5 | 6 | func F(x : integer) => boolean 7 | begin 8 | case x of 9 | when X => return TRUE; 10 | otherwise => return FALSE; 11 | end 12 | // CHECK: Type error: pattern match of `X` should be a constant. 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/record_init_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record R{ 5 | x : integer; 6 | y : integer; 7 | }; 8 | 9 | func T() => R 10 | begin 11 | return R{x=1, z=3}; 12 | // CHECK: Type error: record initializer is missing field[s] y and/or has extra field[s] z 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/record_init_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record R(M) { 5 | x : bits(M); 6 | }; 7 | 8 | func S4(r : R(4)) => bits(4) 9 | begin 10 | return r.x; 11 | end 12 | 13 | func T() 14 | begin 15 | let t = S4(R{x='111'}); 16 | // CHECK: Type error: wrong number of type parameters 17 | end 18 | -------------------------------------------------------------------------------- /tests/lit/tcheck/record_init_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record R{ 5 | x : integer; 6 | y : integer; 7 | }; 8 | 9 | func T() => R 10 | begin 11 | return R{y=3, x=1}; 12 | // CHECK: Type error: record initializer must set fields in the same order as the type declaration. 13 | // CHECK-NEXT: Order of fields in type declaration: x, y 14 | // CHECK-NEXT: Order of fields in record initializer: y, x 15 | end 16 | 17 | -------------------------------------------------------------------------------- /tests/lit/tcheck/records_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record R { 5 | x : integer; 6 | x : integer; 7 | // CHECK: Type error: fieldname `x` is declared multiple times 8 | }; 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/records_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type B of bits(8) { 5 | [7] X 6 | [6] X 7 | // CHECK: Type error: fieldname `X` is declared multiple times 8 | }; 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/records_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | record R { 5 | x : integer; 6 | y : integer; 7 | }; 8 | 9 | func F() => R 10 | begin 11 | return R{x = 1}; 12 | // CHECK: Type error: record initializer is missing field[s] y and/or has extra field[s] 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/return_type_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(x : boolean) => integer 5 | begin 6 | return x; 7 | // CHECK: Type error: type integer does not match boolean 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/setter_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | setter A[] = value : integer; 5 | 6 | func T() 7 | begin 8 | A[] = TRUE; 9 | // CHECK: Type error: type integer does not match boolean 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/setter_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | setter A = value : integer; 5 | 6 | func T() 7 | begin 8 | A = TRUE; 9 | // CHECK: Type error: type integer does not match boolean 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/shadowing_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(x : integer) 5 | begin 6 | let x = 42; 7 | // CHECK: Type error: variable `x` previously declared 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/shadowing_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F(x : integer) 5 | begin 6 | var x = 42; 7 | // CHECK: Type error: variable `x` previously declared 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/shadowing_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F{N}(x : bits(N)) 5 | begin 6 | let N = 32; 7 | // CHECK: Type error: variable `N` previously declared 8 | end 9 | -------------------------------------------------------------------------------- /tests/lit/tcheck/shadowing_03.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | var x : integer; 5 | 6 | func F(x : integer) 7 | begin 8 | let x = 42; 9 | // CHECK: Type error: variable `x` previously declared 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/subtypes_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | type TwoHalves of bits(16) { 5 | [7:0] LO 6 | [15:8] HI 7 | }; 8 | 9 | func IsZeroHalf(x : bits(16)) => boolean 10 | begin 11 | // This tests for an old bug where r was given the type of x, not TwoHalves 12 | var r : TwoHalves = x; 13 | return IsZero(r.LO); 14 | end 15 | 16 | func ZeroHalf(x : bits(16)) => TwoHalves 17 | begin 18 | // This tests for an old bug where r was given the type of x, not TwoHalves 19 | var r : TwoHalves = x; 20 | r.LO = Zeros(8); 21 | return r; 22 | end 23 | 24 | func IsZeroHalf_(x : bits(16)) => boolean 25 | begin 26 | // Variant of IsZeroHalf that (pointlessly) casts and then discards x 27 | var _ : TwoHalves = x; 28 | return TRUE; 29 | end 30 | -------------------------------------------------------------------------------- /tests/lit/tcheck/type_constants_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F{A}(A : integer, src : bits(A)) => boolean 5 | begin 6 | var B : integer; 7 | B = A; 8 | return Zeros(A) == Zeros(B); 9 | // CHECK: Type error: type width parameter B does not match A 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/tcheck/type_constraints_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode --check-constraints %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func W(i : integer {0..3}) 5 | begin 6 | end 7 | 8 | func FUT() 9 | begin 10 | for i = 0 to 4 do 11 | W(i); 12 | // CHECK: Type error: `{0..4}` is not a subrange of `{0..3}` 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /tests/lit/tcheck/type_constraints_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --check-constraints %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func W(i : integer {0..3}) 5 | begin 6 | end 7 | 8 | func FUT() 9 | begin 10 | for i = 0 to 3 do 11 | W(i); 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/type_width_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F{A}(A : integer, src : bits(A)) 5 | begin 6 | end 7 | 8 | func Test() 9 | begin 10 | let src = Zeros(10); 11 | F(5, src); 12 | // CHECK: Type error: type width parameter 10 does not match 5 13 | end 14 | -------------------------------------------------------------------------------- /tests/lit/tcheck/type_width_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: not %asli --batchmode %s | filecheck %s 2 | // Copyright (C) 2023-2025 Intel Corporation 3 | 4 | func F{A}(A : integer, src : bits(A)) => boolean 5 | begin 6 | var B : integer; 7 | B = A; 8 | return Zeros(A) == Zeros(B); 9 | // CHECK: Type error: type width parameter B does not match A 10 | end 11 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/decl_fun_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..10}) => integer {0..10} 7 | begin 8 | return x; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5)) => __sint(5) 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return x; 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(FUT(5)); 19 | // CHECK: 5 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_add_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..14}) => integer {0..15} 7 | begin 8 | return x + 1; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5)) => __sint(5) 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_resize_sintN.0{6, 5}(asl_add_sintN.0{6}(asl_resize_sintN.0{5, 6}(x, 6), asl_resize_sintN.0{2, 6}(i2'x1, 6)), 5); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(FUT(14)); 19 | // CHECK: 15 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_eq_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x == y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_eq_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: FALSE 20 | print(FUT(14, 14)); 21 | // CHECK: TRUE 22 | print(FUT(15, 14)); 23 | // CHECK: FALSE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_ge_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x >= y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_ge_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: FALSE 20 | print(FUT(14, 14)); 21 | // CHECK: TRUE 22 | print(FUT(15, 14)); 23 | // CHECK: TRUE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_gt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x > y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_gt_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: FALSE 20 | print(FUT(14, 14)); 21 | // CHECK: FALSE 22 | print(FUT(15, 14)); 23 | // CHECK: TRUE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_if_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | // Copyright (C) 2024-2024 Intel Corporation 4 | 5 | func FUT(x : integer {0..8}) => integer {0..255} begin 6 | // The node to be transformed is 'hidden' under a node 7 | // that does not need to be transformed 8 | return if x < 15 then x + 1 else 255; 9 | end 10 | 11 | // Note: the code below could be improved further by not applying 12 | // asl_cvt_sintN_int to both branches of the if-expr. 13 | // We are leaving that improvement for the future. 14 | // 15 | // XFORM-LABEL: func FUT.0{}(x : __sint(5)) => __sint(9) 16 | // XFORM-NEXT: begin 17 | // XFORM-NEXT: return asl_cvt_int_sintN.0{9}((if asl_lt_sintN.0{5}(x, i5'x15) then asl_cvt_sintN_int.0{6}(asl_add_sintN.0{6}(asl_resize_sintN.0{5, 6}(x, 6), asl_resize_sintN.0{2, 6}(i2'x1, 6))) else asl_cvt_sintN_int.0{9}(i9'x255)), 9); 18 | // XFORM-NEXT: end 19 | 20 | func main() => integer 21 | begin 22 | print_int_dec(FUT(8)); 23 | // CHECK: 9 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_if_01.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | // Based on UnsignedSat 7 | func FUT(x : integer) => integer {0..255} 8 | begin 9 | let r = if x >= 256 then 255 10 | elsif x < 0 then 0 11 | else x; 12 | return r as {0..255}; 13 | end 14 | 15 | // Note: the code below could be improved further by not applying 16 | // asl_cvt_sintN_int to both branches of the if-expr. 17 | // We are leaving that improvement for the future. 18 | // 19 | // XFORM-LABEL: func FUT.0{}(x : integer) => __sint(9) 20 | // XFORM-NEXT: begin 21 | // XFORM-NEXT: let r : integer = (if asl_ge_int.0{}(x, asl_cvt_sintN_int.0{10}(i10'x256)) then asl_cvt_sintN_int.0{9}(i9'x255) elsif asl_lt_int.0{}(x, asl_cvt_sintN_int.0{1}(i1'x0)) then asl_cvt_sintN_int.0{1}(i1'x0) else x); 22 | // XFORM-NEXT: return asl_cvt_int_sintN.0{9}(r, 9); 23 | // XFORM-NEXT: end 24 | 25 | func main() => integer 26 | begin 27 | print_int_dec(FUT(-1)); 28 | // CHECK: 0 29 | print_int_dec(FUT(0)); 30 | // CHECK: 0 31 | print_int_dec(FUT(1)); 32 | // CHECK: 1 33 | print_int_dec(FUT(255)); 34 | // CHECK: 255 35 | print_int_dec(FUT(256)); 36 | // CHECK: 255 37 | return 0; 38 | end 39 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_le_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x <= y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_le_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: TRUE 20 | print(FUT(14, 14)); 21 | // CHECK: TRUE 22 | print(FUT(15, 14)); 23 | // CHECK: FALSE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_lt_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x < y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_lt_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: TRUE 20 | print(FUT(14, 14)); 21 | // CHECK: FALSE 22 | print(FUT(15, 14)); 23 | // CHECK: FALSE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_ne_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}, y : integer {0..15}) => boolean 7 | begin 8 | return x != y; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5), y : __sint(5)) => boolean 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_ne_sintN.0{5}(x, y); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print(FUT(13, 14)); 19 | // CHECK: TRUE 20 | print(FUT(14, 14)); 21 | // CHECK: FALSE 22 | print(FUT(15, 14)); 23 | // CHECK: TRUE 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_neg_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..15}) => integer {-15..0} 7 | begin 8 | return -x; 9 | end 10 | 11 | // Note: the analysis is slightly imprecise: a 6-bit negation is performed when 12 | // 5 bits would be sufficient. 13 | // This will probably result in good code though because LLVM is more than 14 | // capable of further refining the size based on the available information. 15 | // XFORM-LABEL: func FUT.0{}(x : __sint(5)) => __sint(5) 16 | // XFORM-NEXT: begin 17 | // XFORM-NEXT: return asl_resize_sintN.0{6, 5}(asl_neg_sintN.0{6}(asl_resize_sintN.0{5, 6}(x, 6)), 5); 18 | // XFORM-NEXT: end 19 | 20 | func main() => integer 21 | begin 22 | print_int_dec(FUT(14)); 23 | // CHECK: -14 24 | return 0; 25 | end 26 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_sint_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : bits(8)) => integer {-128..127} 7 | begin 8 | return asl_cvt_bits_sint(x); 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : bits(8)) => __sint(8) 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_cvt_bits_ssintN.0{8}(x); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(FUT('1110 0111')); println(); 19 | // CHECK: -25 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_sub_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : integer {0..14}) => integer {-1..13} 7 | begin 8 | return x - 1; 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : __sint(5)) => __sint(5) 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_resize_sintN.0{6, 5}(asl_sub_sintN.0{6}(asl_resize_sintN.0{5, 6}(x, 6), asl_resize_sintN.0{2, 6}(i2'x1, 6)), 5); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print_int_dec(FUT(14)); 19 | // CHECK: 13 20 | return 0; 21 | end 22 | 23 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/expr_uint_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | 4 | // Copyright (C) 2024-2024 Intel Corporation 5 | 6 | func FUT(x : bits(8)) => integer {0..255} 7 | begin 8 | return asl_cvt_bits_uint(x); 9 | end 10 | 11 | // XFORM-LABEL: func FUT.0{}(x : bits(8)) => __sint(9) 12 | // XFORM-NEXT: begin 13 | // XFORM-NEXT: return asl_resize_sintN.0{8, 9}(asl_cvt_bits_usintN.0{8}(x), 9); 14 | // XFORM-NEXT: end 15 | 16 | func main() => integer 17 | begin 18 | print_int_hex(FUT('1110 0111')); println(); 19 | // CHECK: 0xe7 20 | return 0; 21 | end 22 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/stmt_for_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | // Copyright (C) 2024-2024 Intel Corporation 4 | 5 | func FUT(x : integer {0..15}) => integer {0..100} 6 | begin 7 | var s : integer {0..100} = 0; 8 | for i : integer {0..15} = 0 to x do 9 | s = (s + i) as {0..100}; 10 | end 11 | return s; 12 | end 13 | 14 | // XFORM: func FUT.0{}(x : __sint(5)) => __sint(8) 15 | // XFORM-NEXT: begin 16 | // XFORM-NEXT: var s : __sint(8) = asl_resize_sintN.0{1, 8}(i1'x0, 8); 17 | // XFORM-NEXT: for i : __sint(6) = asl_resize_sintN.0{1, 6}(i1'x0, 6) to asl_resize_sintN.0{5, 6}(x, 6) do 18 | // XFORM-NEXT: s = asl_resize_sintN.0{9, 8}(asl_add_sintN.0{9}(asl_resize_sintN.0{8, 9}(s, 9), asl_resize_sintN.0{5, 9}(i, 9)), 8); 19 | // XFORM-NEXT: end 20 | // XFORM-NEXT: return s; 21 | // XFORM-NEXT: end 22 | 23 | func main() => integer 24 | begin 25 | print_int_dec(FUT(4)); println(); 26 | // CHECK: 10 27 | return 0; 28 | end 29 | -------------------------------------------------------------------------------- /tests/lit/xform_bounded/stmt_let_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %aslopt -O0 -Obounded %s | filecheck --check-prefix=XFORM %s 2 | // RUN: %aslrun -O0 -Obounded %s | filecheck %s 3 | // Copyright (C) 2024-2024 Intel Corporation 4 | 5 | func FUT(x : integer {0..10}) => integer {0..10} 6 | begin 7 | let y = x; 8 | return y; 9 | end 10 | 11 | // still not what we want to see - look at 'let y ...' 12 | // XFORM: func FUT.0{}(x : __sint(5)) => __sint(5) 13 | // XFORM-NEXT: begin 14 | // XFORM-NEXT: let y : __sint(5) = x; 15 | // XFORM-NEXT: return y; 16 | // XFORM-NEXT: end 17 | 18 | func main() => integer 19 | begin 20 | print(FUT(5)); 21 | // CHECK: 5 22 | return 0; 23 | end 24 | -------------------------------------------------------------------------------- /tests/lit/xform_hoist_lets/test_00.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --exec=:xform_hoist_lets --exec=":show --format=raw FUT" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT(x : bits(32), i : integer {0..32}) => boolean 5 | begin 6 | // The original motivating example - this prevented use 7 | // of a transformation that looked for "IsZero(x[_ +: _])" 8 | return IsZero(__let wd : integer = 32-i __in 9 | __let ix : integer = 31-i __in 10 | x[ix +: wd]); 11 | end 12 | 13 | // CHECK: let wd : integer = asl_sub_int.0{}(32, i); 14 | // CHECK: let ix : integer = asl_sub_int.0{}(31, i); 15 | // CHECK: return IsZero.0{wd}({bits(32)}x[ix +: wd]); 16 | -------------------------------------------------------------------------------- /tests/lit/xform_hoist_lets/test_02.asl: -------------------------------------------------------------------------------- 1 | // RUN: %asli --batchmode --exec=:xform_hoist_lets --exec=":show --format=raw FUT" %s | filecheck %s 2 | // Copyright (C) 2025-2025 Intel Corporation 3 | 4 | func FUT(x : bits(32), i : integer {0..32}) => boolean 5 | begin 6 | // A variant of the original motivating example that prevented use 7 | // of a transformation that looked for "IsZero(x[_ +: _])" 8 | return IsZero(__let wd : integer = 32-i __in 9 | __let ix : integer = 31-i __in 10 | __assert 0 <= ix && ix < 32 __in 11 | __assert 0 <= wd && ix + wd <= 32 __in 12 | x[ix +: wd]); 13 | end 14 | 15 | // CHECK: let wd : integer = asl_sub_int.0{}(32, i); 16 | // CHECK: let ix : integer = asl_sub_int.0{}(31, i); 17 | // CHECK: assert asl_lazy_and_bool.0{}(asl_le_int.0{}(0, ix), asl_lt_int.0{}(ix, 32)); 18 | // CHECK: assert asl_lazy_and_bool.0{}(asl_le_int.0{}(0, wd), asl_le_int.0{}(asl_add_int.0{}(ix, wd), 32)); 19 | // CHECK: return IsZero.0{wd}({bits(32)}x[ix +: wd]); 20 | -------------------------------------------------------------------------------- /tests/scripts/not: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Execute the rest of the command line and invert the error code of the command 3 | 4 | $@ 5 | 6 | if [ $? -ne 0 ] 7 | then 8 | exit 0 9 | else 10 | exit 1 11 | fi 12 | -------------------------------------------------------------------------------- /tests/xform_int_bitslices_test.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************** 2 | * Test integer bitslicing transform 3 | * 4 | * Copyright (C) 2023-2025 Intel Corporation 5 | * SPDX-Licence-Identifier: BSD-3-Clause 6 | ****************************************************************) 7 | 8 | open Test_utils 9 | open LibASL 10 | open Asl_utils 11 | module TC = Tcheck 12 | 13 | (**************************************************************** 14 | * Test integer bitslicing 15 | ****************************************************************) 16 | 17 | let int_bitslice_tests : unit Alcotest.test_case list = 18 | TC.enable_runtime_checks := false; 19 | let prelude = load_test_libraries () in 20 | let globals = TC.env0 in 21 | let expr = test_xform_expr Xform_int_bitslices.xform_expr globals prelude in 22 | [ 23 | ("integer bitslice", `Quick, expr 24 | "var x : integer; var i : integer;" 25 | "x[i +: 8]" 26 | "asl_cvt_int_bits(x, i + 8)[i +: 8]"); 27 | ] 28 | 29 | (**************************************************************** 30 | * Main test harness 31 | ****************************************************************) 32 | 33 | let () = Alcotest.run "transforms" [ 34 | ("int_bitslice", int_bitslice_tests); 35 | ] 36 | 37 | (**************************************************************** 38 | * End 39 | ****************************************************************) 40 | --------------------------------------------------------------------------------