Add compiler tests for assembly instructions

This commit is contained in:
Pranav Gaddamadugu 2023-03-26 22:35:34 -07:00
parent 586c56b66c
commit be6061d9a4
66 changed files with 491 additions and 220 deletions

View File

@ -39,7 +39,17 @@ pub trait StatementReconstructor: ExpressionReconstructor + InstructionReconstru
}
fn reconstruct_assembly_block(&mut self, input: AssemblyBlock) -> (Statement, Self::AdditionalOutput) {
todo!()
(
Statement::AssemblyBlock(AssemblyBlock {
instructions: input
.instructions
.into_iter()
.map(|inst| self.reconstruct_instruction(inst).0)
.collect(),
span: input.span,
}),
Default::default(),
)
}
fn reconstruct_assert(&mut self, input: AssertStatement) -> (Statement, Self::AdditionalOutput) {

View File

@ -51,7 +51,7 @@ impl ParserContext<'_> {
| Expression::Access(AccessExpression::Member(_)) => {} // Valid
_ => return Err(ParserError::invalid_instruction_operand(expression.span()).into()),
}
operands.push(self.parse_expression()?);
operands.push(expression);
}
if self.check_identifier_with_name(sym::into) {
// Parse the `into` keyword.

View File

@ -19,6 +19,8 @@ pub use generator::*;
mod visit_expressions;
mod visit_instruction;
mod visit_program;
mod visit_statements;

View File

@ -0,0 +1,48 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::CodeGenerator;
use leo_ast::Instruction;
use itertools::Itertools;
impl<'a> CodeGenerator<'a> {
pub(crate) fn visit_instruction(&mut self, instruction: &'a Instruction) -> String {
// Visit the instruction operands.
// Note that parsing guarantees that the operands are either literals, identifiers, or member accesses.
let operands = instruction
.operands
.iter()
.map(|operand| self.visit_expression(operand).0)
.join(" ");
// Construct the new destination registers and add them to mapping.
let destinations = instruction
.destinations
.iter()
.map(|identifier| {
let destination_register = format!("r{}", self.next_register);
// Increment the register counter.
self.next_register += 1;
// Add the destination to the mapping.
self.variable_mapping
.insert(&identifier.name, destination_register.clone());
destination_register
})
.join(" ");
format!("{} {} into {};", instruction.opcode, operands, destinations)
}
}

View File

@ -44,11 +44,12 @@ impl<'a> CodeGenerator<'a> {
}
fn visit_assembly_block(&mut self, input: &'a AssemblyBlock) -> String {
let mut instructions = String::new();
for instruction in &input.instructions {
instructions.push_str(&instruction.to_string());
}
instructions
// For each instruction in the block, visit it and add it to the program.
input
.instructions
.iter()
.map(|inst| self.visit_instruction(inst))
.join("")
}
fn visit_assert(&mut self, input: &'a AssertStatement) -> String {

View File

@ -17,6 +17,7 @@
use leo_span::Symbol;
use indexmap::IndexSet;
use leo_ast::{Instruction, InstructionReconstructor};
#[derive(Default)]
pub struct DeadCodeEliminator {
@ -35,3 +36,10 @@ impl DeadCodeEliminator {
}
}
}
impl InstructionReconstructor for DeadCodeEliminator {
/// Instructions in assembly blocks are not to be eliminated.
fn reconstruct_instruction(&mut self, input: Instruction) -> (Instruction, Self::AdditionalOutput) {
(input, Default::default())
}
}

View File

@ -15,7 +15,6 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::TypeChecker;
use std::borrow::Borrow;
use leo_ast::*;
use leo_errors::emitter::Handler;

View File

@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{TypeChecker, VariableSymbol, VariableType};
use crate::{TypeChecker, VariableType};
use leo_ast::{Expression, ExpressionVisitor, Instruction, InstructionVisitor, IntegerType, Node, Opcode, Type};
use leo_ast::{ExpressionVisitor, Instruction, InstructionVisitor, IntegerType, Node, Opcode, Type};
use leo_errors::TypeCheckerError;
use itertools::Itertools;
@ -26,21 +26,26 @@ impl<'a> TypeChecker<'a> {
fn check_instruction_is_well_formed<const NUM_OPERANDS: usize, const NUM_DESTINATIONS: usize>(
&mut self,
instruction: &'a Instruction,
) {
) -> bool {
// A flag to indicate if the instruction is well-formed.
let mut is_well_formed = true;
// Check that the number of operands is NUM_OPERANDS.
if instruction.operands.len() != NUM_OPERANDS {
is_well_formed = false;
self.emit_err(TypeCheckerError::malformed_instruction(
format!("Expected {NUM_OPERANDS} operands."),
instruction.span,
));
}
};
// Check that the number of destinations is NUM_DESTINATIONS.
if instruction.destinations.len() != NUM_DESTINATIONS {
is_well_formed = false;
self.emit_err(TypeCheckerError::malformed_instruction(
format!("Expected {NUM_DESTINATIONS} destination registers."),
instruction.span,
));
}
};
is_well_formed
}
// Helper to type check standard instructions.
@ -49,62 +54,71 @@ impl<'a> TypeChecker<'a> {
instruction: &'a Instruction,
expected_types: &[([Type; NUM_OPERANDS], [Type; NUM_DESTINATIONS])],
) {
// Check that the structure of the instruction is well-formed.
self.check_instruction_is_well_formed::<NUM_OPERANDS, NUM_DESTINATIONS>(instruction);
// Get the types of the operands.
let operand_types = instruction
.operands
.iter()
.map(|operand| self.visit_expression(operand, &None))
.collect_vec();
// Check that the types of the operands match one of the expected operand types.
let destination_types = expected_types
.iter()
.find(|(expected_operand_types, _)| {
operand_types
.iter()
.zip_eq(expected_operand_types.iter())
.all(|(operand_type, expected_type)| match operand_type {
Some(operand_type) => operand_type.eq_flat(expected_type),
None => false,
})
})
.map(|(_, expected_destination_types)| expected_destination_types);
// If the destination types are found, add the destination registers to the symbol table.
// Otherwise, emit an error.
match destination_types {
Some(destination_types) => {
for (destination, destination_type) in instruction.destinations.iter().zip_eq(destination_types.iter())
{
self.insert_variable(
destination.name,
destination_type.clone(),
destination.span,
VariableType::Mut,
);
println!("NUM_OPERANDS: {}", NUM_OPERANDS);
println!("NUM_DESTINATIONS: {}", NUM_DESTINATIONS);
println!("instruction: {:?}", instruction);
// Check that the structure of the instruction is well-formed.
if self.check_instruction_is_well_formed::<NUM_OPERANDS, NUM_DESTINATIONS>(instruction) {
// Get the types of the operands.
let operand_types = instruction
.operands
.iter()
.map(|operand| self.visit_expression(operand, &None))
.collect_vec();
println!("operand_types: {:?}", operand_types);
let destination_types = expected_types
.iter()
.find(|(expected_operand_types, _)| {
operand_types
.iter()
.zip_eq(expected_operand_types.iter())
.all(|(operand_type, expected_type)| match operand_type {
Some(operand_type) => operand_type.eq_flat(expected_type),
None => false,
})
})
.map(|(_, expected_destination_types)| expected_destination_types);
// If the destination types are found, add the destination registers to the symbol table.
// Otherwise, emit an error.
match destination_types {
Some(destination_types) => {
for (destination, destination_type) in
instruction.destinations.iter().zip_eq(destination_types.iter())
{
self.insert_variable(
destination.name,
destination_type.clone(),
destination.span,
VariableType::Mut,
);
}
}
None => self.emit_err(TypeCheckerError::invalid_instruction_operand_types(
&instruction.opcode,
expected_types
.iter()
.map(|(operand_types, _)| format!("({})", operand_types.iter().join(", ")))
.join(", "),
instruction.span,
)),
}
None => self.emit_err(TypeCheckerError::invalid_instruction_operand_types(
&instruction.opcode,
expected_types
.iter()
.map(|(operand_types, _)| format!("({})", operand_types.iter().join(", ")))
.join(", "),
instruction.span,
)),
}
}
// Helper to type check commit instructions.
fn check_commit_instruction(&mut self, instruction: &'a Instruction, output_type: Type) {
// Check that the structure of the instruction is well-formed.
self.check_instruction_is_well_formed::<2, 1>(instruction);
// Check that the second operand is a scalar.
let second_type = self.visit_expression(&instruction.operands[1], &None);
self.assert_type(&second_type, &Type::Scalar, instruction.operands[1].span());
// Add the destination register to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, output_type, destination.span, VariableType::Mut);
if self.check_instruction_is_well_formed::<2, 1>(instruction) {
// Check that the second operand is a scalar.
let second_type = self.visit_expression(&instruction.operands[1], &None);
self.assert_type(&second_type, &Type::Scalar, instruction.operands[1].span());
// Add the destination register to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, output_type, destination.span, VariableType::Mut);
}
}
}
@ -162,11 +176,12 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> {
)),
Opcode::AssertEq | Opcode::AssertNeq => {
// Check that the instruction is well-formed.
self.check_instruction_is_well_formed::<2, 0>(instruction);
// Check that the operands are the same type.
let lhs = self.visit_expression(&instruction.operands[0], &None);
let rhs = self.visit_expression(&instruction.operands[1], &None);
self.check_eq_types(&lhs, &rhs, instruction.span);
if self.check_instruction_is_well_formed::<2, 0>(instruction) {
// Check that the operands are the same type.
let lhs = self.visit_expression(&instruction.operands[0], &None);
let rhs = self.visit_expression(&instruction.operands[1], &None);
self.check_eq_types(&lhs, &rhs, instruction.span);
}
}
Opcode::CommitBHP256 | Opcode::CommitBHP512 | Opcode::CommitBHP768 | Opcode::CommitBHP1024 => self.check_commit_instruction(instruction, Type::Field),
Opcode::CommitPED64 | Opcode::CommitPED128 => self.check_commit_instruction(instruction, Type::Group),
@ -201,10 +216,11 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> {
| Opcode::HashPSD4
| Opcode::HashPSD8 => {
// Check that the instruction is well-formed.
self.check_instruction_is_well_formed::<1, 1>(instruction);
// Add the destination to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut);
if self.check_instruction_is_well_formed::<1, 1>(instruction) {
// Add the destination to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut);
}
}
Opcode::Inv
| Opcode::Square
@ -213,14 +229,15 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> {
)),
Opcode::IsEq | Opcode::IsNeq => {
// Check that the instruction is well formed.
self.check_instruction_is_well_formed::<2, 1>(instruction);
// Check that the operands are of the same type.
let lhs = self.visit_expression(&instruction.operands[0], &None);
let rhs = self.visit_expression(&instruction.operands[1], &None);
self.check_eq_types(&lhs, &rhs, instruction.span);
// Add the destination to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut);
if self.check_instruction_is_well_formed::<2, 1>(instruction) {
// Check that the operands are of the same type.
let lhs = self.visit_expression(&instruction.operands[0], &None);
let rhs = self.visit_expression(&instruction.operands[1], &None);
self.check_eq_types(&lhs, &rhs, instruction.span);
// Add the destination to the symbol table.
let destination = &instruction.destinations[0];
self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut);
}
}
Opcode::Modulo => self.check_instruction(instruction, declare_types!(
(Type::Integer(IntegerType::U8), Type::Integer(IntegerType::U8) => Type::Integer(IntegerType::U8)),

View File

@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{TypeChecker, VariableSymbol, VariableType};
use crate::{TypeChecker, VariableType};
use itertools::Itertools;
use leo_ast::*;
use leo_errors::TypeCheckerError;
use leo_span::{Span, Symbol};
impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
fn visit_statement(&mut self, input: &'a Statement) {

View File

@ -0,0 +1,11 @@
---
namespace: Compile
expectation: Pass
outputs:
- initial_ast: d0725a7e0e729114b8cd54afc6b10412d84a15742ae6c12f60aba1676c4b7566
unrolled_ast: d0725a7e0e729114b8cd54afc6b10412d84a15742ae6c12f60aba1676c4b7566
ssa_ast: 22981ac2db8108536bd67526d33619a2441424115d8a1e4d2691d3e9248e4963
flattened_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5
inlined_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5
dce_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5
bytecode: 897bea510b0004df84a28144ea171a0a68c5d351e6d3acd4f9aca376226f272e

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:10:13\n |\n 10 | return d;\n | ^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:8:9\n |\n 8 | return c;\n | ^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'y'\n --> compiler-test:11:13\n |\n 11 | y = z + z;\n | ^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'let'\n --> compiler-test:9:9\n |\n 9 | let f: u8 = d + 1u8;\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'let'\n --> compiler-test:11:9\n |\n 11 | let f: u8 = d + 1u8;\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:8:9\n |\n 8 | return a;\n | ^^^^^^"

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 450d11de6b2c3495ee84a45223a4d5bb59e4bee0de0953e356c2f441f87d9506
unrolled_ast: 450d11de6b2c3495ee84a45223a4d5bb59e4bee0de0953e356c2f441f87d9506
ssa_ast: 570e9b414628d3d469417a9177b1875bb00bfb7d6e207e84b76844acb4a0ca53
flattened_ast: d2f200afaca7fc18edc44c42546a6aa41f5769b1f3040c7c624e58dddbe24445
inlined_ast: d2f200afaca7fc18edc44c42546a6aa41f5769b1f3040c7c624e58dddbe24445
- initial_ast: 56958cf9571d6dfabfaf4e18227ce54fd9b763a535d7aec725242cd9313a4bd7
unrolled_ast: 56958cf9571d6dfabfaf4e18227ce54fd9b763a535d7aec725242cd9313a4bd7
ssa_ast: 11dab7eb6db4b7bea80a9152dcc70a1297b81d54dd934b37dfab681960e61832
flattened_ast: f44271dbd181bcaf30d0564fcd30e5d41510165ef0a00bb9d11c7110b4784c8a
inlined_ast: f44271dbd181bcaf30d0564fcd30e5d41510165ef0a00bb9d11c7110b4784c8a
dce_ast: bf253b773de7fbefe2ca492f077f998365c30a2b2dab512cc3d13aaeb7f01bdf
bytecode: 3ee7be6b9dbdaa4a046c5ca32ed10de40d57c80c13aba2fa5ee7fd80dd5c1ad3

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 7075037df0d5337fd40c7709ef7ad991e5aa2f8de347d5b5132b00f0dcd443c9
unrolled_ast: 7075037df0d5337fd40c7709ef7ad991e5aa2f8de347d5b5132b00f0dcd443c9
ssa_ast: 42ba7b6d8fc7b8bebf50232d4d8ca49769776637ea9aaaeaa1ac8c1b963c5239
flattened_ast: 9005637746f0f1149b73dff4143b8597c2c8259c1e653c3d74fa6ed982c59904
inlined_ast: 9005637746f0f1149b73dff4143b8597c2c8259c1e653c3d74fa6ed982c59904
- initial_ast: 92447c89385d9a8a20fc08b0d2c01249266aeda2bd5928e5760df82e9e7b0bb4
unrolled_ast: 92447c89385d9a8a20fc08b0d2c01249266aeda2bd5928e5760df82e9e7b0bb4
ssa_ast: d89ccd15c83bcb68eca0533db460e0cb2a4c5d5d57a63ecd72dd70eaef976bc0
flattened_ast: 107ce16937aade05a9b3cf6106b5ae4bee1c147432d6f8e5910b80cacdd3dc3f
inlined_ast: 107ce16937aade05a9b3cf6106b5ae4bee1c147432d6f8e5910b80cacdd3dc3f
dce_ast: 088a2c4be3dc20eb2b3b7bc25874fa9547ed9cace1f95d15d846ef7f0612b962
bytecode: b36da573e89979cf5999abf1135a2443a42c08527c962edca14559769f7c3927

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 1fa056ac6bfafa193a25d19d92c44b5eb5f5b4aa50f5c910b08d6e1681a918c8
unrolled_ast: 1fa056ac6bfafa193a25d19d92c44b5eb5f5b4aa50f5c910b08d6e1681a918c8
ssa_ast: e5816bc6f7f6c533f6e19367575efef7f9d6696d7f5e60a1e01e619c47ae8821
flattened_ast: 2157b9d9fb3208071b33add3201ff4cce1fe1c67bcce92ce0ec07461681d4851
inlined_ast: 2157b9d9fb3208071b33add3201ff4cce1fe1c67bcce92ce0ec07461681d4851
- initial_ast: 4811ff9f8f0c33486600cc2c9eae9977ec93ec03a0a191d7deb3ae587b817a04
unrolled_ast: 4811ff9f8f0c33486600cc2c9eae9977ec93ec03a0a191d7deb3ae587b817a04
ssa_ast: 062c86e9f94ca18e845285df1c4036fa2198083f8f9432a024ed9eb453de1732
flattened_ast: d69caf4f05da1fca41c13d8e675925d301ca0be2705274f7bb44430575d05872
inlined_ast: d69caf4f05da1fca41c13d8e675925d301ca0be2705274f7bb44430575d05872
dce_ast: 0875ca662c0e764c1e57247e9ce00fb984b437595276f30bb878dc77405f4f12
bytecode: 7ab3f946685bbd31ea648dcaf0dadbacbd6e50e63d1093f23f92f3387cab35f6

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: eff1e9e82caf84d6baa36c5a7eab33739a3bddc8744c50bacfa5f0f8cb0b8bf4
unrolled_ast: eff1e9e82caf84d6baa36c5a7eab33739a3bddc8744c50bacfa5f0f8cb0b8bf4
ssa_ast: 295f90c7b29c6f0c9179637bcae0dba07b9212feefe1b133ebd43eb785d847b8
flattened_ast: 2a49c36ddb55e0b81b1692283c5f6de9cfe5036981b642105714b337ad87df7c
inlined_ast: 2a49c36ddb55e0b81b1692283c5f6de9cfe5036981b642105714b337ad87df7c
- initial_ast: b5d545b7b4a516e63d68211588a56f80490d21bfdfaa86001f5d44416e1366c0
unrolled_ast: b5d545b7b4a516e63d68211588a56f80490d21bfdfaa86001f5d44416e1366c0
ssa_ast: d4d72e8e3a0437309be4f675e5aaaa6ffc353034c4cd04c6377d04ee71deefeb
flattened_ast: 0bc0b6ec68ca50a95f29b252d31273b3eafe997afb14273895ef36d2118eab39
inlined_ast: 0bc0b6ec68ca50a95f29b252d31273b3eafe997afb14273895ef36d2118eab39
dce_ast: df939888692cd36fa2095f9960448ca767efe6bb818dc151e982d05035dc4886
bytecode: 2bc4334f42205f2800b37e69fac6cacfdf6cac174d71034aaee478be2d1a2ef0

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 928201ba3086292b6434c839920a82a165b1b2d782da35d03bd78c1b399325f0
unrolled_ast: 928201ba3086292b6434c839920a82a165b1b2d782da35d03bd78c1b399325f0
ssa_ast: 3fd59a9e710784b69e95dca5ad4438ba4d4fa4fed189e7bfb6c0f30140190753
flattened_ast: 0734a281c1bb57ff93023454c561d63ba6b8db3c2c34b9774e4a2e01d78f2f35
inlined_ast: 0734a281c1bb57ff93023454c561d63ba6b8db3c2c34b9774e4a2e01d78f2f35
- initial_ast: 60f44279e5cbe65f6fe0f05b83dad371b65863eb7f175b495535abf820cfe587
unrolled_ast: 60f44279e5cbe65f6fe0f05b83dad371b65863eb7f175b495535abf820cfe587
ssa_ast: e59cdbb726cb34d4765af299a3b6e51e14f93b16032e437a8c5f516eb66c6361
flattened_ast: e51aa122bd6b2eae3b300972952cde859d3bcdd720c8db5d1d496ae1bea99ea1
inlined_ast: e51aa122bd6b2eae3b300972952cde859d3bcdd720c8db5d1d496ae1bea99ea1
dce_ast: 3a0427fceb512fcd4d113149514140ea60114e1de8d994e631d26ee33bd857c8
bytecode: 6d23c0ce42f90915f6fe75dc44c729d183aef74ea294f3c5c966a069b1a33fdf

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: f71270a459a000979dce1bf2f514778c8f9ea4e5cdaa834a5f0797e16fc6c09c
unrolled_ast: f71270a459a000979dce1bf2f514778c8f9ea4e5cdaa834a5f0797e16fc6c09c
ssa_ast: cb7aa960ed672414c1e7665a0b02bbb3926180e9f3a399bf526cbca7aa872c8c
flattened_ast: 8affd64c29c8aa7669652801bd58373f6e096d8c82af4e5f1340b552c3123ad9
inlined_ast: 8affd64c29c8aa7669652801bd58373f6e096d8c82af4e5f1340b552c3123ad9
- initial_ast: 7919cc18d1d700acfc094b1fcc2892e362d2eed3213f6bb5583011b65d04b6a2
unrolled_ast: 7919cc18d1d700acfc094b1fcc2892e362d2eed3213f6bb5583011b65d04b6a2
ssa_ast: ef61f8fdd1ebe27fa4aea9d93af5f6782025657492183c0e425cd421cae244f0
flattened_ast: 6724eed786e387aa5be82c83f86c9d4673d07c470bb68458e03c0ce73f2538b0
inlined_ast: 6724eed786e387aa5be82c83f86c9d4673d07c470bb68458e03c0ce73f2538b0
dce_ast: fab8ab63a79dc1b5b97b7ba1f1252f4779cdc324afd436b6dab44379af0c0c72
bytecode: 43507852e6ea9e5cf869a03c94302133470e5d32579620cf12e95614064223ea

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 673add2e4691004b32b69926b69fd8cd798c15a3d163d197edde976cd0373d6e
unrolled_ast: 673add2e4691004b32b69926b69fd8cd798c15a3d163d197edde976cd0373d6e
ssa_ast: 1aa40498ce952b263c37bf0d5877e071b2be8c2d40d433621256f03000bf1772
flattened_ast: b69bc1f6e5076a264057b48afe3fb0e850df2143cba1fcaecd4c53e0c692e32b
inlined_ast: b69bc1f6e5076a264057b48afe3fb0e850df2143cba1fcaecd4c53e0c692e32b
- initial_ast: cbf499904045352a886262be52b3d9fd11d54d360f2c08b4d878e736f0b08ce8
unrolled_ast: cbf499904045352a886262be52b3d9fd11d54d360f2c08b4d878e736f0b08ce8
ssa_ast: 54defa106ce6b9b1f9413a8c9826d8e60a3038097bb92c5efd63f7795ba71dc3
flattened_ast: 880fc6a9cdfdc2303f7e17080b1ae257272bac185bcd3c4e627f26c3864dd844
inlined_ast: 880fc6a9cdfdc2303f7e17080b1ae257272bac185bcd3c4e627f26c3864dd844
dce_ast: 158e4da27be2d9a3ad884b59fc37eb639e4d3ea825d1aa4ef934848b5143c076
bytecode: 77797810cc7ce1ad77b02dc0da8aad7aa850efdee822ccd282305a30899c9dd3

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 8ec18c0e0cd34833461daf3634b6b9bea5509c830873305da03ff43810ca0a81
unrolled_ast: 8ec18c0e0cd34833461daf3634b6b9bea5509c830873305da03ff43810ca0a81
ssa_ast: 3c3bd8bdc9413f5bf10f21e0acf323b043148a56c5e02ad9f8f1a59dd79a286d
flattened_ast: 236bc3e88f512b6158d22daebebf5674e98e26887d6b25ce8e7ba1b1efff03e5
inlined_ast: 236bc3e88f512b6158d22daebebf5674e98e26887d6b25ce8e7ba1b1efff03e5
- initial_ast: 1a91672aee80afbe5c84fdcc4d355a63e8309da77531d436dcfc1443d1dc3e31
unrolled_ast: 1a91672aee80afbe5c84fdcc4d355a63e8309da77531d436dcfc1443d1dc3e31
ssa_ast: 84968cb36d83d06ee34d5f7331adfebd507e3bb1e86b038faec0bf11bc8f5bbc
flattened_ast: ac051743e4c719e4bb2c236385d3f8bbee056d23c6d74eeb5765f3f4e6f8e8a0
inlined_ast: ac051743e4c719e4bb2c236385d3f8bbee056d23c6d74eeb5765f3f4e6f8e8a0
dce_ast: 0ec061faa5f9399193029b02f676d02cf6cfe73220c0f375f1a9354637b420f7
bytecode: 3a6e5f56da93ca64f10519ad72c0dfe039273274b0e88fecaec58c40d1717488

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: f58fdc2727e425eb2183879fb8e4d915ee076d5e54b88d80945423e990e0ea11
unrolled_ast: f58fdc2727e425eb2183879fb8e4d915ee076d5e54b88d80945423e990e0ea11
ssa_ast: 7812a0a147d79d53f32a905f1b44107075bc18ffbb07d350f26d74744623db62
flattened_ast: f144f6abd33191415592fc866fa5a1374383f14cb3d847a2a9571ccedd910399
inlined_ast: f144f6abd33191415592fc866fa5a1374383f14cb3d847a2a9571ccedd910399
- initial_ast: ab8d13323e95a8c8e149e7b8d4cce778a0e8d87d236a1de5f003a5152e109392
unrolled_ast: ab8d13323e95a8c8e149e7b8d4cce778a0e8d87d236a1de5f003a5152e109392
ssa_ast: 14cbdb377aee3ff9070429b690adf54e9d44752394a4be47765f88b2b4e22cc5
flattened_ast: fb16ca7aa74e84ca91b5ac3eed7fa2d06060b132692e7a28ab4d59aa7c19a20e
inlined_ast: fb16ca7aa74e84ca91b5ac3eed7fa2d06060b132692e7a28ab4d59aa7c19a20e
dce_ast: 99d13e0f22f1cbd7d9e6a021f3d1c884cce23900eef9d92069629855be3a8d4b
bytecode: 6df1568996922ad2b9ebab5d7d0b01d5fcd2b723c2a79b7ccb6a9a8c6da706ab

View File

@ -2,10 +2,10 @@
namespace: Compile
expectation: Pass
outputs:
- initial_ast: 49eceb52e53590ba231a2ca416034c6f3718b1bfe3f67ca41b973e7323efaf02
unrolled_ast: 49eceb52e53590ba231a2ca416034c6f3718b1bfe3f67ca41b973e7323efaf02
ssa_ast: e52370740422e008eec0e2630211063995fa07851929a81afe3e68de6c8052de
flattened_ast: 67c260a2ee07c5087249d064140ed1b0bcadee108e8165795d119431a52c601f
inlined_ast: 67c260a2ee07c5087249d064140ed1b0bcadee108e8165795d119431a52c601f
- initial_ast: 2bb0ee8a11f2883241c5ecd1fe800ed428f6c7760a7928f161133ba8870d043f
unrolled_ast: 2bb0ee8a11f2883241c5ecd1fe800ed428f6c7760a7928f161133ba8870d043f
ssa_ast: b737349409c53b451cf8b881e9bce93ca32935bb3982479aefc26d410aca4d73
flattened_ast: 3387bcf3c9c604cfe8c98946993e839501c4629b4eaa1ee12d47603b398ea4e0
inlined_ast: 3387bcf3c9c604cfe8c98946993e839501c4629b4eaa1ee12d47603b398ea4e0
dce_ast: c0095a84d960acb0bd845de7e20902fc26f7b203e91b109e61cd0405cd26a0cc
bytecode: bc96cd7d2338fc235857e720f458edaf870603cb91f763e2e82cff2be42df25c

View File

@ -2,4 +2,5 @@
namespace: ParseInstruction
expectation: Fail
outputs:
- "Error [EPAR0370009]: unexpected string: expected 'expression', found '.'\n --> test:1:9\n |\n 1 | call foo.aleo r0 r1 into r2;\n | ^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | call foo bar baz into bax;\n | ^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | call foo.aleo r0 r1 into r2;\n | ^^^^"

View File

@ -2,4 +2,5 @@
namespace: ParseInstruction
expectation: Fail
outputs:
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found ';'\n --> test:1:22\n |\n 1 | cast foo bar into baz;\n | ^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | cast foo bar baz bax.soup into fleeces as sheep;\n | ^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | cast foo bar into baz;\n | ^^^^"

View File

@ -2,4 +2,5 @@
namespace: ParseInstruction
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected [ -- found 'sender'\n --> test:1:20\n |\n 1 | decrement balances sender by 1u8;\n | ^^^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | decrement balances[sender] by 1u8;\n | ^^^^^^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | decrement balances sender by 1u8;\n | ^^^^^^^^^"

View File

@ -2,4 +2,5 @@
namespace: ParseInstruction
expectation: Fail
outputs:
- "Error [EPAR0370005]: expected [ -- found 'user'\n --> test:1:20\n |\n 1 | increment balances user by 1u8;\n | ^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | increment balances[user] by 1u8;\n | ^^^^^^^^^"
- "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | increment balances user by 1u8;\n | ^^^^^^^^^"

View File

@ -0,0 +1,59 @@
---
namespace: ParseInstruction
expectation: Pass
outputs:
- opcode: Add
operands:
- Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":6}\"}"
- Identifier: "{\"name\":\"tree\",\"span\":\"{\\\"lo\\\":7,\\\"hi\\\":11}\"}"
destinations:
- "{\"name\":\"result\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":23}\"}"
span:
lo: 0
hi: 24
- opcode: Add
operands:
- Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":6}\"}"
- Identifier: "{\"name\":\"r1\",\"span\":\"{\\\"lo\\\":7,\\\"hi\\\":9}\"}"
- Identifier: "{\"name\":\"r4\",\"span\":\"{\\\"lo\\\":10,\\\"hi\\\":12}\"}"
destinations:
- "{\"name\":\"r2\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":20}\"}"
span:
lo: 0
hi: 21
- opcode: Ternary
operands:
- Identifier: "{\"name\":\"floo\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":12}\"}"
- Identifier: "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":13,\\\"hi\\\":16}\"}"
- Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":20}\"}"
destinations:
- "{\"name\":\"fax\",\"span\":\"{\\\"lo\\\":26,\\\"hi\\\":29}\"}"
span:
lo: 0
hi: 30
- opcode: Ternary
operands:
- Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":10}\"}"
- Identifier: "{\"name\":\"r1\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":13}\"}"
destinations:
- "{\"name\":\"r2\",\"span\":\"{\\\"lo\\\":19,\\\"hi\\\":21}\"}"
span:
lo: 0
hi: 22
- opcode: Abs
operands:
- Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":7}\"}"
destinations:
- "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":13,\\\"hi\\\":16}\"}"
span:
lo: 0
hi: 17
- opcode: Abs
operands:
- Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":7}\"}"
- Identifier: "{\"name\":\"bax\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":11}\"}"
destinations:
- "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":20}\"}"
span:
lo: 0
hi: 21

