Skip to content
Snippets Groups Projects
Commit e053de04 authored by Nathanael Sandy's avatar Nathanael Sandy
Browse files

feat: init

parents
No related branches found
No related tags found
No related merge requests found
gen.py 0 → 100755
#!/usr/bin/env python3
import subprocess
from pathlib import Path
def gen_test(input_file, output_file):
command = ["choco-opt", input_file]
try:
result = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)
with open(output_file, "w") as f:
f.write("# RUN: choco-opt %s | filecheck %s\n\n")
for line in input_file.open("r"):
f.write(line)
output_lines = result.stdout.split("\n")
f.write(f"\n# CHECK: {output_lines[0]}\n")
for line in output_lines[1:]:
if line.strip():
f.write(f"# CHECK-NEXT: {line}\n")
except subprocess.CalledProcessError as e:
print(f"Error running choco-opt on {input_file}: {e.stderr}")
def main():
input_dir = Path("gen_input")
output_dir = Path("tests")
output_dir.mkdir(exist_ok=True)
for input_file in input_dir.rglob("*.choc"):
relative_path = input_file.relative_to(input_dir)
output_file = output_dir / relative_path
output_file.parent.mkdir(parents=True, exist_ok=True)
gen_test(input_file, output_file)
if __name__ == "__main__":
main()
if 1:
2
elif 3:
4
5
6
elif 7:
8
9
else:
10
if 1:
2
else:
3
----1
5.118208e-01 parser/arithmetic-comparison-ops/associativity/associativity_plus.choc
5.117595e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_div.choc
5.082073e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_eq.choc
5.053337e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_ge.choc
5.061882e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_gt.choc
5.139861e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_is.choc
5.046902e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_le.choc
5.057118e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_lt.choc
5.122099e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_minus.choc
4.929702e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_mod.choc
5.034056e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_mul.choc
5.096266e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_ne.choc
5.129330e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_plus.choc
4.897881e-01 parser/arithmetic-comparison-ops/ops-coverage/single_op_unary_minus.choc
5.057371e-01 parser/arithmetic-comparison-ops/precedence/precedence_eq_plus.choc
5.098288e-01 parser/complex-expressions/index_expr_1d.choc
5.145748e-01 parser/complex-expressions/index_expr_2d.choc
5.182245e-01 parser/complex-expressions/index_expr_nested.choc
5.042067e-01 parser/complex-expressions/list_empty_empty.choc
5.005424e-01 parser/complex-expressions/list_func_call.choc
4.960597e-01 parser/complex-expressions/list_return.choc
5.070467e-01 parser/complex-expressions/list_true_int.choc
5.387931e-01 parser/complex-expressions/mul_minus_div_paren.choc
5.063939e-01 parser/complex-expressions/ops_coverage/single_expr_call.choc
5.160494e-01 parser/complex-expressions/ops_coverage/single_expr_index.choc
5.093033e-01 parser/complex-expressions/ops_coverage/single_expr_list_one_elem.choc
5.181897e-01 parser/complex-expressions/ops_coverage/single_expr_paren.choc
5.125904e-01 parser/complex-expressions/paren_unary.choc
5.570970e-01 parser/complex-expressions/plus_mod_minus_paren.choc
5.003891e-01 parser/complex-expressions/single_expr_empty_list.choc
4.944985e-01 parser/complex-expressions/single_expr_list_two_elem.choc
4.982076e-01 parser/complex-expressions/single_op_index.choc
4.765797e-01 parser/control-flow/ops_coverage/single_stmt_for.choc
4.575741e-01 parser/control-flow/ops_coverage/single_stmt_if.choc
4.822290e-01 parser/control-flow/ops_coverage/single_stmt_while.choc
5.347939e-01 parser/function-prototypes/ops_coverage/func_prototype.choc
5.024347e-01 parser/function-prototypes/ops_coverage/func_prototype_int.choc
5.119181e-01 parser/literals-identifiers/identifier_1.choc
5.018547e-01 parser/literals-identifiers/literals_bool.choc
5.071821e-01 parser/literals-identifiers/literals_int.choc
5.214489e-01 parser/literals-identifiers/literals_none.choc
4.724987e-01 parser/literals-identifiers/literals_string.choc
4.765193e-01 parser/logical-conditional-ops/ops_coverage/single_op_and.choc
5.092218e-01 parser/logical-conditional-ops/ops_coverage/single_op_if.choc
5.286617e-01 parser/logical-conditional-ops/ops_coverage/single_op_not.choc
5.013268e-01 parser/logical-conditional-ops/ops_coverage/single_op_or.choc
4.320197e-01 parser/simple-statements/assign_id_id_false.choc
5.099597e-01 parser/simple-statements/assign_id_id_id_false.choc
5.073256e-01 parser/simple-statements/func_def_double.choc
5.677733e-01 parser/simple-statements/ops_coverage/empty.choc
5.047126e-01 parser/simple-statements/ops_coverage/single_stmt_assign.choc
5.036497e-01 parser/simple-statements/ops_coverage/single_stmt_pass.choc
5.264471e-01 parser/simple-statements/ops_coverage/single_stmt_return_param.choc
5.161912e-01 parser/simple-statements/ops_coverage/single_stmt_return_void.choc
4.909194e-01 parser/syntax-errors/comma-expected/missing_comma_in_call.choc
5.427096e-01 parser/syntax-errors/comma-expected/missing_comma_in_func_parameters.choc
4.932845e-01 parser/syntax-errors/comma-expected/missing_comma_in_list.choc
5.099349e-01 parser/syntax-errors/comparisons-are-not-associative/comparison_ops_nonassoc_after_func.choc
5.137408e-01 parser/syntax-errors/comparisons-are-not-associative/comparison_ops_nonassoc_and_le_eq.choc
5.183909e-01 parser/syntax-errors/comparisons-are-not-associative/comparison_ops_nonassoc_eq_eq.choc
5.185699e-01 parser/syntax-errors/comparisons-are-not-associative/comparison_ops_nonassoc_in_func.choc
5.090930e-01 parser/syntax-errors/expected-expr/expected_expr_and_expr.choc
5.031285e-01 parser/syntax-errors/expected-expr/expected_expr_if_cond.choc
4.990807e-01 parser/syntax-errors/expected-expr/expected_expr_if_expr.choc
5.032365e-01 parser/syntax-errors/expected-expr/expected_expr_index_expr.choc
5.153320e-01 parser/syntax-errors/expected-expr/expected_expr_index_expr_2d.choc
4.907353e-01 parser/syntax-errors/expected-expr/expected_expr_int.choc
4.991534e-01 parser/syntax-errors/expected-expr/expected_expr_list_expr.choc
4.994988e-01 parser/syntax-errors/expected-expr/expected_expr_no_index_expr.choc
5.027122e-01 parser/syntax-errors/expected-expr/expected_expr_not.choc
4.980104e-01 parser/syntax-errors/expected-expr/expected_expr_not_with_comment.choc
5.098841e-01 parser/syntax-errors/expected-expr/expected_expr_unary.choc
4.992497e-01 parser/syntax-errors/indentation/expected_indent_before_block.choc
4.893944e-01 parser/syntax-errors/indentation/expected_indent_func_def.choc
4.812615e-01 parser/syntax-errors/indentation/expected_indent_func_def_vars.choc
5.097244e-01 parser/syntax-errors/no-lhs-in-assignment/expected_expr_before_assign.choc
5.058582e-01 parser/syntax-errors/no-lhs-in-assignment/expected_expr_before_assign_in_func.choc
4.864264e-01 parser/syntax-errors/no-lhs-in-assignment/expected_expr_before_assign_in_func_pass.choc
5.057755e-01 parser/syntax-errors/token-not-found/expected_assign.choc
5.228539e-01 parser/syntax-errors/token-not-found/expected_colon_elif_case.choc
5.025244e-01 parser/syntax-errors/token-not-found/expected_colon_else_case.choc
5.285439e-01 parser/syntax-errors/token-not-found/expected_colon_for_loop.choc
4.955542e-01 parser/syntax-errors/token-not-found/expected_colon_func_def.choc
4.984355e-01 parser/syntax-errors/token-not-found/expected_colon_if_case.choc
5.054832e-01 parser/syntax-errors/token-not-found/expected_colon_if_case_if_case.choc
5.018463e-01 parser/syntax-errors/token-not-found/expected_else_if_expr.choc
5.044348e-01 parser/syntax-errors/token-not-found/expected_identifier_after_global.choc
5.043690e-01 parser/syntax-errors/token-not-found/expected_identifier_after_nonlocal.choc
5.056643e-01 parser/syntax-errors/token-not-found/expected_in_for_loop.choc
5.011740e-01 parser/syntax-errors/token-not-found/expected_lparen_func_def.choc
4.981952e-01 parser/syntax-errors/token-not-found/expected_newline_after_assign.choc
5.055275e-01 parser/syntax-errors/token-not-found/expected_newline_after_simple_stmt.choc
4.978783e-01 parser/syntax-errors/token-not-found/expected_newline_before_block.choc
5.009220e-01 parser/syntax-errors/token-not-found/expected_newline_func_def.choc
4.957197e-01 parser/syntax-errors/token-not-found/expected_rbracket_index_expr.choc
4.977009e-01 parser/syntax-errors/token-not-found/expected_rbracket_list_expr.choc
5.098593e-01 parser/syntax-errors/token-not-found/expected_rparen_func_call.choc
4.874072e-01 parser/syntax-errors/token-not-found/expected_rparen_func_def.choc
4.909143e-01 parser/syntax-errors/token-not-found/expected_rparen_paren_expr.choc
5.009298e-01 parser/syntax-errors/unexpected-indentation/unexpected_indentation.choc
4.744916e-01 parser/syntax-errors/unexpected-indentation/unexpected_indentation_def.choc
5.071018e-01 parser/syntax-errors/unexpected-indentation/unexpected_indentation_def_stmt.choc
5.263102e-01 parser/syntax-errors/unexpected-indentation/unexpected_indentation_if_stmt.choc
5.046337e-01 parser/syntax-errors/unexpected-indentation/unexpected_indentation_stmts.choc
5.226262e-01 parser/syntax-errors/unknown-type/unknown_type_func_param.choc
5.083461e-01 parser/syntax-errors/unknown-type/unknown_type_list.choc
5.069168e-01 parser/syntax-errors/unknown-type/unknown_type_var_def.choc
5.007944e-01 parser/syntax-errors/unknown-type/unknown_type_var_def_in_func.choc
4.865468e-01 parser/syntax-errors/unmatched-parenthesis/unmatched-parenthesis.choc
5.099213e-01 parser/syntax-errors/variable_defined_later/variable_defined_later.choc
5.000796e-01 parser/syntax-errors/variable_defined_later/variable_defined_later_in_func.choc
5.174193e-01 parser/variable-defs-decls/ops_coverage/single_stmt_global.choc
5.142560e-01 parser/variable-defs-decls/ops_coverage/single_stmt_global_var_def_int.choc
5.123174e-01 parser/variable-defs-decls/ops_coverage/single_stmt_global_var_def_list.choc
5.196404e-01 parser/variable-defs-decls/ops_coverage/single_stmt_nonlocal.choc
5.183003e-01 parser/variable-defs-decls/ops_coverage/var_def_func_def_var_def.choc
5.060186e-01 parser/variable-defs-decls/ops_coverage/var_def_pass.choc
5.209243e-01 parser/variable-defs-decls/ops_coverage/vardef_global.choc
1.056824e-01 lexer/arithmetic.choc
1.184392e-01 lexer/brackets.choc
1.097331e-01 lexer/division.choc
1.657386e-01 lexer/end_with_comment.choc
1.138530e-01 lexer/eq.choc
1.646421e-01 lexer/func_def_double.choc
1.337495e-01 lexer/func_def_func_def_func_def_pass.choc
1.252079e-01 lexer/func_prototype_1.choc
1.133575e-01 lexer/ge.choc
9.458184e-02 lexer/global_def_single.choc
1.497536e-01 lexer/gt.choc
1.311536e-01 lexer/if_elif_else.choc
1.165280e-01 lexer/is.choc
1.185534e-01 lexer/le.choc
1.136291e-01 lexer/literals.choc
1.203423e-01 lexer/logical_ops.choc
9.991956e-02 lexer/lt.choc
1.559887e-01 lexer/minus.choc
1.208224e-01 lexer/modulo.choc
1.196918e-01 lexer/multiplication.choc
1.140716e-01 lexer/ne.choc
1.237307e-01 lexer/nonlocal_single.choc
1.177039e-01 lexer/pass.choc
1.299789e-01 lexer/plus.choc
1.235771e-01 lexer/return.choc
1.396360e-01 lexer/tab_identifiers.choc
1.154523e-01 lexer/types_1.choc
1.136000e-01 lexer/var_def_1.choc
1.183047e-01 lexer/var_def_func_def_double.choc
1.141262e-01 lexer/var_def_func_def_var_def.choc
1.124785e-01 lexer/var_def_func_def_var_def_func_def.choc
1.138523e-01 lexer/while_for.choc
import lit.formats
import os
config.name = "ChocoPy"
config.test_format = lit.formats.ShTest()
config.suffixes = ['.test', '.choc', '.s', '.mlir']
config.test_source_root = os.path.dirname(__file__)
if "PYTHONPATH" in os.environ.keys():
config.environment["PYTHONPATH"] = config.test_source_root + "/../:" + os.environ["PYTHONPATH"]
else:
config.environment["PYTHONPATH"] = config.test_source_root + "/../"
config.environment["PATH"] = config.test_source_root + "/../tools/:" + os.environ["PATH"]
config.available_features = []
if sys.version_info[0] == 3 and sys.version_info[1] == 10:
config.available_features.append('python310')
# RUN: choco-opt %s | filecheck %s
0 + 1 + 2
# CHECK: builtin.module {
# CHECK-NEXT: "choco.ast.program"() ({
# CHECK-NEXT: ^0:
# CHECK-NEXT: }, {
# CHECK-NEXT: "choco.ast.binary_expr"() <{"op" = "+"}> ({
# CHECK-NEXT: "choco.ast.binary_expr"() <{"op" = "+"}> ({
# CHECK-NEXT: "choco.ast.literal"() <{"value" = 0 : i32}> : () -> ()
# CHECK-NEXT: }, {
# CHECK-NEXT: "choco.ast.literal"() <{"value" = 1 : i32}> : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }, {
# CHECK-NEXT: "choco.ast.literal"() <{"value" = 2 : i32}> : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }
# RUN: choco-opt %s | filecheck %s
----1
# CHECK: builtin.module {
# CHECK-NEXT: "choco.ast.program"() ({
# CHECK-NEXT: ^0:
# CHECK-NEXT: }, {
# CHECK-NEXT: "choco.ast.unary_expr"() <{"op" = "-"}> ({
# CHECK-NEXT: "choco.ast.unary_expr"() <{"op" = "-"}> ({
# CHECK-NEXT: "choco.ast.unary_expr"() <{"op" = "-"}> ({
# CHECK-NEXT: "choco.ast.unary_expr"() <{"op" = "-"}> ({
# CHECK-NEXT: "choco.ast.literal"() <{"value" = 1 : i32}> : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }) : () -> ()
# CHECK-NEXT: }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment