Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Inline Assembly #2322

Draft
wants to merge 31 commits into
base: testnet3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e47170
Add asm token
d0cd Mar 13, 2023
66d02e5
Add AssemblyBlock to AST
d0cd Mar 14, 2023
88a3b24
Add Operand to AST
d0cd Mar 14, 2023
d2afc3f
Add Binary instructions to AST
d0cd Mar 14, 2023
8f4e635
Add Call instruction to AST
d0cd Mar 14, 2023
c17c193
Add Cast instruction to AST
d0cd Mar 14, 2023
7c90766
Add Decrement instruction to AST
d0cd Mar 14, 2023
c287c34
Add Increment statement to AST
d0cd Mar 14, 2023
cb73e71
Add Ternary instruciton to AST
d0cd Mar 14, 2023
9b2a7cc
Add Unary instruction to AST
d0cd Mar 14, 2023
d68acdb
Add Span to ProgramID
d0cd Mar 14, 2023
5f36bda
Regen expectations due to AST changes
d0cd Mar 14, 2023
1fcecd5
Add Aleo instruction symbols
d0cd Mar 22, 2023
3bbd6d8
WIP instruction parser
d0cd Mar 22, 2023
d1e7465
WIP instruction parsing
d0cd Mar 24, 2023
b00e001
More grammar updates
d0cd Mar 24, 2023
0dab9fb
Add parser tests
d0cd Mar 24, 2023
512813e
Refactor Consumer trait
d0cd Mar 24, 2023
ca4d39e
Minimize AST repr for instructions
d0cd Mar 25, 2023
b6238fc
Refactor Reconstructor trait
d0cd Mar 25, 2023
b25818e
Refactor Visitor trait
d0cd Mar 26, 2023
e32136c
Cleanup
d0cd Mar 26, 2023
f2b4e33
Simplify parser
d0cd Mar 26, 2023
7a27b25
Use updated pass traits
d0cd Mar 26, 2023
6a1f855
WIP type checking for instructions
d0cd Mar 26, 2023
bfd04c1
Remove cast, call, increment, decrement opcodes
d0cd Mar 26, 2023
fbcef55
Impl tyc for instructions
d0cd Mar 26, 2023
231f9e9
More safety checks in the parser
d0cd Mar 26, 2023
45ba8d2
Check that ASM block is well-formed
d0cd Mar 26, 2023
586c56b
Implement SSA for inline assembly
d0cd Mar 26, 2023
be6061d
Add compiler tests for assembly instructions
d0cd Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
502 changes: 246 additions & 256 deletions Cargo.lock

Large diffs are not rendered by default.

149 changes: 0 additions & 149 deletions compiler/ast/src/passes/consumer.rs

This file was deleted.

62 changes: 62 additions & 0 deletions compiler/ast/src/passes/consumer/expression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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::*;