View File

@ -25,7 +25,7 @@ outputs:
- "Error [EPAR0370009]: unexpected string: expected 'expression', found '<='\n --> test:1:1\n |\n 1 | <= x = 10u8;\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', found '>'\n --> test:1:1\n |\n 1 | > x = 10u8;\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', found '..'\n --> test:1:1\n |\n 1 | .. x = 10u8;\n | ^^"
- "Error [EPAR0370005]: expected ; -- found 'x'\n --> test:1:4\n |\n 1 | as x = 10u8;\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', found 'as'\n --> test:1:1\n |\n 1 | as x = 10u8;\n | ^^"
- "Error [EPAR0370032]: `console` statements are not yet supported.\n --> test:1:1\n |\n 1 | console x = 10u8;\n | ^^^^^^^\n |\n = Consider using `assert`, `assert_eq`, or `assert_neq` instead."
- "Error [EPAR0370005]: expected : -- found '='\n --> test:1:7\n |\n 1 | for x = 10u8;\n | ^"
- "Error [EPAR0370005]: expected { -- found '='\n --> test:1:6\n |\n 1 | if x = 10u8;\n | ^"

View File

@ -30,7 +30,7 @@ outputs:
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found '<='\n --> test:1:4\n |\n 1 | x::<=\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found '>'\n --> test:1:4\n |\n 1 | x::>\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found '..'\n --> test:1:4\n |\n 1 | x::..\n | ^^"
- "Error [EPAR0370005]: expected ; -- found '<eof>'\n --> test:1:4\n |\n 1 | x::as\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'as'\n --> test:1:4\n |\n 1 | x::as\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'console'\n --> test:1:4\n |\n 1 | x::console\n | ^^^^^^^"
- "Error [EPAR0370005]: expected ; -- found '<eof>'\n --> test:1:4\n |\n 1 | x::const\n | ^^^^^"
- "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'let'\n --> test:1:4\n |\n 1 | x::let\n | ^^^"

