Skip to content

Commit

Permalink
Move stl/ => std/ with eyes towards namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 30, 2025
1 parent 4d31a13 commit 8e9124e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
- Change sus stl installation directory to $HOME/.sus/VERSION/stl

## 0.2.0 (indev)
- Add Type Inference
- Add Generative Parameter Inference
- Add Template Inference
- Type
- Generative Value
- Latency Count Inference
- Add if/when distinction
- Add `assert`, `clog2` and `sizeof`
- Rename standard library: stl => std

### Technical Changes
- Hindley-Milner for Concrete Typing
- Submodule Instantiation done During Concrete Typing
- tree-sitter-sus has been merged into sus-compiler and is no longer a separate repository
- Rewrote HM Unifier because it didn't properly handle infinite types
- Add test.sus_regression.sh testing to CI
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["sus", "fpga", "vlsi", "hdl", "verilog"]
categories = ["compilers", "text-processing"]
rust-version = "1.80"

include = ["/src", "/stl/*", "/README.md", "/LICENSE", "/CHANGELOG.md", "/build.rs", "/rustfmt.toml"]
include = ["/src", "/std/*", "/README.md", "/LICENSE", "/CHANGELOG.md", "/build.rs", "/rustfmt.toml"]

[workspace]
members = [
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::{fs, path::PathBuf};
fn main() {
let mut install_dir = get_sus_dir();
install_dir.push(env!("CARGO_PKG_VERSION"));
install_dir.push("stl");
install_dir.push("std");

fs::create_dir_all(&install_dir).expect("Failed to create std_lib directory");

copy_dir("stl", &install_dir).expect("Failed to copy STL folder");
copy_dir("std", &install_dir).expect("Failed to copy STD folder");

// Print the path to make it available during the build
println!("cargo:rustc-env=SUS_COMPILER_STD_LIB_PATH={}", install_dir.display());
Expand Down
14 changes: 7 additions & 7 deletions philosophy/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
By making cycle-latency mostly transparent to the programmer, we enable the use of more generic building blocks. These should be grouped into a standard library built specifically for the language.

## Common interfaces
The STL should provide standardized names for common interface types, such as memory read and write ports and AXI ports. This helps standardise the interfaces of distinct libraries, allowing for easier integration.
The Standard Library should provide standardized names for common interface types, such as memory read and write ports and AXI ports. This helps standardise the interfaces of distinct libraries, allowing for easier integration.

## Memory blocks and FIFOs
Configurable Memory primitives and FIFOs should certainly be part of the standard library. These are so fundamental to any hardware design, and appear to be uniquitous across FPGA vendors. These Memory primitives should however not be fully fixed. Attributes such as read latency and read-write conflict resolution vary substantially between vendors, so this should be left up to the target platform. However of course it should always be possible to properly fix these values in situations where the programmer needs them. Such as when one needs a 0-cycle memory read, even if that would mean it would reach terrible timing, or not synthesize at all on some platforms.

This is also the reason why I believe the 'inference' doctrine of defining memory blocks is fundamentally flawed. An inference implementation will always make implicit assumptions about the read latency and read-write conflict, meaning the code isn't properly portable across devices.

### Multi-Clock Memories and FIFOs
It is still up for debate whether multi-clock variants should be implicit from the use, or explicit different types. There are arguments to be made for both approaches. Certainly this gets blurry when making the distinction between synchronous and asynchronous clocks. In any case, multi-clock modules should be available in the STL in some form.
It is still up for debate whether multi-clock variants should be implicit from the use, or explicit different types. There are arguments to be made for both approaches. Certainly this gets blurry when making the distinction between synchronous and asynchronous clocks. In any case, multi-clock modules should be available in the Standard Library in some form.

## Shift registers, skid buffers, packers, unpackers
These are quite natural utilities that any project could use.

## Clock Domain Crossings
Clock Domain Crossings are a famously difficult problem in hardware design, and are a source of many sporadic and difficult to find bugs. The way one does a clock domain crossing also very much depends on the circumstances. Thus again, no all-encompassing generic solution can really be given. However, various common CDC implementations should be offered in the STL, which can then prove connecting code safe using *rythms*.
Clock Domain Crossings are a famously difficult problem in hardware design, and are a source of many sporadic and difficult to find bugs. The way one does a clock domain crossing also very much depends on the circumstances. Thus again, no all-encompassing generic solution can really be given. However, various common CDC implementations should be offered in the Standard Library, which can then prove connecting code safe using *rythms*.

# Implementation of the STL
Generally, a generic implementation can be given for all STL types. But these won't work well on most platforms. For each platform, there should be platform-specific implementations of each of these.
# Implementation of the Standard Library
Generally, a generic implementation can be given for all Standard Library types. But these won't work well on most platforms. For each platform, there should be platform-specific implementations of each of these.

# STL extensions
In fields like HPC, certain interfaces are ubiquitous, such as DDR memory interfaces, HBM, PCIE and Ethernet. In general these don't fit in the standard library itself, as these features are not available on the majority of platforms, but instead could be offered as separate libraries. These could (like with the STL) provide differing implementations over a generic interface, to again enable more cross-platform code.
# Standard Library extensions
In fields like HPC, certain interfaces are ubiquitous, such as DDR memory interfaces, HBM, PCIE and Ethernet. In general these don't fit in the standard library itself, as these features are not available on the majority of platforms, but instead could be offered as separate libraries. These could (like with the Standard Library) provide differing implementations over a generic interface, to again enable more cross-platform code.
8 changes: 4 additions & 4 deletions src/compiler_top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ impl Linker {
if !config().ci {
println!("Standard Library Directory: {STD_LIB_PATH}");
}
let stl_path = PathBuf::from_str(STD_LIB_PATH).expect("Standard library directory is not a valid path?");
self.add_all_files_in_directory(&stl_path, info_mngr);
let std_path = PathBuf::from_str(STD_LIB_PATH).expect("Standard library directory is not a valid path?");
self.add_all_files_in_directory(&std_path, info_mngr);

// Sanity check for the names the compiler knows internally.
// They are defined in stl/core.sus
// Critically, stl/core.sus MUST be the first file to be loaded into the linker. Otherwise the IDs don't point to the correct objects
// They are defined in std/core.sus
// Critically, std/core.sus MUST be the first file to be loaded into the linker. Otherwise the IDs don't point to the correct objects
assert_eq!(self.types[get_builtin_type!("int")].link_info.name, "int");
assert_eq!(self.types[get_builtin_type!("bool")].link_info.name, "bool");

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions sus-proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn get_builtin_type(token_stream: TokenStream) -> TokenStream {

let object_name = string_literal.value();

let core_file_text = std::fs::read_to_string("stl/core.sus").unwrap();
let core_file_text = std::fs::read_to_string("std/core.sus").unwrap();

let re = Regex::new(r"__builtin__\s+struct\s+([a-zA-Z0-9_]+)\s*(?:#\(.*\))?\s*\{").unwrap();

Expand All @@ -93,7 +93,7 @@ pub fn get_builtin_type(token_stream: TokenStream) -> TokenStream {

quote_spanned!(
string_literal.span() =>
compile_error!("Unknown builtin type was not found in stl/core.sus")
compile_error!("Unknown builtin type was not found in std/core.sus")
).into()
}

Expand All @@ -103,7 +103,7 @@ pub fn get_builtin_const(token_stream: TokenStream) -> TokenStream {

let object_name = string_literal.value();

let core_file_text = std::fs::read_to_string("stl/core.sus").unwrap();
let core_file_text = std::fs::read_to_string("std/core.sus").unwrap();

let re = Regex::new(r"__builtin__\s+const\s+.+\s+([a-zA-Z0-9_]+)\s*(?:#\(.*\))?\s*\{").unwrap();

Expand All @@ -118,6 +118,6 @@ pub fn get_builtin_const(token_stream: TokenStream) -> TokenStream {

quote_spanned!(
string_literal.span() =>
compile_error!("Unknown builtin const was not found in stl/core.sus")
compile_error!("Unknown builtin const was not found in std/core.sus")
).into()
}

0 comments on commit 8e9124e

Please sign in to comment.