Skip to content

Commit

Permalink
The three-address code format CFG (#1577)
Browse files Browse the repository at this point in the history
This PR links to the issue#923.

Here's a summary of the tasks related to the new three-address code
format CFG:

1. Define the data structure of the new three-address code format CFG by
using the following files:
  - `src/lir/cfg.rs`: defines the enum type `lir::LIR` and `lir::Block`
- `src/lir/instructions.rs`: defines the enum type
`lir::instructions::Instruction` for instructions
- `src/lir/expressions.rs`: defines the enum type
`lir::expressions::Expression`
  - `src/lir/ssa_type.rs`: defines the enum type `lir::lir_type::Type`

2. Implement a text dump function for the new CFG by using the following
files:
- `src/lir/printer/mod.rs`: defines the struct `lir::printer::Printer`,
which delegates some operations on `lir::vartable::Vartable`
- Other files in the folder `src/lir/printer/`: implement the
`lir::printer::Printer` for the new CFG

3. Convert the old CFG into the new CFG of three-address codes by using
the following files:
- `src/lir/converter/mod.rs`: defines the struct type
`lir::converter::Converter`, which delegates some operations on
`sema::ast::Namespace`
- `src/lir/vartable.rs`: defines the struct type
`lir::vartable::Vartable`, which will later be used in the
`lir::converter::Converter` to mainly keep track of the temporary
identifiers' number, name, and type
- Other files in the folder `src/lir/converter/`: implements the
`lir::converter::Converter`, which converts the
`codegen::cfg::ControlFlowGraph` to the `lir::LIR`

---------

Signed-off-by: FANYI ZHAO <euclideanrn@163.com>
Co-authored-by: Lucas Steuernagel <38472950+LucasSte@users.noreply.github.com>
  • Loading branch information
fanyi-zhao and LucasSte committed Dec 21, 2023
1 parent 358a184 commit 1474831
Show file tree
Hide file tree
Showing 34 changed files with 7,240 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/abi/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl Deduplicate {
}
}

fn unique_name(&mut self, param: &Parameter) -> String {
fn unique_name(&mut self, param: &Parameter<Type>) -> String {
if param.id.is_none() || param.id.as_ref().unwrap().name.is_empty() {
self.try_prefix()
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/abi/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Type {
}

pub fn gen_abi(contract_no: usize, ns: &Namespace) -> Vec<ABI> {
fn parameter_to_abi(param: &Parameter, ns: &Namespace) -> ABIParam {
fn parameter_to_abi(param: &Parameter<Type>, ns: &Namespace) -> ABIParam {
let components = if let Some(n) = param.ty.is_struct_or_array_of_struct() {
ns.structs[n]
.fields
Expand Down
2 changes: 1 addition & 1 deletion src/bin/languageserver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ impl<'a> Builder<'a> {
}

// Constructs struct fields and stores it in the lookup table.
fn field(&mut self, id: usize, field_id: usize, field: &ast::Parameter) {
fn field(&mut self, id: usize, field_id: usize, field: &ast::Parameter<Type>) {
if let Some(loc) = field.ty_loc {
if let Some(dt) = get_type_definition(&field.ty) {
self.references.push((
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ pub struct BasicBlock {
pub struct ControlFlowGraph {
pub name: String,
pub function_no: ASTFunction,
pub params: Arc<Vec<Parameter>>,
pub returns: Arc<Vec<Parameter>>,
pub params: Arc<Vec<Parameter<Type>>>,
pub returns: Arc<Vec<Parameter<Type>>>,
pub vars: Vars,
pub blocks: Vec<BasicBlock>,
pub nonpayable: bool,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod standard_json;
// In Sema, we use result unit for returning early
// when code-misparses. The error will be added to the namespace diagnostics, no need to have anything but unit
// as error.
pub mod lir;
pub mod sema;

use file_resolver::FileResolver;
Expand Down

0 comments on commit 1474831

Please sign in to comment.