View File

@ -0,0 +1,15 @@
/*
namespace: Compile
expectation: Pass
*/
program test.aleo {
transition hello(a: u8, b: u8) -> u8 {
asm {
add a b into c;
add.w c c into d;
};
let f: u8 = d + 1u8;
return f;
}
}

View File

@ -0,0 +1,18 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
transition hello(a: u8, b: u8) -> u8 {
if a == b {
asm {
add a b into c;
add.w c c into d;
}
return d;
} else {
return a + a;
}
}
}

View File

@ -0,0 +1,17 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
inline adder(a: u8, b: u8) -> u8 {
asm {
add a b into c;
}
return c;
}
transition hello(a: u8, b: u8) -> u8 {
return adder(a, b);
}
}

View File

@ -0,0 +1,18 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
transition main(x: u32) -> bool {
let y: u32 = x;
for i: u32 in 0u32..3u32 {
asm {
sub y 1u32 into z;
}
y = z + z;
}
return y == 0u32;
}
}

View File

@ -0,0 +1,15 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
transition hello(a: u8, b: u8) -> u8 {
asm {
add a b a into c;
add.w c into d;
}
let f: u8 = d + 1u8;
return f;
}
}

View File

@ -0,0 +1,17 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
transition hello(a: u8, b: u8) -> u8 {
let foo: field = 1field;
let bar: u16 = 4u16;
asm {
add a foo into c;
add.w c bar into d;
}
let f: u8 = d + 1u8;
return f;
}
}

