Skip to content

Commit

Permalink
Merge pull request #266 from NoxHarmonium/toolchain-printer
Browse files Browse the repository at this point in the history
feat(toolchain): start writing AST printers
  • Loading branch information
NoxHarmonium authored Jul 1, 2024
2 parents 0c5099b + 0f452cf commit 6553e38
Show file tree
Hide file tree
Showing 38 changed files with 761 additions and 277 deletions.
3 changes: 0 additions & 3 deletions examples/hardware-exception/data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@
.DW #33
.DW #10
.DW #0

; TODO: Why do I need this here to make this file parse???
NOOP
8 changes: 8 additions & 0 deletions sirc-vm/.idea/.gitignore

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

103 changes: 103 additions & 0 deletions sirc-vm/.idea/editor.xml

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

8 changes: 8 additions & 0 deletions sirc-vm/.idea/modules.xml

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

23 changes: 23 additions & 0 deletions sirc-vm/.idea/sirc-vm.iml

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

6 changes: 6 additions & 0 deletions sirc-vm/.idea/vcs.xml

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

6 changes: 5 additions & 1 deletion sirc-vm/sirc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::{cell::RefCell, collections::HashSet, fs::File, io::Write, path::PathBu

use debug_adapter::types::{BreakpointRef, VmChannels};
use debugger::yield_to_debugger;
use device_video::VSYNC_INTERRUPT;
use log::{error, info};
use peripheral_bus::{
device::{BusAssertions, Device},
Expand All @@ -30,6 +29,11 @@ use peripheral_bus::{
use peripheral_cpu::CpuPeripheral;
use utils::{cpu_from_bus::cpu_from_bus, frame_reporter::start_loop};

#[cfg(feature = "video")]
use device_video::VSYNC_INTERRUPT;
#[cfg(not(feature = "video"))]
const VSYNC_INTERRUPT: u8 = 0x0;

#[derive(Debug)]
#[allow(clippy::struct_excessive_bools)]
pub struct DebugState {
Expand Down
3 changes: 2 additions & 1 deletion sirc-vm/toolchain/src/bin/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ use nom_supreme::error::ErrorTree;
use nom_supreme::final_parser::{final_parser, Location};

use toolchain::data::object::build_object;
use toolchain::parsers::instruction::{parse_tokens, Token};

use core::panic;
use std::fs::{read_to_string, write};
use std::io;
use std::path::PathBuf;
use toolchain::parsers::shared::parse_tokens;
use toolchain::types::shared::Token;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down
3 changes: 0 additions & 3 deletions sirc-vm/toolchain/src/bin/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ fn main() -> io::Result<()> {
i16::MAX
)
}) as u16,
RefType::SmallOffset => {
panic!("SmallOffset RefType is only supported by the LDMR/STMR instructions")
}
// TODO: Check that the linker RefTypes are correct
// category=Toolchain
// I think LowerWord and UpperWord should be absolute, not relative?
Expand Down
17 changes: 9 additions & 8 deletions sirc-vm/toolchain/src/data/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::parsers::data::DataType;
use crate::parsers::instruction::{DataToken, Token};
use crate::types::data::{DataToken, DataType, DB_VALUE, DQ_VALUE, DW_VALUE};
use crate::types::object::{ObjectDefinition, SymbolDefinition, SymbolRef};
use crate::types::shared::Token;

use peripheral_cpu::coprocessors::processing_unit::definitions::{
ImmediateInstructionData, InstructionData, ShortImmediateInstructionData,
Expand All @@ -11,6 +11,7 @@ use sirc_vm::debug_adapter::types::ObjectDebugInfo;

use sha2::{Digest, Sha256};

use crate::types::shared::NumberToken;
use std::collections::HashMap;

fn resolve_placeholder(
Expand Down Expand Up @@ -61,19 +62,19 @@ fn inject_data_value(
placeholders: &HashMap<String, u32>,
) {
match data.value {
DataType::Value(value) => {
DataType::Value(NumberToken { value, .. }) => {
// TODO: Make packing smaller data sizes in assembled binaries more efficient
// category=Toolchain
// E.g. put 4 DBs in one 32 bit chunk
// TODO: Clean up the data packing code in the Assembler
// category=Refactoring
let bytes: [u8; 4] = match data.size_bytes {
1 => [0x0, 0x0, 0x0, value as u8],
2 => {
DB_VALUE => [0x0, 0x0, 0x0, value as u8],
DW_VALUE => {
let word_bytes = u16::to_be_bytes(value as u16);
[0x0, 0x0, word_bytes[0], word_bytes[1]]
}
4 => u32::to_be_bytes(value),
DQ_VALUE => u32::to_be_bytes(value),
_ => panic!("Unsupported data size bytes {}", data.size_bytes),
};

Expand Down Expand Up @@ -158,7 +159,7 @@ pub fn build_object(
name: data.name,
offset,
}),
Token::Comment => {
Token::Comment(_) => {
// Do nothing.
}
Token::Origin(data) => {
Expand All @@ -177,7 +178,7 @@ pub fn build_object(
offset += INSTRUCTION_SIZE_BYTES;
}
Token::Equ(data) => {
placeholders.insert(data.placeholder_name, data.value);
placeholders.insert(data.placeholder_name, data.number_token.value);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sirc-vm/toolchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

pub mod data;
pub mod parsers;
pub mod printers;
pub mod types;
Loading

0 comments on commit 6553e38

Please sign in to comment.