/// A Consumer trait for expressions in the AST.
pub trait ExpressionConsumer {
type Output;

fn consume_expression(&mut self, input: Expression) -> Self::Output {
match input {
Expression::Access(access) => self.consume_access(access),
Expression::Binary(binary) => self.consume_binary(binary),
Expression::Call(call) => self.consume_call(call),
Expression::Struct(struct_) => self.consume_struct_init(struct_),
Expression::Err(err) => self.consume_err(err),
Expression::Identifier(identifier) => self.consume_identifier(identifier),
Expression::Literal(value) => self.consume_literal(value),
Expression::Ternary(ternary) => self.consume_ternary(ternary),
Expression::Tuple(tuple) => self.consume_tuple(tuple),
Expression::Unary(unary) => self.consume_unary(unary),
Expression::Unit(unit) => self.consume_unit(unit),
}
}

fn consume_access(&mut self, _input: AccessExpression) -> Self::Output;

fn consume_binary(&mut self, _input: BinaryExpression) -> Self::Output;

fn consume_call(&mut self, _input: CallExpression) -> Self::Output;

fn consume_struct_init(&mut self, _input: StructExpression) -> Self::Output;

fn consume_err(&mut self, _input: ErrExpression) -> Self::Output {
unreachable!("`ErrExpression`s should not be in the AST at this phase of compilation.")
}

fn consume_identifier(&mut self, _input: Identifier) -> Self::Output;

fn consume_literal(&mut self, _input: Literal) -> Self::Output;

fn consume_ternary(&mut self, _input: TernaryExpression) -> Self::Output;

fn consume_tuple(&mut self, _input: TupleExpression) -> Self::Output;

fn consume_unary(&mut self, _input: UnaryExpression) -> Self::Output;

fn consume_unit(&mut self, _input: UnitExpression) -> Self::Output;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +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 leo_ast::*;
use crate::*;

use crate::Unroller;
/// A Consumer trait for instructions in the AST.
pub trait InstructionConsumer {
type Output;

impl ExpressionReconstructor for Unroller<'_> {
type AdditionalOutput = ();
fn consume_instruction(&mut self, input: Instruction) -> Self::Output;
}
30 changes: 30 additions & 0 deletions compiler/ast/src/passes/consumer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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/>.

//! This module contains a Consumer trait for the AST.
//! Consumers are used to completely transform the AST without any restrictions on the output.

pub mod expression;
pub use expression::*;

pub mod instruction;
pub use instruction::*;

pub mod program;
pub use program::*;

pub mod statement;
pub use statement::*;
58 changes: 58 additions & 0 deletions compiler/ast/src/passes/consumer/program.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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::*;

/// A Consumer trait for functions in the AST.
pub trait FunctionConsumer {
type Output;

fn consume_function(&mut self, input: Function) -> Self::Output;
}

/// A Consumer trait for structs in the AST.
pub trait StructConsumer {
type Output;

fn consume_struct(&mut self, input: Struct) -> Self::Output;
}

/// A Consumer trait for imported programs in the AST.
pub trait ImportConsumer {
type Output;

fn consume_import(&mut self, input: Program) -> Self::Output;
}

/// A Consumer trait for mappings in the AST.
pub trait MappingConsumer {
type Output;

fn consume_mapping(&mut self, input: Mapping) -> Self::Output;
}

/// A Consumer trait for program scopes in the AST.
pub trait ProgramScopeConsumer {
type Output;

fn consume_program_scope(&mut self, input: ProgramScope) -> Self::Output;
}

/// A Consumer trait for the program represented by the AST.
pub trait ProgramConsumer {
type Output;
fn consume_program(&mut self, input: Program) -> Self::Output;
}
63 changes: 63 additions & 0 deletions compiler/ast/src/passes/consumer/statement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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::*;

/// A Consumer trait for statements in the AST.
pub trait StatementConsumer {
type Output;

fn consume_statement(&mut self, input: Statement) -> Self::Output {
match input {
Statement::AssemblyBlock(stmt) => self.consume_assembly_block(stmt),
Statement::Assert(assert) => self.consume_assert(assert),
Statement::Assign(stmt) => self.consume_assign(*stmt),
Statement::Block(stmt) => self.consume_block(stmt),
Statement::Conditional(stmt) => self.consume_conditional(stmt),
Statement::Console(stmt) => self.consume_console(stmt),
Statement::Decrement(stmt) => self.consume_decrement(stmt),
Statement::Definition(stmt) => self.consume_definition(stmt),
Statement::Expression(stmt) => self.consume_expression_statement(stmt),
Statement::Increment(stmt) => self.consume_increment(stmt),
Statement::Iteration(stmt) => self.consume_iteration(*stmt),
Statement::Return(stmt) => self.consume_return(stmt),
}
}

fn consume_assembly_block(&mut self, input: AssemblyBlock) -> Self::Output;

fn consume_assert(&mut self, input: AssertStatement) -> Self::Output;

fn consume_assign(&mut self, input: AssignStatement) -> Self::Output;

fn consume_block(&mut self, input: Block) -> Self::Output;

fn consume_conditional(&mut self, input: ConditionalStatement) -> Self::Output;

fn consume_console(&mut self, input: ConsoleStatement) -> Self::Output;

fn consume_decrement(&mut self, input: DecrementStatement) -> Self::Output;

fn consume_definition(&mut self, input: DefinitionStatement) -> Self::Output;

fn consume_expression_statement(&mut self, input: ExpressionStatement) -> Self::Output;

fn consume_increment(&mut self, input: IncrementStatement) -> Self::Output;

fn consume_iteration(&mut self, input: IterationStatement) -> Self::Output;

fn consume_return(&mut self, input: ReturnStatement) -> Self::Output;
}
Loading