View File

@ -0,0 +1,13 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
transition hello(a: u8, b: u8) -> u8 {
asm {
add a b into a;
}
return a;
}
}

View File

@ -45,8 +45,8 @@ program test.aleo {
let ap: i128 = a.shr_wrapped(2u16);
let aq: i128 = a.shr_wrapped(2u32);
let ar: i128 = a.xor(b);
let as: i128 = a.rem(b);
let at: i128 = a.rem_wrapped(b);
let at: i128 = a.rem(b);
let au: i128 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -45,8 +45,8 @@ program test.aleo {
let ap: i16 = a.shr_wrapped(2u16);
let aq: i16 = a.shr_wrapped(2u32);
let ar: i16 = a.xor(b);
let as: i16 = a.rem(b);
let at: i16 = a.rem_wrapped(b);
let at: i16 = a.rem(b);
let au: i16 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -45,8 +45,8 @@ program test.aleo {
let ap: i32 = a.shr_wrapped(2u16);
let aq: i32 = a.shr_wrapped(2u32);
let ar: i32 = a.xor(b);
let as: i32 = a.rem(b);
let at: i32 = a.rem_wrapped(b);
let at: i32 = a.rem(b);
let au: i32 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -45,8 +45,8 @@ program test.aleo {
let ap: i64 = a.shr_wrapped(2u16);
let aq: i64 = a.shr_wrapped(2u32);
let ar: i64 = a.xor(b);
let as: i64 = a.rem(b);
let at: i64 = a.rem_wrapped(b);
let at: i64 = a.rem(b);
let au: i64 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -45,8 +45,8 @@ program test.aleo {
let ap: i8 = a.shr_wrapped(2u16);
let aq: i8 = a.shr_wrapped(2u32);
let ar: i8 = a.xor(b);
let as: i8 = a.rem(b);
let at: i8 = a.rem_wrapped(b);
let at: i8 = a.rem(b);
let au: i8 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -42,9 +42,9 @@ program test.aleo {
let ap: u128 = a.shr_wrapped(2u16);
let aq: u128 = a.shr_wrapped(2u32);
let ar: u128 = a.xor(b);
let as: u128 = a.mod(b);
let at: u128 = a.rem(b);
let au: u128 = a.rem_wrapped(b);
let at: u128 = a.mod(b);
let au: u128 = a.rem(b);
let av: u128 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -43,9 +43,9 @@ program test.aleo {
let ap: u16 = a.shr_wrapped(b);
let aq: u16 = a.shr_wrapped(2u32);
let ar: u16 = a.xor(b);
let as: u16 = a.mod(b);
let at: u16 = a.rem(b);
let au: u16 = a.rem_wrapped(b);
let at: u16 = a.mod(b);
let au: u16 = a.rem(b);
let av: u16 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -43,9 +43,9 @@ program test.aleo {
let ap: u32 = a.shr_wrapped(2u16);
let aq: u32 = a.shr_wrapped(b);
let ar: u32 = a.xor(b);
let as: u32 = a.mod(b);
let at: u32 = a.rem(b);
let au: u32 = a.rem_wrapped(b);
let at: u32 = a.mod(b);
let au: u32 = a.rem(b);
let av: u32 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -42,9 +42,9 @@ program test.aleo {
let ap: u64 = a.shr_wrapped(2u16);
let aq: u64 = a.shr_wrapped(2u32);
let ar: u64 = a.xor(b);
let as: u64 = a.mod(b);
let at: u64 = a.rem(b);
let au: u64 = a.rem_wrapped(b);
let at: u64 = a.mod(b);
let au: u64 = a.rem(b);
let av: u64 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -42,9 +42,9 @@ program test.aleo {
let ap: u8 = a.shr_wrapped(2u16);
let aq: u8 = a.shr_wrapped(2u32);
let ar: u8 = a.xor(b);
let as: u8 = a.mod(b);
let at: u8 = a.rem(b);
let au: u8 = a.rem_wrapped(b);
let at: u8 = a.mod(b);
let au: u8 = a.rem(b);
let av: u8 = a.rem_wrapped(b);
return a == b;
}}

View File

@ -0,0 +1,15 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
asm {}
transition hello(a: u8, b: u8) -> u8 {
let f: u8 = d + 1u8;
return f;
}
}

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
add r0 tree into result;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Fail
*/
add r0 r1 r4 into r2;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
call foo bar baz into bax;

View File

@ -3,4 +3,5 @@ namespace: ParseInstruction
expectation: Fail
*/
call foo bar baz into bax;
call foo.aleo r0 r1 into r2;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
cast foo bar baz bax.soup into fleeces as sheep;

View File

@ -3,4 +3,5 @@ namespace: ParseInstruction
expectation: Fail
*/
cast foo bar baz bax.soup into fleeces as sheep;
cast foo bar into baz;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
decrement balances[sender] by 1u8;

View File

@ -3,4 +3,5 @@ namespace: ParseInstruction
expectation: Fail
*/
decrement balances[sender] by 1u8;
decrement balances sender by 1u8;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
increment balances[user] by 1u8;

View File

@ -3,4 +3,5 @@ namespace: ParseInstruction
expectation: Fail
*/
increment balances[user] by 1u8;
increment balances user by 1u8;

View File

@ -0,0 +1,11 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
add r0 tree into result;
add r0 r1 r4 into r2;
ternary floo bar baz into fax;
ternary r0 r1 into r2;
abs foo into bar;
abs foo bax into bar;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
ternary floo bar baz into fax;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Fail
*/
ternary r0 r1 into r2;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Pass
*/
abs foo into bar;

View File

@ -1,6 +0,0 @@
/*
namespace: ParseInstruction
expectation: Fail
*/
abs foo bax into bar;