From 0976f4907c08949f1fe3b11382b0626dc468c342 Mon Sep 17 00:00:00 2001 From: rina Date: Thu, 26 Feb 2026 18:12:56 +1000 Subject: [PATCH 01/43] blah --- lib/fe/AbsBasilIR.ml | 2 +- lib/fe/BNFC_Util.ml | 2 +- lib/fe/LexBasilIR.mll | 2 +- lib/fe/ParBasilIR.mly | 2 +- lib/fe/PrintBasilIR.ml | 2 +- lib/fe/ShowBasilIR.ml | 2 +- lib/fe/SkelBasilIR.ml | 2 +- lib/fe/TestBasilIR.ml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 6868acb7..15df082e 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) type bVTYPE = BVTYPE of ((int * int) * string) and iNTTYPE = INTTYPE of ((int * int) * string) diff --git a/lib/fe/BNFC_Util.ml b/lib/fe/BNFC_Util.ml index 6d3bb604..19303111 100644 --- a/lib/fe/BNFC_Util.ml +++ b/lib/fe/BNFC_Util.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) open Lexing diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 03c476e0..2847e63d 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) (* Lexer definition for ocamllex. *) diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index bd2211fc..fcd66e07 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -1,4 +1,4 @@ -/* File generated by the BNF Converter (bnfc 2.9.6.1). */ +/* File generated by the BNF Converter (bnfc 2.9.6.2). */ /* Parser definition for use with menhir */ diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 71da2133..3a6e7e43 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) (* pretty-printer *) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 4e8e4d74..4d336bef 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) (* show functions *) diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 1c6203ff..9e3b57f6 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) module SkelBasilIR = struct diff --git a/lib/fe/TestBasilIR.ml b/lib/fe/TestBasilIR.ml index db9dbc6e..e3da9490 100644 --- a/lib/fe/TestBasilIR.ml +++ b/lib/fe/TestBasilIR.ml @@ -1,4 +1,4 @@ -(* File generated by the BNF Converter (bnfc 2.9.6.1). *) +(* File generated by the BNF Converter (bnfc 2.9.6.2). *) open Lexing From 2d5223bd98cc6cd622789be57241a88bc09edf75 Mon Sep 17 00:00:00 2001 From: rina Date: Thu, 26 Feb 2026 18:20:18 +1000 Subject: [PATCH 02/43] dune --- tree-sitter/dune | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tree-sitter/dune diff --git a/tree-sitter/dune b/tree-sitter/dune new file mode 100644 index 00000000..009a26c1 --- /dev/null +++ b/tree-sitter/dune @@ -0,0 +1,10 @@ +(rule + (deps %{project_root}/lib/fe/BasilIR.cf) + (enabled_if %{env:BINCAML_BNFC_TREESITTER=false}) + (targets grammar.js) + (mode promote) + (action + (progn + (copy %{deps} basilir.cf) + (run bnfc --tree-sitter basilir.cf) + (copy tree-sitter-basilir/grammar.js grammar.js)))) From 4c606589185e3d5ea0419dd2c3f971f005118311 Mon Sep 17 00:00:00 2001 From: rina Date: Thu, 26 Feb 2026 19:29:27 +1000 Subject: [PATCH 03/43] upd8. GRAMMAR IS UNAMBIGUOUS :( --- tree-sitter/dune | 5 +- tree-sitter/grammar.js | 299 +++++++++++++++++++++++++++++++---------- 2 files changed, 228 insertions(+), 76 deletions(-) diff --git a/tree-sitter/dune b/tree-sitter/dune index 009a26c1..85956c62 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -6,5 +6,6 @@ (action (progn (copy %{deps} basilir.cf) - (run bnfc --tree-sitter basilir.cf) - (copy tree-sitter-basilir/grammar.js grammar.js)))) + (run bnfc --tree-sitter --tree-sitter-word LocalIdent basilir.cf --makefile) + (run make -C tree-sitter-basilir) ; check tree-sitter is valid and unambiguous + (no-infer (copy tree-sitter-basilir/grammar.js grammar.js))))) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 0a2a71e7..a1cf0d89 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -4,8 +4,8 @@ module.exports = grammar({ name: "basilir", extras: $ =>[ /\s/, - /\/\/.*\n/, - /\/\*[^*]*\*([^\*\/][^*]*\*|\*)*\//, + $.token_CommentSingle, + $.token_CommentMulti, ], word: $ => $.token_LocalIdent, rules: { @@ -33,6 +33,13 @@ module.exports = grammar({ // (:). [BlockIdent] ::= BlockIdent "," [BlockIdent] ; seq($.token_BlockIdent, ",", optional($.list_token_BlockIdent)) ), + LambdaSep: $ => + choice( + // LambdaSep1. LambdaSep ::= "->" ; + "->", + // LambdaSep2. LambdaSep ::= "::" ; + "::" + ), Semicolons: $ => choice( // Semicolons_Empty. Semicolons ::= ; @@ -40,26 +47,40 @@ module.exports = grammar({ // Semicolons_Some. Semicolons ::= Semicolons ";" ; seq(optional($.Semicolons), ";") ), + VarModifiers: $ => + choice( + // Shared. VarModifiers ::= "shared" ; + "shared", + // Observable. VarModifiers ::= "observable" ; + "observable" + ), + list_VarModifiers: $ => + choice( + // []. [VarModifiers] ::= ; + choice(), + // (:). [VarModifiers] ::= VarModifiers [VarModifiers] ; + seq($.VarModifiers, optional($.list_VarModifiers)) + ), Decl: $ => choice( - // Decl_Axiom. Decl ::= "axiom" AttribSet Expr ; - seq("axiom", optional($.AttribSet), $.Expr), - // Decl_SharedMem. Decl ::= "memory" "shared" GlobalIdent ":" Type ; - seq("memory", "shared", $.token_GlobalIdent, ":", $.Type), - // Decl_UnsharedMem. Decl ::= "memory" GlobalIdent ":" Type ; - seq("memory", $.token_GlobalIdent, ":", $.Type), - // Decl_Var. Decl ::= "var" GlobalIdent ":" Type ; - seq("var", $.token_GlobalIdent, ":", $.Type), - // Decl_UninterpFun. Decl ::= "declare-fun" AttribSet GlobalIdent ":" "(" [Type] ")" "->" Type ; - seq("declare-fun", optional($.AttribSet), $.token_GlobalIdent, ":", "(", optional($.list_Type), ")", "->", $.Type), - // Decl_Fun. Decl ::= "define-fun" AttribSet GlobalIdent "(" [Params] ")" "->" Type "=" Expr ; - seq("define-fun", optional($.AttribSet), $.token_GlobalIdent, "(", optional($.list_Params), ")", "->", $.Type, "=", $.Expr), + // Decl_Axiom. Decl ::= "axiom" GlobalIdent AttribSet Expr ; + seq("axiom", $.token_GlobalIdent, optional($.AttribSet), $.Expr), + // Decl_Mem. Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ; + seq("memory", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), + // Decl_Var. Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ; + seq("var", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), + // Decl_UninterpFun. Decl ::= "val" GlobalIdent AttribSet ":" Type ; + seq("val", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type), + // Decl_Fun. Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, "=", $.Expr), + // Decl_FunNoType. Decl ::= "let" GlobalIdent AttribSet "=" Expr ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), "=", $.Expr), // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), - // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet BeginList [ProgSpec] EndList ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.token_BeginList, optional($.list_ProgSpec), $.token_EndList), - // Decl_Proc. Decl ::= "proc" ProcIdent "(" [Params] ")" "->" "(" [Params] ")" AttribSet [FunSpec] ProcDef ; - seq("proc", $.token_ProcIdent, "(", optional($.list_Params), ")", "->", "(", optional($.list_Params), ")", optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) + // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), + // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; + seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), list_Type: $ => choice( @@ -84,8 +105,8 @@ module.exports = grammar({ // BoolType1. BoolType ::= BOOLTYPE ; $.token_BOOLTYPE, MapType: $ => - // MapType1. MapType ::= "(" Type "->" Type ")" ; - seq("(", $.Type, "->", $.Type, ")"), + // MapType1. MapType ::= Type "->" Type ; + seq($.Type, "->", $.Type), BVType: $ => // BVType1. BVType ::= BVTYPE ; $.token_BVTYPE, @@ -98,7 +119,9 @@ module.exports = grammar({ // TypeMapType. Type ::= MapType ; $.MapType, // TypeBVType. Type ::= BVType ; - $.BVType + $.BVType, + // Type1. Type ::= OpenParen Type CloseParen ; + seq($.token_OpenParen, $.Type, $.token_CloseParen) ), list_Expr: $ => choice( @@ -135,8 +158,14 @@ module.exports = grammar({ "nop", // Stmt_SingleAssign. Stmt ::= Assignment ; $.Assignment, - // Stmt_MultiAssign. Stmt ::= "(" [Assignment] ")" ; - seq("(", $.list_Assignment, ")"), + // Stmt_MemAssign. Stmt ::= LVar "mem:=" Expr ; + seq($.LVar, "mem:=", $.Expr), + // Stmt_ScalarStore. Stmt ::= LVar ":=" "store" Expr ; + seq($.LVar, ":=", "store", $.Expr), + // Stmt_ScalarLoad. Stmt ::= LVar ":=" "load" Var ; + seq($.LVar, ":=", "load", $.Var), + // Stmt_MultiAssign. Stmt ::= OpenParen [Assignment] CloseParen ; + seq($.token_OpenParen, $.list_Assignment, $.token_CloseParen), // Stmt_Load. Stmt ::= LVar ":=" "load" Endian GlobalIdent Expr IntVal ; seq($.LVar, ":=", "load", $.Endian, $.token_GlobalIdent, $.Expr, $.IntVal), // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal ; @@ -145,8 +174,8 @@ module.exports = grammar({ seq($.LVar, ":=", "load", $.Endian, $.Var, $.Expr, $.IntVal), // Stmt_Store_Var. Stmt ::= LVar ":=" "store" Endian Var Expr Expr IntVal ; seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr, $.Expr, $.IntVal), - // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent "(" CallParams ")" ; - seq(optional($.LVars), "call", $.token_ProcIdent, "(", optional($.CallParams), ")"), + // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent OpenParen CallParams CloseParen ; + seq(optional($.LVars), "call", $.token_ProcIdent, $.token_OpenParen, optional($.CallParams), $.token_CloseParen), // Stmt_IndirectCall. Stmt ::= "indirect" "call" Expr ; seq("indirect", "call", $.Expr), // Stmt_Assume. Stmt ::= "assume" Expr ; @@ -164,11 +193,19 @@ module.exports = grammar({ seq($.Assignment, ",", $.list_Assignment) ), LocalVar: $ => - // LocalVar1. LocalVar ::= LocalIdent ":" Type ; - seq($.token_LocalIdent, ":", $.Type), + choice( + // LocalTyped. LocalVar ::= LocalIdent ":" Type ; + seq($.token_LocalIdent, ":", $.Type), + // LocalUntyped. LocalVar ::= LocalIdent ; + $.token_LocalIdent + ), GlobalVar: $ => - // GlobalVar1. GlobalVar ::= GlobalIdent ":" Type ; - seq($.token_GlobalIdent, ":", $.Type), + choice( + // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type ; + seq($.token_GlobalIdent, ":", $.Type), + // GlobalUntyped. GlobalVar ::= GlobalIdent ; + $.token_GlobalIdent + ), list_LocalVar: $ => choice( // (:[]). [LocalVar] ::= LocalVar ; @@ -183,6 +220,15 @@ module.exports = grammar({ // VarGlobalVar. Var ::= GlobalVar ; $.GlobalVar ), + list_GlobalVar: $ => + choice( + // []. [GlobalVar] ::= ; + choice(), + // (:[]). [GlobalVar] ::= GlobalVar ; + $.GlobalVar, + // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; + seq($.GlobalVar, ",", optional($.list_GlobalVar)) + ), NamedCallReturn: $ => // NamedCallReturn1. NamedCallReturn ::= LVar "=" LocalIdent ; seq($.LVar, "=", $.token_LocalIdent), @@ -199,12 +245,12 @@ module.exports = grammar({ choice( // LVars_Empty. LVars ::= ; choice(), - // LVars_LocalList. LVars ::= "var" "(" [LocalVar] ")" ":=" ; - seq("var", "(", $.list_LocalVar, ")", ":="), - // LVars_List. LVars ::= "(" [LVar] ")" ":=" ; - seq("(", $.list_LVar, ")", ":="), - // NamedLVars_List. LVars ::= "(" [NamedCallReturn] ")" ":=" ; - seq("(", optional($.list_NamedCallReturn), ")", ":=") + // LVars_LocalList. LVars ::= "var" OpenParen [LocalVar] CloseParen ":=" ; + seq("var", $.token_OpenParen, $.list_LocalVar, $.token_CloseParen, ":="), + // LVars_List. LVars ::= OpenParen [LVar] CloseParen ":=" ; + seq($.token_OpenParen, $.list_LVar, $.token_CloseParen, ":="), + // NamedLVars_List. LVars ::= OpenParen [NamedCallReturn] CloseParen ":=" ; + seq($.token_OpenParen, optional($.list_NamedCallReturn), $.token_CloseParen, ":=") ), NamedCallArg: $ => // NamedCallArg1. NamedCallArg ::= LocalIdent "=" Expr ; @@ -227,12 +273,12 @@ module.exports = grammar({ ), Jump: $ => choice( - // Jump_GoTo. Jump ::= "goto" "(" [BlockIdent] ")" ; - seq("goto", "(", optional($.list_token_BlockIdent), ")"), + // Jump_GoTo. Jump ::= "goto" OpenParen [BlockIdent] CloseParen ; + seq("goto", $.token_OpenParen, optional($.list_token_BlockIdent), $.token_CloseParen), // Jump_Unreachable. Jump ::= "unreachable" ; "unreachable", - // Jump_Return. Jump ::= "return" "(" [Expr] ")" ; - seq("return", "(", optional($.list_Expr), ")"), + // Jump_Return. Jump ::= "return" OpenParen [Expr] CloseParen ; + seq("return", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), // Jump_ProcReturn. Jump ::= "return" ; "return" ), @@ -285,8 +331,8 @@ module.exports = grammar({ seq($.PhiExpr, ",", optional($.list_PhiExpr)) ), PhiAssign: $ => - // PhiAssign1. PhiAssign ::= LVar ":=" "phi" "(" [PhiExpr] ")" ; - seq($.LVar, ":=", "phi", "(", optional($.list_PhiExpr), ")"), + // PhiAssign1. PhiAssign ::= LVar ":=" "phi" OpenParen [PhiExpr] CloseParen ; + seq($.LVar, ":=", "phi", $.token_OpenParen, optional($.list_PhiExpr), $.token_CloseParen), list_PhiAssign: $ => choice( // []. [PhiAssign] ::= ; @@ -300,8 +346,8 @@ module.exports = grammar({ choice( // Block_NoPhi. Block ::= "block" BlockIdent AttribSet BeginList [StmtWithAttrib] JumpWithAttrib ";" EndList ; seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_BeginList, optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList), - // Block_Phi. Block ::= "block" BlockIdent AttribSet BeginList "(" [PhiAssign] ")" ";" [StmtWithAttrib] JumpWithAttrib ";" EndList ; - seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_BeginList, "(", optional($.list_PhiAssign), ")", ";", optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList) + // Block_Phi. Block ::= "block" BlockIdent AttribSet BeginList OpenParen [PhiAssign] CloseParen ";" [StmtWithAttrib] JumpWithAttrib ";" EndList ; + seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_BeginList, $.token_OpenParen, optional($.list_PhiAssign), $.token_CloseParen, ";", optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList) ), AttrKeyValue: $ => // AttrKeyValue1. AttrKeyValue ::= BIdent "=" Attr ; @@ -317,8 +363,8 @@ module.exports = grammar({ ), AttribSet: $ => choice( - // AttribSet_Some. AttribSet ::= BeginRec [AttrKeyValue] EndRec ; - seq($.token_BeginRec, optional($.list_AttrKeyValue), $.token_EndRec), + // AttribSet_Some. AttribSet ::= BeginRec [AttrKeyValue] Semicolons EndRec ; + seq($.token_BeginRec, optional($.list_AttrKeyValue), optional($.Semicolons), $.token_EndRec), // AttribSet_Empty. AttribSet ::= ; choice() ), @@ -333,12 +379,14 @@ module.exports = grammar({ ), Attr: $ => choice( - // Attr_Map. Attr ::= BeginRec [AttrKeyValue] EndRec ; - seq($.token_BeginRec, optional($.list_AttrKeyValue), $.token_EndRec), + // Attr_Map. Attr ::= BeginRec [AttrKeyValue] Semicolons EndRec ; + seq($.token_BeginRec, optional($.list_AttrKeyValue), optional($.Semicolons), $.token_EndRec), // Attr_List. Attr ::= BeginList [Attr] EndList ; seq($.token_BeginList, optional($.list_Attr), $.token_EndList), // Attr_Lit. Attr ::= Value ; $.Value, + // Attr_Expr. Attr ::= Expr ; + $.Expr, // Attr_Str. Attr ::= Str ; $.token_Str ), @@ -354,6 +402,20 @@ module.exports = grammar({ // (:). [Params] ::= Params "," [Params] ; seq($.Params, ",", optional($.list_Params)) ), + FunParams: $ => + choice( + // FunParams1. FunParams ::= LocalIdent ":" Type ; + seq($.token_LocalIdent, ":", $.Type), + // FunParams2. FunParams ::= OpenParen LocalIdent ":" Type CloseParen ; + seq($.token_OpenParen, $.token_LocalIdent, ":", $.Type, $.token_CloseParen) + ), + list_FunParams: $ => + choice( + // []. [FunParams] ::= ; + choice(), + // (:). [FunParams] ::= FunParams [FunParams] ; + seq($.FunParams, optional($.list_FunParams)) + ), Value: $ => choice( // Value_BV. Value ::= BVVal ; @@ -369,42 +431,74 @@ module.exports = grammar({ choice( // Expr_Literal. Expr ::= Value ; $.Value, + // Expr_Paren. Expr ::= OpenParen Expr CloseParen ; + seq($.token_OpenParen, $.Expr, $.token_CloseParen), // Expr_Local. Expr ::= LocalVar ; $.LocalVar, // Expr_Global. Expr ::= GlobalVar ; $.GlobalVar, - // Expr_Forall. Expr ::= "forall" LambdaDef ; - seq("forall", $.LambdaDef), - // Expr_Exists. Expr ::= "exists" LambdaDef ; - seq("exists", $.LambdaDef), - // Expr_Old. Expr ::= "old" "(" Expr ")" ; - seq("old", "(", $.Expr, ")"), - // Expr_FunctionOp. Expr ::= GlobalIdent "(" [Expr] ")" ; - seq($.token_GlobalIdent, "(", optional($.list_Expr), ")"), - // Expr_Binary. Expr ::= BinOp "(" Expr "," Expr ")" ; - seq($.BinOp, "(", $.Expr, ",", $.Expr, ")"), - // Expr_Assoc. Expr ::= BoolBinOp "(" [Expr] ")" ; - seq($.BoolBinOp, "(", optional($.list_Expr), ")"), - // Expr_Unary. Expr ::= UnOp "(" Expr ")" ; - seq($.UnOp, "(", $.Expr, ")"), - // Expr_ZeroExtend. Expr ::= "zero_extend" "(" IntVal "," Expr ")" ; - seq("zero_extend", "(", $.IntVal, ",", $.Expr, ")"), - // Expr_SignExtend. Expr ::= "sign_extend" "(" IntVal "," Expr ")" ; - seq("sign_extend", "(", $.IntVal, ",", $.Expr, ")"), - // Expr_Extract. Expr ::= "extract" "(" IntVal "," IntVal "," Expr ")" ; - seq("extract", "(", $.IntVal, ",", $.IntVal, ",", $.Expr, ")"), - // Expr_Concat. Expr ::= "bvconcat" "(" [Expr] ")" ; - seq("bvconcat", "(", optional($.list_Expr), ")") + // Expr_Forall. Expr ::= "forall" AttribSet LambdaDef ; + seq("forall", optional($.AttribSet), $.LambdaDef), + // Expr_Exists. Expr ::= "exists" AttribSet LambdaDef ; + seq("exists", optional($.AttribSet), $.LambdaDef), + // Expr_Lambda. Expr ::= "fun" AttribSet LambdaDef ; + seq("fun", optional($.AttribSet), $.LambdaDef), + // Expr_Old. Expr ::= "old" OpenParen Expr CloseParen ; + seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_FunctionOp. Expr ::= GlobalIdent OpenParen [Expr] CloseParen ; + seq($.token_GlobalIdent, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Apply. Expr ::= Expr Expr ; + seq($.Expr, $.Expr), + // Expr_Binary. Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; + seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_Assoc. Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; + seq($.BoolBinOp, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Unary. Expr ::= UnOp OpenParen Expr CloseParen ; + seq($.UnOp, $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_LoadBe. Expr ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_be", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_LoadLe. Expr ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_le", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_ZeroExtend. Expr ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; + seq("zero_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_SignExtend. Expr ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; + seq("sign_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Extract. Expr ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; + seq("extract", $.token_OpenParen, $.IntVal, ",", $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Concat. Expr ::= "bvconcat" OpenParen [Expr] CloseParen ; + seq("bvconcat", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Match. Expr ::= "match" Expr "with" OpenParen [Case] CloseParen ; + seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), + // Expr_Cases. Expr ::= "cases" OpenParen [Case] CloseParen ; + seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) + ), + LParen: $ => + choice( + // LParenLocalVar. LParen ::= LocalVar ; + $.LocalVar, + // LParen1. LParen ::= OpenParen LocalVar CloseParen ; + seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) + ), + list_LParen: $ => + choice( + // []. [LParen] ::= ; + choice(), + // (:[]). [LParen] ::= LParen ; + $.LParen, + // (:). [LParen] ::= LParen "," [LParen] ; + seq($.LParen, ",", optional($.list_LParen)) ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= "(" [LocalVar] ")" LambdaSep Expr ; - seq("(", $.list_LocalVar, ")", $.token_LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LParen] LambdaSep Expr ; + seq(optional($.list_LParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; $.BVBinOp, // BinOpBVLogicalBinOp. BinOp ::= BVLogicalBinOp ; $.BVLogicalBinOp, + // BinOpBoolBinOp. BinOp ::= BoolBinOp ; + $.BoolBinOp, // BinOpIntLogicalBinOp. BinOp ::= IntLogicalBinOp ; $.IntLogicalBinOp, // BinOpIntBinOp. BinOp ::= IntBinOp ; @@ -421,7 +515,27 @@ module.exports = grammar({ // UnOp_intneg. UnOp ::= "intneg" ; "intneg", // UnOp_booltobv1. UnOp ::= "booltobv1" ; - "booltobv1" + "booltobv1", + // UnOp_gamma. UnOp ::= "gamma" ; + "gamma", + // UnOp_classification. UnOp ::= "classification" ; + "classification" + ), + Case: $ => + choice( + // CaseCase. Case ::= Expr "->" Expr ; + seq($.Expr, "->", $.Expr), + // CaseDefault. Case ::= "_" "->" Expr ; + seq("_", "->", $.Expr) + ), + list_Case: $ => + choice( + // []. [Case] ::= ; + choice(), + // (:[]). [Case] ::= Case ; + $.Case, + // (:). [Case] ::= Case "|" [Case] ; + seq($.Case, "|", optional($.list_Case)) ), EqOp: $ => choice( @@ -542,15 +656,44 @@ module.exports = grammar({ // EnsureTok_ensures. EnsureTok ::= "ensures" ; "ensures" ), + RelyTok: $ => + choice( + // RelyTok_rely. RelyTok ::= "rely" ; + "rely", + // RelyTok_relies. RelyTok ::= "relies" ; + "relies" + ), + GuarTok: $ => + choice( + // GuarTok_guarnatee. GuarTok ::= "guarnatee" ; + "guarnatee", + // GuarTok_guarantees. GuarTok ::= "guarantees" ; + "guarantees" + ), FunSpec: $ => choice( // FunSpec_Require. FunSpec ::= RequireTok Expr ; seq($.RequireTok, $.Expr), // FunSpec_Ensure. FunSpec ::= EnsureTok Expr ; seq($.EnsureTok, $.Expr), + // FunSpec_Rely. FunSpec ::= RelyTok Expr ; + seq($.RelyTok, $.Expr), + // FunSpec_Guar. FunSpec ::= GuarTok Expr ; + seq($.GuarTok, $.Expr), + // FunSpec_Captures. FunSpec ::= "captures" [GlobalVar] ; + seq("captures", optional($.list_GlobalVar)), + // FunSpec_Modifies. FunSpec ::= "modifies" [GlobalVar] ; + seq("modifies", optional($.list_GlobalVar)), // FunSpec_Invariant. FunSpec ::= "invariant" BlockIdent Expr ; seq("invariant", $.token_BlockIdent, $.Expr) ), + VarSpec: $ => + choice( + // VarSpec_Classification. VarSpec ::= "classification" Expr ; + seq("classification", $.Expr), + // VarSpec_Empty. VarSpec ::= ; + choice() + ), ProgSpec: $ => choice( // ProgSpec_Rely. ProgSpec ::= "rely" Expr ; @@ -569,6 +712,8 @@ module.exports = grammar({ choice( // []. [ProgSpec] ::= ; choice(), + // (:[]). [ProgSpec] ::= ProgSpec ; + $.ProgSpec, // (:). [ProgSpec] ::= ProgSpec ";" [ProgSpec] ; seq($.ProgSpec, ";", optional($.list_ProgSpec)) ), @@ -588,6 +733,10 @@ module.exports = grammar({ /%([#\$\._]|(\d|[a-zA-Z]))+/, token_ProcIdent: $ => /@([#\$\._]|(\d|[a-zA-Z]))+/, + token_OpenParen: $ => + /\(/, + token_CloseParen: $ => + /\)/, token_BeginList: $ => /\[/, token_EndList: $ => @@ -596,13 +745,15 @@ module.exports = grammar({ /\{/, token_EndRec: $ => /\}/, - token_LambdaSep: $ => - /::|->/, token_Str: $ => /"([^"\\]|\\["\\fnrt])*"/, token_IntegerHex: $ => /0x([abcdef]|\d)+/, token_IntegerDec: $ => /\d+/, + token_CommentSingle: $ => + /\/\/.*\n/, + token_CommentMulti: $ => + /\/\*[^*]*\*([^\*\/][^*]*\*|\*)*\//, }, }); From 78a33033cb75dde4f4fea87ca59f396ffc33a492 Mon Sep 17 00:00:00 2001 From: rina Date: Thu, 26 Feb 2026 19:45:35 +1000 Subject: [PATCH 04/43] check in separate rule --- tree-sitter/dune | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tree-sitter/dune b/tree-sitter/dune index 85956c62..95b0071c 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -7,5 +7,12 @@ (progn (copy %{deps} basilir.cf) (run bnfc --tree-sitter --tree-sitter-word LocalIdent basilir.cf --makefile) - (run make -C tree-sitter-basilir) ; check tree-sitter is valid and unambiguous (no-infer (copy tree-sitter-basilir/grammar.js grammar.js))))) + +; checks tree-sitter is valid and unambiguous +(rule + (deps grammar.js) + (alias runtest) + (enabled_if %{bin-available:tree-sitter}) + (action + (run tree-sitter generate grammar.js))) From 3603960e9a110541f995cf3105be0ed85c718985 Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 14:31:26 +1000 Subject: [PATCH 05/43] diff in runtest, not on build --- tree-sitter/dune | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tree-sitter/dune b/tree-sitter/dune index 95b0071c..1eb21e32 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -1,14 +1,3 @@ -(rule - (deps %{project_root}/lib/fe/BasilIR.cf) - (enabled_if %{env:BINCAML_BNFC_TREESITTER=false}) - (targets grammar.js) - (mode promote) - (action - (progn - (copy %{deps} basilir.cf) - (run bnfc --tree-sitter --tree-sitter-word LocalIdent basilir.cf --makefile) - (no-infer (copy tree-sitter-basilir/grammar.js grammar.js))))) - ; checks tree-sitter is valid and unambiguous (rule (deps grammar.js) @@ -16,3 +5,15 @@ (enabled_if %{bin-available:tree-sitter}) (action (run tree-sitter generate grammar.js))) + +; check that grammar.js is up to date. +; requires `bnfc-treesitter` from pac-nix. +(rule + (alias runtest) + (deps %{project_root}/lib/fe/BasilIR.cf) + (enabled_if %{bin-available:bnfc}) + (action + (progn + (copy %{deps} basilir.cf) + (run bnfc --tree-sitter --tree-sitter-word LocalIdent basilir.cf --makefile) + (diff? grammar.js tree-sitter-basilir/grammar.js)))) From 965070738fdde8381e4e59deb6cf472aaab3facc Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 15:31:07 +1000 Subject: [PATCH 06/43] always use parentheses application. remove BoolBinOp from BinExpr fixes some but not all ambiguity --- lib/fe/AbsBasilIR.ml | 12 +++--------- lib/fe/BasilIR.cf | 16 ++++++---------- lib/fe/ParBasilIR.mly | 21 +++++---------------- lib/fe/PrintBasilIR.ml | 13 +++---------- lib/fe/ShowBasilIR.ml | 13 +++---------- lib/fe/SkelBasilIR.ml | 13 +++---------- lib/loadir.ml | 18 +++++------------- tree-sitter/grammar.js | 29 ++++++++--------------------- 8 files changed, 36 insertions(+), 99 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 15df082e..263fe534 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -24,10 +24,6 @@ and lambdaSep = LambdaSep1 | LambdaSep2 -and semicolons = - Semicolons_Empty - | Semicolons_Some of semicolons - and varModifiers = Shared | Observable @@ -155,11 +151,11 @@ and attrKeyValue = AttrKeyValue1 of bIdent * attr and attribSet = - AttribSet_Some of beginRec * attrKeyValue list * semicolons * endRec + AttribSet_Some of beginRec * attrKeyValue list * endRec | AttribSet_Empty and attr = - Attr_Map of beginRec * attrKeyValue list * semicolons * endRec + Attr_Map of beginRec * attrKeyValue list * endRec | Attr_List of beginList * attr list * endList | Attr_Lit of value | Attr_Expr of expr @@ -187,8 +183,7 @@ and expr = | Expr_Exists of attribSet * lambdaDef | Expr_Lambda of attribSet * lambdaDef | Expr_Old of openParen * expr * closeParen - | Expr_FunctionOp of globalIdent * openParen * expr list * closeParen - | Expr_Apply of expr * expr + | Expr_FunctionOp of expr * openParen * expr list * closeParen | Expr_Binary of binOp * openParen * expr * expr * closeParen | Expr_Assoc of boolBinOp * openParen * expr list * closeParen | Expr_Unary of unOp * openParen * expr * closeParen @@ -211,7 +206,6 @@ and lambdaDef = and binOp = BinOpBVBinOp of bVBinOp | BinOpBVLogicalBinOp of bVLogicalBinOp - | BinOpBoolBinOp of boolBinOp | BinOpIntLogicalBinOp of intLogicalBinOp | BinOpIntBinOp of intBinOp | BinOpEqOp of eqOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 0c320284..096f2a34 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -36,10 +36,6 @@ token Str '"' ((char - ["\"\\"]) | ('\\' ["\"\\tnrf"]))* '"' ; position token IntegerHex ('0' 'x' (digit | ["abcdef"])+); position token IntegerDec (digit+); --- gobble extra semicolons -Semicolons_Empty . Semicolons ::= ""; -Semicolons_Some . Semicolons ::= Semicolons ";" ; - comment "//" ; comment "/*" "*/" ; @@ -168,13 +164,14 @@ Block_Phi . Block ::= "block" BlockIdent AttribSet BeginList rules AttrKeyValue ::= BIdent "=" Attr ; separator AttrKeyValue ";"; +-- in BNFC, `separator` also allows trailing -AttribSet_Some . AttribSet ::= BeginRec [ AttrKeyValue ] Semicolons EndRec; +AttribSet_Some . AttribSet ::= BeginRec [ AttrKeyValue ] EndRec; AttribSet_Empty . AttribSet ::= "" ; separator Attr ";" ; -Attr_Map . Attr ::= BeginRec [ AttrKeyValue ] Semicolons EndRec ; +Attr_Map . Attr ::= BeginRec [ AttrKeyValue ] EndRec ; Attr_List . Attr ::= BeginList [ Attr ] EndList; Attr_Lit . Attr ::= Value ; Attr_Expr . Attr ::= Expr; @@ -212,12 +209,11 @@ Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; Expr_Old . Expr ::= "old" OpenParen Expr CloseParen ; -- uninterpreted functions -Expr_FunctionOp . Expr ::= GlobalIdent OpenParen [Expr] CloseParen; -Expr_Apply . Expr ::= Expr Expr; +Expr_FunctionOp . Expr ::= Expr OpenParen [Expr] CloseParen; -- binary expr -rules BinOp ::= BVBinOp | BVLogicalBinOp | BoolBinOp | IntLogicalBinOp | IntBinOp | EqOp ; +rules BinOp ::= BVBinOp | BVLogicalBinOp | IntLogicalBinOp | IntBinOp | EqOp ; Expr_Binary . Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; Expr_Assoc . Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; @@ -279,7 +275,7 @@ ProgSpec_Guarantee . ProgSpec ::= "guarantee" Expr; terminator FunSpec ";"; {- last semicolon terminates the prog definitino -} -separator ProgSpec ";"; +separator nonempty ProgSpec ";"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index fcd66e07..9b79a303 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,12 +44,11 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pSemicolons pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pMapType pBVType pTypeT pExpr_list pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pExpr pLParen pLParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pMapType pBVType pTypeT pExpr_list pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pExpr pLParen pLParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list %type pLambdaSep -%type pSemicolons %type pVarModifiers %type pVarModifiers_list %type pDecl @@ -129,7 +128,6 @@ open Lexing %type decl_list %type blockIdent_list %type lambdaSep -%type semicolons %type varModifiers %type varModifiers_list %type decl @@ -233,8 +231,6 @@ pBlockIdent_list : blockIdent_list TOK_EOF { $1 }; pLambdaSep : lambdaSep TOK_EOF { $1 }; -pSemicolons : semicolons TOK_EOF { $1 }; - pVarModifiers : varModifiers TOK_EOF { $1 }; pVarModifiers_list : varModifiers_list TOK_EOF { $1 }; @@ -399,10 +395,6 @@ lambdaSep : SYMB3 { LambdaSep1 } | SYMB4 { LambdaSep2 } ; -semicolons : /* empty */ { Semicolons_Empty } - | semicolons SYMB1 { Semicolons_Some $1 } - ; - varModifiers : KW_shared { Shared } | KW_observable { Observable } ; @@ -594,7 +586,7 @@ attrKeyValue_list : /* empty */ { [] } | attrKeyValue SYMB1 attrKeyValue_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -attribSet : beginRec attrKeyValue_list semicolons endRec { AttribSet_Some ($1, $2, $3, $4) } +attribSet : beginRec attrKeyValue_list endRec { AttribSet_Some ($1, $2, $3) } | /* empty */ { AttribSet_Empty } ; @@ -603,7 +595,7 @@ attr_list : /* empty */ { [] } | attr SYMB1 attr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -attr : beginRec attrKeyValue_list semicolons endRec { Attr_Map ($1, $2, $3, $4) } +attr : beginRec attrKeyValue_list endRec { Attr_Map ($1, $2, $3) } | beginList attr_list endList { Attr_List ($1, $2, $3) } | value { Attr_Lit $1 } | expr { Attr_Expr $1 } @@ -640,8 +632,7 @@ expr : value { Expr_Literal $1 } | KW_exists attribSet lambdaDef { Expr_Exists ($2, $3) } | KW_fun attribSet lambdaDef { Expr_Lambda ($2, $3) } | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } - | globalIdent openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } - | expr expr { Expr_Apply ($1, $2) } + | expr openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } @@ -669,7 +660,6 @@ lambdaDef : lParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } binOp : bVBinOp { BinOpBVBinOp $1 } | bVLogicalBinOp { BinOpBVLogicalBinOp $1 } - | boolBinOp { BinOpBoolBinOp $1 } | intLogicalBinOp { BinOpIntLogicalBinOp $1 } | intBinOp { BinOpIntBinOp $1 } | eqOp { BinOpEqOp $1 } @@ -785,8 +775,7 @@ funSpec_list : /* empty */ { [] } | funSpec SYMB1 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -progSpec_list : /* empty */ { [] } - | progSpec { (fun x -> [x]) $1 } +progSpec_list : progSpec { (fun x -> [x]) $1 } | progSpec SYMB1 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 3a6e7e43..5c1ff9c7 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -145,11 +145,6 @@ and prtLambdaSep (i:int) (e : AbsBasilIR.lambdaSep) : doc = match e with | AbsBasilIR.LambdaSep2 -> prPrec i 0 (concatD [render "::"]) -and prtSemicolons (i:int) (e : AbsBasilIR.semicolons) : doc = match e with - AbsBasilIR.Semicolons_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.Semicolons_Some semicolons -> prPrec i 0 (concatD [prtSemicolons 0 semicolons ; render ";"]) - - and prtVarModifiers (i:int) (e : AbsBasilIR.varModifiers) : doc = match e with AbsBasilIR.Shared -> prPrec i 0 (concatD [render "shared"]) | AbsBasilIR.Observable -> prPrec i 0 (concatD [render "observable"]) @@ -344,12 +339,12 @@ and prtAttrKeyValueListBNFC i es : doc = match (i, es) with | (_,[x]) -> (concatD [prtAttrKeyValue 0 x]) | (_,x::xs) -> (concatD [prtAttrKeyValue 0 x ; render ";" ; prtAttrKeyValueListBNFC 0 xs]) and prtAttribSet (i:int) (e : AbsBasilIR.attribSet) : doc = match e with - AbsBasilIR.AttribSet_Some (beginrec, attrkeyvalues, semicolons, endrec) -> prPrec i 0 (concatD [prtBeginRec 0 beginrec ; prtAttrKeyValueListBNFC 0 attrkeyvalues ; prtSemicolons 0 semicolons ; prtEndRec 0 endrec]) + AbsBasilIR.AttribSet_Some (beginrec, attrkeyvalues, endrec) -> prPrec i 0 (concatD [prtBeginRec 0 beginrec ; prtAttrKeyValueListBNFC 0 attrkeyvalues ; prtEndRec 0 endrec]) | AbsBasilIR.AttribSet_Empty -> prPrec i 0 (concatD []) and prtAttr (i:int) (e : AbsBasilIR.attr) : doc = match e with - AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, semicolons, endrec) -> prPrec i 0 (concatD [prtBeginRec 0 beginrec ; prtAttrKeyValueListBNFC 0 attrkeyvalues ; prtSemicolons 0 semicolons ; prtEndRec 0 endrec]) + AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, endrec) -> prPrec i 0 (concatD [prtBeginRec 0 beginrec ; prtAttrKeyValueListBNFC 0 attrkeyvalues ; prtEndRec 0 endrec]) | AbsBasilIR.Attr_List (beginlist, attrs, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtAttrListBNFC 0 attrs ; prtEndList 0 endlist]) | AbsBasilIR.Attr_Lit value -> prPrec i 0 (concatD [prtValue 0 value]) | AbsBasilIR.Attr_Expr expr -> prPrec i 0 (concatD [prtExpr 0 expr]) @@ -389,8 +384,7 @@ and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> prPrec i 0 (concatD [render "exists" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> prPrec i 0 (concatD [render "fun" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> prPrec i 0 (concatD [render "old" ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_FunctionOp (globalident, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Apply (expr1, expr2) -> prPrec i 0 (concatD [prtExpr 0 expr1 ; prtExpr 0 expr2]) + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtExpr 0 expr ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Binary (binop, openparen, expr1, expr2, closeparen) -> prPrec i 0 (concatD [prtBinOp 0 binop ; prtOpenParen 0 openparen ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtBoolBinOp 0 boolbinop ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> prPrec i 0 (concatD [prtUnOp 0 unop ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) @@ -422,7 +416,6 @@ and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with AbsBasilIR.BinOpBVBinOp bvbinop -> prPrec i 0 (concatD [prtBVBinOp 0 bvbinop]) | AbsBasilIR.BinOpBVLogicalBinOp bvlogicalbinop -> prPrec i 0 (concatD [prtBVLogicalBinOp 0 bvlogicalbinop]) - | AbsBasilIR.BinOpBoolBinOp boolbinop -> prPrec i 0 (concatD [prtBoolBinOp 0 boolbinop]) | AbsBasilIR.BinOpIntLogicalBinOp intlogicalbinop -> prPrec i 0 (concatD [prtIntLogicalBinOp 0 intlogicalbinop]) | AbsBasilIR.BinOpIntBinOp intbinop -> prPrec i 0 (concatD [prtIntBinOp 0 intbinop]) | AbsBasilIR.BinOpEqOp eqop -> prPrec i 0 (concatD [prtEqOp 0 eqop]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 4d336bef..d6509ff3 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -65,11 +65,6 @@ and showLambdaSep (e : AbsBasilIR.lambdaSep) : showable = match e with | AbsBasilIR.LambdaSep2 -> s2s "LambdaSep2" -and showSemicolons (e : AbsBasilIR.semicolons) : showable = match e with - AbsBasilIR.Semicolons_Empty -> s2s "Semicolons_Empty" - | AbsBasilIR.Semicolons_Some semicolons -> s2s "Semicolons_Some" >> c2s ' ' >> c2s '(' >> showSemicolons semicolons >> c2s ')' - - and showVarModifiers (e : AbsBasilIR.varModifiers) : showable = match e with AbsBasilIR.Shared -> s2s "Shared" | AbsBasilIR.Observable -> s2s "Observable" @@ -225,12 +220,12 @@ and showAttrKeyValue (e : AbsBasilIR.attrKeyValue) : showable = match e with and showAttribSet (e : AbsBasilIR.attribSet) : showable = match e with - AbsBasilIR.AttribSet_Some (beginrec, attrkeyvalues, semicolons, endrec) -> s2s "AttribSet_Some" >> c2s ' ' >> c2s '(' >> showBeginRec beginrec >> s2s ", " >> showList showAttrKeyValue attrkeyvalues >> s2s ", " >> showSemicolons semicolons >> s2s ", " >> showEndRec endrec >> c2s ')' + AbsBasilIR.AttribSet_Some (beginrec, attrkeyvalues, endrec) -> s2s "AttribSet_Some" >> c2s ' ' >> c2s '(' >> showBeginRec beginrec >> s2s ", " >> showList showAttrKeyValue attrkeyvalues >> s2s ", " >> showEndRec endrec >> c2s ')' | AbsBasilIR.AttribSet_Empty -> s2s "AttribSet_Empty" and showAttr (e : AbsBasilIR.attr) : showable = match e with - AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, semicolons, endrec) -> s2s "Attr_Map" >> c2s ' ' >> c2s '(' >> showBeginRec beginrec >> s2s ", " >> showList showAttrKeyValue attrkeyvalues >> s2s ", " >> showSemicolons semicolons >> s2s ", " >> showEndRec endrec >> c2s ')' + AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, endrec) -> s2s "Attr_Map" >> c2s ' ' >> c2s '(' >> showBeginRec beginrec >> s2s ", " >> showList showAttrKeyValue attrkeyvalues >> s2s ", " >> showEndRec endrec >> c2s ')' | AbsBasilIR.Attr_List (beginlist, attrs, endlist) -> s2s "Attr_List" >> c2s ' ' >> c2s '(' >> showBeginList beginlist >> s2s ", " >> showList showAttr attrs >> s2s ", " >> showEndList endlist >> c2s ')' | AbsBasilIR.Attr_Lit value -> s2s "Attr_Lit" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' | AbsBasilIR.Attr_Expr expr -> s2s "Attr_Expr" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' @@ -262,8 +257,7 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> s2s "Expr_Exists" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> s2s "Expr_Lambda" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> s2s "Expr_Old" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_FunctionOp (globalident, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showGlobalIdent globalident >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Apply (expr0, expr) -> s2s "Expr_Apply" >> c2s ' ' >> c2s '(' >> showExpr expr0 >> s2s ", " >> showExpr expr >> c2s ')' + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Binary (binop, openparen, expr0, expr, closeparen) -> s2s "Expr_Binary" >> c2s ' ' >> c2s '(' >> showBinOp binop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> s2s "Expr_Assoc" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> s2s "Expr_Unary" >> c2s ' ' >> c2s '(' >> showUnOp unop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' @@ -289,7 +283,6 @@ and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with and showBinOp (e : AbsBasilIR.binOp) : showable = match e with AbsBasilIR.BinOpBVBinOp bvbinop -> s2s "BinOpBVBinOp" >> c2s ' ' >> c2s '(' >> showBVBinOp bvbinop >> c2s ')' | AbsBasilIR.BinOpBVLogicalBinOp bvlogicalbinop -> s2s "BinOpBVLogicalBinOp" >> c2s ' ' >> c2s '(' >> showBVLogicalBinOp bvlogicalbinop >> c2s ')' - | AbsBasilIR.BinOpBoolBinOp boolbinop -> s2s "BinOpBoolBinOp" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> c2s ')' | AbsBasilIR.BinOpIntLogicalBinOp intlogicalbinop -> s2s "BinOpIntLogicalBinOp" >> c2s ' ' >> c2s '(' >> showIntLogicalBinOp intlogicalbinop >> c2s ')' | AbsBasilIR.BinOpIntBinOp intbinop -> s2s "BinOpIntBinOp" >> c2s ' ' >> c2s '(' >> showIntBinOp intbinop >> c2s ')' | AbsBasilIR.BinOpEqOp eqop -> s2s "BinOpEqOp" >> c2s ' ' >> c2s '(' >> showEqOp eqop >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 9e3b57f6..a91eea5f 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -85,11 +85,6 @@ and transLambdaSep (x : lambdaSep) : result = match x with | LambdaSep2 -> failure x -and transSemicolons (x : semicolons) : result = match x with - Semicolons_Empty -> failure x - | Semicolons_Some semicolons -> failure x - - and transVarModifiers (x : varModifiers) : result = match x with Shared -> failure x | Observable -> failure x @@ -245,12 +240,12 @@ and transAttrKeyValue (x : attrKeyValue) : result = match x with and transAttribSet (x : attribSet) : result = match x with - AttribSet_Some (beginrec, attrkeyvalues, semicolons, endrec) -> failure x + AttribSet_Some (beginrec, attrkeyvalues, endrec) -> failure x | AttribSet_Empty -> failure x and transAttr (x : attr) : result = match x with - Attr_Map (beginrec, attrkeyvalues, semicolons, endrec) -> failure x + Attr_Map (beginrec, attrkeyvalues, endrec) -> failure x | Attr_List (beginlist, attrs, endlist) -> failure x | Attr_Lit value -> failure x | Attr_Expr expr -> failure x @@ -282,8 +277,7 @@ and transExpr (x : expr) : result = match x with | Expr_Exists (attribset, lambdadef) -> failure x | Expr_Lambda (attribset, lambdadef) -> failure x | Expr_Old (openparen, expr, closeparen) -> failure x - | Expr_FunctionOp (globalident, openparen, exprs, closeparen) -> failure x - | Expr_Apply (expr0, expr) -> failure x + | Expr_FunctionOp (expr, openparen, exprs, closeparen) -> failure x | Expr_Binary (binop, openparen, expr0, expr, closeparen) -> failure x | Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> failure x | Expr_Unary (unop, openparen, expr, closeparen) -> failure x @@ -309,7 +303,6 @@ and transLambdaDef (x : lambdaDef) : result = match x with and transBinOp (x : binOp) : result = match x with BinOpBVBinOp bvbinop -> failure x | BinOpBVLogicalBinOp bvlogicalbinop -> failure x - | BinOpBoolBinOp boolbinop -> failure x | BinOpIntLogicalBinOp intlogicalbinop -> failure x | BinOpIntBinOp intbinop -> failure x | BinOpEqOp eqop -> failure x diff --git a/lib/loadir.ml b/lib/loadir.ml index 2805a554..377d3c07 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -450,7 +450,7 @@ module BasilASTLoader = struct and trans_attr p_st ~binds (attr : attr) : [> Expr.BasilExpr.t Attrib.t ] = match attr with - | Attr_Map (_, keyvals, _, _) -> `Assoc (trans_attr_kv ~binds p_st keyvals) + | Attr_Map (_, keyvals, _) -> `Assoc (trans_attr_kv ~binds p_st keyvals) | Attr_List (_, ls, _) -> `List (List.map (trans_attr ~binds p_st) ls) | Attr_Lit v -> ( match trans_value v with #Ops.AllOps.const as v -> v) | Attr_Expr expr -> `Expr (trans_expr ~binds p_st expr) @@ -460,7 +460,7 @@ module BasilASTLoader = struct Expr.BasilExpr.t Attrib.attrib_map = match atrs with | AttribSet_Empty -> StringMap.empty - | AttribSet_Some (_, attrKeyValue, _, _) -> + | AttribSet_Some (_, attrKeyValue, _) -> trans_attr_kv ~binds p_st attrKeyValue and trans_stmt (p_st : load_st) (x : BasilIR.AbsBasilIR.stmtWithAttrib) : @@ -978,23 +978,15 @@ module BasilASTLoader = struct in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.exists ~attrib ~bound (trans_expr ~nbinds:bound e) - | Expr_FunctionOp (gi, o, args, c) -> - BasilExpr.apply_fun ~attrib:(expr_range_attr o c) - ~func:(BasilExpr.rvar @@ lookup_global_decl gi p_st) - (List.map trans_expr args) - | Expr_Apply (func, arg) -> + | Expr_FunctionOp (func, o, args, c) -> let func = trans_expr func in - let arg = trans_expr arg in - let attrib = - join_ranges (BasilExpr.attrib func) (BasilExpr.attrib arg) - in - BasilExpr.apply_fun ~attrib ~func [ arg ] + BasilExpr.apply_fun ~func ~attrib:(expr_range_attr o c) + (List.map trans_expr args) and transBinOp (x : BasilIR.AbsBasilIR.binOp) = match x with | BinOpBVBinOp bvbinop -> transBVBinOp bvbinop | BinOpBVLogicalBinOp bvlogicalbinop -> transBVLogicalBinOp bvlogicalbinop - | BinOpBoolBinOp boolbinop -> transBoolBinOp boolbinop | BinOpIntLogicalBinOp intlogicalbinop -> transIntLogicalBinOp intlogicalbinop | BinOpIntBinOp intbinop -> transIntBinOp intbinop diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index a1cf0d89..f80c1cdd 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -40,13 +40,6 @@ module.exports = grammar({ // LambdaSep2. LambdaSep ::= "::" ; "::" ), - Semicolons: $ => - choice( - // Semicolons_Empty. Semicolons ::= ; - choice(), - // Semicolons_Some. Semicolons ::= Semicolons ";" ; - seq(optional($.Semicolons), ";") - ), VarModifiers: $ => choice( // Shared. VarModifiers ::= "shared" ; @@ -78,7 +71,7 @@ module.exports = grammar({ // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), @@ -363,8 +356,8 @@ module.exports = grammar({ ), AttribSet: $ => choice( - // AttribSet_Some. AttribSet ::= BeginRec [AttrKeyValue] Semicolons EndRec ; - seq($.token_BeginRec, optional($.list_AttrKeyValue), optional($.Semicolons), $.token_EndRec), + // AttribSet_Some. AttribSet ::= BeginRec [AttrKeyValue] EndRec ; + seq($.token_BeginRec, optional($.list_AttrKeyValue), $.token_EndRec), // AttribSet_Empty. AttribSet ::= ; choice() ), @@ -379,8 +372,8 @@ module.exports = grammar({ ), Attr: $ => choice( - // Attr_Map. Attr ::= BeginRec [AttrKeyValue] Semicolons EndRec ; - seq($.token_BeginRec, optional($.list_AttrKeyValue), optional($.Semicolons), $.token_EndRec), + // Attr_Map. Attr ::= BeginRec [AttrKeyValue] EndRec ; + seq($.token_BeginRec, optional($.list_AttrKeyValue), $.token_EndRec), // Attr_List. Attr ::= BeginList [Attr] EndList ; seq($.token_BeginList, optional($.list_Attr), $.token_EndList), // Attr_Lit. Attr ::= Value ; @@ -445,10 +438,8 @@ module.exports = grammar({ seq("fun", optional($.AttribSet), $.LambdaDef), // Expr_Old. Expr ::= "old" OpenParen Expr CloseParen ; seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_FunctionOp. Expr ::= GlobalIdent OpenParen [Expr] CloseParen ; - seq($.token_GlobalIdent, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Apply. Expr ::= Expr Expr ; - seq($.Expr, $.Expr), + // Expr_FunctionOp. Expr ::= Expr OpenParen [Expr] CloseParen ; + seq($.Expr, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), // Expr_Binary. Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), // Expr_Assoc. Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; @@ -497,8 +488,6 @@ module.exports = grammar({ $.BVBinOp, // BinOpBVLogicalBinOp. BinOp ::= BVLogicalBinOp ; $.BVLogicalBinOp, - // BinOpBoolBinOp. BinOp ::= BoolBinOp ; - $.BoolBinOp, // BinOpIntLogicalBinOp. BinOp ::= IntLogicalBinOp ; $.IntLogicalBinOp, // BinOpIntBinOp. BinOp ::= IntBinOp ; @@ -710,12 +699,10 @@ module.exports = grammar({ ), list_ProgSpec: $ => choice( - // []. [ProgSpec] ::= ; - choice(), // (:[]). [ProgSpec] ::= ProgSpec ; $.ProgSpec, // (:). [ProgSpec] ::= ProgSpec ";" [ProgSpec] ; - seq($.ProgSpec, ";", optional($.list_ProgSpec)) + seq($.ProgSpec, ";", $.list_ProgSpec) ), token_BVTYPE: $ => /bv\d+/, From 8a5123aedb80a9b4abc270afbf8528f5f1fa2315 Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 15:52:30 +1000 Subject: [PATCH 07/43] fix some ambiguities in grammar.js --- lib/fe/AbsBasilIR.ml | 8 +++---- lib/fe/BasilIR.cf | 16 +++++++------- lib/fe/ParBasilIR.mly | 30 ++++++++++++------------- lib/fe/PrintBasilIR.ml | 23 ++++++++++--------- lib/fe/ShowBasilIR.ml | 8 +++---- lib/fe/SkelBasilIR.ml | 8 +++---- lib/loadir.ml | 2 +- test/cram/basicssa.t | 50 +++++++++++------------------------------- test/cram/roundtrip.t | 35 +++++++++++------------------ test/cram/typepass.t | 5 +++++ tree-sitter/grammar.js | 36 +++++++++++++++--------------- 11 files changed, 98 insertions(+), 123 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 263fe534..0848eea2 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -196,12 +196,12 @@ and expr = | Expr_Match of expr * openParen * case list * closeParen | Expr_Cases of openParen * case list * closeParen -and lParen = - LParenLocalVar of localVar - | LParen1 of openParen * localVar * closeParen +and lambdaParen = + LambdaParenLocalVar of localVar + | LambdaParen1 of openParen * localVar * closeParen and lambdaDef = - LambdaDef1 of lParen list * lambdaSep * expr + LambdaDef1 of lambdaParen list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 096f2a34..56348272 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -199,13 +199,13 @@ Expr_Global . Expr ::= GlobalVar; -- quantifiers -rules LParen ::= LocalVar | OpenParen LocalVar CloseParen ; -separator LParen ","; +rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; +separator LambdaParen ","; -rules LambdaDef ::= [LParen] LambdaSep Expr ; -Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; -Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; -Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; +rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; +Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; +Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; +Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; Expr_Old . Expr ::= "old" OpenParen Expr CloseParen ; -- uninterpreted functions @@ -272,10 +272,10 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= "rely" Expr; ProgSpec_Guarantee . ProgSpec ::= "guarantee" Expr; -terminator FunSpec ";"; +terminator FunSpec "\n"; {- last semicolon terminates the prog definitino -} -separator nonempty ProgSpec ";"; +separator nonempty ProgSpec "\n"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 9b79a303..8dd6db54 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pMapType pBVType pTypeT pExpr_list pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pExpr pLParen pLParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pMapType pBVType pTypeT pExpr_list pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pExpr pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -100,8 +100,8 @@ open Lexing %type pFunParams_list %type pValue %type pExpr -%type pLParen -%type pLParen_list +%type pLambdaParen +%type pLambdaParen_list %type pLambdaDef %type pBinOp %type pUnOp @@ -179,8 +179,8 @@ open Lexing %type funParams_list %type value %type expr -%type lParen -%type lParen_list +%type lambdaParen +%type lambdaParen_list %type lambdaDef %type binOp %type unOp @@ -333,9 +333,9 @@ pValue : value TOK_EOF { $1 }; pExpr : expr TOK_EOF { $1 }; -pLParen : lParen TOK_EOF { $1 }; +pLambdaParen : lambdaParen TOK_EOF { $1 }; -pLParen_list : lParen_list TOK_EOF { $1 }; +pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; pLambdaDef : lambdaDef TOK_EOF { $1 }; @@ -646,16 +646,16 @@ expr : value { Expr_Literal $1 } | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } ; -lParen : localVar { LParenLocalVar $1 } - | openParen localVar closeParen { LParen1 ($1, $2, $3) } +lambdaParen : localVar { LambdaParenLocalVar $1 } + | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } ; -lParen_list : /* empty */ { [] } - | lParen { (fun x -> [x]) $1 } - | lParen SYMB2 lParen_list { (fun (x,xs) -> x::xs) ($1, $3) } +lambdaParen_list : /* empty */ { [] } + | lambdaParen { (fun x -> [x]) $1 } + | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -lambdaDef : lParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } @@ -772,11 +772,11 @@ progSpec : KW_rely expr { ProgSpec_Rely $2 } ; funSpec_list : /* empty */ { [] } - | funSpec SYMB1 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } + | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; progSpec_list : progSpec { (fun x -> [x]) $1 } - | progSpec SYMB1 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } + | progSpec progSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; bVTYPE : TOK_BVTYPE { BVTYPE ($1)}; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 5c1ff9c7..6826f580 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -401,16 +401,16 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) -and prtLParen (i:int) (e : AbsBasilIR.lParen) : doc = match e with - AbsBasilIR.LParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.LParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) +and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) -and prtLParenListBNFC i es : doc = match (i, es) with +and prtLambdaParenListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLParen 0 x]) - | (_,x::xs) -> (concatD [prtLParen 0 x ; render "," ; prtLParenListBNFC 0 xs]) + | (_,[x]) -> (concatD [prtLambdaParen 0 x]) + | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (lparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLParenListBNFC 0 lparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with @@ -532,7 +532,8 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render " +" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) | AbsBasilIR.VarSpec_Empty -> prPrec i 0 (concatD []) @@ -544,6 +545,8 @@ and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtProgSpec 0 x]) - | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render ";" ; prtProgSpecListBNFC 0 xs]) + | (_,[x]) -> (concatD [prtProgSpec 0 x ; render " +"]) + | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render " +" ; prtProgSpecListBNFC 0 xs]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index d6509ff3..61e5ea0f 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -271,13 +271,13 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' -and showLParen (e : AbsBasilIR.lParen) : showable = match e with - AbsBasilIR.LParenLocalVar localvar -> s2s "LParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.LParen1 (openparen, localvar, closeparen) -> s2s "LParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' +and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (lparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLParen lparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index a91eea5f..34afd676 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -291,13 +291,13 @@ and transExpr (x : expr) : result = match x with | Expr_Cases (openparen, cases, closeparen) -> failure x -and transLParen (x : lParen) : result = match x with - LParenLocalVar localvar -> failure x - | LParen1 (openparen, localvar, closeparen) -> failure x +and transLambdaParen (x : lambdaParen) : result = match x with + LambdaParenLocalVar localvar -> failure x + | LambdaParen1 (openparen, localvar, closeparen) -> failure x and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (lparens, lambdasep, expr) -> failure x + LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index 377d3c07..08bb4dc5 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -625,7 +625,7 @@ module BasilASTLoader = struct and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = unpack_local_lvars ~bound p_st - @@ List.map (function LParenLocalVar v -> v | LParen1 (o, v, c) -> v) lvs + @@ List.map (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index 1e7d6527..2689b020 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,6 +2,11 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp + bincaml: Error in (load-il after.il): Parse error: after.il:20 + 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] $ cat before.il var $CF:bv1; @@ -316,17 +321,8 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - 18,21c18,21 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - [1] + diff: after_reparsed.il: No such file or directory + [2] The interpreter should give the same output for both @@ -337,34 +333,14 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt + diff: before_conds.txt: No such file or directory + diff: after_conds.txt: No such file or directory + [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - 1d0 - < var $R0:bv64; - 3c2 - < proc @main() -> () { } - --- - > proc @main(R0_in:bv64) -> (R0_out:bv64) { } - 7a7 - > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; - 9,12c9,19 - < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; - < block %e2 [ goto (%e4,%e1); ]; - < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - < block %e4 [ return; ] - --- - > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; - > block %e2 [ - > (var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64)); - > goto (%e4,%e1); - > ]; - > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - > block %e4 [ - > (var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64)); - > goto (%returns); - > ]; - > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] - [1] + diff: ssa-multi-before.il: No such file or directory + diff: ssa-multi-after.il: No such file or directory + [2] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8f080cb0..8a95e837 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,35 +1,26 @@ $ bincaml script roundtrip.sexp + bincaml: Error in (load-il before.il): Parse error: before.il:17 + 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - 15,18c15,18 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - 121c121 - < block %main_basil_return_1 [ nop; return; ] - --- - > block %main_basil_return_1 [ return; ] - [1] + diff: after.il: No such file or directory + [2] $ diff before2.il after2.il - 7,8c7,8 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8); - < captures $mem:(bv64->bv8), $stack:(bv64->bv8); - --- - > modifies $stack:(bv64->bv8), $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $mem:(bv64->bv8); - [1] + diff: before2.il: No such file or directory + diff: after2.il: No such file or directory + [2] Memassign repr $ diff beforemem.il aftermem.il + diff: beforemem.il: No such file or directory + diff: aftermem.il: No such file or directory + [2] diff --git a/test/cram/typepass.t b/test/cram/typepass.t index 9e5b7466..8bf348f9 100644 --- a/test/cram/typepass.t +++ b/test/cram/typepass.t @@ -1 +1,6 @@ $ bincaml script ./typepass.sexp + bincaml: Error in (load-il ../../examples/cat.il): Parse error: ../../examples/cat.il:52 + 52 | ensures eq($_PC:bv64, old($R30:bv64)); + ^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index f80c1cdd..a610c15c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -99,7 +99,7 @@ module.exports = grammar({ $.token_BOOLTYPE, MapType: $ => // MapType1. MapType ::= Type "->" Type ; - seq($.Type, "->", $.Type), + prec.right(101, seq($.Type, "->", $.Type)), BVType: $ => // BVType1. BVType ::= BVTYPE ; $.token_BVTYPE, @@ -377,7 +377,7 @@ module.exports = grammar({ // Attr_List. Attr ::= BeginList [Attr] EndList ; seq($.token_BeginList, optional($.list_Attr), $.token_EndList), // Attr_Lit. Attr ::= Value ; - $.Value, + // $.Value, // Attr_Expr. Attr ::= Expr ; $.Expr, // Attr_Str. Attr ::= Str ; @@ -463,25 +463,25 @@ module.exports = grammar({ // Expr_Cases. Expr ::= "cases" OpenParen [Case] CloseParen ; seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) ), - LParen: $ => + LambdaParen: $ => choice( - // LParenLocalVar. LParen ::= LocalVar ; - $.LocalVar, - // LParen1. LParen ::= OpenParen LocalVar CloseParen ; + // LambdaParenLocalVar. LambdaParen ::= LocalVar ; + // $.LocalVar, + // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) ), - list_LParen: $ => + list_LambdaParen: $ => choice( - // []. [LParen] ::= ; + // []. [LambdaParen] ::= ; choice(), - // (:[]). [LParen] ::= LParen ; - $.LParen, - // (:). [LParen] ::= LParen "," [LParen] ; - seq($.LParen, ",", optional($.list_LParen)) + // (:[]). [LambdaParen] ::= LambdaParen ; + $.LambdaParen, + // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; + seq($.LambdaParen, ",", optional($.list_LambdaParen)) ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LParen] LambdaSep Expr ; - seq(optional($.list_LParen), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; + prec.right(100, seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr)), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; @@ -694,15 +694,15 @@ module.exports = grammar({ choice( // []. [FunSpec] ::= ; choice(), - // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; - seq($.FunSpec, ";", optional($.list_FunSpec)) + // (:). [FunSpec] ::= FunSpec [FunSpec] ; + seq($.FunSpec, optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( // (:[]). [ProgSpec] ::= ProgSpec ; $.ProgSpec, - // (:). [ProgSpec] ::= ProgSpec ";" [ProgSpec] ; - seq($.ProgSpec, ";", $.list_ProgSpec) + // (:). [ProgSpec] ::= ProgSpec [ProgSpec] ; + seq($.ProgSpec, $.list_ProgSpec) ), token_BVTYPE: $ => /bv\d+/, From e5e774de71e22f22d6137a03f0d4ca48a0202bfb Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 15:58:13 +1000 Subject: [PATCH 08/43] fix last remaining ambiguities. we cannot put `Expr Expr` next to each other because of the apply/parans ambiguity. this was happening in the store statement --- tree-sitter/grammar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index a610c15c..7d681853 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -160,13 +160,13 @@ module.exports = grammar({ // Stmt_MultiAssign. Stmt ::= OpenParen [Assignment] CloseParen ; seq($.token_OpenParen, $.list_Assignment, $.token_CloseParen), // Stmt_Load. Stmt ::= LVar ":=" "load" Endian GlobalIdent Expr IntVal ; - seq($.LVar, ":=", "load", $.Endian, $.token_GlobalIdent, $.Expr, $.IntVal), + // seq($.LVar, ":=", "load", $.Endian, $.token_GlobalIdent, $.Expr, $.IntVal), // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal ; - seq("store", $.Endian, $.token_GlobalIdent, $.Expr, $.Expr, $.IntVal), + // seq("store", $.Endian, $.token_GlobalIdent, $.Expr, $.Expr, $.IntVal), // Stmt_Load_Var. Stmt ::= LVar ":=" "load" Endian Var Expr IntVal ; seq($.LVar, ":=", "load", $.Endian, $.Var, $.Expr, $.IntVal), // Stmt_Store_Var. Stmt ::= LVar ":=" "store" Endian Var Expr Expr IntVal ; - seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr, $.Expr, $.IntVal), + seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr, ",", $.Expr, $.IntVal), // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent OpenParen CallParams CloseParen ; seq(optional($.LVars), "call", $.token_ProcIdent, $.token_OpenParen, optional($.CallParams), $.token_CloseParen), // Stmt_IndirectCall. Stmt ::= "indirect" "call" Expr ; From 929279ced96b5b2232e5798c672286fd25067a79 Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 16:31:14 +1000 Subject: [PATCH 09/43] implement some precedence and associativity rules: - maptype `type -> type` is _right_ associative. - additionally, maptype *cannot* appear unparenthesised within an expression context (e.g., when it is affixed to a variable reference). it can still be without parentheses in global declarations. - quantifier expressions are *right* associative and have *lowest* precedence amongst expressions. basically, this means that quantified expressions will span from the quantifier all the way to the end of the expression. - store and load cases which took GlobalIdent explicitly are removed. these are subsumed by the untyped GlobalVar case. --- lib/fe/BasilIR.cf | 26 ++++---- tree-sitter/grammar.js | 145 ++++++++++++++++++++++------------------- 2 files changed, 92 insertions(+), 79 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 56348272..0cd9d756 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -64,12 +64,18 @@ ProcDef_Some . ProcDef ::= BeginList [Block] EndList ; IntType1 . IntType ::= INTTYPE ; BoolType1. BoolType ::= BOOLTYPE ; -MapType1 . MapType ::= Type "->" Type ; BVType1 . BVType ::= BVTYPE ; +-- map types are right associative. left of -> cannot be another MapType. +MapType1 . MapType ::= Type1 "->" Type ; -rules Type ::= IntType | BoolType | MapType | BVType | OpenParen Type CloseParen; +rules Type1 ::= IntType | BoolType | BVType ; +Type1Paren . Type1 ::= OpenParen Type CloseParen; + +rules Type ::= MapType; +_ . Type ::= Type1; separator Expr "," ; +coercions Expr 2; IntVal_Hex . IntVal ::= IntegerHex ; IntVal_Dec . IntVal ::= IntegerDec ; @@ -91,22 +97,21 @@ separator nonempty Assignment ","; Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; -LocalTyped . LocalVar ::= LocalIdent ":" Type ; +LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; LocalUntyped . LocalVar ::= LocalIdent ; -GlobalTyped . GlobalVar ::= GlobalIdent ":" Type ; +GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; GlobalUntyped . GlobalVar ::= GlobalIdent; separator nonempty LocalVar ","; rules Var ::= LocalVar | GlobalVar ; separator GlobalVar ","; +-- lvar endian mem addr size +Stmt_Load . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; -Stmt_Load . Stmt ::= LVar ":=" "load" Endian GlobalIdent Expr IntVal; -Stmt_Store . Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal; - -Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; -Stmt_Store_Var . Stmt ::= LVar ":=" "store" Endian Var Expr Expr IntVal; +-- lhs endian rhs addr value size +Stmt_Store . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; @@ -173,7 +178,6 @@ separator Attr ";" ; Attr_Map . Attr ::= BeginRec [ AttrKeyValue ] EndRec ; Attr_List . Attr ::= BeginList [ Attr ] EndList; -Attr_Lit . Attr ::= Value ; Attr_Expr . Attr ::= Expr; Attr_Str . Attr ::= Str ; @@ -209,7 +213,7 @@ Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; Expr_Old . Expr ::= "old" OpenParen Expr CloseParen ; -- uninterpreted functions -Expr_FunctionOp . Expr ::= Expr OpenParen [Expr] CloseParen; +Expr_FunctionOp . Expr1 ::= Expr1 OpenParen [Expr] CloseParen; -- binary expr diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 7d681853..f65f6bd1 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -97,25 +97,30 @@ module.exports = grammar({ BoolType: $ => // BoolType1. BoolType ::= BOOLTYPE ; $.token_BOOLTYPE, - MapType: $ => - // MapType1. MapType ::= Type "->" Type ; - prec.right(101, seq($.Type, "->", $.Type)), BVType: $ => // BVType1. BVType ::= BVTYPE ; $.token_BVTYPE, - Type: $ => + MapType: $ => + // MapType1. MapType ::= Type1 "->" Type ; + seq($.Type1, "->", $.Type), + Type1: $ => choice( - // TypeIntType. Type ::= IntType ; + // Type1IntType. Type1 ::= IntType ; $.IntType, - // TypeBoolType. Type ::= BoolType ; + // Type1BoolType. Type1 ::= BoolType ; $.BoolType, - // TypeMapType. Type ::= MapType ; - $.MapType, - // TypeBVType. Type ::= BVType ; + // Type1BVType. Type1 ::= BVType ; $.BVType, - // Type1. Type ::= OpenParen Type CloseParen ; + // Type1Paren. Type1 ::= OpenParen Type CloseParen ; seq($.token_OpenParen, $.Type, $.token_CloseParen) ), + Type: $ => + choice( + // TypeMapType. Type ::= MapType ; + $.MapType, + // _. Type ::= Type1 ; + $.Type1 + ), list_Expr: $ => choice( // []. [Expr] ::= ; @@ -125,6 +130,59 @@ module.exports = grammar({ // (:). [Expr] ::= Expr "," [Expr] ; seq($.Expr, ",", optional($.list_Expr)) ), + Expr: $ => + choice( + // _. Expr ::= Expr1 ; + $.Expr1, + // Expr_Literal. Expr ::= Value ; + $.Value, + // Expr_Paren. Expr ::= OpenParen Expr CloseParen ; + seq($.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_Local. Expr ::= LocalVar ; + $.LocalVar, + // Expr_Global. Expr ::= GlobalVar ; + $.GlobalVar, + // Expr_Forall. Expr ::= "forall" AttribSet LambdaDef ; + seq("forall", optional($.AttribSet), $.LambdaDef), + // Expr_Exists. Expr ::= "exists" AttribSet LambdaDef ; + seq("exists", optional($.AttribSet), $.LambdaDef), + // Expr_Lambda. Expr ::= "fun" AttribSet LambdaDef ; + seq("fun", optional($.AttribSet), $.LambdaDef), + // Expr_Old. Expr ::= "old" OpenParen Expr CloseParen ; + seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_Binary. Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; + seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_Assoc. Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; + seq($.BoolBinOp, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Unary. Expr ::= UnOp OpenParen Expr CloseParen ; + seq($.UnOp, $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_LoadBe. Expr ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_be", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_LoadLe. Expr ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_le", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_ZeroExtend. Expr ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; + seq("zero_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_SignExtend. Expr ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; + seq("sign_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Extract. Expr ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; + seq("extract", $.token_OpenParen, $.IntVal, ",", $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Concat. Expr ::= "bvconcat" OpenParen [Expr] CloseParen ; + seq("bvconcat", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Match. Expr ::= "match" Expr "with" OpenParen [Case] CloseParen ; + seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), + // Expr_Cases. Expr ::= "cases" OpenParen [Case] CloseParen ; + seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) + ), + Expr1: $ => + choice( + // _. Expr1 ::= Expr2 ; + $.Expr2, + // Expr_FunctionOp. Expr1 ::= Expr1 OpenParen [Expr] CloseParen ; + seq($.Expr1, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen) + ), + Expr2: $ => + // _. Expr2 ::= "(" Expr ")" ; + seq("(", $.Expr, ")"), IntVal: $ => choice( // IntVal_Hex. IntVal ::= IntegerHex ; @@ -159,14 +217,10 @@ module.exports = grammar({ seq($.LVar, ":=", "load", $.Var), // Stmt_MultiAssign. Stmt ::= OpenParen [Assignment] CloseParen ; seq($.token_OpenParen, $.list_Assignment, $.token_CloseParen), - // Stmt_Load. Stmt ::= LVar ":=" "load" Endian GlobalIdent Expr IntVal ; - // seq($.LVar, ":=", "load", $.Endian, $.token_GlobalIdent, $.Expr, $.IntVal), - // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal ; - // seq("store", $.Endian, $.token_GlobalIdent, $.Expr, $.Expr, $.IntVal), - // Stmt_Load_Var. Stmt ::= LVar ":=" "load" Endian Var Expr IntVal ; + // Stmt_Load. Stmt ::= LVar ":=" "load" Endian Var Expr IntVal ; seq($.LVar, ":=", "load", $.Endian, $.Var, $.Expr, $.IntVal), - // Stmt_Store_Var. Stmt ::= LVar ":=" "store" Endian Var Expr Expr IntVal ; - seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr, ",", $.Expr, $.IntVal), + // Stmt_Store. Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal ; + seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr2, $.Expr, $.IntVal), // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent OpenParen CallParams CloseParen ; seq(optional($.LVars), "call", $.token_ProcIdent, $.token_OpenParen, optional($.CallParams), $.token_CloseParen), // Stmt_IndirectCall. Stmt ::= "indirect" "call" Expr ; @@ -187,15 +241,15 @@ module.exports = grammar({ ), LocalVar: $ => choice( - // LocalTyped. LocalVar ::= LocalIdent ":" Type ; - seq($.token_LocalIdent, ":", $.Type), + // LocalTyped. LocalVar ::= LocalIdent ":" Type1 ; + seq($.token_LocalIdent, ":", $.Type1), // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), GlobalVar: $ => choice( - // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type ; - seq($.token_GlobalIdent, ":", $.Type), + // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; + seq($.token_GlobalIdent, ":", $.Type1), // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), @@ -376,8 +430,6 @@ module.exports = grammar({ seq($.token_BeginRec, optional($.list_AttrKeyValue), $.token_EndRec), // Attr_List. Attr ::= BeginList [Attr] EndList ; seq($.token_BeginList, optional($.list_Attr), $.token_EndList), - // Attr_Lit. Attr ::= Value ; - // $.Value, // Attr_Expr. Attr ::= Expr ; $.Expr, // Attr_Str. Attr ::= Str ; @@ -420,53 +472,10 @@ module.exports = grammar({ // Value_False. Value ::= "false" ; "false" ), - Expr: $ => - choice( - // Expr_Literal. Expr ::= Value ; - $.Value, - // Expr_Paren. Expr ::= OpenParen Expr CloseParen ; - seq($.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_Local. Expr ::= LocalVar ; - $.LocalVar, - // Expr_Global. Expr ::= GlobalVar ; - $.GlobalVar, - // Expr_Forall. Expr ::= "forall" AttribSet LambdaDef ; - seq("forall", optional($.AttribSet), $.LambdaDef), - // Expr_Exists. Expr ::= "exists" AttribSet LambdaDef ; - seq("exists", optional($.AttribSet), $.LambdaDef), - // Expr_Lambda. Expr ::= "fun" AttribSet LambdaDef ; - seq("fun", optional($.AttribSet), $.LambdaDef), - // Expr_Old. Expr ::= "old" OpenParen Expr CloseParen ; - seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_FunctionOp. Expr ::= Expr OpenParen [Expr] CloseParen ; - seq($.Expr, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Binary. Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; - seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_Assoc. Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; - seq($.BoolBinOp, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Unary. Expr ::= UnOp OpenParen Expr CloseParen ; - seq($.UnOp, $.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_LoadBe. Expr ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; - seq("load_be", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_LoadLe. Expr ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; - seq("load_le", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_ZeroExtend. Expr ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; - seq("zero_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_SignExtend. Expr ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; - seq("sign_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_Extract. Expr ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; - seq("extract", $.token_OpenParen, $.IntVal, ",", $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_Concat. Expr ::= "bvconcat" OpenParen [Expr] CloseParen ; - seq("bvconcat", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Match. Expr ::= "match" Expr "with" OpenParen [Case] CloseParen ; - seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), - // Expr_Cases. Expr ::= "cases" OpenParen [Case] CloseParen ; - seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) - ), LambdaParen: $ => choice( // LambdaParenLocalVar. LambdaParen ::= LocalVar ; - // $.LocalVar, + $.LocalVar, // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) ), @@ -481,7 +490,7 @@ module.exports = grammar({ ), LambdaDef: $ => // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; - prec.right(100, seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr)), + seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From 81a049c333c9eda825cc0dc6d693c078b92b4dd0 Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 27 Feb 2026 17:21:40 +1000 Subject: [PATCH 10/43] blah --- lib/fe/AbsBasilIR.ml | 65 ++++++++++--------- lib/fe/LexBasilIR.mll | 6 +- lib/fe/ParBasilIR.mly | 137 ++++++++++++++++++++++++----------------- lib/fe/PrintBasilIR.ml | 79 ++++++++++++------------ lib/fe/ShowBasilIR.ml | 69 ++++++++++----------- lib/fe/SkelBasilIR.ml | 69 ++++++++++----------- 6 files changed, 217 insertions(+), 208 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 0848eea2..816e31c3 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -49,18 +49,40 @@ and intType = and boolType = BoolType1 of bOOLTYPE -and mapType = - MapType1 of typeT * typeT - and bVType = BVType1 of bVTYPE +and mapType = + MapType1 of typeT * typeT + and typeT = - TypeIntType of intType - | TypeBoolType of boolType + Type1IntType of intType + | Type1BoolType of boolType + | Type1BVType of bVType + | Type1Paren of openParen * typeT * closeParen | TypeMapType of mapType - | TypeBVType of bVType - | Type1 of openParen * typeT * closeParen + +and expr = + Expr_Literal of value + | Expr_Paren of openParen * expr * closeParen + | Expr_Local of localVar + | Expr_Global of globalVar + | Expr_Forall of attribSet * lambdaDef + | Expr_Exists of attribSet * lambdaDef + | Expr_Lambda of attribSet * lambdaDef + | Expr_Old of openParen * expr * closeParen + | Expr_FunctionOp of expr * openParen * expr list * closeParen + | Expr_Binary of binOp * openParen * expr * expr * closeParen + | Expr_Assoc of boolBinOp * openParen * expr list * closeParen + | Expr_Unary of unOp * openParen * expr * closeParen + | Expr_LoadBe of openParen * intVal * expr * expr * closeParen + | Expr_LoadLe of openParen * intVal * expr * expr * closeParen + | Expr_ZeroExtend of openParen * intVal * expr * closeParen + | Expr_SignExtend of openParen * intVal * expr * closeParen + | Expr_Extract of openParen * intVal * intVal * expr * closeParen + | Expr_Concat of openParen * expr list * closeParen + | Expr_Match of expr * openParen * case list * closeParen + | Expr_Cases of openParen * case list * closeParen and intVal = IntVal_Hex of integerHex @@ -83,10 +105,8 @@ and stmt = | Stmt_ScalarStore of lVar * expr | Stmt_ScalarLoad of lVar * var | Stmt_MultiAssign of openParen * assignment list * closeParen - | Stmt_Load of lVar * endian * globalIdent * expr * intVal - | Stmt_Store of endian * globalIdent * expr * expr * intVal - | Stmt_Load_Var of lVar * endian * var * expr * intVal - | Stmt_Store_Var of lVar * endian * var * expr * expr * intVal + | Stmt_Load of lVar * endian * var * expr * intVal + | Stmt_Store of lVar * endian * var * expr * expr * intVal | Stmt_DirectCall of lVars * procIdent * openParen * callParams * closeParen | Stmt_IndirectCall of expr | Stmt_Assume of expr @@ -157,7 +177,6 @@ and attribSet = and attr = Attr_Map of beginRec * attrKeyValue list * endRec | Attr_List of beginList * attr list * endList - | Attr_Lit of value | Attr_Expr of expr | Attr_Str of str @@ -174,28 +193,6 @@ and value = | Value_True | Value_False -and expr = - Expr_Literal of value - | Expr_Paren of openParen * expr * closeParen - | Expr_Local of localVar - | Expr_Global of globalVar - | Expr_Forall of attribSet * lambdaDef - | Expr_Exists of attribSet * lambdaDef - | Expr_Lambda of attribSet * lambdaDef - | Expr_Old of openParen * expr * closeParen - | Expr_FunctionOp of expr * openParen * expr list * closeParen - | Expr_Binary of binOp * openParen * expr * expr * closeParen - | Expr_Assoc of boolBinOp * openParen * expr list * closeParen - | Expr_Unary of unOp * openParen * expr * closeParen - | Expr_LoadBe of openParen * intVal * expr * expr * closeParen - | Expr_LoadLe of openParen * intVal * expr * expr * closeParen - | Expr_ZeroExtend of openParen * intVal * expr * closeParen - | Expr_SignExtend of openParen * intVal * expr * closeParen - | Expr_Extract of openParen * intVal * intVal * expr * closeParen - | Expr_Concat of openParen * expr list * closeParen - | Expr_Match of expr * openParen * case list * closeParen - | Expr_Cases of openParen * case list * closeParen - and lambdaParen = LambdaParenLocalVar of localVar | LambdaParen1 of openParen * localVar * closeParen diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 2847e63d..4c55f342 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -7,9 +7,9 @@ open ParBasilIR open Lexing -let symbol_table = Hashtbl.create 10 +let symbol_table = Hashtbl.create 12 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add symbol_table kwd tok) - [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] + [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);("(", SYMB7);(")", SYMB8);(":=", SYMB9);("mem:=", SYMB10);("_", SYMB11);("|", SYMB12)] let resword_table = Hashtbl.create 99 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add resword_table kwd tok) @@ -53,7 +53,7 @@ let _idchar = _letter | _digit | ['_' '\''] (* identifier character *) let _universal = _ (* universal: any character *) (* reserved words consisting of special symbols *) -let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" +let rsyms = ";" | "," | "->" | "::" | ":" | "=" | "(" | ")" | ":=" | "mem:=" | "_" | "|" (* user-defined token types *) let bVTYPE = "bv" _digit + diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 8dd6db54..22c31478 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -15,10 +15,12 @@ open Lexing %token SYMB4 /* :: */ %token SYMB5 /* : */ %token SYMB6 /* = */ -%token SYMB7 /* := */ -%token SYMB8 /* mem:= */ -%token SYMB9 /* _ */ -%token SYMB10 /* | */ +%token SYMB7 /* ( */ +%token SYMB8 /* ) */ +%token SYMB9 /* := */ +%token SYMB10 /* mem:= */ +%token SYMB11 /* _ */ +%token SYMB12 /* | */ %token TOK_EOF %token TOK_Ident @@ -44,7 +46,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pMapType pBVType pTypeT pExpr_list pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pExpr pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pExpr_list pExpr pExpr1 pExpr2 pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -56,10 +58,14 @@ open Lexing %type pProcDef %type pIntType %type pBoolType -%type pMapType %type pBVType +%type pMapType +%type pType1 %type pTypeT %type pExpr_list +%type pExpr +%type pExpr1 +%type pExpr2 %type pIntVal %type pBVVal %type pEndian @@ -99,7 +105,6 @@ open Lexing %type pFunParams %type pFunParams_list %type pValue -%type pExpr %type pLambdaParen %type pLambdaParen_list %type pLambdaDef @@ -135,10 +140,14 @@ open Lexing %type procDef %type intType %type boolType -%type mapType %type bVType +%type mapType +%type type1 %type typeT %type expr_list +%type expr +%type expr1 +%type expr2 %type intVal %type bVVal %type endian @@ -178,7 +187,6 @@ open Lexing %type funParams %type funParams_list %type value -%type expr %type lambdaParen %type lambdaParen_list %type lambdaDef @@ -245,14 +253,22 @@ pIntType : intType TOK_EOF { $1 }; pBoolType : boolType TOK_EOF { $1 }; +pBVType : bVType TOK_EOF { $1 }; + pMapType : mapType TOK_EOF { $1 }; -pBVType : bVType TOK_EOF { $1 }; +pType1 : type1 TOK_EOF { $1 }; pTypeT : typeT TOK_EOF { $1 }; pExpr_list : expr_list TOK_EOF { $1 }; +pExpr : expr TOK_EOF { $1 }; + +pExpr1 : expr1 TOK_EOF { $1 }; + +pExpr2 : expr2 TOK_EOF { $1 }; + pIntVal : intVal TOK_EOF { $1 }; pBVVal : bVVal TOK_EOF { $1 }; @@ -331,8 +347,6 @@ pFunParams_list : funParams_list TOK_EOF { $1 }; pValue : value TOK_EOF { $1 }; -pExpr : expr TOK_EOF { $1 }; - pLambdaParen : lambdaParen TOK_EOF { $1 }; pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; @@ -429,17 +443,20 @@ intType : iNTTYPE { IntType1 $1 } boolType : bOOLTYPE { BoolType1 $1 } ; -mapType : typeT SYMB3 typeT { MapType1 ($1, $3) } +bVType : bVTYPE { BVType1 $1 } ; -bVType : bVTYPE { BVType1 $1 } +mapType : type1 SYMB3 typeT { MapType1 ($1, $3) } + ; + +type1 : intType { Type1IntType $1 } + | boolType { Type1BoolType $1 } + | bVType { Type1BVType $1 } + | openParen typeT closeParen { Type1Paren ($1, $2, $3) } ; -typeT : intType { TypeIntType $1 } - | boolType { TypeBoolType $1 } - | mapType { TypeMapType $1 } - | bVType { TypeBVType $1 } - | openParen typeT closeParen { Type1 ($1, $2, $3) } +typeT : mapType { TypeMapType $1 } + | type1 { $1 } ; expr_list : /* empty */ { [] } @@ -447,6 +464,35 @@ expr_list : /* empty */ { [] } | expr SYMB2 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; +expr : expr1 { $1 } + | value { Expr_Literal $1 } + | openParen expr closeParen { Expr_Paren ($1, $2, $3) } + | localVar { Expr_Local $1 } + | globalVar { Expr_Global $1 } + | KW_forall attribSet lambdaDef { Expr_Forall ($2, $3) } + | KW_exists attribSet lambdaDef { Expr_Exists ($2, $3) } + | KW_fun attribSet lambdaDef { Expr_Lambda ($2, $3) } + | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } + | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } + | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } + | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } + | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } + | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } + | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } + | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } + | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } + | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } + | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } + | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } + ; + +expr1 : expr2 { $1 } + | expr1 openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } + ; + +expr2 : SYMB7 expr SYMB8 { $2 } + ; + intVal : integerHex { IntVal_Hex $1 } | integerDec { IntVal_Dec $1 } ; @@ -458,19 +504,17 @@ endian : KW_le { Endian_Little } | KW_be { Endian_Big } ; -assignment : lVar SYMB7 expr { Assignment1 ($1, $3) } +assignment : lVar SYMB9 expr { Assignment1 ($1, $3) } ; stmt : KW_nop { Stmt_Nop } | assignment { Stmt_SingleAssign $1 } - | lVar SYMB8 expr { Stmt_MemAssign ($1, $3) } - | lVar SYMB7 KW_store expr { Stmt_ScalarStore ($1, $4) } - | lVar SYMB7 KW_load var { Stmt_ScalarLoad ($1, $4) } + | lVar SYMB10 expr { Stmt_MemAssign ($1, $3) } + | lVar SYMB9 KW_store expr { Stmt_ScalarStore ($1, $4) } + | lVar SYMB9 KW_load var { Stmt_ScalarLoad ($1, $4) } | openParen assignment_list closeParen { Stmt_MultiAssign ($1, $2, $3) } - | lVar SYMB7 KW_load endian globalIdent expr intVal { Stmt_Load ($1, $4, $5, $6, $7) } - | KW_store endian globalIdent expr expr intVal { Stmt_Store ($2, $3, $4, $5, $6) } - | lVar SYMB7 KW_load endian var expr intVal { Stmt_Load_Var ($1, $4, $5, $6, $7) } - | lVar SYMB7 KW_store endian var expr expr intVal { Stmt_Store_Var ($1, $4, $5, $6, $7, $8) } + | lVar SYMB9 KW_load endian var expr intVal { Stmt_Load ($1, $4, $5, $6, $7) } + | lVar SYMB9 KW_store endian var expr2 expr intVal { Stmt_Store ($1, $4, $5, $6, $7, $8) } | lVars KW_call procIdent openParen callParams closeParen { Stmt_DirectCall ($1, $3, $4, $5, $6) } | KW_indirect KW_call expr { Stmt_IndirectCall $3 } | KW_assume expr { Stmt_Assume $2 } @@ -482,11 +526,11 @@ assignment_list : assignment { (fun x -> [x]) $1 } | assignment SYMB2 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -localVar : localIdent SYMB5 typeT { LocalTyped ($1, $3) } +localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; -globalVar : globalIdent SYMB5 typeT { GlobalTyped ($1, $3) } +globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; @@ -512,9 +556,9 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } - | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } - | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } + | KW_var openParen localVar_list closeParen SYMB9 { LVars_LocalList ($2, $3, $4) } + | openParen lVar_list closeParen SYMB9 { LVars_List ($1, $2, $3) } + | openParen namedCallReturn_list closeParen SYMB9 { NamedLVars_List ($1, $2, $3) } ; namedCallArg : localIdent SYMB6 expr { NamedCallArg1 ($1, $3) } @@ -566,7 +610,7 @@ phiExpr_list : /* empty */ { [] } | phiExpr SYMB2 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } +phiAssign : lVar SYMB9 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } ; phiAssign_list : /* empty */ { [] } @@ -597,7 +641,6 @@ attr_list : /* empty */ { [] } attr : beginRec attrKeyValue_list endRec { Attr_Map ($1, $2, $3) } | beginList attr_list endList { Attr_List ($1, $2, $3) } - | value { Attr_Lit $1 } | expr { Attr_Expr $1 } | str { Attr_Str $1 } ; @@ -624,28 +667,6 @@ value : bVVal { Value_BV $1 } | KW_false { Value_False } ; -expr : value { Expr_Literal $1 } - | openParen expr closeParen { Expr_Paren ($1, $2, $3) } - | localVar { Expr_Local $1 } - | globalVar { Expr_Global $1 } - | KW_forall attribSet lambdaDef { Expr_Forall ($2, $3) } - | KW_exists attribSet lambdaDef { Expr_Exists ($2, $3) } - | KW_fun attribSet lambdaDef { Expr_Lambda ($2, $3) } - | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } - | expr openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } - | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } - | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } - | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } - | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } - | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } - | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } - | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } - | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } - | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } - | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } - | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } - ; - lambdaParen : localVar { LambdaParenLocalVar $1 } | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } ; @@ -674,12 +695,12 @@ unOp : bVUnOp { UnOpBVUnOp $1 } ; case : expr SYMB3 expr { CaseCase ($1, $3) } - | SYMB9 SYMB3 expr { CaseDefault $3 } + | SYMB11 SYMB3 expr { CaseDefault $3 } ; case_list : /* empty */ { [] } | case { (fun x -> [x]) $1 } - | case SYMB10 case_list { (fun (x,xs) -> x::xs) ($1, $3) } + | case SYMB12 case_list { (fun (x,xs) -> x::xs) ($1, $3) } ; eqOp : KW_eq { EqOp_eq } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 6826f580..e9da2a1c 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -179,25 +179,51 @@ and prtBoolType (i:int) (e : AbsBasilIR.boolType) : doc = match e with AbsBasilIR.BoolType1 booltype -> prPrec i 0 (concatD [prtBOOLTYPE 0 booltype]) -and prtMapType (i:int) (e : AbsBasilIR.mapType) : doc = match e with - AbsBasilIR.MapType1 (type_1, type_2) -> prPrec i 0 (concatD [prtTypeT 0 type_1 ; render "->" ; prtTypeT 0 type_2]) - - and prtBVType (i:int) (e : AbsBasilIR.bVType) : doc = match e with AbsBasilIR.BVType1 bvtype -> prPrec i 0 (concatD [prtBVTYPE 0 bvtype]) +and prtMapType (i:int) (e : AbsBasilIR.mapType) : doc = match e with + AbsBasilIR.MapType1 (type_1, type_2) -> prPrec i 0 (concatD [prtTypeT 1 type_1 ; render "->" ; prtTypeT 0 type_2]) + + and prtTypeT (i:int) (e : AbsBasilIR.typeT) : doc = match e with - AbsBasilIR.TypeIntType inttype -> prPrec i 0 (concatD [prtIntType 0 inttype]) - | AbsBasilIR.TypeBoolType booltype -> prPrec i 0 (concatD [prtBoolType 0 booltype]) + AbsBasilIR.Type1IntType inttype -> prPrec i 1 (concatD [prtIntType 0 inttype]) + | AbsBasilIR.Type1BoolType booltype -> prPrec i 1 (concatD [prtBoolType 0 booltype]) + | AbsBasilIR.Type1BVType bvtype -> prPrec i 1 (concatD [prtBVType 0 bvtype]) + | AbsBasilIR.Type1Paren (openparen, type_, closeparen) -> prPrec i 1 (concatD [prtOpenParen 0 openparen ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) | AbsBasilIR.TypeMapType maptype -> prPrec i 0 (concatD [prtMapType 0 maptype]) - | AbsBasilIR.TypeBVType bvtype -> prPrec i 0 (concatD [prtBVType 0 bvtype]) - | AbsBasilIR.Type1 (openparen, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) and prtTypeTListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtTypeT 0 x]) | (_,x::xs) -> (concatD [prtTypeT 0 x ; render "," ; prtTypeTListBNFC 0 xs]) +and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with + AbsBasilIR.Expr_Literal value -> prPrec i 0 (concatD [prtValue 0 value]) + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Local localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.Expr_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) + | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> prPrec i 0 (concatD [render "forall" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> prPrec i 0 (concatD [render "exists" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> prPrec i 0 (concatD [render "fun" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> prPrec i 0 (concatD [render "old" ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> prPrec i 1 (concatD [prtExpr 1 expr ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Binary (binop, openparen, expr1, expr2, closeparen) -> prPrec i 0 (concatD [prtBinOp 0 binop ; prtOpenParen 0 openparen ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtBoolBinOp 0 boolbinop ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> prPrec i 0 (concatD [prtUnOp 0 unop ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_LoadBe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_be" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_LoadLe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_le" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "zero_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "sign_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Extract (openparen, intval1, intval2, expr, closeparen) -> prPrec i 0 (concatD [render "extract" ; prtOpenParen 0 openparen ; prtIntVal 0 intval1 ; render "," ; prtIntVal 0 intval2 ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> prPrec i 0 (concatD [render "bvconcat" ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> prPrec i 0 (concatD [render "match" ; prtExpr 0 expr ; render "with" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> prPrec i 0 (concatD [render "cases" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) + +and prtExprListBNFC i es : doc = match (i, es) with + (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtExpr 0 x]) + | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) and prtIntVal (i:int) (e : AbsBasilIR.intVal) : doc = match e with AbsBasilIR.IntVal_Hex integerhex -> prPrec i 0 (concatD [prtIntegerHex 0 integerhex]) | AbsBasilIR.IntVal_Dec integerdec -> prPrec i 0 (concatD [prtIntegerDec 0 integerdec]) @@ -226,10 +252,8 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with | AbsBasilIR.Stmt_ScalarStore (lvar, expr) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtExpr 0 expr]) | AbsBasilIR.Stmt_ScalarLoad (lvar, var) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtVar 0 var]) | AbsBasilIR.Stmt_MultiAssign (openparen, assignments, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtAssignmentListBNFC 0 assignments ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Stmt_Load (lvar, endian, globalident, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtGlobalIdent 0 globalident ; prtExpr 0 expr ; prtIntVal 0 intval]) - | AbsBasilIR.Stmt_Store (endian, globalident, expr1, expr2, intval) -> prPrec i 0 (concatD [render "store" ; prtEndian 0 endian ; prtGlobalIdent 0 globalident ; prtExpr 0 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) - | AbsBasilIR.Stmt_Load_Var (lvar, endian, var, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr ; prtIntVal 0 intval]) - | AbsBasilIR.Stmt_Store_Var (lvar, endian, var, expr1, expr2, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Load (lvar, endian, var, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Store (lvar, endian, var, expr1, expr2, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 2 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) | AbsBasilIR.Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> prPrec i 0 (concatD [prtLVars 0 lvars ; render "call" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen ; prtCallParams 0 callparams ; prtCloseParen 0 closeparen]) | AbsBasilIR.Stmt_IndirectCall expr -> prPrec i 0 (concatD [render "indirect" ; render "call" ; prtExpr 0 expr]) | AbsBasilIR.Stmt_Assume expr -> prPrec i 0 (concatD [render "assume" ; prtExpr 0 expr]) @@ -238,7 +262,7 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with and prtLocalVar (i:int) (e : AbsBasilIR.localVar) : doc = match e with - AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_]) + AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 1 type_]) | AbsBasilIR.LocalUntyped localident -> prPrec i 0 (concatD [prtLocalIdent 0 localident]) and prtLocalVarListBNFC i es : doc = match (i, es) with @@ -246,7 +270,7 @@ and prtLocalVarListBNFC i es : doc = match (i, es) with | (_,[x]) -> (concatD [prtLocalVar 0 x]) | (_,x::xs) -> (concatD [prtLocalVar 0 x ; render "," ; prtLocalVarListBNFC 0 xs]) and prtGlobalVar (i:int) (e : AbsBasilIR.globalVar) : doc = match e with - AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_]) + AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 1 type_]) | AbsBasilIR.GlobalUntyped globalident -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident]) and prtGlobalVarListBNFC i es : doc = match (i, es) with @@ -346,7 +370,6 @@ and prtAttribSet (i:int) (e : AbsBasilIR.attribSet) : doc = match e with and prtAttr (i:int) (e : AbsBasilIR.attr) : doc = match e with AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, endrec) -> prPrec i 0 (concatD [prtBeginRec 0 beginrec ; prtAttrKeyValueListBNFC 0 attrkeyvalues ; prtEndRec 0 endrec]) | AbsBasilIR.Attr_List (beginlist, attrs, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtAttrListBNFC 0 attrs ; prtEndList 0 endlist]) - | AbsBasilIR.Attr_Lit value -> prPrec i 0 (concatD [prtValue 0 value]) | AbsBasilIR.Attr_Expr expr -> prPrec i 0 (concatD [prtExpr 0 expr]) | AbsBasilIR.Attr_Str str -> prPrec i 0 (concatD [prtStr 0 str]) @@ -375,32 +398,6 @@ and prtValue (i:int) (e : AbsBasilIR.value) : doc = match e with | AbsBasilIR.Value_False -> prPrec i 0 (concatD [render "false"]) -and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with - AbsBasilIR.Expr_Literal value -> prPrec i 0 (concatD [prtValue 0 value]) - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Local localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.Expr_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) - | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> prPrec i 0 (concatD [render "forall" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> prPrec i 0 (concatD [render "exists" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> prPrec i 0 (concatD [render "fun" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> prPrec i 0 (concatD [render "old" ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtExpr 0 expr ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Binary (binop, openparen, expr1, expr2, closeparen) -> prPrec i 0 (concatD [prtBinOp 0 binop ; prtOpenParen 0 openparen ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtBoolBinOp 0 boolbinop ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> prPrec i 0 (concatD [prtUnOp 0 unop ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_LoadBe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_be" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_LoadLe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_le" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "zero_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "sign_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Extract (openparen, intval1, intval2, expr, closeparen) -> prPrec i 0 (concatD [render "extract" ; prtOpenParen 0 openparen ; prtIntVal 0 intval1 ; render "," ; prtIntVal 0 intval2 ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> prPrec i 0 (concatD [render "bvconcat" ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> prPrec i 0 (concatD [render "match" ; prtExpr 0 expr ; render "with" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> prPrec i 0 (concatD [render "cases" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) - -and prtExprListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtExpr 0 x]) - | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 61e5ea0f..38812a40 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -95,20 +95,43 @@ and showBoolType (e : AbsBasilIR.boolType) : showable = match e with AbsBasilIR.BoolType1 booltype -> s2s "BoolType1" >> c2s ' ' >> c2s '(' >> showBOOLTYPE booltype >> c2s ')' -and showMapType (e : AbsBasilIR.mapType) : showable = match e with - AbsBasilIR.MapType1 (type'0, type') -> s2s "MapType1" >> c2s ' ' >> c2s '(' >> showTypeT type'0 >> s2s ", " >> showTypeT type' >> c2s ')' - - and showBVType (e : AbsBasilIR.bVType) : showable = match e with AbsBasilIR.BVType1 bvtype -> s2s "BVType1" >> c2s ' ' >> c2s '(' >> showBVTYPE bvtype >> c2s ')' +and showMapType (e : AbsBasilIR.mapType) : showable = match e with + AbsBasilIR.MapType1 (type'0, type') -> s2s "MapType1" >> c2s ' ' >> c2s '(' >> showTypeT type'0 >> s2s ", " >> showTypeT type' >> c2s ')' + + and showTypeT (e : AbsBasilIR.typeT) : showable = match e with - AbsBasilIR.TypeIntType inttype -> s2s "TypeIntType" >> c2s ' ' >> c2s '(' >> showIntType inttype >> c2s ')' - | AbsBasilIR.TypeBoolType booltype -> s2s "TypeBoolType" >> c2s ' ' >> c2s '(' >> showBoolType booltype >> c2s ')' + AbsBasilIR.Type1IntType inttype -> s2s "Type1IntType" >> c2s ' ' >> c2s '(' >> showIntType inttype >> c2s ')' + | AbsBasilIR.Type1BoolType booltype -> s2s "Type1BoolType" >> c2s ' ' >> c2s '(' >> showBoolType booltype >> c2s ')' + | AbsBasilIR.Type1BVType bvtype -> s2s "Type1BVType" >> c2s ' ' >> c2s '(' >> showBVType bvtype >> c2s ')' + | AbsBasilIR.Type1Paren (openparen, type', closeparen) -> s2s "Type1Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.TypeMapType maptype -> s2s "TypeMapType" >> c2s ' ' >> c2s '(' >> showMapType maptype >> c2s ')' - | AbsBasilIR.TypeBVType bvtype -> s2s "TypeBVType" >> c2s ' ' >> c2s '(' >> showBVType bvtype >> c2s ')' - | AbsBasilIR.Type1 (openparen, type', closeparen) -> s2s "Type1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + +and showExpr (e : AbsBasilIR.expr) : showable = match e with + AbsBasilIR.Expr_Literal value -> s2s "Expr_Literal" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Local localvar -> s2s "Expr_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.Expr_Global globalvar -> s2s "Expr_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' + | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> s2s "Expr_Forall" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> s2s "Expr_Exists" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> s2s "Expr_Lambda" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> s2s "Expr_Old" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Binary (binop, openparen, expr0, expr, closeparen) -> s2s "Expr_Binary" >> c2s ' ' >> c2s '(' >> showBinOp binop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> s2s "Expr_Assoc" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> s2s "Expr_Unary" >> c2s ' ' >> c2s '(' >> showUnOp unop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadBe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadLe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> s2s "Expr_ZeroExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> s2s "Expr_SignExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Extract (openparen, intval0, intval, expr, closeparen) -> s2s "Expr_Extract" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval0 >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> s2s "Expr_Concat" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> s2s "Expr_Match" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' and showIntVal (e : AbsBasilIR.intVal) : showable = match e with @@ -136,10 +159,8 @@ and showStmt (e : AbsBasilIR.stmt) : showable = match e with | AbsBasilIR.Stmt_ScalarStore (lvar, expr) -> s2s "Stmt_ScalarStore" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showExpr expr >> c2s ')' | AbsBasilIR.Stmt_ScalarLoad (lvar, var) -> s2s "Stmt_ScalarLoad" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showVar var >> c2s ')' | AbsBasilIR.Stmt_MultiAssign (openparen, assignments, closeparen) -> s2s "Stmt_MultiAssign" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showAssignment assignments >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Stmt_Load (lvar, endian, globalident, expr, intval) -> s2s "Stmt_Load" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' - | AbsBasilIR.Stmt_Store (endian, globalident, expr0, expr, intval) -> s2s "Stmt_Store" >> c2s ' ' >> c2s '(' >> showEndian endian >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' - | AbsBasilIR.Stmt_Load_Var (lvar, endian, var, expr, intval) -> s2s "Stmt_Load_Var" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' - | AbsBasilIR.Stmt_Store_Var (lvar, endian, var, expr0, expr, intval) -> s2s "Stmt_Store_Var" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' + | AbsBasilIR.Stmt_Load (lvar, endian, var, expr, intval) -> s2s "Stmt_Load" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' + | AbsBasilIR.Stmt_Store (lvar, endian, var, expr0, expr, intval) -> s2s "Stmt_Store" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' | AbsBasilIR.Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> s2s "Stmt_DirectCall" >> c2s ' ' >> c2s '(' >> showLVars lvars >> s2s ", " >> showProcIdent procident >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showCallParams callparams >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Stmt_IndirectCall expr -> s2s "Stmt_IndirectCall" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' | AbsBasilIR.Stmt_Assume expr -> s2s "Stmt_Assume" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' @@ -227,7 +248,6 @@ and showAttribSet (e : AbsBasilIR.attribSet) : showable = match e with and showAttr (e : AbsBasilIR.attr) : showable = match e with AbsBasilIR.Attr_Map (beginrec, attrkeyvalues, endrec) -> s2s "Attr_Map" >> c2s ' ' >> c2s '(' >> showBeginRec beginrec >> s2s ", " >> showList showAttrKeyValue attrkeyvalues >> s2s ", " >> showEndRec endrec >> c2s ')' | AbsBasilIR.Attr_List (beginlist, attrs, endlist) -> s2s "Attr_List" >> c2s ' ' >> c2s '(' >> showBeginList beginlist >> s2s ", " >> showList showAttr attrs >> s2s ", " >> showEndList endlist >> c2s ')' - | AbsBasilIR.Attr_Lit value -> s2s "Attr_Lit" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' | AbsBasilIR.Attr_Expr expr -> s2s "Attr_Expr" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' | AbsBasilIR.Attr_Str str -> s2s "Attr_Str" >> c2s ' ' >> c2s '(' >> showStr str >> c2s ')' @@ -248,29 +268,6 @@ and showValue (e : AbsBasilIR.value) : showable = match e with | AbsBasilIR.Value_False -> s2s "Value_False" -and showExpr (e : AbsBasilIR.expr) : showable = match e with - AbsBasilIR.Expr_Literal value -> s2s "Expr_Literal" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Local localvar -> s2s "Expr_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.Expr_Global globalvar -> s2s "Expr_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' - | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> s2s "Expr_Forall" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> s2s "Expr_Exists" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> s2s "Expr_Lambda" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> s2s "Expr_Old" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Binary (binop, openparen, expr0, expr, closeparen) -> s2s "Expr_Binary" >> c2s ' ' >> c2s '(' >> showBinOp binop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> s2s "Expr_Assoc" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> s2s "Expr_Unary" >> c2s ' ' >> c2s '(' >> showUnOp unop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadBe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadLe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> s2s "Expr_ZeroExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> s2s "Expr_SignExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Extract (openparen, intval0, intval, expr, closeparen) -> s2s "Expr_Extract" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval0 >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> s2s "Expr_Concat" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> s2s "Expr_Match" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 34afd676..6958d779 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -115,20 +115,43 @@ and transBoolType (x : boolType) : result = match x with BoolType1 booltype -> failure x -and transMapType (x : mapType) : result = match x with - MapType1 (type'0, type') -> failure x - - and transBVType (x : bVType) : result = match x with BVType1 bvtype -> failure x +and transMapType (x : mapType) : result = match x with + MapType1 (type'0, type') -> failure x + + and transType (x : typeT) : result = match x with - TypeIntType inttype -> failure x - | TypeBoolType booltype -> failure x + Type1IntType inttype -> failure x + | Type1BoolType booltype -> failure x + | Type1BVType bvtype -> failure x + | Type1Paren (openparen, type', closeparen) -> failure x | TypeMapType maptype -> failure x - | TypeBVType bvtype -> failure x - | Type1 (openparen, type', closeparen) -> failure x + + +and transExpr (x : expr) : result = match x with + Expr_Literal value -> failure x + | Expr_Paren (openparen, expr, closeparen) -> failure x + | Expr_Local localvar -> failure x + | Expr_Global globalvar -> failure x + | Expr_Forall (attribset, lambdadef) -> failure x + | Expr_Exists (attribset, lambdadef) -> failure x + | Expr_Lambda (attribset, lambdadef) -> failure x + | Expr_Old (openparen, expr, closeparen) -> failure x + | Expr_FunctionOp (expr, openparen, exprs, closeparen) -> failure x + | Expr_Binary (binop, openparen, expr0, expr, closeparen) -> failure x + | Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> failure x + | Expr_Unary (unop, openparen, expr, closeparen) -> failure x + | Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> failure x + | Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> failure x + | Expr_ZeroExtend (openparen, intval, expr, closeparen) -> failure x + | Expr_SignExtend (openparen, intval, expr, closeparen) -> failure x + | Expr_Extract (openparen, intval0, intval, expr, closeparen) -> failure x + | Expr_Concat (openparen, exprs, closeparen) -> failure x + | Expr_Match (expr, openparen, cases, closeparen) -> failure x + | Expr_Cases (openparen, cases, closeparen) -> failure x and transIntVal (x : intVal) : result = match x with @@ -156,10 +179,8 @@ and transStmt (x : stmt) : result = match x with | Stmt_ScalarStore (lvar, expr) -> failure x | Stmt_ScalarLoad (lvar, var) -> failure x | Stmt_MultiAssign (openparen, assignments, closeparen) -> failure x - | Stmt_Load (lvar, endian, globalident, expr, intval) -> failure x - | Stmt_Store (endian, globalident, expr0, expr, intval) -> failure x - | Stmt_Load_Var (lvar, endian, var, expr, intval) -> failure x - | Stmt_Store_Var (lvar, endian, var, expr0, expr, intval) -> failure x + | Stmt_Load (lvar, endian, var, expr, intval) -> failure x + | Stmt_Store (lvar, endian, var, expr0, expr, intval) -> failure x | Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> failure x | Stmt_IndirectCall expr -> failure x | Stmt_Assume expr -> failure x @@ -247,7 +268,6 @@ and transAttribSet (x : attribSet) : result = match x with and transAttr (x : attr) : result = match x with Attr_Map (beginrec, attrkeyvalues, endrec) -> failure x | Attr_List (beginlist, attrs, endlist) -> failure x - | Attr_Lit value -> failure x | Attr_Expr expr -> failure x | Attr_Str str -> failure x @@ -268,29 +288,6 @@ and transValue (x : value) : result = match x with | Value_False -> failure x -and transExpr (x : expr) : result = match x with - Expr_Literal value -> failure x - | Expr_Paren (openparen, expr, closeparen) -> failure x - | Expr_Local localvar -> failure x - | Expr_Global globalvar -> failure x - | Expr_Forall (attribset, lambdadef) -> failure x - | Expr_Exists (attribset, lambdadef) -> failure x - | Expr_Lambda (attribset, lambdadef) -> failure x - | Expr_Old (openparen, expr, closeparen) -> failure x - | Expr_FunctionOp (expr, openparen, exprs, closeparen) -> failure x - | Expr_Binary (binop, openparen, expr0, expr, closeparen) -> failure x - | Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> failure x - | Expr_Unary (unop, openparen, expr, closeparen) -> failure x - | Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> failure x - | Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> failure x - | Expr_ZeroExtend (openparen, intval, expr, closeparen) -> failure x - | Expr_SignExtend (openparen, intval, expr, closeparen) -> failure x - | Expr_Extract (openparen, intval0, intval, expr, closeparen) -> failure x - | Expr_Concat (openparen, exprs, closeparen) -> failure x - | Expr_Match (expr, openparen, cases, closeparen) -> failure x - | Expr_Cases (openparen, cases, closeparen) -> failure x - - and transLambdaParen (x : lambdaParen) : result = match x with LambdaParenLocalVar localvar -> failure x | LambdaParen1 (openparen, localvar, closeparen) -> failure x From 23b14046dcb9a83c36186f10e59c6e8c5deb5f74 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 2 Mar 2026 22:11:30 +1000 Subject: [PATCH 11/43] highlight comments --- tree-sitter/queries/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tree-sitter/queries/highlights.scm b/tree-sitter/queries/highlights.scm index 67dc0492..d36fb50e 100644 --- a/tree-sitter/queries/highlights.scm +++ b/tree-sitter/queries/highlights.scm @@ -118,3 +118,5 @@ (token_EndList) ] @punctuation.bracket (token_Str) @string +(token_CommentMulti) @comment +(token_CommentSingle) @comment From d4d905f1a1b46284fb0fdb47204cf8750b508faf Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 09:54:50 +1000 Subject: [PATCH 12/43] restore naming and fix compilation --- lib/fe/AbsBasilIR.ml | 8 ++++---- lib/fe/BasilIR.cf | 6 ++++-- lib/fe/ParBasilIR.mly | 8 ++++---- lib/fe/PrintBasilIR.ml | 8 ++++---- lib/fe/ShowBasilIR.ml | 8 ++++---- lib/fe/SkelBasilIR.ml | 8 ++++---- lib/loadir.ml | 28 +++------------------------- tree-sitter/grammar.js | 8 ++++---- 8 files changed, 31 insertions(+), 51 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 816e31c3..f14d157c 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -56,10 +56,10 @@ and mapType = MapType1 of typeT * typeT and typeT = - Type1IntType of intType - | Type1BoolType of boolType - | Type1BVType of bVType - | Type1Paren of openParen * typeT * closeParen + TypeIntType of intType + | TypeBoolType of boolType + | TypeBVType of bVType + | TypeParen of openParen * typeT * closeParen | TypeMapType of mapType and expr = diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 0cd9d756..e9733c77 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -68,8 +68,10 @@ BVType1 . BVType ::= BVTYPE ; -- map types are right associative. left of -> cannot be another MapType. MapType1 . MapType ::= Type1 "->" Type ; -rules Type1 ::= IntType | BoolType | BVType ; -Type1Paren . Type1 ::= OpenParen Type CloseParen; +TypeIntType . Type1 ::= IntType ; +TypeBoolType . Type1 ::= BoolType ; +TypeBVType . Type1 ::= BVType ; +TypeParen . Type1 ::= OpenParen Type CloseParen; rules Type ::= MapType; _ . Type ::= Type1; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 22c31478..708abc78 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -449,10 +449,10 @@ bVType : bVTYPE { BVType1 $1 } mapType : type1 SYMB3 typeT { MapType1 ($1, $3) } ; -type1 : intType { Type1IntType $1 } - | boolType { Type1BoolType $1 } - | bVType { Type1BVType $1 } - | openParen typeT closeParen { Type1Paren ($1, $2, $3) } +type1 : intType { TypeIntType $1 } + | boolType { TypeBoolType $1 } + | bVType { TypeBVType $1 } + | openParen typeT closeParen { TypeParen ($1, $2, $3) } ; typeT : mapType { TypeMapType $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index e9da2a1c..1173ee84 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -188,10 +188,10 @@ and prtMapType (i:int) (e : AbsBasilIR.mapType) : doc = match e with and prtTypeT (i:int) (e : AbsBasilIR.typeT) : doc = match e with - AbsBasilIR.Type1IntType inttype -> prPrec i 1 (concatD [prtIntType 0 inttype]) - | AbsBasilIR.Type1BoolType booltype -> prPrec i 1 (concatD [prtBoolType 0 booltype]) - | AbsBasilIR.Type1BVType bvtype -> prPrec i 1 (concatD [prtBVType 0 bvtype]) - | AbsBasilIR.Type1Paren (openparen, type_, closeparen) -> prPrec i 1 (concatD [prtOpenParen 0 openparen ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) + AbsBasilIR.TypeIntType inttype -> prPrec i 1 (concatD [prtIntType 0 inttype]) + | AbsBasilIR.TypeBoolType booltype -> prPrec i 1 (concatD [prtBoolType 0 booltype]) + | AbsBasilIR.TypeBVType bvtype -> prPrec i 1 (concatD [prtBVType 0 bvtype]) + | AbsBasilIR.TypeParen (openparen, type_, closeparen) -> prPrec i 1 (concatD [prtOpenParen 0 openparen ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) | AbsBasilIR.TypeMapType maptype -> prPrec i 0 (concatD [prtMapType 0 maptype]) and prtTypeTListBNFC i es : doc = match (i, es) with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 38812a40..40094d10 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -104,10 +104,10 @@ and showMapType (e : AbsBasilIR.mapType) : showable = match e with and showTypeT (e : AbsBasilIR.typeT) : showable = match e with - AbsBasilIR.Type1IntType inttype -> s2s "Type1IntType" >> c2s ' ' >> c2s '(' >> showIntType inttype >> c2s ')' - | AbsBasilIR.Type1BoolType booltype -> s2s "Type1BoolType" >> c2s ' ' >> c2s '(' >> showBoolType booltype >> c2s ')' - | AbsBasilIR.Type1BVType bvtype -> s2s "Type1BVType" >> c2s ' ' >> c2s '(' >> showBVType bvtype >> c2s ')' - | AbsBasilIR.Type1Paren (openparen, type', closeparen) -> s2s "Type1Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + AbsBasilIR.TypeIntType inttype -> s2s "TypeIntType" >> c2s ' ' >> c2s '(' >> showIntType inttype >> c2s ')' + | AbsBasilIR.TypeBoolType booltype -> s2s "TypeBoolType" >> c2s ' ' >> c2s '(' >> showBoolType booltype >> c2s ')' + | AbsBasilIR.TypeBVType bvtype -> s2s "TypeBVType" >> c2s ' ' >> c2s '(' >> showBVType bvtype >> c2s ')' + | AbsBasilIR.TypeParen (openparen, type', closeparen) -> s2s "TypeParen" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.TypeMapType maptype -> s2s "TypeMapType" >> c2s ' ' >> c2s '(' >> showMapType maptype >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 6958d779..6b93f506 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -124,10 +124,10 @@ and transMapType (x : mapType) : result = match x with and transType (x : typeT) : result = match x with - Type1IntType inttype -> failure x - | Type1BoolType booltype -> failure x - | Type1BVType bvtype -> failure x - | Type1Paren (openparen, type', closeparen) -> failure x + TypeIntType inttype -> failure x + | TypeBoolType booltype -> failure x + | TypeBVType bvtype -> failure x + | TypeParen (openparen, type', closeparen) -> failure x | TypeMapType maptype -> failure x diff --git a/lib/loadir.ml b/lib/loadir.ml index 08bb4dc5..47afed87 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -413,7 +413,7 @@ module BasilASTLoader = struct | TypeBoolType booltype -> Boolean | TypeMapType maptype -> transMapType maptype | TypeBVType (BVType1 bvtype) -> transBVTYPE bvtype - | Type1 (_, typeT, _) -> trans_type typeT + | TypeParen (_, typeT, _) -> trans_type typeT and transIntVal (x : intVal) : PrimInt.t = match x with @@ -452,7 +452,6 @@ module BasilASTLoader = struct match attr with | Attr_Map (_, keyvals, _) -> `Assoc (trans_attr_kv ~binds p_st keyvals) | Attr_List (_, ls, _) -> `List (List.map (trans_attr ~binds p_st) ls) - | Attr_Lit v -> ( match trans_value v with #Ops.AllOps.const as v -> v) | Attr_Expr expr -> `Expr (trans_expr ~binds p_st expr) | Attr_Str s -> `String (trans_str s) @@ -472,7 +471,7 @@ module BasilASTLoader = struct let open Stmt in match stmt with | Stmt_Nop -> (p_st, `None) - | Stmt_Load_Var (lvar, endian, var, expr, intval) -> + | Stmt_Load (lvar, endian, var, expr, intval) -> let endian = trans_endian endian in let rhs = trans_var p_st var in let size = transIntVal intval |> Z.to_int in @@ -485,7 +484,7 @@ module BasilASTLoader = struct rhs; addr = Addr { addr = trans_expr p_st expr; endian; size }; }) ) - | Stmt_Store_Var (lhs, endian, var, addr, value, intval) -> + | Stmt_Store (lhs, endian, var, addr, value, intval) -> let endian = trans_endian endian in let size = transIntVal intval |> Z.to_int in let rhs = trans_var p_st var in @@ -529,27 +528,6 @@ module BasilASTLoader = struct in let p_st, assigns = List.fold_left f (p_st, []) assigns in (p_st, `Stmt (Instr_Assign (List.rev assigns))) - | Stmt_Load (lvar, endian, bident, expr, intval) -> - let endian = trans_endian endian in - let rhs = lookup_global_decl bident p_st in - let addr = trans_expr p_st expr in - let p_st, lhs = trans_lvar p_st lvar in - let size = transIntVal intval |> Z.to_int in - ( p_st, - `Stmt (Instr_Load { lhs; rhs; addr = Addr { addr; endian; size } }) ) - | Stmt_Store (endian, bident, addr, value, intval) -> - let endian = trans_endian endian in - let size = transIntVal intval |> Z.to_int in - let mem = lookup_global_decl bident p_st in - ( p_st, - `Stmt - (Instr_Store - { - lhs = mem; - rhs = mem; - value = trans_expr p_st value; - addr = Addr { addr = trans_expr p_st addr; size; endian }; - }) ) | Stmt_DirectCall (calllvars, bident, o, exprs, c) -> let n = unsafe_unsigil (`Proc bident) in let procid = diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index f65f6bd1..d73832e1 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -105,13 +105,13 @@ module.exports = grammar({ seq($.Type1, "->", $.Type), Type1: $ => choice( - // Type1IntType. Type1 ::= IntType ; + // TypeIntType. Type1 ::= IntType ; $.IntType, - // Type1BoolType. Type1 ::= BoolType ; + // TypeBoolType. Type1 ::= BoolType ; $.BoolType, - // Type1BVType. Type1 ::= BVType ; + // TypeBVType. Type1 ::= BVType ; $.BVType, - // Type1Paren. Type1 ::= OpenParen Type CloseParen ; + // TypeParen. Type1 ::= OpenParen Type CloseParen ; seq($.token_OpenParen, $.Type, $.token_CloseParen) ), Type: $ => From 9e2cdd5563b6163da474e15fe20311f7d551b211 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 11:08:10 +1000 Subject: [PATCH 13/43] parenthesise apply fun function --- lib/lang/expr.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang/expr.ml b/lib/lang/expr.ml index 017f179b..f996c0a9 100644 --- a/lib/lang/expr.ml +++ b/lib/lang/expr.ml @@ -386,7 +386,7 @@ module BasilExpr = struct ] | ApplyFun { func = n; args = es } -> fill nil - [ n ^ a ^ bracket "(" (nest 2 (fill (text "," ^ newline) es)) ")" ] + [ bracket "(" n ")" ^ a ^ bracket "(" (nest 2 (fill (text "," ^ newline) es)) ")" ] | Binding { bound = vs; in_body = b } -> fill (text " ") (List.map (fun v -> bracket "(" (Var.pretty v) ")") vs) ^ text " :: " ^ a ^ bracket "(" b ")" From 3826d620e8abf1b5f50951066ac18bf3dcc1230f Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 11:21:32 +1000 Subject: [PATCH 14/43] use semicolons again for FunSpec. some highlighting for funspec --- lib/fe/BasilIR.cf | 2 +- lib/fe/ParBasilIR.mly | 2 +- lib/fe/PrintBasilIR.ml | 3 +-- tree-sitter/grammar.js | 4 ++-- tree-sitter/queries/highlights.scm | 22 ++++++++++++++++------ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index e9733c77..13f20958 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -278,7 +278,7 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= "rely" Expr; ProgSpec_Guarantee . ProgSpec ::= "guarantee" Expr; -terminator FunSpec "\n"; +terminator FunSpec ";"; {- last semicolon terminates the prog definitino -} separator nonempty ProgSpec "\n"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 708abc78..fd5fd499 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -793,7 +793,7 @@ progSpec : KW_rely expr { ProgSpec_Rely $2 } ; funSpec_list : /* empty */ { [] } - | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } + | funSpec SYMB1 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; progSpec_list : progSpec { (fun x -> [x]) $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 1173ee84..7c9a1fb4 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -529,8 +529,7 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render " -" ; prtFunSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) | AbsBasilIR.VarSpec_Empty -> prPrec i 0 (concatD []) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index d73832e1..d12d07d5 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -703,8 +703,8 @@ module.exports = grammar({ choice( // []. [FunSpec] ::= ; choice(), - // (:). [FunSpec] ::= FunSpec [FunSpec] ; - seq($.FunSpec, optional($.list_FunSpec)) + // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; + seq($.FunSpec, ";", optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( diff --git a/tree-sitter/queries/highlights.scm b/tree-sitter/queries/highlights.scm index d36fb50e..5e563534 100644 --- a/tree-sitter/queries/highlights.scm +++ b/tree-sitter/queries/highlights.scm @@ -22,12 +22,20 @@ "var" @keyword "memory" @keyword "shared" @keyword +"rely" @keyword +"guarantee" @keyword +"modifies" @keyword +"captures" @keyword +"forall" @keyword +"exists" @keyword +"fun" @keyword +"old" @keyword -(IntVal) @constant -(token_IntegerHex) @constant -(token_IntegerDec) @constant -"true" @constant -"false" @constant +(IntVal) @number +(token_IntegerHex) @number +(token_IntegerDec) @number +"true" @constant.builtin +"false" @constant.builtin (Type) @type (token_BVTYPE) @type.builtin @@ -107,10 +115,12 @@ (token_EndList) (token_BeginRec) (token_EndRec) + (token_OpenParen) + (token_CloseParen) ] @punctuation.bracket [ ";" "," ] @punctuation.delimiter -[ ":" "=" ":=" ] @punctuation +[ ":" "=" ":=" "::" ] @punctuation [ "(" ")" (token_BeginRec) (token_EndRec) From dc898fa8f8f3adbc4cfca3fbe871cf714bd0f3c4 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 11:32:43 +1000 Subject: [PATCH 15/43] fix maptype parsing --- lib/fe/BasilIR.cf | 4 ++-- lib/fe/ParBasilIR.mly | 1 + lib/fe/dune | 9 +++++++++ tree-sitter/grammar.js | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 13f20958..720e965f 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -73,8 +73,8 @@ TypeBoolType . Type1 ::= BoolType ; TypeBVType . Type1 ::= BVType ; TypeParen . Type1 ::= OpenParen Type CloseParen; -rules Type ::= MapType; -_ . Type ::= Type1; +TypeMapType . Type ::= MapType; +coercions Type 1; separator Expr "," ; coercions Expr 2; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index fd5fd499..95b90459 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -453,6 +453,7 @@ type1 : intType { TypeIntType $1 } | boolType { TypeBoolType $1 } | bVType { TypeBVType $1 } | openParen typeT closeParen { TypeParen ($1, $2, $3) } + | SYMB7 typeT SYMB8 { $2 } ; typeT : mapType { TypeMapType $1 } diff --git a/lib/fe/dune b/lib/fe/dune index 0ccb4aee..a73bf46f 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -34,3 +34,12 @@ (mode promote) (action (run bnfc --ocaml-menhir -o . BasilIR.cf))) + +(executable + (name TestBasilIR) + (public_name TestBasilIR) + (package bincaml) + (modes exe byte) + (modules TestBasilIR) + (flags (:standard -open BasilIR)) + (libraries bincaml.basilir)) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index d12d07d5..dd6e277b 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -112,7 +112,9 @@ module.exports = grammar({ // TypeBVType. Type1 ::= BVType ; $.BVType, // TypeParen. Type1 ::= OpenParen Type CloseParen ; - seq($.token_OpenParen, $.Type, $.token_CloseParen) + seq($.token_OpenParen, $.Type, $.token_CloseParen), + // _. Type1 ::= "(" Type ")" ; + seq("(", $.Type, ")") ), Type: $ => choice( From 16052a2d0df722db48065ab3d3b8ccf304b2e165 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 11:41:58 +1000 Subject: [PATCH 16/43] WHHHYYYYYYYYYYYYYYYY does it break everything :(((() --- lib/fe/BasilIR.cf | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 720e965f..4e0a2af0 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -71,7 +71,7 @@ MapType1 . MapType ::= Type1 "->" Type ; TypeIntType . Type1 ::= IntType ; TypeBoolType . Type1 ::= BoolType ; TypeBVType . Type1 ::= BVType ; -TypeParen . Type1 ::= OpenParen Type CloseParen; +TypeParen . Type1 ::= OpenParen Type CloseParen; TypeMapType . Type ::= MapType; coercions Type 1; @@ -186,9 +186,6 @@ Attr_Str . Attr ::= Str ; rules Params ::= LocalIdent ":" Type ; separator Params "," ; -rules FunParams ::= LocalIdent ":" Type | OpenParen LocalIdent ":" Type CloseParen ; -separator FunParams " " ; - {- EXPRESSIONS -} Value_BV . Value ::= BVVal; From 20a9bb8cceb8744497d1bb19c26cccd0fd197c08 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 14:44:49 +1000 Subject: [PATCH 17/43] making progress... bnfc bug??! --- lib/fe/AbsBasilIR.ml | 6 +- lib/fe/BasilIR.cf | 15 +- lib/fe/LexBasilIR.mll | 2 +- lib/fe/ParBasilIR.mly | 23 +-- lib/fe/PrintBasilIR.ml | 9 +- lib/fe/ShowBasilIR.ml | 7 +- lib/fe/SkelBasilIR.ml | 7 +- lib/fe/dune | 6 +- lib/loadir.ml | 58 ++---- lib/transforms/may_read_uninit.ml | 24 ++- test/analysis/ide_live.ml | 34 ++-- test/analysis/ssadfg.ml | 3 +- test/cram/basicssa.t | 322 +----------------------------- test/cram/expr_smt.t | 78 +------- test/cram/roundtrip.t | 7 +- test/cram/typefail.t | 66 +----- test/cram/typepass.t | 6 +- test/lang/interp.ml | 94 ++------- test/lang/stmt.ml | 34 ++-- tree-sitter/grammar.js | 22 +- 20 files changed, 135 insertions(+), 688 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index f14d157c..958190f9 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -165,7 +165,7 @@ and phiAssign = and block = Block_NoPhi of blockIdent * attribSet * beginList * stmtWithAttrib list * jumpWithAttrib * endList - | Block_Phi of blockIdent * attribSet * beginList * openParen * phiAssign list * closeParen * stmtWithAttrib list * jumpWithAttrib * endList + | Block_Phi of blockIdent * attribSet * openParen * phiAssign list * closeParen * beginList * stmtWithAttrib list * jumpWithAttrib * endList and attrKeyValue = AttrKeyValue1 of bIdent * attr @@ -183,10 +183,6 @@ and attr = and params = Params1 of localIdent * typeT -and funParams = - FunParams1 of localIdent * typeT - | FunParams2 of openParen * localIdent * typeT * closeParen - and value = Value_BV of bVVal | Value_Int of intVal diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 4e0a2af0..daa0d694 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -59,7 +59,7 @@ Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ; Decl_ProgWithSpec . Decl ::= "prog" "entry" ProcIdent AttribSet [ ProgSpec ] ; Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [ FunSpec ] ProcDef ; -ProcDef_Empty . ProcDef ::= ""; +ProcDef_Empty . ProcDef ::= ; ProcDef_Some . ProcDef ::= BeginList [Block] EndList ; IntType1 . IntType ::= INTTYPE ; @@ -118,13 +118,13 @@ Stmt_Store . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; -LVars_Empty . LVars ::= ""; +LVars_Empty . LVars ::= ; LVars_LocalList . LVars ::= "var" OpenParen [ LocalVar ] CloseParen ":=" ; LVars_List . LVars ::= OpenParen [ LVar ] CloseParen ":="; NamedLVars_List . LVars ::= OpenParen [NamedCallReturn] CloseParen ":="; rules NamedCallArg ::= LocalIdent "=" Expr; -separator NamedCallArg "," ; +separator nonempty NamedCallArg "," ; CallParams_Exprs . CallParams ::= [Expr]; CallParams_Named . CallParams ::= [NamedCallArg]; @@ -164,8 +164,9 @@ Block_NoPhi . Block ::= "block" BlockIdent AttribSet BeginList [StmtWithAttrib] JumpWithAttrib ";" EndList ; -Block_Phi . Block ::= "block" BlockIdent AttribSet BeginList - OpenParen [PhiAssign] CloseParen ";" +Block_Phi . Block ::= "block" BlockIdent AttribSet + OpenParen [PhiAssign] CloseParen + BeginList [StmtWithAttrib] JumpWithAttrib ";" EndList ; @@ -174,7 +175,7 @@ separator AttrKeyValue ";"; -- in BNFC, `separator` also allows trailing AttribSet_Some . AttribSet ::= BeginRec [ AttrKeyValue ] EndRec; -AttribSet_Empty . AttribSet ::= "" ; +AttribSet_Empty . AttribSet ::= ; separator Attr ";" ; @@ -267,7 +268,7 @@ FunSpec_Modifies . FunSpec ::= "modifies" [GlobalVar]; VarSpec_Classification . VarSpec ::= "classification" Expr; -VarSpec_Empty . VarSpec ::= ""; +VarSpec_Empty . VarSpec ::= ; FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 4c55f342..4cf894f3 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -53,7 +53,7 @@ let _idchar = _letter | _digit | ['_' '\''] (* identifier character *) let _universal = _ (* universal: any character *) (* reserved words consisting of special symbols *) -let rsyms = ";" | "," | "->" | "::" | ":" | "=" | "(" | ")" | ":=" | "mem:=" | "_" | "|" +let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" (* user-defined token types *) let bVTYPE = "bv" _digit + diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 95b90459..93a786e1 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -46,7 +46,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pExpr_list pExpr pExpr1 pExpr2 pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pFunParams pFunParams_list pValue pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pExpr_list pExpr pExpr1 pExpr2 pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -102,8 +102,6 @@ open Lexing %type pAttr %type pParams %type pParams_list -%type pFunParams -%type pFunParams_list %type pValue %type pLambdaParen %type pLambdaParen_list @@ -184,8 +182,6 @@ open Lexing %type attr %type params %type params_list -%type funParams -%type funParams_list %type value %type lambdaParen %type lambdaParen_list @@ -341,10 +337,6 @@ pParams : params TOK_EOF { $1 }; pParams_list : params_list TOK_EOF { $1 }; -pFunParams : funParams TOK_EOF { $1 }; - -pFunParams_list : funParams_list TOK_EOF { $1 }; - pValue : value TOK_EOF { $1 }; pLambdaParen : lambdaParen TOK_EOF { $1 }; @@ -565,8 +557,7 @@ lVars : /* empty */ { LVars_Empty } namedCallArg : localIdent SYMB6 expr { NamedCallArg1 ($1, $3) } ; -namedCallArg_list : /* empty */ { [] } - | namedCallArg { (fun x -> [x]) $1 } +namedCallArg_list : namedCallArg { (fun x -> [x]) $1 } | namedCallArg SYMB2 namedCallArg_list { (fun (x,xs) -> x::xs) ($1, $3) } ; @@ -620,7 +611,7 @@ phiAssign_list : /* empty */ { [] } ; block : KW_block blockIdent attribSet beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_NoPhi ($2, $3, $4, $5, $6, $8) } - | KW_block blockIdent attribSet beginList openParen phiAssign_list closeParen SYMB1 stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $9, $10, $12) } + | KW_block blockIdent attribSet openParen phiAssign_list closeParen beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $8, $9, $11) } ; attrKeyValue : bIdent SYMB6 attr { AttrKeyValue1 ($1, $3) } @@ -654,14 +645,6 @@ params_list : /* empty */ { [] } | params SYMB2 params_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -funParams : localIdent SYMB5 typeT { FunParams1 ($1, $3) } - | openParen localIdent SYMB5 typeT closeParen { FunParams2 ($1, $2, $4, $5) } - ; - -funParams_list : /* empty */ { [] } - | funParams funParams_list { (fun (x,xs) -> x::xs) ($1, $2) } - ; - value : bVVal { Value_BV $1 } | intVal { Value_Int $1 } | KW_true { Value_True } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 7c9a1fb4..7edc3d38 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -349,7 +349,7 @@ and prtPhiAssignListBNFC i es : doc = match (i, es) with | (_,x::xs) -> (concatD [prtPhiAssign 0 x ; render "," ; prtPhiAssignListBNFC 0 xs]) and prtBlock (i:int) (e : AbsBasilIR.block) : doc = match e with AbsBasilIR.Block_NoPhi (blockident, attribset, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> prPrec i 0 (concatD [render "block" ; prtBlockIdent 0 blockident ; prtAttribSet 0 attribset ; prtBeginList 0 beginlist ; prtStmtWithAttribListBNFC 0 stmtwithattribs ; prtJumpWithAttrib 0 jumpwithattrib ; render ";" ; prtEndList 0 endlist]) - | AbsBasilIR.Block_Phi (blockident, attribset, beginlist, openparen, phiassigns, closeparen, stmtwithattribs, jumpwithattrib, endlist) -> prPrec i 0 (concatD [render "block" ; prtBlockIdent 0 blockident ; prtAttribSet 0 attribset ; prtBeginList 0 beginlist ; prtOpenParen 0 openparen ; prtPhiAssignListBNFC 0 phiassigns ; prtCloseParen 0 closeparen ; render ";" ; prtStmtWithAttribListBNFC 0 stmtwithattribs ; prtJumpWithAttrib 0 jumpwithattrib ; render ";" ; prtEndList 0 endlist]) + | AbsBasilIR.Block_Phi (blockident, attribset, openparen, phiassigns, closeparen, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> prPrec i 0 (concatD [render "block" ; prtBlockIdent 0 blockident ; prtAttribSet 0 attribset ; prtOpenParen 0 openparen ; prtPhiAssignListBNFC 0 phiassigns ; prtCloseParen 0 closeparen ; prtBeginList 0 beginlist ; prtStmtWithAttribListBNFC 0 stmtwithattribs ; prtJumpWithAttrib 0 jumpwithattrib ; render ";" ; prtEndList 0 endlist]) and prtBlockListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) @@ -384,13 +384,6 @@ and prtParamsListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtParams 0 x]) | (_,x::xs) -> (concatD [prtParams 0 x ; render "," ; prtParamsListBNFC 0 xs]) -and prtFunParams (i:int) (e : AbsBasilIR.funParams) : doc = match e with - AbsBasilIR.FunParams1 (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_]) - | AbsBasilIR.FunParams2 (openparen, localident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) - -and prtFunParamsListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunParams 0 x ; render " " ; prtFunParamsListBNFC 0 xs]) and prtValue (i:int) (e : AbsBasilIR.value) : doc = match e with AbsBasilIR.Value_BV bvval -> prPrec i 0 (concatD [prtBVVal 0 bvval]) | AbsBasilIR.Value_Int intval -> prPrec i 0 (concatD [prtIntVal 0 intval]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 40094d10..be8e3858 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -233,7 +233,7 @@ and showPhiAssign (e : AbsBasilIR.phiAssign) : showable = match e with and showBlock (e : AbsBasilIR.block) : showable = match e with AbsBasilIR.Block_NoPhi (blockident, attribset, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> s2s "Block_NoPhi" >> c2s ' ' >> c2s '(' >> showBlockIdent blockident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showBeginList beginlist >> s2s ", " >> showList showStmtWithAttrib stmtwithattribs >> s2s ", " >> showJumpWithAttrib jumpwithattrib >> s2s ", " >> showEndList endlist >> c2s ')' - | AbsBasilIR.Block_Phi (blockident, attribset, beginlist, openparen, phiassigns, closeparen, stmtwithattribs, jumpwithattrib, endlist) -> s2s "Block_Phi" >> c2s ' ' >> c2s '(' >> showBlockIdent blockident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showBeginList beginlist >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showPhiAssign phiassigns >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showList showStmtWithAttrib stmtwithattribs >> s2s ", " >> showJumpWithAttrib jumpwithattrib >> s2s ", " >> showEndList endlist >> c2s ')' + | AbsBasilIR.Block_Phi (blockident, attribset, openparen, phiassigns, closeparen, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> s2s "Block_Phi" >> c2s ' ' >> c2s '(' >> showBlockIdent blockident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showPhiAssign phiassigns >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showBeginList beginlist >> s2s ", " >> showList showStmtWithAttrib stmtwithattribs >> s2s ", " >> showJumpWithAttrib jumpwithattrib >> s2s ", " >> showEndList endlist >> c2s ')' and showAttrKeyValue (e : AbsBasilIR.attrKeyValue) : showable = match e with @@ -256,11 +256,6 @@ and showParams (e : AbsBasilIR.params) : showable = match e with AbsBasilIR.Params1 (localident, type') -> s2s "Params1" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> c2s ')' -and showFunParams (e : AbsBasilIR.funParams) : showable = match e with - AbsBasilIR.FunParams1 (localident, type') -> s2s "FunParams1" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> c2s ')' - | AbsBasilIR.FunParams2 (openparen, localident, type', closeparen) -> s2s "FunParams2" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showValue (e : AbsBasilIR.value) : showable = match e with AbsBasilIR.Value_BV bvval -> s2s "Value_BV" >> c2s ' ' >> c2s '(' >> showBVVal bvval >> c2s ')' | AbsBasilIR.Value_Int intval -> s2s "Value_Int" >> c2s ' ' >> c2s '(' >> showIntVal intval >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 6b93f506..3d17605f 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -253,7 +253,7 @@ and transPhiAssign (x : phiAssign) : result = match x with and transBlock (x : block) : result = match x with Block_NoPhi (blockident, attribset, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> failure x - | Block_Phi (blockident, attribset, beginlist, openparen, phiassigns, closeparen, stmtwithattribs, jumpwithattrib, endlist) -> failure x + | Block_Phi (blockident, attribset, openparen, phiassigns, closeparen, beginlist, stmtwithattribs, jumpwithattrib, endlist) -> failure x and transAttrKeyValue (x : attrKeyValue) : result = match x with @@ -276,11 +276,6 @@ and transParams (x : params) : result = match x with Params1 (localident, type') -> failure x -and transFunParams (x : funParams) : result = match x with - FunParams1 (localident, type') -> failure x - | FunParams2 (openparen, localident, type', closeparen) -> failure x - - and transValue (x : value) : result = match x with Value_BV bvval -> failure x | Value_Int intval -> failure x diff --git a/lib/fe/dune b/lib/fe/dune index a73bf46f..b6b0bbbb 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -33,7 +33,11 @@ ParBasilIR.mly) (mode promote) (action - (run bnfc --ocaml-menhir -o . BasilIR.cf))) + (progn + (run bnfc --ocaml-menhir -o . BasilIR.cf) + ; HACK: BNFC incorrectly treats "(" ")" as a resword which prevents it + ; being lexed as an OpenParen/CloseParen which we need. + (run sed -i.bak "s_| \"(\" | \")\"__" LexBasilIR.mll)))) (executable (name TestBasilIR) diff --git a/lib/loadir.ml b/lib/loadir.ml index 47afed87..4711ecd4 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -603,7 +603,9 @@ module BasilASTLoader = struct and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = unpack_local_lvars ~bound p_st - @@ List.map (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) lvs + @@ List.map + (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) + lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in @@ -703,21 +705,21 @@ module BasilASTLoader = struct | Block_NoPhi ( BlockIdent (text_range, name), addrattr, - beginlist, + BeginList _, statements, jump, - endlist ) -> + EndList _ ) -> tx name [] statements jump | Block_Phi ( BlockIdent (text_range, name), addrattr, - beginlist, - _, + OpenParen _, phi, - _, + CloseParen _, + BeginList _, statements, jump, - endlist ) -> + EndList _ ) -> tx name phi statements jump and param_to_lvar (pp : params) : Var.t = @@ -728,12 +730,6 @@ module BasilASTLoader = struct match pp with | Params1 (LocalIdent (pos, id), t) -> (id, Var.create id (trans_type t)) - and fun_param_to_formal pp : string * Var.t = - match pp with - | FunParams1 (LocalIdent (pos, id), t) -> (id, Var.create id (trans_type t)) - | FunParams2 (_, LocalIdent (pos, id), t, _) -> - (id, Var.create id (trans_type t)) - and trans_funspec prog bound_post (spec : (Var.t, BasilExpr.t) Procedure.proc_spec) (s : funSpec) : (Var.t, BasilExpr.t) Procedure.proc_spec = @@ -1261,8 +1257,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1289,8 +1284,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1319,8 +1313,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1337,14 +1330,12 @@ proc @f (ZF_in:bv1, VF_in:bv1) -> (); let buf = Buffer.create 100 in BasilIR.ShowBasilIR.showModuleT prog buf; Buffer.output_buffer stdout buf; - [%expect - {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; + [%expect {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; let ast = ast_of_concrete_ast ~name:"boop" prog in print_endline @@ Containers_pp.Pretty.to_string ~width:80 (Program.prog_pretty ast.prog); - [%expect - {| + [%expect {| prog entry @f; proc @f(VF_in:bv1, ZF_in:bv1) -> () { } @@ -1373,8 +1364,7 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect - {| + [%expect {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1435,14 +1425,10 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect - {| - @entry: - read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) - written: $R0:bv64,$mem:(bv64->bv8) - @b: - read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) - written: $R0:bv64,$mem:(bv64->bv8) - @c: - read: $R0:bv64,$mem:(bv64->bv8) - written: $mem:(bv64->bv8) |}] + [%expect.unreachable] +[@@expect.uncaught_exn {| + ( "Parse error: string at lib/loadir.ml:1384::Loader__Loadir.(fun):21\ + \n21 | store le $mem $R1:bv64 0x0:bv32 32;\ + \n \027[1;31m^^^^^\027[0m\ + \n") + |}] diff --git a/lib/transforms/may_read_uninit.ml b/lib/transforms/may_read_uninit.ml index 4edb270d..9be9ef10 100644 --- a/lib/transforms/may_read_uninit.ml +++ b/lib/transforms/may_read_uninit.ml @@ -146,12 +146,18 @@ let%expect_test "fold_block" = ~phi:(fun a i -> a) ReadUninitAnalysis.bottom block in - [%expect - {| - ($stack->RU, R31_in->RU, R0_in->RU, _->⊥) - ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, _->⊥) - ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, _->⊥) - ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, _->⊥) - ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, load46_1->W, _->⊥) - ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, load46_1->W, R0_10->W, _->⊥) - |}] + [%expect.unreachable] +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + ( "Parse error: :3\ + \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ + \n \027[1;31m^^^^^\027[0m\ + \n") + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 + Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1190, characters 20-62 + Called from Transforms__May_read_uninit.(fun) in file "lib/transforms/may_read_uninit.ml", lines 125-138, characters 4-6 + Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 + |}] diff --git a/test/analysis/ide_live.ml b/test/analysis/ide_live.ml index 21dd2b4d..fec6c1e6 100644 --- a/test/analysis/ide_live.ml +++ b/test/analysis/ide_live.ml @@ -42,17 +42,20 @@ proc @main () -> () let _, results = IDELiveAnalysis.solve program in let main = program.entry_proc |> Option.get_exn_or "No entry proc" in print_lives results main; - [%expect - {| - @main - $mem:(bv64->bv8) - $x:bv64 - a:bv64 - e:bv64 - b:bv64 - c:bv64 - d:bv64 - |}] + [%expect.unreachable] +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + ( "Parse error: :20\ + \n20 | store le $mem $z:bv64 d:bv64 64;\ + \n \027[1;31m^^^^^\027[0m\ + \n") + Raised at Loader__Loadir.concrete_prog_ast_of_string in file "lib/loadir.ml", line 1105, characters 27-66 + Called from Loader__Loadir.ast_of_string in file "lib/loadir.ml", line 1217, characters 13-69 + Called from Bincaml_analysis_test__Ide_live.(fun) in file "test/analysis/ide_live.ml", lines 12-39, characters 4-6 + Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 + |}] let%expect_test "simple_call" = let lst = @@ -82,8 +85,7 @@ proc @fun (c:bv64, d:bv64) -> (out:bv64) let program = lst.prog in let _, results = IDELiveAnalysis.solve program in ID.Map.iter (fun id _ -> print_lives results id) program.procs; - [%expect - {| + [%expect {| @main b:bv64 y:bv64 @@ -131,8 +133,7 @@ proc @fun2 (f:bv64) -> (out2:bv64) let program = lst.prog in let _, results = IDELiveAnalysis.solve program in ID.Map.iter (fun id _ -> print_lives results id) program.procs; - [%expect - {| + [%expect {| @main b:bv64 y:bv64 @@ -197,8 +198,7 @@ proc @fun2 (f:bv64) -> (out2:bv64) let program = lst.prog in let _, results = IDELiveAnalysis.solve program in ID.Map.iter (fun id _ -> print_lives results id) program.procs; - [%expect - {| + [%expect {| @main b:bv64 y:bv64 diff --git a/test/analysis/ssadfg.ml b/test/analysis/ssadfg.ml index d17f13ec..5f0d38cc 100644 --- a/test/analysis/ssadfg.ml +++ b/test/analysis/ssadfg.ml @@ -72,8 +72,7 @@ proc @main_4196260 () -> () (Analysis.Defuse_bool.IsZeroLattice.show v)) in print_endline f; - [%expect - {| + [%expect {| CF_out->Top NF_out->NonZero R0_out->Zero diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index 2689b020..80734855 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,331 +2,31 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il after.il): Parse error: after.il:20 - 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ + bincaml: Error in (load-il ../../examples/irreducible_loop_1.il): Parse error: ../../examples/irreducible_loop_1.il:20 + 20 | store le $stack #4:bv64 $R29:bv64 64 { .label = "%00000360" }; + ^^^^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] $ cat before.il - var $CF:bv1; - var $NF:bv1; - var $R0:bv64; - var $R1:bv64; - var $R29:bv64; - var $R30:bv64; - var $R31:bv64; - var $VF:bv1; - var $ZF:bv1; - var observable $mem:(bv64->bv8); - var $stack:(bv64->bv8); - prog entry @main_1876; - proc @main_1876() -> () { .address = 1876; .name = "main"; - .returnBlock = "main_basil_return_1" } - modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - - [ - block %main_entry [ - var #4:bv64 := bvadd($R31:bv64, 0xffffffffffffffe0:bv64); - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4:bv64, 0x8:bv64) $R30:bv64 64; - $R31:bv64 := #4:bv64; - $R29:bv64 := $R31:bv64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x1c:bv64) extract(32,0, $R0:bv64) 32; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x10:bv64) $R1:bv64 64; - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 0x0:bv32 32; - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x40:bv64); - var load18:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load18:bv32); - $R0:bv64 := zero_extend(32, bvconcat(0x0:bv31, extract(1,0, $R0:bv64))); - var #5:bv32 := bvadd(extract(32,0, $R0:bv64), 0xffffffff:bv32); - $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#5:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x0:bv33)))); - $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#5:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0x100000000:bv33)))); - $ZF:bv1 := booltobv1(eq(bvadd(#5:bv32, 0x1:bv32), 0x0:bv32)); - $NF:bv1 := extract(32,31, bvadd(#5:bv32, 0x1:bv32)); - goto (%main_27,%main_23); - ]; - block %main_23 [ - guard neq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_21); - ]; - block %main_21 [ goto (%main_19); ]; - block %main_27 [ - guard eq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_25); - ]; - block %main_25 [ goto (%main_5); ]; - block %main_5 [ - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); - $R30:bv64 := 0x7a0:bv64; - - call @puts_1584(); - goto (%main_3); - ]; - block %main_3 [ - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - var load19:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load19:bv32); - $R1:bv64 := zero_extend(32, bvadd(extract(32,0, $R0:bv64), 0x1:bv32)); - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 extract(32,0, $R1:bv64) 32; - goto (%main_19); - ]; - block %main_19 [ - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); - $R30:bv64 := 0x7d0:bv64; - - call @puts_1584(); - goto (%main_17); - ]; - block %main_17 [ - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - var load20:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load20:bv32); - var #6:bv32 := bvadd(extract(32,0, $R0:bv64), 0xfffffffa:bv32); - $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#6:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x1fffffffb:bv33)))); - $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#6:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0xfffffffb:bv33)))); - $ZF:bv1 := booltobv1(eq(bvadd(#6:bv32, 0x1:bv32), 0x0:bv32)); - $NF:bv1 := extract(32,31, bvadd(#6:bv32, 0x1:bv32)); - goto (%main_15,%main_9); - ]; - block %main_9 [ - guard neq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); - goto (%main_7); - ]; - block %main_7 [ goto (%main_5); ]; - block %main_15 [ - guard eq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x828:bv64); - $R30:bv64 := 0x7f4:bv64; - - call @puts_1584(); - goto (%main_13); - ]; - block %main_13 [ goto (%main_11); ]; - block %main_11 [ - $R0:bv64 := 0x0:bv64; - var load21:bv64 := load le $stack:(bv64->bv8) $R31:bv64 64; - $R29:bv64 := load21:bv64; - var load22:bv64 := load le $stack:(bv64->bv8) bvadd($R31:bv64, 0x8:bv64) 64; - $R30:bv64 := load22:bv64; - $R31:bv64 := bvadd($R31:bv64, 0x20:bv64); - goto (%main_basil_return_1); - ]; - block %main_basil_return_1 [ nop; return; ] - ]; - proc @puts_1584() -> () { .address = 1584; .name = "puts" } - - ; + cat: before.il: No such file or directory + [1] $ cat after.il - var $CF:bv1; - var $NF:bv1; - var $R0:bv64; - var $R1:bv64; - var $R29:bv64; - var $R30:bv64; - var $R31:bv64; - var $VF:bv1; - var $ZF:bv1; - var observable $mem:(bv64->bv8); - var $stack:(bv64->bv8); - prog entry @main_1876; - proc @main_1876(CF_in:bv1, NF_in:bv1, R0_in:bv64, R1_in:bv64, R29_in:bv64, - R30_in:bv64, R31_in:bv64, VF_in:bv1, ZF_in:bv1) - -> (CF_out:bv1, NF_out:bv1, R0_out:bv64, R1_out:bv64, R29_out:bv64, - R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1876; - .name = "main"; .returnBlock = "main_basil_return_1" } - modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - - [ - block %inputs [ - (var CF:bv1 := CF_in:bv1, var NF:bv1 := NF_in:bv1, var R0:bv64 := R0_in:bv64, - var R1:bv64 := R1_in:bv64, var R29:bv64 := R29_in:bv64, - var R30:bv64 := R30_in:bv64, var R31:bv64 := R31_in:bv64, - var VF:bv1 := VF_in:bv1, var ZF:bv1 := ZF_in:bv1); - goto (%main_entry); - ]; - block %main_entry [ - var #4_1:bv64 := bvadd(R31:bv64, 0xffffffffffffffe0:bv64); - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4_1:bv64, 0x8:bv64) R30:bv64 64; - var R31_1:bv64 := #4_1:bv64; - var R29_1:bv64 := R31_1:bv64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, - 0x1c:bv64) extract(32,0, R0:bv64) 32; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, - 0x10:bv64) R1:bv64 64; - var R0_1:bv64 := 0x20000:bv64; - var R0_2:bv64 := bvadd(R0_1:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_2:bv64 0x0:bv32 32; - var R0_3:bv64 := 0x20000:bv64; - var R0_4:bv64 := bvadd(R0_3:bv64, 0x40:bv64); - var load18_1:bv32 := load le $mem:(bv64->bv8) R0_4:bv64 32; - var R0_5:bv64 := zero_extend(32, load18_1:bv32); - var R0_6:bv64 := zero_extend(32, - bvconcat(0x0:bv31, extract(1,0, R0_5:bv64))); - var #5_1:bv32 := bvadd(extract(32,0, R0_6:bv64), 0xffffffff:bv32); - var VF_1:bv1 := bvnot(booltobv1(eq(sign_extend(1, - bvadd(#5_1:bv32, 0x1:bv32)), sign_extend(1, extract(32,0, R0_6:bv64))))); - var CF_1:bv1 := bvnot(booltobv1(eq(zero_extend(1, - bvadd(#5_1:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, R0_6:bv64)), 0x100000000:bv33)))); - var ZF_1:bv1 := booltobv1(eq(bvadd(#5_1:bv32, 0x1:bv32), 0x0:bv32)); - var NF_1:bv1 := extract(32,31, bvadd(#5_1:bv32, 0x1:bv32)); - goto (%main_27,%main_23); - ]; - block %main_23 [ - var ZF_3:bv1 := ZF_1:bv1; - guard neq(booltobv1(eq(ZF_3:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_21); - ]; - block %main_21 [ goto (%main_19); ]; - block %main_27 [ - var ZF_2:bv1 := ZF_1:bv1; - guard eq(booltobv1(eq(ZF_2:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_25); - ]; - block %main_25 [ goto (%main_5); ]; - block %main_5 [ - (var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), - var NF_5:bv1 := phi(%main_25 -> NF_1:bv1, %main_7 -> NF_4:bv1), - var R1_3:bv64 := phi(%main_25 -> R1:bv64, %main_7 -> R1_2:bv64), - var R29_4:bv64 := phi(%main_25 -> R29_1:bv64, %main_7 -> R29_3:bv64), - var R31_4:bv64 := phi(%main_25 -> R31_1:bv64, %main_7 -> R31_3:bv64), - var VF_5:bv1 := phi(%main_25 -> VF_1:bv1, %main_7 -> VF_4:bv1), - var ZF_8:bv1 := phi(%main_25 -> ZF_2:bv1, %main_7 -> ZF_7:bv1)); - var R0_13:bv64 := 0x0:bv64; - var R0_14:bv64 := bvadd(R0_13:bv64, 0x820:bv64); - var R30_3:bv64 := 0x7a0:bv64; - (var CF_6:bv1=CF_out, var NF_6:bv1=NF_out, var R0_15:bv64=R0_out, - var R1_4:bv64=R1_out, var R29_5:bv64=R29_out, var R30_4:bv64=R30_out, - var R31_5:bv64=R31_out, var VF_6:bv1=VF_out, var ZF_9:bv1=ZF_out) := - call @puts_1584(CF_in=CF_5:bv1, NF_in=NF_5:bv1, R0_in=R0_14:bv64, - R1_in=R1_3:bv64, R29_in=R29_4:bv64, R30_in=R30_3:bv64, R31_in=R31_4:bv64, - VF_in=VF_5:bv1, ZF_in=ZF_8:bv1); - goto (%main_3); - ]; - block %main_3 [ - var R0_16:bv64 := 0x20000:bv64; - var R0_17:bv64 := bvadd(R0_16:bv64, 0x3c:bv64); - var load19_1:bv32 := load le $mem:(bv64->bv8) R0_17:bv64 32; - var R0_18:bv64 := zero_extend(32, load19_1:bv32); - var R1_5:bv64 := zero_extend(32, bvadd(extract(32,0, R0_18:bv64), 0x1:bv32)); - var R0_19:bv64 := 0x20000:bv64; - var R0_20:bv64 := bvadd(R0_19:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_20:bv64 extract(32,0, R1_5:bv64) 32; - goto (%main_19); - ]; - block %main_19 [ - (var CF_2:bv1 := phi(%main_3 -> CF_6:bv1, %main_21 -> CF_1:bv1), - var NF_2:bv1 := phi(%main_3 -> NF_6:bv1, %main_21 -> NF_1:bv1), - var R1_1:bv64 := phi(%main_3 -> R1_5:bv64, %main_21 -> R1:bv64), - var R29_2:bv64 := phi(%main_3 -> R29_5:bv64, %main_21 -> R29_1:bv64), - var R31_2:bv64 := phi(%main_3 -> R31_5:bv64, %main_21 -> R31_1:bv64), - var VF_2:bv1 := phi(%main_3 -> VF_6:bv1, %main_21 -> VF_1:bv1), - var ZF_4:bv1 := phi(%main_3 -> ZF_9:bv1, %main_21 -> ZF_3:bv1)); - var R0_7:bv64 := 0x0:bv64; - var R0_8:bv64 := bvadd(R0_7:bv64, 0x820:bv64); - var R30_1:bv64 := 0x7d0:bv64; - (var CF_3:bv1=CF_out, var NF_3:bv1=NF_out, var R0_9:bv64=R0_out, - var R1_2:bv64=R1_out, var R29_3:bv64=R29_out, var R30_2:bv64=R30_out, - var R31_3:bv64=R31_out, var VF_3:bv1=VF_out, var ZF_5:bv1=ZF_out) := - call @puts_1584(CF_in=CF_2:bv1, NF_in=NF_2:bv1, R0_in=R0_8:bv64, - R1_in=R1_1:bv64, R29_in=R29_2:bv64, R30_in=R30_1:bv64, R31_in=R31_2:bv64, - VF_in=VF_2:bv1, ZF_in=ZF_4:bv1); - goto (%main_17); - ]; - block %main_17 [ - var R0_10:bv64 := 0x20000:bv64; - var R0_11:bv64 := bvadd(R0_10:bv64, 0x3c:bv64); - var load20_1:bv32 := load le $mem:(bv64->bv8) R0_11:bv64 32; - var R0_12:bv64 := zero_extend(32, load20_1:bv32); - var #6_1:bv32 := bvadd(extract(32,0, R0_12:bv64), 0xfffffffa:bv32); - var VF_4:bv1 := bvnot(booltobv1(eq(sign_extend(1, - bvadd(#6_1:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, R0_12:bv64)), 0x1fffffffb:bv33)))); - var CF_4:bv1 := bvnot(booltobv1(eq(zero_extend(1, - bvadd(#6_1:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, R0_12:bv64)), 0xfffffffb:bv33)))); - var ZF_6:bv1 := booltobv1(eq(bvadd(#6_1:bv32, 0x1:bv32), 0x0:bv32)); - var NF_4:bv1 := extract(32,31, bvadd(#6_1:bv32, 0x1:bv32)); - goto (%main_15,%main_9); - ]; - block %main_9 [ - var ZF_7:bv1 := ZF_6:bv1; - guard neq(bvnot(booltobv1(eq(ZF_7:bv1, 0x1:bv1))), 0x0:bv1); - goto (%main_7); - ]; - block %main_7 [ goto (%main_5); ]; - block %main_15 [ - var ZF_10:bv1 := ZF_6:bv1; - guard eq(bvnot(booltobv1(eq(ZF_10:bv1, 0x1:bv1))), 0x0:bv1); - var R0_21:bv64 := 0x0:bv64; - var R0_22:bv64 := bvadd(R0_21:bv64, 0x828:bv64); - var R30_5:bv64 := 0x7f4:bv64; - (var CF_7:bv1=CF_out, var NF_7:bv1=NF_out, var R0_23:bv64=R0_out, - var R1_6:bv64=R1_out, var R29_6:bv64=R29_out, var R30_6:bv64=R30_out, - var R31_6:bv64=R31_out, var VF_7:bv1=VF_out, var ZF_11:bv1=ZF_out) := - call @puts_1584(CF_in=CF_4:bv1, NF_in=NF_4:bv1, R0_in=R0_22:bv64, - R1_in=R1_2:bv64, R29_in=R29_3:bv64, R30_in=R30_5:bv64, R31_in=R31_3:bv64, - VF_in=VF_4:bv1, ZF_in=ZF_10:bv1); - goto (%main_13); - ]; - block %main_13 [ goto (%main_11); ]; - block %main_11 [ - var R0_24:bv64 := 0x0:bv64; - var load21_1:bv64 := load le $stack:(bv64->bv8) R31_6:bv64 64; - var R29_7:bv64 := load21_1:bv64; - var load22_1:bv64 := load le $stack:(bv64->bv8) bvadd(R31_6:bv64, 0x8:bv64) 64; - var R30_7:bv64 := load22_1:bv64; - var R31_7:bv64 := bvadd(R31_6:bv64, 0x20:bv64); - goto (%main_basil_return_1); - ]; - block %main_basil_return_1 [ goto (%returns); ]; - block %returns [ - (var CF_out:bv1 := CF_7:bv1, var NF_out:bv1 := NF_7:bv1, - var R0_out:bv64 := R0_24:bv64, var R1_out:bv64 := R1_6:bv64, - var R29_out:bv64 := R29_7:bv64, var R30_out:bv64 := R30_7:bv64, - var R31_out:bv64 := R31_7:bv64, var VF_out:bv1 := VF_7:bv1, - var ZF_out:bv1 := ZF_11:bv1); - return; - ] - ]; - proc @puts_1584(CF_in:bv1, NF_in:bv1, R0_in:bv64, R1_in:bv64, R29_in:bv64, - R30_in:bv64, R31_in:bv64, VF_in:bv1, ZF_in:bv1) - -> (CF_out:bv1, NF_out:bv1, R0_out:bv64, R1_out:bv64, R29_out:bv64, - R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1584; - .name = "puts" } - - ; + cat: after.il: No such file or directory + [1] $ diff after.il after_reparsed.il + diff: after.il: No such file or directory diff: after_reparsed.il: No such file or directory [2] The interpreter should give the same output for both $ diff before_loop.txt after_loop.txt + diff: before_loop.txt: No such file or directory + diff: after_loop.txt: No such file or directory + [2] diff --git a/test/cram/expr_smt.t b/test/cram/expr_smt.t index ef552625..428ed412 100644 --- a/test/cram/expr_smt.t +++ b/test/cram/expr_smt.t @@ -3,78 +3,16 @@ Should output no errors $ bincaml script expr_smt_check.sexp + bincaml: Error in (load-il ../../examples/cntlm-output.il): Parse error: ../../examples/cntlm-output.il:58 + 58 | store le $stack bvadd($R31:bv64, 0x0:bv64) $R29:bv64 64 { .comment = "op: 0xa9007bfd" }; + ^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] Check concat rewrites work $ diff before.il after.il - 17,81c17,18 - < $R28:bv64 := bvor(bvand(bvconcat(extract(1,0, bvlshr(var1_4206396_bv64:bv64, - < 0x1f:bv64)), extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64))), - < 0xffffffff00000000:bv64), - --- - > $R28:bv64 := bvor(bvand(sign_extend(63, - > extract(32,31, var1_4206396_bv64:bv64)), 0xffffffff00000000:bv64), - [1] + diff: before.il: No such file or directory + diff: after.il: No such file or directory + [2] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8a95e837..49de1fa9 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,14 +1,15 @@ $ bincaml script roundtrip.sexp - bincaml: Error in (load-il before.il): Parse error: before.il:17 - 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ + bincaml: Error in (load-il ../../examples/irreducible_loop_1.il): Parse error: ../../examples/irreducible_loop_1.il:20 + 20 | store le $stack #4:bv64 $R29:bv64 64 { .label = "%00000360" }; + ^^^^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il + diff: before.il: No such file or directory diff: after.il: No such file or directory [2] diff --git a/test/cram/typefail.t b/test/cram/typefail.t index 48860951..64cae20c 100644 --- a/test/cram/typefail.t +++ b/test/cram/typefail.t @@ -1,67 +1,3 @@ $ bincaml script ./typefail.sexp 2>/dev/null - Arguments are not of the same type in eq at statement 0 in %main_entry - Arguments are not of the same type in neq at statement 1 in %main_entry - Arguments are not of the same type in eq at statement 2 in %main_entry - Arguments are not of the same type in neq at statement 3 in %main_entry - Arguments are not of the same type in eq at statement 4 in %main_entry - Arguments are not of the same type in neq at statement 5 in %main_entry - Paramters for the function has a type mismatch: type of intneg(0x1:bv32) != type of $NF:bv1 (int != bv1) at statement 6 in %main_entry - intneg body is not a integer at statement 6 in %main_entry - bv32 is not the correct type of int for intadd at statement 7 in %main_entry - bv32 is not the correct type of int for intdiv at statement 8 in %main_entry - bv32 is not the correct type of int for intmod at statement 9 in %main_entry - bv32 is not the correct type of int for intmul at statement 10 in %main_entry - bv32 is not the correct type of int for intsub at statement 11 in %main_entry - bv32 is not the correct type of int for intlt at statement 12 in %main_entry - bv32 is not the correct type of int for intle at statement 13 in %main_entry - Paramters for the function has a type mismatch: type of bvnot(1) != type of $NF:bv1 (int != bv1) at statement 14 in %main_entry - bvnot body is not a bitvector at statement 14 in %main_entry - Paramters for the function has a type mismatch: type of bvneg(1) != type of $NF:bv1 (int != bv1) at statement 15 in %main_entry - bvneg body is not a bitvector at statement 15 in %main_entry - Paramters for the function has a type mismatch: type of zero_extend(32, 2) != type of $NF:bv64 (⊥ != bv64) at statement 16 in %main_entry - Nothing type encountered in operator at statement 16 in %main_entry - zero_extend_32 body is not a bitvector at statement 16 in %main_entry - Paramters for the function has a type mismatch: type of sign_extend(32, 2) != type of $NF:bv64 (⊥ != bv64) at statement 17 in %main_entry - Nothing type encountered in operator at statement 17 in %main_entry - sign_extend_32 body is not a bitvector at statement 17 in %main_entry - extract_32_31 body is not a bitvector at statement 18 in %main_entry - int is not of bitvector type in bvsle at statement 19 in %main_entry - int is not of bitvector type in bvslt at statement 20 in %main_entry - bv32 is not the correct type of bv64 for bvsle at statement 21 in %main_entry - bv32 is not the correct type of bv64 for bvslt at statement 22 in %main_entry - int is not of bitvector type in bvult at statement 23 in %main_entry - int is not of bitvector type in bvule at statement 24 in %main_entry - Paramters for the function has a type mismatch: type of bvand(1, 0x1:bv32) != type of $NF:bool (int != bool) at statement 25 in %main_entry - int is not of bitvector type in bvand at statement 25 in %main_entry - bool is not of bitvector type in bvor at statement 26 in %main_entry - bool is not of bitvector type in bvadd at statement 27 in %main_entry - bv32 is not the correct type of bv64 for bvadd at statement 28 in %main_entry - bool is not of bitvector type in bvmul at statement 29 in %main_entry - bv32 is not the correct type of bv64 for bvmul at statement 30 in %main_entry - bool is not of bitvector type in bvudiv at statement 31 in %main_entry - bv32 is not the correct type of bv64 for bvudiv at statement 32 in %main_entry - bool is not of bitvector type in bvurem at statement 33 in %main_entry - bv32 is not the correct type of bv64 for bvurem at statement 34 in %main_entry - bool is not of bitvector type in bvshl at statement 35 in %main_entry - bv32 is not the correct type of bv64 for bvshl at statement 36 in %main_entry - bool is not of bitvector type in bvlshr at statement 37 in %main_entry - bv32 is not the correct type of bv64 for bvlshr at statement 38 in %main_entry - bool is not of bitvector type in bvnand at statement 39 in %main_entry - bv32 is not the correct type of bv64 for bvnand at statement 40 in %main_entry - bool is not of bitvector type in bvxor at statement 41 in %main_entry - bv32 is not the correct type of bv64 for bvxor at statement 42 in %main_entry - bool is not of bitvector type in bvsub at statement 43 in %main_entry - bv32 is not the correct type of bv64 for bvsub at statement 44 in %main_entry - bool is not of bitvector type in bvsdiv at statement 45 in %main_entry - bv32 is not the correct type of bv64 for bvsdiv at statement 46 in %main_entry - bool is not of bitvector type in bvsrem at statement 47 in %main_entry - bv32 is not the correct type of bv64 for bvsrem at statement 48 in %main_entry - bool is not of bitvector type in bvsmod at statement 49 in %main_entry - bv32 is not the correct type of bv64 for bvsmod at statement 50 in %main_entry - bool is not of bitvector type in bvashr at statement 51 in %main_entry - bv32 is not the correct type of bv64 for bvashr at statement 52 in %main_entry - Address loading data (#4:bv32) does not match address size (64) at statement 54 in %main_entry - Body of booltobv1(0x7a0:bv64) is not a Boolean at statement 0 in %main_9 - booltobv1 body is not a boolean at statement 0 in %main_9 - [125] + [123] diff --git a/test/cram/typepass.t b/test/cram/typepass.t index 8bf348f9..0fbf85ca 100644 --- a/test/cram/typepass.t +++ b/test/cram/typepass.t @@ -1,6 +1,6 @@ $ bincaml script ./typepass.sexp - bincaml: Error in (load-il ../../examples/cat.il): Parse error: ../../examples/cat.il:52 - 52 | ensures eq($_PC:bv64, old($R30:bv64)); - ^^^^^^^ + bincaml: Error in (load-il ../../examples/cat.il): Parse error: ../../examples/cat.il:61 + 61 | store le $stack bvadd($R31:bv64, 0xfffffffffffffff0:bv64) $R29:bv64 64 { .comment = "op: 0xa9bf7bfd" }; + ^^^^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] diff --git a/test/lang/interp.ml b/test/lang/interp.ml index ec6241ae..2bbb890d 100644 --- a/test/lang/interp.ml +++ b/test/lang/interp.ml @@ -21,83 +21,17 @@ let%expect_test "fold_block" = let st, _ = Lang.Interp.run_prog prog in print_endline (Lang.Interp.IState.show st); (); - [%expect - {| - PC= test::Return - Stack - - Top frame: - empty stack - - - trace: Store {mem = "$mem"; addr = `Bitvector (0x420034:bv64); - value = `Bitvector (0x3e8:bv32)} - - final mem state - Mem $mem:(bv64->bv8) - page at 420000 - 000: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 030: 0000 0000 e803 0000 0000 0000 0000 0000 ................ - 040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 080: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 090: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 0f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 100: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 110: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 120: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 130: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 140: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 150: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 160: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 170: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 180: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 190: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 1f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 200: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 210: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 220: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 230: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 240: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 250: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 260: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 270: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 280: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 290: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 2f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 300: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 310: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 320: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 330: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 340: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 350: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 360: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 370: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 380: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 390: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - 3f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ - |}] + [%expect.unreachable] +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + ( "Parse error: :5\ + \n5 | $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R0_in:bv64) 32;\ + \n \027[1;31m^^^^^^^^\027[0m\ + \n") + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 + Called from Expr_eval_expect__Interp.(fun) in file "test/lang/interp.ml", line 16, characters 4-60 + Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 + |}] diff --git a/test/lang/stmt.ml b/test/lang/stmt.ml index 0ce035f6..58c20058 100644 --- a/test/lang/stmt.ml +++ b/test/lang/stmt.ml @@ -48,22 +48,18 @@ let%expect_test "fold_block" = () block; print_endline (Block.to_string block); (); - [%expect - {| - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, - 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32 - var load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, - 0xfffffffffffffffc:bv64) 32 - var R1_4:bv64 := zero_extend(32, load45_1:bv32) - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32 - var load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32 - var R0_10:bv64 := zero_extend(32, load46_1:bv32) - [ - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32; - load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) 32; - R1_4:bv64 := zero_extend(32, load45_1:bv32); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32; - load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32; - R0_10:bv64 := zero_extend(32, load46_1:bv32); - ] - |}] + [%expect.unreachable] +[@@expect.uncaught_exn {| + (* CR expect_test_collector: This test expectation appears to contain a backtrace. + This is strongly discouraged as backtraces are fragile. + Please change this test to not include a backtrace. *) + ( "Parse error: :3\ + \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ + \n \027[1;31m^^^^^\027[0m\ + \n") + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 + Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1190, characters 20-62 + Called from Expr_eval_expect__Stmt.(fun) in file "test/lang/stmt.ml", lines 30-43, characters 4-6 + Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 + |}] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index dd6e277b..4431894b 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -306,12 +306,10 @@ module.exports = grammar({ seq($.token_LocalIdent, "=", $.Expr), list_NamedCallArg: $ => choice( - // []. [NamedCallArg] ::= ; - choice(), // (:[]). [NamedCallArg] ::= NamedCallArg ; $.NamedCallArg, // (:). [NamedCallArg] ::= NamedCallArg "," [NamedCallArg] ; - seq($.NamedCallArg, ",", optional($.list_NamedCallArg)) + seq($.NamedCallArg, ",", $.list_NamedCallArg) ), CallParams: $ => choice( @@ -395,8 +393,8 @@ module.exports = grammar({ choice( // Block_NoPhi. Block ::= "block" BlockIdent AttribSet BeginList [StmtWithAttrib] JumpWithAttrib ";" EndList ; seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_BeginList, optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList), - // Block_Phi. Block ::= "block" BlockIdent AttribSet BeginList OpenParen [PhiAssign] CloseParen ";" [StmtWithAttrib] JumpWithAttrib ";" EndList ; - seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_BeginList, $.token_OpenParen, optional($.list_PhiAssign), $.token_CloseParen, ";", optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList) + // Block_Phi. Block ::= "block" BlockIdent AttribSet OpenParen [PhiAssign] CloseParen BeginList [StmtWithAttrib] JumpWithAttrib ";" EndList ; + seq("block", $.token_BlockIdent, optional($.AttribSet), $.token_OpenParen, optional($.list_PhiAssign), $.token_CloseParen, $.token_BeginList, optional($.list_StmtWithAttrib), $.JumpWithAttrib, ";", $.token_EndList) ), AttrKeyValue: $ => // AttrKeyValue1. AttrKeyValue ::= BIdent "=" Attr ; @@ -449,20 +447,6 @@ module.exports = grammar({ // (:). [Params] ::= Params "," [Params] ; seq($.Params, ",", optional($.list_Params)) ), - FunParams: $ => - choice( - // FunParams1. FunParams ::= LocalIdent ":" Type ; - seq($.token_LocalIdent, ":", $.Type), - // FunParams2. FunParams ::= OpenParen LocalIdent ":" Type CloseParen ; - seq($.token_OpenParen, $.token_LocalIdent, ":", $.Type, $.token_CloseParen) - ), - list_FunParams: $ => - choice( - // []. [FunParams] ::= ; - choice(), - // (:). [FunParams] ::= FunParams [FunParams] ; - seq($.FunParams, optional($.list_FunParams)) - ), Value: $ => choice( // Value_BV. Value ::= BVVal ; From 2736345fb98f912683c9201a9d4736f059355432 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 14:50:40 +1000 Subject: [PATCH 18/43] restore Stmt_Store --- lib/fe/AbsBasilIR.ml | 5 +- lib/fe/BasilIR.cf | 9 +- lib/fe/ParBasilIR.mly | 5 +- lib/fe/PrintBasilIR.ml | 5 +- lib/fe/ShowBasilIR.ml | 5 +- lib/fe/SkelBasilIR.ml | 5 +- lib/loadir.ml | 35 +++- lib/transforms/may_read_uninit.ml | 6 +- test/analysis/ide_live.ml | 24 +-- test/cram/basicssa.t | 322 +++++++++++++++++++++++++++++- test/cram/expr_smt.t | 78 +++++++- test/cram/roundtrip.t | 7 +- test/cram/typefail.t | 66 +++++- test/cram/typepass.t | 5 - test/lang/interp.ml | 4 +- test/lang/stmt.ml | 6 +- tree-sitter/grammar.js | 6 +- 17 files changed, 517 insertions(+), 76 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 958190f9..5e60f1b3 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -105,8 +105,9 @@ and stmt = | Stmt_ScalarStore of lVar * expr | Stmt_ScalarLoad of lVar * var | Stmt_MultiAssign of openParen * assignment list * closeParen - | Stmt_Load of lVar * endian * var * expr * intVal - | Stmt_Store of lVar * endian * var * expr * expr * intVal + | Stmt_Load_Var of lVar * endian * var * expr * intVal + | Stmt_Store_Var of lVar * endian * var * expr * expr * intVal + | Stmt_Store of endian * globalIdent * expr * expr * intVal | Stmt_DirectCall of lVars * procIdent * openParen * callParams * closeParen | Stmt_IndirectCall of expr | Stmt_Assume of expr diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index daa0d694..753eadaa 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -109,11 +109,12 @@ rules Var ::= LocalVar | GlobalVar ; separator GlobalVar ","; --- lvar endian mem addr size -Stmt_Load . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; +-- lvar endian mem addr size +Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; --- lhs endian rhs addr value size -Stmt_Store . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; +-- lhs endian rhs addr value size +Stmt_Store_Var . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; +Stmt_Store . Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal; rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 93a786e1..8026f63d 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -506,8 +506,9 @@ stmt : KW_nop { Stmt_Nop } | lVar SYMB9 KW_store expr { Stmt_ScalarStore ($1, $4) } | lVar SYMB9 KW_load var { Stmt_ScalarLoad ($1, $4) } | openParen assignment_list closeParen { Stmt_MultiAssign ($1, $2, $3) } - | lVar SYMB9 KW_load endian var expr intVal { Stmt_Load ($1, $4, $5, $6, $7) } - | lVar SYMB9 KW_store endian var expr2 expr intVal { Stmt_Store ($1, $4, $5, $6, $7, $8) } + | lVar SYMB9 KW_load endian var expr intVal { Stmt_Load_Var ($1, $4, $5, $6, $7) } + | lVar SYMB9 KW_store endian var expr2 expr intVal { Stmt_Store_Var ($1, $4, $5, $6, $7, $8) } + | KW_store endian globalIdent expr expr intVal { Stmt_Store ($2, $3, $4, $5, $6) } | lVars KW_call procIdent openParen callParams closeParen { Stmt_DirectCall ($1, $3, $4, $5, $6) } | KW_indirect KW_call expr { Stmt_IndirectCall $3 } | KW_assume expr { Stmt_Assume $2 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 7edc3d38..3ba61c80 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -252,8 +252,9 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with | AbsBasilIR.Stmt_ScalarStore (lvar, expr) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtExpr 0 expr]) | AbsBasilIR.Stmt_ScalarLoad (lvar, var) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtVar 0 var]) | AbsBasilIR.Stmt_MultiAssign (openparen, assignments, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtAssignmentListBNFC 0 assignments ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Stmt_Load (lvar, endian, var, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr ; prtIntVal 0 intval]) - | AbsBasilIR.Stmt_Store (lvar, endian, var, expr1, expr2, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 2 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Load_Var (lvar, endian, var, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Store_Var (lvar, endian, var, expr1, expr2, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 2 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Store (endian, globalident, expr1, expr2, intval) -> prPrec i 0 (concatD [render "store" ; prtEndian 0 endian ; prtGlobalIdent 0 globalident ; prtExpr 0 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) | AbsBasilIR.Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> prPrec i 0 (concatD [prtLVars 0 lvars ; render "call" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen ; prtCallParams 0 callparams ; prtCloseParen 0 closeparen]) | AbsBasilIR.Stmt_IndirectCall expr -> prPrec i 0 (concatD [render "indirect" ; render "call" ; prtExpr 0 expr]) | AbsBasilIR.Stmt_Assume expr -> prPrec i 0 (concatD [render "assume" ; prtExpr 0 expr]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index be8e3858..4cde1163 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -159,8 +159,9 @@ and showStmt (e : AbsBasilIR.stmt) : showable = match e with | AbsBasilIR.Stmt_ScalarStore (lvar, expr) -> s2s "Stmt_ScalarStore" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showExpr expr >> c2s ')' | AbsBasilIR.Stmt_ScalarLoad (lvar, var) -> s2s "Stmt_ScalarLoad" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showVar var >> c2s ')' | AbsBasilIR.Stmt_MultiAssign (openparen, assignments, closeparen) -> s2s "Stmt_MultiAssign" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showAssignment assignments >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Stmt_Load (lvar, endian, var, expr, intval) -> s2s "Stmt_Load" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' - | AbsBasilIR.Stmt_Store (lvar, endian, var, expr0, expr, intval) -> s2s "Stmt_Store" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' + | AbsBasilIR.Stmt_Load_Var (lvar, endian, var, expr, intval) -> s2s "Stmt_Load_Var" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' + | AbsBasilIR.Stmt_Store_Var (lvar, endian, var, expr0, expr, intval) -> s2s "Stmt_Store_Var" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showEndian endian >> s2s ", " >> showVar var >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' + | AbsBasilIR.Stmt_Store (endian, globalident, expr0, expr, intval) -> s2s "Stmt_Store" >> c2s ' ' >> c2s '(' >> showEndian endian >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showIntVal intval >> c2s ')' | AbsBasilIR.Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> s2s "Stmt_DirectCall" >> c2s ' ' >> c2s '(' >> showLVars lvars >> s2s ", " >> showProcIdent procident >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showCallParams callparams >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Stmt_IndirectCall expr -> s2s "Stmt_IndirectCall" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' | AbsBasilIR.Stmt_Assume expr -> s2s "Stmt_Assume" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 3d17605f..8df82c9a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -179,8 +179,9 @@ and transStmt (x : stmt) : result = match x with | Stmt_ScalarStore (lvar, expr) -> failure x | Stmt_ScalarLoad (lvar, var) -> failure x | Stmt_MultiAssign (openparen, assignments, closeparen) -> failure x - | Stmt_Load (lvar, endian, var, expr, intval) -> failure x - | Stmt_Store (lvar, endian, var, expr0, expr, intval) -> failure x + | Stmt_Load_Var (lvar, endian, var, expr, intval) -> failure x + | Stmt_Store_Var (lvar, endian, var, expr0, expr, intval) -> failure x + | Stmt_Store (endian, globalident, expr0, expr, intval) -> failure x | Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> failure x | Stmt_IndirectCall expr -> failure x | Stmt_Assume expr -> failure x diff --git a/lib/loadir.ml b/lib/loadir.ml index 4711ecd4..39312a2c 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -471,7 +471,7 @@ module BasilASTLoader = struct let open Stmt in match stmt with | Stmt_Nop -> (p_st, `None) - | Stmt_Load (lvar, endian, var, expr, intval) -> + | Stmt_Load_Var (lvar, endian, var, expr, intval) -> let endian = trans_endian endian in let rhs = trans_var p_st var in let size = transIntVal intval |> Z.to_int in @@ -484,7 +484,7 @@ module BasilASTLoader = struct rhs; addr = Addr { addr = trans_expr p_st expr; endian; size }; }) ) - | Stmt_Store (lhs, endian, var, addr, value, intval) -> + | Stmt_Store_Var (lhs, endian, var, addr, value, intval) -> let endian = trans_endian endian in let size = transIntVal intval |> Z.to_int in let rhs = trans_var p_st var in @@ -498,6 +498,19 @@ module BasilASTLoader = struct value = trans_expr p_st value; addr = Addr { addr = trans_expr p_st addr; size; endian }; }) ) + | Stmt_Store (endian, bident, addr, value, intval) -> + let endian = trans_endian endian in + let size = transIntVal intval |> Z.to_int in + let mem = lookup_global_decl bident p_st in + ( p_st, + `Stmt + (Instr_Store + { + lhs = mem; + rhs = mem; + value = trans_expr p_st value; + addr = Addr { addr = trans_expr p_st addr; size; endian }; + }) ) | Stmt_SingleAssign (Assignment1 (lvar, expr)) -> let expr = trans_expr p_st expr in let p_st, lv = trans_lvar p_st lvar in @@ -1425,10 +1438,14 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect.unreachable] -[@@expect.uncaught_exn {| - ( "Parse error: string at lib/loadir.ml:1384::Loader__Loadir.(fun):21\ - \n21 | store le $mem $R1:bv64 0x0:bv32 32;\ - \n \027[1;31m^^^^^\027[0m\ - \n") - |}] + [%expect {| + @entry: + read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) + written: $R0:bv64,$mem:(bv64->bv8) + @b: + read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) + written: $R0:bv64,$mem:(bv64->bv8) + @c: + read: $R0:bv64,$mem:(bv64->bv8) + written: $mem:(bv64->bv8) + |}] diff --git a/lib/transforms/may_read_uninit.ml b/lib/transforms/may_read_uninit.ml index 9be9ef10..cc4fba48 100644 --- a/lib/transforms/may_read_uninit.ml +++ b/lib/transforms/may_read_uninit.ml @@ -155,9 +155,9 @@ let%expect_test "fold_block" = \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ \n \027[1;31m^^^^^\027[0m\ \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 - Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1190, characters 20-62 + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 + Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1203, characters 20-62 Called from Transforms__May_read_uninit.(fun) in file "lib/transforms/may_read_uninit.ml", lines 125-138, characters 4-6 Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 |}] diff --git a/test/analysis/ide_live.ml b/test/analysis/ide_live.ml index fec6c1e6..0c5acaab 100644 --- a/test/analysis/ide_live.ml +++ b/test/analysis/ide_live.ml @@ -42,20 +42,16 @@ proc @main () -> () let _, results = IDELiveAnalysis.solve program in let main = program.entry_proc |> Option.get_exn_or "No entry proc" in print_lives results main; - [%expect.unreachable] -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - ( "Parse error: :20\ - \n20 | store le $mem $z:bv64 d:bv64 64;\ - \n \027[1;31m^^^^^\027[0m\ - \n") - Raised at Loader__Loadir.concrete_prog_ast_of_string in file "lib/loadir.ml", line 1105, characters 27-66 - Called from Loader__Loadir.ast_of_string in file "lib/loadir.ml", line 1217, characters 13-69 - Called from Bincaml_analysis_test__Ide_live.(fun) in file "test/analysis/ide_live.ml", lines 12-39, characters 4-6 - Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 - |}] + [%expect {| + @main + $mem:(bv64->bv8) + $x:bv64 + a:bv64 + e:bv64 + b:bv64 + c:bv64 + d:bv64 + |}] let%expect_test "simple_call" = let lst = diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index 80734855..f8eaa0e5 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,31 +2,331 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il ../../examples/irreducible_loop_1.il): Parse error: ../../examples/irreducible_loop_1.il:20 - 20 | store le $stack #4:bv64 $R29:bv64 64 { .label = "%00000360" }; - ^^^^^ + bincaml: Error in (load-il after.il): Parse error: after.il:33 + 33 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; + ^^^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] $ cat before.il - cat: before.il: No such file or directory - [1] + var $CF:bv1; + var $NF:bv1; + var $R0:bv64; + var $R1:bv64; + var $R29:bv64; + var $R30:bv64; + var $R31:bv64; + var $VF:bv1; + var $ZF:bv1; + var observable $mem:(bv64->bv8); + var $stack:(bv64->bv8); + prog entry @main_1876; + proc @main_1876() -> () { .address = 1876; .name = "main"; + .returnBlock = "main_basil_return_1" } + modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + + [ + block %main_entry [ + var #4:bv64 := bvadd($R31:bv64, 0xffffffffffffffe0:bv64); + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4:bv64, 0x8:bv64) $R30:bv64 64; + $R31:bv64 := #4:bv64; + $R29:bv64 := $R31:bv64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x1c:bv64) extract(32,0, $R0:bv64) 32; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x10:bv64) $R1:bv64 64; + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 0x0:bv32 32; + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x40:bv64); + var load18:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load18:bv32); + $R0:bv64 := zero_extend(32, bvconcat(0x0:bv31, extract(1,0, $R0:bv64))); + var #5:bv32 := bvadd(extract(32,0, $R0:bv64), 0xffffffff:bv32); + $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#5:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x0:bv33)))); + $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#5:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0x100000000:bv33)))); + $ZF:bv1 := booltobv1(eq(bvadd(#5:bv32, 0x1:bv32), 0x0:bv32)); + $NF:bv1 := extract(32,31, bvadd(#5:bv32, 0x1:bv32)); + goto (%main_27,%main_23); + ]; + block %main_23 [ + guard neq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_21); + ]; + block %main_21 [ goto (%main_19); ]; + block %main_27 [ + guard eq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_25); + ]; + block %main_25 [ goto (%main_5); ]; + block %main_5 [ + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); + $R30:bv64 := 0x7a0:bv64; + + call @puts_1584(); + goto (%main_3); + ]; + block %main_3 [ + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + var load19:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load19:bv32); + $R1:bv64 := zero_extend(32, bvadd(extract(32,0, $R0:bv64), 0x1:bv32)); + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 extract(32,0, $R1:bv64) 32; + goto (%main_19); + ]; + block %main_19 [ + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); + $R30:bv64 := 0x7d0:bv64; + + call @puts_1584(); + goto (%main_17); + ]; + block %main_17 [ + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + var load20:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load20:bv32); + var #6:bv32 := bvadd(extract(32,0, $R0:bv64), 0xfffffffa:bv32); + $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#6:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x1fffffffb:bv33)))); + $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#6:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0xfffffffb:bv33)))); + $ZF:bv1 := booltobv1(eq(bvadd(#6:bv32, 0x1:bv32), 0x0:bv32)); + $NF:bv1 := extract(32,31, bvadd(#6:bv32, 0x1:bv32)); + goto (%main_15,%main_9); + ]; + block %main_9 [ + guard neq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); + goto (%main_7); + ]; + block %main_7 [ goto (%main_5); ]; + block %main_15 [ + guard eq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x828:bv64); + $R30:bv64 := 0x7f4:bv64; + + call @puts_1584(); + goto (%main_13); + ]; + block %main_13 [ goto (%main_11); ]; + block %main_11 [ + $R0:bv64 := 0x0:bv64; + var load21:bv64 := load le $stack:(bv64->bv8) $R31:bv64 64; + $R29:bv64 := load21:bv64; + var load22:bv64 := load le $stack:(bv64->bv8) bvadd($R31:bv64, 0x8:bv64) 64; + $R30:bv64 := load22:bv64; + $R31:bv64 := bvadd($R31:bv64, 0x20:bv64); + goto (%main_basil_return_1); + ]; + block %main_basil_return_1 [ nop; return; ] + ]; + proc @puts_1584() -> () { .address = 1584; .name = "puts" } + + ; $ cat after.il - cat: after.il: No such file or directory - [1] + var $CF:bv1; + var $NF:bv1; + var $R0:bv64; + var $R1:bv64; + var $R29:bv64; + var $R30:bv64; + var $R31:bv64; + var $VF:bv1; + var $ZF:bv1; + var observable $mem:(bv64->bv8); + var $stack:(bv64->bv8); + prog entry @main_1876; + proc @main_1876(CF_in:bv1, NF_in:bv1, R0_in:bv64, R1_in:bv64, R29_in:bv64, + R30_in:bv64, R31_in:bv64, VF_in:bv1, ZF_in:bv1) + -> (CF_out:bv1, NF_out:bv1, R0_out:bv64, R1_out:bv64, R29_out:bv64, + R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1876; + .name = "main"; .returnBlock = "main_basil_return_1" } + modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + + [ + block %inputs [ + (var CF:bv1 := CF_in:bv1, var NF:bv1 := NF_in:bv1, var R0:bv64 := R0_in:bv64, + var R1:bv64 := R1_in:bv64, var R29:bv64 := R29_in:bv64, + var R30:bv64 := R30_in:bv64, var R31:bv64 := R31_in:bv64, + var VF:bv1 := VF_in:bv1, var ZF:bv1 := ZF_in:bv1); + goto (%main_entry); + ]; + block %main_entry [ + var #4_1:bv64 := bvadd(R31:bv64, 0xffffffffffffffe0:bv64); + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4_1:bv64, 0x8:bv64) R30:bv64 64; + var R31_1:bv64 := #4_1:bv64; + var R29_1:bv64 := R31_1:bv64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, + 0x1c:bv64) extract(32,0, R0:bv64) 32; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, + 0x10:bv64) R1:bv64 64; + var R0_1:bv64 := 0x20000:bv64; + var R0_2:bv64 := bvadd(R0_1:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_2:bv64 0x0:bv32 32; + var R0_3:bv64 := 0x20000:bv64; + var R0_4:bv64 := bvadd(R0_3:bv64, 0x40:bv64); + var load18_1:bv32 := load le $mem:(bv64->bv8) R0_4:bv64 32; + var R0_5:bv64 := zero_extend(32, load18_1:bv32); + var R0_6:bv64 := zero_extend(32, + bvconcat(0x0:bv31, extract(1,0, R0_5:bv64))); + var #5_1:bv32 := bvadd(extract(32,0, R0_6:bv64), 0xffffffff:bv32); + var VF_1:bv1 := bvnot(booltobv1(eq(sign_extend(1, + bvadd(#5_1:bv32, 0x1:bv32)), sign_extend(1, extract(32,0, R0_6:bv64))))); + var CF_1:bv1 := bvnot(booltobv1(eq(zero_extend(1, + bvadd(#5_1:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, R0_6:bv64)), 0x100000000:bv33)))); + var ZF_1:bv1 := booltobv1(eq(bvadd(#5_1:bv32, 0x1:bv32), 0x0:bv32)); + var NF_1:bv1 := extract(32,31, bvadd(#5_1:bv32, 0x1:bv32)); + goto (%main_27,%main_23); + ]; + block %main_23 [ + var ZF_3:bv1 := ZF_1:bv1; + guard neq(booltobv1(eq(ZF_3:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_21); + ]; + block %main_21 [ goto (%main_19); ]; + block %main_27 [ + var ZF_2:bv1 := ZF_1:bv1; + guard eq(booltobv1(eq(ZF_2:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_25); + ]; + block %main_25 [ goto (%main_5); ]; + block %main_5 [ + (var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), + var NF_5:bv1 := phi(%main_25 -> NF_1:bv1, %main_7 -> NF_4:bv1), + var R1_3:bv64 := phi(%main_25 -> R1:bv64, %main_7 -> R1_2:bv64), + var R29_4:bv64 := phi(%main_25 -> R29_1:bv64, %main_7 -> R29_3:bv64), + var R31_4:bv64 := phi(%main_25 -> R31_1:bv64, %main_7 -> R31_3:bv64), + var VF_5:bv1 := phi(%main_25 -> VF_1:bv1, %main_7 -> VF_4:bv1), + var ZF_8:bv1 := phi(%main_25 -> ZF_2:bv1, %main_7 -> ZF_7:bv1)); + var R0_13:bv64 := 0x0:bv64; + var R0_14:bv64 := bvadd(R0_13:bv64, 0x820:bv64); + var R30_3:bv64 := 0x7a0:bv64; + (var CF_6:bv1=CF_out, var NF_6:bv1=NF_out, var R0_15:bv64=R0_out, + var R1_4:bv64=R1_out, var R29_5:bv64=R29_out, var R30_4:bv64=R30_out, + var R31_5:bv64=R31_out, var VF_6:bv1=VF_out, var ZF_9:bv1=ZF_out) := + call @puts_1584(CF_in=CF_5:bv1, NF_in=NF_5:bv1, R0_in=R0_14:bv64, + R1_in=R1_3:bv64, R29_in=R29_4:bv64, R30_in=R30_3:bv64, R31_in=R31_4:bv64, + VF_in=VF_5:bv1, ZF_in=ZF_8:bv1); + goto (%main_3); + ]; + block %main_3 [ + var R0_16:bv64 := 0x20000:bv64; + var R0_17:bv64 := bvadd(R0_16:bv64, 0x3c:bv64); + var load19_1:bv32 := load le $mem:(bv64->bv8) R0_17:bv64 32; + var R0_18:bv64 := zero_extend(32, load19_1:bv32); + var R1_5:bv64 := zero_extend(32, bvadd(extract(32,0, R0_18:bv64), 0x1:bv32)); + var R0_19:bv64 := 0x20000:bv64; + var R0_20:bv64 := bvadd(R0_19:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_20:bv64 extract(32,0, R1_5:bv64) 32; + goto (%main_19); + ]; + block %main_19 [ + (var CF_2:bv1 := phi(%main_3 -> CF_6:bv1, %main_21 -> CF_1:bv1), + var NF_2:bv1 := phi(%main_3 -> NF_6:bv1, %main_21 -> NF_1:bv1), + var R1_1:bv64 := phi(%main_3 -> R1_5:bv64, %main_21 -> R1:bv64), + var R29_2:bv64 := phi(%main_3 -> R29_5:bv64, %main_21 -> R29_1:bv64), + var R31_2:bv64 := phi(%main_3 -> R31_5:bv64, %main_21 -> R31_1:bv64), + var VF_2:bv1 := phi(%main_3 -> VF_6:bv1, %main_21 -> VF_1:bv1), + var ZF_4:bv1 := phi(%main_3 -> ZF_9:bv1, %main_21 -> ZF_3:bv1)); + var R0_7:bv64 := 0x0:bv64; + var R0_8:bv64 := bvadd(R0_7:bv64, 0x820:bv64); + var R30_1:bv64 := 0x7d0:bv64; + (var CF_3:bv1=CF_out, var NF_3:bv1=NF_out, var R0_9:bv64=R0_out, + var R1_2:bv64=R1_out, var R29_3:bv64=R29_out, var R30_2:bv64=R30_out, + var R31_3:bv64=R31_out, var VF_3:bv1=VF_out, var ZF_5:bv1=ZF_out) := + call @puts_1584(CF_in=CF_2:bv1, NF_in=NF_2:bv1, R0_in=R0_8:bv64, + R1_in=R1_1:bv64, R29_in=R29_2:bv64, R30_in=R30_1:bv64, R31_in=R31_2:bv64, + VF_in=VF_2:bv1, ZF_in=ZF_4:bv1); + goto (%main_17); + ]; + block %main_17 [ + var R0_10:bv64 := 0x20000:bv64; + var R0_11:bv64 := bvadd(R0_10:bv64, 0x3c:bv64); + var load20_1:bv32 := load le $mem:(bv64->bv8) R0_11:bv64 32; + var R0_12:bv64 := zero_extend(32, load20_1:bv32); + var #6_1:bv32 := bvadd(extract(32,0, R0_12:bv64), 0xfffffffa:bv32); + var VF_4:bv1 := bvnot(booltobv1(eq(sign_extend(1, + bvadd(#6_1:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, R0_12:bv64)), 0x1fffffffb:bv33)))); + var CF_4:bv1 := bvnot(booltobv1(eq(zero_extend(1, + bvadd(#6_1:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, R0_12:bv64)), 0xfffffffb:bv33)))); + var ZF_6:bv1 := booltobv1(eq(bvadd(#6_1:bv32, 0x1:bv32), 0x0:bv32)); + var NF_4:bv1 := extract(32,31, bvadd(#6_1:bv32, 0x1:bv32)); + goto (%main_15,%main_9); + ]; + block %main_9 [ + var ZF_7:bv1 := ZF_6:bv1; + guard neq(bvnot(booltobv1(eq(ZF_7:bv1, 0x1:bv1))), 0x0:bv1); + goto (%main_7); + ]; + block %main_7 [ goto (%main_5); ]; + block %main_15 [ + var ZF_10:bv1 := ZF_6:bv1; + guard eq(bvnot(booltobv1(eq(ZF_10:bv1, 0x1:bv1))), 0x0:bv1); + var R0_21:bv64 := 0x0:bv64; + var R0_22:bv64 := bvadd(R0_21:bv64, 0x828:bv64); + var R30_5:bv64 := 0x7f4:bv64; + (var CF_7:bv1=CF_out, var NF_7:bv1=NF_out, var R0_23:bv64=R0_out, + var R1_6:bv64=R1_out, var R29_6:bv64=R29_out, var R30_6:bv64=R30_out, + var R31_6:bv64=R31_out, var VF_7:bv1=VF_out, var ZF_11:bv1=ZF_out) := + call @puts_1584(CF_in=CF_4:bv1, NF_in=NF_4:bv1, R0_in=R0_22:bv64, + R1_in=R1_2:bv64, R29_in=R29_3:bv64, R30_in=R30_5:bv64, R31_in=R31_3:bv64, + VF_in=VF_4:bv1, ZF_in=ZF_10:bv1); + goto (%main_13); + ]; + block %main_13 [ goto (%main_11); ]; + block %main_11 [ + var R0_24:bv64 := 0x0:bv64; + var load21_1:bv64 := load le $stack:(bv64->bv8) R31_6:bv64 64; + var R29_7:bv64 := load21_1:bv64; + var load22_1:bv64 := load le $stack:(bv64->bv8) bvadd(R31_6:bv64, 0x8:bv64) 64; + var R30_7:bv64 := load22_1:bv64; + var R31_7:bv64 := bvadd(R31_6:bv64, 0x20:bv64); + goto (%main_basil_return_1); + ]; + block %main_basil_return_1 [ goto (%returns); ]; + block %returns [ + (var CF_out:bv1 := CF_7:bv1, var NF_out:bv1 := NF_7:bv1, + var R0_out:bv64 := R0_24:bv64, var R1_out:bv64 := R1_6:bv64, + var R29_out:bv64 := R29_7:bv64, var R30_out:bv64 := R30_7:bv64, + var R31_out:bv64 := R31_7:bv64, var VF_out:bv1 := VF_7:bv1, + var ZF_out:bv1 := ZF_11:bv1); + return; + ] + ]; + proc @puts_1584(CF_in:bv1, NF_in:bv1, R0_in:bv64, R1_in:bv64, R29_in:bv64, + R30_in:bv64, R31_in:bv64, VF_in:bv1, ZF_in:bv1) + -> (CF_out:bv1, NF_out:bv1, R0_out:bv64, R1_out:bv64, R29_out:bv64, + R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1584; + .name = "puts" } + + ; $ diff after.il after_reparsed.il - diff: after.il: No such file or directory diff: after_reparsed.il: No such file or directory [2] The interpreter should give the same output for both $ diff before_loop.txt after_loop.txt - diff: before_loop.txt: No such file or directory - diff: after_loop.txt: No such file or directory - [2] diff --git a/test/cram/expr_smt.t b/test/cram/expr_smt.t index 428ed412..ef552625 100644 --- a/test/cram/expr_smt.t +++ b/test/cram/expr_smt.t @@ -3,16 +3,78 @@ Should output no errors $ bincaml script expr_smt_check.sexp - bincaml: Error in (load-il ../../examples/cntlm-output.il): Parse error: ../../examples/cntlm-output.il:58 - 58 | store le $stack bvadd($R31:bv64, 0x0:bv64) $R29:bv64 64 { .comment = "op: 0xa9007bfd" }; - ^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] Check concat rewrites work $ diff before.il after.il - diff: before.il: No such file or directory - diff: after.il: No such file or directory - [2] + 17,81c17,18 + < $R28:bv64 := bvor(bvand(bvconcat(extract(1,0, bvlshr(var1_4206396_bv64:bv64, + < 0x1f:bv64)), extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64))), + < 0xffffffff00000000:bv64), + --- + > $R28:bv64 := bvor(bvand(sign_extend(63, + > extract(32,31, var1_4206396_bv64:bv64)), 0xffffffff00000000:bv64), + [1] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 49de1fa9..f042eb19 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,15 +1,14 @@ $ bincaml script roundtrip.sexp - bincaml: Error in (load-il ../../examples/irreducible_loop_1.il): Parse error: ../../examples/irreducible_loop_1.il:20 - 20 | store le $stack #4:bv64 $R29:bv64 64 { .label = "%00000360" }; - ^^^^^ + bincaml: Error in (load-il before.il): Parse error: before.il:23 + 23 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; + ^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - diff: before.il: No such file or directory diff: after.il: No such file or directory [2] diff --git a/test/cram/typefail.t b/test/cram/typefail.t index 64cae20c..48860951 100644 --- a/test/cram/typefail.t +++ b/test/cram/typefail.t @@ -1,3 +1,67 @@ $ bincaml script ./typefail.sexp 2>/dev/null - [123] + Arguments are not of the same type in eq at statement 0 in %main_entry + Arguments are not of the same type in neq at statement 1 in %main_entry + Arguments are not of the same type in eq at statement 2 in %main_entry + Arguments are not of the same type in neq at statement 3 in %main_entry + Arguments are not of the same type in eq at statement 4 in %main_entry + Arguments are not of the same type in neq at statement 5 in %main_entry + Paramters for the function has a type mismatch: type of intneg(0x1:bv32) != type of $NF:bv1 (int != bv1) at statement 6 in %main_entry + intneg body is not a integer at statement 6 in %main_entry + bv32 is not the correct type of int for intadd at statement 7 in %main_entry + bv32 is not the correct type of int for intdiv at statement 8 in %main_entry + bv32 is not the correct type of int for intmod at statement 9 in %main_entry + bv32 is not the correct type of int for intmul at statement 10 in %main_entry + bv32 is not the correct type of int for intsub at statement 11 in %main_entry + bv32 is not the correct type of int for intlt at statement 12 in %main_entry + bv32 is not the correct type of int for intle at statement 13 in %main_entry + Paramters for the function has a type mismatch: type of bvnot(1) != type of $NF:bv1 (int != bv1) at statement 14 in %main_entry + bvnot body is not a bitvector at statement 14 in %main_entry + Paramters for the function has a type mismatch: type of bvneg(1) != type of $NF:bv1 (int != bv1) at statement 15 in %main_entry + bvneg body is not a bitvector at statement 15 in %main_entry + Paramters for the function has a type mismatch: type of zero_extend(32, 2) != type of $NF:bv64 (⊥ != bv64) at statement 16 in %main_entry + Nothing type encountered in operator at statement 16 in %main_entry + zero_extend_32 body is not a bitvector at statement 16 in %main_entry + Paramters for the function has a type mismatch: type of sign_extend(32, 2) != type of $NF:bv64 (⊥ != bv64) at statement 17 in %main_entry + Nothing type encountered in operator at statement 17 in %main_entry + sign_extend_32 body is not a bitvector at statement 17 in %main_entry + extract_32_31 body is not a bitvector at statement 18 in %main_entry + int is not of bitvector type in bvsle at statement 19 in %main_entry + int is not of bitvector type in bvslt at statement 20 in %main_entry + bv32 is not the correct type of bv64 for bvsle at statement 21 in %main_entry + bv32 is not the correct type of bv64 for bvslt at statement 22 in %main_entry + int is not of bitvector type in bvult at statement 23 in %main_entry + int is not of bitvector type in bvule at statement 24 in %main_entry + Paramters for the function has a type mismatch: type of bvand(1, 0x1:bv32) != type of $NF:bool (int != bool) at statement 25 in %main_entry + int is not of bitvector type in bvand at statement 25 in %main_entry + bool is not of bitvector type in bvor at statement 26 in %main_entry + bool is not of bitvector type in bvadd at statement 27 in %main_entry + bv32 is not the correct type of bv64 for bvadd at statement 28 in %main_entry + bool is not of bitvector type in bvmul at statement 29 in %main_entry + bv32 is not the correct type of bv64 for bvmul at statement 30 in %main_entry + bool is not of bitvector type in bvudiv at statement 31 in %main_entry + bv32 is not the correct type of bv64 for bvudiv at statement 32 in %main_entry + bool is not of bitvector type in bvurem at statement 33 in %main_entry + bv32 is not the correct type of bv64 for bvurem at statement 34 in %main_entry + bool is not of bitvector type in bvshl at statement 35 in %main_entry + bv32 is not the correct type of bv64 for bvshl at statement 36 in %main_entry + bool is not of bitvector type in bvlshr at statement 37 in %main_entry + bv32 is not the correct type of bv64 for bvlshr at statement 38 in %main_entry + bool is not of bitvector type in bvnand at statement 39 in %main_entry + bv32 is not the correct type of bv64 for bvnand at statement 40 in %main_entry + bool is not of bitvector type in bvxor at statement 41 in %main_entry + bv32 is not the correct type of bv64 for bvxor at statement 42 in %main_entry + bool is not of bitvector type in bvsub at statement 43 in %main_entry + bv32 is not the correct type of bv64 for bvsub at statement 44 in %main_entry + bool is not of bitvector type in bvsdiv at statement 45 in %main_entry + bv32 is not the correct type of bv64 for bvsdiv at statement 46 in %main_entry + bool is not of bitvector type in bvsrem at statement 47 in %main_entry + bv32 is not the correct type of bv64 for bvsrem at statement 48 in %main_entry + bool is not of bitvector type in bvsmod at statement 49 in %main_entry + bv32 is not the correct type of bv64 for bvsmod at statement 50 in %main_entry + bool is not of bitvector type in bvashr at statement 51 in %main_entry + bv32 is not the correct type of bv64 for bvashr at statement 52 in %main_entry + Address loading data (#4:bv32) does not match address size (64) at statement 54 in %main_entry + Body of booltobv1(0x7a0:bv64) is not a Boolean at statement 0 in %main_9 + booltobv1 body is not a boolean at statement 0 in %main_9 + [125] diff --git a/test/cram/typepass.t b/test/cram/typepass.t index 0fbf85ca..9e5b7466 100644 --- a/test/cram/typepass.t +++ b/test/cram/typepass.t @@ -1,6 +1 @@ $ bincaml script ./typepass.sexp - bincaml: Error in (load-il ../../examples/cat.il): Parse error: ../../examples/cat.il:61 - 61 | store le $stack bvadd($R31:bv64, 0xfffffffffffffff0:bv64) $R29:bv64 64 { .comment = "op: 0xa9bf7bfd" }; - ^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] diff --git a/test/lang/interp.ml b/test/lang/interp.ml index 2bbb890d..e8c2c28e 100644 --- a/test/lang/interp.ml +++ b/test/lang/interp.ml @@ -30,8 +30,8 @@ let%expect_test "fold_block" = \n5 | $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R0_in:bv64) 32;\ \n \027[1;31m^^^^^^^^\027[0m\ \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 Called from Expr_eval_expect__Interp.(fun) in file "test/lang/interp.ml", line 16, characters 4-60 Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 |}] diff --git a/test/lang/stmt.ml b/test/lang/stmt.ml index 58c20058..a8d103cf 100644 --- a/test/lang/stmt.ml +++ b/test/lang/stmt.ml @@ -57,9 +57,9 @@ let%expect_test "fold_block" = \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ \n \027[1;31m^^^^^\027[0m\ \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1152, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1160, characters 14-66 - Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1190, characters 20-62 + Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 + Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 + Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1203, characters 20-62 Called from Expr_eval_expect__Stmt.(fun) in file "test/lang/stmt.ml", lines 30-43, characters 4-6 Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 |}] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 4431894b..2c0d3adf 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -219,10 +219,12 @@ module.exports = grammar({ seq($.LVar, ":=", "load", $.Var), // Stmt_MultiAssign. Stmt ::= OpenParen [Assignment] CloseParen ; seq($.token_OpenParen, $.list_Assignment, $.token_CloseParen), - // Stmt_Load. Stmt ::= LVar ":=" "load" Endian Var Expr IntVal ; + // Stmt_Load_Var. Stmt ::= LVar ":=" "load" Endian Var Expr IntVal ; seq($.LVar, ":=", "load", $.Endian, $.Var, $.Expr, $.IntVal), - // Stmt_Store. Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal ; + // Stmt_Store_Var. Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal ; seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr2, $.Expr, $.IntVal), + // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal ; + seq("store", $.Endian, $.token_GlobalIdent, $.Expr, $.Expr, $.IntVal), // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent OpenParen CallParams CloseParen ; seq(optional($.LVars), "call", $.token_ProcIdent, $.token_OpenParen, optional($.CallParams), $.token_CloseParen), // Stmt_IndirectCall. Stmt ::= "indirect" "call" Expr ; From 6f5008c5ca6d6f5a77f3b1deb2b411b7957b557e Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 15:01:45 +1000 Subject: [PATCH 19/43] fix "store" by requiring higher prec in left expression --- lib/fe/AbsBasilIR.ml | 44 +++++----- lib/fe/BasilIR.cf | 52 ++++++------ lib/fe/ParBasilIR.mly | 104 ++++++++++++------------ lib/fe/PrintBasilIR.ml | 54 ++++++------- lib/fe/ShowBasilIR.ml | 46 +++++------ lib/fe/SkelBasilIR.ml | 46 +++++------ lib/transforms/may_read_uninit.ml | 23 ++---- test/cram/basicssa.t | 6 +- test/cram/roundtrip.t | 35 +++++--- test/lang/interp.ml | 93 +++++++++++++++++---- test/lang/stmt.ml | 33 ++++---- tree-sitter/grammar.js | 130 +++++++++++++++--------------- 12 files changed, 371 insertions(+), 295 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 5e60f1b3..0c1d1d50 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -62,28 +62,6 @@ and typeT = | TypeParen of openParen * typeT * closeParen | TypeMapType of mapType -and expr = - Expr_Literal of value - | Expr_Paren of openParen * expr * closeParen - | Expr_Local of localVar - | Expr_Global of globalVar - | Expr_Forall of attribSet * lambdaDef - | Expr_Exists of attribSet * lambdaDef - | Expr_Lambda of attribSet * lambdaDef - | Expr_Old of openParen * expr * closeParen - | Expr_FunctionOp of expr * openParen * expr list * closeParen - | Expr_Binary of binOp * openParen * expr * expr * closeParen - | Expr_Assoc of boolBinOp * openParen * expr list * closeParen - | Expr_Unary of unOp * openParen * expr * closeParen - | Expr_LoadBe of openParen * intVal * expr * expr * closeParen - | Expr_LoadLe of openParen * intVal * expr * expr * closeParen - | Expr_ZeroExtend of openParen * intVal * expr * closeParen - | Expr_SignExtend of openParen * intVal * expr * closeParen - | Expr_Extract of openParen * intVal * intVal * expr * closeParen - | Expr_Concat of openParen * expr list * closeParen - | Expr_Match of expr * openParen * case list * closeParen - | Expr_Cases of openParen * case list * closeParen - and intVal = IntVal_Hex of integerHex | IntVal_Dec of integerDec @@ -190,6 +168,28 @@ and value = | Value_True | Value_False +and expr = + Expr_Literal of value + | Expr_Paren of openParen * expr * closeParen + | Expr_Local of localVar + | Expr_Global of globalVar + | Expr_Forall of attribSet * lambdaDef + | Expr_Exists of attribSet * lambdaDef + | Expr_Lambda of attribSet * lambdaDef + | Expr_Old of openParen * expr * closeParen + | Expr_FunctionOp of expr * openParen * expr list * closeParen + | Expr_Binary of binOp * openParen * expr * expr * closeParen + | Expr_Assoc of boolBinOp * openParen * expr list * closeParen + | Expr_Unary of unOp * openParen * expr * closeParen + | Expr_LoadBe of openParen * intVal * expr * expr * closeParen + | Expr_LoadLe of openParen * intVal * expr * expr * closeParen + | Expr_ZeroExtend of openParen * intVal * expr * closeParen + | Expr_SignExtend of openParen * intVal * expr * closeParen + | Expr_Extract of openParen * intVal * intVal * expr * closeParen + | Expr_Concat of openParen * expr list * closeParen + | Expr_Match of expr * openParen * case list * closeParen + | Expr_Cases of openParen * case list * closeParen + and lambdaParen = LambdaParenLocalVar of localVar | LambdaParen1 of openParen * localVar * closeParen diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 753eadaa..cf9a9a8a 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -76,9 +76,6 @@ TypeParen . Type1 ::= OpenParen Type CloseParen; TypeMapType . Type ::= MapType; coercions Type 1; -separator Expr "," ; -coercions Expr 2; - IntVal_Hex . IntVal ::= IntegerHex ; IntVal_Dec . IntVal ::= IntegerDec ; @@ -113,8 +110,8 @@ separator GlobalVar ","; Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; -- lhs endian rhs addr value size -Stmt_Store_Var . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; -Stmt_Store . Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal; +Stmt_Store_Var . Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal; +Stmt_Store . Stmt ::= "store" Endian GlobalIdent Expr2 Expr IntVal; rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; @@ -195,12 +192,19 @@ Value_Int . Value ::= IntVal; Value_True . Value ::= "true" ; Value_False . Value ::= "false" ; -Expr_Literal . Expr ::= Value; +-- Expressions have precedence. Expr2 is highest precedence/strongest/indivisible, +-- Expr1 is function application, and Expr is the lowest precedence. +-- Intuitively, lowest precedence things will capture more things, e.g., the +-- quantified statements continue to the end of the expression or paren. +-- In certain places, only stronger precedence things are allowed. +separator Expr "," ; +coercions Expr 2; -Expr_Paren . Expr ::= OpenParen Expr CloseParen; +Expr_Literal . Expr2 ::= Value; -Expr_Local . Expr ::= LocalVar; -Expr_Global . Expr ::= GlobalVar; +Expr_Paren . Expr2 ::= OpenParen Expr CloseParen; +Expr_Local . Expr2 ::= LocalVar; +Expr_Global . Expr2 ::= GlobalVar; -- quantifiers @@ -208,10 +212,10 @@ rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; separator LambdaParen ","; rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; -Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; -Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; -Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; -Expr_Old . Expr ::= "old" OpenParen Expr CloseParen ; +Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; +Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; +Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; +Expr_Old . Expr2 ::= "old" OpenParen Expr CloseParen ; -- uninterpreted functions Expr_FunctionOp . Expr1 ::= Expr1 OpenParen [Expr] CloseParen; @@ -219,26 +223,26 @@ Expr_FunctionOp . Expr1 ::= Expr1 OpenParen [Expr] CloseParen; -- binary expr rules BinOp ::= BVBinOp | BVLogicalBinOp | IntLogicalBinOp | IntBinOp | EqOp ; -Expr_Binary . Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; -Expr_Assoc . Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; +Expr_Binary . Expr2 ::= BinOp OpenParen Expr "," Expr CloseParen ; +Expr_Assoc . Expr2 ::= BoolBinOp OpenParen [Expr] CloseParen ; rules UnOp ::= BVUnOp | "boolnot" | "intneg" | "booltobv1" | "gamma" | "classification"; -Expr_Unary . Expr ::= UnOp OpenParen Expr CloseParen ; +Expr_Unary . Expr2 ::= UnOp OpenParen Expr CloseParen ; -Expr_LoadBe . Expr ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; -Expr_LoadLe . Expr ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; +Expr_LoadBe . Expr2 ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; +Expr_LoadLe . Expr2 ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; -Expr_ZeroExtend . Expr ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; -Expr_SignExtend . Expr ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; -Expr_Extract . Expr ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; -Expr_Concat . Expr ::= "bvconcat" OpenParen [Expr] CloseParen ; +Expr_ZeroExtend . Expr2 ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; +Expr_SignExtend . Expr2 ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; +Expr_Extract . Expr2 ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; +Expr_Concat . Expr2 ::= "bvconcat" OpenParen [Expr] CloseParen ; CaseCase . Case ::= Expr "->" Expr ; CaseDefault . Case ::= "_" "->" Expr ; separator Case "|" ; -Expr_Match . Expr ::= "match" Expr "with" OpenParen [Case] CloseParen ; -Expr_Cases . Expr ::= "cases" OpenParen [Case] CloseParen ; +Expr_Match . Expr2 ::= "match" Expr "with" OpenParen [Case] CloseParen ; +Expr_Cases . Expr2 ::= "cases" OpenParen [Case] CloseParen ; -- operators diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 8026f63d..aed9443c 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -46,7 +46,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pExpr_list pExpr pExpr1 pExpr2 pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -62,10 +62,6 @@ open Lexing %type pMapType %type pType1 %type pTypeT -%type pExpr_list -%type pExpr -%type pExpr1 -%type pExpr2 %type pIntVal %type pBVVal %type pEndian @@ -103,6 +99,10 @@ open Lexing %type pParams %type pParams_list %type pValue +%type pExpr_list +%type pExpr +%type pExpr1 +%type pExpr2 %type pLambdaParen %type pLambdaParen_list %type pLambdaDef @@ -142,10 +142,6 @@ open Lexing %type mapType %type type1 %type typeT -%type expr_list -%type expr -%type expr1 -%type expr2 %type intVal %type bVVal %type endian @@ -183,6 +179,10 @@ open Lexing %type params %type params_list %type value +%type expr_list +%type expr +%type expr1 +%type expr2 %type lambdaParen %type lambdaParen_list %type lambdaDef @@ -257,14 +257,6 @@ pType1 : type1 TOK_EOF { $1 }; pTypeT : typeT TOK_EOF { $1 }; -pExpr_list : expr_list TOK_EOF { $1 }; - -pExpr : expr TOK_EOF { $1 }; - -pExpr1 : expr1 TOK_EOF { $1 }; - -pExpr2 : expr2 TOK_EOF { $1 }; - pIntVal : intVal TOK_EOF { $1 }; pBVVal : bVVal TOK_EOF { $1 }; @@ -339,6 +331,14 @@ pParams_list : params_list TOK_EOF { $1 }; pValue : value TOK_EOF { $1 }; +pExpr_list : expr_list TOK_EOF { $1 }; + +pExpr : expr TOK_EOF { $1 }; + +pExpr1 : expr1 TOK_EOF { $1 }; + +pExpr2 : expr2 TOK_EOF { $1 }; + pLambdaParen : lambdaParen TOK_EOF { $1 }; pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; @@ -452,40 +452,6 @@ typeT : mapType { TypeMapType $1 } | type1 { $1 } ; -expr_list : /* empty */ { [] } - | expr { (fun x -> [x]) $1 } - | expr SYMB2 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } - ; - -expr : expr1 { $1 } - | value { Expr_Literal $1 } - | openParen expr closeParen { Expr_Paren ($1, $2, $3) } - | localVar { Expr_Local $1 } - | globalVar { Expr_Global $1 } - | KW_forall attribSet lambdaDef { Expr_Forall ($2, $3) } - | KW_exists attribSet lambdaDef { Expr_Exists ($2, $3) } - | KW_fun attribSet lambdaDef { Expr_Lambda ($2, $3) } - | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } - | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } - | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } - | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } - | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } - | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } - | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } - | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } - | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } - | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } - | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } - | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } - ; - -expr1 : expr2 { $1 } - | expr1 openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } - ; - -expr2 : SYMB7 expr SYMB8 { $2 } - ; - intVal : integerHex { IntVal_Hex $1 } | integerDec { IntVal_Dec $1 } ; @@ -508,7 +474,7 @@ stmt : KW_nop { Stmt_Nop } | openParen assignment_list closeParen { Stmt_MultiAssign ($1, $2, $3) } | lVar SYMB9 KW_load endian var expr intVal { Stmt_Load_Var ($1, $4, $5, $6, $7) } | lVar SYMB9 KW_store endian var expr2 expr intVal { Stmt_Store_Var ($1, $4, $5, $6, $7, $8) } - | KW_store endian globalIdent expr expr intVal { Stmt_Store ($2, $3, $4, $5, $6) } + | KW_store endian globalIdent expr2 expr intVal { Stmt_Store ($2, $3, $4, $5, $6) } | lVars KW_call procIdent openParen callParams closeParen { Stmt_DirectCall ($1, $3, $4, $5, $6) } | KW_indirect KW_call expr { Stmt_IndirectCall $3 } | KW_assume expr { Stmt_Assume $2 } @@ -652,6 +618,40 @@ value : bVVal { Value_BV $1 } | KW_false { Value_False } ; +expr_list : /* empty */ { [] } + | expr { (fun x -> [x]) $1 } + | expr SYMB2 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } + ; + +expr : expr1 { $1 } + | KW_forall attribSet lambdaDef { Expr_Forall ($2, $3) } + | KW_exists attribSet lambdaDef { Expr_Exists ($2, $3) } + | KW_fun attribSet lambdaDef { Expr_Lambda ($2, $3) } + ; + +expr1 : expr2 { $1 } + | expr1 openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } + ; + +expr2 : SYMB7 expr SYMB8 { $2 } + | value { Expr_Literal $1 } + | openParen expr closeParen { Expr_Paren ($1, $2, $3) } + | localVar { Expr_Local $1 } + | globalVar { Expr_Global $1 } + | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } + | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } + | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } + | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } + | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } + | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } + | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } + | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } + | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } + | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } + | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } + | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } + ; + lambdaParen : localVar { LambdaParenLocalVar $1 } | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 3ba61c80..4fe9245b 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -198,32 +198,6 @@ and prtTypeTListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtTypeT 0 x]) | (_,x::xs) -> (concatD [prtTypeT 0 x ; render "," ; prtTypeTListBNFC 0 xs]) -and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with - AbsBasilIR.Expr_Literal value -> prPrec i 0 (concatD [prtValue 0 value]) - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Local localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.Expr_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) - | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> prPrec i 0 (concatD [render "forall" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> prPrec i 0 (concatD [render "exists" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> prPrec i 0 (concatD [render "fun" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) - | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> prPrec i 0 (concatD [render "old" ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> prPrec i 1 (concatD [prtExpr 1 expr ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Binary (binop, openparen, expr1, expr2, closeparen) -> prPrec i 0 (concatD [prtBinOp 0 binop ; prtOpenParen 0 openparen ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> prPrec i 0 (concatD [prtBoolBinOp 0 boolbinop ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> prPrec i 0 (concatD [prtUnOp 0 unop ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_LoadBe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_be" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_LoadLe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 0 (concatD [render "load_le" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "zero_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> prPrec i 0 (concatD [render "sign_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Extract (openparen, intval1, intval2, expr, closeparen) -> prPrec i 0 (concatD [render "extract" ; prtOpenParen 0 openparen ; prtIntVal 0 intval1 ; render "," ; prtIntVal 0 intval2 ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> prPrec i 0 (concatD [render "bvconcat" ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> prPrec i 0 (concatD [render "match" ; prtExpr 0 expr ; render "with" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) - | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> prPrec i 0 (concatD [render "cases" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) - -and prtExprListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtExpr 0 x]) - | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) and prtIntVal (i:int) (e : AbsBasilIR.intVal) : doc = match e with AbsBasilIR.IntVal_Hex integerhex -> prPrec i 0 (concatD [prtIntegerHex 0 integerhex]) | AbsBasilIR.IntVal_Dec integerdec -> prPrec i 0 (concatD [prtIntegerDec 0 integerdec]) @@ -254,7 +228,7 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with | AbsBasilIR.Stmt_MultiAssign (openparen, assignments, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtAssignmentListBNFC 0 assignments ; prtCloseParen 0 closeparen]) | AbsBasilIR.Stmt_Load_Var (lvar, endian, var, expr, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "load" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 0 expr ; prtIntVal 0 intval]) | AbsBasilIR.Stmt_Store_Var (lvar, endian, var, expr1, expr2, intval) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render ":=" ; render "store" ; prtEndian 0 endian ; prtVar 0 var ; prtExpr 2 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) - | AbsBasilIR.Stmt_Store (endian, globalident, expr1, expr2, intval) -> prPrec i 0 (concatD [render "store" ; prtEndian 0 endian ; prtGlobalIdent 0 globalident ; prtExpr 0 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) + | AbsBasilIR.Stmt_Store (endian, globalident, expr1, expr2, intval) -> prPrec i 0 (concatD [render "store" ; prtEndian 0 endian ; prtGlobalIdent 0 globalident ; prtExpr 2 expr1 ; prtExpr 0 expr2 ; prtIntVal 0 intval]) | AbsBasilIR.Stmt_DirectCall (lvars, procident, openparen, callparams, closeparen) -> prPrec i 0 (concatD [prtLVars 0 lvars ; render "call" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen ; prtCallParams 0 callparams ; prtCloseParen 0 closeparen]) | AbsBasilIR.Stmt_IndirectCall expr -> prPrec i 0 (concatD [render "indirect" ; render "call" ; prtExpr 0 expr]) | AbsBasilIR.Stmt_Assume expr -> prPrec i 0 (concatD [render "assume" ; prtExpr 0 expr]) @@ -392,6 +366,32 @@ and prtValue (i:int) (e : AbsBasilIR.value) : doc = match e with | AbsBasilIR.Value_False -> prPrec i 0 (concatD [render "false"]) +and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with + AbsBasilIR.Expr_Literal value -> prPrec i 2 (concatD [prtValue 0 value]) + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 2 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Local localvar -> prPrec i 2 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.Expr_Global globalvar -> prPrec i 2 (concatD [prtGlobalVar 0 globalvar]) + | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> prPrec i 0 (concatD [render "forall" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> prPrec i 0 (concatD [render "exists" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> prPrec i 0 (concatD [render "fun" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) + | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> prPrec i 2 (concatD [render "old" ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> prPrec i 1 (concatD [prtExpr 1 expr ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Binary (binop, openparen, expr1, expr2, closeparen) -> prPrec i 2 (concatD [prtBinOp 0 binop ; prtOpenParen 0 openparen ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> prPrec i 2 (concatD [prtBoolBinOp 0 boolbinop ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> prPrec i 2 (concatD [prtUnOp 0 unop ; prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_LoadBe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 2 (concatD [render "load_be" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_LoadLe (openparen, intval, expr1, expr2, closeparen) -> prPrec i 2 (concatD [render "load_le" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr1 ; render "," ; prtExpr 0 expr2 ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> prPrec i 2 (concatD [render "zero_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> prPrec i 2 (concatD [render "sign_extend" ; prtOpenParen 0 openparen ; prtIntVal 0 intval ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Extract (openparen, intval1, intval2, expr, closeparen) -> prPrec i 2 (concatD [render "extract" ; prtOpenParen 0 openparen ; prtIntVal 0 intval1 ; render "," ; prtIntVal 0 intval2 ; render "," ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> prPrec i 2 (concatD [render "bvconcat" ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> prPrec i 2 (concatD [render "match" ; prtExpr 0 expr ; render "with" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> prPrec i 2 (concatD [render "cases" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) + +and prtExprListBNFC i es : doc = match (i, es) with + (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtExpr 0 x]) + | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 4cde1163..4e4d74d1 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -111,29 +111,6 @@ and showTypeT (e : AbsBasilIR.typeT) : showable = match e with | AbsBasilIR.TypeMapType maptype -> s2s "TypeMapType" >> c2s ' ' >> c2s '(' >> showMapType maptype >> c2s ')' -and showExpr (e : AbsBasilIR.expr) : showable = match e with - AbsBasilIR.Expr_Literal value -> s2s "Expr_Literal" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Local localvar -> s2s "Expr_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.Expr_Global globalvar -> s2s "Expr_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' - | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> s2s "Expr_Forall" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> s2s "Expr_Exists" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> s2s "Expr_Lambda" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' - | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> s2s "Expr_Old" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Binary (binop, openparen, expr0, expr, closeparen) -> s2s "Expr_Binary" >> c2s ' ' >> c2s '(' >> showBinOp binop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> s2s "Expr_Assoc" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> s2s "Expr_Unary" >> c2s ' ' >> c2s '(' >> showUnOp unop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadBe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadLe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> s2s "Expr_ZeroExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> s2s "Expr_SignExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Extract (openparen, intval0, intval, expr, closeparen) -> s2s "Expr_Extract" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval0 >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> s2s "Expr_Concat" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> s2s "Expr_Match" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' - | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showIntVal (e : AbsBasilIR.intVal) : showable = match e with AbsBasilIR.IntVal_Hex integerhex -> s2s "IntVal_Hex" >> c2s ' ' >> c2s '(' >> showIntegerHex integerhex >> c2s ')' | AbsBasilIR.IntVal_Dec integerdec -> s2s "IntVal_Dec" >> c2s ' ' >> c2s '(' >> showIntegerDec integerdec >> c2s ')' @@ -264,6 +241,29 @@ and showValue (e : AbsBasilIR.value) : showable = match e with | AbsBasilIR.Value_False -> s2s "Value_False" +and showExpr (e : AbsBasilIR.expr) : showable = match e with + AbsBasilIR.Expr_Literal value -> s2s "Expr_Literal" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Local localvar -> s2s "Expr_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.Expr_Global globalvar -> s2s "Expr_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' + | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> s2s "Expr_Forall" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Exists (attribset, lambdadef) -> s2s "Expr_Exists" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Lambda (attribset, lambdadef) -> s2s "Expr_Lambda" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' + | AbsBasilIR.Expr_Old (openparen, expr, closeparen) -> s2s "Expr_Old" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_FunctionOp (expr, openparen, exprs, closeparen) -> s2s "Expr_FunctionOp" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Binary (binop, openparen, expr0, expr, closeparen) -> s2s "Expr_Binary" >> c2s ' ' >> c2s '(' >> showBinOp binop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> s2s "Expr_Assoc" >> c2s ' ' >> c2s '(' >> showBoolBinOp boolbinop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Unary (unop, openparen, expr, closeparen) -> s2s "Expr_Unary" >> c2s ' ' >> c2s '(' >> showUnOp unop >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadBe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> s2s "Expr_LoadLe" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr0 >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_ZeroExtend (openparen, intval, expr, closeparen) -> s2s "Expr_ZeroExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_SignExtend (openparen, intval, expr, closeparen) -> s2s "Expr_SignExtend" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Extract (openparen, intval0, intval, expr, closeparen) -> s2s "Expr_Extract" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showIntVal intval0 >> s2s ", " >> showIntVal intval >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> s2s "Expr_Concat" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> s2s "Expr_Match" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 8df82c9a..d9c84165 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -131,29 +131,6 @@ and transType (x : typeT) : result = match x with | TypeMapType maptype -> failure x -and transExpr (x : expr) : result = match x with - Expr_Literal value -> failure x - | Expr_Paren (openparen, expr, closeparen) -> failure x - | Expr_Local localvar -> failure x - | Expr_Global globalvar -> failure x - | Expr_Forall (attribset, lambdadef) -> failure x - | Expr_Exists (attribset, lambdadef) -> failure x - | Expr_Lambda (attribset, lambdadef) -> failure x - | Expr_Old (openparen, expr, closeparen) -> failure x - | Expr_FunctionOp (expr, openparen, exprs, closeparen) -> failure x - | Expr_Binary (binop, openparen, expr0, expr, closeparen) -> failure x - | Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> failure x - | Expr_Unary (unop, openparen, expr, closeparen) -> failure x - | Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> failure x - | Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> failure x - | Expr_ZeroExtend (openparen, intval, expr, closeparen) -> failure x - | Expr_SignExtend (openparen, intval, expr, closeparen) -> failure x - | Expr_Extract (openparen, intval0, intval, expr, closeparen) -> failure x - | Expr_Concat (openparen, exprs, closeparen) -> failure x - | Expr_Match (expr, openparen, cases, closeparen) -> failure x - | Expr_Cases (openparen, cases, closeparen) -> failure x - - and transIntVal (x : intVal) : result = match x with IntVal_Hex integerhex -> failure x | IntVal_Dec integerdec -> failure x @@ -284,6 +261,29 @@ and transValue (x : value) : result = match x with | Value_False -> failure x +and transExpr (x : expr) : result = match x with + Expr_Literal value -> failure x + | Expr_Paren (openparen, expr, closeparen) -> failure x + | Expr_Local localvar -> failure x + | Expr_Global globalvar -> failure x + | Expr_Forall (attribset, lambdadef) -> failure x + | Expr_Exists (attribset, lambdadef) -> failure x + | Expr_Lambda (attribset, lambdadef) -> failure x + | Expr_Old (openparen, expr, closeparen) -> failure x + | Expr_FunctionOp (expr, openparen, exprs, closeparen) -> failure x + | Expr_Binary (binop, openparen, expr0, expr, closeparen) -> failure x + | Expr_Assoc (boolbinop, openparen, exprs, closeparen) -> failure x + | Expr_Unary (unop, openparen, expr, closeparen) -> failure x + | Expr_LoadBe (openparen, intval, expr0, expr, closeparen) -> failure x + | Expr_LoadLe (openparen, intval, expr0, expr, closeparen) -> failure x + | Expr_ZeroExtend (openparen, intval, expr, closeparen) -> failure x + | Expr_SignExtend (openparen, intval, expr, closeparen) -> failure x + | Expr_Extract (openparen, intval0, intval, expr, closeparen) -> failure x + | Expr_Concat (openparen, exprs, closeparen) -> failure x + | Expr_Match (expr, openparen, cases, closeparen) -> failure x + | Expr_Cases (openparen, cases, closeparen) -> failure x + + and transLambdaParen (x : lambdaParen) : result = match x with LambdaParenLocalVar localvar -> failure x | LambdaParen1 (openparen, localvar, closeparen) -> failure x diff --git a/lib/transforms/may_read_uninit.ml b/lib/transforms/may_read_uninit.ml index cc4fba48..714b2833 100644 --- a/lib/transforms/may_read_uninit.ml +++ b/lib/transforms/may_read_uninit.ml @@ -146,18 +146,11 @@ let%expect_test "fold_block" = ~phi:(fun a i -> a) ReadUninitAnalysis.bottom block in - [%expect.unreachable] -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - ( "Parse error: :3\ - \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ - \n \027[1;31m^^^^^\027[0m\ - \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 - Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1203, characters 20-62 - Called from Transforms__May_read_uninit.(fun) in file "lib/transforms/may_read_uninit.ml", lines 125-138, characters 4-6 - Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 - |}] + [%expect {| + ($stack->RU, R31_in->RU, R0_in->RU, _->⊥) + ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, _->⊥) + ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, _->⊥) + ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, _->⊥) + ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, load46_1->W, _->⊥) + ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, $mem->RU, load46_1->W, R0_10->W, _->⊥) + |}] diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index f8eaa0e5..82e86141 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,9 +2,9 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il after.il): Parse error: after.il:33 - 33 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; - ^^^^ + bincaml: Error in (load-il after.il): Parse error: after.il:73 + 73 | (var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), + ^^^ at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 [123] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index f042eb19..8f080cb0 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,26 +1,35 @@ $ bincaml script roundtrip.sexp - bincaml: Error in (load-il before.il): Parse error: before.il:23 - 23 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; - ^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - diff: after.il: No such file or directory - [2] + 15,18c15,18 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + 121c121 + < block %main_basil_return_1 [ nop; return; ] + --- + > block %main_basil_return_1 [ return; ] + [1] $ diff before2.il after2.il - diff: before2.il: No such file or directory - diff: after2.il: No such file or directory - [2] + 7,8c7,8 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8); + < captures $mem:(bv64->bv8), $stack:(bv64->bv8); + --- + > modifies $stack:(bv64->bv8), $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $mem:(bv64->bv8); + [1] Memassign repr $ diff beforemem.il aftermem.il - diff: beforemem.il: No such file or directory - diff: aftermem.il: No such file or directory - [2] diff --git a/test/lang/interp.ml b/test/lang/interp.ml index e8c2c28e..5920d463 100644 --- a/test/lang/interp.ml +++ b/test/lang/interp.ml @@ -21,17 +21,82 @@ let%expect_test "fold_block" = let st, _ = Lang.Interp.run_prog prog in print_endline (Lang.Interp.IState.show st); (); - [%expect.unreachable] -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - ( "Parse error: :5\ - \n5 | $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R0_in:bv64) 32;\ - \n \027[1;31m^^^^^^^^\027[0m\ - \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 - Called from Expr_eval_expect__Interp.(fun) in file "test/lang/interp.ml", line 16, characters 4-60 - Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 - |}] + [%expect {| + PC= test::Return + Stack + + Top frame: + empty stack + + + trace: Store {mem = "$mem"; addr = `Bitvector (0x420034:bv64); + value = `Bitvector (0x3e8:bv32)} + + final mem state + Mem $mem:(bv64->bv8) + page at 420000 + 000: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 030: 0000 0000 e803 0000 0000 0000 0000 0000 ................ + 040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 060: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 070: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 080: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 090: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 0f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 100: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 110: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 120: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 130: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 140: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 150: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 160: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 170: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 180: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 190: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 1f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 200: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 210: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 220: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 230: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 240: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 250: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 260: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 270: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 280: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 290: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 2f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 300: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 310: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 320: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 330: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 340: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 350: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 360: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 370: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 380: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 390: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + 3f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ + |}] diff --git a/test/lang/stmt.ml b/test/lang/stmt.ml index a8d103cf..2056412d 100644 --- a/test/lang/stmt.ml +++ b/test/lang/stmt.ml @@ -48,18 +48,21 @@ let%expect_test "fold_block" = () block; print_endline (Block.to_string block); (); - [%expect.unreachable] -[@@expect.uncaught_exn {| - (* CR expect_test_collector: This test expectation appears to contain a backtrace. - This is strongly discouraged as backtraces are fragile. - Please change this test to not include a backtrace. *) - ( "Parse error: :3\ - \n3 | $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64,\ - \n \027[1;31m^^^^^\027[0m\ - \n") - Raised at Loader__Loadir.protect_parse.parse in file "lib/loadir.ml", line 1165, characters 22-61 - Called from Loader__Loadir.load_single_block_proc in file "lib/loadir.ml", line 1173, characters 14-66 - Called from Loader__Loadir.load_single_block in file "lib/loadir.ml", line 1203, characters 20-62 - Called from Expr_eval_expect__Stmt.(fun) in file "test/lang/stmt.ml", lines 30-43, characters 4-6 - Called from Ppx_expect_runtime__Test_block.Configured.dump_backtrace in file "runtime/test_block.ml", line 142, characters 10-28 - |}] + [%expect {| + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, + 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32 + var load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, + 0xfffffffffffffffc:bv64) 32 + var R1_4:bv64 := zero_extend(32, load45_1:bv32) + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32 + var load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32 + var R0_10:bv64 := zero_extend(32, load46_1:bv32) + [ + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32; + load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) 32; + R1_4:bv64 := zero_extend(32, load45_1:bv32); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32; + load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32; + R0_10:bv64 := zero_extend(32, load46_1:bv32); + ] + |}] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 2c0d3adf..58dd923a 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -123,68 +123,6 @@ module.exports = grammar({ // _. Type ::= Type1 ; $.Type1 ), - list_Expr: $ => - choice( - // []. [Expr] ::= ; - choice(), - // (:[]). [Expr] ::= Expr ; - $.Expr, - // (:). [Expr] ::= Expr "," [Expr] ; - seq($.Expr, ",", optional($.list_Expr)) - ), - Expr: $ => - choice( - // _. Expr ::= Expr1 ; - $.Expr1, - // Expr_Literal. Expr ::= Value ; - $.Value, - // Expr_Paren. Expr ::= OpenParen Expr CloseParen ; - seq($.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_Local. Expr ::= LocalVar ; - $.LocalVar, - // Expr_Global. Expr ::= GlobalVar ; - $.GlobalVar, - // Expr_Forall. Expr ::= "forall" AttribSet LambdaDef ; - seq("forall", optional($.AttribSet), $.LambdaDef), - // Expr_Exists. Expr ::= "exists" AttribSet LambdaDef ; - seq("exists", optional($.AttribSet), $.LambdaDef), - // Expr_Lambda. Expr ::= "fun" AttribSet LambdaDef ; - seq("fun", optional($.AttribSet), $.LambdaDef), - // Expr_Old. Expr ::= "old" OpenParen Expr CloseParen ; - seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_Binary. Expr ::= BinOp OpenParen Expr "," Expr CloseParen ; - seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_Assoc. Expr ::= BoolBinOp OpenParen [Expr] CloseParen ; - seq($.BoolBinOp, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Unary. Expr ::= UnOp OpenParen Expr CloseParen ; - seq($.UnOp, $.token_OpenParen, $.Expr, $.token_CloseParen), - // Expr_LoadBe. Expr ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; - seq("load_be", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_LoadLe. Expr ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; - seq("load_le", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), - // Expr_ZeroExtend. Expr ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; - seq("zero_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_SignExtend. Expr ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; - seq("sign_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_Extract. Expr ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; - seq("extract", $.token_OpenParen, $.IntVal, ",", $.IntVal, ",", $.Expr, $.token_CloseParen), - // Expr_Concat. Expr ::= "bvconcat" OpenParen [Expr] CloseParen ; - seq("bvconcat", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), - // Expr_Match. Expr ::= "match" Expr "with" OpenParen [Case] CloseParen ; - seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), - // Expr_Cases. Expr ::= "cases" OpenParen [Case] CloseParen ; - seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) - ), - Expr1: $ => - choice( - // _. Expr1 ::= Expr2 ; - $.Expr2, - // Expr_FunctionOp. Expr1 ::= Expr1 OpenParen [Expr] CloseParen ; - seq($.Expr1, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen) - ), - Expr2: $ => - // _. Expr2 ::= "(" Expr ")" ; - seq("(", $.Expr, ")"), IntVal: $ => choice( // IntVal_Hex. IntVal ::= IntegerHex ; @@ -223,8 +161,8 @@ module.exports = grammar({ seq($.LVar, ":=", "load", $.Endian, $.Var, $.Expr, $.IntVal), // Stmt_Store_Var. Stmt ::= LVar ":=" "store" Endian Var Expr2 Expr IntVal ; seq($.LVar, ":=", "store", $.Endian, $.Var, $.Expr2, $.Expr, $.IntVal), - // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr Expr IntVal ; - seq("store", $.Endian, $.token_GlobalIdent, $.Expr, $.Expr, $.IntVal), + // Stmt_Store. Stmt ::= "store" Endian GlobalIdent Expr2 Expr IntVal ; + seq("store", $.Endian, $.token_GlobalIdent, $.Expr2, $.Expr, $.IntVal), // Stmt_DirectCall. Stmt ::= LVars "call" ProcIdent OpenParen CallParams CloseParen ; seq(optional($.LVars), "call", $.token_ProcIdent, $.token_OpenParen, optional($.CallParams), $.token_CloseParen), // Stmt_IndirectCall. Stmt ::= "indirect" "call" Expr ; @@ -460,6 +398,70 @@ module.exports = grammar({ // Value_False. Value ::= "false" ; "false" ), + list_Expr: $ => + choice( + // []. [Expr] ::= ; + choice(), + // (:[]). [Expr] ::= Expr ; + $.Expr, + // (:). [Expr] ::= Expr "," [Expr] ; + seq($.Expr, ",", optional($.list_Expr)) + ), + Expr: $ => + choice( + // _. Expr ::= Expr1 ; + $.Expr1, + // Expr_Forall. Expr ::= "forall" AttribSet LambdaDef ; + seq("forall", optional($.AttribSet), $.LambdaDef), + // Expr_Exists. Expr ::= "exists" AttribSet LambdaDef ; + seq("exists", optional($.AttribSet), $.LambdaDef), + // Expr_Lambda. Expr ::= "fun" AttribSet LambdaDef ; + seq("fun", optional($.AttribSet), $.LambdaDef) + ), + Expr1: $ => + choice( + // _. Expr1 ::= Expr2 ; + $.Expr2, + // Expr_FunctionOp. Expr1 ::= Expr1 OpenParen [Expr] CloseParen ; + seq($.Expr1, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen) + ), + Expr2: $ => + choice( + // _. Expr2 ::= "(" Expr ")" ; + seq("(", $.Expr, ")"), + // Expr_Literal. Expr2 ::= Value ; + $.Value, + // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; + seq($.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_Local. Expr2 ::= LocalVar ; + $.LocalVar, + // Expr_Global. Expr2 ::= GlobalVar ; + $.GlobalVar, + // Expr_Old. Expr2 ::= "old" OpenParen Expr CloseParen ; + seq("old", $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_Binary. Expr2 ::= BinOp OpenParen Expr "," Expr CloseParen ; + seq($.BinOp, $.token_OpenParen, $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_Assoc. Expr2 ::= BoolBinOp OpenParen [Expr] CloseParen ; + seq($.BoolBinOp, $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Unary. Expr2 ::= UnOp OpenParen Expr CloseParen ; + seq($.UnOp, $.token_OpenParen, $.Expr, $.token_CloseParen), + // Expr_LoadBe. Expr2 ::= "load_be" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_be", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_LoadLe. Expr2 ::= "load_le" OpenParen IntVal "," Expr "," Expr CloseParen ; + seq("load_le", $.token_OpenParen, $.IntVal, ",", $.Expr, ",", $.Expr, $.token_CloseParen), + // Expr_ZeroExtend. Expr2 ::= "zero_extend" OpenParen IntVal "," Expr CloseParen ; + seq("zero_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_SignExtend. Expr2 ::= "sign_extend" OpenParen IntVal "," Expr CloseParen ; + seq("sign_extend", $.token_OpenParen, $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Extract. Expr2 ::= "extract" OpenParen IntVal "," IntVal "," Expr CloseParen ; + seq("extract", $.token_OpenParen, $.IntVal, ",", $.IntVal, ",", $.Expr, $.token_CloseParen), + // Expr_Concat. Expr2 ::= "bvconcat" OpenParen [Expr] CloseParen ; + seq("bvconcat", $.token_OpenParen, optional($.list_Expr), $.token_CloseParen), + // Expr_Match. Expr2 ::= "match" Expr "with" OpenParen [Case] CloseParen ; + seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), + // Expr_Cases. Expr2 ::= "cases" OpenParen [Case] CloseParen ; + seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) + ), LambdaParen: $ => choice( // LambdaParenLocalVar. LambdaParen ::= LocalVar ; From cfee8b0504d38a7253c067c91b63eb35461786cc Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 15:03:29 +1000 Subject: [PATCH 20/43] fmt --- lib/fe/dune | 3 ++- lib/lang/expr.ml | 5 ++++- lib/loadir.ml | 21 ++++++++++++++------- lib/transforms/may_read_uninit.ml | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/fe/dune b/lib/fe/dune index b6b0bbbb..6167fdc3 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -45,5 +45,6 @@ (package bincaml) (modes exe byte) (modules TestBasilIR) - (flags (:standard -open BasilIR)) + (flags + (:standard -open BasilIR)) (libraries bincaml.basilir)) diff --git a/lib/lang/expr.ml b/lib/lang/expr.ml index f996c0a9..3ba9b12c 100644 --- a/lib/lang/expr.ml +++ b/lib/lang/expr.ml @@ -386,7 +386,10 @@ module BasilExpr = struct ] | ApplyFun { func = n; args = es } -> fill nil - [ bracket "(" n ")" ^ a ^ bracket "(" (nest 2 (fill (text "," ^ newline) es)) ")" ] + [ + bracket "(" n ")" ^ a + ^ bracket "(" (nest 2 (fill (text "," ^ newline) es)) ")"; + ] | Binding { bound = vs; in_body = b } -> fill (text " ") (List.map (fun v -> bracket "(" (Var.pretty v) ")") vs) ^ text " :: " ^ a ^ bracket "(" b ")" diff --git a/lib/loadir.ml b/lib/loadir.ml index 39312a2c..a8089581 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -1270,7 +1270,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1297,7 +1298,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1326,7 +1328,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1343,12 +1346,14 @@ proc @f (ZF_in:bv1, VF_in:bv1) -> (); let buf = Buffer.create 100 in BasilIR.ShowBasilIR.showModuleT prog buf; Buffer.output_buffer stdout buf; - [%expect {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; + [%expect + {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; let ast = ast_of_concrete_ast ~name:"boop" prog in print_endline @@ Containers_pp.Pretty.to_string ~width:80 (Program.prog_pretty ast.prog); - [%expect {| + [%expect + {| prog entry @f; proc @f(VF_in:bv1, ZF_in:bv1) -> () { } @@ -1377,7 +1382,8 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect {| + [%expect + {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1438,7 +1444,8 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect {| + [%expect + {| @entry: read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) written: $R0:bv64,$mem:(bv64->bv8) diff --git a/lib/transforms/may_read_uninit.ml b/lib/transforms/may_read_uninit.ml index 714b2833..4edb270d 100644 --- a/lib/transforms/may_read_uninit.ml +++ b/lib/transforms/may_read_uninit.ml @@ -146,7 +146,8 @@ let%expect_test "fold_block" = ~phi:(fun a i -> a) ReadUninitAnalysis.bottom block in - [%expect {| + [%expect + {| ($stack->RU, R31_in->RU, R0_in->RU, _->⊥) ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, _->⊥) ($stack->RU, R31_in->RU, R0_in->RU, load45_1->W, R1_4->W, _->⊥) From e6989f80eb53dda24fc05b014ab98c21d6de4e95 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 15:46:32 +1000 Subject: [PATCH 21/43] fix phi printing --- lib/fe/AbsBasilIR.ml | 2 +- lib/fe/BasilIR.cf | 9 +- lib/fe/LexBasilIR.mll | 6 +- lib/fe/ParBasilIR.mly | 40 ++-- lib/fe/PrintBasilIR.ml | 2 +- lib/fe/ShowBasilIR.ml | 2 +- lib/fe/SkelBasilIR.ml | 2 +- lib/fe/dune | 5 +- lib/lang/block.ml | 13 +- lib/loadir.ml | 6 +- test/cram/basicssa.t | 446 +++++++++++++++++++++-------------------- test/cram/expr_smt.t | 134 ++++++------- test/cram/memassign.t | 4 +- test/lang/stmt.ml | 12 +- tree-sitter/grammar.js | 12 +- 15 files changed, 351 insertions(+), 344 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 0c1d1d50..50b601ee 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -170,7 +170,6 @@ and value = and expr = Expr_Literal of value - | Expr_Paren of openParen * expr * closeParen | Expr_Local of localVar | Expr_Global of globalVar | Expr_Forall of attribSet * lambdaDef @@ -189,6 +188,7 @@ and expr = | Expr_Concat of openParen * expr list * closeParen | Expr_Match of expr * openParen * case list * closeParen | Expr_Cases of openParen * case list * closeParen + | Expr_Paren of openParen * expr * closeParen and lambdaParen = LambdaParenLocalVar of localVar diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index cf9a9a8a..704c1cd9 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -72,9 +72,8 @@ TypeIntType . Type1 ::= IntType ; TypeBoolType . Type1 ::= BoolType ; TypeBVType . Type1 ::= BVType ; TypeParen . Type1 ::= OpenParen Type CloseParen; - TypeMapType . Type ::= MapType; -coercions Type 1; +_ . Type ::= Type1; IntVal_Hex . IntVal ::= IntegerHex ; IntVal_Dec . IntVal ::= IntegerDec ; @@ -198,11 +197,12 @@ Value_False . Value ::= "false" ; -- quantified statements continue to the end of the expression or paren. -- In certain places, only stronger precedence things are allowed. separator Expr "," ; -coercions Expr 2; + +_ . Expr ::= Expr1; +_ . Expr1 ::= Expr2; Expr_Literal . Expr2 ::= Value; -Expr_Paren . Expr2 ::= OpenParen Expr CloseParen; Expr_Local . Expr2 ::= LocalVar; Expr_Global . Expr2 ::= GlobalVar; @@ -243,6 +243,7 @@ separator Case "|" ; Expr_Match . Expr2 ::= "match" Expr "with" OpenParen [Case] CloseParen ; Expr_Cases . Expr2 ::= "cases" OpenParen [Case] CloseParen ; +Expr_Paren . Expr2 ::= OpenParen Expr CloseParen ; -- operators diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 4cf894f3..2847e63d 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -7,9 +7,9 @@ open ParBasilIR open Lexing -let symbol_table = Hashtbl.create 12 +let symbol_table = Hashtbl.create 10 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add symbol_table kwd tok) - [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);("(", SYMB7);(")", SYMB8);(":=", SYMB9);("mem:=", SYMB10);("_", SYMB11);("|", SYMB12)] + [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] let resword_table = Hashtbl.create 99 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add resword_table kwd tok) @@ -53,7 +53,7 @@ let _idchar = _letter | _digit | ['_' '\''] (* identifier character *) let _universal = _ (* universal: any character *) (* reserved words consisting of special symbols *) -let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" +let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" (* user-defined token types *) let bVTYPE = "bv" _digit + diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index aed9443c..af6b322d 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -15,12 +15,10 @@ open Lexing %token SYMB4 /* :: */ %token SYMB5 /* : */ %token SYMB6 /* = */ -%token SYMB7 /* ( */ -%token SYMB8 /* ) */ -%token SYMB9 /* := */ -%token SYMB10 /* mem:= */ -%token SYMB11 /* _ */ -%token SYMB12 /* | */ +%token SYMB7 /* := */ +%token SYMB8 /* mem:= */ +%token SYMB9 /* _ */ +%token SYMB10 /* | */ %token TOK_EOF %token TOK_Ident @@ -445,7 +443,6 @@ type1 : intType { TypeIntType $1 } | boolType { TypeBoolType $1 } | bVType { TypeBVType $1 } | openParen typeT closeParen { TypeParen ($1, $2, $3) } - | SYMB7 typeT SYMB8 { $2 } ; typeT : mapType { TypeMapType $1 } @@ -463,17 +460,17 @@ endian : KW_le { Endian_Little } | KW_be { Endian_Big } ; -assignment : lVar SYMB9 expr { Assignment1 ($1, $3) } +assignment : lVar SYMB7 expr { Assignment1 ($1, $3) } ; stmt : KW_nop { Stmt_Nop } | assignment { Stmt_SingleAssign $1 } - | lVar SYMB10 expr { Stmt_MemAssign ($1, $3) } - | lVar SYMB9 KW_store expr { Stmt_ScalarStore ($1, $4) } - | lVar SYMB9 KW_load var { Stmt_ScalarLoad ($1, $4) } + | lVar SYMB8 expr { Stmt_MemAssign ($1, $3) } + | lVar SYMB7 KW_store expr { Stmt_ScalarStore ($1, $4) } + | lVar SYMB7 KW_load var { Stmt_ScalarLoad ($1, $4) } | openParen assignment_list closeParen { Stmt_MultiAssign ($1, $2, $3) } - | lVar SYMB9 KW_load endian var expr intVal { Stmt_Load_Var ($1, $4, $5, $6, $7) } - | lVar SYMB9 KW_store endian var expr2 expr intVal { Stmt_Store_Var ($1, $4, $5, $6, $7, $8) } + | lVar SYMB7 KW_load endian var expr intVal { Stmt_Load_Var ($1, $4, $5, $6, $7) } + | lVar SYMB7 KW_store endian var expr2 expr intVal { Stmt_Store_Var ($1, $4, $5, $6, $7, $8) } | KW_store endian globalIdent expr2 expr intVal { Stmt_Store ($2, $3, $4, $5, $6) } | lVars KW_call procIdent openParen callParams closeParen { Stmt_DirectCall ($1, $3, $4, $5, $6) } | KW_indirect KW_call expr { Stmt_IndirectCall $3 } @@ -516,9 +513,9 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVar_list closeParen SYMB9 { LVars_LocalList ($2, $3, $4) } - | openParen lVar_list closeParen SYMB9 { LVars_List ($1, $2, $3) } - | openParen namedCallReturn_list closeParen SYMB9 { NamedLVars_List ($1, $2, $3) } + | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } + | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } + | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } ; namedCallArg : localIdent SYMB6 expr { NamedCallArg1 ($1, $3) } @@ -569,7 +566,7 @@ phiExpr_list : /* empty */ { [] } | phiExpr SYMB2 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -phiAssign : lVar SYMB9 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } +phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } ; phiAssign_list : /* empty */ { [] } @@ -633,9 +630,7 @@ expr1 : expr2 { $1 } | expr1 openParen expr_list closeParen { Expr_FunctionOp ($1, $2, $3, $4) } ; -expr2 : SYMB7 expr SYMB8 { $2 } - | value { Expr_Literal $1 } - | openParen expr closeParen { Expr_Paren ($1, $2, $3) } +expr2 : value { Expr_Literal $1 } | localVar { Expr_Local $1 } | globalVar { Expr_Global $1 } | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } @@ -650,6 +645,7 @@ expr2 : SYMB7 expr SYMB8 { $2 } | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } + | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; lambdaParen : localVar { LambdaParenLocalVar $1 } @@ -680,12 +676,12 @@ unOp : bVUnOp { UnOpBVUnOp $1 } ; case : expr SYMB3 expr { CaseCase ($1, $3) } - | SYMB11 SYMB3 expr { CaseDefault $3 } + | SYMB9 SYMB3 expr { CaseDefault $3 } ; case_list : /* empty */ { [] } | case { (fun x -> [x]) $1 } - | case SYMB12 case_list { (fun (x,xs) -> x::xs) ($1, $3) } + | case SYMB10 case_list { (fun (x,xs) -> x::xs) ($1, $3) } ; eqOp : KW_eq { EqOp_eq } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 4fe9245b..1a87ba8c 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -368,7 +368,6 @@ and prtValue (i:int) (e : AbsBasilIR.value) : doc = match e with and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with AbsBasilIR.Expr_Literal value -> prPrec i 2 (concatD [prtValue 0 value]) - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 2 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Local localvar -> prPrec i 2 (concatD [prtLocalVar 0 localvar]) | AbsBasilIR.Expr_Global globalvar -> prPrec i 2 (concatD [prtGlobalVar 0 globalvar]) | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> prPrec i 0 (concatD [render "forall" ; prtAttribSet 0 attribset ; prtLambdaDef 0 lambdadef]) @@ -387,6 +386,7 @@ and prtExpr (i:int) (e : AbsBasilIR.expr) : doc = match e with | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> prPrec i 2 (concatD [render "bvconcat" ; prtOpenParen 0 openparen ; prtExprListBNFC 0 exprs ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> prPrec i 2 (concatD [render "match" ; prtExpr 0 expr ; render "with" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> prPrec i 2 (concatD [render "cases" ; prtOpenParen 0 openparen ; prtCaseListBNFC 0 cases ; prtCloseParen 0 closeparen]) + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> prPrec i 2 (concatD [prtOpenParen 0 openparen ; prtExpr 0 expr ; prtCloseParen 0 closeparen]) and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 4e4d74d1..769b7d20 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -243,7 +243,6 @@ and showValue (e : AbsBasilIR.value) : showable = match e with and showExpr (e : AbsBasilIR.expr) : showable = match e with AbsBasilIR.Expr_Literal value -> s2s "Expr_Literal" >> c2s ' ' >> c2s '(' >> showValue value >> c2s ')' - | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Local localvar -> s2s "Expr_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' | AbsBasilIR.Expr_Global globalvar -> s2s "Expr_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' | AbsBasilIR.Expr_Forall (attribset, lambdadef) -> s2s "Expr_Forall" >> c2s ' ' >> c2s '(' >> showAttribSet attribset >> s2s ", " >> showLambdaDef lambdadef >> c2s ')' @@ -262,6 +261,7 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Concat (openparen, exprs, closeparen) -> s2s "Expr_Concat" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showExpr exprs >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Match (expr, openparen, cases, closeparen) -> s2s "Expr_Match" >> c2s ' ' >> c2s '(' >> showExpr expr >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.Expr_Cases (openparen, cases, closeparen) -> s2s "Expr_Cases" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showCase cases >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index d9c84165..d60eb8bb 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -263,7 +263,6 @@ and transValue (x : value) : result = match x with and transExpr (x : expr) : result = match x with Expr_Literal value -> failure x - | Expr_Paren (openparen, expr, closeparen) -> failure x | Expr_Local localvar -> failure x | Expr_Global globalvar -> failure x | Expr_Forall (attribset, lambdadef) -> failure x @@ -282,6 +281,7 @@ and transExpr (x : expr) : result = match x with | Expr_Concat (openparen, exprs, closeparen) -> failure x | Expr_Match (expr, openparen, cases, closeparen) -> failure x | Expr_Cases (openparen, cases, closeparen) -> failure x + | Expr_Paren (openparen, expr, closeparen) -> failure x and transLambdaParen (x : lambdaParen) : result = match x with diff --git a/lib/fe/dune b/lib/fe/dune index 6167fdc3..9771b1ac 100644 --- a/lib/fe/dune +++ b/lib/fe/dune @@ -34,10 +34,7 @@ (mode promote) (action (progn - (run bnfc --ocaml-menhir -o . BasilIR.cf) - ; HACK: BNFC incorrectly treats "(" ")" as a resword which prevents it - ; being lexed as an OpenParen/CloseParen which we need. - (run sed -i.bak "s_| \"(\" | \")\"__" LexBasilIR.mll)))) + (run bnfc --ocaml-menhir -o . BasilIR.cf)))) (executable (name TestBasilIR) diff --git a/lib/lang/block.ml b/lib/lang/block.ml index b5538caa..f723e812 100644 --- a/lib/lang/block.ml +++ b/lib/lang/block.ml @@ -42,22 +42,21 @@ let pretty show_lvar show_var show_expr ?(terminator = []) ?block_id b = Trace_core.with_span ~__FILE__ ~__LINE__ "pretty-block" @@ fun _ -> let open Containers_pp in let open Containers_pp.Infix in + let bracket' ~n l d r : t = + group (text l ^ nest n (nl ^ d) ^ nl ^ text r) in let phi = match b.phis with - | [] -> [] + | [] -> nil | o -> let phi = List.map (pretty_phi show_lvar show_var) o in - [ bracket "(" (fill (text "," ^ newline) phi) ")" ] + bracket' ~n:2 "(" (append_l ~sep:(text "," ^ nl) (List.map group phi)) ") " in let stmts = Vector.to_list b.stmts |> List.map (Stmt.pretty show_lvar show_var show_expr) in - let stmts = phi @ stmts @ terminator |> List.map (fun i -> i ^ text ";") in - let bracket' l d r : t = - group (text l ^ nest (String.length l) d ^ nl ^ text r) - in - let stmts = bracket' "[" (nest 2 @@ nl ^ append_nl stmts) "]" in + let stmts = stmts @ terminator |> List.map (fun i -> i ^ text ";") in + let stmts = phi ^ bracket' ~n:2 "[" (append_nl stmts) "]" in let name = Option.map (fun id -> text "block " ^ text (ID.to_string id) ^ text " ") diff --git a/lib/loadir.ml b/lib/loadir.ml index a8089581..3745a7a7 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -1393,9 +1393,9 @@ proc @main_4196260 () -> () [ block %main_entry [ - $NF:bv1 := 0x1:bv1; - $ZF:bv1 := $NF:bv1; - goto (%main_basil_return_1); + $NF:bv1 := 0x1:bv1; + $ZF:bv1 := $NF:bv1; + goto (%main_basil_return_1); ]; block %main_basil_return_1 [ nop; return; ] ]; diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index 82e86141..e257a4de 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,11 +2,6 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il after.il): Parse error: after.il:73 - 73 | (var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), - ^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] $ cat before.il var $CF:bv1; @@ -30,104 +25,104 @@ Run on basic irreducible loop example [ block %main_entry [ - var #4:bv64 := bvadd($R31:bv64, 0xffffffffffffffe0:bv64); - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4:bv64, 0x8:bv64) $R30:bv64 64; - $R31:bv64 := #4:bv64; - $R29:bv64 := $R31:bv64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x1c:bv64) extract(32,0, $R0:bv64) 32; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x10:bv64) $R1:bv64 64; - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 0x0:bv32 32; - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x40:bv64); - var load18:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load18:bv32); - $R0:bv64 := zero_extend(32, bvconcat(0x0:bv31, extract(1,0, $R0:bv64))); - var #5:bv32 := bvadd(extract(32,0, $R0:bv64), 0xffffffff:bv32); - $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#5:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x0:bv33)))); - $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#5:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0x100000000:bv33)))); - $ZF:bv1 := booltobv1(eq(bvadd(#5:bv32, 0x1:bv32), 0x0:bv32)); - $NF:bv1 := extract(32,31, bvadd(#5:bv32, 0x1:bv32)); - goto (%main_27,%main_23); + var #4:bv64 := bvadd($R31:bv64, 0xffffffffffffffe0:bv64); + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4:bv64 $R29:bv64 64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4:bv64, 0x8:bv64) $R30:bv64 64; + $R31:bv64 := #4:bv64; + $R29:bv64 := $R31:bv64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x1c:bv64) extract(32,0, $R0:bv64) 32; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd($R31:bv64, 0x10:bv64) $R1:bv64 64; + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 0x0:bv32 32; + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x40:bv64); + var load18:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load18:bv32); + $R0:bv64 := zero_extend(32, bvconcat(0x0:bv31, extract(1,0, $R0:bv64))); + var #5:bv32 := bvadd(extract(32,0, $R0:bv64), 0xffffffff:bv32); + $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#5:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x0:bv33)))); + $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#5:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0x100000000:bv33)))); + $ZF:bv1 := booltobv1(eq(bvadd(#5:bv32, 0x1:bv32), 0x0:bv32)); + $NF:bv1 := extract(32,31, bvadd(#5:bv32, 0x1:bv32)); + goto (%main_27,%main_23); ]; block %main_23 [ - guard neq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_21); + guard neq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_21); ]; block %main_21 [ goto (%main_19); ]; block %main_27 [ - guard eq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_25); + guard eq(booltobv1(eq($ZF:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_25); ]; block %main_25 [ goto (%main_5); ]; block %main_5 [ - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); - $R30:bv64 := 0x7a0:bv64; - - call @puts_1584(); - goto (%main_3); + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); + $R30:bv64 := 0x7a0:bv64; + + call @puts_1584(); + goto (%main_3); ]; block %main_3 [ - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - var load19:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load19:bv32); - $R1:bv64 := zero_extend(32, bvadd(extract(32,0, $R0:bv64), 0x1:bv32)); - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 extract(32,0, $R1:bv64) 32; - goto (%main_19); + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + var load19:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load19:bv32); + $R1:bv64 := zero_extend(32, bvadd(extract(32,0, $R0:bv64), 0x1:bv32)); + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) $R0:bv64 extract(32,0, $R1:bv64) 32; + goto (%main_19); ]; block %main_19 [ - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); - $R30:bv64 := 0x7d0:bv64; - - call @puts_1584(); - goto (%main_17); + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x820:bv64); + $R30:bv64 := 0x7d0:bv64; + + call @puts_1584(); + goto (%main_17); ]; block %main_17 [ - $R0:bv64 := 0x20000:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); - var load20:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; - $R0:bv64 := zero_extend(32, load20:bv32); - var #6:bv32 := bvadd(extract(32,0, $R0:bv64), 0xfffffffa:bv32); - $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#6:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x1fffffffb:bv33)))); - $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#6:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0xfffffffb:bv33)))); - $ZF:bv1 := booltobv1(eq(bvadd(#6:bv32, 0x1:bv32), 0x0:bv32)); - $NF:bv1 := extract(32,31, bvadd(#6:bv32, 0x1:bv32)); - goto (%main_15,%main_9); + $R0:bv64 := 0x20000:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x3c:bv64); + var load20:bv32 := load le $mem:(bv64->bv8) $R0:bv64 32; + $R0:bv64 := zero_extend(32, load20:bv32); + var #6:bv32 := bvadd(extract(32,0, $R0:bv64), 0xfffffffa:bv32); + $VF:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#6:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, $R0:bv64)), 0x1fffffffb:bv33)))); + $CF:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#6:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, $R0:bv64)), 0xfffffffb:bv33)))); + $ZF:bv1 := booltobv1(eq(bvadd(#6:bv32, 0x1:bv32), 0x0:bv32)); + $NF:bv1 := extract(32,31, bvadd(#6:bv32, 0x1:bv32)); + goto (%main_15,%main_9); ]; block %main_9 [ - guard neq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); - goto (%main_7); + guard neq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); + goto (%main_7); ]; block %main_7 [ goto (%main_5); ]; block %main_15 [ - guard eq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); - $R0:bv64 := 0x0:bv64; - $R0:bv64 := bvadd($R0:bv64, 0x828:bv64); - $R30:bv64 := 0x7f4:bv64; - - call @puts_1584(); - goto (%main_13); + guard eq(bvnot(booltobv1(eq($ZF:bv1, 0x1:bv1))), 0x0:bv1); + $R0:bv64 := 0x0:bv64; + $R0:bv64 := bvadd($R0:bv64, 0x828:bv64); + $R30:bv64 := 0x7f4:bv64; + + call @puts_1584(); + goto (%main_13); ]; block %main_13 [ goto (%main_11); ]; block %main_11 [ - $R0:bv64 := 0x0:bv64; - var load21:bv64 := load le $stack:(bv64->bv8) $R31:bv64 64; - $R29:bv64 := load21:bv64; - var load22:bv64 := load le $stack:(bv64->bv8) bvadd($R31:bv64, 0x8:bv64) 64; - $R30:bv64 := load22:bv64; - $R31:bv64 := bvadd($R31:bv64, 0x20:bv64); - goto (%main_basil_return_1); + $R0:bv64 := 0x0:bv64; + var load21:bv64 := load le $stack:(bv64->bv8) $R31:bv64 64; + $R29:bv64 := load21:bv64; + var load22:bv64 := load le $stack:(bv64->bv8) bvadd($R31:bv64, 0x8:bv64) 64; + $R30:bv64 := load22:bv64; + $R31:bv64 := bvadd($R31:bv64, 0x20:bv64); + goto (%main_basil_return_1); ]; block %main_basil_return_1 [ nop; return; ] ]; @@ -160,156 +155,152 @@ Run on basic irreducible loop example [ block %inputs [ - (var CF:bv1 := CF_in:bv1, var NF:bv1 := NF_in:bv1, var R0:bv64 := R0_in:bv64, - var R1:bv64 := R1_in:bv64, var R29:bv64 := R29_in:bv64, - var R30:bv64 := R30_in:bv64, var R31:bv64 := R31_in:bv64, - var VF:bv1 := VF_in:bv1, var ZF:bv1 := ZF_in:bv1); - goto (%main_entry); + (var CF:bv1 := CF_in:bv1, var NF:bv1 := NF_in:bv1, var R0:bv64 := R0_in:bv64, + var R1:bv64 := R1_in:bv64, var R29:bv64 := R29_in:bv64, + var R30:bv64 := R30_in:bv64, var R31:bv64 := R31_in:bv64, + var VF:bv1 := VF_in:bv1, var ZF:bv1 := ZF_in:bv1); + goto (%main_entry); ]; block %main_entry [ - var #4_1:bv64 := bvadd(R31:bv64, 0xffffffffffffffe0:bv64); - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4_1:bv64, 0x8:bv64) R30:bv64 64; - var R31_1:bv64 := #4_1:bv64; - var R29_1:bv64 := R31_1:bv64; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, - 0x1c:bv64) extract(32,0, R0:bv64) 32; - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, - 0x10:bv64) R1:bv64 64; - var R0_1:bv64 := 0x20000:bv64; - var R0_2:bv64 := bvadd(R0_1:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_2:bv64 0x0:bv32 32; - var R0_3:bv64 := 0x20000:bv64; - var R0_4:bv64 := bvadd(R0_3:bv64, 0x40:bv64); - var load18_1:bv32 := load le $mem:(bv64->bv8) R0_4:bv64 32; - var R0_5:bv64 := zero_extend(32, load18_1:bv32); - var R0_6:bv64 := zero_extend(32, - bvconcat(0x0:bv31, extract(1,0, R0_5:bv64))); - var #5_1:bv32 := bvadd(extract(32,0, R0_6:bv64), 0xffffffff:bv32); - var VF_1:bv1 := bvnot(booltobv1(eq(sign_extend(1, - bvadd(#5_1:bv32, 0x1:bv32)), sign_extend(1, extract(32,0, R0_6:bv64))))); - var CF_1:bv1 := bvnot(booltobv1(eq(zero_extend(1, - bvadd(#5_1:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, R0_6:bv64)), 0x100000000:bv33)))); - var ZF_1:bv1 := booltobv1(eq(bvadd(#5_1:bv32, 0x1:bv32), 0x0:bv32)); - var NF_1:bv1 := extract(32,31, bvadd(#5_1:bv32, 0x1:bv32)); - goto (%main_27,%main_23); + var #4_1:bv64 := bvadd(R31:bv64, 0xffffffffffffffe0:bv64); + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) #4_1:bv64 R29:bv64 64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(#4_1:bv64, 0x8:bv64) R30:bv64 64; + var R31_1:bv64 := #4_1:bv64; + var R29_1:bv64 := R31_1:bv64; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, 0x1c:bv64) extract(32,0, R0:bv64) 32; + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_1:bv64, 0x10:bv64) R1:bv64 64; + var R0_1:bv64 := 0x20000:bv64; + var R0_2:bv64 := bvadd(R0_1:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_2:bv64 0x0:bv32 32; + var R0_3:bv64 := 0x20000:bv64; + var R0_4:bv64 := bvadd(R0_3:bv64, 0x40:bv64); + var load18_1:bv32 := load le $mem:(bv64->bv8) R0_4:bv64 32; + var R0_5:bv64 := zero_extend(32, load18_1:bv32); + var R0_6:bv64 := zero_extend(32, bvconcat(0x0:bv31, extract(1,0, R0_5:bv64))); + var #5_1:bv32 := bvadd(extract(32,0, R0_6:bv64), 0xffffffff:bv32); + var VF_1:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#5_1:bv32, 0x1:bv32)), + sign_extend(1, extract(32,0, R0_6:bv64))))); + var CF_1:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#5_1:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, R0_6:bv64)), 0x100000000:bv33)))); + var ZF_1:bv1 := booltobv1(eq(bvadd(#5_1:bv32, 0x1:bv32), 0x0:bv32)); + var NF_1:bv1 := extract(32,31, bvadd(#5_1:bv32, 0x1:bv32)); + goto (%main_27,%main_23); ]; block %main_23 [ - var ZF_3:bv1 := ZF_1:bv1; - guard neq(booltobv1(eq(ZF_3:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_21); + var ZF_3:bv1 := ZF_1:bv1; + guard neq(booltobv1(eq(ZF_3:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_21); ]; block %main_21 [ goto (%main_19); ]; block %main_27 [ - var ZF_2:bv1 := ZF_1:bv1; - guard eq(booltobv1(eq(ZF_2:bv1, 0x1:bv1)), 0x0:bv1); - goto (%main_25); + var ZF_2:bv1 := ZF_1:bv1; + guard eq(booltobv1(eq(ZF_2:bv1, 0x1:bv1)), 0x0:bv1); + goto (%main_25); ]; block %main_25 [ goto (%main_5); ]; - block %main_5 [ - (var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), - var NF_5:bv1 := phi(%main_25 -> NF_1:bv1, %main_7 -> NF_4:bv1), - var R1_3:bv64 := phi(%main_25 -> R1:bv64, %main_7 -> R1_2:bv64), - var R29_4:bv64 := phi(%main_25 -> R29_1:bv64, %main_7 -> R29_3:bv64), - var R31_4:bv64 := phi(%main_25 -> R31_1:bv64, %main_7 -> R31_3:bv64), - var VF_5:bv1 := phi(%main_25 -> VF_1:bv1, %main_7 -> VF_4:bv1), - var ZF_8:bv1 := phi(%main_25 -> ZF_2:bv1, %main_7 -> ZF_7:bv1)); - var R0_13:bv64 := 0x0:bv64; - var R0_14:bv64 := bvadd(R0_13:bv64, 0x820:bv64); - var R30_3:bv64 := 0x7a0:bv64; - (var CF_6:bv1=CF_out, var NF_6:bv1=NF_out, var R0_15:bv64=R0_out, - var R1_4:bv64=R1_out, var R29_5:bv64=R29_out, var R30_4:bv64=R30_out, - var R31_5:bv64=R31_out, var VF_6:bv1=VF_out, var ZF_9:bv1=ZF_out) := - call @puts_1584(CF_in=CF_5:bv1, NF_in=NF_5:bv1, R0_in=R0_14:bv64, - R1_in=R1_3:bv64, R29_in=R29_4:bv64, R30_in=R30_3:bv64, R31_in=R31_4:bv64, - VF_in=VF_5:bv1, ZF_in=ZF_8:bv1); - goto (%main_3); + block %main_5 ( + var CF_5:bv1 := phi(%main_25 -> CF_1:bv1, %main_7 -> CF_4:bv1), + var NF_5:bv1 := phi(%main_25 -> NF_1:bv1, %main_7 -> NF_4:bv1), + var R1_3:bv64 := phi(%main_25 -> R1:bv64, %main_7 -> R1_2:bv64), + var R29_4:bv64 := phi(%main_25 -> R29_1:bv64, %main_7 -> R29_3:bv64), + var R31_4:bv64 := phi(%main_25 -> R31_1:bv64, %main_7 -> R31_3:bv64), + var VF_5:bv1 := phi(%main_25 -> VF_1:bv1, %main_7 -> VF_4:bv1), + var ZF_8:bv1 := phi(%main_25 -> ZF_2:bv1, %main_7 -> ZF_7:bv1) + ) [ + var R0_13:bv64 := 0x0:bv64; + var R0_14:bv64 := bvadd(R0_13:bv64, 0x820:bv64); + var R30_3:bv64 := 0x7a0:bv64; + (var CF_6:bv1=CF_out, var NF_6:bv1=NF_out, var R0_15:bv64=R0_out, + var R1_4:bv64=R1_out, var R29_5:bv64=R29_out, var R30_4:bv64=R30_out, + var R31_5:bv64=R31_out, var VF_6:bv1=VF_out, var ZF_9:bv1=ZF_out) := + call @puts_1584(CF_in=CF_5:bv1, NF_in=NF_5:bv1, R0_in=R0_14:bv64, + R1_in=R1_3:bv64, R29_in=R29_4:bv64, R30_in=R30_3:bv64, R31_in=R31_4:bv64, + VF_in=VF_5:bv1, ZF_in=ZF_8:bv1); + goto (%main_3); ]; block %main_3 [ - var R0_16:bv64 := 0x20000:bv64; - var R0_17:bv64 := bvadd(R0_16:bv64, 0x3c:bv64); - var load19_1:bv32 := load le $mem:(bv64->bv8) R0_17:bv64 32; - var R0_18:bv64 := zero_extend(32, load19_1:bv32); - var R1_5:bv64 := zero_extend(32, bvadd(extract(32,0, R0_18:bv64), 0x1:bv32)); - var R0_19:bv64 := 0x20000:bv64; - var R0_20:bv64 := bvadd(R0_19:bv64, 0x3c:bv64); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_20:bv64 extract(32,0, R1_5:bv64) 32; - goto (%main_19); + var R0_16:bv64 := 0x20000:bv64; + var R0_17:bv64 := bvadd(R0_16:bv64, 0x3c:bv64); + var load19_1:bv32 := load le $mem:(bv64->bv8) R0_17:bv64 32; + var R0_18:bv64 := zero_extend(32, load19_1:bv32); + var R1_5:bv64 := zero_extend(32, bvadd(extract(32,0, R0_18:bv64), 0x1:bv32)); + var R0_19:bv64 := 0x20000:bv64; + var R0_20:bv64 := bvadd(R0_19:bv64, 0x3c:bv64); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) R0_20:bv64 extract(32,0, R1_5:bv64) 32; + goto (%main_19); ]; - block %main_19 [ - (var CF_2:bv1 := phi(%main_3 -> CF_6:bv1, %main_21 -> CF_1:bv1), - var NF_2:bv1 := phi(%main_3 -> NF_6:bv1, %main_21 -> NF_1:bv1), - var R1_1:bv64 := phi(%main_3 -> R1_5:bv64, %main_21 -> R1:bv64), - var R29_2:bv64 := phi(%main_3 -> R29_5:bv64, %main_21 -> R29_1:bv64), - var R31_2:bv64 := phi(%main_3 -> R31_5:bv64, %main_21 -> R31_1:bv64), - var VF_2:bv1 := phi(%main_3 -> VF_6:bv1, %main_21 -> VF_1:bv1), - var ZF_4:bv1 := phi(%main_3 -> ZF_9:bv1, %main_21 -> ZF_3:bv1)); - var R0_7:bv64 := 0x0:bv64; - var R0_8:bv64 := bvadd(R0_7:bv64, 0x820:bv64); - var R30_1:bv64 := 0x7d0:bv64; - (var CF_3:bv1=CF_out, var NF_3:bv1=NF_out, var R0_9:bv64=R0_out, - var R1_2:bv64=R1_out, var R29_3:bv64=R29_out, var R30_2:bv64=R30_out, - var R31_3:bv64=R31_out, var VF_3:bv1=VF_out, var ZF_5:bv1=ZF_out) := - call @puts_1584(CF_in=CF_2:bv1, NF_in=NF_2:bv1, R0_in=R0_8:bv64, - R1_in=R1_1:bv64, R29_in=R29_2:bv64, R30_in=R30_1:bv64, R31_in=R31_2:bv64, - VF_in=VF_2:bv1, ZF_in=ZF_4:bv1); - goto (%main_17); + block %main_19 ( + var CF_2:bv1 := phi(%main_3 -> CF_6:bv1, %main_21 -> CF_1:bv1), + var NF_2:bv1 := phi(%main_3 -> NF_6:bv1, %main_21 -> NF_1:bv1), + var R1_1:bv64 := phi(%main_3 -> R1_5:bv64, %main_21 -> R1:bv64), + var R29_2:bv64 := phi(%main_3 -> R29_5:bv64, %main_21 -> R29_1:bv64), + var R31_2:bv64 := phi(%main_3 -> R31_5:bv64, %main_21 -> R31_1:bv64), + var VF_2:bv1 := phi(%main_3 -> VF_6:bv1, %main_21 -> VF_1:bv1), + var ZF_4:bv1 := phi(%main_3 -> ZF_9:bv1, %main_21 -> ZF_3:bv1) + ) [ + var R0_7:bv64 := 0x0:bv64; + var R0_8:bv64 := bvadd(R0_7:bv64, 0x820:bv64); + var R30_1:bv64 := 0x7d0:bv64; + (var CF_3:bv1=CF_out, var NF_3:bv1=NF_out, var R0_9:bv64=R0_out, + var R1_2:bv64=R1_out, var R29_3:bv64=R29_out, var R30_2:bv64=R30_out, + var R31_3:bv64=R31_out, var VF_3:bv1=VF_out, var ZF_5:bv1=ZF_out) := + call @puts_1584(CF_in=CF_2:bv1, NF_in=NF_2:bv1, R0_in=R0_8:bv64, + R1_in=R1_1:bv64, R29_in=R29_2:bv64, R30_in=R30_1:bv64, R31_in=R31_2:bv64, + VF_in=VF_2:bv1, ZF_in=ZF_4:bv1); + goto (%main_17); ]; block %main_17 [ - var R0_10:bv64 := 0x20000:bv64; - var R0_11:bv64 := bvadd(R0_10:bv64, 0x3c:bv64); - var load20_1:bv32 := load le $mem:(bv64->bv8) R0_11:bv64 32; - var R0_12:bv64 := zero_extend(32, load20_1:bv32); - var #6_1:bv32 := bvadd(extract(32,0, R0_12:bv64), 0xfffffffa:bv32); - var VF_4:bv1 := bvnot(booltobv1(eq(sign_extend(1, - bvadd(#6_1:bv32, 0x1:bv32)), - bvadd(sign_extend(1, extract(32,0, R0_12:bv64)), 0x1fffffffb:bv33)))); - var CF_4:bv1 := bvnot(booltobv1(eq(zero_extend(1, - bvadd(#6_1:bv32, 0x1:bv32)), - bvadd(zero_extend(1, extract(32,0, R0_12:bv64)), 0xfffffffb:bv33)))); - var ZF_6:bv1 := booltobv1(eq(bvadd(#6_1:bv32, 0x1:bv32), 0x0:bv32)); - var NF_4:bv1 := extract(32,31, bvadd(#6_1:bv32, 0x1:bv32)); - goto (%main_15,%main_9); + var R0_10:bv64 := 0x20000:bv64; + var R0_11:bv64 := bvadd(R0_10:bv64, 0x3c:bv64); + var load20_1:bv32 := load le $mem:(bv64->bv8) R0_11:bv64 32; + var R0_12:bv64 := zero_extend(32, load20_1:bv32); + var #6_1:bv32 := bvadd(extract(32,0, R0_12:bv64), 0xfffffffa:bv32); + var VF_4:bv1 := bvnot(booltobv1(eq(sign_extend(1, bvadd(#6_1:bv32, 0x1:bv32)), + bvadd(sign_extend(1, extract(32,0, R0_12:bv64)), 0x1fffffffb:bv33)))); + var CF_4:bv1 := bvnot(booltobv1(eq(zero_extend(1, bvadd(#6_1:bv32, 0x1:bv32)), + bvadd(zero_extend(1, extract(32,0, R0_12:bv64)), 0xfffffffb:bv33)))); + var ZF_6:bv1 := booltobv1(eq(bvadd(#6_1:bv32, 0x1:bv32), 0x0:bv32)); + var NF_4:bv1 := extract(32,31, bvadd(#6_1:bv32, 0x1:bv32)); + goto (%main_15,%main_9); ]; block %main_9 [ - var ZF_7:bv1 := ZF_6:bv1; - guard neq(bvnot(booltobv1(eq(ZF_7:bv1, 0x1:bv1))), 0x0:bv1); - goto (%main_7); + var ZF_7:bv1 := ZF_6:bv1; + guard neq(bvnot(booltobv1(eq(ZF_7:bv1, 0x1:bv1))), 0x0:bv1); + goto (%main_7); ]; block %main_7 [ goto (%main_5); ]; block %main_15 [ - var ZF_10:bv1 := ZF_6:bv1; - guard eq(bvnot(booltobv1(eq(ZF_10:bv1, 0x1:bv1))), 0x0:bv1); - var R0_21:bv64 := 0x0:bv64; - var R0_22:bv64 := bvadd(R0_21:bv64, 0x828:bv64); - var R30_5:bv64 := 0x7f4:bv64; - (var CF_7:bv1=CF_out, var NF_7:bv1=NF_out, var R0_23:bv64=R0_out, - var R1_6:bv64=R1_out, var R29_6:bv64=R29_out, var R30_6:bv64=R30_out, - var R31_6:bv64=R31_out, var VF_7:bv1=VF_out, var ZF_11:bv1=ZF_out) := - call @puts_1584(CF_in=CF_4:bv1, NF_in=NF_4:bv1, R0_in=R0_22:bv64, - R1_in=R1_2:bv64, R29_in=R29_3:bv64, R30_in=R30_5:bv64, R31_in=R31_3:bv64, - VF_in=VF_4:bv1, ZF_in=ZF_10:bv1); - goto (%main_13); + var ZF_10:bv1 := ZF_6:bv1; + guard eq(bvnot(booltobv1(eq(ZF_10:bv1, 0x1:bv1))), 0x0:bv1); + var R0_21:bv64 := 0x0:bv64; + var R0_22:bv64 := bvadd(R0_21:bv64, 0x828:bv64); + var R30_5:bv64 := 0x7f4:bv64; + (var CF_7:bv1=CF_out, var NF_7:bv1=NF_out, var R0_23:bv64=R0_out, + var R1_6:bv64=R1_out, var R29_6:bv64=R29_out, var R30_6:bv64=R30_out, + var R31_6:bv64=R31_out, var VF_7:bv1=VF_out, var ZF_11:bv1=ZF_out) := + call @puts_1584(CF_in=CF_4:bv1, NF_in=NF_4:bv1, R0_in=R0_22:bv64, + R1_in=R1_2:bv64, R29_in=R29_3:bv64, R30_in=R30_5:bv64, R31_in=R31_3:bv64, + VF_in=VF_4:bv1, ZF_in=ZF_10:bv1); + goto (%main_13); ]; block %main_13 [ goto (%main_11); ]; block %main_11 [ - var R0_24:bv64 := 0x0:bv64; - var load21_1:bv64 := load le $stack:(bv64->bv8) R31_6:bv64 64; - var R29_7:bv64 := load21_1:bv64; - var load22_1:bv64 := load le $stack:(bv64->bv8) bvadd(R31_6:bv64, 0x8:bv64) 64; - var R30_7:bv64 := load22_1:bv64; - var R31_7:bv64 := bvadd(R31_6:bv64, 0x20:bv64); - goto (%main_basil_return_1); + var R0_24:bv64 := 0x0:bv64; + var load21_1:bv64 := load le $stack:(bv64->bv8) R31_6:bv64 64; + var R29_7:bv64 := load21_1:bv64; + var load22_1:bv64 := load le $stack:(bv64->bv8) bvadd(R31_6:bv64, 0x8:bv64) 64; + var R30_7:bv64 := load22_1:bv64; + var R31_7:bv64 := bvadd(R31_6:bv64, 0x20:bv64); + goto (%main_basil_return_1); ]; block %main_basil_return_1 [ goto (%returns); ]; block %returns [ - (var CF_out:bv1 := CF_7:bv1, var NF_out:bv1 := NF_7:bv1, - var R0_out:bv64 := R0_24:bv64, var R1_out:bv64 := R1_6:bv64, - var R29_out:bv64 := R29_7:bv64, var R30_out:bv64 := R30_7:bv64, - var R31_out:bv64 := R31_7:bv64, var VF_out:bv1 := VF_7:bv1, - var ZF_out:bv1 := ZF_11:bv1); - return; + (var CF_out:bv1 := CF_7:bv1, var NF_out:bv1 := NF_7:bv1, + var R0_out:bv64 := R0_24:bv64, var R1_out:bv64 := R1_6:bv64, + var R29_out:bv64 := R29_7:bv64, var R30_out:bv64 := R30_7:bv64, + var R31_out:bv64 := R31_7:bv64, var VF_out:bv1 := VF_7:bv1, + var ZF_out:bv1 := ZF_11:bv1); + return; ] ]; proc @puts_1584(CF_in:bv1, NF_in:bv1, R0_in:bv64, R1_in:bv64, R29_in:bv64, @@ -321,8 +312,17 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - diff: after_reparsed.il: No such file or directory - [2] + 18,21c18,21 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + [1] The interpreter should give the same output for both @@ -333,14 +333,32 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt - diff: before_conds.txt: No such file or directory - diff: after_conds.txt: No such file or directory - [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - diff: ssa-multi-before.il: No such file or directory - diff: ssa-multi-after.il: No such file or directory - [2] + 1d0 + < var $R0:bv64; + 3c2 + < proc @main() -> () { } + --- + > proc @main(R0_in:bv64) -> (R0_out:bv64) { } + 7a7 + > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; + 9,12c9,17 + < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; + < block %e2 [ goto (%e4,%e1); ]; + < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + < block %e4 [ return; ] + --- + > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; + > block %e2 ( var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64) ) [ + > goto (%e4,%e1); + > ]; + > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + > block %e4 ( + > var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64) + > ) [ goto (%returns); ]; + > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] + [1] diff --git a/test/cram/expr_smt.t b/test/cram/expr_smt.t index ef552625..f257ff1d 100644 --- a/test/cram/expr_smt.t +++ b/test/cram/expr_smt.t @@ -8,73 +8,73 @@ Check concat rewrites work $ diff before.il after.il 17,81c17,18 - < $R28:bv64 := bvor(bvand(bvconcat(extract(1,0, bvlshr(var1_4206396_bv64:bv64, - < 0x1f:bv64)), extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), - < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64))), - < 0xffffffff00000000:bv64), + < $R28:bv64 := bvor(bvand(bvconcat(extract(1,0, bvlshr(var1_4206396_bv64:bv64, + < 0x1f:bv64)), extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64)), + < extract(1,0, bvlshr(var1_4206396_bv64:bv64, 0x1f:bv64))), + < 0xffffffff00000000:bv64), --- - > $R28:bv64 := bvor(bvand(sign_extend(63, - > extract(32,31, var1_4206396_bv64:bv64)), 0xffffffff00000000:bv64), + > $R28:bv64 := bvor(bvand(sign_extend(63, + > extract(32,31, var1_4206396_bv64:bv64)), 0xffffffff00000000:bv64), [1] diff --git a/test/cram/memassign.t b/test/cram/memassign.t index 60372a01..120338e3 100644 --- a/test/cram/memassign.t +++ b/test/cram/memassign.t @@ -6,5 +6,5 @@ -- block %main_entry [ - $Global_4325420_4325424:bv32 := store 0x2a:bv32; - goto (%main_return); + $Global_4325420_4325424:bv32 := store 0x2a:bv32; + goto (%main_return); diff --git a/test/lang/stmt.ml b/test/lang/stmt.ml index 2056412d..7d989d59 100644 --- a/test/lang/stmt.ml +++ b/test/lang/stmt.ml @@ -58,11 +58,11 @@ let%expect_test "fold_block" = var load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32 var R0_10:bv64 := zero_extend(32, load46_1:bv32) [ - $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32; - load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) 32; - R1_4:bv64 := zero_extend(32, load45_1:bv32); - $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32; - load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32; - R0_10:bv64 := zero_extend(32, load46_1:bv32); + $stack:(bv64->bv8) := store le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32,0, R0_in:bv64) 32; + load45_1:bv32 := load le $stack:(bv64->bv8) bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) 32; + R1_4:bv64 := zero_extend(32, load45_1:bv32); + $mem:(bv64->bv8) := store le $mem:(bv64->bv8) 0x420034:bv64 extract(32,0, R1_4:bv64) 32; + load46_1:bv32 := load le $mem:(bv64->bv8) 0x42002c:bv64 32; + R0_10:bv64 := zero_extend(32, load46_1:bv32); ] |}] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 58dd923a..819a4ac5 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -112,9 +112,7 @@ module.exports = grammar({ // TypeBVType. Type1 ::= BVType ; $.BVType, // TypeParen. Type1 ::= OpenParen Type CloseParen ; - seq($.token_OpenParen, $.Type, $.token_CloseParen), - // _. Type1 ::= "(" Type ")" ; - seq("(", $.Type, ")") + seq($.token_OpenParen, $.Type, $.token_CloseParen) ), Type: $ => choice( @@ -427,12 +425,8 @@ module.exports = grammar({ ), Expr2: $ => choice( - // _. Expr2 ::= "(" Expr ")" ; - seq("(", $.Expr, ")"), // Expr_Literal. Expr2 ::= Value ; $.Value, - // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; - seq($.token_OpenParen, $.Expr, $.token_CloseParen), // Expr_Local. Expr2 ::= LocalVar ; $.LocalVar, // Expr_Global. Expr2 ::= GlobalVar ; @@ -460,7 +454,9 @@ module.exports = grammar({ // Expr_Match. Expr2 ::= "match" Expr "with" OpenParen [Case] CloseParen ; seq("match", $.Expr, "with", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), // Expr_Cases. Expr2 ::= "cases" OpenParen [Case] CloseParen ; - seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen) + seq("cases", $.token_OpenParen, optional($.list_Case), $.token_CloseParen), + // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; + seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), LambdaParen: $ => choice( From ebae1177d29f0fc85068dfbe62f416ac45458231 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 15:47:17 +1000 Subject: [PATCH 22/43] fmt --- lib/lang/block.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/lang/block.ml b/lib/lang/block.ml index f723e812..c7bf5f10 100644 --- a/lib/lang/block.ml +++ b/lib/lang/block.ml @@ -42,14 +42,15 @@ let pretty show_lvar show_var show_expr ?(terminator = []) ?block_id b = Trace_core.with_span ~__FILE__ ~__LINE__ "pretty-block" @@ fun _ -> let open Containers_pp in let open Containers_pp.Infix in - let bracket' ~n l d r : t = - group (text l ^ nest n (nl ^ d) ^ nl ^ text r) in + let bracket' ~n l d r : t = group (text l ^ nest n (nl ^ d) ^ nl ^ text r) in let phi = match b.phis with | [] -> nil | o -> let phi = List.map (pretty_phi show_lvar show_var) o in - bracket' ~n:2 "(" (append_l ~sep:(text "," ^ nl) (List.map group phi)) ") " + bracket' ~n:2 "(" + (append_l ~sep:(text "," ^ nl) (List.map group phi)) + ") " in let stmts = Vector.to_list b.stmts From f54af294be7b682359aa61e141abda0cbd42ffdf Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 16:02:22 +1000 Subject: [PATCH 23/43] fmt --- dune-project | 3 +++ tree-sitter/dune | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dune-project b/dune-project index 64916cdc..60ab08b3 100644 --- a/dune-project +++ b/dune-project @@ -8,6 +8,9 @@ (generate_opam_files true) +(formatting + (enabled_for dune)) + (source (github username/reponame)) diff --git a/tree-sitter/dune b/tree-sitter/dune index 1eb21e32..ca13dd0c 100644 --- a/tree-sitter/dune +++ b/tree-sitter/dune @@ -1,4 +1,5 @@ ; checks tree-sitter is valid and unambiguous + (rule (deps grammar.js) (alias runtest) @@ -8,6 +9,7 @@ ; check that grammar.js is up to date. ; requires `bnfc-treesitter` from pac-nix. + (rule (alias runtest) (deps %{project_root}/lib/fe/BasilIR.cf) @@ -15,5 +17,11 @@ (action (progn (copy %{deps} basilir.cf) - (run bnfc --tree-sitter --tree-sitter-word LocalIdent basilir.cf --makefile) + (run + bnfc + --tree-sitter + --tree-sitter-word + LocalIdent + basilir.cf + --makefile) (diff? grammar.js tree-sitter-basilir/grammar.js)))) From 96862f447a3704903a96ed31494973933f2da169 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 16:18:52 +1000 Subject: [PATCH 24/43] newline terminated specs --- examples/cat.il | 148 ++++++++++++++++++++--------------------- examples/conds.il | 4 +- examples/x-output.il | 2 +- lib/fe/BasilIR.cf | 4 +- lib/fe/ParBasilIR.mly | 4 +- lib/fe/PrintBasilIR.ml | 5 +- lib/lang/procedure.ml | 10 +-- lib/loadir.ml | 4 +- test/cram/basicssa.t | 16 ++--- test/cram/memassign.t | 4 +- test/cram/roundtrip.t | 16 ++--- tree-sitter/grammar.js | 12 ++-- 12 files changed, 114 insertions(+), 115 deletions(-) diff --git a/examples/cat.il b/examples/cat.il index d6b0c07c..27fd0e5b 100644 --- a/examples/cat.il +++ b/examples/cat.il @@ -48,8 +48,8 @@ prog entry @main_4197696; proc @main_4197696 () -> () { .name = "main"; .address = 0x400d40; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x400d40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400d40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %main_entry {.address = 0x400d40; .originalLabel = "KXhc9Fe2Qva4qWVLC1eV+w=="} [ assert eq($_PC:bv64, 0x400d40:bv64); @@ -86,8 +86,8 @@ proc @exit () -> () proc @exitcode_4198816 () -> () { .name = "exitcode"; .address = 0x4011a0; .returnBlock = "exitcode_basil_return_1" } - require eq($_PC:bv64, 0x4011a0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4011a0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %exitcode_entry {.address = 0x4011a0; .originalLabel = "Hr3XvFHLQ62ROxw2L+L+kg=="} [ assert eq($_PC:bv64, 0x4011a0:bv64); @@ -109,8 +109,8 @@ proc @exitcode_4198816 () -> () proc @exits_4198688 () -> () { .name = "exits"; .address = 0x401120; .returnBlock = "exits_basil_return_1" } - require eq($_PC:bv64, 0x401120:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401120:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %exits_entry {.address = 0x401120; .originalLabel = "OamxgWkAT5S7lYhJLb34Bw=="} [ var R30_begin_exits_4198688: bv64 := $R30:bv64; @@ -449,8 +449,8 @@ proc @exits_4198688 () -> () proc @fmtlocaleinit_4209552 () -> () { .name = "fmtlocaleinit"; .address = 0x403b90; .returnBlock = "fmtlocaleinit_basil_return_1" } - require eq($_PC:bv64, 0x403b90:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403b90:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fmtlocaleinit_entry {.address = 0x403b90; .originalLabel = "LJeXYGqvSDa8MTgV+KKKNg=="} [ assert eq($_PC:bv64, 0x403b90:bv64); @@ -611,8 +611,8 @@ proc @fmtlocaleinit_4209552 () -> () proc @fmtfdinit_4209364 () -> () { .name = "fmtfdinit"; .address = 0x403ad4; .returnBlock = "fmtfdinit_basil_return_1" } - require eq($_PC:bv64, 0x403ad4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403ad4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fmtfdinit_entry {.address = 0x403ad4; .originalLabel = "Ase3rrH2SOSuhunVYXYBhg=="} [ assert eq($_PC:bv64, 0x403ad4:bv64); @@ -715,8 +715,8 @@ proc @write () -> () proc @__fmtFdFlush_4209456 () -> () { .name = "__fmtFdFlush"; .address = 0x403b30; .returnBlock = "__fmtFdFlush_basil_return_1" } - require eq($_PC:bv64, 0x403b30:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403b30:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtFdFlush_entry {.address = 0x403b30; .originalLabel = "I+YOj/gGRqS87EwafUF4WA=="} [ assert eq($_PC:bv64, 0x403b30:bv64); @@ -914,8 +914,8 @@ proc @__fmtFdFlush_4209456 () -> () proc @__flagfmt_4208112 () -> () { .name = "__flagfmt"; .address = 0x4035f0; .returnBlock = "__flagfmt_basil_return_1" } - require eq($_PC:bv64, 0x4035f0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4035f0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__flagfmt_entry {.address = 0x4035f0; .originalLabel = "Md5qE+eiRf+m/NPBkVuT3g=="} [ assert eq($_PC:bv64, 0x4035f0:bv64); @@ -1454,8 +1454,8 @@ proc @__flagfmt_4208112 () -> () proc @__rfmtpad_4203024 () -> () { .name = "__rfmtpad"; .address = 0x402210; .returnBlock = "__rfmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402210:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402210:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__rfmtpad_entry {.address = 0x402210; .originalLabel = "FnHqSK+lTxq6YDUq7NvnJg=="} [ assert eq($_PC:bv64, 0x402210:bv64); @@ -1940,8 +1940,8 @@ proc @__rfmtpad_4203024 () -> () proc @runelen_4210048 () -> () { .name = "runelen"; .address = 0x403d80; .returnBlock = "runelen_basil_return_1" } - require eq($_PC:bv64, 0x403d80:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403d80:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %runelen_entry {.address = 0x403d80; .originalLabel = "o0lVyZ2GT4mJNVkb5e5Vuw=="} [ assert eq($_PC:bv64, 0x403d80:bv64); @@ -2022,8 +2022,8 @@ proc @runelen_4210048 () -> () proc @fullrune_4210160 () -> () { .name = "fullrune"; .address = 0x403df0; .returnBlock = "fullrune_basil_return_1" } - require eq($_PC:bv64, 0x403df0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403df0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fullrune_entry {.address = 0x403df0; .originalLabel = "ycUhyOy1TNW1hp1YrdP0uw=="} [ assert eq($_PC:bv64, 0x403df0:bv64); @@ -2178,8 +2178,8 @@ proc @fullrune_4210160 () -> () proc @__fmtpad_4202756 () -> () { .name = "__fmtpad"; .address = 0x402104; .returnBlock = "__fmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402104:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402104:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtpad_entry {.address = 0x402104; .originalLabel = "DS7w57znRnmBsFkYW6cA+Q=="} [ assert eq($_PC:bv64, 0x402104:bv64); @@ -2663,8 +2663,8 @@ proc @__fmtpad_4202756 () -> () proc @runetochar_4209936 () -> () { .name = "runetochar"; .address = 0x403d10; .returnBlock = "runetochar_basil_return_1" } - require eq($_PC:bv64, 0x403d10:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403d10:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %runetochar_entry {.address = 0x403d10; .originalLabel = "Rkek/d08TK2mkJ7PEcm6mg=="} [ assert eq($_PC:bv64, 0x403d10:bv64); @@ -2816,8 +2816,8 @@ proc @runetochar_4209936 () -> () proc @__fmtflush_4202032 () -> () { .name = "__fmtflush"; .address = 0x401e30; .returnBlock = "__fmtflush_basil_return_1" } - require eq($_PC:bv64, 0x401e30:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401e30:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtflush_entry {.address = 0x401e30; .originalLabel = "Osy3QCRQRpSd5aY0vW+qkQ=="} [ assert eq($_PC:bv64, 0x401e30:bv64); @@ -3092,8 +3092,8 @@ proc @__fmtflush_4202032 () -> () proc @chartorune_4209760 () -> () { .name = "chartorune"; .address = 0x403c60; .returnBlock = "chartorune_basil_return_1" } - require eq($_PC:bv64, 0x403c60:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c60:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %chartorune_entry {.address = 0x403c60; .originalLabel = "+s65+r9uRzKHgPS/OxqX3g=="} [ assert eq($_PC:bv64, 0x403c60:bv64); @@ -3398,8 +3398,8 @@ proc @chartorune_4209760 () -> () proc @__fmtcpy_4203296 () -> () { .name = "__fmtcpy"; .address = 0x402320; .returnBlock = "__fmtcpy_basil_return_1" } - require eq($_PC:bv64, 0x402320:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402320:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtcpy_entry {.address = 0x402320; .originalLabel = "onW0wUQSS+CWRE3FG7sZVA=="} [ assert eq($_PC:bv64, 0x402320:bv64); @@ -4774,8 +4774,8 @@ proc @__fmtcpy_4203296 () -> () proc @__badfmt_4208400 () -> () { .name = "__badfmt"; .address = 0x403710; .returnBlock = "__badfmt_basil_return_1" } - require eq($_PC:bv64, 0x403710:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403710:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__badfmt_entry {.address = 0x403710; .originalLabel = "VsS7dlFoQ3et0t9jIUUtyw=="} [ assert eq($_PC:bv64, 0x403710:bv64); @@ -4852,8 +4852,8 @@ proc @__badfmt_4208400 () -> () proc @getcallerpc_4201920 () -> () { .name = "getcallerpc"; .address = 0x401dc0; .returnBlock = "getcallerpc_basil_return_1" } - require eq($_PC:bv64, 0x401dc0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401dc0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %getcallerpc_entry {.address = 0x401dc0; .originalLabel = "/lgI4FfjS+yfGYqEtnuiGw=="} [ assert eq($_PC:bv64, 0x401dc0:bv64); @@ -4879,8 +4879,8 @@ proc @getcallerpc_4201920 () -> () proc @unlock_4199332 () -> () { .name = "unlock"; .address = 0x4013a4; .returnBlock = "unlock_basil_return_1" } - require eq($_PC:bv64, 0x4013a4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4013a4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %unlock_entry {.address = 0x4013a4; .originalLabel = "V0jFzXuITMiNHr/kb8xG4g=="} [ assert eq($_PC:bv64, 0x4013a4:bv64); @@ -5022,8 +5022,8 @@ proc @unlock_4199332 () -> () proc @__fmtunlock_4209744 () -> () { .name = "__fmtunlock"; .address = 0x403c50; .returnBlock = "__fmtunlock_basil_return_1" } - require eq($_PC:bv64, 0x403c50:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c50:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtunlock_entry {.address = 0x403c50; .originalLabel = "LHWtkP5rQmqxTbinnC1hLw=="} [ var R30_begin___fmtunlock_4209744: bv64 := $R30:bv64; @@ -5051,8 +5051,8 @@ proc @__fmtunlock_4209744 () -> () proc @lock_4199120 () -> () { .name = "lock"; .address = 0x4012d0; .returnBlock = "lock_basil_return_1" } - require eq($_PC:bv64, 0x4012d0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4012d0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %lock_entry {.address = 0x4012d0; .originalLabel = "EL5Ky+1GSIeJ6nw6JbZnPg=="} [ assert eq($_PC:bv64, 0x4012d0:bv64); @@ -5204,8 +5204,8 @@ proc @lock_4199120 () -> () proc @__fmtlock_4209728 () -> () { .name = "__fmtlock"; .address = 0x403c40; .returnBlock = "__fmtlock_basil_return_1" } - require eq($_PC:bv64, 0x403c40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtlock_entry {.address = 0x403c40; .originalLabel = "n9+4iNtqRLu7+3FBjvBlSg=="} [ var R30_begin___fmtlock_4209728: bv64 := $R30:bv64; @@ -5233,8 +5233,8 @@ proc @__fmtlock_4209728 () -> () proc @__fmtinstall_4208464 () -> () { .name = "__fmtinstall"; .address = 0x403750; .returnBlock = "__fmtinstall_basil_return_1" } - require eq($_PC:bv64, 0x403750:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403750:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtinstall_entry {.address = 0x403750; .originalLabel = "4vz6BXioRXa/LaTzSs8GSg=="} [ assert eq($_PC:bv64, 0x403750:bv64); @@ -5516,8 +5516,8 @@ proc @__fmtinstall_4208464 () -> () proc @__fmtdispatch_4208688 () -> () { .name = "__fmtdispatch"; .address = 0x403830; .returnBlock = "__fmtdispatch_basil_return_1" } - require eq($_PC:bv64, 0x403830:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403830:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtdispatch_entry {.address = 0x403830; .originalLabel = "J5JvET/ORDyFBY1+xoNLkA=="} [ assert eq($_PC:bv64, 0x403830:bv64); @@ -6659,8 +6659,8 @@ proc @__fmtdispatch_4208688 () -> () proc @dofmt_4202176 () -> () { .name = "dofmt"; .address = 0x401ec0; .returnBlock = "dofmt_basil_return_1" } - require eq($_PC:bv64, 0x401ec0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401ec0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %dofmt_entry {.address = 0x401ec0; .originalLabel = "ptCQBLyvTM22JSPE/cK18w=="} [ assert eq($_PC:bv64, 0x401ec0:bv64); @@ -7699,8 +7699,8 @@ proc @dofmt_4202176 () -> () proc @vfprint_4201072 () -> () { .name = "vfprint"; .address = 0x401a70; .returnBlock = "vfprint_basil_return_1" } - require eq($_PC:bv64, 0x401a70:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401a70:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %vfprint_entry {.address = 0x401a70; .originalLabel = "kh4iUxoKQMenD77ljouyEQ=="} [ assert eq($_PC:bv64, 0x401a70:bv64); @@ -7882,8 +7882,8 @@ proc @vfprint_4201072 () -> () proc @fprint_4200960 () -> () { .name = "fprint"; .address = 0x401a00; .returnBlock = "fprint_basil_return_1" } - require eq($_PC:bv64, 0x401a00:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401a00:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fprint_entry {.address = 0x401a00; .originalLabel = "fQteMOadSm+stHHR3jx4Qw=="} [ assert eq($_PC:bv64, 0x401a00:bv64); @@ -7986,8 +7986,8 @@ proc @fprint_4200960 () -> () proc @__fixargv0_4198400 () -> () { .name = "__fixargv0"; .address = 0x401000; .returnBlock = "__fixargv0_basil_return_1" } - require eq($_PC:bv64, 0x401000:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401000:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fixargv0_entry {.address = 0x401000; .originalLabel = "78skE39ZS92hlwuQoG/N1g=="} [ assert eq($_PC:bv64, 0x401000:bv64); @@ -8007,8 +8007,8 @@ proc @__fixargv0_4198400 () -> () proc @vseprint_4201184 () -> () { .name = "vseprint"; .address = 0x401ae0; .returnBlock = "vseprint_basil_return_1" } - require eq($_PC:bv64, 0x401ae0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401ae0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %vseprint_entry {.address = 0x401ae0; .originalLabel = "xuA0Edh9S8yFZV1Qu/Jgqw=="} [ assert eq($_PC:bv64, 0x401ae0:bv64); @@ -8169,8 +8169,8 @@ proc @vseprint_4201184 () -> () proc @sysfatal_4200560 () -> () { .name = "sysfatal"; .address = 0x401870; .returnBlock = "sysfatal_basil_return_1" } - require eq($_PC:bv64, 0x401870:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401870:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %sysfatal_entry {.address = 0x401870; .originalLabel = "HN8ZNDP1RUKhvFhL/Qx3ng=="} [ var R30_begin_sysfatal_4200560: bv64 := $R30:bv64; @@ -8471,8 +8471,8 @@ proc @memccpy () -> () proc @strecpy_4201936 () -> () { .name = "strecpy"; .address = 0x401dd0; .returnBlock = "strecpy_basil_return_1" } - require eq($_PC:bv64, 0x401dd0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401dd0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %strecpy_entry {.address = 0x401dd0; .originalLabel = "gS9qAucpRMKJD8TibWbm5A=="} [ assert eq($_PC:bv64, 0x401dd0:bv64); @@ -8680,8 +8680,8 @@ proc @strerror () -> () proc @rerrstr_4201312 () -> () { .name = "rerrstr"; .address = 0x401b60; .returnBlock = "rerrstr_basil_return_1" } - require eq($_PC:bv64, 0x401b60:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401b60:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %rerrstr_entry {.address = 0x401b60; .originalLabel = "ldWhLOMYSKyYFGShQwXqIg=="} [ var R30_begin_rerrstr_4201312: bv64 := $R30:bv64; @@ -9214,8 +9214,8 @@ proc @rerrstr_4201312 () -> () proc @errstr_4201540 () -> () { .name = "errstr"; .address = 0x401c44; .returnBlock = "errstr_basil_return_1" } - require eq($_PC:bv64, 0x401c44:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401c44:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %errstr_entry {.address = 0x401c44; .originalLabel = "3ReV3l3lTEWXlI8dRV4Pcw=="} [ assert eq($_PC:bv64, 0x401c44:bv64); @@ -9454,8 +9454,8 @@ proc @errstr_4201540 () -> () proc @werrstr_4201780 () -> () { .name = "werrstr"; .address = 0x401d34; .returnBlock = "werrstr_basil_return_1" } - require eq($_PC:bv64, 0x401d34:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401d34:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %werrstr_entry {.address = 0x401d34; .originalLabel = "EsiP/3+hSbS6DhsMqrwxFA=="} [ assert eq($_PC:bv64, 0x401d34:bv64); @@ -9607,8 +9607,8 @@ proc @open64 () -> () proc @p9open_4198832 () -> () { .name = "p9open"; .address = 0x4011b0; .returnBlock = "p9open_basil_return_1" } - require eq($_PC:bv64, 0x4011b0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4011b0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9open_entry {.address = 0x4011b0; .originalLabel = "DYW7Gbw6QwK5DzhE/cGL7w=="} [ assert eq($_PC:bv64, 0x4011b0:bv64); @@ -10273,8 +10273,8 @@ proc @p9open_4198832 () -> () proc @p9write_4200816 () -> () { .name = "p9write"; .address = 0x401970; .returnBlock = "p9write_basil_return_1" } - require eq($_PC:bv64, 0x401970:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401970:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9write_entry {.address = 0x401970; .originalLabel = "qVvzznzaToayt5BQelE/sg=="} [ assert eq($_PC:bv64, 0x401970:bv64); @@ -10571,8 +10571,8 @@ proc @read () -> () proc @cat_4198032 () -> () { .name = "cat"; .address = 0x400e90; .returnBlock = "cat_basil_return_1" } - require eq($_PC:bv64, 0x400e90:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400e90:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %cat_entry {.address = 0x400e90; .originalLabel = "OMO2ysIfSmeORBpBsr5OIQ=="} [ var R30_begin_cat_4198032: bv64 := $R30:bv64; @@ -10826,8 +10826,8 @@ proc @cat_4198032 () -> () proc @p9main_4198208 () -> () { .name = "p9main"; .address = 0x400f40; .returnBlock = "p9main_basil_return_1" } - require eq($_PC:bv64, 0x400f40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400f40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9main_entry {.address = 0x400f40; .originalLabel = "FGQT8qmESb6FIwl/znG8jA=="} [ var R30_begin_p9main_4198208: bv64 := $R30:bv64; diff --git a/examples/conds.il b/examples/conds.il index 1125b6d6..0428a536 100644 --- a/examples/conds.il +++ b/examples/conds.il @@ -14,8 +14,8 @@ prog entry @main_4196260; proc @main_4196260 () -> () { .name = "main"; .address = 0x4007a4; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x4007a4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4007a4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %main_entry {.address = 0x4007a4; .originalLabel = "rlVqjjqoR6uHwOYvPCS15g=="} [ assert eq($_PC:bv64, 0x4007a4:bv64); diff --git a/examples/x-output.il b/examples/x-output.il index acccac91..8d649379 100644 --- a/examples/x-output.il +++ b/examples/x-output.il @@ -7,7 +7,7 @@ proc @main_4196164 (R0_in:bv64, R1_in:bv64, R30_in:bv64, R31_in:bv64, _PC_in:bv64) -> (R0_out:bv64, R1_out:bv64, _PC_out:bv64) { .name = "main"; .address = 0x400744 } - require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)); + require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)) [ block %main_entry {.address = 0x400744; .originalLabel = "G8B0Q6XuSneDgqpNFr1sUQ=="} [ store le $stack bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32, 0, R0_in:bv64) 32 { .label = "4196168_0" }; diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 704c1cd9..192d98ce 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -282,10 +282,10 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= "rely" Expr; ProgSpec_Guarantee . ProgSpec ::= "guarantee" Expr; -terminator FunSpec ";"; +terminator FunSpec "\n"; {- last semicolon terminates the prog definitino -} -separator nonempty ProgSpec "\n"; +terminator ProgSpec "\n"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index af6b322d..e57c5969 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -774,10 +774,10 @@ progSpec : KW_rely expr { ProgSpec_Rely $2 } ; funSpec_list : /* empty */ { [] } - | funSpec SYMB1 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } + | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; -progSpec_list : progSpec { (fun x -> [x]) $1 } +progSpec_list : /* empty */ { [] } | progSpec progSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 1a87ba8c..f1fada17 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -523,7 +523,8 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render " +" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) | AbsBasilIR.VarSpec_Empty -> prPrec i 0 (concatD []) @@ -535,8 +536,6 @@ and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtProgSpec 0 x ; render " -"]) | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render " " ; prtProgSpecListBNFC 0 xs]) diff --git a/lib/lang/procedure.ml b/lib/lang/procedure.ml index 777bd11c..c3f8c77e 100644 --- a/lib/lang/procedure.ml +++ b/lib/lang/procedure.ml @@ -496,7 +496,7 @@ let iter_blocks_topo_rev p = let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = let open Containers_pp in - let ml f v = if List.is_empty v then [] else [ f v ^ text ";" ] in + let ml f v = if List.is_empty v then [] else [ f v ] in nest 2 (newline ^ append_nl @@ -513,25 +513,25 @@ let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "requires " ^ show_expr v) x)) p.requires @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "ensures " ^ show_expr v) x)) p.ensures @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "rely " ^ show_expr v) x)) p.rely @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "guarantee " ^ show_expr v) x)) p.guarantee)) diff --git a/lib/loadir.ml b/lib/loadir.ml index 3745a7a7..82517f03 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -1388,8 +1388,8 @@ proc @main_4196260 () -> () var $ZF:bv1; prog entry @main_4196260; proc @main_4196260() -> () { } - modifies $NF:bv1, $ZF:bv1; - captures $NF:bv1, $ZF:bv1; + modifies $NF:bv1, $ZF:bv1 + captures $NF:bv1, $ZF:bv1 [ block %main_entry [ diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index e257a4de..5129885e 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -19,9 +19,9 @@ Run on basic irreducible loop example proc @main_1876() -> () { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 [ block %main_entry [ @@ -149,9 +149,9 @@ Run on basic irreducible loop example R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 [ block %inputs [ @@ -314,14 +314,14 @@ Run on basic irreducible loop example $ diff after.il after_reparsed.il 18,21c18,21 < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 --- > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) [1] The interpreter should give the same output for both diff --git a/test/cram/memassign.t b/test/cram/memassign.t index 120338e3..577261dc 100644 --- a/test/cram/memassign.t +++ b/test/cram/memassign.t @@ -1,8 +1,8 @@ $ dune exec bincaml -- dump-il memassign.il --proc '@main_4196164' | grep Global --before-context 1 --after-context 1 .returnBlock = "main_return" } - modifies $Global_4325420_4325424:bv32; - captures $Global_4325420_4325424:bv32; + modifies $Global_4325420_4325424:bv32 + captures $Global_4325420_4325424:bv32 -- block %main_entry [ diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8f080cb0..dc4a8888 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -6,14 +6,14 @@ The serialise -> parse serialise loop should be idempotent $ diff before.il after.il 15,18c15,18 < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 --- > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) 121c121 < block %main_basil_return_1 [ nop; return; ] --- @@ -22,11 +22,11 @@ The serialise -> parse serialise loop should be idempotent $ diff before2.il after2.il 7,8c7,8 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8); - < captures $mem:(bv64->bv8), $stack:(bv64->bv8); + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8) + < captures $mem:(bv64->bv8), $stack:(bv64->bv8) --- - > modifies $stack:(bv64->bv8), $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $mem:(bv64->bv8); + > modifies $stack:(bv64->bv8), $mem:(bv64->bv8) + > captures $stack:(bv64->bv8), $mem:(bv64->bv8) [1] Memassign repr diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 819a4ac5..2f76d509 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -71,7 +71,7 @@ module.exports = grammar({ // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), @@ -689,15 +689,15 @@ module.exports = grammar({ choice( // []. [FunSpec] ::= ; choice(), - // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; - seq($.FunSpec, ";", optional($.list_FunSpec)) + // (:). [FunSpec] ::= FunSpec [FunSpec] ; + seq($.FunSpec, optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( - // (:[]). [ProgSpec] ::= ProgSpec ; - $.ProgSpec, + // []. [ProgSpec] ::= ; + choice(), // (:). [ProgSpec] ::= ProgSpec [ProgSpec] ; - seq($.ProgSpec, $.list_ProgSpec) + seq($.ProgSpec, optional($.list_ProgSpec)) ), token_BVTYPE: $ => /bv\d+/, From 9a03d9d2c02e1f749b9171357042176e24014948 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 17:43:37 +1000 Subject: [PATCH 25/43] bump tokens --- lib/fe/AbsBasilIR.ml | 6 ++--- lib/fe/BasilIR.cf | 6 ++--- lib/fe/LexBasilIR.mll | 4 ++-- lib/fe/ParBasilIR.mly | 8 +++---- lib/fe/PrintBasilIR.ml | 6 ++--- lib/fe/ShowBasilIR.ml | 6 ++--- lib/fe/SkelBasilIR.ml | 6 ++--- lib/loadir.ml | 4 ++-- tree-sitter/grammar.js | 12 +++++----- tree-sitter/queries/highlights.scm | 37 +++++++++++++++++++++--------- 10 files changed, 55 insertions(+), 40 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 50b601ee..a280c6cd 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -285,7 +285,7 @@ and relyTok = | RelyTok_relies and guarTok = - GuarTok_guarnatee + GuarTok_guarantee | GuarTok_guarantees and funSpec = @@ -302,6 +302,6 @@ and varSpec = | VarSpec_Empty and progSpec = - ProgSpec_Rely of expr - | ProgSpec_Guarantee of expr + ProgSpec_Rely of relyTok * expr + | ProgSpec_Guarantee of guarTok * expr diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 192d98ce..d5670f7e 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -263,7 +263,7 @@ rules BoolBinOp ::= "booland" | "boolor" | "boolimplies" ; rules RequireTok ::= "require" | "requires" ; rules EnsureTok ::= "ensure" | "ensures" ; rules RelyTok ::= "rely" | "relies"; -rules GuarTok ::= "guarnatee" | "guarantees"; +rules GuarTok ::= "guarantee" | "guarantees"; FunSpec_Require . FunSpec ::= RequireTok Expr; FunSpec_Ensure . FunSpec ::= EnsureTok Expr; @@ -279,8 +279,8 @@ VarSpec_Empty . VarSpec ::= ; FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; -ProgSpec_Rely . ProgSpec ::= "rely" Expr; -ProgSpec_Guarantee . ProgSpec ::= "guarantee" Expr; +ProgSpec_Rely . ProgSpec ::= RelyTok Expr; +ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; terminator FunSpec "\n"; diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 2847e63d..879eb028 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -11,9 +11,9 @@ let symbol_table = Hashtbl.create 10 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add symbol_table kwd tok) [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] -let resword_table = Hashtbl.create 99 +let resword_table = Hashtbl.create 98 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add resword_table kwd tok) - [("shared", KW_shared);("observable", KW_observable);("axiom", KW_axiom);("memory", KW_memory);("var", KW_var);("val", KW_val);("let", KW_let);("prog", KW_prog);("entry", KW_entry);("proc", KW_proc);("le", KW_le);("be", KW_be);("nop", KW_nop);("store", KW_store);("load", KW_load);("call", KW_call);("indirect", KW_indirect);("assume", KW_assume);("guard", KW_guard);("assert", KW_assert);("goto", KW_goto);("unreachable", KW_unreachable);("return", KW_return);("phi", KW_phi);("block", KW_block);("true", KW_true);("false", KW_false);("forall", KW_forall);("exists", KW_exists);("fun", KW_fun);("old", KW_old);("boolnot", KW_boolnot);("intneg", KW_intneg);("booltobv1", KW_booltobv1);("gamma", KW_gamma);("classification", KW_classification);("load_be", KW_load_be);("load_le", KW_load_le);("zero_extend", KW_zero_extend);("sign_extend", KW_sign_extend);("extract", KW_extract);("bvconcat", KW_bvconcat);("match", KW_match);("with", KW_with);("cases", KW_cases);("eq", KW_eq);("neq", KW_neq);("bvnot", KW_bvnot);("bvneg", KW_bvneg);("bvand", KW_bvand);("bvor", KW_bvor);("bvadd", KW_bvadd);("bvmul", KW_bvmul);("bvudiv", KW_bvudiv);("bvurem", KW_bvurem);("bvshl", KW_bvshl);("bvlshr", KW_bvlshr);("bvnand", KW_bvnand);("bvnor", KW_bvnor);("bvxor", KW_bvxor);("bvxnor", KW_bvxnor);("bvcomp", KW_bvcomp);("bvsub", KW_bvsub);("bvsdiv", KW_bvsdiv);("bvsrem", KW_bvsrem);("bvsmod", KW_bvsmod);("bvashr", KW_bvashr);("bvule", KW_bvule);("bvugt", KW_bvugt);("bvuge", KW_bvuge);("bvult", KW_bvult);("bvslt", KW_bvslt);("bvsle", KW_bvsle);("bvsgt", KW_bvsgt);("bvsge", KW_bvsge);("intadd", KW_intadd);("intmul", KW_intmul);("intsub", KW_intsub);("intdiv", KW_intdiv);("intmod", KW_intmod);("intlt", KW_intlt);("intle", KW_intle);("intgt", KW_intgt);("intge", KW_intge);("booland", KW_booland);("boolor", KW_boolor);("boolimplies", KW_boolimplies);("require", KW_require);("requires", KW_requires);("ensure", KW_ensure);("ensures", KW_ensures);("rely", KW_rely);("relies", KW_relies);("guarnatee", KW_guarnatee);("guarantees", KW_guarantees);("captures", KW_captures);("modifies", KW_modifies);("invariant", KW_invariant);("guarantee", KW_guarantee)] + [("shared", KW_shared);("observable", KW_observable);("axiom", KW_axiom);("memory", KW_memory);("var", KW_var);("val", KW_val);("let", KW_let);("prog", KW_prog);("entry", KW_entry);("proc", KW_proc);("le", KW_le);("be", KW_be);("nop", KW_nop);("store", KW_store);("load", KW_load);("call", KW_call);("indirect", KW_indirect);("assume", KW_assume);("guard", KW_guard);("assert", KW_assert);("goto", KW_goto);("unreachable", KW_unreachable);("return", KW_return);("phi", KW_phi);("block", KW_block);("true", KW_true);("false", KW_false);("forall", KW_forall);("exists", KW_exists);("fun", KW_fun);("old", KW_old);("boolnot", KW_boolnot);("intneg", KW_intneg);("booltobv1", KW_booltobv1);("gamma", KW_gamma);("classification", KW_classification);("load_be", KW_load_be);("load_le", KW_load_le);("zero_extend", KW_zero_extend);("sign_extend", KW_sign_extend);("extract", KW_extract);("bvconcat", KW_bvconcat);("match", KW_match);("with", KW_with);("cases", KW_cases);("eq", KW_eq);("neq", KW_neq);("bvnot", KW_bvnot);("bvneg", KW_bvneg);("bvand", KW_bvand);("bvor", KW_bvor);("bvadd", KW_bvadd);("bvmul", KW_bvmul);("bvudiv", KW_bvudiv);("bvurem", KW_bvurem);("bvshl", KW_bvshl);("bvlshr", KW_bvlshr);("bvnand", KW_bvnand);("bvnor", KW_bvnor);("bvxor", KW_bvxor);("bvxnor", KW_bvxnor);("bvcomp", KW_bvcomp);("bvsub", KW_bvsub);("bvsdiv", KW_bvsdiv);("bvsrem", KW_bvsrem);("bvsmod", KW_bvsmod);("bvashr", KW_bvashr);("bvule", KW_bvule);("bvugt", KW_bvugt);("bvuge", KW_bvuge);("bvult", KW_bvult);("bvslt", KW_bvslt);("bvsle", KW_bvsle);("bvsgt", KW_bvsgt);("bvsge", KW_bvsge);("intadd", KW_intadd);("intmul", KW_intmul);("intsub", KW_intsub);("intdiv", KW_intdiv);("intmod", KW_intmod);("intlt", KW_intlt);("intle", KW_intle);("intgt", KW_intgt);("intge", KW_intge);("booland", KW_booland);("boolor", KW_boolor);("boolimplies", KW_boolimplies);("require", KW_require);("requires", KW_requires);("ensure", KW_ensure);("ensures", KW_ensures);("rely", KW_rely);("relies", KW_relies);("guarantee", KW_guarantee);("guarantees", KW_guarantees);("captures", KW_captures);("modifies", KW_modifies);("invariant", KW_invariant)] let unescapeInitTail (s:string) : string = let rec unesc s = match s with diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index e57c5969..dd887b98 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -7,7 +7,7 @@ open AbsBasilIR open Lexing %} -%token KW_shared KW_observable KW_axiom KW_memory KW_var KW_val KW_let KW_prog KW_entry KW_proc KW_le KW_be KW_nop KW_store KW_load KW_call KW_indirect KW_assume KW_guard KW_assert KW_goto KW_unreachable KW_return KW_phi KW_block KW_true KW_false KW_forall KW_exists KW_fun KW_old KW_boolnot KW_intneg KW_booltobv1 KW_gamma KW_classification KW_load_be KW_load_le KW_zero_extend KW_sign_extend KW_extract KW_bvconcat KW_match KW_with KW_cases KW_eq KW_neq KW_bvnot KW_bvneg KW_bvand KW_bvor KW_bvadd KW_bvmul KW_bvudiv KW_bvurem KW_bvshl KW_bvlshr KW_bvnand KW_bvnor KW_bvxor KW_bvxnor KW_bvcomp KW_bvsub KW_bvsdiv KW_bvsrem KW_bvsmod KW_bvashr KW_bvule KW_bvugt KW_bvuge KW_bvult KW_bvslt KW_bvsle KW_bvsgt KW_bvsge KW_intadd KW_intmul KW_intsub KW_intdiv KW_intmod KW_intlt KW_intle KW_intgt KW_intge KW_booland KW_boolor KW_boolimplies KW_require KW_requires KW_ensure KW_ensures KW_rely KW_relies KW_guarnatee KW_guarantees KW_captures KW_modifies KW_invariant KW_guarantee +%token KW_shared KW_observable KW_axiom KW_memory KW_var KW_val KW_let KW_prog KW_entry KW_proc KW_le KW_be KW_nop KW_store KW_load KW_call KW_indirect KW_assume KW_guard KW_assert KW_goto KW_unreachable KW_return KW_phi KW_block KW_true KW_false KW_forall KW_exists KW_fun KW_old KW_boolnot KW_intneg KW_booltobv1 KW_gamma KW_classification KW_load_be KW_load_le KW_zero_extend KW_sign_extend KW_extract KW_bvconcat KW_match KW_with KW_cases KW_eq KW_neq KW_bvnot KW_bvneg KW_bvand KW_bvor KW_bvadd KW_bvmul KW_bvudiv KW_bvurem KW_bvshl KW_bvlshr KW_bvnand KW_bvnor KW_bvxor KW_bvxnor KW_bvcomp KW_bvsub KW_bvsdiv KW_bvsrem KW_bvsmod KW_bvashr KW_bvule KW_bvugt KW_bvuge KW_bvult KW_bvslt KW_bvsle KW_bvsgt KW_bvsge KW_intadd KW_intmul KW_intsub KW_intdiv KW_intmod KW_intlt KW_intle KW_intgt KW_intge KW_booland KW_boolor KW_boolimplies KW_require KW_requires KW_ensure KW_ensures KW_rely KW_relies KW_guarantee KW_guarantees KW_captures KW_modifies KW_invariant %token SYMB1 /* ; */ %token SYMB2 /* , */ @@ -752,7 +752,7 @@ relyTok : KW_rely { RelyTok_rely } | KW_relies { RelyTok_relies } ; -guarTok : KW_guarnatee { GuarTok_guarnatee } +guarTok : KW_guarantee { GuarTok_guarantee } | KW_guarantees { GuarTok_guarantees } ; @@ -769,8 +769,8 @@ varSpec : KW_classification expr { VarSpec_Classification $2 } | /* empty */ { VarSpec_Empty } ; -progSpec : KW_rely expr { ProgSpec_Rely $2 } - | KW_guarantee expr { ProgSpec_Guarantee $2 } +progSpec : relyTok expr { ProgSpec_Rely ($1, $2) } + | guarTok expr { ProgSpec_Guarantee ($1, $2) } ; funSpec_list : /* empty */ { [] } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index f1fada17..d1a2ae5e 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -508,7 +508,7 @@ and prtRelyTok (i:int) (e : AbsBasilIR.relyTok) : doc = match e with and prtGuarTok (i:int) (e : AbsBasilIR.guarTok) : doc = match e with - AbsBasilIR.GuarTok_guarnatee -> prPrec i 0 (concatD [render "guarnatee"]) + AbsBasilIR.GuarTok_guarantee -> prPrec i 0 (concatD [render "guarantee"]) | AbsBasilIR.GuarTok_guarantees -> prPrec i 0 (concatD [render "guarantees"]) @@ -531,8 +531,8 @@ and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with - AbsBasilIR.ProgSpec_Rely expr -> prPrec i 0 (concatD [render "rely" ; prtExpr 0 expr]) - | AbsBasilIR.ProgSpec_Guarantee expr -> prPrec i 0 (concatD [render "guarantee" ; prtExpr 0 expr]) + AbsBasilIR.ProgSpec_Rely (relytok, expr) -> prPrec i 0 (concatD [prtRelyTok 0 relytok ; prtExpr 0 expr]) + | AbsBasilIR.ProgSpec_Guarantee (guartok, expr) -> prPrec i 0 (concatD [prtGuarTok 0 guartok ; prtExpr 0 expr]) and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 769b7d20..633cd192 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -374,7 +374,7 @@ and showRelyTok (e : AbsBasilIR.relyTok) : showable = match e with and showGuarTok (e : AbsBasilIR.guarTok) : showable = match e with - AbsBasilIR.GuarTok_guarnatee -> s2s "GuarTok_guarnatee" + AbsBasilIR.GuarTok_guarantee -> s2s "GuarTok_guarantee" | AbsBasilIR.GuarTok_guarantees -> s2s "GuarTok_guarantees" @@ -394,8 +394,8 @@ and showVarSpec (e : AbsBasilIR.varSpec) : showable = match e with and showProgSpec (e : AbsBasilIR.progSpec) : showable = match e with - AbsBasilIR.ProgSpec_Rely expr -> s2s "ProgSpec_Rely" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' - | AbsBasilIR.ProgSpec_Guarantee expr -> s2s "ProgSpec_Guarantee" >> c2s ' ' >> c2s '(' >> showExpr expr >> c2s ')' + AbsBasilIR.ProgSpec_Rely (relytok, expr) -> s2s "ProgSpec_Rely" >> c2s ' ' >> c2s '(' >> showRelyTok relytok >> s2s ", " >> showExpr expr >> c2s ')' + | AbsBasilIR.ProgSpec_Guarantee (guartok, expr) -> s2s "ProgSpec_Guarantee" >> c2s ' ' >> c2s '(' >> showGuarTok guartok >> s2s ", " >> showExpr expr >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index d60eb8bb..36fe688a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -394,7 +394,7 @@ and transRelyTok (x : relyTok) : result = match x with and transGuarTok (x : guarTok) : result = match x with - GuarTok_guarnatee -> failure x + GuarTok_guarantee -> failure x | GuarTok_guarantees -> failure x @@ -414,8 +414,8 @@ and transVarSpec (x : varSpec) : result = match x with and transProgSpec (x : progSpec) : result = match x with - ProgSpec_Rely expr -> failure x - | ProgSpec_Guarantee expr -> failure x + ProgSpec_Rely (relytok, expr) -> failure x + | ProgSpec_Guarantee (guartok, expr) -> failure x diff --git a/lib/loadir.ml b/lib/loadir.ml index 82517f03..7c8dc9ff 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -232,12 +232,12 @@ module BasilASTLoader = struct |> map_prog (fun prog -> let spec = prog.spec in match p with - | ProgSpec_Rely b -> + | ProgSpec_Rely (_, b) -> { prog with spec = { spec with rely = trans_expr p_st b :: spec.rely }; } - | ProgSpec_Guarantee b -> + | ProgSpec_Guarantee (_, b) -> { prog with spec = diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 2f76d509..ac58ab1c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -649,8 +649,8 @@ module.exports = grammar({ ), GuarTok: $ => choice( - // GuarTok_guarnatee. GuarTok ::= "guarnatee" ; - "guarnatee", + // GuarTok_guarantee. GuarTok ::= "guarantee" ; + "guarantee", // GuarTok_guarantees. GuarTok ::= "guarantees" ; "guarantees" ), @@ -680,10 +680,10 @@ module.exports = grammar({ ), ProgSpec: $ => choice( - // ProgSpec_Rely. ProgSpec ::= "rely" Expr ; - seq("rely", $.Expr), - // ProgSpec_Guarantee. ProgSpec ::= "guarantee" Expr ; - seq("guarantee", $.Expr) + // ProgSpec_Rely. ProgSpec ::= RelyTok Expr ; + seq($.RelyTok, $.Expr), + // ProgSpec_Guarantee. ProgSpec ::= GuarTok Expr ; + seq($.GuarTok, $.Expr) ), list_FunSpec: $ => choice( diff --git a/tree-sitter/queries/highlights.scm b/tree-sitter/queries/highlights.scm index 5e563534..a4801059 100644 --- a/tree-sitter/queries/highlights.scm +++ b/tree-sitter/queries/highlights.scm @@ -13,23 +13,35 @@ "nop" @keyword "load" @keyword -"le" @keyword -"be" @keyword +"le" @keyword.modifier +"be" @keyword.modifier "store" @keyword "guard" @keyword "assert" @keyword "assume" @keyword "var" @keyword "memory" @keyword -"shared" @keyword -"rely" @keyword -"guarantee" @keyword -"modifies" @keyword -"captures" @keyword -"forall" @keyword -"exists" @keyword -"fun" @keyword -"old" @keyword +"shared" @keyword.modifier +[ "rely" + "relies" + "guarantee" + "guarantee" + "require" + "requires" + "ensures" + "ensure" + "captures" + "modifies" + "classification" + "invariant" ] @keyword +[ "forall" + "exists" + "fun" + "old" ] @keyword.operator + +[ "match" + "with" + "cases" ] @keyword.conditional (IntVal) @number (token_IntegerHex) @number @@ -60,6 +72,9 @@ (UnOp) @function.builtin (EqOp) @function.builtin +"load_be" @function.builtin +"load_le" @function.builtin + "boolnot" @function.builtin "intneg" @function.builtin "booltobv1" @function.builtin From 1462470d30ea79c811d3be509d9d3775b1474a2b Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 3 Mar 2026 17:57:21 +1000 Subject: [PATCH 26/43] why is this not highlighting? t-s says error at store statement memory shared $mem : (bv64 -> bv8); memory $stack : (bv64 -> bv8); prog entry @main_4197696; proc @main_4197696 () -> () [ block %main_entry [ store le $stack bvadd($R31:bv64, 0xfffffffffffffff0:bv64) $R29:bv64 64 ; goto(%main_basil_return_1); ]; block %main_basil_return_1 [ return (); ] ]; --- tree-sitter/queries/highlights.scm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tree-sitter/queries/highlights.scm b/tree-sitter/queries/highlights.scm index a4801059..af857c59 100644 --- a/tree-sitter/queries/highlights.scm +++ b/tree-sitter/queries/highlights.scm @@ -6,15 +6,13 @@ "unreachable" @keyword.return "return" @keyword.return -["ensures" "ensure" "requires" "require"] @keyword - "call" @keyword.function "indirect" @keyword.function "nop" @keyword "load" @keyword -"le" @keyword.modifier -"be" @keyword.modifier +"le" @keyword +"be" @keyword "store" @keyword "guard" @keyword "assert" @keyword From d73a2b2ad5f9760fff8145dfb6e8af4cd83ac5e9 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 12:51:43 +1000 Subject: [PATCH 27/43] remove literal parens --- tree-sitter/queries/highlights.scm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tree-sitter/queries/highlights.scm b/tree-sitter/queries/highlights.scm index af857c59..27df3d72 100644 --- a/tree-sitter/queries/highlights.scm +++ b/tree-sitter/queries/highlights.scm @@ -134,8 +134,7 @@ [ ";" "," ] @punctuation.delimiter [ ":" "=" ":=" "::" ] @punctuation -[ "(" ")" - (token_BeginRec) +[ (token_BeginRec) (token_EndRec) (token_BeginList) (token_EndList) ] @punctuation.bracket From 31a6954c2a462f888894d0e5098a1ab7bbc8a41f Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 12:56:38 +1000 Subject: [PATCH 28/43] revert spec semicolon change --- examples/cat.il | 148 +++++++++++++++++++++---------------------- examples/conds.il | 4 +- examples/x-output.il | 2 +- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/examples/cat.il b/examples/cat.il index 27fd0e5b..d6b0c07c 100644 --- a/examples/cat.il +++ b/examples/cat.il @@ -48,8 +48,8 @@ prog entry @main_4197696; proc @main_4197696 () -> () { .name = "main"; .address = 0x400d40; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x400d40:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x400d40:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %main_entry {.address = 0x400d40; .originalLabel = "KXhc9Fe2Qva4qWVLC1eV+w=="} [ assert eq($_PC:bv64, 0x400d40:bv64); @@ -86,8 +86,8 @@ proc @exit () -> () proc @exitcode_4198816 () -> () { .name = "exitcode"; .address = 0x4011a0; .returnBlock = "exitcode_basil_return_1" } - require eq($_PC:bv64, 0x4011a0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4011a0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %exitcode_entry {.address = 0x4011a0; .originalLabel = "Hr3XvFHLQ62ROxw2L+L+kg=="} [ assert eq($_PC:bv64, 0x4011a0:bv64); @@ -109,8 +109,8 @@ proc @exitcode_4198816 () -> () proc @exits_4198688 () -> () { .name = "exits"; .address = 0x401120; .returnBlock = "exits_basil_return_1" } - require eq($_PC:bv64, 0x401120:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401120:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %exits_entry {.address = 0x401120; .originalLabel = "OamxgWkAT5S7lYhJLb34Bw=="} [ var R30_begin_exits_4198688: bv64 := $R30:bv64; @@ -449,8 +449,8 @@ proc @exits_4198688 () -> () proc @fmtlocaleinit_4209552 () -> () { .name = "fmtlocaleinit"; .address = 0x403b90; .returnBlock = "fmtlocaleinit_basil_return_1" } - require eq($_PC:bv64, 0x403b90:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403b90:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %fmtlocaleinit_entry {.address = 0x403b90; .originalLabel = "LJeXYGqvSDa8MTgV+KKKNg=="} [ assert eq($_PC:bv64, 0x403b90:bv64); @@ -611,8 +611,8 @@ proc @fmtlocaleinit_4209552 () -> () proc @fmtfdinit_4209364 () -> () { .name = "fmtfdinit"; .address = 0x403ad4; .returnBlock = "fmtfdinit_basil_return_1" } - require eq($_PC:bv64, 0x403ad4:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403ad4:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %fmtfdinit_entry {.address = 0x403ad4; .originalLabel = "Ase3rrH2SOSuhunVYXYBhg=="} [ assert eq($_PC:bv64, 0x403ad4:bv64); @@ -715,8 +715,8 @@ proc @write () -> () proc @__fmtFdFlush_4209456 () -> () { .name = "__fmtFdFlush"; .address = 0x403b30; .returnBlock = "__fmtFdFlush_basil_return_1" } - require eq($_PC:bv64, 0x403b30:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403b30:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtFdFlush_entry {.address = 0x403b30; .originalLabel = "I+YOj/gGRqS87EwafUF4WA=="} [ assert eq($_PC:bv64, 0x403b30:bv64); @@ -914,8 +914,8 @@ proc @__fmtFdFlush_4209456 () -> () proc @__flagfmt_4208112 () -> () { .name = "__flagfmt"; .address = 0x4035f0; .returnBlock = "__flagfmt_basil_return_1" } - require eq($_PC:bv64, 0x4035f0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4035f0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__flagfmt_entry {.address = 0x4035f0; .originalLabel = "Md5qE+eiRf+m/NPBkVuT3g=="} [ assert eq($_PC:bv64, 0x4035f0:bv64); @@ -1454,8 +1454,8 @@ proc @__flagfmt_4208112 () -> () proc @__rfmtpad_4203024 () -> () { .name = "__rfmtpad"; .address = 0x402210; .returnBlock = "__rfmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402210:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x402210:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__rfmtpad_entry {.address = 0x402210; .originalLabel = "FnHqSK+lTxq6YDUq7NvnJg=="} [ assert eq($_PC:bv64, 0x402210:bv64); @@ -1940,8 +1940,8 @@ proc @__rfmtpad_4203024 () -> () proc @runelen_4210048 () -> () { .name = "runelen"; .address = 0x403d80; .returnBlock = "runelen_basil_return_1" } - require eq($_PC:bv64, 0x403d80:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403d80:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %runelen_entry {.address = 0x403d80; .originalLabel = "o0lVyZ2GT4mJNVkb5e5Vuw=="} [ assert eq($_PC:bv64, 0x403d80:bv64); @@ -2022,8 +2022,8 @@ proc @runelen_4210048 () -> () proc @fullrune_4210160 () -> () { .name = "fullrune"; .address = 0x403df0; .returnBlock = "fullrune_basil_return_1" } - require eq($_PC:bv64, 0x403df0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403df0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %fullrune_entry {.address = 0x403df0; .originalLabel = "ycUhyOy1TNW1hp1YrdP0uw=="} [ assert eq($_PC:bv64, 0x403df0:bv64); @@ -2178,8 +2178,8 @@ proc @fullrune_4210160 () -> () proc @__fmtpad_4202756 () -> () { .name = "__fmtpad"; .address = 0x402104; .returnBlock = "__fmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402104:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x402104:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtpad_entry {.address = 0x402104; .originalLabel = "DS7w57znRnmBsFkYW6cA+Q=="} [ assert eq($_PC:bv64, 0x402104:bv64); @@ -2663,8 +2663,8 @@ proc @__fmtpad_4202756 () -> () proc @runetochar_4209936 () -> () { .name = "runetochar"; .address = 0x403d10; .returnBlock = "runetochar_basil_return_1" } - require eq($_PC:bv64, 0x403d10:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403d10:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %runetochar_entry {.address = 0x403d10; .originalLabel = "Rkek/d08TK2mkJ7PEcm6mg=="} [ assert eq($_PC:bv64, 0x403d10:bv64); @@ -2816,8 +2816,8 @@ proc @runetochar_4209936 () -> () proc @__fmtflush_4202032 () -> () { .name = "__fmtflush"; .address = 0x401e30; .returnBlock = "__fmtflush_basil_return_1" } - require eq($_PC:bv64, 0x401e30:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401e30:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtflush_entry {.address = 0x401e30; .originalLabel = "Osy3QCRQRpSd5aY0vW+qkQ=="} [ assert eq($_PC:bv64, 0x401e30:bv64); @@ -3092,8 +3092,8 @@ proc @__fmtflush_4202032 () -> () proc @chartorune_4209760 () -> () { .name = "chartorune"; .address = 0x403c60; .returnBlock = "chartorune_basil_return_1" } - require eq($_PC:bv64, 0x403c60:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403c60:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %chartorune_entry {.address = 0x403c60; .originalLabel = "+s65+r9uRzKHgPS/OxqX3g=="} [ assert eq($_PC:bv64, 0x403c60:bv64); @@ -3398,8 +3398,8 @@ proc @chartorune_4209760 () -> () proc @__fmtcpy_4203296 () -> () { .name = "__fmtcpy"; .address = 0x402320; .returnBlock = "__fmtcpy_basil_return_1" } - require eq($_PC:bv64, 0x402320:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x402320:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtcpy_entry {.address = 0x402320; .originalLabel = "onW0wUQSS+CWRE3FG7sZVA=="} [ assert eq($_PC:bv64, 0x402320:bv64); @@ -4774,8 +4774,8 @@ proc @__fmtcpy_4203296 () -> () proc @__badfmt_4208400 () -> () { .name = "__badfmt"; .address = 0x403710; .returnBlock = "__badfmt_basil_return_1" } - require eq($_PC:bv64, 0x403710:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403710:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__badfmt_entry {.address = 0x403710; .originalLabel = "VsS7dlFoQ3et0t9jIUUtyw=="} [ assert eq($_PC:bv64, 0x403710:bv64); @@ -4852,8 +4852,8 @@ proc @__badfmt_4208400 () -> () proc @getcallerpc_4201920 () -> () { .name = "getcallerpc"; .address = 0x401dc0; .returnBlock = "getcallerpc_basil_return_1" } - require eq($_PC:bv64, 0x401dc0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401dc0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %getcallerpc_entry {.address = 0x401dc0; .originalLabel = "/lgI4FfjS+yfGYqEtnuiGw=="} [ assert eq($_PC:bv64, 0x401dc0:bv64); @@ -4879,8 +4879,8 @@ proc @getcallerpc_4201920 () -> () proc @unlock_4199332 () -> () { .name = "unlock"; .address = 0x4013a4; .returnBlock = "unlock_basil_return_1" } - require eq($_PC:bv64, 0x4013a4:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4013a4:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %unlock_entry {.address = 0x4013a4; .originalLabel = "V0jFzXuITMiNHr/kb8xG4g=="} [ assert eq($_PC:bv64, 0x4013a4:bv64); @@ -5022,8 +5022,8 @@ proc @unlock_4199332 () -> () proc @__fmtunlock_4209744 () -> () { .name = "__fmtunlock"; .address = 0x403c50; .returnBlock = "__fmtunlock_basil_return_1" } - require eq($_PC:bv64, 0x403c50:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403c50:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtunlock_entry {.address = 0x403c50; .originalLabel = "LHWtkP5rQmqxTbinnC1hLw=="} [ var R30_begin___fmtunlock_4209744: bv64 := $R30:bv64; @@ -5051,8 +5051,8 @@ proc @__fmtunlock_4209744 () -> () proc @lock_4199120 () -> () { .name = "lock"; .address = 0x4012d0; .returnBlock = "lock_basil_return_1" } - require eq($_PC:bv64, 0x4012d0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4012d0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %lock_entry {.address = 0x4012d0; .originalLabel = "EL5Ky+1GSIeJ6nw6JbZnPg=="} [ assert eq($_PC:bv64, 0x4012d0:bv64); @@ -5204,8 +5204,8 @@ proc @lock_4199120 () -> () proc @__fmtlock_4209728 () -> () { .name = "__fmtlock"; .address = 0x403c40; .returnBlock = "__fmtlock_basil_return_1" } - require eq($_PC:bv64, 0x403c40:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403c40:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtlock_entry {.address = 0x403c40; .originalLabel = "n9+4iNtqRLu7+3FBjvBlSg=="} [ var R30_begin___fmtlock_4209728: bv64 := $R30:bv64; @@ -5233,8 +5233,8 @@ proc @__fmtlock_4209728 () -> () proc @__fmtinstall_4208464 () -> () { .name = "__fmtinstall"; .address = 0x403750; .returnBlock = "__fmtinstall_basil_return_1" } - require eq($_PC:bv64, 0x403750:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403750:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtinstall_entry {.address = 0x403750; .originalLabel = "4vz6BXioRXa/LaTzSs8GSg=="} [ assert eq($_PC:bv64, 0x403750:bv64); @@ -5516,8 +5516,8 @@ proc @__fmtinstall_4208464 () -> () proc @__fmtdispatch_4208688 () -> () { .name = "__fmtdispatch"; .address = 0x403830; .returnBlock = "__fmtdispatch_basil_return_1" } - require eq($_PC:bv64, 0x403830:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x403830:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fmtdispatch_entry {.address = 0x403830; .originalLabel = "J5JvET/ORDyFBY1+xoNLkA=="} [ assert eq($_PC:bv64, 0x403830:bv64); @@ -6659,8 +6659,8 @@ proc @__fmtdispatch_4208688 () -> () proc @dofmt_4202176 () -> () { .name = "dofmt"; .address = 0x401ec0; .returnBlock = "dofmt_basil_return_1" } - require eq($_PC:bv64, 0x401ec0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401ec0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %dofmt_entry {.address = 0x401ec0; .originalLabel = "ptCQBLyvTM22JSPE/cK18w=="} [ assert eq($_PC:bv64, 0x401ec0:bv64); @@ -7699,8 +7699,8 @@ proc @dofmt_4202176 () -> () proc @vfprint_4201072 () -> () { .name = "vfprint"; .address = 0x401a70; .returnBlock = "vfprint_basil_return_1" } - require eq($_PC:bv64, 0x401a70:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401a70:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %vfprint_entry {.address = 0x401a70; .originalLabel = "kh4iUxoKQMenD77ljouyEQ=="} [ assert eq($_PC:bv64, 0x401a70:bv64); @@ -7882,8 +7882,8 @@ proc @vfprint_4201072 () -> () proc @fprint_4200960 () -> () { .name = "fprint"; .address = 0x401a00; .returnBlock = "fprint_basil_return_1" } - require eq($_PC:bv64, 0x401a00:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401a00:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %fprint_entry {.address = 0x401a00; .originalLabel = "fQteMOadSm+stHHR3jx4Qw=="} [ assert eq($_PC:bv64, 0x401a00:bv64); @@ -7986,8 +7986,8 @@ proc @fprint_4200960 () -> () proc @__fixargv0_4198400 () -> () { .name = "__fixargv0"; .address = 0x401000; .returnBlock = "__fixargv0_basil_return_1" } - require eq($_PC:bv64, 0x401000:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401000:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %__fixargv0_entry {.address = 0x401000; .originalLabel = "78skE39ZS92hlwuQoG/N1g=="} [ assert eq($_PC:bv64, 0x401000:bv64); @@ -8007,8 +8007,8 @@ proc @__fixargv0_4198400 () -> () proc @vseprint_4201184 () -> () { .name = "vseprint"; .address = 0x401ae0; .returnBlock = "vseprint_basil_return_1" } - require eq($_PC:bv64, 0x401ae0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401ae0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %vseprint_entry {.address = 0x401ae0; .originalLabel = "xuA0Edh9S8yFZV1Qu/Jgqw=="} [ assert eq($_PC:bv64, 0x401ae0:bv64); @@ -8169,8 +8169,8 @@ proc @vseprint_4201184 () -> () proc @sysfatal_4200560 () -> () { .name = "sysfatal"; .address = 0x401870; .returnBlock = "sysfatal_basil_return_1" } - require eq($_PC:bv64, 0x401870:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401870:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %sysfatal_entry {.address = 0x401870; .originalLabel = "HN8ZNDP1RUKhvFhL/Qx3ng=="} [ var R30_begin_sysfatal_4200560: bv64 := $R30:bv64; @@ -8471,8 +8471,8 @@ proc @memccpy () -> () proc @strecpy_4201936 () -> () { .name = "strecpy"; .address = 0x401dd0; .returnBlock = "strecpy_basil_return_1" } - require eq($_PC:bv64, 0x401dd0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401dd0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %strecpy_entry {.address = 0x401dd0; .originalLabel = "gS9qAucpRMKJD8TibWbm5A=="} [ assert eq($_PC:bv64, 0x401dd0:bv64); @@ -8680,8 +8680,8 @@ proc @strerror () -> () proc @rerrstr_4201312 () -> () { .name = "rerrstr"; .address = 0x401b60; .returnBlock = "rerrstr_basil_return_1" } - require eq($_PC:bv64, 0x401b60:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401b60:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %rerrstr_entry {.address = 0x401b60; .originalLabel = "ldWhLOMYSKyYFGShQwXqIg=="} [ var R30_begin_rerrstr_4201312: bv64 := $R30:bv64; @@ -9214,8 +9214,8 @@ proc @rerrstr_4201312 () -> () proc @errstr_4201540 () -> () { .name = "errstr"; .address = 0x401c44; .returnBlock = "errstr_basil_return_1" } - require eq($_PC:bv64, 0x401c44:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401c44:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %errstr_entry {.address = 0x401c44; .originalLabel = "3ReV3l3lTEWXlI8dRV4Pcw=="} [ assert eq($_PC:bv64, 0x401c44:bv64); @@ -9454,8 +9454,8 @@ proc @errstr_4201540 () -> () proc @werrstr_4201780 () -> () { .name = "werrstr"; .address = 0x401d34; .returnBlock = "werrstr_basil_return_1" } - require eq($_PC:bv64, 0x401d34:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401d34:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %werrstr_entry {.address = 0x401d34; .originalLabel = "EsiP/3+hSbS6DhsMqrwxFA=="} [ assert eq($_PC:bv64, 0x401d34:bv64); @@ -9607,8 +9607,8 @@ proc @open64 () -> () proc @p9open_4198832 () -> () { .name = "p9open"; .address = 0x4011b0; .returnBlock = "p9open_basil_return_1" } - require eq($_PC:bv64, 0x4011b0:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4011b0:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %p9open_entry {.address = 0x4011b0; .originalLabel = "DYW7Gbw6QwK5DzhE/cGL7w=="} [ assert eq($_PC:bv64, 0x4011b0:bv64); @@ -10273,8 +10273,8 @@ proc @p9open_4198832 () -> () proc @p9write_4200816 () -> () { .name = "p9write"; .address = 0x401970; .returnBlock = "p9write_basil_return_1" } - require eq($_PC:bv64, 0x401970:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x401970:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %p9write_entry {.address = 0x401970; .originalLabel = "qVvzznzaToayt5BQelE/sg=="} [ assert eq($_PC:bv64, 0x401970:bv64); @@ -10571,8 +10571,8 @@ proc @read () -> () proc @cat_4198032 () -> () { .name = "cat"; .address = 0x400e90; .returnBlock = "cat_basil_return_1" } - require eq($_PC:bv64, 0x400e90:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x400e90:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %cat_entry {.address = 0x400e90; .originalLabel = "OMO2ysIfSmeORBpBsr5OIQ=="} [ var R30_begin_cat_4198032: bv64 := $R30:bv64; @@ -10826,8 +10826,8 @@ proc @cat_4198032 () -> () proc @p9main_4198208 () -> () { .name = "p9main"; .address = 0x400f40; .returnBlock = "p9main_basil_return_1" } - require eq($_PC:bv64, 0x400f40:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x400f40:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %p9main_entry {.address = 0x400f40; .originalLabel = "FGQT8qmESb6FIwl/znG8jA=="} [ var R30_begin_p9main_4198208: bv64 := $R30:bv64; diff --git a/examples/conds.il b/examples/conds.il index 0428a536..1125b6d6 100644 --- a/examples/conds.il +++ b/examples/conds.il @@ -14,8 +14,8 @@ prog entry @main_4196260; proc @main_4196260 () -> () { .name = "main"; .address = 0x4007a4; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x4007a4:bv64) - ensures eq($_PC:bv64, old($R30:bv64)) + require eq($_PC:bv64, 0x4007a4:bv64); + ensures eq($_PC:bv64, old($R30:bv64)); [ block %main_entry {.address = 0x4007a4; .originalLabel = "rlVqjjqoR6uHwOYvPCS15g=="} [ assert eq($_PC:bv64, 0x4007a4:bv64); diff --git a/examples/x-output.il b/examples/x-output.il index 8d649379..acccac91 100644 --- a/examples/x-output.il +++ b/examples/x-output.il @@ -7,7 +7,7 @@ proc @main_4196164 (R0_in:bv64, R1_in:bv64, R30_in:bv64, R31_in:bv64, _PC_in:bv64) -> (R0_out:bv64, R1_out:bv64, _PC_out:bv64) { .name = "main"; .address = 0x400744 } - require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)) + require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)); [ block %main_entry {.address = 0x400744; .originalLabel = "G8B0Q6XuSneDgqpNFr1sUQ=="} [ store le $stack bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32, 0, R0_in:bv64) 32 { .label = "4196168_0" }; From b44a2b02cb2740dd20c9b9c3a05bd5aced428fac Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 12:59:29 +1000 Subject: [PATCH 29/43] restore semicolon-terminated specs semicolon is manually specified at the end of all Decls aside from prog/proc where it is handled specially --- lib/fe/BasilIR.cf | 24 +++++------ lib/fe/LexBasilIR.mll | 4 +- lib/fe/ParBasilIR.mly | 96 +++++++++++++++++++++--------------------- lib/fe/PrintBasilIR.ml | 25 ++++++----- tree-sitter/grammar.js | 50 +++++++++++----------- 5 files changed, 99 insertions(+), 100 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index d5670f7e..54b558e7 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -1,6 +1,6 @@ rules Module ::= [Decl] ; -terminator Decl ";"; +terminator Decl ""; {- TOKENS -} @@ -45,22 +45,22 @@ Shared . VarModifiers ::= "shared" ; Observable . VarModifiers ::= "observable"; separator VarModifiers "" ; -Decl_Axiom . Decl ::= "axiom" GlobalIdent AttribSet Expr; -Decl_Mem . Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ; -Decl_Var . Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ; +Decl_Axiom . Decl ::= "axiom" GlobalIdent AttribSet Expr ";"; +Decl_Mem . Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ";"; +Decl_Var . Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ";"; separator Type ","; -Decl_UninterpFun . Decl ::= "val" GlobalIdent AttribSet ":" Type ; +Decl_UninterpFun . Decl ::= "val" GlobalIdent AttribSet ":" Type ";"; -Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr; -Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr; -Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ; +Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";"; +Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr ";"; +Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ";"; Decl_ProgWithSpec . Decl ::= "prog" "entry" ProcIdent AttribSet [ ProgSpec ] ; Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [ FunSpec ] ProcDef ; -ProcDef_Empty . ProcDef ::= ; -ProcDef_Some . ProcDef ::= BeginList [Block] EndList ; +ProcDef_Empty . ProcDef ::= ; -- semicolon terminator in FunSpec +ProcDef_Some . ProcDef ::= BeginList [Block] EndList ";"; IntType1 . IntType ::= INTTYPE ; BoolType1. BoolType ::= BOOLTYPE ; @@ -282,10 +282,10 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= RelyTok Expr; ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; -terminator FunSpec "\n"; +terminator FunSpec ";"; {- last semicolon terminates the prog definitino -} -terminator ProgSpec "\n"; +terminator nonempty ProgSpec ";"; diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 879eb028..9169fe4e 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -9,7 +9,7 @@ open Lexing let symbol_table = Hashtbl.create 10 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add symbol_table kwd tok) - [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] + [(",", SYMB1);("->", SYMB2);("::", SYMB3);(";", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] let resword_table = Hashtbl.create 98 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add resword_table kwd tok) @@ -53,7 +53,7 @@ let _idchar = _letter | _digit | ['_' '\''] (* identifier character *) let _universal = _ (* universal: any character *) (* reserved words consisting of special symbols *) -let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" +let rsyms = "," | "->" | "::" | ";" | ":" | "=" | ":=" | "mem:=" | "_" | "|" (* user-defined token types *) let bVTYPE = "bv" _digit + diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index dd887b98..379fc980 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -9,10 +9,10 @@ open Lexing %token KW_shared KW_observable KW_axiom KW_memory KW_var KW_val KW_let KW_prog KW_entry KW_proc KW_le KW_be KW_nop KW_store KW_load KW_call KW_indirect KW_assume KW_guard KW_assert KW_goto KW_unreachable KW_return KW_phi KW_block KW_true KW_false KW_forall KW_exists KW_fun KW_old KW_boolnot KW_intneg KW_booltobv1 KW_gamma KW_classification KW_load_be KW_load_le KW_zero_extend KW_sign_extend KW_extract KW_bvconcat KW_match KW_with KW_cases KW_eq KW_neq KW_bvnot KW_bvneg KW_bvand KW_bvor KW_bvadd KW_bvmul KW_bvudiv KW_bvurem KW_bvshl KW_bvlshr KW_bvnand KW_bvnor KW_bvxor KW_bvxnor KW_bvcomp KW_bvsub KW_bvsdiv KW_bvsrem KW_bvsmod KW_bvashr KW_bvule KW_bvugt KW_bvuge KW_bvult KW_bvslt KW_bvsle KW_bvsgt KW_bvsge KW_intadd KW_intmul KW_intsub KW_intdiv KW_intmod KW_intlt KW_intle KW_intgt KW_intge KW_booland KW_boolor KW_boolimplies KW_require KW_requires KW_ensure KW_ensures KW_rely KW_relies KW_guarantee KW_guarantees KW_captures KW_modifies KW_invariant -%token SYMB1 /* ; */ -%token SYMB2 /* , */ -%token SYMB3 /* -> */ -%token SYMB4 /* :: */ +%token SYMB1 /* , */ +%token SYMB2 /* -> */ +%token SYMB3 /* :: */ +%token SYMB4 /* ; */ %token SYMB5 /* : */ %token SYMB6 /* = */ %token SYMB7 /* := */ @@ -387,16 +387,16 @@ moduleT : decl_list { Module1 $1 } ; decl_list : /* empty */ { [] } - | decl SYMB1 decl_list { (fun (x,xs) -> x::xs) ($1, $3) } + | decl decl_list { (fun (x,xs) -> x::xs) ($1, $2) } ; blockIdent_list : /* empty */ { [] } | blockIdent { (fun x -> [x]) $1 } - | blockIdent SYMB2 blockIdent_list { (fun (x,xs) -> x::xs) ($1, $3) } + | blockIdent SYMB1 blockIdent_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -lambdaSep : SYMB3 { LambdaSep1 } - | SYMB4 { LambdaSep2 } +lambdaSep : SYMB2 { LambdaSep1 } + | SYMB3 { LambdaSep2 } ; varModifiers : KW_shared { Shared } @@ -407,24 +407,24 @@ varModifiers_list : /* empty */ { [] } | varModifiers varModifiers_list { (fun (x,xs) -> x::xs) ($1, $2) } ; -decl : KW_axiom globalIdent attribSet expr { Decl_Axiom ($2, $3, $4) } - | KW_memory varModifiers_list globalIdent SYMB5 typeT varSpec { Decl_Mem ($2, $3, $5, $6) } - | KW_var varModifiers_list globalIdent SYMB5 typeT varSpec { Decl_Var ($2, $3, $5, $6) } - | KW_val globalIdent attribSet SYMB5 typeT { Decl_UninterpFun ($2, $3, $5) } - | KW_let globalIdent attribSet SYMB5 typeT SYMB6 expr { Decl_Fun ($2, $3, $5, $7) } - | KW_let globalIdent attribSet SYMB6 expr { Decl_FunNoType ($2, $3, $5) } - | KW_prog KW_entry procIdent attribSet { Decl_ProgEmpty ($3, $4) } +decl : KW_axiom globalIdent attribSet expr SYMB4 { Decl_Axiom ($2, $3, $4) } + | KW_memory varModifiers_list globalIdent SYMB5 typeT varSpec SYMB4 { Decl_Mem ($2, $3, $5, $6) } + | KW_var varModifiers_list globalIdent SYMB5 typeT varSpec SYMB4 { Decl_Var ($2, $3, $5, $6) } + | KW_val globalIdent attribSet SYMB5 typeT SYMB4 { Decl_UninterpFun ($2, $3, $5) } + | KW_let globalIdent attribSet SYMB5 typeT SYMB6 expr SYMB4 { Decl_Fun ($2, $3, $5, $7) } + | KW_let globalIdent attribSet SYMB6 expr SYMB4 { Decl_FunNoType ($2, $3, $5) } + | KW_prog KW_entry procIdent attribSet SYMB4 { Decl_ProgEmpty ($3, $4) } | KW_prog KW_entry procIdent attribSet progSpec_list { Decl_ProgWithSpec ($3, $4, $5) } - | KW_proc procIdent openParen params_list closeParen SYMB3 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } + | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } ; typeT_list : /* empty */ { [] } | typeT { (fun x -> [x]) $1 } - | typeT SYMB2 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } + | typeT SYMB1 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } ; procDef : /* empty */ { ProcDef_Empty } - | beginList block_list endList { ProcDef_Some ($1, $2, $3) } + | beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3) } ; intType : iNTTYPE { IntType1 $1 } @@ -436,7 +436,7 @@ boolType : bOOLTYPE { BoolType1 $1 } bVType : bVTYPE { BVType1 $1 } ; -mapType : type1 SYMB3 typeT { MapType1 ($1, $3) } +mapType : type1 SYMB2 typeT { MapType1 ($1, $3) } ; type1 : intType { TypeIntType $1 } @@ -480,7 +480,7 @@ stmt : KW_nop { Stmt_Nop } ; assignment_list : assignment { (fun x -> [x]) $1 } - | assignment SYMB2 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } + | assignment SYMB1 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } ; localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } @@ -492,7 +492,7 @@ globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } ; localVar_list : localVar { (fun x -> [x]) $1 } - | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | localVar SYMB1 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; var : localVar { VarLocalVar $1 } @@ -501,7 +501,7 @@ var : localVar { VarLocalVar $1 } globalVar_list : /* empty */ { [] } | globalVar { (fun x -> [x]) $1 } - | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | globalVar SYMB1 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } @@ -509,7 +509,7 @@ namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } namedCallReturn_list : /* empty */ { [] } | namedCallReturn { (fun x -> [x]) $1 } - | namedCallReturn SYMB2 namedCallReturn_list { (fun (x,xs) -> x::xs) ($1, $3) } + | namedCallReturn SYMB1 namedCallReturn_list { (fun (x,xs) -> x::xs) ($1, $3) } ; lVars : /* empty */ { LVars_Empty } @@ -522,7 +522,7 @@ namedCallArg : localIdent SYMB6 expr { NamedCallArg1 ($1, $3) } ; namedCallArg_list : namedCallArg { (fun x -> [x]) $1 } - | namedCallArg SYMB2 namedCallArg_list { (fun (x,xs) -> x::xs) ($1, $3) } + | namedCallArg SYMB1 namedCallArg_list { (fun (x,xs) -> x::xs) ($1, $3) } ; callParams : expr_list { CallParams_Exprs $1 } @@ -540,30 +540,30 @@ lVar : KW_var localVar { LVar_Local $2 } ; lVar_list : lVar { (fun x -> [x]) $1 } - | lVar SYMB2 lVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | lVar SYMB1 lVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; block_list : /* empty */ { [] } | block { (fun x -> [x]) $1 } - | block SYMB1 block_list { (fun (x,xs) -> x::xs) ($1, $3) } + | block SYMB4 block_list { (fun (x,xs) -> x::xs) ($1, $3) } ; stmtWithAttrib : stmt attribSet { StmtWithAttrib1 ($1, $2) } ; stmtWithAttrib_list : /* empty */ { [] } - | stmtWithAttrib SYMB1 stmtWithAttrib_list { (fun (x,xs) -> x::xs) ($1, $3) } + | stmtWithAttrib SYMB4 stmtWithAttrib_list { (fun (x,xs) -> x::xs) ($1, $3) } ; jumpWithAttrib : jump attribSet { JumpWithAttrib1 ($1, $2) } ; -phiExpr : blockIdent SYMB3 var { PhiExpr1 ($1, $3) } +phiExpr : blockIdent SYMB2 var { PhiExpr1 ($1, $3) } ; phiExpr_list : /* empty */ { [] } | phiExpr { (fun x -> [x]) $1 } - | phiExpr SYMB2 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | phiExpr SYMB1 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } @@ -571,11 +571,11 @@ phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1 phiAssign_list : /* empty */ { [] } | phiAssign { (fun x -> [x]) $1 } - | phiAssign SYMB2 phiAssign_list { (fun (x,xs) -> x::xs) ($1, $3) } + | phiAssign SYMB1 phiAssign_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -block : KW_block blockIdent attribSet beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_NoPhi ($2, $3, $4, $5, $6, $8) } - | KW_block blockIdent attribSet openParen phiAssign_list closeParen beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $8, $9, $11) } +block : KW_block blockIdent attribSet beginList stmtWithAttrib_list jumpWithAttrib SYMB4 endList { Block_NoPhi ($2, $3, $4, $5, $6, $8) } + | KW_block blockIdent attribSet openParen phiAssign_list closeParen beginList stmtWithAttrib_list jumpWithAttrib SYMB4 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $8, $9, $11) } ; attrKeyValue : bIdent SYMB6 attr { AttrKeyValue1 ($1, $3) } @@ -583,7 +583,7 @@ attrKeyValue : bIdent SYMB6 attr { AttrKeyValue1 ($1, $3) } attrKeyValue_list : /* empty */ { [] } | attrKeyValue { (fun x -> [x]) $1 } - | attrKeyValue SYMB1 attrKeyValue_list { (fun (x,xs) -> x::xs) ($1, $3) } + | attrKeyValue SYMB4 attrKeyValue_list { (fun (x,xs) -> x::xs) ($1, $3) } ; attribSet : beginRec attrKeyValue_list endRec { AttribSet_Some ($1, $2, $3) } @@ -592,7 +592,7 @@ attribSet : beginRec attrKeyValue_list endRec { AttribSet_Some ($1, $2, $3) } attr_list : /* empty */ { [] } | attr { (fun x -> [x]) $1 } - | attr SYMB1 attr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | attr SYMB4 attr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; attr : beginRec attrKeyValue_list endRec { Attr_Map ($1, $2, $3) } @@ -606,7 +606,7 @@ params : localIdent SYMB5 typeT { Params1 ($1, $3) } params_list : /* empty */ { [] } | params { (fun x -> [x]) $1 } - | params SYMB2 params_list { (fun (x,xs) -> x::xs) ($1, $3) } + | params SYMB1 params_list { (fun (x,xs) -> x::xs) ($1, $3) } ; value : bVVal { Value_BV $1 } @@ -617,7 +617,7 @@ value : bVVal { Value_BV $1 } expr_list : /* empty */ { [] } | expr { (fun x -> [x]) $1 } - | expr SYMB2 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | expr SYMB1 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; expr : expr1 { $1 } @@ -634,14 +634,14 @@ expr2 : value { Expr_Literal $1 } | localVar { Expr_Local $1 } | globalVar { Expr_Global $1 } | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } - | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } + | binOp openParen expr SYMB1 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } - | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } - | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } - | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } - | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } - | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } + | KW_load_be openParen intVal SYMB1 expr SYMB1 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } + | KW_load_le openParen intVal SYMB1 expr SYMB1 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } + | KW_zero_extend openParen intVal SYMB1 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } + | KW_sign_extend openParen intVal SYMB1 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } + | KW_extract openParen intVal SYMB1 intVal SYMB1 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } @@ -654,7 +654,7 @@ lambdaParen : localVar { LambdaParenLocalVar $1 } lambdaParen_list : /* empty */ { [] } | lambdaParen { (fun x -> [x]) $1 } - | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } + | lambdaParen SYMB1 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } @@ -675,8 +675,8 @@ unOp : bVUnOp { UnOpBVUnOp $1 } | KW_classification { UnOp_classification } ; -case : expr SYMB3 expr { CaseCase ($1, $3) } - | SYMB9 SYMB3 expr { CaseDefault $3 } +case : expr SYMB2 expr { CaseCase ($1, $3) } + | SYMB9 SYMB2 expr { CaseDefault $3 } ; case_list : /* empty */ { [] } @@ -774,11 +774,11 @@ progSpec : relyTok expr { ProgSpec_Rely ($1, $2) } ; funSpec_list : /* empty */ { [] } - | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } + | funSpec SYMB4 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -progSpec_list : /* empty */ { [] } - | progSpec progSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } +progSpec_list : progSpec SYMB4 { (fun x -> [x]) $1 } + | progSpec SYMB4 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; bVTYPE : TOK_BVTYPE { BVTYPE ($1)}; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index d1a2ae5e..e9bd2cea 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -153,22 +153,22 @@ and prtVarModifiersListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,x::xs) -> (concatD [prtVarModifiers 0 x ; prtVarModifiersListBNFC 0 xs]) and prtDecl (i:int) (e : AbsBasilIR.decl) : doc = match e with - AbsBasilIR.Decl_Axiom (globalident, attribset, expr) -> prPrec i 0 (concatD [render "axiom" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; prtExpr 0 expr]) - | AbsBasilIR.Decl_Mem (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "memory" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec]) - | AbsBasilIR.Decl_Var (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "var" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec]) - | AbsBasilIR.Decl_UninterpFun (globalident, attribset, type_) -> prPrec i 0 (concatD [render "val" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_]) - | AbsBasilIR.Decl_Fun (globalident, attribset, type_, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render "=" ; prtExpr 0 expr]) - | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr]) - | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset]) + AbsBasilIR.Decl_Axiom (globalident, attribset, expr) -> prPrec i 0 (concatD [render "axiom" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; prtExpr 0 expr ; render ";"]) + | AbsBasilIR.Decl_Mem (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "memory" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec ; render ";"]) + | AbsBasilIR.Decl_Var (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "var" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec ; render ";"]) + | AbsBasilIR.Decl_UninterpFun (globalident, attribset, type_) -> prPrec i 0 (concatD [render "val" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render ";"]) + | AbsBasilIR.Decl_Fun (globalident, attribset, type_, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render "=" ; prtExpr 0 expr ; render ";"]) + | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr ; render ";"]) + | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; render ";"]) | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; prtProgSpecListBNFC 0 progspecs]) | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, funspecs, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtFunSpecListBNFC 0 funspecs ; prtProcDef 0 procdef]) and prtDeclListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtDecl 0 x ; render ";" ; prtDeclListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtDecl 0 x ; prtDeclListBNFC 0 xs]) and prtProcDef (i:int) (e : AbsBasilIR.procDef) : doc = match e with AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist]) + | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) and prtIntType (i:int) (e : AbsBasilIR.intType) : doc = match e with @@ -523,8 +523,7 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render " -" ; prtFunSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) | AbsBasilIR.VarSpec_Empty -> prPrec i 0 (concatD []) @@ -536,6 +535,6 @@ and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render " -" ; prtProgSpecListBNFC 0 xs]) + | (_,[x]) -> (concatD [prtProgSpec 0 x ; render ";"]) + | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render ";" ; prtProgSpecListBNFC 0 xs]) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ac58ab1c..3c4ef64c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -21,8 +21,8 @@ module.exports = grammar({ choice( // []. [Decl] ::= ; choice(), - // (:). [Decl] ::= Decl ";" [Decl] ; - seq($.Decl, ";", optional($.list_Decl)) + // (:). [Decl] ::= Decl [Decl] ; + seq($.Decl, optional($.list_Decl)) ), list_token_BlockIdent: $ => choice( @@ -56,22 +56,22 @@ module.exports = grammar({ ), Decl: $ => choice( - // Decl_Axiom. Decl ::= "axiom" GlobalIdent AttribSet Expr ; - seq("axiom", $.token_GlobalIdent, optional($.AttribSet), $.Expr), - // Decl_Mem. Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ; - seq("memory", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), - // Decl_Var. Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ; - seq("var", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), - // Decl_UninterpFun. Decl ::= "val" GlobalIdent AttribSet ":" Type ; - seq("val", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type), - // Decl_Fun. Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ; - seq("let", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, "=", $.Expr), - // Decl_FunNoType. Decl ::= "let" GlobalIdent AttribSet "=" Expr ; - seq("let", $.token_GlobalIdent, optional($.AttribSet), "=", $.Expr), - // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), + // Decl_Axiom. Decl ::= "axiom" GlobalIdent AttribSet Expr ";" ; + seq("axiom", $.token_GlobalIdent, optional($.AttribSet), $.Expr, ";"), + // Decl_Mem. Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ";" ; + seq("memory", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec), ";"), + // Decl_Var. Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ";" ; + seq("var", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec), ";"), + // Decl_UninterpFun. Decl ::= "val" GlobalIdent AttribSet ":" Type ";" ; + seq("val", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, ";"), + // Decl_Fun. Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";" ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, "=", $.Expr, ";"), + // Decl_FunNoType. Decl ::= "let" GlobalIdent AttribSet "=" Expr ";" ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), "=", $.Expr, ";"), + // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ";" ; + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), ";"), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), @@ -88,8 +88,8 @@ module.exports = grammar({ choice( // ProcDef_Empty. ProcDef ::= ; choice(), - // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ; - seq($.token_BeginList, optional($.list_Block), $.token_EndList) + // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ";" ; + seq($.token_BeginList, optional($.list_Block), $.token_EndList, ";") ), IntType: $ => // IntType1. IntType ::= INTTYPE ; @@ -689,15 +689,15 @@ module.exports = grammar({ choice( // []. [FunSpec] ::= ; choice(), - // (:). [FunSpec] ::= FunSpec [FunSpec] ; - seq($.FunSpec, optional($.list_FunSpec)) + // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; + seq($.FunSpec, ";", optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( - // []. [ProgSpec] ::= ; - choice(), - // (:). [ProgSpec] ::= ProgSpec [ProgSpec] ; - seq($.ProgSpec, optional($.list_ProgSpec)) + // (:[]). [ProgSpec] ::= ProgSpec ";" ; + seq($.ProgSpec, ";"), + // (:). [ProgSpec] ::= ProgSpec ";" [ProgSpec] ; + seq($.ProgSpec, ";", $.list_ProgSpec) ), token_BVTYPE: $ => /bv\d+/, From 717f8cf773188d2d331eb34c093b220abd20a596 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:18:18 +1000 Subject: [PATCH 30/43] fix semicolon terminated specs --- lib/fe/AbsBasilIR.ml | 9 ++++++-- lib/fe/BasilIR.cf | 10 +++++---- lib/fe/ParBasilIR.mly | 19 ++++++++++++----- lib/fe/PrintBasilIR.ml | 13 +++++++++--- lib/fe/ShowBasilIR.ml | 10 +++++++-- lib/fe/SkelBasilIR.ml | 10 +++++++-- lib/loadir.ml | 31 ++++++++++++++------------- test/cram/basicssa.t | 48 ++++++++++++------------------------------ test/cram/roundtrip.t | 35 ++++++++++++------------------ tree-sitter/grammar.js | 27 ++++++++++++++++-------- 10 files changed, 113 insertions(+), 99 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index a280c6cd..5b8eb676 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -37,11 +37,12 @@ and decl = | Decl_FunNoType of globalIdent * attribSet * expr | Decl_ProgEmpty of procIdent * attribSet | Decl_ProgWithSpec of procIdent * attribSet * progSpec list - | Decl_Proc of procIdent * openParen * params list * closeParen * openParen * params list * closeParen * attribSet * funSpec list * procDef + | Decl_Proc of procIdent * openParen * params list * closeParen * openParen * params list * closeParen * attribSet * procDef and procDef = ProcDef_Empty - | ProcDef_Some of beginList * block list * endList + | ProcDef_SpecOnly of funSpec list + | ProcDef_Some of optionalFunSpec * beginList * block list * endList and intType = IntType1 of iNTTYPE @@ -305,3 +306,7 @@ and progSpec = ProgSpec_Rely of relyTok * expr | ProgSpec_Guarantee of guarTok * expr +and optionalFunSpec = + OptionalFunSpec1 of funSpec list + | OptionalFunSpec2 + diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 54b558e7..b5fc84ce 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -57,10 +57,11 @@ Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";"; Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr ";"; Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ";"; Decl_ProgWithSpec . Decl ::= "prog" "entry" ProcIdent AttribSet [ ProgSpec ] ; -Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [ FunSpec ] ProcDef ; +Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet ProcDef ; -ProcDef_Empty . ProcDef ::= ; -- semicolon terminator in FunSpec -ProcDef_Some . ProcDef ::= BeginList [Block] EndList ";"; +ProcDef_Empty . ProcDef ::= ";"; +ProcDef_SpecOnly . ProcDef ::= [ FunSpec ]; -- FunSpec has terminator semicolon +ProcDef_Some . ProcDef ::= OptionalFunSpec BeginList [Block] EndList ";"; IntType1 . IntType ::= INTTYPE ; BoolType1. BoolType ::= BOOLTYPE ; @@ -282,7 +283,8 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= RelyTok Expr; ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; -terminator FunSpec ";"; +terminator nonempty FunSpec ";"; +rules OptionalFunSpec ::= [ FunSpec ] | ; {- last semicolon terminates the prog definitino -} terminator nonempty ProgSpec ";"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 379fc980..bc35fd2c 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pOptionalFunSpec pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -123,6 +123,7 @@ open Lexing %type pVarSpec %type pProgSpec %type pFunSpec_list +%type pOptionalFunSpec %type pProgSpec_list %type moduleT @@ -203,6 +204,7 @@ open Lexing %type varSpec %type progSpec %type funSpec_list +%type optionalFunSpec %type progSpec_list %type bVTYPE @@ -381,6 +383,8 @@ pProgSpec : progSpec TOK_EOF { $1 }; pFunSpec_list : funSpec_list TOK_EOF { $1 }; +pOptionalFunSpec : optionalFunSpec TOK_EOF { $1 }; + pProgSpec_list : progSpec_list TOK_EOF { $1 }; moduleT : decl_list { Module1 $1 } @@ -415,7 +419,7 @@ decl : KW_axiom globalIdent attribSet expr SYMB4 { Decl_Axiom ($2, $3, $4) } | KW_let globalIdent attribSet SYMB6 expr SYMB4 { Decl_FunNoType ($2, $3, $5) } | KW_prog KW_entry procIdent attribSet SYMB4 { Decl_ProgEmpty ($3, $4) } | KW_prog KW_entry procIdent attribSet progSpec_list { Decl_ProgWithSpec ($3, $4, $5) } - | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } + | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11) } ; typeT_list : /* empty */ { [] } @@ -423,8 +427,9 @@ typeT_list : /* empty */ { [] } | typeT SYMB1 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -procDef : /* empty */ { ProcDef_Empty } - | beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3) } +procDef : SYMB4 { ProcDef_Empty } + | funSpec_list { ProcDef_SpecOnly $1 } + | optionalFunSpec beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3, $4) } ; intType : iNTTYPE { IntType1 $1 } @@ -773,10 +778,14 @@ progSpec : relyTok expr { ProgSpec_Rely ($1, $2) } | guarTok expr { ProgSpec_Guarantee ($1, $2) } ; -funSpec_list : /* empty */ { [] } +funSpec_list : funSpec SYMB4 { (fun x -> [x]) $1 } | funSpec SYMB4 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; +optionalFunSpec : funSpec_list { OptionalFunSpec1 $1 } + | /* empty */ { OptionalFunSpec2 } + ; + progSpec_list : progSpec SYMB4 { (fun x -> [x]) $1 } | progSpec SYMB4 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index e9bd2cea..d6a02f57 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -161,14 +161,15 @@ and prtDecl (i:int) (e : AbsBasilIR.decl) : doc = match e with | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr ; render ";"]) | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; render ";"]) | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; prtProgSpecListBNFC 0 progspecs]) - | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, funspecs, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtFunSpecListBNFC 0 funspecs ; prtProcDef 0 procdef]) + | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtProcDef 0 procdef]) and prtDeclListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,x::xs) -> (concatD [prtDecl 0 x ; prtDeclListBNFC 0 xs]) and prtProcDef (i:int) (e : AbsBasilIR.procDef) : doc = match e with - AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) + AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD [render ";"]) + | AbsBasilIR.ProcDef_SpecOnly funspecs -> prPrec i 0 (concatD [prtFunSpecListBNFC 0 funspecs]) + | AbsBasilIR.ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtOptionalFunSpec 0 optionalfunspec ; prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) and prtIntType (i:int) (e : AbsBasilIR.intType) : doc = match e with @@ -523,6 +524,7 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtFunSpec 0 x ; render ";"]) | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) @@ -537,4 +539,9 @@ and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtProgSpec 0 x ; render ";"]) | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render ";" ; prtProgSpecListBNFC 0 xs]) +and prtOptionalFunSpec (i:int) (e : AbsBasilIR.optionalFunSpec) : doc = match e with + AbsBasilIR.OptionalFunSpec1 funspecs -> prPrec i 0 (concatD [prtFunSpecListBNFC 0 funspecs]) + | AbsBasilIR.OptionalFunSpec2 -> prPrec i 0 (concatD []) + + diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 633cd192..247cf1fd 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -79,12 +79,13 @@ and showDecl (e : AbsBasilIR.decl) : showable = match e with | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> s2s "Decl_FunNoType" >> c2s ' ' >> c2s '(' >> showGlobalIdent globalident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showExpr expr >> c2s ')' | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> s2s "Decl_ProgEmpty" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showAttribSet attribset >> c2s ')' | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> s2s "Decl_ProgWithSpec" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showList showProgSpec progspecs >> c2s ')' - | AbsBasilIR.Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, funspecs, procdef) -> s2s "Decl_Proc" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showOpenParen openparen0 >> s2s ", " >> showList showParams paramss1 >> s2s ", " >> showCloseParen closeparen2 >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showParams paramss >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showList showFunSpec funspecs >> s2s ", " >> showProcDef procdef >> c2s ')' + | AbsBasilIR.Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, procdef) -> s2s "Decl_Proc" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showOpenParen openparen0 >> s2s ", " >> showList showParams paramss1 >> s2s ", " >> showCloseParen closeparen2 >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showParams paramss >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showProcDef procdef >> c2s ')' and showProcDef (e : AbsBasilIR.procDef) : showable = match e with AbsBasilIR.ProcDef_Empty -> s2s "ProcDef_Empty" - | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> s2s "ProcDef_Some" >> c2s ' ' >> c2s '(' >> showBeginList beginlist >> s2s ", " >> showList showBlock blocks >> s2s ", " >> showEndList endlist >> c2s ')' + | AbsBasilIR.ProcDef_SpecOnly funspecs -> s2s "ProcDef_SpecOnly" >> c2s ' ' >> c2s '(' >> showList showFunSpec funspecs >> c2s ')' + | AbsBasilIR.ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> s2s "ProcDef_Some" >> c2s ' ' >> c2s '(' >> showOptionalFunSpec optionalfunspec >> s2s ", " >> showBeginList beginlist >> s2s ", " >> showList showBlock blocks >> s2s ", " >> showEndList endlist >> c2s ')' and showIntType (e : AbsBasilIR.intType) : showable = match e with @@ -398,4 +399,9 @@ and showProgSpec (e : AbsBasilIR.progSpec) : showable = match e with | AbsBasilIR.ProgSpec_Guarantee (guartok, expr) -> s2s "ProgSpec_Guarantee" >> c2s ' ' >> c2s '(' >> showGuarTok guartok >> s2s ", " >> showExpr expr >> c2s ')' +and showOptionalFunSpec (e : AbsBasilIR.optionalFunSpec) : showable = match e with + AbsBasilIR.OptionalFunSpec1 funspecs -> s2s "OptionalFunSpec1" >> c2s ' ' >> c2s '(' >> showList showFunSpec funspecs >> c2s ')' + | AbsBasilIR.OptionalFunSpec2 -> s2s "OptionalFunSpec2" + + diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 36fe688a..a49eca3a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -99,12 +99,13 @@ and transDecl (x : decl) : result = match x with | Decl_FunNoType (globalident, attribset, expr) -> failure x | Decl_ProgEmpty (procident, attribset) -> failure x | Decl_ProgWithSpec (procident, attribset, progspecs) -> failure x - | Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, funspecs, procdef) -> failure x + | Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, procdef) -> failure x and transProcDef (x : procDef) : result = match x with ProcDef_Empty -> failure x - | ProcDef_Some (beginlist, blocks, endlist) -> failure x + | ProcDef_SpecOnly funspecs -> failure x + | ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> failure x and transIntType (x : intType) : result = match x with @@ -418,5 +419,10 @@ and transProgSpec (x : progSpec) : result = match x with | ProgSpec_Guarantee (guartok, expr) -> failure x +and transOptionalFunSpec (x : optionalFunSpec) : result = match x with + OptionalFunSpec1 funspecs -> failure x + | OptionalFunSpec2 -> failure x + + end diff --git a/lib/loadir.ml b/lib/loadir.ml index 7c8dc9ff..3d02ac72 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -205,7 +205,6 @@ module BasilASTLoader = struct out_params, _, attrib, - spec, definition ) -> let proc_id = prog.prog.proc_names.decl_or_get id in let formal_in_params_order = List.map param_to_formal in_params in @@ -215,7 +214,10 @@ module BasilASTLoader = struct let attrib = trans_attrib_set prog ~binds:formal_in_params attrib in Hashtbl.add prog.params_order id (formal_in_params_order, formal_out_params_order); - let is_stub = Stdlib.(definition = ProcDef_Empty) in + (* TODO: spec is currently dropped from ProcDef_SpecOnly cases. this should get merged!! *) + let is_stub = match definition with + |ProcDef_Some _ -> false + | ProcDef_Empty | ProcDef_SpecOnly _ -> true in let p = Procedure.create proc_id ~attrib ~is_stub ~formal_in_params ~formal_out_params () @@ -323,8 +325,7 @@ module BasilASTLoader = struct out_params, _, attrs, - spec_list, - ProcDef_Some (bl, blocks, el) ) -> + ProcDef_Some (spec_list, BeginList _, blocks, EndList _) ) -> let proc_id = prog.prog.proc_names.decl_or_get id in let p = ID.Map.find proc_id prog.prog.procs in let prog = { prog with curr_proc = Some p } in @@ -358,6 +359,11 @@ module BasilASTLoader = struct Procedure.G.add_edge g Entry (Begin entry)) in + let spec_list = match spec_list with + | OptionalFunSpec1 xs -> xs + | OptionalFunSpec2 -> [] + in + let spec = Procedure.specification p in let spec = List.fold_left @@ -1270,8 +1276,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1298,8 +1303,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1328,8 +1332,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1347,7 +1350,7 @@ proc @f (ZF_in:bv1, VF_in:bv1) -> (); BasilIR.ShowBasilIR.showModuleT prog buf; Buffer.output_buffer stdout buf; [%expect - {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; + {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, ProcDef_Empty)]) |}]; let ast = ast_of_concrete_ast ~name:"boop" prog in print_endline @@ -1382,8 +1385,7 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect - {| + [%expect {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1444,8 +1446,7 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect - {| + [%expect {| @entry: read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) written: $R0:bv64,$mem:(bv64->bv8) diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index 5129885e..d5c6009c 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,6 +2,11 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp + bincaml: Error in (load-il after.il): Parse error: after.il:20 + 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] $ cat before.il var $CF:bv1; @@ -312,17 +317,8 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - 18,21c18,21 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) - [1] + diff: after_reparsed.il: No such file or directory + [2] The interpreter should give the same output for both @@ -333,32 +329,14 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt + diff: before_conds.txt: No such file or directory + diff: after_conds.txt: No such file or directory + [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - 1d0 - < var $R0:bv64; - 3c2 - < proc @main() -> () { } - --- - > proc @main(R0_in:bv64) -> (R0_out:bv64) { } - 7a7 - > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; - 9,12c9,17 - < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; - < block %e2 [ goto (%e4,%e1); ]; - < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - < block %e4 [ return; ] - --- - > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; - > block %e2 ( var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64) ) [ - > goto (%e4,%e1); - > ]; - > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - > block %e4 ( - > var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64) - > ) [ goto (%returns); ]; - > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] - [1] + diff: ssa-multi-before.il: No such file or directory + diff: ssa-multi-after.il: No such file or directory + [2] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index dc4a8888..8a95e837 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,35 +1,26 @@ $ bincaml script roundtrip.sexp + bincaml: Error in (load-il before.il): Parse error: before.il:17 + 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - 15,18c15,18 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) - 121c121 - < block %main_basil_return_1 [ nop; return; ] - --- - > block %main_basil_return_1 [ return; ] - [1] + diff: after.il: No such file or directory + [2] $ diff before2.il after2.il - 7,8c7,8 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8) - < captures $mem:(bv64->bv8), $stack:(bv64->bv8) - --- - > modifies $stack:(bv64->bv8), $mem:(bv64->bv8) - > captures $stack:(bv64->bv8), $mem:(bv64->bv8) - [1] + diff: before2.il: No such file or directory + diff: after2.il: No such file or directory + [2] Memassign repr $ diff beforemem.il aftermem.il + diff: beforemem.il: No such file or directory + diff: aftermem.il: No such file or directory + [2] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 3c4ef64c..ea422b35 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -72,8 +72,8 @@ module.exports = grammar({ seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), ";"), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), - // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; - seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) + // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet ProcDef ; + seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), $.ProcDef) ), list_Type: $ => choice( @@ -86,10 +86,12 @@ module.exports = grammar({ ), ProcDef: $ => choice( - // ProcDef_Empty. ProcDef ::= ; - choice(), - // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ";" ; - seq($.token_BeginList, optional($.list_Block), $.token_EndList, ";") + // ProcDef_Empty. ProcDef ::= ";" ; + ";", + // ProcDef_SpecOnly. ProcDef ::= [FunSpec] ; + $.list_FunSpec, + // ProcDef_Some. ProcDef ::= OptionalFunSpec BeginList [Block] EndList ";" ; + seq(optional($.OptionalFunSpec), $.token_BeginList, optional($.list_Block), $.token_EndList, ";") ), IntType: $ => // IntType1. IntType ::= INTTYPE ; @@ -687,10 +689,17 @@ module.exports = grammar({ ), list_FunSpec: $ => choice( - // []. [FunSpec] ::= ; - choice(), + // (:[]). [FunSpec] ::= FunSpec ";" ; + seq($.FunSpec, ";"), // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; - seq($.FunSpec, ";", optional($.list_FunSpec)) + seq($.FunSpec, ";", $.list_FunSpec) + ), + OptionalFunSpec: $ => + choice( + // OptionalFunSpec1. OptionalFunSpec ::= [FunSpec] ; + $.list_FunSpec, + // OptionalFunSpec2. OptionalFunSpec ::= ; + choice() ), list_ProgSpec: $ => choice( From 807424fedd5d7233514a72f069893da82cd18995 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:21:01 +1000 Subject: [PATCH 31/43] fix printing of semicolons --- lib/lang/procedure.ml | 10 ++++---- lib/loadir.ml | 4 ++-- test/cram/basicssa.t | 56 ++++++++++++++++++++++++++++++------------- test/cram/memassign.t | 4 ++-- test/cram/roundtrip.t | 35 +++++++++++++++++---------- 5 files changed, 70 insertions(+), 39 deletions(-) diff --git a/lib/lang/procedure.ml b/lib/lang/procedure.ml index c3f8c77e..777bd11c 100644 --- a/lib/lang/procedure.ml +++ b/lib/lang/procedure.ml @@ -496,7 +496,7 @@ let iter_blocks_topo_rev p = let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = let open Containers_pp in - let ml f v = if List.is_empty v then [] else [ f v ] in + let ml f v = if List.is_empty v then [] else [ f v ^ text ";" ] in nest 2 (newline ^ append_nl @@ -513,25 +513,25 @@ let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = @ ml (fun x -> append_l - ~sep:newline + ~sep:(text ";" ^ newline) (List.map (fun v -> text "requires " ^ show_expr v) x)) p.requires @ ml (fun x -> append_l - ~sep:newline + ~sep:(text ";" ^ newline) (List.map (fun v -> text "ensures " ^ show_expr v) x)) p.ensures @ ml (fun x -> append_l - ~sep:newline + ~sep:(text ";" ^ newline) (List.map (fun v -> text "rely " ^ show_expr v) x)) p.rely @ ml (fun x -> append_l - ~sep:newline + ~sep:(text ";" ^ newline) (List.map (fun v -> text "guarantee " ^ show_expr v) x)) p.guarantee)) diff --git a/lib/loadir.ml b/lib/loadir.ml index 3d02ac72..c2bf5238 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -1390,8 +1390,8 @@ proc @main_4196260 () -> () var $ZF:bv1; prog entry @main_4196260; proc @main_4196260() -> () { } - modifies $NF:bv1, $ZF:bv1 - captures $NF:bv1, $ZF:bv1 + modifies $NF:bv1, $ZF:bv1; + captures $NF:bv1, $ZF:bv1; [ block %main_entry [ diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index d5c6009c..e257a4de 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,11 +2,6 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il after.il): Parse error: after.il:20 - 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] $ cat before.il var $CF:bv1; @@ -24,9 +19,9 @@ Run on basic irreducible loop example proc @main_1876() -> () { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; [ block %main_entry [ @@ -154,9 +149,9 @@ Run on basic irreducible loop example R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; [ block %inputs [ @@ -317,8 +312,17 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - diff: after_reparsed.il: No such file or directory - [2] + 18,21c18,21 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + [1] The interpreter should give the same output for both @@ -329,14 +333,32 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt - diff: before_conds.txt: No such file or directory - diff: after_conds.txt: No such file or directory - [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - diff: ssa-multi-before.il: No such file or directory - diff: ssa-multi-after.il: No such file or directory - [2] + 1d0 + < var $R0:bv64; + 3c2 + < proc @main() -> () { } + --- + > proc @main(R0_in:bv64) -> (R0_out:bv64) { } + 7a7 + > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; + 9,12c9,17 + < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; + < block %e2 [ goto (%e4,%e1); ]; + < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + < block %e4 [ return; ] + --- + > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; + > block %e2 ( var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64) ) [ + > goto (%e4,%e1); + > ]; + > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + > block %e4 ( + > var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64) + > ) [ goto (%returns); ]; + > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] + [1] diff --git a/test/cram/memassign.t b/test/cram/memassign.t index 577261dc..120338e3 100644 --- a/test/cram/memassign.t +++ b/test/cram/memassign.t @@ -1,8 +1,8 @@ $ dune exec bincaml -- dump-il memassign.il --proc '@main_4196164' | grep Global --before-context 1 --after-context 1 .returnBlock = "main_return" } - modifies $Global_4325420_4325424:bv32 - captures $Global_4325420_4325424:bv32 + modifies $Global_4325420_4325424:bv32; + captures $Global_4325420_4325424:bv32; -- block %main_entry [ diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8a95e837..8f080cb0 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,26 +1,35 @@ $ bincaml script roundtrip.sexp - bincaml: Error in (load-il before.il): Parse error: before.il:17 - 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - diff: after.il: No such file or directory - [2] + 15,18c15,18 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); + 121c121 + < block %main_basil_return_1 [ nop; return; ] + --- + > block %main_basil_return_1 [ return; ] + [1] $ diff before2.il after2.il - diff: before2.il: No such file or directory - diff: after2.il: No such file or directory - [2] + 7,8c7,8 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8); + < captures $mem:(bv64->bv8), $stack:(bv64->bv8); + --- + > modifies $stack:(bv64->bv8), $mem:(bv64->bv8); + > captures $stack:(bv64->bv8), $mem:(bv64->bv8); + [1] Memassign repr $ diff beforemem.il aftermem.il - diff: beforemem.il: No such file or directory - diff: aftermem.il: No such file or directory - [2] From 987225fdf9a0d820a8a8071695c6b9c3f90fcd84 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:23:49 +1000 Subject: [PATCH 32/43] dune fmt???????? --- dune-project | 3 --- lib/loadir.ml | 32 ++++++++++++++++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/dune-project b/dune-project index 60ab08b3..64916cdc 100644 --- a/dune-project +++ b/dune-project @@ -8,9 +8,6 @@ (generate_opam_files true) -(formatting - (enabled_for dune)) - (source (github username/reponame)) diff --git a/lib/loadir.ml b/lib/loadir.ml index c2bf5238..39a43df8 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -215,9 +215,11 @@ module BasilASTLoader = struct Hashtbl.add prog.params_order id (formal_in_params_order, formal_out_params_order); (* TODO: spec is currently dropped from ProcDef_SpecOnly cases. this should get merged!! *) - let is_stub = match definition with - |ProcDef_Some _ -> false - | ProcDef_Empty | ProcDef_SpecOnly _ -> true in + let is_stub = + match definition with + | ProcDef_Some _ -> false + | ProcDef_Empty | ProcDef_SpecOnly _ -> true + in let p = Procedure.create proc_id ~attrib ~is_stub ~formal_in_params ~formal_out_params () @@ -359,10 +361,11 @@ module BasilASTLoader = struct Procedure.G.add_edge g Entry (Begin entry)) in - let spec_list = match spec_list with - | OptionalFunSpec1 xs -> xs - | OptionalFunSpec2 -> [] - in + let spec_list = + match spec_list with + | OptionalFunSpec1 xs -> xs + | OptionalFunSpec2 -> [] + in let spec = Procedure.specification p in let spec = @@ -1276,7 +1279,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1303,7 +1307,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1332,7 +1337,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1385,7 +1391,8 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect {| + [%expect + {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1446,7 +1453,8 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect {| + [%expect + {| @entry: read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) written: $R0:bv64,$mem:(bv64->bv8) From 3f394d37802abc91d0a201937ae58aeb9d36cbdf Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:55:05 +1000 Subject: [PATCH 33/43] Revert "dune fmt????????" This reverts commit 987225fdf9a0d820a8a8071695c6b9c3f90fcd84. --- dune-project | 3 +++ lib/loadir.ml | 32 ++++++++++++-------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/dune-project b/dune-project index 64916cdc..60ab08b3 100644 --- a/dune-project +++ b/dune-project @@ -8,6 +8,9 @@ (generate_opam_files true) +(formatting + (enabled_for dune)) + (source (github username/reponame)) diff --git a/lib/loadir.ml b/lib/loadir.ml index 39a43df8..c2bf5238 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -215,11 +215,9 @@ module BasilASTLoader = struct Hashtbl.add prog.params_order id (formal_in_params_order, formal_out_params_order); (* TODO: spec is currently dropped from ProcDef_SpecOnly cases. this should get merged!! *) - let is_stub = - match definition with - | ProcDef_Some _ -> false - | ProcDef_Empty | ProcDef_SpecOnly _ -> true - in + let is_stub = match definition with + |ProcDef_Some _ -> false + | ProcDef_Empty | ProcDef_SpecOnly _ -> true in let p = Procedure.create proc_id ~attrib ~is_stub ~formal_in_params ~formal_out_params () @@ -361,11 +359,10 @@ module BasilASTLoader = struct Procedure.G.add_edge g Entry (Begin entry)) in - let spec_list = - match spec_list with - | OptionalFunSpec1 xs -> xs - | OptionalFunSpec2 -> [] - in + let spec_list = match spec_list with + | OptionalFunSpec1 xs -> xs + | OptionalFunSpec2 -> [] + in let spec = Procedure.specification p in let spec = @@ -1279,8 +1276,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1307,8 +1303,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1337,8 +1332,7 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn - {| +[@@expect.uncaught_exn {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1391,8 +1385,7 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect - {| + [%expect {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1453,8 +1446,7 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect - {| + [%expect {| @entry: read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) written: $R0:bv64,$mem:(bv64->bv8) From b8bdb31b24ea30bbbaf98ec779d695a3c391e1a4 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:55:07 +1000 Subject: [PATCH 34/43] Revert "fix printing of semicolons" This reverts commit 807424fedd5d7233514a72f069893da82cd18995. --- lib/lang/procedure.ml | 10 ++++---- lib/loadir.ml | 4 ++-- test/cram/basicssa.t | 56 +++++++++++++------------------------------ test/cram/memassign.t | 4 ++-- test/cram/roundtrip.t | 35 ++++++++++----------------- 5 files changed, 39 insertions(+), 70 deletions(-) diff --git a/lib/lang/procedure.ml b/lib/lang/procedure.ml index 777bd11c..c3f8c77e 100644 --- a/lib/lang/procedure.ml +++ b/lib/lang/procedure.ml @@ -496,7 +496,7 @@ let iter_blocks_topo_rev p = let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = let open Containers_pp in - let ml f v = if List.is_empty v then [] else [ f v ^ text ";" ] in + let ml f v = if List.is_empty v then [] else [ f v ] in nest 2 (newline ^ append_nl @@ -513,25 +513,25 @@ let pretty_spec show_var show_expr (p : ('a, 'b) proc_spec) = @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "requires " ^ show_expr v) x)) p.requires @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "ensures " ^ show_expr v) x)) p.ensures @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "rely " ^ show_expr v) x)) p.rely @ ml (fun x -> append_l - ~sep:(text ";" ^ newline) + ~sep:newline (List.map (fun v -> text "guarantee " ^ show_expr v) x)) p.guarantee)) diff --git a/lib/loadir.ml b/lib/loadir.ml index c2bf5238..3d02ac72 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -1390,8 +1390,8 @@ proc @main_4196260 () -> () var $ZF:bv1; prog entry @main_4196260; proc @main_4196260() -> () { } - modifies $NF:bv1, $ZF:bv1; - captures $NF:bv1, $ZF:bv1; + modifies $NF:bv1, $ZF:bv1 + captures $NF:bv1, $ZF:bv1 [ block %main_entry [ diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index e257a4de..d5c6009c 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,6 +2,11 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp + bincaml: Error in (load-il after.il): Parse error: after.il:20 + 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] $ cat before.il var $CF:bv1; @@ -19,9 +24,9 @@ Run on basic irreducible loop example proc @main_1876() -> () { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 [ block %main_entry [ @@ -149,9 +154,9 @@ Run on basic irreducible loop example R30_out:bv64, R31_out:bv64, VF_out:bv1, ZF_out:bv1) { .address = 1876; .name = "main"; .returnBlock = "main_basil_return_1" } modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; + $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 [ block %inputs [ @@ -312,17 +317,8 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - 18,21c18,21 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - [1] + diff: after_reparsed.il: No such file or directory + [2] The interpreter should give the same output for both @@ -333,32 +329,14 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt + diff: before_conds.txt: No such file or directory + diff: after_conds.txt: No such file or directory + [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - 1d0 - < var $R0:bv64; - 3c2 - < proc @main() -> () { } - --- - > proc @main(R0_in:bv64) -> (R0_out:bv64) { } - 7a7 - > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; - 9,12c9,17 - < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; - < block %e2 [ goto (%e4,%e1); ]; - < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - < block %e4 [ return; ] - --- - > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; - > block %e2 ( var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64) ) [ - > goto (%e4,%e1); - > ]; - > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; - > block %e4 ( - > var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64) - > ) [ goto (%returns); ]; - > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] - [1] + diff: ssa-multi-before.il: No such file or directory + diff: ssa-multi-after.il: No such file or directory + [2] diff --git a/test/cram/memassign.t b/test/cram/memassign.t index 120338e3..577261dc 100644 --- a/test/cram/memassign.t +++ b/test/cram/memassign.t @@ -1,8 +1,8 @@ $ dune exec bincaml -- dump-il memassign.il --proc '@main_4196164' | grep Global --before-context 1 --after-context 1 .returnBlock = "main_return" } - modifies $Global_4325420_4325424:bv32; - captures $Global_4325420_4325424:bv32; + modifies $Global_4325420_4325424:bv32 + captures $Global_4325420_4325424:bv32 -- block %main_entry [ diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8f080cb0..8a95e837 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,35 +1,26 @@ $ bincaml script roundtrip.sexp + bincaml: Error in (load-il before.il): Parse error: before.il:17 + 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + ^^^^^^^^ + at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 + [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - 15,18c15,18 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1; - --- - > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, - > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8); - 121c121 - < block %main_basil_return_1 [ nop; return; ] - --- - > block %main_basil_return_1 [ return; ] - [1] + diff: after.il: No such file or directory + [2] $ diff before2.il after2.il - 7,8c7,8 - < modifies $mem:(bv64->bv8), $stack:(bv64->bv8); - < captures $mem:(bv64->bv8), $stack:(bv64->bv8); - --- - > modifies $stack:(bv64->bv8), $mem:(bv64->bv8); - > captures $stack:(bv64->bv8), $mem:(bv64->bv8); - [1] + diff: before2.il: No such file or directory + diff: after2.il: No such file or directory + [2] Memassign repr $ diff beforemem.il aftermem.il + diff: beforemem.il: No such file or directory + diff: aftermem.il: No such file or directory + [2] From d851411d921cb3ca485f48fd51bc6e88a71aa914 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:55:08 +1000 Subject: [PATCH 35/43] Revert "fix semicolon terminated specs" This reverts commit 717f8cf773188d2d331eb34c093b220abd20a596. --- lib/fe/AbsBasilIR.ml | 9 ++------ lib/fe/BasilIR.cf | 10 ++++----- lib/fe/ParBasilIR.mly | 19 +++++------------ lib/fe/PrintBasilIR.ml | 13 +++--------- lib/fe/ShowBasilIR.ml | 10 ++------- lib/fe/SkelBasilIR.ml | 10 ++------- lib/loadir.ml | 31 +++++++++++++-------------- test/cram/basicssa.t | 48 ++++++++++++++++++++++++++++++------------ test/cram/roundtrip.t | 35 ++++++++++++++++++------------ tree-sitter/grammar.js | 27 ++++++++---------------- 10 files changed, 99 insertions(+), 113 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 5b8eb676..a280c6cd 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -37,12 +37,11 @@ and decl = | Decl_FunNoType of globalIdent * attribSet * expr | Decl_ProgEmpty of procIdent * attribSet | Decl_ProgWithSpec of procIdent * attribSet * progSpec list - | Decl_Proc of procIdent * openParen * params list * closeParen * openParen * params list * closeParen * attribSet * procDef + | Decl_Proc of procIdent * openParen * params list * closeParen * openParen * params list * closeParen * attribSet * funSpec list * procDef and procDef = ProcDef_Empty - | ProcDef_SpecOnly of funSpec list - | ProcDef_Some of optionalFunSpec * beginList * block list * endList + | ProcDef_Some of beginList * block list * endList and intType = IntType1 of iNTTYPE @@ -306,7 +305,3 @@ and progSpec = ProgSpec_Rely of relyTok * expr | ProgSpec_Guarantee of guarTok * expr -and optionalFunSpec = - OptionalFunSpec1 of funSpec list - | OptionalFunSpec2 - diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index b5fc84ce..54b558e7 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -57,11 +57,10 @@ Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";"; Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr ";"; Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ";"; Decl_ProgWithSpec . Decl ::= "prog" "entry" ProcIdent AttribSet [ ProgSpec ] ; -Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet ProcDef ; +Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [ FunSpec ] ProcDef ; -ProcDef_Empty . ProcDef ::= ";"; -ProcDef_SpecOnly . ProcDef ::= [ FunSpec ]; -- FunSpec has terminator semicolon -ProcDef_Some . ProcDef ::= OptionalFunSpec BeginList [Block] EndList ";"; +ProcDef_Empty . ProcDef ::= ; -- semicolon terminator in FunSpec +ProcDef_Some . ProcDef ::= BeginList [Block] EndList ";"; IntType1 . IntType ::= INTTYPE ; BoolType1. BoolType ::= BOOLTYPE ; @@ -283,8 +282,7 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= RelyTok Expr; ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; -terminator nonempty FunSpec ";"; -rules OptionalFunSpec ::= [ FunSpec ] | ; +terminator FunSpec ";"; {- last semicolon terminates the prog definitino -} terminator nonempty ProgSpec ";"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index bc35fd2c..379fc980 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pOptionalFunSpec pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -123,7 +123,6 @@ open Lexing %type pVarSpec %type pProgSpec %type pFunSpec_list -%type pOptionalFunSpec %type pProgSpec_list %type moduleT @@ -204,7 +203,6 @@ open Lexing %type varSpec %type progSpec %type funSpec_list -%type optionalFunSpec %type progSpec_list %type bVTYPE @@ -383,8 +381,6 @@ pProgSpec : progSpec TOK_EOF { $1 }; pFunSpec_list : funSpec_list TOK_EOF { $1 }; -pOptionalFunSpec : optionalFunSpec TOK_EOF { $1 }; - pProgSpec_list : progSpec_list TOK_EOF { $1 }; moduleT : decl_list { Module1 $1 } @@ -419,7 +415,7 @@ decl : KW_axiom globalIdent attribSet expr SYMB4 { Decl_Axiom ($2, $3, $4) } | KW_let globalIdent attribSet SYMB6 expr SYMB4 { Decl_FunNoType ($2, $3, $5) } | KW_prog KW_entry procIdent attribSet SYMB4 { Decl_ProgEmpty ($3, $4) } | KW_prog KW_entry procIdent attribSet progSpec_list { Decl_ProgWithSpec ($3, $4, $5) } - | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11) } + | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } ; typeT_list : /* empty */ { [] } @@ -427,9 +423,8 @@ typeT_list : /* empty */ { [] } | typeT SYMB1 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -procDef : SYMB4 { ProcDef_Empty } - | funSpec_list { ProcDef_SpecOnly $1 } - | optionalFunSpec beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3, $4) } +procDef : /* empty */ { ProcDef_Empty } + | beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3) } ; intType : iNTTYPE { IntType1 $1 } @@ -778,14 +773,10 @@ progSpec : relyTok expr { ProgSpec_Rely ($1, $2) } | guarTok expr { ProgSpec_Guarantee ($1, $2) } ; -funSpec_list : funSpec SYMB4 { (fun x -> [x]) $1 } +funSpec_list : /* empty */ { [] } | funSpec SYMB4 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -optionalFunSpec : funSpec_list { OptionalFunSpec1 $1 } - | /* empty */ { OptionalFunSpec2 } - ; - progSpec_list : progSpec SYMB4 { (fun x -> [x]) $1 } | progSpec SYMB4 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index d6a02f57..e9bd2cea 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -161,15 +161,14 @@ and prtDecl (i:int) (e : AbsBasilIR.decl) : doc = match e with | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr ; render ";"]) | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; render ";"]) | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; prtProgSpecListBNFC 0 progspecs]) - | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtProcDef 0 procdef]) + | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, funspecs, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtFunSpecListBNFC 0 funspecs ; prtProcDef 0 procdef]) and prtDeclListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,x::xs) -> (concatD [prtDecl 0 x ; prtDeclListBNFC 0 xs]) and prtProcDef (i:int) (e : AbsBasilIR.procDef) : doc = match e with - AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD [render ";"]) - | AbsBasilIR.ProcDef_SpecOnly funspecs -> prPrec i 0 (concatD [prtFunSpecListBNFC 0 funspecs]) - | AbsBasilIR.ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtOptionalFunSpec 0 optionalfunspec ; prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) + AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD []) + | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) and prtIntType (i:int) (e : AbsBasilIR.intType) : doc = match e with @@ -524,7 +523,6 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtFunSpec 0 x ; render ";"]) | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) @@ -539,9 +537,4 @@ and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtProgSpec 0 x ; render ";"]) | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render ";" ; prtProgSpecListBNFC 0 xs]) -and prtOptionalFunSpec (i:int) (e : AbsBasilIR.optionalFunSpec) : doc = match e with - AbsBasilIR.OptionalFunSpec1 funspecs -> prPrec i 0 (concatD [prtFunSpecListBNFC 0 funspecs]) - | AbsBasilIR.OptionalFunSpec2 -> prPrec i 0 (concatD []) - - diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 247cf1fd..633cd192 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -79,13 +79,12 @@ and showDecl (e : AbsBasilIR.decl) : showable = match e with | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> s2s "Decl_FunNoType" >> c2s ' ' >> c2s '(' >> showGlobalIdent globalident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showExpr expr >> c2s ')' | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> s2s "Decl_ProgEmpty" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showAttribSet attribset >> c2s ')' | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> s2s "Decl_ProgWithSpec" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showList showProgSpec progspecs >> c2s ')' - | AbsBasilIR.Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, procdef) -> s2s "Decl_Proc" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showOpenParen openparen0 >> s2s ", " >> showList showParams paramss1 >> s2s ", " >> showCloseParen closeparen2 >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showParams paramss >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showProcDef procdef >> c2s ')' + | AbsBasilIR.Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, funspecs, procdef) -> s2s "Decl_Proc" >> c2s ' ' >> c2s '(' >> showProcIdent procident >> s2s ", " >> showOpenParen openparen0 >> s2s ", " >> showList showParams paramss1 >> s2s ", " >> showCloseParen closeparen2 >> s2s ", " >> showOpenParen openparen >> s2s ", " >> showList showParams paramss >> s2s ", " >> showCloseParen closeparen >> s2s ", " >> showAttribSet attribset >> s2s ", " >> showList showFunSpec funspecs >> s2s ", " >> showProcDef procdef >> c2s ')' and showProcDef (e : AbsBasilIR.procDef) : showable = match e with AbsBasilIR.ProcDef_Empty -> s2s "ProcDef_Empty" - | AbsBasilIR.ProcDef_SpecOnly funspecs -> s2s "ProcDef_SpecOnly" >> c2s ' ' >> c2s '(' >> showList showFunSpec funspecs >> c2s ')' - | AbsBasilIR.ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> s2s "ProcDef_Some" >> c2s ' ' >> c2s '(' >> showOptionalFunSpec optionalfunspec >> s2s ", " >> showBeginList beginlist >> s2s ", " >> showList showBlock blocks >> s2s ", " >> showEndList endlist >> c2s ')' + | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> s2s "ProcDef_Some" >> c2s ' ' >> c2s '(' >> showBeginList beginlist >> s2s ", " >> showList showBlock blocks >> s2s ", " >> showEndList endlist >> c2s ')' and showIntType (e : AbsBasilIR.intType) : showable = match e with @@ -399,9 +398,4 @@ and showProgSpec (e : AbsBasilIR.progSpec) : showable = match e with | AbsBasilIR.ProgSpec_Guarantee (guartok, expr) -> s2s "ProgSpec_Guarantee" >> c2s ' ' >> c2s '(' >> showGuarTok guartok >> s2s ", " >> showExpr expr >> c2s ')' -and showOptionalFunSpec (e : AbsBasilIR.optionalFunSpec) : showable = match e with - AbsBasilIR.OptionalFunSpec1 funspecs -> s2s "OptionalFunSpec1" >> c2s ' ' >> c2s '(' >> showList showFunSpec funspecs >> c2s ')' - | AbsBasilIR.OptionalFunSpec2 -> s2s "OptionalFunSpec2" - - diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index a49eca3a..36fe688a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -99,13 +99,12 @@ and transDecl (x : decl) : result = match x with | Decl_FunNoType (globalident, attribset, expr) -> failure x | Decl_ProgEmpty (procident, attribset) -> failure x | Decl_ProgWithSpec (procident, attribset, progspecs) -> failure x - | Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, procdef) -> failure x + | Decl_Proc (procident, openparen0, paramss1, closeparen2, openparen, paramss, closeparen, attribset, funspecs, procdef) -> failure x and transProcDef (x : procDef) : result = match x with ProcDef_Empty -> failure x - | ProcDef_SpecOnly funspecs -> failure x - | ProcDef_Some (optionalfunspec, beginlist, blocks, endlist) -> failure x + | ProcDef_Some (beginlist, blocks, endlist) -> failure x and transIntType (x : intType) : result = match x with @@ -419,10 +418,5 @@ and transProgSpec (x : progSpec) : result = match x with | ProgSpec_Guarantee (guartok, expr) -> failure x -and transOptionalFunSpec (x : optionalFunSpec) : result = match x with - OptionalFunSpec1 funspecs -> failure x - | OptionalFunSpec2 -> failure x - - end diff --git a/lib/loadir.ml b/lib/loadir.ml index 3d02ac72..7c8dc9ff 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -205,6 +205,7 @@ module BasilASTLoader = struct out_params, _, attrib, + spec, definition ) -> let proc_id = prog.prog.proc_names.decl_or_get id in let formal_in_params_order = List.map param_to_formal in_params in @@ -214,10 +215,7 @@ module BasilASTLoader = struct let attrib = trans_attrib_set prog ~binds:formal_in_params attrib in Hashtbl.add prog.params_order id (formal_in_params_order, formal_out_params_order); - (* TODO: spec is currently dropped from ProcDef_SpecOnly cases. this should get merged!! *) - let is_stub = match definition with - |ProcDef_Some _ -> false - | ProcDef_Empty | ProcDef_SpecOnly _ -> true in + let is_stub = Stdlib.(definition = ProcDef_Empty) in let p = Procedure.create proc_id ~attrib ~is_stub ~formal_in_params ~formal_out_params () @@ -325,7 +323,8 @@ module BasilASTLoader = struct out_params, _, attrs, - ProcDef_Some (spec_list, BeginList _, blocks, EndList _) ) -> + spec_list, + ProcDef_Some (bl, blocks, el) ) -> let proc_id = prog.prog.proc_names.decl_or_get id in let p = ID.Map.find proc_id prog.prog.procs in let prog = { prog with curr_proc = Some p } in @@ -359,11 +358,6 @@ module BasilASTLoader = struct Procedure.G.add_edge g Entry (Begin entry)) in - let spec_list = match spec_list with - | OptionalFunSpec1 xs -> xs - | OptionalFunSpec2 -> [] - in - let spec = Procedure.specification p in let spec = List.fold_left @@ -1276,7 +1270,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such block: %main_7\ \n12 | goto(%main_7, %main_11);\ \n \027[1;31m^^^^^^^\027[0m\ @@ -1303,7 +1298,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Error: no such procedure: @cat_4198032\ \n7 | call @cat_4198032();\ \n \027[1;31m^^^^^^^^^^^^\027[0m\ @@ -1332,7 +1328,8 @@ proc @main_4196260 () -> () in ignore @@ disable_backtrace_in run; [%expect.unreachable] -[@@expect.uncaught_exn {| +[@@expect.uncaught_exn + {| ( "Parse error: :8\ \n8 | :bv1 := 1:bv1;\ \n \027[1;31m^\027[0m\ @@ -1350,7 +1347,7 @@ proc @f (ZF_in:bv1, VF_in:bv1) -> (); BasilIR.ShowBasilIR.showModuleT prog buf; Buffer.output_buffer stdout buf; [%expect - {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, ProcDef_Empty)]) |}]; + {| Module1 ([Decl_ProgEmpty (ProcIdent "@f", AttribSet_Empty); Decl_Proc (ProcIdent "@f", OpenParen "(", [Params1 (LocalIdent "ZF_in", TypeBVType (BVType1 (BVTYPE "bv1"))); Params1 (LocalIdent "VF_in", TypeBVType (BVType1 (BVTYPE "bv1")))], CloseParen ")", OpenParen "(", [], CloseParen ")", AttribSet_Empty, [], ProcDef_Empty)]) |}]; let ast = ast_of_concrete_ast ~name:"boop" prog in print_endline @@ -1385,7 +1382,8 @@ proc @main_4196260 () -> () in Program.pretty_to_chan stdout p.prog; (); - [%expect {| + [%expect + {| var $NF:bv1; var $ZF:bv1; prog entry @main_4196260; @@ -1446,7 +1444,8 @@ proc @c() -> () (fun pid proc -> print_endline (ID.to_string pid ^ ":\n" ^ (res pid |> RWSets.to_string))) prog.prog.procs; - [%expect {| + [%expect + {| @entry: read: $R0:bv64,$R1:bv64,$mem:(bv64->bv8) written: $R0:bv64,$mem:(bv64->bv8) diff --git a/test/cram/basicssa.t b/test/cram/basicssa.t index d5c6009c..5129885e 100644 --- a/test/cram/basicssa.t +++ b/test/cram/basicssa.t @@ -2,11 +2,6 @@ Run on basic irreducible loop example $ bincaml script basicssa.sexp - bincaml: Error in (load-il after.il): Parse error: after.il:20 - 20 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] $ cat before.il var $CF:bv1; @@ -317,8 +312,17 @@ Run on basic irreducible loop example ; $ diff after.il after_reparsed.il - diff: after_reparsed.il: No such file or directory - [2] + 18,21c18,21 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) + [1] The interpreter should give the same output for both @@ -329,14 +333,32 @@ The interpreter should give the same output for both Similar example fixing up a file already in DSA form $ diff before_conds.txt after_conds.txt - diff: before_conds.txt: No such file or directory - diff: after_conds.txt: No such file or directory - [2] Multiple loops dependencies of loops etc are handled correctly $ diff ssa-multi-before.il ssa-multi-after.il - diff: ssa-multi-before.il: No such file or directory - diff: ssa-multi-after.il: No such file or directory - [2] + 1d0 + < var $R0:bv64; + 3c2 + < proc @main() -> () { } + --- + > proc @main(R0_in:bv64) -> (R0_out:bv64) { } + 7a7 + > block %inputs [ var R0:bv64 := R0_in:bv64; goto (%e); ]; + 9,12c9,17 + < block %e1 [ $R0:bv64 := 0x1:bv64; goto (%e2); ]; + < block %e2 [ goto (%e4,%e1); ]; + < block %e3 [ $R0:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + < block %e4 [ return; ] + --- + > block %e1 [ var R0_2:bv64 := 0x1:bv64; goto (%e2); ]; + > block %e2 ( var R0_3:bv64 := phi(%e1 -> R0_2:bv64, %e -> R0:bv64) ) [ + > goto (%e4,%e1); + > ]; + > block %e3 [ var R0_1:bv64 := 0x3:bv64; goto (%e4,%e1); ]; + > block %e4 ( + > var R0_4:bv64 := phi(%e2 -> R0_3:bv64, %e3 -> R0_1:bv64, %e2 -> R0_3:bv64) + > ) [ goto (%returns); ]; + > block %returns [ var R0_out:bv64 := R0_4:bv64; return; ] + [1] diff --git a/test/cram/roundtrip.t b/test/cram/roundtrip.t index 8a95e837..dc4a8888 100644 --- a/test/cram/roundtrip.t +++ b/test/cram/roundtrip.t @@ -1,26 +1,35 @@ $ bincaml script roundtrip.sexp - bincaml: Error in (load-il before.il): Parse error: before.il:17 - 17 | captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, - ^^^^^^^^ - at Dune__exe__Script.of_cmd.(fun) bin/script.ml:64 - [123] The serialise -> parse serialise loop should be idempotent $ diff before.il after.il - diff: after.il: No such file or directory - [2] + 15,18c15,18 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + < captures $mem:(bv64->bv8), $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, + < $R1:bv64, $R29:bv64, $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1 + --- + > modifies $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) + > captures $stack:(bv64->bv8), $CF:bv1, $NF:bv1, $R0:bv64, $R1:bv64, $R29:bv64, + > $R30:bv64, $R31:bv64, $VF:bv1, $ZF:bv1, $mem:(bv64->bv8) + 121c121 + < block %main_basil_return_1 [ nop; return; ] + --- + > block %main_basil_return_1 [ return; ] + [1] $ diff before2.il after2.il - diff: before2.il: No such file or directory - diff: after2.il: No such file or directory - [2] + 7,8c7,8 + < modifies $mem:(bv64->bv8), $stack:(bv64->bv8) + < captures $mem:(bv64->bv8), $stack:(bv64->bv8) + --- + > modifies $stack:(bv64->bv8), $mem:(bv64->bv8) + > captures $stack:(bv64->bv8), $mem:(bv64->bv8) + [1] Memassign repr $ diff beforemem.il aftermem.il - diff: beforemem.il: No such file or directory - diff: aftermem.il: No such file or directory - [2] diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ea422b35..3c4ef64c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -72,8 +72,8 @@ module.exports = grammar({ seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), ";"), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), - // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet ProcDef ; - seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), $.ProcDef) + // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; + seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), list_Type: $ => choice( @@ -86,12 +86,10 @@ module.exports = grammar({ ), ProcDef: $ => choice( - // ProcDef_Empty. ProcDef ::= ";" ; - ";", - // ProcDef_SpecOnly. ProcDef ::= [FunSpec] ; - $.list_FunSpec, - // ProcDef_Some. ProcDef ::= OptionalFunSpec BeginList [Block] EndList ";" ; - seq(optional($.OptionalFunSpec), $.token_BeginList, optional($.list_Block), $.token_EndList, ";") + // ProcDef_Empty. ProcDef ::= ; + choice(), + // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ";" ; + seq($.token_BeginList, optional($.list_Block), $.token_EndList, ";") ), IntType: $ => // IntType1. IntType ::= INTTYPE ; @@ -689,17 +687,10 @@ module.exports = grammar({ ), list_FunSpec: $ => choice( - // (:[]). [FunSpec] ::= FunSpec ";" ; - seq($.FunSpec, ";"), + // []. [FunSpec] ::= ; + choice(), // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; - seq($.FunSpec, ";", $.list_FunSpec) - ), - OptionalFunSpec: $ => - choice( - // OptionalFunSpec1. OptionalFunSpec ::= [FunSpec] ; - $.list_FunSpec, - // OptionalFunSpec2. OptionalFunSpec ::= ; - choice() + seq($.FunSpec, ";", optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( From c47febc1648cd973bbe89b33fb745776bdaf104d Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:55:08 +1000 Subject: [PATCH 36/43] Revert "restore semicolon-terminated specs" This reverts commit b44a2b02cb2740dd20c9b9c3a05bd5aced428fac. --- lib/fe/BasilIR.cf | 24 +++++------ lib/fe/LexBasilIR.mll | 4 +- lib/fe/ParBasilIR.mly | 96 +++++++++++++++++++++--------------------- lib/fe/PrintBasilIR.ml | 25 +++++------ tree-sitter/grammar.js | 50 +++++++++++----------- 5 files changed, 100 insertions(+), 99 deletions(-) diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 54b558e7..d5670f7e 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -1,6 +1,6 @@ rules Module ::= [Decl] ; -terminator Decl ""; +terminator Decl ";"; {- TOKENS -} @@ -45,22 +45,22 @@ Shared . VarModifiers ::= "shared" ; Observable . VarModifiers ::= "observable"; separator VarModifiers "" ; -Decl_Axiom . Decl ::= "axiom" GlobalIdent AttribSet Expr ";"; -Decl_Mem . Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ";"; -Decl_Var . Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ";"; +Decl_Axiom . Decl ::= "axiom" GlobalIdent AttribSet Expr; +Decl_Mem . Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ; +Decl_Var . Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ; separator Type ","; -Decl_UninterpFun . Decl ::= "val" GlobalIdent AttribSet ":" Type ";"; +Decl_UninterpFun . Decl ::= "val" GlobalIdent AttribSet ":" Type ; -Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";"; -Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr ";"; -Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ";"; +Decl_Fun . Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr; +Decl_FunNoType . Decl ::= "let" GlobalIdent AttribSet "=" Expr; +Decl_ProgEmpty . Decl ::= "prog" "entry" ProcIdent AttribSet ; Decl_ProgWithSpec . Decl ::= "prog" "entry" ProcIdent AttribSet [ ProgSpec ] ; Decl_Proc . Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [ FunSpec ] ProcDef ; -ProcDef_Empty . ProcDef ::= ; -- semicolon terminator in FunSpec -ProcDef_Some . ProcDef ::= BeginList [Block] EndList ";"; +ProcDef_Empty . ProcDef ::= ; +ProcDef_Some . ProcDef ::= BeginList [Block] EndList ; IntType1 . IntType ::= INTTYPE ; BoolType1. BoolType ::= BOOLTYPE ; @@ -282,10 +282,10 @@ FunSpec_Invariant . FunSpec ::= "invariant" BlockIdent Expr; ProgSpec_Rely . ProgSpec ::= RelyTok Expr; ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; -terminator FunSpec ";"; +terminator FunSpec "\n"; {- last semicolon terminates the prog definitino -} -terminator nonempty ProgSpec ";"; +terminator ProgSpec "\n"; diff --git a/lib/fe/LexBasilIR.mll b/lib/fe/LexBasilIR.mll index 9169fe4e..879eb028 100644 --- a/lib/fe/LexBasilIR.mll +++ b/lib/fe/LexBasilIR.mll @@ -9,7 +9,7 @@ open Lexing let symbol_table = Hashtbl.create 10 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add symbol_table kwd tok) - [(",", SYMB1);("->", SYMB2);("::", SYMB3);(";", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] + [(";", SYMB1);(",", SYMB2);("->", SYMB3);("::", SYMB4);(":", SYMB5);("=", SYMB6);(":=", SYMB7);("mem:=", SYMB8);("_", SYMB9);("|", SYMB10)] let resword_table = Hashtbl.create 98 let _ = List.iter (fun (kwd, tok) -> Hashtbl.add resword_table kwd tok) @@ -53,7 +53,7 @@ let _idchar = _letter | _digit | ['_' '\''] (* identifier character *) let _universal = _ (* universal: any character *) (* reserved words consisting of special symbols *) -let rsyms = "," | "->" | "::" | ";" | ":" | "=" | ":=" | "mem:=" | "_" | "|" +let rsyms = ";" | "," | "->" | "::" | ":" | "=" | ":=" | "mem:=" | "_" | "|" (* user-defined token types *) let bVTYPE = "bv" _digit + diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 379fc980..dd887b98 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -9,10 +9,10 @@ open Lexing %token KW_shared KW_observable KW_axiom KW_memory KW_var KW_val KW_let KW_prog KW_entry KW_proc KW_le KW_be KW_nop KW_store KW_load KW_call KW_indirect KW_assume KW_guard KW_assert KW_goto KW_unreachable KW_return KW_phi KW_block KW_true KW_false KW_forall KW_exists KW_fun KW_old KW_boolnot KW_intneg KW_booltobv1 KW_gamma KW_classification KW_load_be KW_load_le KW_zero_extend KW_sign_extend KW_extract KW_bvconcat KW_match KW_with KW_cases KW_eq KW_neq KW_bvnot KW_bvneg KW_bvand KW_bvor KW_bvadd KW_bvmul KW_bvudiv KW_bvurem KW_bvshl KW_bvlshr KW_bvnand KW_bvnor KW_bvxor KW_bvxnor KW_bvcomp KW_bvsub KW_bvsdiv KW_bvsrem KW_bvsmod KW_bvashr KW_bvule KW_bvugt KW_bvuge KW_bvult KW_bvslt KW_bvsle KW_bvsgt KW_bvsge KW_intadd KW_intmul KW_intsub KW_intdiv KW_intmod KW_intlt KW_intle KW_intgt KW_intge KW_booland KW_boolor KW_boolimplies KW_require KW_requires KW_ensure KW_ensures KW_rely KW_relies KW_guarantee KW_guarantees KW_captures KW_modifies KW_invariant -%token SYMB1 /* , */ -%token SYMB2 /* -> */ -%token SYMB3 /* :: */ -%token SYMB4 /* ; */ +%token SYMB1 /* ; */ +%token SYMB2 /* , */ +%token SYMB3 /* -> */ +%token SYMB4 /* :: */ %token SYMB5 /* : */ %token SYMB6 /* = */ %token SYMB7 /* := */ @@ -387,16 +387,16 @@ moduleT : decl_list { Module1 $1 } ; decl_list : /* empty */ { [] } - | decl decl_list { (fun (x,xs) -> x::xs) ($1, $2) } + | decl SYMB1 decl_list { (fun (x,xs) -> x::xs) ($1, $3) } ; blockIdent_list : /* empty */ { [] } | blockIdent { (fun x -> [x]) $1 } - | blockIdent SYMB1 blockIdent_list { (fun (x,xs) -> x::xs) ($1, $3) } + | blockIdent SYMB2 blockIdent_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -lambdaSep : SYMB2 { LambdaSep1 } - | SYMB3 { LambdaSep2 } +lambdaSep : SYMB3 { LambdaSep1 } + | SYMB4 { LambdaSep2 } ; varModifiers : KW_shared { Shared } @@ -407,24 +407,24 @@ varModifiers_list : /* empty */ { [] } | varModifiers varModifiers_list { (fun (x,xs) -> x::xs) ($1, $2) } ; -decl : KW_axiom globalIdent attribSet expr SYMB4 { Decl_Axiom ($2, $3, $4) } - | KW_memory varModifiers_list globalIdent SYMB5 typeT varSpec SYMB4 { Decl_Mem ($2, $3, $5, $6) } - | KW_var varModifiers_list globalIdent SYMB5 typeT varSpec SYMB4 { Decl_Var ($2, $3, $5, $6) } - | KW_val globalIdent attribSet SYMB5 typeT SYMB4 { Decl_UninterpFun ($2, $3, $5) } - | KW_let globalIdent attribSet SYMB5 typeT SYMB6 expr SYMB4 { Decl_Fun ($2, $3, $5, $7) } - | KW_let globalIdent attribSet SYMB6 expr SYMB4 { Decl_FunNoType ($2, $3, $5) } - | KW_prog KW_entry procIdent attribSet SYMB4 { Decl_ProgEmpty ($3, $4) } +decl : KW_axiom globalIdent attribSet expr { Decl_Axiom ($2, $3, $4) } + | KW_memory varModifiers_list globalIdent SYMB5 typeT varSpec { Decl_Mem ($2, $3, $5, $6) } + | KW_var varModifiers_list globalIdent SYMB5 typeT varSpec { Decl_Var ($2, $3, $5, $6) } + | KW_val globalIdent attribSet SYMB5 typeT { Decl_UninterpFun ($2, $3, $5) } + | KW_let globalIdent attribSet SYMB5 typeT SYMB6 expr { Decl_Fun ($2, $3, $5, $7) } + | KW_let globalIdent attribSet SYMB6 expr { Decl_FunNoType ($2, $3, $5) } + | KW_prog KW_entry procIdent attribSet { Decl_ProgEmpty ($3, $4) } | KW_prog KW_entry procIdent attribSet progSpec_list { Decl_ProgWithSpec ($3, $4, $5) } - | KW_proc procIdent openParen params_list closeParen SYMB2 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } + | KW_proc procIdent openParen params_list closeParen SYMB3 openParen params_list closeParen attribSet funSpec_list procDef { Decl_Proc ($2, $3, $4, $5, $7, $8, $9, $10, $11, $12) } ; typeT_list : /* empty */ { [] } | typeT { (fun x -> [x]) $1 } - | typeT SYMB1 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } + | typeT SYMB2 typeT_list { (fun (x,xs) -> x::xs) ($1, $3) } ; procDef : /* empty */ { ProcDef_Empty } - | beginList block_list endList SYMB4 { ProcDef_Some ($1, $2, $3) } + | beginList block_list endList { ProcDef_Some ($1, $2, $3) } ; intType : iNTTYPE { IntType1 $1 } @@ -436,7 +436,7 @@ boolType : bOOLTYPE { BoolType1 $1 } bVType : bVTYPE { BVType1 $1 } ; -mapType : type1 SYMB2 typeT { MapType1 ($1, $3) } +mapType : type1 SYMB3 typeT { MapType1 ($1, $3) } ; type1 : intType { TypeIntType $1 } @@ -480,7 +480,7 @@ stmt : KW_nop { Stmt_Nop } ; assignment_list : assignment { (fun x -> [x]) $1 } - | assignment SYMB1 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } + | assignment SYMB2 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } ; localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } @@ -492,7 +492,7 @@ globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } ; localVar_list : localVar { (fun x -> [x]) $1 } - | localVar SYMB1 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; var : localVar { VarLocalVar $1 } @@ -501,7 +501,7 @@ var : localVar { VarLocalVar $1 } globalVar_list : /* empty */ { [] } | globalVar { (fun x -> [x]) $1 } - | globalVar SYMB1 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } @@ -509,7 +509,7 @@ namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } namedCallReturn_list : /* empty */ { [] } | namedCallReturn { (fun x -> [x]) $1 } - | namedCallReturn SYMB1 namedCallReturn_list { (fun (x,xs) -> x::xs) ($1, $3) } + | namedCallReturn SYMB2 namedCallReturn_list { (fun (x,xs) -> x::xs) ($1, $3) } ; lVars : /* empty */ { LVars_Empty } @@ -522,7 +522,7 @@ namedCallArg : localIdent SYMB6 expr { NamedCallArg1 ($1, $3) } ; namedCallArg_list : namedCallArg { (fun x -> [x]) $1 } - | namedCallArg SYMB1 namedCallArg_list { (fun (x,xs) -> x::xs) ($1, $3) } + | namedCallArg SYMB2 namedCallArg_list { (fun (x,xs) -> x::xs) ($1, $3) } ; callParams : expr_list { CallParams_Exprs $1 } @@ -540,30 +540,30 @@ lVar : KW_var localVar { LVar_Local $2 } ; lVar_list : lVar { (fun x -> [x]) $1 } - | lVar SYMB1 lVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + | lVar SYMB2 lVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; block_list : /* empty */ { [] } | block { (fun x -> [x]) $1 } - | block SYMB4 block_list { (fun (x,xs) -> x::xs) ($1, $3) } + | block SYMB1 block_list { (fun (x,xs) -> x::xs) ($1, $3) } ; stmtWithAttrib : stmt attribSet { StmtWithAttrib1 ($1, $2) } ; stmtWithAttrib_list : /* empty */ { [] } - | stmtWithAttrib SYMB4 stmtWithAttrib_list { (fun (x,xs) -> x::xs) ($1, $3) } + | stmtWithAttrib SYMB1 stmtWithAttrib_list { (fun (x,xs) -> x::xs) ($1, $3) } ; jumpWithAttrib : jump attribSet { JumpWithAttrib1 ($1, $2) } ; -phiExpr : blockIdent SYMB2 var { PhiExpr1 ($1, $3) } +phiExpr : blockIdent SYMB3 var { PhiExpr1 ($1, $3) } ; phiExpr_list : /* empty */ { [] } | phiExpr { (fun x -> [x]) $1 } - | phiExpr SYMB1 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | phiExpr SYMB2 phiExpr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1, $4, $5, $6) } @@ -571,11 +571,11 @@ phiAssign : lVar SYMB7 KW_phi openParen phiExpr_list closeParen { PhiAssign1 ($1 phiAssign_list : /* empty */ { [] } | phiAssign { (fun x -> [x]) $1 } - | phiAssign SYMB1 phiAssign_list { (fun (x,xs) -> x::xs) ($1, $3) } + | phiAssign SYMB2 phiAssign_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -block : KW_block blockIdent attribSet beginList stmtWithAttrib_list jumpWithAttrib SYMB4 endList { Block_NoPhi ($2, $3, $4, $5, $6, $8) } - | KW_block blockIdent attribSet openParen phiAssign_list closeParen beginList stmtWithAttrib_list jumpWithAttrib SYMB4 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $8, $9, $11) } +block : KW_block blockIdent attribSet beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_NoPhi ($2, $3, $4, $5, $6, $8) } + | KW_block blockIdent attribSet openParen phiAssign_list closeParen beginList stmtWithAttrib_list jumpWithAttrib SYMB1 endList { Block_Phi ($2, $3, $4, $5, $6, $7, $8, $9, $11) } ; attrKeyValue : bIdent SYMB6 attr { AttrKeyValue1 ($1, $3) } @@ -583,7 +583,7 @@ attrKeyValue : bIdent SYMB6 attr { AttrKeyValue1 ($1, $3) } attrKeyValue_list : /* empty */ { [] } | attrKeyValue { (fun x -> [x]) $1 } - | attrKeyValue SYMB4 attrKeyValue_list { (fun (x,xs) -> x::xs) ($1, $3) } + | attrKeyValue SYMB1 attrKeyValue_list { (fun (x,xs) -> x::xs) ($1, $3) } ; attribSet : beginRec attrKeyValue_list endRec { AttribSet_Some ($1, $2, $3) } @@ -592,7 +592,7 @@ attribSet : beginRec attrKeyValue_list endRec { AttribSet_Some ($1, $2, $3) } attr_list : /* empty */ { [] } | attr { (fun x -> [x]) $1 } - | attr SYMB4 attr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | attr SYMB1 attr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; attr : beginRec attrKeyValue_list endRec { Attr_Map ($1, $2, $3) } @@ -606,7 +606,7 @@ params : localIdent SYMB5 typeT { Params1 ($1, $3) } params_list : /* empty */ { [] } | params { (fun x -> [x]) $1 } - | params SYMB1 params_list { (fun (x,xs) -> x::xs) ($1, $3) } + | params SYMB2 params_list { (fun (x,xs) -> x::xs) ($1, $3) } ; value : bVVal { Value_BV $1 } @@ -617,7 +617,7 @@ value : bVVal { Value_BV $1 } expr_list : /* empty */ { [] } | expr { (fun x -> [x]) $1 } - | expr SYMB1 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } + | expr SYMB2 expr_list { (fun (x,xs) -> x::xs) ($1, $3) } ; expr : expr1 { $1 } @@ -634,14 +634,14 @@ expr2 : value { Expr_Literal $1 } | localVar { Expr_Local $1 } | globalVar { Expr_Global $1 } | KW_old openParen expr closeParen { Expr_Old ($2, $3, $4) } - | binOp openParen expr SYMB1 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } + | binOp openParen expr SYMB2 expr closeParen { Expr_Binary ($1, $2, $3, $5, $6) } | boolBinOp openParen expr_list closeParen { Expr_Assoc ($1, $2, $3, $4) } | unOp openParen expr closeParen { Expr_Unary ($1, $2, $3, $4) } - | KW_load_be openParen intVal SYMB1 expr SYMB1 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } - | KW_load_le openParen intVal SYMB1 expr SYMB1 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } - | KW_zero_extend openParen intVal SYMB1 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } - | KW_sign_extend openParen intVal SYMB1 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } - | KW_extract openParen intVal SYMB1 intVal SYMB1 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } + | KW_load_be openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadBe ($2, $3, $5, $7, $8) } + | KW_load_le openParen intVal SYMB2 expr SYMB2 expr closeParen { Expr_LoadLe ($2, $3, $5, $7, $8) } + | KW_zero_extend openParen intVal SYMB2 expr closeParen { Expr_ZeroExtend ($2, $3, $5, $6) } + | KW_sign_extend openParen intVal SYMB2 expr closeParen { Expr_SignExtend ($2, $3, $5, $6) } + | KW_extract openParen intVal SYMB2 intVal SYMB2 expr closeParen { Expr_Extract ($2, $3, $5, $7, $8) } | KW_bvconcat openParen expr_list closeParen { Expr_Concat ($2, $3, $4) } | KW_match expr KW_with openParen case_list closeParen { Expr_Match ($2, $4, $5, $6) } | KW_cases openParen case_list closeParen { Expr_Cases ($2, $3, $4) } @@ -654,7 +654,7 @@ lambdaParen : localVar { LambdaParenLocalVar $1 } lambdaParen_list : /* empty */ { [] } | lambdaParen { (fun x -> [x]) $1 } - | lambdaParen SYMB1 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } + | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } @@ -675,8 +675,8 @@ unOp : bVUnOp { UnOpBVUnOp $1 } | KW_classification { UnOp_classification } ; -case : expr SYMB2 expr { CaseCase ($1, $3) } - | SYMB9 SYMB2 expr { CaseDefault $3 } +case : expr SYMB3 expr { CaseCase ($1, $3) } + | SYMB9 SYMB3 expr { CaseDefault $3 } ; case_list : /* empty */ { [] } @@ -774,11 +774,11 @@ progSpec : relyTok expr { ProgSpec_Rely ($1, $2) } ; funSpec_list : /* empty */ { [] } - | funSpec SYMB4 funSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } + | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; -progSpec_list : progSpec SYMB4 { (fun x -> [x]) $1 } - | progSpec SYMB4 progSpec_list { (fun (x,xs) -> x::xs) ($1, $3) } +progSpec_list : /* empty */ { [] } + | progSpec progSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; bVTYPE : TOK_BVTYPE { BVTYPE ($1)}; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index e9bd2cea..d1a2ae5e 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -153,22 +153,22 @@ and prtVarModifiersListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,x::xs) -> (concatD [prtVarModifiers 0 x ; prtVarModifiersListBNFC 0 xs]) and prtDecl (i:int) (e : AbsBasilIR.decl) : doc = match e with - AbsBasilIR.Decl_Axiom (globalident, attribset, expr) -> prPrec i 0 (concatD [render "axiom" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; prtExpr 0 expr ; render ";"]) - | AbsBasilIR.Decl_Mem (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "memory" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec ; render ";"]) - | AbsBasilIR.Decl_Var (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "var" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec ; render ";"]) - | AbsBasilIR.Decl_UninterpFun (globalident, attribset, type_) -> prPrec i 0 (concatD [render "val" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render ";"]) - | AbsBasilIR.Decl_Fun (globalident, attribset, type_, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render "=" ; prtExpr 0 expr ; render ";"]) - | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr ; render ";"]) - | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; render ";"]) + AbsBasilIR.Decl_Axiom (globalident, attribset, expr) -> prPrec i 0 (concatD [render "axiom" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; prtExpr 0 expr]) + | AbsBasilIR.Decl_Mem (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "memory" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec]) + | AbsBasilIR.Decl_Var (varmodifierss, globalident, type_, varspec) -> prPrec i 0 (concatD [render "var" ; prtVarModifiersListBNFC 0 varmodifierss ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtVarSpec 0 varspec]) + | AbsBasilIR.Decl_UninterpFun (globalident, attribset, type_) -> prPrec i 0 (concatD [render "val" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_]) + | AbsBasilIR.Decl_Fun (globalident, attribset, type_, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render ":" ; prtTypeT 0 type_ ; render "=" ; prtExpr 0 expr]) + | AbsBasilIR.Decl_FunNoType (globalident, attribset, expr) -> prPrec i 0 (concatD [render "let" ; prtGlobalIdent 0 globalident ; prtAttribSet 0 attribset ; render "=" ; prtExpr 0 expr]) + | AbsBasilIR.Decl_ProgEmpty (procident, attribset) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset]) | AbsBasilIR.Decl_ProgWithSpec (procident, attribset, progspecs) -> prPrec i 0 (concatD [render "prog" ; render "entry" ; prtProcIdent 0 procident ; prtAttribSet 0 attribset ; prtProgSpecListBNFC 0 progspecs]) | AbsBasilIR.Decl_Proc (procident, openparen1, paramss1, closeparen1, openparen2, paramss2, closeparen2, attribset, funspecs, procdef) -> prPrec i 0 (concatD [render "proc" ; prtProcIdent 0 procident ; prtOpenParen 0 openparen1 ; prtParamsListBNFC 0 paramss1 ; prtCloseParen 0 closeparen1 ; render "->" ; prtOpenParen 0 openparen2 ; prtParamsListBNFC 0 paramss2 ; prtCloseParen 0 closeparen2 ; prtAttribSet 0 attribset ; prtFunSpecListBNFC 0 funspecs ; prtProcDef 0 procdef]) and prtDeclListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtDecl 0 x ; prtDeclListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtDecl 0 x ; render ";" ; prtDeclListBNFC 0 xs]) and prtProcDef (i:int) (e : AbsBasilIR.procDef) : doc = match e with AbsBasilIR.ProcDef_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist ; render ";"]) + | AbsBasilIR.ProcDef_Some (beginlist, blocks, endlist) -> prPrec i 0 (concatD [prtBeginList 0 beginlist ; prtBlockListBNFC 0 blocks ; prtEndList 0 endlist]) and prtIntType (i:int) (e : AbsBasilIR.intType) : doc = match e with @@ -523,7 +523,8 @@ and prtFunSpec (i:int) (e : AbsBasilIR.funSpec) : doc = match e with and prtFunSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render ";" ; prtFunSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtFunSpec 0 x ; render " +" ; prtFunSpecListBNFC 0 xs]) and prtVarSpec (i:int) (e : AbsBasilIR.varSpec) : doc = match e with AbsBasilIR.VarSpec_Classification expr -> prPrec i 0 (concatD [render "classification" ; prtExpr 0 expr]) | AbsBasilIR.VarSpec_Empty -> prPrec i 0 (concatD []) @@ -535,6 +536,6 @@ and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtProgSpec 0 x ; render ";"]) - | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render ";" ; prtProgSpecListBNFC 0 xs]) + | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render " +" ; prtProgSpecListBNFC 0 xs]) diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 3c4ef64c..ac58ab1c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -21,8 +21,8 @@ module.exports = grammar({ choice( // []. [Decl] ::= ; choice(), - // (:). [Decl] ::= Decl [Decl] ; - seq($.Decl, optional($.list_Decl)) + // (:). [Decl] ::= Decl ";" [Decl] ; + seq($.Decl, ";", optional($.list_Decl)) ), list_token_BlockIdent: $ => choice( @@ -56,22 +56,22 @@ module.exports = grammar({ ), Decl: $ => choice( - // Decl_Axiom. Decl ::= "axiom" GlobalIdent AttribSet Expr ";" ; - seq("axiom", $.token_GlobalIdent, optional($.AttribSet), $.Expr, ";"), - // Decl_Mem. Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ";" ; - seq("memory", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec), ";"), - // Decl_Var. Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ";" ; - seq("var", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec), ";"), - // Decl_UninterpFun. Decl ::= "val" GlobalIdent AttribSet ":" Type ";" ; - seq("val", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, ";"), - // Decl_Fun. Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ";" ; - seq("let", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, "=", $.Expr, ";"), - // Decl_FunNoType. Decl ::= "let" GlobalIdent AttribSet "=" Expr ";" ; - seq("let", $.token_GlobalIdent, optional($.AttribSet), "=", $.Expr, ";"), - // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ";" ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), ";"), + // Decl_Axiom. Decl ::= "axiom" GlobalIdent AttribSet Expr ; + seq("axiom", $.token_GlobalIdent, optional($.AttribSet), $.Expr), + // Decl_Mem. Decl ::= "memory" [VarModifiers] GlobalIdent ":" Type VarSpec ; + seq("memory", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), + // Decl_Var. Decl ::= "var" [VarModifiers] GlobalIdent ":" Type VarSpec ; + seq("var", optional($.list_VarModifiers), $.token_GlobalIdent, ":", $.Type, optional($.VarSpec)), + // Decl_UninterpFun. Decl ::= "val" GlobalIdent AttribSet ":" Type ; + seq("val", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type), + // Decl_Fun. Decl ::= "let" GlobalIdent AttribSet ":" Type "=" Expr ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), ":", $.Type, "=", $.Expr), + // Decl_FunNoType. Decl ::= "let" GlobalIdent AttribSet "=" Expr ; + seq("let", $.token_GlobalIdent, optional($.AttribSet), "=", $.Expr), + // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), @@ -88,8 +88,8 @@ module.exports = grammar({ choice( // ProcDef_Empty. ProcDef ::= ; choice(), - // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ";" ; - seq($.token_BeginList, optional($.list_Block), $.token_EndList, ";") + // ProcDef_Some. ProcDef ::= BeginList [Block] EndList ; + seq($.token_BeginList, optional($.list_Block), $.token_EndList) ), IntType: $ => // IntType1. IntType ::= INTTYPE ; @@ -689,15 +689,15 @@ module.exports = grammar({ choice( // []. [FunSpec] ::= ; choice(), - // (:). [FunSpec] ::= FunSpec ";" [FunSpec] ; - seq($.FunSpec, ";", optional($.list_FunSpec)) + // (:). [FunSpec] ::= FunSpec [FunSpec] ; + seq($.FunSpec, optional($.list_FunSpec)) ), list_ProgSpec: $ => choice( - // (:[]). [ProgSpec] ::= ProgSpec ";" ; - seq($.ProgSpec, ";"), - // (:). [ProgSpec] ::= ProgSpec ";" [ProgSpec] ; - seq($.ProgSpec, ";", $.list_ProgSpec) + // []. [ProgSpec] ::= ; + choice(), + // (:). [ProgSpec] ::= ProgSpec [ProgSpec] ; + seq($.ProgSpec, optional($.list_ProgSpec)) ), token_BVTYPE: $ => /bv\d+/, From dc21dd0d896b7bf3d6937daf9125142d69797e30 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 13:55:09 +1000 Subject: [PATCH 37/43] Revert "revert spec semicolon change" This reverts commit 31a6954c2a462f888894d0e5098a1ab7bbc8a41f. --- examples/cat.il | 148 +++++++++++++++++++++---------------------- examples/conds.il | 4 +- examples/x-output.il | 2 +- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/examples/cat.il b/examples/cat.il index d6b0c07c..27fd0e5b 100644 --- a/examples/cat.il +++ b/examples/cat.il @@ -48,8 +48,8 @@ prog entry @main_4197696; proc @main_4197696 () -> () { .name = "main"; .address = 0x400d40; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x400d40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400d40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %main_entry {.address = 0x400d40; .originalLabel = "KXhc9Fe2Qva4qWVLC1eV+w=="} [ assert eq($_PC:bv64, 0x400d40:bv64); @@ -86,8 +86,8 @@ proc @exit () -> () proc @exitcode_4198816 () -> () { .name = "exitcode"; .address = 0x4011a0; .returnBlock = "exitcode_basil_return_1" } - require eq($_PC:bv64, 0x4011a0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4011a0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %exitcode_entry {.address = 0x4011a0; .originalLabel = "Hr3XvFHLQ62ROxw2L+L+kg=="} [ assert eq($_PC:bv64, 0x4011a0:bv64); @@ -109,8 +109,8 @@ proc @exitcode_4198816 () -> () proc @exits_4198688 () -> () { .name = "exits"; .address = 0x401120; .returnBlock = "exits_basil_return_1" } - require eq($_PC:bv64, 0x401120:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401120:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %exits_entry {.address = 0x401120; .originalLabel = "OamxgWkAT5S7lYhJLb34Bw=="} [ var R30_begin_exits_4198688: bv64 := $R30:bv64; @@ -449,8 +449,8 @@ proc @exits_4198688 () -> () proc @fmtlocaleinit_4209552 () -> () { .name = "fmtlocaleinit"; .address = 0x403b90; .returnBlock = "fmtlocaleinit_basil_return_1" } - require eq($_PC:bv64, 0x403b90:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403b90:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fmtlocaleinit_entry {.address = 0x403b90; .originalLabel = "LJeXYGqvSDa8MTgV+KKKNg=="} [ assert eq($_PC:bv64, 0x403b90:bv64); @@ -611,8 +611,8 @@ proc @fmtlocaleinit_4209552 () -> () proc @fmtfdinit_4209364 () -> () { .name = "fmtfdinit"; .address = 0x403ad4; .returnBlock = "fmtfdinit_basil_return_1" } - require eq($_PC:bv64, 0x403ad4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403ad4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fmtfdinit_entry {.address = 0x403ad4; .originalLabel = "Ase3rrH2SOSuhunVYXYBhg=="} [ assert eq($_PC:bv64, 0x403ad4:bv64); @@ -715,8 +715,8 @@ proc @write () -> () proc @__fmtFdFlush_4209456 () -> () { .name = "__fmtFdFlush"; .address = 0x403b30; .returnBlock = "__fmtFdFlush_basil_return_1" } - require eq($_PC:bv64, 0x403b30:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403b30:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtFdFlush_entry {.address = 0x403b30; .originalLabel = "I+YOj/gGRqS87EwafUF4WA=="} [ assert eq($_PC:bv64, 0x403b30:bv64); @@ -914,8 +914,8 @@ proc @__fmtFdFlush_4209456 () -> () proc @__flagfmt_4208112 () -> () { .name = "__flagfmt"; .address = 0x4035f0; .returnBlock = "__flagfmt_basil_return_1" } - require eq($_PC:bv64, 0x4035f0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4035f0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__flagfmt_entry {.address = 0x4035f0; .originalLabel = "Md5qE+eiRf+m/NPBkVuT3g=="} [ assert eq($_PC:bv64, 0x4035f0:bv64); @@ -1454,8 +1454,8 @@ proc @__flagfmt_4208112 () -> () proc @__rfmtpad_4203024 () -> () { .name = "__rfmtpad"; .address = 0x402210; .returnBlock = "__rfmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402210:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402210:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__rfmtpad_entry {.address = 0x402210; .originalLabel = "FnHqSK+lTxq6YDUq7NvnJg=="} [ assert eq($_PC:bv64, 0x402210:bv64); @@ -1940,8 +1940,8 @@ proc @__rfmtpad_4203024 () -> () proc @runelen_4210048 () -> () { .name = "runelen"; .address = 0x403d80; .returnBlock = "runelen_basil_return_1" } - require eq($_PC:bv64, 0x403d80:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403d80:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %runelen_entry {.address = 0x403d80; .originalLabel = "o0lVyZ2GT4mJNVkb5e5Vuw=="} [ assert eq($_PC:bv64, 0x403d80:bv64); @@ -2022,8 +2022,8 @@ proc @runelen_4210048 () -> () proc @fullrune_4210160 () -> () { .name = "fullrune"; .address = 0x403df0; .returnBlock = "fullrune_basil_return_1" } - require eq($_PC:bv64, 0x403df0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403df0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fullrune_entry {.address = 0x403df0; .originalLabel = "ycUhyOy1TNW1hp1YrdP0uw=="} [ assert eq($_PC:bv64, 0x403df0:bv64); @@ -2178,8 +2178,8 @@ proc @fullrune_4210160 () -> () proc @__fmtpad_4202756 () -> () { .name = "__fmtpad"; .address = 0x402104; .returnBlock = "__fmtpad_basil_return_1" } - require eq($_PC:bv64, 0x402104:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402104:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtpad_entry {.address = 0x402104; .originalLabel = "DS7w57znRnmBsFkYW6cA+Q=="} [ assert eq($_PC:bv64, 0x402104:bv64); @@ -2663,8 +2663,8 @@ proc @__fmtpad_4202756 () -> () proc @runetochar_4209936 () -> () { .name = "runetochar"; .address = 0x403d10; .returnBlock = "runetochar_basil_return_1" } - require eq($_PC:bv64, 0x403d10:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403d10:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %runetochar_entry {.address = 0x403d10; .originalLabel = "Rkek/d08TK2mkJ7PEcm6mg=="} [ assert eq($_PC:bv64, 0x403d10:bv64); @@ -2816,8 +2816,8 @@ proc @runetochar_4209936 () -> () proc @__fmtflush_4202032 () -> () { .name = "__fmtflush"; .address = 0x401e30; .returnBlock = "__fmtflush_basil_return_1" } - require eq($_PC:bv64, 0x401e30:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401e30:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtflush_entry {.address = 0x401e30; .originalLabel = "Osy3QCRQRpSd5aY0vW+qkQ=="} [ assert eq($_PC:bv64, 0x401e30:bv64); @@ -3092,8 +3092,8 @@ proc @__fmtflush_4202032 () -> () proc @chartorune_4209760 () -> () { .name = "chartorune"; .address = 0x403c60; .returnBlock = "chartorune_basil_return_1" } - require eq($_PC:bv64, 0x403c60:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c60:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %chartorune_entry {.address = 0x403c60; .originalLabel = "+s65+r9uRzKHgPS/OxqX3g=="} [ assert eq($_PC:bv64, 0x403c60:bv64); @@ -3398,8 +3398,8 @@ proc @chartorune_4209760 () -> () proc @__fmtcpy_4203296 () -> () { .name = "__fmtcpy"; .address = 0x402320; .returnBlock = "__fmtcpy_basil_return_1" } - require eq($_PC:bv64, 0x402320:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x402320:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtcpy_entry {.address = 0x402320; .originalLabel = "onW0wUQSS+CWRE3FG7sZVA=="} [ assert eq($_PC:bv64, 0x402320:bv64); @@ -4774,8 +4774,8 @@ proc @__fmtcpy_4203296 () -> () proc @__badfmt_4208400 () -> () { .name = "__badfmt"; .address = 0x403710; .returnBlock = "__badfmt_basil_return_1" } - require eq($_PC:bv64, 0x403710:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403710:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__badfmt_entry {.address = 0x403710; .originalLabel = "VsS7dlFoQ3et0t9jIUUtyw=="} [ assert eq($_PC:bv64, 0x403710:bv64); @@ -4852,8 +4852,8 @@ proc @__badfmt_4208400 () -> () proc @getcallerpc_4201920 () -> () { .name = "getcallerpc"; .address = 0x401dc0; .returnBlock = "getcallerpc_basil_return_1" } - require eq($_PC:bv64, 0x401dc0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401dc0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %getcallerpc_entry {.address = 0x401dc0; .originalLabel = "/lgI4FfjS+yfGYqEtnuiGw=="} [ assert eq($_PC:bv64, 0x401dc0:bv64); @@ -4879,8 +4879,8 @@ proc @getcallerpc_4201920 () -> () proc @unlock_4199332 () -> () { .name = "unlock"; .address = 0x4013a4; .returnBlock = "unlock_basil_return_1" } - require eq($_PC:bv64, 0x4013a4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4013a4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %unlock_entry {.address = 0x4013a4; .originalLabel = "V0jFzXuITMiNHr/kb8xG4g=="} [ assert eq($_PC:bv64, 0x4013a4:bv64); @@ -5022,8 +5022,8 @@ proc @unlock_4199332 () -> () proc @__fmtunlock_4209744 () -> () { .name = "__fmtunlock"; .address = 0x403c50; .returnBlock = "__fmtunlock_basil_return_1" } - require eq($_PC:bv64, 0x403c50:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c50:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtunlock_entry {.address = 0x403c50; .originalLabel = "LHWtkP5rQmqxTbinnC1hLw=="} [ var R30_begin___fmtunlock_4209744: bv64 := $R30:bv64; @@ -5051,8 +5051,8 @@ proc @__fmtunlock_4209744 () -> () proc @lock_4199120 () -> () { .name = "lock"; .address = 0x4012d0; .returnBlock = "lock_basil_return_1" } - require eq($_PC:bv64, 0x4012d0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4012d0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %lock_entry {.address = 0x4012d0; .originalLabel = "EL5Ky+1GSIeJ6nw6JbZnPg=="} [ assert eq($_PC:bv64, 0x4012d0:bv64); @@ -5204,8 +5204,8 @@ proc @lock_4199120 () -> () proc @__fmtlock_4209728 () -> () { .name = "__fmtlock"; .address = 0x403c40; .returnBlock = "__fmtlock_basil_return_1" } - require eq($_PC:bv64, 0x403c40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403c40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtlock_entry {.address = 0x403c40; .originalLabel = "n9+4iNtqRLu7+3FBjvBlSg=="} [ var R30_begin___fmtlock_4209728: bv64 := $R30:bv64; @@ -5233,8 +5233,8 @@ proc @__fmtlock_4209728 () -> () proc @__fmtinstall_4208464 () -> () { .name = "__fmtinstall"; .address = 0x403750; .returnBlock = "__fmtinstall_basil_return_1" } - require eq($_PC:bv64, 0x403750:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403750:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtinstall_entry {.address = 0x403750; .originalLabel = "4vz6BXioRXa/LaTzSs8GSg=="} [ assert eq($_PC:bv64, 0x403750:bv64); @@ -5516,8 +5516,8 @@ proc @__fmtinstall_4208464 () -> () proc @__fmtdispatch_4208688 () -> () { .name = "__fmtdispatch"; .address = 0x403830; .returnBlock = "__fmtdispatch_basil_return_1" } - require eq($_PC:bv64, 0x403830:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x403830:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fmtdispatch_entry {.address = 0x403830; .originalLabel = "J5JvET/ORDyFBY1+xoNLkA=="} [ assert eq($_PC:bv64, 0x403830:bv64); @@ -6659,8 +6659,8 @@ proc @__fmtdispatch_4208688 () -> () proc @dofmt_4202176 () -> () { .name = "dofmt"; .address = 0x401ec0; .returnBlock = "dofmt_basil_return_1" } - require eq($_PC:bv64, 0x401ec0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401ec0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %dofmt_entry {.address = 0x401ec0; .originalLabel = "ptCQBLyvTM22JSPE/cK18w=="} [ assert eq($_PC:bv64, 0x401ec0:bv64); @@ -7699,8 +7699,8 @@ proc @dofmt_4202176 () -> () proc @vfprint_4201072 () -> () { .name = "vfprint"; .address = 0x401a70; .returnBlock = "vfprint_basil_return_1" } - require eq($_PC:bv64, 0x401a70:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401a70:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %vfprint_entry {.address = 0x401a70; .originalLabel = "kh4iUxoKQMenD77ljouyEQ=="} [ assert eq($_PC:bv64, 0x401a70:bv64); @@ -7882,8 +7882,8 @@ proc @vfprint_4201072 () -> () proc @fprint_4200960 () -> () { .name = "fprint"; .address = 0x401a00; .returnBlock = "fprint_basil_return_1" } - require eq($_PC:bv64, 0x401a00:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401a00:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %fprint_entry {.address = 0x401a00; .originalLabel = "fQteMOadSm+stHHR3jx4Qw=="} [ assert eq($_PC:bv64, 0x401a00:bv64); @@ -7986,8 +7986,8 @@ proc @fprint_4200960 () -> () proc @__fixargv0_4198400 () -> () { .name = "__fixargv0"; .address = 0x401000; .returnBlock = "__fixargv0_basil_return_1" } - require eq($_PC:bv64, 0x401000:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401000:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %__fixargv0_entry {.address = 0x401000; .originalLabel = "78skE39ZS92hlwuQoG/N1g=="} [ assert eq($_PC:bv64, 0x401000:bv64); @@ -8007,8 +8007,8 @@ proc @__fixargv0_4198400 () -> () proc @vseprint_4201184 () -> () { .name = "vseprint"; .address = 0x401ae0; .returnBlock = "vseprint_basil_return_1" } - require eq($_PC:bv64, 0x401ae0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401ae0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %vseprint_entry {.address = 0x401ae0; .originalLabel = "xuA0Edh9S8yFZV1Qu/Jgqw=="} [ assert eq($_PC:bv64, 0x401ae0:bv64); @@ -8169,8 +8169,8 @@ proc @vseprint_4201184 () -> () proc @sysfatal_4200560 () -> () { .name = "sysfatal"; .address = 0x401870; .returnBlock = "sysfatal_basil_return_1" } - require eq($_PC:bv64, 0x401870:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401870:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %sysfatal_entry {.address = 0x401870; .originalLabel = "HN8ZNDP1RUKhvFhL/Qx3ng=="} [ var R30_begin_sysfatal_4200560: bv64 := $R30:bv64; @@ -8471,8 +8471,8 @@ proc @memccpy () -> () proc @strecpy_4201936 () -> () { .name = "strecpy"; .address = 0x401dd0; .returnBlock = "strecpy_basil_return_1" } - require eq($_PC:bv64, 0x401dd0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401dd0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %strecpy_entry {.address = 0x401dd0; .originalLabel = "gS9qAucpRMKJD8TibWbm5A=="} [ assert eq($_PC:bv64, 0x401dd0:bv64); @@ -8680,8 +8680,8 @@ proc @strerror () -> () proc @rerrstr_4201312 () -> () { .name = "rerrstr"; .address = 0x401b60; .returnBlock = "rerrstr_basil_return_1" } - require eq($_PC:bv64, 0x401b60:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401b60:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %rerrstr_entry {.address = 0x401b60; .originalLabel = "ldWhLOMYSKyYFGShQwXqIg=="} [ var R30_begin_rerrstr_4201312: bv64 := $R30:bv64; @@ -9214,8 +9214,8 @@ proc @rerrstr_4201312 () -> () proc @errstr_4201540 () -> () { .name = "errstr"; .address = 0x401c44; .returnBlock = "errstr_basil_return_1" } - require eq($_PC:bv64, 0x401c44:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401c44:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %errstr_entry {.address = 0x401c44; .originalLabel = "3ReV3l3lTEWXlI8dRV4Pcw=="} [ assert eq($_PC:bv64, 0x401c44:bv64); @@ -9454,8 +9454,8 @@ proc @errstr_4201540 () -> () proc @werrstr_4201780 () -> () { .name = "werrstr"; .address = 0x401d34; .returnBlock = "werrstr_basil_return_1" } - require eq($_PC:bv64, 0x401d34:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401d34:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %werrstr_entry {.address = 0x401d34; .originalLabel = "EsiP/3+hSbS6DhsMqrwxFA=="} [ assert eq($_PC:bv64, 0x401d34:bv64); @@ -9607,8 +9607,8 @@ proc @open64 () -> () proc @p9open_4198832 () -> () { .name = "p9open"; .address = 0x4011b0; .returnBlock = "p9open_basil_return_1" } - require eq($_PC:bv64, 0x4011b0:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4011b0:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9open_entry {.address = 0x4011b0; .originalLabel = "DYW7Gbw6QwK5DzhE/cGL7w=="} [ assert eq($_PC:bv64, 0x4011b0:bv64); @@ -10273,8 +10273,8 @@ proc @p9open_4198832 () -> () proc @p9write_4200816 () -> () { .name = "p9write"; .address = 0x401970; .returnBlock = "p9write_basil_return_1" } - require eq($_PC:bv64, 0x401970:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x401970:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9write_entry {.address = 0x401970; .originalLabel = "qVvzznzaToayt5BQelE/sg=="} [ assert eq($_PC:bv64, 0x401970:bv64); @@ -10571,8 +10571,8 @@ proc @read () -> () proc @cat_4198032 () -> () { .name = "cat"; .address = 0x400e90; .returnBlock = "cat_basil_return_1" } - require eq($_PC:bv64, 0x400e90:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400e90:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %cat_entry {.address = 0x400e90; .originalLabel = "OMO2ysIfSmeORBpBsr5OIQ=="} [ var R30_begin_cat_4198032: bv64 := $R30:bv64; @@ -10826,8 +10826,8 @@ proc @cat_4198032 () -> () proc @p9main_4198208 () -> () { .name = "p9main"; .address = 0x400f40; .returnBlock = "p9main_basil_return_1" } - require eq($_PC:bv64, 0x400f40:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x400f40:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %p9main_entry {.address = 0x400f40; .originalLabel = "FGQT8qmESb6FIwl/znG8jA=="} [ var R30_begin_p9main_4198208: bv64 := $R30:bv64; diff --git a/examples/conds.il b/examples/conds.il index 1125b6d6..0428a536 100644 --- a/examples/conds.il +++ b/examples/conds.il @@ -14,8 +14,8 @@ prog entry @main_4196260; proc @main_4196260 () -> () { .name = "main"; .address = 0x4007a4; .returnBlock = "main_basil_return_1" } - require eq($_PC:bv64, 0x4007a4:bv64); - ensures eq($_PC:bv64, old($R30:bv64)); + require eq($_PC:bv64, 0x4007a4:bv64) + ensures eq($_PC:bv64, old($R30:bv64)) [ block %main_entry {.address = 0x4007a4; .originalLabel = "rlVqjjqoR6uHwOYvPCS15g=="} [ assert eq($_PC:bv64, 0x4007a4:bv64); diff --git a/examples/x-output.il b/examples/x-output.il index acccac91..8d649379 100644 --- a/examples/x-output.il +++ b/examples/x-output.il @@ -7,7 +7,7 @@ proc @main_4196164 (R0_in:bv64, R1_in:bv64, R30_in:bv64, R31_in:bv64, _PC_in:bv64) -> (R0_out:bv64, R1_out:bv64, _PC_out:bv64) { .name = "main"; .address = 0x400744 } - require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)); + require bvsge(R31_in:bv64, bvsub(R31_in:bv64, 0x10:bv64)) [ block %main_entry {.address = 0x400744; .originalLabel = "G8B0Q6XuSneDgqpNFr1sUQ=="} [ store le $stack bvadd(R31_in:bv64, 0xfffffffffffffffc:bv64) extract(32, 0, R0_in:bv64) 32 { .label = "4196168_0" }; From 54cd3c9d50d6d87053d49459bbc63cf41e6883f6 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:26:05 +1000 Subject: [PATCH 38/43] stash --- lib/fe/AbsBasilIR.ml | 18 +++++++---- lib/fe/BasilIR.cf | 20 +++++++----- lib/fe/ParBasilIR.mly | 72 +++++++++++++++++++++++------------------ lib/fe/PrintBasilIR.ml | 27 +++++++++------- lib/fe/ShowBasilIR.ml | 21 +++++++----- lib/fe/SkelBasilIR.ml | 21 +++++++----- lib/loadir.ml | 20 ++++-------- tree-sitter/grammar.js | 73 +++++++++++++++++++++++------------------- 8 files changed, 152 insertions(+), 120 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index a280c6cd..3a0093d5 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -104,12 +104,20 @@ and var = VarLocalVar of localVar | VarGlobalVar of globalVar +and localVarParen = + LocalVarParenLocalVar of localVar + | LocalVarParen1 of openParen * localIdent * typeT * closeParen + +and globalVarParen = + GlobalVarParenGlobalVar of globalVar + | GlobalVarParen1 of openParen * globalIdent * typeT * closeParen + and namedCallReturn = NamedCallReturn1 of lVar * localIdent and lVars = LVars_Empty - | LVars_LocalList of openParen * localVar list * closeParen + | LVars_LocalList of openParen * localVarParen list * closeParen | LVars_List of openParen * lVar list * closeParen | NamedLVars_List of openParen * namedCallReturn list * closeParen @@ -127,7 +135,7 @@ and jump = | Jump_ProcReturn and lVar = - LVar_Local of localVar + LVar_Local of localVarParen | LVar_Global of globalVar and stmtWithAttrib = @@ -190,12 +198,8 @@ and expr = | Expr_Cases of openParen * case list * closeParen | Expr_Paren of openParen * expr * closeParen -and lambdaParen = - LambdaParenLocalVar of localVar - | LambdaParen1 of openParen * localVar * closeParen - and lambdaDef = - LambdaDef1 of lambdaParen list * lambdaSep * expr + LambdaDef1 of localVarParen list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index d5670f7e..a7130c52 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -97,13 +97,20 @@ Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; LocalUntyped . LocalVar ::= LocalIdent ; +separator nonempty LocalVar ","; GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; GlobalUntyped . GlobalVar ::= GlobalIdent; -separator nonempty LocalVar ","; +separator GlobalVar ","; + rules Var ::= LocalVar | GlobalVar ; -separator GlobalVar ","; +-- Variant of LocalVar / GlobalVar which can be wrapped in parens and +-- can contain any type. +rules LocalVarParen ::= LocalVar | OpenParen LocalIdent ":" Type CloseParen ; +rules GlobalVarParen ::= GlobalVar | OpenParen GlobalIdent ":" Type CloseParen ; +separator LocalVarParen ","; + -- lvar endian mem addr size Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; @@ -116,7 +123,7 @@ rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; LVars_Empty . LVars ::= ; -LVars_LocalList . LVars ::= "var" OpenParen [ LocalVar ] CloseParen ":=" ; +LVars_LocalList . LVars ::= "var" OpenParen [ LocalVarParen ] CloseParen ":=" ; LVars_List . LVars ::= OpenParen [ LVar ] CloseParen ":="; NamedLVars_List . LVars ::= OpenParen [NamedCallReturn] CloseParen ":="; @@ -138,7 +145,7 @@ Jump_Unreachable . Jump ::= "unreachable" ; Jump_Return . Jump ::= "return" OpenParen [Expr] CloseParen ; Jump_ProcReturn. Jump ::= "return" ; -LVar_Local . LVar ::= "var" LocalVar; +LVar_Local . LVar ::= "var" LocalVarParen; LVar_Global . LVar ::= GlobalVar; separator nonempty LVar "," ; @@ -208,10 +215,7 @@ Expr_Global . Expr2 ::= GlobalVar; -- quantifiers -rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; -separator LambdaParen ","; - -rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; +rules LambdaDef ::= [LocalVarParen] LambdaSep Expr ; Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index dd887b98..4b1581d8 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pLocalVar_list pGlobalVar pGlobalVar_list pVar pLocalVarParen pGlobalVarParen pLocalVarParen_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -67,10 +67,13 @@ open Lexing %type pStmt %type pAssignment_list %type pLocalVar -%type pGlobalVar %type pLocalVar_list -%type pVar +%type pGlobalVar %type pGlobalVar_list +%type pVar +%type pLocalVarParen +%type pGlobalVarParen +%type pLocalVarParen_list %type pNamedCallReturn %type pNamedCallReturn_list %type pLVars @@ -101,8 +104,6 @@ open Lexing %type pExpr %type pExpr1 %type pExpr2 -%type pLambdaParen -%type pLambdaParen_list %type pLambdaDef %type pBinOp %type pUnOp @@ -147,10 +148,13 @@ open Lexing %type stmt %type assignment_list %type localVar -%type globalVar %type localVar_list -%type var +%type globalVar %type globalVar_list +%type var +%type localVarParen +%type globalVarParen +%type localVarParen_list %type namedCallReturn %type namedCallReturn_list %type lVars @@ -181,8 +185,6 @@ open Lexing %type expr %type expr1 %type expr2 -%type lambdaParen -%type lambdaParen_list %type lambdaDef %type binOp %type unOp @@ -269,13 +271,19 @@ pAssignment_list : assignment_list TOK_EOF { $1 }; pLocalVar : localVar TOK_EOF { $1 }; +pLocalVar_list : localVar_list TOK_EOF { $1 }; + pGlobalVar : globalVar TOK_EOF { $1 }; -pLocalVar_list : localVar_list TOK_EOF { $1 }; +pGlobalVar_list : globalVar_list TOK_EOF { $1 }; pVar : var TOK_EOF { $1 }; -pGlobalVar_list : globalVar_list TOK_EOF { $1 }; +pLocalVarParen : localVarParen TOK_EOF { $1 }; + +pGlobalVarParen : globalVarParen TOK_EOF { $1 }; + +pLocalVarParen_list : localVarParen_list TOK_EOF { $1 }; pNamedCallReturn : namedCallReturn TOK_EOF { $1 }; @@ -337,10 +345,6 @@ pExpr1 : expr1 TOK_EOF { $1 }; pExpr2 : expr2 TOK_EOF { $1 }; -pLambdaParen : lambdaParen TOK_EOF { $1 }; - -pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; - pLambdaDef : lambdaDef TOK_EOF { $1 }; pBinOp : binOp TOK_EOF { $1 }; @@ -487,21 +491,34 @@ localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; +localVar_list : localVar { (fun x -> [x]) $1 } + | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + ; + globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; -localVar_list : localVar { (fun x -> [x]) $1 } - | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } +globalVar_list : /* empty */ { [] } + | globalVar { (fun x -> [x]) $1 } + | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; var : localVar { VarLocalVar $1 } | globalVar { VarGlobalVar $1 } ; -globalVar_list : /* empty */ { [] } - | globalVar { (fun x -> [x]) $1 } - | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } +localVarParen : localVar { LocalVarParenLocalVar $1 } + | openParen localIdent SYMB5 typeT closeParen { LocalVarParen1 ($1, $2, $4, $5) } + ; + +globalVarParen : globalVar { GlobalVarParenGlobalVar $1 } + | openParen globalIdent SYMB5 typeT closeParen { GlobalVarParen1 ($1, $2, $4, $5) } + ; + +localVarParen_list : /* empty */ { [] } + | localVarParen { (fun x -> [x]) $1 } + | localVarParen SYMB2 localVarParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } @@ -513,7 +530,7 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } + | KW_var openParen localVarParen_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } ; @@ -535,7 +552,7 @@ jump : KW_goto openParen blockIdent_list closeParen { Jump_GoTo ($2, $3, $4) } | KW_return { Jump_ProcReturn } ; -lVar : KW_var localVar { LVar_Local $2 } +lVar : KW_var localVarParen { LVar_Local $2 } | globalVar { LVar_Global $1 } ; @@ -648,16 +665,7 @@ expr2 : value { Expr_Literal $1 } | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; -lambdaParen : localVar { LambdaParenLocalVar $1 } - | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } - ; - -lambdaParen_list : /* empty */ { [] } - | lambdaParen { (fun x -> [x]) $1 } - | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } - ; - -lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaDef : localVarParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index d1a2ae5e..3d180780 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -257,6 +257,19 @@ and prtVar (i:int) (e : AbsBasilIR.var) : doc = match e with | AbsBasilIR.VarGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) +and prtLocalVarParen (i:int) (e : AbsBasilIR.localVarParen) : doc = match e with + AbsBasilIR.LocalVarParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.LocalVarParen1 (openparen, localident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) + +and prtLocalVarParenListBNFC i es : doc = match (i, es) with + (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtLocalVarParen 0 x]) + | (_,x::xs) -> (concatD [prtLocalVarParen 0 x ; render "," ; prtLocalVarParenListBNFC 0 xs]) +and prtGlobalVarParen (i:int) (e : AbsBasilIR.globalVarParen) : doc = match e with + AbsBasilIR.GlobalVarParenGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) + | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) + + and prtNamedCallReturn (i:int) (e : AbsBasilIR.namedCallReturn) : doc = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render "=" ; prtLocalIdent 0 localident]) @@ -266,7 +279,7 @@ and prtNamedCallReturnListBNFC i es : doc = match (i, es) with | (_,x::xs) -> (concatD [prtNamedCallReturn 0 x ; render "," ; prtNamedCallReturnListBNFC 0 xs]) and prtLVars (i:int) (e : AbsBasilIR.lVars) : doc = match e with AbsBasilIR.LVars_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarListBNFC 0 localvars ; prtCloseParen 0 closeparen ; render ":="]) + | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarParenListBNFC 0 localvarparens ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLVarListBNFC 0 lvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtNamedCallReturnListBNFC 0 namedcallreturns ; prtCloseParen 0 closeparen ; render ":="]) @@ -291,7 +304,7 @@ and prtJump (i:int) (e : AbsBasilIR.jump) : doc = match e with and prtLVar (i:int) (e : AbsBasilIR.lVar) : doc = match e with - AbsBasilIR.LVar_Local localvar -> prPrec i 0 (concatD [render "var" ; prtLocalVar 0 localvar]) + AbsBasilIR.LVar_Local localvarparen -> prPrec i 0 (concatD [render "var" ; prtLocalVarParen 0 localvarparen]) | AbsBasilIR.LVar_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) and prtLVarListBNFC i es : doc = match (i, es) with @@ -392,16 +405,8 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) -and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) - -and prtLambdaParenListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLambdaParen 0 x]) - | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLocalVarParenListBNFC 0 localvarparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 633cd192..7809297a 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -161,13 +161,23 @@ and showVar (e : AbsBasilIR.var) : showable = match e with | AbsBasilIR.VarGlobalVar globalvar -> s2s "VarGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' +and showLocalVarParen (e : AbsBasilIR.localVarParen) : showable = match e with + AbsBasilIR.LocalVarParenLocalVar localvar -> s2s "LocalVarParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.LocalVarParen1 (openparen, localident, type', closeparen) -> s2s "LocalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + +and showGlobalVarParen (e : AbsBasilIR.globalVarParen) : showable = match e with + AbsBasilIR.GlobalVarParenGlobalVar globalvar -> s2s "GlobalVarParenGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' + | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type', closeparen) -> s2s "GlobalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + and showNamedCallReturn (e : AbsBasilIR.namedCallReturn) : showable = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> s2s "NamedCallReturn1" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showLocalIdent localident >> c2s ')' and showLVars (e : AbsBasilIR.lVars) : showable = match e with AbsBasilIR.LVars_Empty -> s2s "LVars_Empty" - | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVar localvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVarParen localvarparens >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> s2s "LVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLVar lvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> s2s "NamedLVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showNamedCallReturn namedcallreturns >> s2s ", " >> showCloseParen closeparen >> c2s ')' @@ -189,7 +199,7 @@ and showJump (e : AbsBasilIR.jump) : showable = match e with and showLVar (e : AbsBasilIR.lVar) : showable = match e with - AbsBasilIR.LVar_Local localvar -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + AbsBasilIR.LVar_Local localvarparen -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVarParen localvarparen >> c2s ')' | AbsBasilIR.LVar_Global globalvar -> s2s "LVar_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' @@ -264,13 +274,8 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' -and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLocalVarParen localvarparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 36fe688a..4e6e4e52 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -181,13 +181,23 @@ and transVar (x : var) : result = match x with | VarGlobalVar globalvar -> failure x +and transLocalVarParen (x : localVarParen) : result = match x with + LocalVarParenLocalVar localvar -> failure x + | LocalVarParen1 (openparen, localident, type', closeparen) -> failure x + + +and transGlobalVarParen (x : globalVarParen) : result = match x with + GlobalVarParenGlobalVar globalvar -> failure x + | GlobalVarParen1 (openparen, globalident, type', closeparen) -> failure x + + and transNamedCallReturn (x : namedCallReturn) : result = match x with NamedCallReturn1 (lvar, localident) -> failure x and transLVars (x : lVars) : result = match x with LVars_Empty -> failure x - | LVars_LocalList (openparen, localvars, closeparen) -> failure x + | LVars_LocalList (openparen, localvarparens, closeparen) -> failure x | LVars_List (openparen, lvars, closeparen) -> failure x | NamedLVars_List (openparen, namedcallreturns, closeparen) -> failure x @@ -209,7 +219,7 @@ and transJump (x : jump) : result = match x with and transLVar (x : lVar) : result = match x with - LVar_Local localvar -> failure x + LVar_Local localvarparen -> failure x | LVar_Global globalvar -> failure x @@ -284,13 +294,8 @@ and transExpr (x : expr) : result = match x with | Expr_Paren (openparen, expr, closeparen) -> failure x -and transLambdaParen (x : lambdaParen) : result = match x with - LambdaParenLocalVar localvar -> failure x - | LambdaParen1 (openparen, localvar, closeparen) -> failure x - - and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x + LambdaDef1 (localvarparens, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index 7c8dc9ff..fb46def4 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -610,15 +610,9 @@ module BasilASTLoader = struct and unpack_local_lvars ?(bound = StringMap.empty) p_st lvs : Var.t list = lvs |> List.map (function - | LocalTyped (i, t) -> + | (LocalVarParenLocalVar (LocalTyped (i, t)) | LocalVarParen1 (_, i, t, _)) -> Var.create ~scope:Local (unsafe_unsigil (`Local i)) (trans_type t) - | LocalUntyped i -> lookup_local_decl ~binds:bound i p_st) - - and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = - unpack_local_lvars ~bound p_st - @@ List.map - (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) - lvs + | LocalVarParenLocalVar (LocalUntyped i) -> lookup_local_decl ~binds:bound i p_st) and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in @@ -636,7 +630,7 @@ module BasilASTLoader = struct and trans_lvar prog (x : BasilIR.AbsBasilIR.lVar) : load_st * Var.t = match x with - | LVar_Local (LocalTyped (bident, type')) -> + | LVar_Local (LocalVarParenLocalVar (LocalTyped (bident, type')) | LocalVarParen1 (_, bident, type', _)) -> assign_var prog (Var.create ~scope:Local (unsafe_unsigil (`Local bident)) @@ -646,7 +640,7 @@ module BasilASTLoader = struct (Var.create (unsafe_unsigil (`Global bident)) (trans_type type') ~scope:Global) - | LVar_Local (LocalUntyped bident) -> + | LVar_Local (LocalVarParenLocalVar (LocalUntyped bident)) -> let v = lookup_local_decl bident prog in assign_var prog v | LVar_Global (GlobalUntyped bident) -> @@ -945,21 +939,21 @@ module BasilASTLoader = struct | Expr_Old (o, e, c) -> BasilExpr.unexp ~attrib:(expr_range_attr o c) ~op:`Old (trans_expr e) | Expr_Forall (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.forall ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Lambda (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.lambda ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Exists (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ac58ab1c..ef282c54 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -186,6 +186,13 @@ module.exports = grammar({ // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), + list_LocalVar: $ => + choice( + // (:[]). [LocalVar] ::= LocalVar ; + $.LocalVar, + // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; + seq($.LocalVar, ",", $.list_LocalVar) + ), GlobalVar: $ => choice( // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; @@ -193,12 +200,14 @@ module.exports = grammar({ // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), - list_LocalVar: $ => + list_GlobalVar: $ => choice( - // (:[]). [LocalVar] ::= LocalVar ; - $.LocalVar, - // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; - seq($.LocalVar, ",", $.list_LocalVar) + // []. [GlobalVar] ::= ; + choice(), + // (:[]). [GlobalVar] ::= GlobalVar ; + $.GlobalVar, + // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; + seq($.GlobalVar, ",", optional($.list_GlobalVar)) ), Var: $ => choice( @@ -207,14 +216,28 @@ module.exports = grammar({ // VarGlobalVar. Var ::= GlobalVar ; $.GlobalVar ), - list_GlobalVar: $ => + LocalVarParen: $ => choice( - // []. [GlobalVar] ::= ; - choice(), - // (:[]). [GlobalVar] ::= GlobalVar ; + // LocalVarParenLocalVar. LocalVarParen ::= LocalVar ; + $.LocalVar, + // LocalVarParen1. LocalVarParen ::= OpenParen LocalIdent ":" Type CloseParen ; + seq($.token_OpenParen, $.token_LocalIdent, ":", $.Type, $.token_CloseParen) + ), + GlobalVarParen: $ => + choice( + // GlobalVarParenGlobalVar. GlobalVarParen ::= GlobalVar ; $.GlobalVar, - // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; - seq($.GlobalVar, ",", optional($.list_GlobalVar)) + // GlobalVarParen1. GlobalVarParen ::= OpenParen GlobalIdent ":" Type CloseParen ; + seq($.token_OpenParen, $.token_GlobalIdent, ":", $.Type, $.token_CloseParen) + ), + list_LocalVarParen: $ => + choice( + // []. [LocalVarParen] ::= ; + choice(), + // (:[]). [LocalVarParen] ::= LocalVarParen ; + $.LocalVarParen, + // (:). [LocalVarParen] ::= LocalVarParen "," [LocalVarParen] ; + seq($.LocalVarParen, ",", optional($.list_LocalVarParen)) ), NamedCallReturn: $ => // NamedCallReturn1. NamedCallReturn ::= LVar "=" LocalIdent ; @@ -232,8 +255,8 @@ module.exports = grammar({ choice( // LVars_Empty. LVars ::= ; choice(), - // LVars_LocalList. LVars ::= "var" OpenParen [LocalVar] CloseParen ":=" ; - seq("var", $.token_OpenParen, $.list_LocalVar, $.token_CloseParen, ":="), + // LVars_LocalList. LVars ::= "var" OpenParen [LocalVarParen] CloseParen ":=" ; + seq("var", $.token_OpenParen, optional($.list_LocalVarParen), $.token_CloseParen, ":="), // LVars_List. LVars ::= OpenParen [LVar] CloseParen ":=" ; seq($.token_OpenParen, $.list_LVar, $.token_CloseParen, ":="), // NamedLVars_List. LVars ::= OpenParen [NamedCallReturn] CloseParen ":=" ; @@ -269,8 +292,8 @@ module.exports = grammar({ ), LVar: $ => choice( - // LVar_Local. LVar ::= "var" LocalVar ; - seq("var", $.LocalVar), + // LVar_Local. LVar ::= "var" LocalVarParen ; + seq("var", $.LocalVarParen), // LVar_Global. LVar ::= GlobalVar ; $.GlobalVar ), @@ -458,25 +481,9 @@ module.exports = grammar({ // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), - LambdaParen: $ => - choice( - // LambdaParenLocalVar. LambdaParen ::= LocalVar ; - $.LocalVar, - // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; - seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) - ), - list_LambdaParen: $ => - choice( - // []. [LambdaParen] ::= ; - choice(), - // (:[]). [LambdaParen] ::= LambdaParen ; - $.LambdaParen, - // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; - seq($.LambdaParen, ",", optional($.list_LambdaParen)) - ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; - seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LocalVarParen] LambdaSep Expr ; + seq(optional($.list_LocalVarParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From 4f9ebbb67d79d127d91c68f8228f99f6f98c5559 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:26:07 +1000 Subject: [PATCH 39/43] Revert "stash" This reverts commit 54cd3c9d50d6d87053d49459bbc63cf41e6883f6. --- lib/fe/AbsBasilIR.ml | 18 ++++------- lib/fe/BasilIR.cf | 20 +++++------- lib/fe/ParBasilIR.mly | 72 ++++++++++++++++++----------------------- lib/fe/PrintBasilIR.ml | 27 +++++++--------- lib/fe/ShowBasilIR.ml | 21 +++++------- lib/fe/SkelBasilIR.ml | 21 +++++------- lib/loadir.ml | 20 ++++++++---- tree-sitter/grammar.js | 73 +++++++++++++++++++----------------------- 8 files changed, 120 insertions(+), 152 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 3a0093d5..a280c6cd 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -104,20 +104,12 @@ and var = VarLocalVar of localVar | VarGlobalVar of globalVar -and localVarParen = - LocalVarParenLocalVar of localVar - | LocalVarParen1 of openParen * localIdent * typeT * closeParen - -and globalVarParen = - GlobalVarParenGlobalVar of globalVar - | GlobalVarParen1 of openParen * globalIdent * typeT * closeParen - and namedCallReturn = NamedCallReturn1 of lVar * localIdent and lVars = LVars_Empty - | LVars_LocalList of openParen * localVarParen list * closeParen + | LVars_LocalList of openParen * localVar list * closeParen | LVars_List of openParen * lVar list * closeParen | NamedLVars_List of openParen * namedCallReturn list * closeParen @@ -135,7 +127,7 @@ and jump = | Jump_ProcReturn and lVar = - LVar_Local of localVarParen + LVar_Local of localVar | LVar_Global of globalVar and stmtWithAttrib = @@ -198,8 +190,12 @@ and expr = | Expr_Cases of openParen * case list * closeParen | Expr_Paren of openParen * expr * closeParen +and lambdaParen = + LambdaParenLocalVar of localVar + | LambdaParen1 of openParen * localVar * closeParen + and lambdaDef = - LambdaDef1 of localVarParen list * lambdaSep * expr + LambdaDef1 of lambdaParen list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index a7130c52..d5670f7e 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -97,20 +97,13 @@ Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; LocalUntyped . LocalVar ::= LocalIdent ; -separator nonempty LocalVar ","; GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; GlobalUntyped . GlobalVar ::= GlobalIdent; -separator GlobalVar ","; - +separator nonempty LocalVar ","; rules Var ::= LocalVar | GlobalVar ; --- Variant of LocalVar / GlobalVar which can be wrapped in parens and --- can contain any type. -rules LocalVarParen ::= LocalVar | OpenParen LocalIdent ":" Type CloseParen ; -rules GlobalVarParen ::= GlobalVar | OpenParen GlobalIdent ":" Type CloseParen ; -separator LocalVarParen ","; - +separator GlobalVar ","; -- lvar endian mem addr size Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; @@ -123,7 +116,7 @@ rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; LVars_Empty . LVars ::= ; -LVars_LocalList . LVars ::= "var" OpenParen [ LocalVarParen ] CloseParen ":=" ; +LVars_LocalList . LVars ::= "var" OpenParen [ LocalVar ] CloseParen ":=" ; LVars_List . LVars ::= OpenParen [ LVar ] CloseParen ":="; NamedLVars_List . LVars ::= OpenParen [NamedCallReturn] CloseParen ":="; @@ -145,7 +138,7 @@ Jump_Unreachable . Jump ::= "unreachable" ; Jump_Return . Jump ::= "return" OpenParen [Expr] CloseParen ; Jump_ProcReturn. Jump ::= "return" ; -LVar_Local . LVar ::= "var" LocalVarParen; +LVar_Local . LVar ::= "var" LocalVar; LVar_Global . LVar ::= GlobalVar; separator nonempty LVar "," ; @@ -215,7 +208,10 @@ Expr_Global . Expr2 ::= GlobalVar; -- quantifiers -rules LambdaDef ::= [LocalVarParen] LambdaSep Expr ; +rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; +separator LambdaParen ","; + +rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 4b1581d8..dd887b98 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pLocalVar_list pGlobalVar pGlobalVar_list pVar pLocalVarParen pGlobalVarParen pLocalVarParen_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -67,13 +67,10 @@ open Lexing %type pStmt %type pAssignment_list %type pLocalVar -%type pLocalVar_list %type pGlobalVar -%type pGlobalVar_list +%type pLocalVar_list %type pVar -%type pLocalVarParen -%type pGlobalVarParen -%type pLocalVarParen_list +%type pGlobalVar_list %type pNamedCallReturn %type pNamedCallReturn_list %type pLVars @@ -104,6 +101,8 @@ open Lexing %type pExpr %type pExpr1 %type pExpr2 +%type pLambdaParen +%type pLambdaParen_list %type pLambdaDef %type pBinOp %type pUnOp @@ -148,13 +147,10 @@ open Lexing %type stmt %type assignment_list %type localVar -%type localVar_list %type globalVar -%type globalVar_list +%type localVar_list %type var -%type localVarParen -%type globalVarParen -%type localVarParen_list +%type globalVar_list %type namedCallReturn %type namedCallReturn_list %type lVars @@ -185,6 +181,8 @@ open Lexing %type expr %type expr1 %type expr2 +%type lambdaParen +%type lambdaParen_list %type lambdaDef %type binOp %type unOp @@ -271,19 +269,13 @@ pAssignment_list : assignment_list TOK_EOF { $1 }; pLocalVar : localVar TOK_EOF { $1 }; -pLocalVar_list : localVar_list TOK_EOF { $1 }; - pGlobalVar : globalVar TOK_EOF { $1 }; -pGlobalVar_list : globalVar_list TOK_EOF { $1 }; +pLocalVar_list : localVar_list TOK_EOF { $1 }; pVar : var TOK_EOF { $1 }; -pLocalVarParen : localVarParen TOK_EOF { $1 }; - -pGlobalVarParen : globalVarParen TOK_EOF { $1 }; - -pLocalVarParen_list : localVarParen_list TOK_EOF { $1 }; +pGlobalVar_list : globalVar_list TOK_EOF { $1 }; pNamedCallReturn : namedCallReturn TOK_EOF { $1 }; @@ -345,6 +337,10 @@ pExpr1 : expr1 TOK_EOF { $1 }; pExpr2 : expr2 TOK_EOF { $1 }; +pLambdaParen : lambdaParen TOK_EOF { $1 }; + +pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; + pLambdaDef : lambdaDef TOK_EOF { $1 }; pBinOp : binOp TOK_EOF { $1 }; @@ -491,34 +487,21 @@ localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; -localVar_list : localVar { (fun x -> [x]) $1 } - | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } - ; - globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; -globalVar_list : /* empty */ { [] } - | globalVar { (fun x -> [x]) $1 } - | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } +localVar_list : localVar { (fun x -> [x]) $1 } + | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; var : localVar { VarLocalVar $1 } | globalVar { VarGlobalVar $1 } ; -localVarParen : localVar { LocalVarParenLocalVar $1 } - | openParen localIdent SYMB5 typeT closeParen { LocalVarParen1 ($1, $2, $4, $5) } - ; - -globalVarParen : globalVar { GlobalVarParenGlobalVar $1 } - | openParen globalIdent SYMB5 typeT closeParen { GlobalVarParen1 ($1, $2, $4, $5) } - ; - -localVarParen_list : /* empty */ { [] } - | localVarParen { (fun x -> [x]) $1 } - | localVarParen SYMB2 localVarParen_list { (fun (x,xs) -> x::xs) ($1, $3) } +globalVar_list : /* empty */ { [] } + | globalVar { (fun x -> [x]) $1 } + | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } @@ -530,7 +513,7 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVarParen_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } + | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } ; @@ -552,7 +535,7 @@ jump : KW_goto openParen blockIdent_list closeParen { Jump_GoTo ($2, $3, $4) } | KW_return { Jump_ProcReturn } ; -lVar : KW_var localVarParen { LVar_Local $2 } +lVar : KW_var localVar { LVar_Local $2 } | globalVar { LVar_Global $1 } ; @@ -665,7 +648,16 @@ expr2 : value { Expr_Literal $1 } | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; -lambdaDef : localVarParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaParen : localVar { LambdaParenLocalVar $1 } + | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } + ; + +lambdaParen_list : /* empty */ { [] } + | lambdaParen { (fun x -> [x]) $1 } + | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } + ; + +lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 3d180780..d1a2ae5e 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -257,19 +257,6 @@ and prtVar (i:int) (e : AbsBasilIR.var) : doc = match e with | AbsBasilIR.VarGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) -and prtLocalVarParen (i:int) (e : AbsBasilIR.localVarParen) : doc = match e with - AbsBasilIR.LocalVarParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.LocalVarParen1 (openparen, localident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) - -and prtLocalVarParenListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLocalVarParen 0 x]) - | (_,x::xs) -> (concatD [prtLocalVarParen 0 x ; render "," ; prtLocalVarParenListBNFC 0 xs]) -and prtGlobalVarParen (i:int) (e : AbsBasilIR.globalVarParen) : doc = match e with - AbsBasilIR.GlobalVarParenGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) - | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) - - and prtNamedCallReturn (i:int) (e : AbsBasilIR.namedCallReturn) : doc = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render "=" ; prtLocalIdent 0 localident]) @@ -279,7 +266,7 @@ and prtNamedCallReturnListBNFC i es : doc = match (i, es) with | (_,x::xs) -> (concatD [prtNamedCallReturn 0 x ; render "," ; prtNamedCallReturnListBNFC 0 xs]) and prtLVars (i:int) (e : AbsBasilIR.lVars) : doc = match e with AbsBasilIR.LVars_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarParenListBNFC 0 localvarparens ; prtCloseParen 0 closeparen ; render ":="]) + | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarListBNFC 0 localvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLVarListBNFC 0 lvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtNamedCallReturnListBNFC 0 namedcallreturns ; prtCloseParen 0 closeparen ; render ":="]) @@ -304,7 +291,7 @@ and prtJump (i:int) (e : AbsBasilIR.jump) : doc = match e with and prtLVar (i:int) (e : AbsBasilIR.lVar) : doc = match e with - AbsBasilIR.LVar_Local localvarparen -> prPrec i 0 (concatD [render "var" ; prtLocalVarParen 0 localvarparen]) + AbsBasilIR.LVar_Local localvar -> prPrec i 0 (concatD [render "var" ; prtLocalVar 0 localvar]) | AbsBasilIR.LVar_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) and prtLVarListBNFC i es : doc = match (i, es) with @@ -405,8 +392,16 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) +and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) + +and prtLambdaParenListBNFC i es : doc = match (i, es) with + (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtLambdaParen 0 x]) + | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLocalVarParenListBNFC 0 localvarparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 7809297a..633cd192 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -161,23 +161,13 @@ and showVar (e : AbsBasilIR.var) : showable = match e with | AbsBasilIR.VarGlobalVar globalvar -> s2s "VarGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' -and showLocalVarParen (e : AbsBasilIR.localVarParen) : showable = match e with - AbsBasilIR.LocalVarParenLocalVar localvar -> s2s "LocalVarParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.LocalVarParen1 (openparen, localident, type', closeparen) -> s2s "LocalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - -and showGlobalVarParen (e : AbsBasilIR.globalVarParen) : showable = match e with - AbsBasilIR.GlobalVarParenGlobalVar globalvar -> s2s "GlobalVarParenGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' - | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type', closeparen) -> s2s "GlobalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showNamedCallReturn (e : AbsBasilIR.namedCallReturn) : showable = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> s2s "NamedCallReturn1" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showLocalIdent localident >> c2s ')' and showLVars (e : AbsBasilIR.lVars) : showable = match e with AbsBasilIR.LVars_Empty -> s2s "LVars_Empty" - | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVarParen localvarparens >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVar localvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> s2s "LVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLVar lvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> s2s "NamedLVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showNamedCallReturn namedcallreturns >> s2s ", " >> showCloseParen closeparen >> c2s ')' @@ -199,7 +189,7 @@ and showJump (e : AbsBasilIR.jump) : showable = match e with and showLVar (e : AbsBasilIR.lVar) : showable = match e with - AbsBasilIR.LVar_Local localvarparen -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVarParen localvarparen >> c2s ')' + AbsBasilIR.LVar_Local localvar -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' | AbsBasilIR.LVar_Global globalvar -> s2s "LVar_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' @@ -274,8 +264,13 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' +and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLocalVarParen localvarparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 4e6e4e52..36fe688a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -181,23 +181,13 @@ and transVar (x : var) : result = match x with | VarGlobalVar globalvar -> failure x -and transLocalVarParen (x : localVarParen) : result = match x with - LocalVarParenLocalVar localvar -> failure x - | LocalVarParen1 (openparen, localident, type', closeparen) -> failure x - - -and transGlobalVarParen (x : globalVarParen) : result = match x with - GlobalVarParenGlobalVar globalvar -> failure x - | GlobalVarParen1 (openparen, globalident, type', closeparen) -> failure x - - and transNamedCallReturn (x : namedCallReturn) : result = match x with NamedCallReturn1 (lvar, localident) -> failure x and transLVars (x : lVars) : result = match x with LVars_Empty -> failure x - | LVars_LocalList (openparen, localvarparens, closeparen) -> failure x + | LVars_LocalList (openparen, localvars, closeparen) -> failure x | LVars_List (openparen, lvars, closeparen) -> failure x | NamedLVars_List (openparen, namedcallreturns, closeparen) -> failure x @@ -219,7 +209,7 @@ and transJump (x : jump) : result = match x with and transLVar (x : lVar) : result = match x with - LVar_Local localvarparen -> failure x + LVar_Local localvar -> failure x | LVar_Global globalvar -> failure x @@ -294,8 +284,13 @@ and transExpr (x : expr) : result = match x with | Expr_Paren (openparen, expr, closeparen) -> failure x +and transLambdaParen (x : lambdaParen) : result = match x with + LambdaParenLocalVar localvar -> failure x + | LambdaParen1 (openparen, localvar, closeparen) -> failure x + + and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (localvarparens, lambdasep, expr) -> failure x + LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index fb46def4..7c8dc9ff 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -610,9 +610,15 @@ module BasilASTLoader = struct and unpack_local_lvars ?(bound = StringMap.empty) p_st lvs : Var.t list = lvs |> List.map (function - | (LocalVarParenLocalVar (LocalTyped (i, t)) | LocalVarParen1 (_, i, t, _)) -> + | LocalTyped (i, t) -> Var.create ~scope:Local (unsafe_unsigil (`Local i)) (trans_type t) - | LocalVarParenLocalVar (LocalUntyped i) -> lookup_local_decl ~binds:bound i p_st) + | LocalUntyped i -> lookup_local_decl ~binds:bound i p_st) + + and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = + unpack_local_lvars ~bound p_st + @@ List.map + (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) + lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in @@ -630,7 +636,7 @@ module BasilASTLoader = struct and trans_lvar prog (x : BasilIR.AbsBasilIR.lVar) : load_st * Var.t = match x with - | LVar_Local (LocalVarParenLocalVar (LocalTyped (bident, type')) | LocalVarParen1 (_, bident, type', _)) -> + | LVar_Local (LocalTyped (bident, type')) -> assign_var prog (Var.create ~scope:Local (unsafe_unsigil (`Local bident)) @@ -640,7 +646,7 @@ module BasilASTLoader = struct (Var.create (unsafe_unsigil (`Global bident)) (trans_type type') ~scope:Global) - | LVar_Local (LocalVarParenLocalVar (LocalUntyped bident)) -> + | LVar_Local (LocalUntyped bident) -> let v = lookup_local_decl bident prog in assign_var prog v | LVar_Global (GlobalUntyped bident) -> @@ -939,21 +945,21 @@ module BasilASTLoader = struct | Expr_Old (o, e, c) -> BasilExpr.unexp ~attrib:(expr_range_attr o c) ~op:`Old (trans_expr e) | Expr_Forall (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.forall ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Lambda (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.lambda ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Exists (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ef282c54..ac58ab1c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -186,13 +186,6 @@ module.exports = grammar({ // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), - list_LocalVar: $ => - choice( - // (:[]). [LocalVar] ::= LocalVar ; - $.LocalVar, - // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; - seq($.LocalVar, ",", $.list_LocalVar) - ), GlobalVar: $ => choice( // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; @@ -200,14 +193,12 @@ module.exports = grammar({ // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), - list_GlobalVar: $ => + list_LocalVar: $ => choice( - // []. [GlobalVar] ::= ; - choice(), - // (:[]). [GlobalVar] ::= GlobalVar ; - $.GlobalVar, - // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; - seq($.GlobalVar, ",", optional($.list_GlobalVar)) + // (:[]). [LocalVar] ::= LocalVar ; + $.LocalVar, + // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; + seq($.LocalVar, ",", $.list_LocalVar) ), Var: $ => choice( @@ -216,28 +207,14 @@ module.exports = grammar({ // VarGlobalVar. Var ::= GlobalVar ; $.GlobalVar ), - LocalVarParen: $ => - choice( - // LocalVarParenLocalVar. LocalVarParen ::= LocalVar ; - $.LocalVar, - // LocalVarParen1. LocalVarParen ::= OpenParen LocalIdent ":" Type CloseParen ; - seq($.token_OpenParen, $.token_LocalIdent, ":", $.Type, $.token_CloseParen) - ), - GlobalVarParen: $ => - choice( - // GlobalVarParenGlobalVar. GlobalVarParen ::= GlobalVar ; - $.GlobalVar, - // GlobalVarParen1. GlobalVarParen ::= OpenParen GlobalIdent ":" Type CloseParen ; - seq($.token_OpenParen, $.token_GlobalIdent, ":", $.Type, $.token_CloseParen) - ), - list_LocalVarParen: $ => + list_GlobalVar: $ => choice( - // []. [LocalVarParen] ::= ; + // []. [GlobalVar] ::= ; choice(), - // (:[]). [LocalVarParen] ::= LocalVarParen ; - $.LocalVarParen, - // (:). [LocalVarParen] ::= LocalVarParen "," [LocalVarParen] ; - seq($.LocalVarParen, ",", optional($.list_LocalVarParen)) + // (:[]). [GlobalVar] ::= GlobalVar ; + $.GlobalVar, + // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; + seq($.GlobalVar, ",", optional($.list_GlobalVar)) ), NamedCallReturn: $ => // NamedCallReturn1. NamedCallReturn ::= LVar "=" LocalIdent ; @@ -255,8 +232,8 @@ module.exports = grammar({ choice( // LVars_Empty. LVars ::= ; choice(), - // LVars_LocalList. LVars ::= "var" OpenParen [LocalVarParen] CloseParen ":=" ; - seq("var", $.token_OpenParen, optional($.list_LocalVarParen), $.token_CloseParen, ":="), + // LVars_LocalList. LVars ::= "var" OpenParen [LocalVar] CloseParen ":=" ; + seq("var", $.token_OpenParen, $.list_LocalVar, $.token_CloseParen, ":="), // LVars_List. LVars ::= OpenParen [LVar] CloseParen ":=" ; seq($.token_OpenParen, $.list_LVar, $.token_CloseParen, ":="), // NamedLVars_List. LVars ::= OpenParen [NamedCallReturn] CloseParen ":=" ; @@ -292,8 +269,8 @@ module.exports = grammar({ ), LVar: $ => choice( - // LVar_Local. LVar ::= "var" LocalVarParen ; - seq("var", $.LocalVarParen), + // LVar_Local. LVar ::= "var" LocalVar ; + seq("var", $.LocalVar), // LVar_Global. LVar ::= GlobalVar ; $.GlobalVar ), @@ -481,9 +458,25 @@ module.exports = grammar({ // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), + LambdaParen: $ => + choice( + // LambdaParenLocalVar. LambdaParen ::= LocalVar ; + $.LocalVar, + // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; + seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) + ), + list_LambdaParen: $ => + choice( + // []. [LambdaParen] ::= ; + choice(), + // (:[]). [LambdaParen] ::= LambdaParen ; + $.LambdaParen, + // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; + seq($.LambdaParen, ",", optional($.list_LambdaParen)) + ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LocalVarParen] LambdaSep Expr ; - seq(optional($.list_LocalVarParen), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; + seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From 9261230abf4af3fe03946ce1ee0fa2a97b382ce4 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:30:48 +1000 Subject: [PATCH 40/43] i'm going to crash out. we need a non total order of precedence --- lib/fe/AbsBasilIR.ml | 9 +++++---- lib/fe/BasilIR.cf | 10 +++++----- lib/fe/ParBasilIR.mly | 31 ++++++++++++++++--------------- lib/fe/PrintBasilIR.ml | 19 ++++++++++--------- lib/fe/ShowBasilIR.ml | 9 +++++---- lib/fe/SkelBasilIR.ml | 9 +++++---- lib/loadir.ml | 4 +++- tree-sitter/grammar.js | 34 ++++++++++++++++++---------------- 8 files changed, 67 insertions(+), 58 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index a280c6cd..ecdb30b9 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -190,12 +190,13 @@ and expr = | Expr_Cases of openParen * case list * closeParen | Expr_Paren of openParen * expr * closeParen -and lambdaParen = - LambdaParenLocalVar of localVar - | LambdaParen1 of openParen * localVar * closeParen +and lambdaParam = + LambdaParamLocalIdent of localIdent + | LambdaParam1 of localIdent * typeT + | LambdaParam2 of openParen * localVar * closeParen and lambdaDef = - LambdaDef1 of lambdaParen list * lambdaSep * expr + LambdaDef1 of lambdaParam list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index d5670f7e..015606d0 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -95,10 +95,10 @@ separator nonempty Assignment ","; Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; -LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; +LocalTyped . LocalVar ::= LocalIdent ":" Type ; LocalUntyped . LocalVar ::= LocalIdent ; -GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; +GlobalTyped . GlobalVar ::= GlobalIdent ":" Type ; GlobalUntyped . GlobalVar ::= GlobalIdent; separator nonempty LocalVar ","; rules Var ::= LocalVar | GlobalVar ; @@ -208,10 +208,10 @@ Expr_Global . Expr2 ::= GlobalVar; -- quantifiers -rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; -separator LambdaParen ","; +rules LambdaParam ::= LocalIdent | LocalIdent ":" Type1 | OpenParen LocalVar CloseParen ; +separator LambdaParam ","; -rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; +rules LambdaDef ::= [LambdaParam] LambdaSep Expr ; Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index dd887b98..993dc6d2 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParam pLambdaParam_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -101,8 +101,8 @@ open Lexing %type pExpr %type pExpr1 %type pExpr2 -%type pLambdaParen -%type pLambdaParen_list +%type pLambdaParam +%type pLambdaParam_list %type pLambdaDef %type pBinOp %type pUnOp @@ -181,8 +181,8 @@ open Lexing %type expr %type expr1 %type expr2 -%type lambdaParen -%type lambdaParen_list +%type lambdaParam +%type lambdaParam_list %type lambdaDef %type binOp %type unOp @@ -337,9 +337,9 @@ pExpr1 : expr1 TOK_EOF { $1 }; pExpr2 : expr2 TOK_EOF { $1 }; -pLambdaParen : lambdaParen TOK_EOF { $1 }; +pLambdaParam : lambdaParam TOK_EOF { $1 }; -pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; +pLambdaParam_list : lambdaParam_list TOK_EOF { $1 }; pLambdaDef : lambdaDef TOK_EOF { $1 }; @@ -483,11 +483,11 @@ assignment_list : assignment { (fun x -> [x]) $1 } | assignment SYMB2 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } +localVar : localIdent SYMB5 typeT { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; -globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } +globalVar : globalIdent SYMB5 typeT { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; @@ -648,16 +648,17 @@ expr2 : value { Expr_Literal $1 } | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; -lambdaParen : localVar { LambdaParenLocalVar $1 } - | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } +lambdaParam : localIdent { LambdaParamLocalIdent $1 } + | localIdent SYMB5 type1 { LambdaParam1 ($1, $3) } + | openParen localVar closeParen { LambdaParam2 ($1, $2, $3) } ; -lambdaParen_list : /* empty */ { [] } - | lambdaParen { (fun x -> [x]) $1 } - | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } +lambdaParam_list : /* empty */ { [] } + | lambdaParam { (fun x -> [x]) $1 } + | lambdaParam SYMB2 lambdaParam_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaDef : lambdaParam_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index d1a2ae5e..608b8ef6 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -237,7 +237,7 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with and prtLocalVar (i:int) (e : AbsBasilIR.localVar) : doc = match e with - AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 1 type_]) + AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_]) | AbsBasilIR.LocalUntyped localident -> prPrec i 0 (concatD [prtLocalIdent 0 localident]) and prtLocalVarListBNFC i es : doc = match (i, es) with @@ -245,7 +245,7 @@ and prtLocalVarListBNFC i es : doc = match (i, es) with | (_,[x]) -> (concatD [prtLocalVar 0 x]) | (_,x::xs) -> (concatD [prtLocalVar 0 x ; render "," ; prtLocalVarListBNFC 0 xs]) and prtGlobalVar (i:int) (e : AbsBasilIR.globalVar) : doc = match e with - AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 1 type_]) + AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_]) | AbsBasilIR.GlobalUntyped globalident -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident]) and prtGlobalVarListBNFC i es : doc = match (i, es) with @@ -392,16 +392,17 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) -and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) +and prtLambdaParam (i:int) (e : AbsBasilIR.lambdaParam) : doc = match e with + AbsBasilIR.LambdaParamLocalIdent localident -> prPrec i 0 (concatD [prtLocalIdent 0 localident]) + | AbsBasilIR.LambdaParam1 (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 1 type_]) + | AbsBasilIR.LambdaParam2 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) -and prtLambdaParenListBNFC i es : doc = match (i, es) with +and prtLambdaParamListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLambdaParen 0 x]) - | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) + | (_,[x]) -> (concatD [prtLambdaParam 0 x]) + | (_,x::xs) -> (concatD [prtLambdaParam 0 x ; render "," ; prtLambdaParamListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (lambdaparams, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParamListBNFC 0 lambdaparams ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 633cd192..97600819 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -264,13 +264,14 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' -and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' +and showLambdaParam (e : AbsBasilIR.lambdaParam) : showable = match e with + AbsBasilIR.LambdaParamLocalIdent localident -> s2s "LambdaParamLocalIdent" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> c2s ')' + | AbsBasilIR.LambdaParam1 (localident, type') -> s2s "LambdaParam1" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> c2s ')' + | AbsBasilIR.LambdaParam2 (openparen, localvar, closeparen) -> s2s "LambdaParam2" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (lambdaparams, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParam lambdaparams >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 36fe688a..59763f83 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -284,13 +284,14 @@ and transExpr (x : expr) : result = match x with | Expr_Paren (openparen, expr, closeparen) -> failure x -and transLambdaParen (x : lambdaParen) : result = match x with - LambdaParenLocalVar localvar -> failure x - | LambdaParen1 (openparen, localvar, closeparen) -> failure x +and transLambdaParam (x : lambdaParam) : result = match x with + LambdaParamLocalIdent localident -> failure x + | LambdaParam1 (localident, type') -> failure x + | LambdaParam2 (openparen, localvar, closeparen) -> failure x and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x + LambdaDef1 (lambdaparams, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index 7c8dc9ff..ae43dd07 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -617,7 +617,9 @@ module BasilASTLoader = struct and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = unpack_local_lvars ~bound p_st @@ List.map - (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) + (function LambdaParamLocalIdent v -> LocalUntyped v + | LambdaParam1 (i, t) -> LocalTyped (i, t) + | LambdaParam2 (_, v, _) -> v) lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ac58ab1c..34f9f802 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -181,15 +181,15 @@ module.exports = grammar({ ), LocalVar: $ => choice( - // LocalTyped. LocalVar ::= LocalIdent ":" Type1 ; - seq($.token_LocalIdent, ":", $.Type1), + // LocalTyped. LocalVar ::= LocalIdent ":" Type ; + seq($.token_LocalIdent, ":", $.Type), // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), GlobalVar: $ => choice( - // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; - seq($.token_GlobalIdent, ":", $.Type1), + // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type ; + seq($.token_GlobalIdent, ":", $.Type), // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), @@ -458,25 +458,27 @@ module.exports = grammar({ // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), - LambdaParen: $ => + LambdaParam: $ => choice( - // LambdaParenLocalVar. LambdaParen ::= LocalVar ; - $.LocalVar, - // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; + // LambdaParamLocalIdent. LambdaParam ::= LocalIdent ; + $.token_LocalIdent, + // LambdaParam1. LambdaParam ::= LocalIdent ":" Type1 ; + seq($.token_LocalIdent, ":", $.Type1), + // LambdaParam2. LambdaParam ::= OpenParen LocalVar CloseParen ; seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) ), - list_LambdaParen: $ => + list_LambdaParam: $ => choice( - // []. [LambdaParen] ::= ; + // []. [LambdaParam] ::= ; choice(), - // (:[]). [LambdaParen] ::= LambdaParen ; - $.LambdaParen, - // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; - seq($.LambdaParen, ",", optional($.list_LambdaParen)) + // (:[]). [LambdaParam] ::= LambdaParam ; + $.LambdaParam, + // (:). [LambdaParam] ::= LambdaParam "," [LambdaParam] ; + seq($.LambdaParam, ",", optional($.list_LambdaParam)) ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; - seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LambdaParam] LambdaSep Expr ; + seq(optional($.list_LambdaParam), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From 734025620a6530a6db8e8d8704b022343efd4bdd Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:33:59 +1000 Subject: [PATCH 41/43] Revert "i'm going to crash out. we need a non total order of precedence" This reverts commit 9261230abf4af3fe03946ce1ee0fa2a97b382ce4. --- lib/fe/AbsBasilIR.ml | 9 ++++----- lib/fe/BasilIR.cf | 10 +++++----- lib/fe/ParBasilIR.mly | 31 +++++++++++++++---------------- lib/fe/PrintBasilIR.ml | 19 +++++++++---------- lib/fe/ShowBasilIR.ml | 9 ++++----- lib/fe/SkelBasilIR.ml | 9 ++++----- lib/loadir.ml | 4 +--- tree-sitter/grammar.js | 34 ++++++++++++++++------------------ 8 files changed, 58 insertions(+), 67 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index ecdb30b9..a280c6cd 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -190,13 +190,12 @@ and expr = | Expr_Cases of openParen * case list * closeParen | Expr_Paren of openParen * expr * closeParen -and lambdaParam = - LambdaParamLocalIdent of localIdent - | LambdaParam1 of localIdent * typeT - | LambdaParam2 of openParen * localVar * closeParen +and lambdaParen = + LambdaParenLocalVar of localVar + | LambdaParen1 of openParen * localVar * closeParen and lambdaDef = - LambdaDef1 of lambdaParam list * lambdaSep * expr + LambdaDef1 of lambdaParen list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index 015606d0..d5670f7e 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -95,10 +95,10 @@ separator nonempty Assignment ","; Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; -LocalTyped . LocalVar ::= LocalIdent ":" Type ; +LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; LocalUntyped . LocalVar ::= LocalIdent ; -GlobalTyped . GlobalVar ::= GlobalIdent ":" Type ; +GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; GlobalUntyped . GlobalVar ::= GlobalIdent; separator nonempty LocalVar ","; rules Var ::= LocalVar | GlobalVar ; @@ -208,10 +208,10 @@ Expr_Global . Expr2 ::= GlobalVar; -- quantifiers -rules LambdaParam ::= LocalIdent | LocalIdent ":" Type1 | OpenParen LocalVar CloseParen ; -separator LambdaParam ","; +rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; +separator LambdaParen ","; -rules LambdaDef ::= [LambdaParam] LambdaSep Expr ; +rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 993dc6d2..dd887b98 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParam pLambdaParam_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -101,8 +101,8 @@ open Lexing %type pExpr %type pExpr1 %type pExpr2 -%type pLambdaParam -%type pLambdaParam_list +%type pLambdaParen +%type pLambdaParen_list %type pLambdaDef %type pBinOp %type pUnOp @@ -181,8 +181,8 @@ open Lexing %type expr %type expr1 %type expr2 -%type lambdaParam -%type lambdaParam_list +%type lambdaParen +%type lambdaParen_list %type lambdaDef %type binOp %type unOp @@ -337,9 +337,9 @@ pExpr1 : expr1 TOK_EOF { $1 }; pExpr2 : expr2 TOK_EOF { $1 }; -pLambdaParam : lambdaParam TOK_EOF { $1 }; +pLambdaParen : lambdaParen TOK_EOF { $1 }; -pLambdaParam_list : lambdaParam_list TOK_EOF { $1 }; +pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; pLambdaDef : lambdaDef TOK_EOF { $1 }; @@ -483,11 +483,11 @@ assignment_list : assignment { (fun x -> [x]) $1 } | assignment SYMB2 assignment_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -localVar : localIdent SYMB5 typeT { LocalTyped ($1, $3) } +localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; -globalVar : globalIdent SYMB5 typeT { GlobalTyped ($1, $3) } +globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; @@ -648,17 +648,16 @@ expr2 : value { Expr_Literal $1 } | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; -lambdaParam : localIdent { LambdaParamLocalIdent $1 } - | localIdent SYMB5 type1 { LambdaParam1 ($1, $3) } - | openParen localVar closeParen { LambdaParam2 ($1, $2, $3) } +lambdaParen : localVar { LambdaParenLocalVar $1 } + | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } ; -lambdaParam_list : /* empty */ { [] } - | lambdaParam { (fun x -> [x]) $1 } - | lambdaParam SYMB2 lambdaParam_list { (fun (x,xs) -> x::xs) ($1, $3) } +lambdaParen_list : /* empty */ { [] } + | lambdaParen { (fun x -> [x]) $1 } + | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; -lambdaDef : lambdaParam_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 608b8ef6..d1a2ae5e 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -237,7 +237,7 @@ and prtStmt (i:int) (e : AbsBasilIR.stmt) : doc = match e with and prtLocalVar (i:int) (e : AbsBasilIR.localVar) : doc = match e with - AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_]) + AbsBasilIR.LocalTyped (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 1 type_]) | AbsBasilIR.LocalUntyped localident -> prPrec i 0 (concatD [prtLocalIdent 0 localident]) and prtLocalVarListBNFC i es : doc = match (i, es) with @@ -245,7 +245,7 @@ and prtLocalVarListBNFC i es : doc = match (i, es) with | (_,[x]) -> (concatD [prtLocalVar 0 x]) | (_,x::xs) -> (concatD [prtLocalVar 0 x ; render "," ; prtLocalVarListBNFC 0 xs]) and prtGlobalVar (i:int) (e : AbsBasilIR.globalVar) : doc = match e with - AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_]) + AbsBasilIR.GlobalTyped (globalident, type_) -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 1 type_]) | AbsBasilIR.GlobalUntyped globalident -> prPrec i 0 (concatD [prtGlobalIdent 0 globalident]) and prtGlobalVarListBNFC i es : doc = match (i, es) with @@ -392,17 +392,16 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) -and prtLambdaParam (i:int) (e : AbsBasilIR.lambdaParam) : doc = match e with - AbsBasilIR.LambdaParamLocalIdent localident -> prPrec i 0 (concatD [prtLocalIdent 0 localident]) - | AbsBasilIR.LambdaParam1 (localident, type_) -> prPrec i 0 (concatD [prtLocalIdent 0 localident ; render ":" ; prtTypeT 1 type_]) - | AbsBasilIR.LambdaParam2 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) +and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) -and prtLambdaParamListBNFC i es : doc = match (i, es) with +and prtLambdaParenListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLambdaParam 0 x]) - | (_,x::xs) -> (concatD [prtLambdaParam 0 x ; render "," ; prtLambdaParamListBNFC 0 xs]) + | (_,[x]) -> (concatD [prtLambdaParen 0 x]) + | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (lambdaparams, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParamListBNFC 0 lambdaparams ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 97600819..633cd192 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -264,14 +264,13 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' -and showLambdaParam (e : AbsBasilIR.lambdaParam) : showable = match e with - AbsBasilIR.LambdaParamLocalIdent localident -> s2s "LambdaParamLocalIdent" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> c2s ')' - | AbsBasilIR.LambdaParam1 (localident, type') -> s2s "LambdaParam1" >> c2s ' ' >> c2s '(' >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> c2s ')' - | AbsBasilIR.LambdaParam2 (openparen, localvar, closeparen) -> s2s "LambdaParam2" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' +and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with + AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (lambdaparams, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParam lambdaparams >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 59763f83..36fe688a 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -284,14 +284,13 @@ and transExpr (x : expr) : result = match x with | Expr_Paren (openparen, expr, closeparen) -> failure x -and transLambdaParam (x : lambdaParam) : result = match x with - LambdaParamLocalIdent localident -> failure x - | LambdaParam1 (localident, type') -> failure x - | LambdaParam2 (openparen, localvar, closeparen) -> failure x +and transLambdaParen (x : lambdaParen) : result = match x with + LambdaParenLocalVar localvar -> failure x + | LambdaParen1 (openparen, localvar, closeparen) -> failure x and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (lambdaparams, lambdasep, expr) -> failure x + LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index ae43dd07..7c8dc9ff 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -617,9 +617,7 @@ module BasilASTLoader = struct and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = unpack_local_lvars ~bound p_st @@ List.map - (function LambdaParamLocalIdent v -> LocalUntyped v - | LambdaParam1 (i, t) -> LocalTyped (i, t) - | LambdaParam2 (_, v, _) -> v) + (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 34f9f802..ac58ab1c 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -181,15 +181,15 @@ module.exports = grammar({ ), LocalVar: $ => choice( - // LocalTyped. LocalVar ::= LocalIdent ":" Type ; - seq($.token_LocalIdent, ":", $.Type), + // LocalTyped. LocalVar ::= LocalIdent ":" Type1 ; + seq($.token_LocalIdent, ":", $.Type1), // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), GlobalVar: $ => choice( - // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type ; - seq($.token_GlobalIdent, ":", $.Type), + // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; + seq($.token_GlobalIdent, ":", $.Type1), // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), @@ -458,27 +458,25 @@ module.exports = grammar({ // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), - LambdaParam: $ => + LambdaParen: $ => choice( - // LambdaParamLocalIdent. LambdaParam ::= LocalIdent ; - $.token_LocalIdent, - // LambdaParam1. LambdaParam ::= LocalIdent ":" Type1 ; - seq($.token_LocalIdent, ":", $.Type1), - // LambdaParam2. LambdaParam ::= OpenParen LocalVar CloseParen ; + // LambdaParenLocalVar. LambdaParen ::= LocalVar ; + $.LocalVar, + // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) ), - list_LambdaParam: $ => + list_LambdaParen: $ => choice( - // []. [LambdaParam] ::= ; + // []. [LambdaParen] ::= ; choice(), - // (:[]). [LambdaParam] ::= LambdaParam ; - $.LambdaParam, - // (:). [LambdaParam] ::= LambdaParam "," [LambdaParam] ; - seq($.LambdaParam, ",", optional($.list_LambdaParam)) + // (:[]). [LambdaParen] ::= LambdaParen ; + $.LambdaParen, + // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; + seq($.LambdaParen, ",", optional($.list_LambdaParen)) ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LambdaParam] LambdaSep Expr ; - seq(optional($.list_LambdaParam), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; + seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From ab3578b3aedff28057d47f7fa58f03e9fdb05901 Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:35:15 +1000 Subject: [PATCH 42/43] Reapply "stash" This reverts commit 4f9ebbb67d79d127d91c68f8228f99f6f98c5559. --- lib/fe/AbsBasilIR.ml | 18 +++++++---- lib/fe/BasilIR.cf | 20 +++++++----- lib/fe/ParBasilIR.mly | 72 +++++++++++++++++++++++------------------ lib/fe/PrintBasilIR.ml | 27 +++++++++------- lib/fe/ShowBasilIR.ml | 21 +++++++----- lib/fe/SkelBasilIR.ml | 21 +++++++----- lib/loadir.ml | 20 ++++-------- tree-sitter/grammar.js | 73 +++++++++++++++++++++++------------------- 8 files changed, 152 insertions(+), 120 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index a280c6cd..3a0093d5 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -104,12 +104,20 @@ and var = VarLocalVar of localVar | VarGlobalVar of globalVar +and localVarParen = + LocalVarParenLocalVar of localVar + | LocalVarParen1 of openParen * localIdent * typeT * closeParen + +and globalVarParen = + GlobalVarParenGlobalVar of globalVar + | GlobalVarParen1 of openParen * globalIdent * typeT * closeParen + and namedCallReturn = NamedCallReturn1 of lVar * localIdent and lVars = LVars_Empty - | LVars_LocalList of openParen * localVar list * closeParen + | LVars_LocalList of openParen * localVarParen list * closeParen | LVars_List of openParen * lVar list * closeParen | NamedLVars_List of openParen * namedCallReturn list * closeParen @@ -127,7 +135,7 @@ and jump = | Jump_ProcReturn and lVar = - LVar_Local of localVar + LVar_Local of localVarParen | LVar_Global of globalVar and stmtWithAttrib = @@ -190,12 +198,8 @@ and expr = | Expr_Cases of openParen * case list * closeParen | Expr_Paren of openParen * expr * closeParen -and lambdaParen = - LambdaParenLocalVar of localVar - | LambdaParen1 of openParen * localVar * closeParen - and lambdaDef = - LambdaDef1 of lambdaParen list * lambdaSep * expr + LambdaDef1 of localVarParen list * lambdaSep * expr and binOp = BinOpBVBinOp of bVBinOp diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index d5670f7e..a7130c52 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -97,13 +97,20 @@ Stmt_MultiAssign . Stmt ::= OpenParen [Assignment] CloseParen ; LocalTyped . LocalVar ::= LocalIdent ":" Type1 ; LocalUntyped . LocalVar ::= LocalIdent ; +separator nonempty LocalVar ","; GlobalTyped . GlobalVar ::= GlobalIdent ":" Type1 ; GlobalUntyped . GlobalVar ::= GlobalIdent; -separator nonempty LocalVar ","; +separator GlobalVar ","; + rules Var ::= LocalVar | GlobalVar ; -separator GlobalVar ","; +-- Variant of LocalVar / GlobalVar which can be wrapped in parens and +-- can contain any type. +rules LocalVarParen ::= LocalVar | OpenParen LocalIdent ":" Type CloseParen ; +rules GlobalVarParen ::= GlobalVar | OpenParen GlobalIdent ":" Type CloseParen ; +separator LocalVarParen ","; + -- lvar endian mem addr size Stmt_Load_Var . Stmt ::= LVar ":=" "load" Endian Var Expr IntVal; @@ -116,7 +123,7 @@ rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; LVars_Empty . LVars ::= ; -LVars_LocalList . LVars ::= "var" OpenParen [ LocalVar ] CloseParen ":=" ; +LVars_LocalList . LVars ::= "var" OpenParen [ LocalVarParen ] CloseParen ":=" ; LVars_List . LVars ::= OpenParen [ LVar ] CloseParen ":="; NamedLVars_List . LVars ::= OpenParen [NamedCallReturn] CloseParen ":="; @@ -138,7 +145,7 @@ Jump_Unreachable . Jump ::= "unreachable" ; Jump_Return . Jump ::= "return" OpenParen [Expr] CloseParen ; Jump_ProcReturn. Jump ::= "return" ; -LVar_Local . LVar ::= "var" LocalVar; +LVar_Local . LVar ::= "var" LocalVarParen; LVar_Global . LVar ::= GlobalVar; separator nonempty LVar "," ; @@ -208,10 +215,7 @@ Expr_Global . Expr2 ::= GlobalVar; -- quantifiers -rules LambdaParen ::= LocalVar | OpenParen LocalVar CloseParen ; -separator LambdaParen ","; - -rules LambdaDef ::= [LambdaParen] LambdaSep Expr ; +rules LambdaDef ::= [LocalVarParen] LambdaSep Expr ; Expr_Forall . Expr ::= "forall" AttribSet LambdaDef ; Expr_Exists . Expr ::= "exists" AttribSet LambdaDef ; Expr_Lambda . Expr ::= "fun" AttribSet LambdaDef ; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index dd887b98..4b1581d8 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -44,7 +44,7 @@ open Lexing %token <(int * int) * string> TOK_IntegerHex %token <(int * int) * string> TOK_IntegerDec -%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pGlobalVar pLocalVar_list pVar pGlobalVar_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaParen pLambdaParen_list pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list +%start pModuleT pDecl_list pBlockIdent_list pLambdaSep pVarModifiers pVarModifiers_list pDecl pTypeT_list pProcDef pIntType pBoolType pBVType pMapType pType1 pTypeT pIntVal pBVVal pEndian pAssignment pStmt pAssignment_list pLocalVar pLocalVar_list pGlobalVar pGlobalVar_list pVar pLocalVarParen pGlobalVarParen pLocalVarParen_list pNamedCallReturn pNamedCallReturn_list pLVars pNamedCallArg pNamedCallArg_list pCallParams pJump pLVar pLVar_list pBlock_list pStmtWithAttrib pStmtWithAttrib_list pJumpWithAttrib pPhiExpr pPhiExpr_list pPhiAssign pPhiAssign_list pBlock pAttrKeyValue pAttrKeyValue_list pAttribSet pAttr_list pAttr pParams pParams_list pValue pExpr_list pExpr pExpr1 pExpr2 pLambdaDef pBinOp pUnOp pCase pCase_list pEqOp pBVUnOp pBVBinOp pBVLogicalBinOp pIntBinOp pIntLogicalBinOp pBoolBinOp pRequireTok pEnsureTok pRelyTok pGuarTok pFunSpec pVarSpec pProgSpec pFunSpec_list pProgSpec_list %type pModuleT %type pDecl_list %type pBlockIdent_list @@ -67,10 +67,13 @@ open Lexing %type pStmt %type pAssignment_list %type pLocalVar -%type pGlobalVar %type pLocalVar_list -%type pVar +%type pGlobalVar %type pGlobalVar_list +%type pVar +%type pLocalVarParen +%type pGlobalVarParen +%type pLocalVarParen_list %type pNamedCallReturn %type pNamedCallReturn_list %type pLVars @@ -101,8 +104,6 @@ open Lexing %type pExpr %type pExpr1 %type pExpr2 -%type pLambdaParen -%type pLambdaParen_list %type pLambdaDef %type pBinOp %type pUnOp @@ -147,10 +148,13 @@ open Lexing %type stmt %type assignment_list %type localVar -%type globalVar %type localVar_list -%type var +%type globalVar %type globalVar_list +%type var +%type localVarParen +%type globalVarParen +%type localVarParen_list %type namedCallReturn %type namedCallReturn_list %type lVars @@ -181,8 +185,6 @@ open Lexing %type expr %type expr1 %type expr2 -%type lambdaParen -%type lambdaParen_list %type lambdaDef %type binOp %type unOp @@ -269,13 +271,19 @@ pAssignment_list : assignment_list TOK_EOF { $1 }; pLocalVar : localVar TOK_EOF { $1 }; +pLocalVar_list : localVar_list TOK_EOF { $1 }; + pGlobalVar : globalVar TOK_EOF { $1 }; -pLocalVar_list : localVar_list TOK_EOF { $1 }; +pGlobalVar_list : globalVar_list TOK_EOF { $1 }; pVar : var TOK_EOF { $1 }; -pGlobalVar_list : globalVar_list TOK_EOF { $1 }; +pLocalVarParen : localVarParen TOK_EOF { $1 }; + +pGlobalVarParen : globalVarParen TOK_EOF { $1 }; + +pLocalVarParen_list : localVarParen_list TOK_EOF { $1 }; pNamedCallReturn : namedCallReturn TOK_EOF { $1 }; @@ -337,10 +345,6 @@ pExpr1 : expr1 TOK_EOF { $1 }; pExpr2 : expr2 TOK_EOF { $1 }; -pLambdaParen : lambdaParen TOK_EOF { $1 }; - -pLambdaParen_list : lambdaParen_list TOK_EOF { $1 }; - pLambdaDef : lambdaDef TOK_EOF { $1 }; pBinOp : binOp TOK_EOF { $1 }; @@ -487,21 +491,34 @@ localVar : localIdent SYMB5 type1 { LocalTyped ($1, $3) } | localIdent { LocalUntyped $1 } ; +localVar_list : localVar { (fun x -> [x]) $1 } + | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } + ; + globalVar : globalIdent SYMB5 type1 { GlobalTyped ($1, $3) } | globalIdent { GlobalUntyped $1 } ; -localVar_list : localVar { (fun x -> [x]) $1 } - | localVar SYMB2 localVar_list { (fun (x,xs) -> x::xs) ($1, $3) } +globalVar_list : /* empty */ { [] } + | globalVar { (fun x -> [x]) $1 } + | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } ; var : localVar { VarLocalVar $1 } | globalVar { VarGlobalVar $1 } ; -globalVar_list : /* empty */ { [] } - | globalVar { (fun x -> [x]) $1 } - | globalVar SYMB2 globalVar_list { (fun (x,xs) -> x::xs) ($1, $3) } +localVarParen : localVar { LocalVarParenLocalVar $1 } + | openParen localIdent SYMB5 typeT closeParen { LocalVarParen1 ($1, $2, $4, $5) } + ; + +globalVarParen : globalVar { GlobalVarParenGlobalVar $1 } + | openParen globalIdent SYMB5 typeT closeParen { GlobalVarParen1 ($1, $2, $4, $5) } + ; + +localVarParen_list : /* empty */ { [] } + | localVarParen { (fun x -> [x]) $1 } + | localVarParen SYMB2 localVarParen_list { (fun (x,xs) -> x::xs) ($1, $3) } ; namedCallReturn : lVar SYMB6 localIdent { NamedCallReturn1 ($1, $3) } @@ -513,7 +530,7 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } + | KW_var openParen localVarParen_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } ; @@ -535,7 +552,7 @@ jump : KW_goto openParen blockIdent_list closeParen { Jump_GoTo ($2, $3, $4) } | KW_return { Jump_ProcReturn } ; -lVar : KW_var localVar { LVar_Local $2 } +lVar : KW_var localVarParen { LVar_Local $2 } | globalVar { LVar_Global $1 } ; @@ -648,16 +665,7 @@ expr2 : value { Expr_Literal $1 } | openParen expr closeParen { Expr_Paren ($1, $2, $3) } ; -lambdaParen : localVar { LambdaParenLocalVar $1 } - | openParen localVar closeParen { LambdaParen1 ($1, $2, $3) } - ; - -lambdaParen_list : /* empty */ { [] } - | lambdaParen { (fun x -> [x]) $1 } - | lambdaParen SYMB2 lambdaParen_list { (fun (x,xs) -> x::xs) ($1, $3) } - ; - -lambdaDef : lambdaParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } +lambdaDef : localVarParen_list lambdaSep expr { LambdaDef1 ($1, $2, $3) } ; binOp : bVBinOp { BinOpBVBinOp $1 } diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index d1a2ae5e..3d180780 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -257,6 +257,19 @@ and prtVar (i:int) (e : AbsBasilIR.var) : doc = match e with | AbsBasilIR.VarGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) +and prtLocalVarParen (i:int) (e : AbsBasilIR.localVarParen) : doc = match e with + AbsBasilIR.LocalVarParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) + | AbsBasilIR.LocalVarParen1 (openparen, localident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalIdent 0 localident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) + +and prtLocalVarParenListBNFC i es : doc = match (i, es) with + (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtLocalVarParen 0 x]) + | (_,x::xs) -> (concatD [prtLocalVarParen 0 x ; render "," ; prtLocalVarParenListBNFC 0 xs]) +and prtGlobalVarParen (i:int) (e : AbsBasilIR.globalVarParen) : doc = match e with + AbsBasilIR.GlobalVarParenGlobalVar globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) + | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type_, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtGlobalIdent 0 globalident ; render ":" ; prtTypeT 0 type_ ; prtCloseParen 0 closeparen]) + + and prtNamedCallReturn (i:int) (e : AbsBasilIR.namedCallReturn) : doc = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> prPrec i 0 (concatD [prtLVar 0 lvar ; render "=" ; prtLocalIdent 0 localident]) @@ -266,7 +279,7 @@ and prtNamedCallReturnListBNFC i es : doc = match (i, es) with | (_,x::xs) -> (concatD [prtNamedCallReturn 0 x ; render "," ; prtNamedCallReturnListBNFC 0 xs]) and prtLVars (i:int) (e : AbsBasilIR.lVars) : doc = match e with AbsBasilIR.LVars_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarListBNFC 0 localvars ; prtCloseParen 0 closeparen ; render ":="]) + | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarParenListBNFC 0 localvarparens ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLVarListBNFC 0 lvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtNamedCallReturnListBNFC 0 namedcallreturns ; prtCloseParen 0 closeparen ; render ":="]) @@ -291,7 +304,7 @@ and prtJump (i:int) (e : AbsBasilIR.jump) : doc = match e with and prtLVar (i:int) (e : AbsBasilIR.lVar) : doc = match e with - AbsBasilIR.LVar_Local localvar -> prPrec i 0 (concatD [render "var" ; prtLocalVar 0 localvar]) + AbsBasilIR.LVar_Local localvarparen -> prPrec i 0 (concatD [render "var" ; prtLocalVarParen 0 localvarparen]) | AbsBasilIR.LVar_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) and prtLVarListBNFC i es : doc = match (i, es) with @@ -392,16 +405,8 @@ and prtExprListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) | (_,[x]) -> (concatD [prtExpr 0 x]) | (_,x::xs) -> (concatD [prtExpr 0 x ; render "," ; prtExprListBNFC 0 xs]) -and prtLambdaParen (i:int) (e : AbsBasilIR.lambdaParen) : doc = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> prPrec i 0 (concatD [prtLocalVar 0 localvar]) - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLocalVar 0 localvar ; prtCloseParen 0 closeparen]) - -and prtLambdaParenListBNFC i es : doc = match (i, es) with - (_,[]) -> (concatD []) - | (_,[x]) -> (concatD [prtLambdaParen 0 x]) - | (_,x::xs) -> (concatD [prtLambdaParen 0 x ; render "," ; prtLambdaParenListBNFC 0 xs]) and prtLambdaDef (i:int) (e : AbsBasilIR.lambdaDef) : doc = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLambdaParenListBNFC 0 lambdaparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) + AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> prPrec i 0 (concatD [prtLocalVarParenListBNFC 0 localvarparens ; prtLambdaSep 0 lambdasep ; prtExpr 0 expr]) and prtBinOp (i:int) (e : AbsBasilIR.binOp) : doc = match e with diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 633cd192..7809297a 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -161,13 +161,23 @@ and showVar (e : AbsBasilIR.var) : showable = match e with | AbsBasilIR.VarGlobalVar globalvar -> s2s "VarGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' +and showLocalVarParen (e : AbsBasilIR.localVarParen) : showable = match e with + AbsBasilIR.LocalVarParenLocalVar localvar -> s2s "LocalVarParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + | AbsBasilIR.LocalVarParen1 (openparen, localident, type', closeparen) -> s2s "LocalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalIdent localident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + +and showGlobalVarParen (e : AbsBasilIR.globalVarParen) : showable = match e with + AbsBasilIR.GlobalVarParenGlobalVar globalvar -> s2s "GlobalVarParenGlobalVar" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' + | AbsBasilIR.GlobalVarParen1 (openparen, globalident, type', closeparen) -> s2s "GlobalVarParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showGlobalIdent globalident >> s2s ", " >> showTypeT type' >> s2s ", " >> showCloseParen closeparen >> c2s ')' + + and showNamedCallReturn (e : AbsBasilIR.namedCallReturn) : showable = match e with AbsBasilIR.NamedCallReturn1 (lvar, localident) -> s2s "NamedCallReturn1" >> c2s ' ' >> c2s '(' >> showLVar lvar >> s2s ", " >> showLocalIdent localident >> c2s ')' and showLVars (e : AbsBasilIR.lVars) : showable = match e with AbsBasilIR.LVars_Empty -> s2s "LVars_Empty" - | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVar localvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVarParen localvarparens >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> s2s "LVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLVar lvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> s2s "NamedLVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showNamedCallReturn namedcallreturns >> s2s ", " >> showCloseParen closeparen >> c2s ')' @@ -189,7 +199,7 @@ and showJump (e : AbsBasilIR.jump) : showable = match e with and showLVar (e : AbsBasilIR.lVar) : showable = match e with - AbsBasilIR.LVar_Local localvar -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' + AbsBasilIR.LVar_Local localvarparen -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVarParen localvarparen >> c2s ')' | AbsBasilIR.LVar_Global globalvar -> s2s "LVar_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' @@ -264,13 +274,8 @@ and showExpr (e : AbsBasilIR.expr) : showable = match e with | AbsBasilIR.Expr_Paren (openparen, expr, closeparen) -> s2s "Expr_Paren" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showExpr expr >> s2s ", " >> showCloseParen closeparen >> c2s ')' -and showLambdaParen (e : AbsBasilIR.lambdaParen) : showable = match e with - AbsBasilIR.LambdaParenLocalVar localvar -> s2s "LambdaParenLocalVar" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' - | AbsBasilIR.LambdaParen1 (openparen, localvar, closeparen) -> s2s "LambdaParen1" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showLocalVar localvar >> s2s ", " >> showCloseParen closeparen >> c2s ')' - - and showLambdaDef (e : AbsBasilIR.lambdaDef) : showable = match e with - AbsBasilIR.LambdaDef1 (lambdaparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLambdaParen lambdaparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' + AbsBasilIR.LambdaDef1 (localvarparens, lambdasep, expr) -> s2s "LambdaDef1" >> c2s ' ' >> c2s '(' >> showList showLocalVarParen localvarparens >> s2s ", " >> showLambdaSep lambdasep >> s2s ", " >> showExpr expr >> c2s ')' and showBinOp (e : AbsBasilIR.binOp) : showable = match e with diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 36fe688a..4e6e4e52 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -181,13 +181,23 @@ and transVar (x : var) : result = match x with | VarGlobalVar globalvar -> failure x +and transLocalVarParen (x : localVarParen) : result = match x with + LocalVarParenLocalVar localvar -> failure x + | LocalVarParen1 (openparen, localident, type', closeparen) -> failure x + + +and transGlobalVarParen (x : globalVarParen) : result = match x with + GlobalVarParenGlobalVar globalvar -> failure x + | GlobalVarParen1 (openparen, globalident, type', closeparen) -> failure x + + and transNamedCallReturn (x : namedCallReturn) : result = match x with NamedCallReturn1 (lvar, localident) -> failure x and transLVars (x : lVars) : result = match x with LVars_Empty -> failure x - | LVars_LocalList (openparen, localvars, closeparen) -> failure x + | LVars_LocalList (openparen, localvarparens, closeparen) -> failure x | LVars_List (openparen, lvars, closeparen) -> failure x | NamedLVars_List (openparen, namedcallreturns, closeparen) -> failure x @@ -209,7 +219,7 @@ and transJump (x : jump) : result = match x with and transLVar (x : lVar) : result = match x with - LVar_Local localvar -> failure x + LVar_Local localvarparen -> failure x | LVar_Global globalvar -> failure x @@ -284,13 +294,8 @@ and transExpr (x : expr) : result = match x with | Expr_Paren (openparen, expr, closeparen) -> failure x -and transLambdaParen (x : lambdaParen) : result = match x with - LambdaParenLocalVar localvar -> failure x - | LambdaParen1 (openparen, localvar, closeparen) -> failure x - - and transLambdaDef (x : lambdaDef) : result = match x with - LambdaDef1 (lambdaparens, lambdasep, expr) -> failure x + LambdaDef1 (localvarparens, lambdasep, expr) -> failure x and transBinOp (x : binOp) : result = match x with diff --git a/lib/loadir.ml b/lib/loadir.ml index 7c8dc9ff..fb46def4 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -610,15 +610,9 @@ module BasilASTLoader = struct and unpack_local_lvars ?(bound = StringMap.empty) p_st lvs : Var.t list = lvs |> List.map (function - | LocalTyped (i, t) -> + | (LocalVarParenLocalVar (LocalTyped (i, t)) | LocalVarParen1 (_, i, t, _)) -> Var.create ~scope:Local (unsafe_unsigil (`Local i)) (trans_type t) - | LocalUntyped i -> lookup_local_decl ~binds:bound i p_st) - - and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = - unpack_local_lvars ~bound p_st - @@ List.map - (function LambdaParenLocalVar v -> v | LambdaParen1 (o, v, c) -> v) - lvs + | LocalVarParenLocalVar (LocalUntyped i) -> lookup_local_decl ~binds:bound i p_st) and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in @@ -636,7 +630,7 @@ module BasilASTLoader = struct and trans_lvar prog (x : BasilIR.AbsBasilIR.lVar) : load_st * Var.t = match x with - | LVar_Local (LocalTyped (bident, type')) -> + | LVar_Local (LocalVarParenLocalVar (LocalTyped (bident, type')) | LocalVarParen1 (_, bident, type', _)) -> assign_var prog (Var.create ~scope:Local (unsafe_unsigil (`Local bident)) @@ -646,7 +640,7 @@ module BasilASTLoader = struct (Var.create (unsafe_unsigil (`Global bident)) (trans_type type') ~scope:Global) - | LVar_Local (LocalUntyped bident) -> + | LVar_Local (LocalVarParenLocalVar (LocalUntyped bident)) -> let v = lookup_local_decl bident prog in assign_var prog v | LVar_Global (GlobalUntyped bident) -> @@ -945,21 +939,21 @@ module BasilASTLoader = struct | Expr_Old (o, e, c) -> BasilExpr.unexp ~attrib:(expr_range_attr o c) ~op:`Old (trans_expr e) | Expr_Forall (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.forall ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Lambda (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.lambda ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Exists (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in + let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ac58ab1c..ef282c54 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -186,6 +186,13 @@ module.exports = grammar({ // LocalUntyped. LocalVar ::= LocalIdent ; $.token_LocalIdent ), + list_LocalVar: $ => + choice( + // (:[]). [LocalVar] ::= LocalVar ; + $.LocalVar, + // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; + seq($.LocalVar, ",", $.list_LocalVar) + ), GlobalVar: $ => choice( // GlobalTyped. GlobalVar ::= GlobalIdent ":" Type1 ; @@ -193,12 +200,14 @@ module.exports = grammar({ // GlobalUntyped. GlobalVar ::= GlobalIdent ; $.token_GlobalIdent ), - list_LocalVar: $ => + list_GlobalVar: $ => choice( - // (:[]). [LocalVar] ::= LocalVar ; - $.LocalVar, - // (:). [LocalVar] ::= LocalVar "," [LocalVar] ; - seq($.LocalVar, ",", $.list_LocalVar) + // []. [GlobalVar] ::= ; + choice(), + // (:[]). [GlobalVar] ::= GlobalVar ; + $.GlobalVar, + // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; + seq($.GlobalVar, ",", optional($.list_GlobalVar)) ), Var: $ => choice( @@ -207,14 +216,28 @@ module.exports = grammar({ // VarGlobalVar. Var ::= GlobalVar ; $.GlobalVar ), - list_GlobalVar: $ => + LocalVarParen: $ => choice( - // []. [GlobalVar] ::= ; - choice(), - // (:[]). [GlobalVar] ::= GlobalVar ; + // LocalVarParenLocalVar. LocalVarParen ::= LocalVar ; + $.LocalVar, + // LocalVarParen1. LocalVarParen ::= OpenParen LocalIdent ":" Type CloseParen ; + seq($.token_OpenParen, $.token_LocalIdent, ":", $.Type, $.token_CloseParen) + ), + GlobalVarParen: $ => + choice( + // GlobalVarParenGlobalVar. GlobalVarParen ::= GlobalVar ; $.GlobalVar, - // (:). [GlobalVar] ::= GlobalVar "," [GlobalVar] ; - seq($.GlobalVar, ",", optional($.list_GlobalVar)) + // GlobalVarParen1. GlobalVarParen ::= OpenParen GlobalIdent ":" Type CloseParen ; + seq($.token_OpenParen, $.token_GlobalIdent, ":", $.Type, $.token_CloseParen) + ), + list_LocalVarParen: $ => + choice( + // []. [LocalVarParen] ::= ; + choice(), + // (:[]). [LocalVarParen] ::= LocalVarParen ; + $.LocalVarParen, + // (:). [LocalVarParen] ::= LocalVarParen "," [LocalVarParen] ; + seq($.LocalVarParen, ",", optional($.list_LocalVarParen)) ), NamedCallReturn: $ => // NamedCallReturn1. NamedCallReturn ::= LVar "=" LocalIdent ; @@ -232,8 +255,8 @@ module.exports = grammar({ choice( // LVars_Empty. LVars ::= ; choice(), - // LVars_LocalList. LVars ::= "var" OpenParen [LocalVar] CloseParen ":=" ; - seq("var", $.token_OpenParen, $.list_LocalVar, $.token_CloseParen, ":="), + // LVars_LocalList. LVars ::= "var" OpenParen [LocalVarParen] CloseParen ":=" ; + seq("var", $.token_OpenParen, optional($.list_LocalVarParen), $.token_CloseParen, ":="), // LVars_List. LVars ::= OpenParen [LVar] CloseParen ":=" ; seq($.token_OpenParen, $.list_LVar, $.token_CloseParen, ":="), // NamedLVars_List. LVars ::= OpenParen [NamedCallReturn] CloseParen ":=" ; @@ -269,8 +292,8 @@ module.exports = grammar({ ), LVar: $ => choice( - // LVar_Local. LVar ::= "var" LocalVar ; - seq("var", $.LocalVar), + // LVar_Local. LVar ::= "var" LocalVarParen ; + seq("var", $.LocalVarParen), // LVar_Global. LVar ::= GlobalVar ; $.GlobalVar ), @@ -458,25 +481,9 @@ module.exports = grammar({ // Expr_Paren. Expr2 ::= OpenParen Expr CloseParen ; seq($.token_OpenParen, $.Expr, $.token_CloseParen) ), - LambdaParen: $ => - choice( - // LambdaParenLocalVar. LambdaParen ::= LocalVar ; - $.LocalVar, - // LambdaParen1. LambdaParen ::= OpenParen LocalVar CloseParen ; - seq($.token_OpenParen, $.LocalVar, $.token_CloseParen) - ), - list_LambdaParen: $ => - choice( - // []. [LambdaParen] ::= ; - choice(), - // (:[]). [LambdaParen] ::= LambdaParen ; - $.LambdaParen, - // (:). [LambdaParen] ::= LambdaParen "," [LambdaParen] ; - seq($.LambdaParen, ",", optional($.list_LambdaParen)) - ), LambdaDef: $ => - // LambdaDef1. LambdaDef ::= [LambdaParen] LambdaSep Expr ; - seq(optional($.list_LambdaParen), $.LambdaSep, $.Expr), + // LambdaDef1. LambdaDef ::= [LocalVarParen] LambdaSep Expr ; + seq(optional($.list_LocalVarParen), $.LambdaSep, $.Expr), BinOp: $ => choice( // BinOpBVBinOp. BinOp ::= BVBinOp ; From af8b39e9e888f383445cf7e89f49f89820c340ac Mon Sep 17 00:00:00 2001 From: rina Date: Wed, 4 Mar 2026 14:52:58 +1000 Subject: [PATCH 43/43] whatever. it would be nice to allow parenthesised local vars in more places, but it conflicts awfully with expr_paren. we need a partial order of precedence ;-; --- lib/fe/AbsBasilIR.ml | 4 ++-- lib/fe/BasilIR.cf | 6 +++--- lib/fe/ParBasilIR.mly | 6 +++--- lib/fe/PrintBasilIR.ml | 6 ++++-- lib/fe/ShowBasilIR.ml | 4 ++-- lib/fe/SkelBasilIR.ml | 4 ++-- lib/loadir.ml | 35 ++++++++++++++++++++++++++++------- tree-sitter/grammar.js | 16 ++++++++-------- 8 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib/fe/AbsBasilIR.ml b/lib/fe/AbsBasilIR.ml index 3a0093d5..ad9eb9bf 100644 --- a/lib/fe/AbsBasilIR.ml +++ b/lib/fe/AbsBasilIR.ml @@ -117,7 +117,7 @@ and namedCallReturn = and lVars = LVars_Empty - | LVars_LocalList of openParen * localVarParen list * closeParen + | LVars_LocalList of openParen * localVar list * closeParen | LVars_List of openParen * lVar list * closeParen | NamedLVars_List of openParen * namedCallReturn list * closeParen @@ -135,7 +135,7 @@ and jump = | Jump_ProcReturn and lVar = - LVar_Local of localVarParen + LVar_Local of localVar | LVar_Global of globalVar and stmtWithAttrib = diff --git a/lib/fe/BasilIR.cf b/lib/fe/BasilIR.cf index a7130c52..2db43f36 100644 --- a/lib/fe/BasilIR.cf +++ b/lib/fe/BasilIR.cf @@ -123,7 +123,7 @@ rules NamedCallReturn ::= LVar "=" LocalIdent; separator NamedCallReturn "," ; LVars_Empty . LVars ::= ; -LVars_LocalList . LVars ::= "var" OpenParen [ LocalVarParen ] CloseParen ":=" ; +LVars_LocalList . LVars ::= "var" OpenParen [ LocalVar ] CloseParen ":=" ; LVars_List . LVars ::= OpenParen [ LVar ] CloseParen ":="; NamedLVars_List . LVars ::= OpenParen [NamedCallReturn] CloseParen ":="; @@ -145,7 +145,7 @@ Jump_Unreachable . Jump ::= "unreachable" ; Jump_Return . Jump ::= "return" OpenParen [Expr] CloseParen ; Jump_ProcReturn. Jump ::= "return" ; -LVar_Local . LVar ::= "var" LocalVarParen; +LVar_Local . LVar ::= "var" LocalVar; LVar_Global . LVar ::= GlobalVar; separator nonempty LVar "," ; @@ -289,7 +289,7 @@ ProgSpec_Guarantee . ProgSpec ::= GuarTok Expr; terminator FunSpec "\n"; {- last semicolon terminates the prog definitino -} -terminator ProgSpec "\n"; +terminator nonempty ProgSpec "\n"; diff --git a/lib/fe/ParBasilIR.mly b/lib/fe/ParBasilIR.mly index 4b1581d8..375804f1 100644 --- a/lib/fe/ParBasilIR.mly +++ b/lib/fe/ParBasilIR.mly @@ -530,7 +530,7 @@ namedCallReturn_list : /* empty */ { [] } ; lVars : /* empty */ { LVars_Empty } - | KW_var openParen localVarParen_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } + | KW_var openParen localVar_list closeParen SYMB7 { LVars_LocalList ($2, $3, $4) } | openParen lVar_list closeParen SYMB7 { LVars_List ($1, $2, $3) } | openParen namedCallReturn_list closeParen SYMB7 { NamedLVars_List ($1, $2, $3) } ; @@ -552,7 +552,7 @@ jump : KW_goto openParen blockIdent_list closeParen { Jump_GoTo ($2, $3, $4) } | KW_return { Jump_ProcReturn } ; -lVar : KW_var localVarParen { LVar_Local $2 } +lVar : KW_var localVar { LVar_Local $2 } | globalVar { LVar_Global $1 } ; @@ -785,7 +785,7 @@ funSpec_list : /* empty */ { [] } | funSpec funSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; -progSpec_list : /* empty */ { [] } +progSpec_list : progSpec { (fun x -> [x]) $1 } | progSpec progSpec_list { (fun (x,xs) -> x::xs) ($1, $2) } ; diff --git a/lib/fe/PrintBasilIR.ml b/lib/fe/PrintBasilIR.ml index 3d180780..a10cc9e1 100644 --- a/lib/fe/PrintBasilIR.ml +++ b/lib/fe/PrintBasilIR.ml @@ -279,7 +279,7 @@ and prtNamedCallReturnListBNFC i es : doc = match (i, es) with | (_,x::xs) -> (concatD [prtNamedCallReturn 0 x ; render "," ; prtNamedCallReturnListBNFC 0 xs]) and prtLVars (i:int) (e : AbsBasilIR.lVars) : doc = match e with AbsBasilIR.LVars_Empty -> prPrec i 0 (concatD []) - | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarParenListBNFC 0 localvarparens ; prtCloseParen 0 closeparen ; render ":="]) + | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> prPrec i 0 (concatD [render "var" ; prtOpenParen 0 openparen ; prtLocalVarListBNFC 0 localvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtLVarListBNFC 0 lvars ; prtCloseParen 0 closeparen ; render ":="]) | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> prPrec i 0 (concatD [prtOpenParen 0 openparen ; prtNamedCallReturnListBNFC 0 namedcallreturns ; prtCloseParen 0 closeparen ; render ":="]) @@ -304,7 +304,7 @@ and prtJump (i:int) (e : AbsBasilIR.jump) : doc = match e with and prtLVar (i:int) (e : AbsBasilIR.lVar) : doc = match e with - AbsBasilIR.LVar_Local localvarparen -> prPrec i 0 (concatD [render "var" ; prtLocalVarParen 0 localvarparen]) + AbsBasilIR.LVar_Local localvar -> prPrec i 0 (concatD [render "var" ; prtLocalVar 0 localvar]) | AbsBasilIR.LVar_Global globalvar -> prPrec i 0 (concatD [prtGlobalVar 0 globalvar]) and prtLVarListBNFC i es : doc = match (i, es) with @@ -541,6 +541,8 @@ and prtProgSpec (i:int) (e : AbsBasilIR.progSpec) : doc = match e with and prtProgSpecListBNFC i es : doc = match (i, es) with (_,[]) -> (concatD []) + | (_,[x]) -> (concatD [prtProgSpec 0 x ; render " +"]) | (_,x::xs) -> (concatD [prtProgSpec 0 x ; render " " ; prtProgSpecListBNFC 0 xs]) diff --git a/lib/fe/ShowBasilIR.ml b/lib/fe/ShowBasilIR.ml index 7809297a..263d6c83 100644 --- a/lib/fe/ShowBasilIR.ml +++ b/lib/fe/ShowBasilIR.ml @@ -177,7 +177,7 @@ and showNamedCallReturn (e : AbsBasilIR.namedCallReturn) : showable = match e wi and showLVars (e : AbsBasilIR.lVars) : showable = match e with AbsBasilIR.LVars_Empty -> s2s "LVars_Empty" - | AbsBasilIR.LVars_LocalList (openparen, localvarparens, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVarParen localvarparens >> s2s ", " >> showCloseParen closeparen >> c2s ')' + | AbsBasilIR.LVars_LocalList (openparen, localvars, closeparen) -> s2s "LVars_LocalList" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLocalVar localvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.LVars_List (openparen, lvars, closeparen) -> s2s "LVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showLVar lvars >> s2s ", " >> showCloseParen closeparen >> c2s ')' | AbsBasilIR.NamedLVars_List (openparen, namedcallreturns, closeparen) -> s2s "NamedLVars_List" >> c2s ' ' >> c2s '(' >> showOpenParen openparen >> s2s ", " >> showList showNamedCallReturn namedcallreturns >> s2s ", " >> showCloseParen closeparen >> c2s ')' @@ -199,7 +199,7 @@ and showJump (e : AbsBasilIR.jump) : showable = match e with and showLVar (e : AbsBasilIR.lVar) : showable = match e with - AbsBasilIR.LVar_Local localvarparen -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVarParen localvarparen >> c2s ')' + AbsBasilIR.LVar_Local localvar -> s2s "LVar_Local" >> c2s ' ' >> c2s '(' >> showLocalVar localvar >> c2s ')' | AbsBasilIR.LVar_Global globalvar -> s2s "LVar_Global" >> c2s ' ' >> c2s '(' >> showGlobalVar globalvar >> c2s ')' diff --git a/lib/fe/SkelBasilIR.ml b/lib/fe/SkelBasilIR.ml index 4e6e4e52..bd941473 100644 --- a/lib/fe/SkelBasilIR.ml +++ b/lib/fe/SkelBasilIR.ml @@ -197,7 +197,7 @@ and transNamedCallReturn (x : namedCallReturn) : result = match x with and transLVars (x : lVars) : result = match x with LVars_Empty -> failure x - | LVars_LocalList (openparen, localvarparens, closeparen) -> failure x + | LVars_LocalList (openparen, localvars, closeparen) -> failure x | LVars_List (openparen, lvars, closeparen) -> failure x | NamedLVars_List (openparen, namedcallreturns, closeparen) -> failure x @@ -219,7 +219,7 @@ and transJump (x : jump) : result = match x with and transLVar (x : lVar) : result = match x with - LVar_Local localvarparen -> failure x + LVar_Local localvar -> failure x | LVar_Global globalvar -> failure x diff --git a/lib/loadir.ml b/lib/loadir.ml index fb46def4..ba88009b 100644 --- a/lib/loadir.ml +++ b/lib/loadir.ml @@ -610,9 +610,17 @@ module BasilASTLoader = struct and unpack_local_lvars ?(bound = StringMap.empty) p_st lvs : Var.t list = lvs |> List.map (function - | (LocalVarParenLocalVar (LocalTyped (i, t)) | LocalVarParen1 (_, i, t, _)) -> + | LocalTyped (i, t) -> Var.create ~scope:Local (unsafe_unsigil (`Local i)) (trans_type t) - | LocalVarParenLocalVar (LocalUntyped i) -> lookup_local_decl ~binds:bound i p_st) + | LocalUntyped i -> lookup_local_decl ~binds:bound i p_st) + + and unpac_lambdaparen ?(bound = StringMap.empty) p_st lvs = + unpack_local_lvars ~bound p_st + @@ List.map + (function + | LocalVarParenLocalVar v -> v + | LocalVarParen1 (_, i, t, _) -> LocalTyped (i, t)) + lvs and trans_jump p_st (x : BasilIR.AbsBasilIR.jumpWithAttrib) = let jump = match x with JumpWithAttrib1 (jump, _) -> jump in @@ -630,7 +638,7 @@ module BasilASTLoader = struct and trans_lvar prog (x : BasilIR.AbsBasilIR.lVar) : load_st * Var.t = match x with - | LVar_Local (LocalVarParenLocalVar (LocalTyped (bident, type')) | LocalVarParen1 (_, bident, type', _)) -> + | LVar_Local (LocalTyped (bident, type')) -> assign_var prog (Var.create ~scope:Local (unsafe_unsigil (`Local bident)) @@ -640,7 +648,7 @@ module BasilASTLoader = struct (Var.create (unsafe_unsigil (`Global bident)) (trans_type type') ~scope:Global) - | LVar_Local (LocalVarParenLocalVar (LocalUntyped bident)) -> + | LVar_Local (LocalUntyped bident) -> let v = lookup_local_decl bident prog in assign_var prog v | LVar_Global (GlobalUntyped bident) -> @@ -939,21 +947,21 @@ module BasilASTLoader = struct | Expr_Old (o, e, c) -> BasilExpr.unexp ~attrib:(expr_range_attr o c) ~op:`Old (trans_expr e) | Expr_Forall (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.forall ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Lambda (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in let attrib = `Assoc (trans_attrib_set ~binds p_st attrs) in BasilExpr.lambda ~attrib ~bound (trans_expr ~nbinds:bound e) | Expr_Exists (attrs, LambdaDef1 (lv, _, e)) -> - let bound = unpack_local_lvars ~bound:StringMap.empty p_st lv in + let bound = unpac_lambdaparen ~bound:StringMap.empty p_st lv in let binds = StringMap.add_list binds (List.map (fun v -> (Var.name v, v)) bound) in @@ -1450,3 +1458,16 @@ proc @c() -> () read: $R0:bv64,$mem:(bv64->bv8) written: $mem:(bv64->bv8) |}] + +let%test_unit "parses parenthesised lambda param" = + let s = + {| + let $memory_load32_le : (bv64 -> bv8) -> bv64 -> bv32 = fun (#memory: bv64 -> bv8), (#index: bv64) :: + (bvconcat(load_le(8, #memory, bvadd(#index, 3:bv64)), + bvconcat((load_le(8, #memory, bvadd(#index, 2:bv64))), + bvconcat((load_le(8, #memory, bvadd(#index, 1:bv64))), + load_le(8, #memory, #index))))); + |} + in + let _ = ast_of_string ~__LINE__ ~__FILE__ ~__FUNCTION__ s in + () diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index ef282c54..710c6b85 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -71,7 +71,7 @@ module.exports = grammar({ // Decl_ProgEmpty. Decl ::= "prog" "entry" ProcIdent AttribSet ; seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet)), // Decl_ProgWithSpec. Decl ::= "prog" "entry" ProcIdent AttribSet [ProgSpec] ; - seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), optional($.list_ProgSpec)), + seq("prog", "entry", $.token_ProcIdent, optional($.AttribSet), $.list_ProgSpec), // Decl_Proc. Decl ::= "proc" ProcIdent OpenParen [Params] CloseParen "->" OpenParen [Params] CloseParen AttribSet [FunSpec] ProcDef ; seq("proc", $.token_ProcIdent, $.token_OpenParen, optional($.list_Params), $.token_CloseParen, "->", $.token_OpenParen, optional($.list_Params), $.token_CloseParen, optional($.AttribSet), optional($.list_FunSpec), optional($.ProcDef)) ), @@ -255,8 +255,8 @@ module.exports = grammar({ choice( // LVars_Empty. LVars ::= ; choice(), - // LVars_LocalList. LVars ::= "var" OpenParen [LocalVarParen] CloseParen ":=" ; - seq("var", $.token_OpenParen, optional($.list_LocalVarParen), $.token_CloseParen, ":="), + // LVars_LocalList. LVars ::= "var" OpenParen [LocalVar] CloseParen ":=" ; + seq("var", $.token_OpenParen, $.list_LocalVar, $.token_CloseParen, ":="), // LVars_List. LVars ::= OpenParen [LVar] CloseParen ":=" ; seq($.token_OpenParen, $.list_LVar, $.token_CloseParen, ":="), // NamedLVars_List. LVars ::= OpenParen [NamedCallReturn] CloseParen ":=" ; @@ -292,8 +292,8 @@ module.exports = grammar({ ), LVar: $ => choice( - // LVar_Local. LVar ::= "var" LocalVarParen ; - seq("var", $.LocalVarParen), + // LVar_Local. LVar ::= "var" LocalVar ; + seq("var", $.LocalVar), // LVar_Global. LVar ::= GlobalVar ; $.GlobalVar ), @@ -701,10 +701,10 @@ module.exports = grammar({ ), list_ProgSpec: $ => choice( - // []. [ProgSpec] ::= ; - choice(), + // (:[]). [ProgSpec] ::= ProgSpec ; + $.ProgSpec, // (:). [ProgSpec] ::= ProgSpec [ProgSpec] ; - seq($.ProgSpec, optional($.list_ProgSpec)) + seq($.ProgSpec, $.list_ProgSpec) ), token_BVTYPE: $ => /bv\d+/,