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

Allow running online-change-example #10

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
54c78d9
ci: rename workflow, update readme
ghaith Jun 10, 2024
c186d0e
refactor(AST): introduce AstVisitor trait (#1231)
riederm Jun 12, 2024
b545e41
codegen: Add mangling for global variables
CohenArthur Mar 20, 2024
7a29d58
rusty: Update testsuite for new global variable section names
CohenArthur Mar 20, 2024
f880974
section_mangler: Change API for `SectionMangler::with_return_type`
CohenArthur Apr 18, 2024
15b8704
codegen: Propagate errors better when creating section names
CohenArthur Apr 18, 2024
92e586a
Merge pull request #1198 from embecosm/move-variables-to-sections
ghaith Jun 12, 2024
823dc54
section_mangler: Encode structs and enums
CohenArthur Mar 20, 2024
28b6b41
codegen: Mangle struct and enum types properly
CohenArthur Mar 20, 2024
06ece68
section-mangler: Add base for handling arrays
CohenArthur Mar 20, 2024
2e628ea
codegen: Handle more complex types in mangle_type
CohenArthur Mar 20, 2024
8c8f973
codegen: Mangle type aliases properly
CohenArthur Mar 20, 2024
54e08eb
rusty: Accept snapshots with new section names
CohenArthur Mar 20, 2024
a9d55a1
Merge pull request #1199 from embecosm/encode-complex-types
ghaith Jun 13, 2024
07e893f
section_mangler: Add base for decoding mangled names
CohenArthur Mar 20, 2024
10363b5
section-mangler: Add prefix constant, derive Debug and PartialEq
CohenArthur Mar 27, 2024
9d1ef35
section_mangler: Add struct decoding
CohenArthur Mar 28, 2024
a261e79
section_mangler: Add decoding of enum types
CohenArthur Mar 28, 2024
2df6561
section_mangler: Derive Clone on SectionMangler
CohenArthur Mar 29, 2024
6370241
section_mangler: Add .name() method
CohenArthur Mar 29, 2024
48a1f00
section_mangler: Add parsing of mangled functions
CohenArthur Mar 29, 2024
10d7826
rusty: Update insta testsuite for section mangling.
CohenArthur Apr 18, 2024
5174c2c
Merge pull request #1205 from embecosm/add-decoding-to-section-mangler
ghaith Jun 13, 2024
1a86c8a
Merge remote-tracking branch 'origin/master' into workflow_fixes
ghaith Jun 14, 2024
44df0db
Merge pull request #1246 from PLC-lang/workflow_fixes
ghaith Jun 14, 2024
8d0e9e5
feat: Validate argument count (#1233)
volsa Jun 17, 2024
45f487f
ci: Introduce llvm-lit for Linux (#1243)
volsa Jun 18, 2024
c7f3d82
fix: Bitaccess for VAR_OUTPUT (#1214)
volsa Jun 19, 2024
ef09b87
fix: for loops no longer execute once when condition is already met (…
mhasel Jun 27, 2024
4aea520
feat: Add --ast CLI argument to emit the AST to stdout (#1256)
nturley-copia Jul 9, 2024
79abdb6
feat: Introduce `REF=` and `REFERENCE_TO` (#1251)
volsa Jul 10, 2024
0397288
chore: Enable logging in VSCode debug view (#1262)
volsa Jul 17, 2024
0c04d54
chore: Bump openssl from 0.10.64 to 0.10.66 (#1264)
dependabot[bot] Jul 23, 2024
446f073
feat: Aliasing (#1258)
volsa Jul 25, 2024
1406d38
fix: Match Option value when parsing alias variables (#1266)
volsa Jul 26, 2024
50dc477
chore: Update README (#1261)
volsa Jul 29, 2024
1ad2fc9
feat: Generate a custom GOT array and save/load its layout
lewis-revill Apr 2, 2024
ac36e70
feat: Access references to globals through a custom GOT
lewis-revill Jun 12, 2024
61eb9b5
feat: Generate calls via the GOT
lewis-revill Jun 19, 2024
c771b2a
section_mangler: Add test for parsing qualified name in section name
CohenArthur Jun 21, 2024
acdf708
variable_generator: Use qualified name when mangling variable sections
CohenArthur Jun 21, 2024
89b1822
rusty: Work around race conditions when compiling multiple modules
CohenArthur Jun 20, 2024
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
  •  
  •  
  •  
File renamed without changes.
35 changes: 35 additions & 0 deletions .github/workflows/lit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build

on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
lit-linux-debug:
name: lit tests (Linux, debug build)
runs-on: ubuntu-latest
container: ghcr.io/plc-lang/rust-llvm:latest
steps:
- uses: actions/checkout@v3

- name: Run `build.sh --lit`
shell: bash
run: |
./scripts/build.sh --lit

lit-linux-release:
name: lit tests (Linux, release build)
runs-on: ubuntu-latest
container: ghcr.io/plc-lang/rust-llvm:latest
steps:
- uses: actions/checkout@v3

- name: Run `build.sh --lit --release`
shell: bash
run: |
./scripts/build.sh --lit --release
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
*.a
*.elf
*.out

# Garbage generated by llvm-lit
tests/lit/**/*.txt
tests/lit/**/Output/
14 changes: 11 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
}
},
"args": [
"target/demo.st",
"target/demo.st"
],
"cwd": "${workspaceFolder}"
"cwd": "${workspaceFolder}",
"env": {
"RUST_LOG": "rusty"
},
"terminal": "integrated"
},
{
"type": "lldb",
Expand All @@ -43,7 +47,11 @@
"args": [
"demo"
],
"cwd": "${workspaceFolder}"
"cwd": "${workspaceFolder}",
"env": {
"RUST_LOG": "rusty"
},
"terminal": "integrated"
},
]
}
12 changes: 8 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 21 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
# RuSTy

[![Rust Build](https://github.com/PLC-lang/rusty/actions/workflows/rust.yml/badge.svg)](https://github.com/PLC-lang/ruSTy/actions)
[![codecov](https://codecov.io/gh/PLC-lang/rusty/branch/master/graph/badge.svg?token=7ZZ5XZYE9V)](https://codecov.io/gh/PLC-lang/rusty)
[![Lines of Code](https://tokei.rs/b1/github/PLC-lang/rusty)](https://github.com/XAMPPRocky/tokei)
<div align="center">
<!-- Eventually(?) we'll have a logo, which we can insert here -->
<h1>RuSTy</h1>
<p>A <a href="https://en.wikipedia.org/wiki/Structured_text">structured text</a> compiler written in Rust, utilizing the LLVM framework for native code compilation.</p>

[Structured text](https://en.wikipedia.org/wiki/Structured_text) compiler written in Rust
<a href="https://github.com/PLC-lang/ruSTy/actions/workflows/linux.yml"><img src="https://github.com/PLC-lang/rusty/actions/workflows/linux.yml/badge.svg"/></a>
<a href="https://github.com/PLC-lang/ruSTy/actions/workflows/windows.yml"><img src="https://github.com/PLC-lang/rusty/actions/workflows/windows.yml/badge.svg"/></a>
<a href="https://plc-lang.github.io/metrics"><img src="https://github.com/PLC-lang/rusty/actions/workflows/metrics.yml/badge.svg"/></a>
<a href="https://codecov.io/gh/PLC-lang/rusty"><img src="https://codecov.io/gh/PLC-lang/rusty/branch/master/graph/badge.svg?token=7ZZ5XZYE9V"/></a>
<a href="https://github.com/XAMPPRocky/tokei"><img src="https://tokei.rs/b1/github/PLC-lang/rusty"/></a>

## About RuSTy
<p>
<a href="https://github.com/PLC-lang/rusty/tree/master/examples">Examples</a> |
<a href="https://plc-lang.github.io/rusty/">Documentation</a> |
<a href="https://github.com/PLC-lang/rusty/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22">Contributing</a>
</p>

RuSTy is a structured text (ST) compiler written in Rust. RuSTy utilizes the
LLVM framework to compile eventually to native code.
</div>

## Getting started

The easiest way to compile this project is to use the provided `Dockerfile`. The project offers a `.devcontainer` when using [VSCode](https://code.visualstudio.com/docs/remote/containers). The Dockerfile offers a linux-image which contains everything you need to run `cargo build` / `cargo test` in the project's root directory.

If you want to build the project without docker, start [here](https://plc-lang.github.io/rusty/build_and_install.html).

### Documentation

The compiler's documentation can be found here: [documentation](https://plc-lang.github.io/rusty/).

### Contributing

If you want to contribute to the project you should look for some [beginner-friendly issues](https://github.com/PLC-lang/rusty/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) and reach out to project's maintainers.

## Why RuSTy
## Why RuSTy?

Structured Text is a popular language in the domain of automation. A standardized specification of the language ([IEC 61131](https://en.wikipedia.org/wiki/IEC_61131)) was published in the 90s. It was updated several times in the meantime, while its initial spirit - being built for cyclic, robust and deterministic automation applications - still applies.

Several automation platform suppliers built proprietary compilers and runtime libraries, native to the vendor's hard- and software platform.

RuSTy is aiming towards a _fast_, _modern_ and _open-source_ industry-grade ST compiler for a wide range of platforms, sticking close to the standard.
RuSTy is aiming towards a **fast**, **modern** and **open-source** industry-grade ST compiler for a wide range of platforms, sticking close to the standard.

## Dependencies
## Getting started

The easiest way to compile this project is to use the provided `Dockerfile`. The project offers a `.devcontainer` when using [VSCode](https://code.visualstudio.com/docs/remote/containers). The Dockerfile offers a linux-image which contains everything you need to run `cargo build` / `cargo test` in the project's root directory.

We use the [_logos_](https://crates.io/crates/logos/)
crate library to perform lexical analysis before a handwritten recursive decent parser creates the AST.
Generating LLVM IR is accomplished with the help of [_inkwell_](https://github.com/TheDan64/inkwell), a Rust-wrapper around the native LLVM C-API.
If you want to build the project without docker, start [here](https://plc-lang.github.io/rusty/build_and_install.html).
74 changes: 59 additions & 15 deletions compiler/plc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ pub enum DataType {
PointerType {
name: Option<String>,
referenced_type: Box<DataTypeDeclaration>,
auto_deref: Option<AutoDerefType>,
},
StringType {
name: Option<String>,
Expand All @@ -504,6 +505,18 @@ pub enum DataType {
},
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AutoDerefType {
/// A plain pointer variable with the auto-deref trait, e.g. VAR_IN_OUT or VAR_INPUT{ref} variables
Default,

/// An alias pointer variable, e.g. `foo AT bar : DINT`
Alias,

/// A reference pointer variable, e.g. `foo : REFERENCE TO DINT;`
Reference,
}

impl DataType {
pub fn set_name(&mut self, new_name: String) {
match self {
Expand Down Expand Up @@ -596,12 +609,14 @@ pub struct AstNode {
#[derive(Debug, Clone, PartialEq)]
pub enum AstStatement {
EmptyStatement(EmptyStatement),
// a placeholder that indicates a default value of a datatype

// A placeholder which indicates a default value of a datatype
DefaultValue(DefaultValue),

// Literals
Literal(AstLiteral),
CastStatement(CastStatement),
MultipliedStatement(MultipliedStatement),

// Expressions
ReferenceExpr(ReferenceExpr),
Identifier(String),
Expand All @@ -613,15 +628,17 @@ pub enum AstStatement {
ParenExpression(Box<AstNode>),
RangeStatement(RangeStatement),
VlaRangeStatement,
// Assignment

// TODO: Merge these variants with a `kind` field?
// Assignments
Assignment(Assignment),
// OutputAssignment
OutputAssignment(Assignment),
//Call Statement
RefAssignment(Assignment),

CallStatement(CallStatement),

// Control Statements
ControlStatement(AstControlStatement),

CaseCondition(Box<AstNode>),
ExitStatement(()),
ContinueStatement(()),
Expand Down Expand Up @@ -662,6 +679,9 @@ impl Debug for AstNode {
AstStatement::OutputAssignment(Assignment { left, right }) => {
f.debug_struct("OutputAssignment").field("left", left).field("right", right).finish()
}
AstStatement::RefAssignment(Assignment { left, right }) => {
f.debug_struct("ReferenceAssignment").field("left", left).field("right", right).finish()
}
AstStatement::CallStatement(CallStatement { operator, parameters }) => f
.debug_struct("CallStatement")
.field("operator", operator)
Expand Down Expand Up @@ -735,9 +755,6 @@ impl Debug for AstNode {
}
AstStatement::ContinueStatement(..) => f.debug_struct("ContinueStatement").finish(),
AstStatement::ExitStatement(..) => f.debug_struct("ExitStatement").finish(),
AstStatement::CastStatement(CastStatement { target, type_name }) => {
f.debug_struct("CastStatement").field("type_name", type_name).field("target", target).finish()
}
AstStatement::ReferenceExpr(ReferenceExpr { access, base }) => {
f.debug_struct("ReferenceExpr").field("kind", access).field("base", base).finish()
}
Expand Down Expand Up @@ -855,6 +872,14 @@ impl AstNode {
matches!(self.stmt, AstStatement::EmptyStatement(..))
}

pub fn is_assignment(&self) -> bool {
matches!(self.stmt, AstStatement::Assignment(..))
}

pub fn is_output_assignment(&self) -> bool {
matches!(self.stmt, AstStatement::OutputAssignment(..))
}

pub fn is_reference(&self) -> bool {
matches!(self.stmt, AstStatement::ReferenceExpr(..))
}
Expand Down Expand Up @@ -1280,8 +1305,11 @@ impl AstFactory {
}

/// creates a new Identifier
pub fn create_identifier(name: &str, location: &SourceLocation, id: AstId) -> AstNode {
AstNode::new(AstStatement::Identifier(name.to_string()), id, location.clone())
pub fn create_identifier<T>(name: &str, location: T, id: AstId) -> AstNode
where
T: Into<SourceLocation>,
{
AstNode::new(AstStatement::Identifier(name.to_string()), id, location.into())
}

pub fn create_unary_expression(
Expand Down Expand Up @@ -1315,6 +1343,19 @@ impl AstFactory {
)
}

// TODO: Merge `create_assignment`, `create_output_assignment` and `create_ref_assignment`
// once the the Assignment AstStatements have been merged and a `kind` field is available
// I.e. something like `AstStatement::Assignment { data, kind: AssignmentKind { Normal, Output, Reference } }
// and then fn create_assignment(kind: AssignmentKind, ...)
pub fn create_ref_assignment(left: AstNode, right: AstNode, id: AstId) -> AstNode {
let location = left.location.span(&right.location);
AstNode::new(
AstStatement::RefAssignment(Assignment { left: Box::new(left), right: Box::new(right) }),
id,
location,
)
}

pub fn create_member_reference(member: AstNode, base: Option<AstNode>, id: AstId) -> AstNode {
let location = base
.as_ref()
Expand Down Expand Up @@ -1413,18 +1454,21 @@ impl AstFactory {
}
}

pub fn create_call_statement(
pub fn create_call_statement<T>(
operator: AstNode,
parameters: Option<AstNode>,
id: usize,
location: SourceLocation,
) -> AstNode {
location: T,
) -> AstNode
where
T: Into<SourceLocation>,
{
AstNode {
stmt: AstStatement::CallStatement(CallStatement {
operator: Box::new(operator),
parameters: parameters.map(Box::new),
}),
location,
location: location.into(),
id,
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/plc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod control_statements;
pub mod literals;
mod pre_processor;
pub mod provider;
pub mod visitor;
Loading
Loading