t27c на настоящей машине
Вы узнаете
Тот же компилятор на настоящей машине, печатающий то, что он действительно печатает.
Плеер в уроке 7 запускает компилятор в вашем браузере. Эта запись — нативный t27c, написанный на Rust, запущенный на настоящей машине на том же hello_world.t27: он сообщает статус спеки, тесты и инварианты, которые выпускает, и модуль Verilog с параметрами. Каждый байт записи напечатала команда; инсценирован только набор текста.
Попробуйте
Найдите строку, где t27c печатает параметры модуля Verilog.

t27c 0.4.0 on specs/demos/hello_world.t27: spec-status IMPLEMENTED, the two tests and two invariants the Zig backend emits, and the Verilog module with its parameters.
specs/demos/hello_world.t27
// SPDX-License-Identifier: Apache-2.0
// Hello World Spec for T27 Language Explorer
// This spec demonstrates every major construct in the T27 language
// with explanatory comments about why each part is shaped the way it is.
// Module declaration: every T27 program lives in a module namespace.
// Modules provide encapsulation and prevent name collisions.
module HelloWorld {
use base::types;
// Public constant: specs must declare what reaches hardware.
// Types are mandatory because the compiler needs to know memory layout
// and hardware interface requirements at compile time.
pub const MAGIC_NUMBER : u32 = 0xDEADBEEF;
pub const VERSION : u8 = 1;
pub const FLAG_ENABLE : bool = true;
// Packed struct: memory layout is guaranteed to match hardware expectations.
// The 'packed' keyword ensures no padding bytes are inserted between fields,
// which is critical for hardware communication protocols and memory-mapped registers.
pub struct ConfigPacked {
pub width : u8,
pub height : u8,
pub depth : u8,
pub enable : bool,
}
// Public function with explicit signature: every function must declare its
// parameter types and return type. This is required for type safety and
// hardware interface generation - the compiler needs to know exactly what
// data moves between modules and what operations are valid.
pub fn create_config(width : u8, height : u8, depth : u8) -> ConfigPacked {
// Function body with explicit construction
let config : ConfigPacked = ConfigPacked {
width = width,
height = height,
depth = depth,
enable = FLAG_ENABLE,
};
return config;
}
// Public function that demonstrates computation and type conversion.
// Explicit signatures ensure type safety across hardware boundaries.
pub fn calculate_area(config : ConfigPacked) -> u16 {
// Type conversion is explicit: u8 * u8 -> u16 prevents overflow
let area : u16 = cast(config.width) * cast(config.height);
return area;
}
// Public function demonstrating conditional logic and early returns.
// Explicit return type ensures the function always produces valid hardware data.
pub fn is_config_valid(config : ConfigPacked) -> bool {
// Early return with explicit type checking
if config.width == 0u8 {
return false;
}
if config.height == 0u8 {
return false;
}
if config.depth == 0u8 {
return false;
}
return config.enable;
}
// Test block: tests verify specific behaviors with concrete examples.
// Tests are essential for regression checking and specification validation.
test basic_config_creation
let config = create_config(8u8, 16u8, 3u8)
assert config.width == 8u8
assert config.height == 16u8
assert config.depth == 3u8
assert config.enable == true
// Test block demonstrating computation verification.
// Tests catch logical errors and ensure the implementation matches specification.
test area_calculation
let small_config = create_config(5u8, 7u8, 2u8)
let area = calculate_area(small_config)
assert area == 35u16 // 5 * 7 = 35
// Invariant block: invariants express properties that tests cannot verify.
// While tests check specific cases, invariants declare general truths that
// must hold across all possible executions - they are mathematical assertions
// about the module's behavior that the compiler can leverage for optimization
// and formal verification.
invariant config_field_bounds
// All numeric fields must be within reasonable hardware limits
assert MAGIC_NUMBER <= 0xFFFFFFFFu32
assert VERSION <= 255u8
assert create_config(255u8, 255u8, 255u8).width <= 255u8
// Invariant block demonstrating logical consistency.
// Invariants can express complex relationships between data structures
// that would be impossible to test exhaustively.
invariant area_consistency
// The calculated area must always be positive for valid configs
let test_config = create_config(10u8, 20u8, 1u8)
let area = calculate_area(test_config)
assert area > 0u16
}Все уроки
Модуль 1 · Чип
Что такое FPGA, какой чип у нас и как его выводы встречаются с платой.
Модуль 2 · Числа в железе
Биты, триты и форматы чисел, и сколько стоит арифметика в логике.
Модуль 3 · Ваша программа на t27
Напишите спеку, проверьте её и увидьте, почему «компилируется» не значит «верно».
Модуль 4 · Внутри t27c
Как компилятор читает спеку и что он пишет, включая нативный t27b.
Модуль 5 · От спеки к железу
Verilog, который пишет t27c, ячейки, в которые он превращается, и что делает одна LUT.
Модуль 6 · Читаем синтез
Что yosys сообщает о вашем дизайне и какие предупреждения важны.
Модуль 7 · Размещение, трассировка, тайминг
Где ячейки оказываются на кристалле и успевает ли тактовая частота.
Модуль 8 · Битстрим
Как оттрассированный дизайн становится битами, которые загружает чип, без Vivado.
Модуль 9 · На плате
Спросите чип, кто он, загрузите биты и проверьте их.