This commit is contained in:
Janggun Lee
2025-01-06 18:45:28 +09:00
parent 021f2cd240
commit fcb6ca2538
15 changed files with 253 additions and 423 deletions

View File

@@ -921,7 +921,7 @@ impl Dtype {
match self {
Self::Unit { .. } => Ok((0, 1)),
Self::Int { width, .. } | Self::Float { width, .. } => {
let size_of = (*width + Self::BITS_OF_BYTE - 1) / Self::BITS_OF_BYTE;
let size_of = (*width).div_ceil(Self::BITS_OF_BYTE);
let align_of = size_of;
Ok((size_of, align_of))

View File

@@ -1155,7 +1155,7 @@ struct State<'i> {
}
impl<'i> State<'i> {
fn new(ir: &'i TranslationUnit, args: Vec<Value>) -> Result<State<'_>, InterpreterError> {
fn new(ir: &'i TranslationUnit, args: Vec<Value>) -> Result<State<'i>, InterpreterError> {
// Interpreter starts with the main function
let func_name = String::from("main");
let func = ir

View File

@@ -17,7 +17,6 @@ use ordered_float::OrderedFloat;
use std::collections::{BTreeMap, HashMap};
use std::hash::{Hash, Hasher};
use crate::write_base::*;
pub use dtype::{Dtype, DtypeError, HasDtype};
pub use interp::{interp, Value};
pub use parse::Parse;
@@ -260,6 +259,16 @@ impl Instruction {
}
}
/// Format `lang_c::ast::{Binary,Unary}Operations` into KECC-IR.
///
/// Most cases, `fmt::Display` is used to format a type to a string. However, in some cases, we
/// can't implement `fmt::Display` for a type as it is defined in another crate. In such cases, we
/// can implement this trait to format the type to a string.
pub trait WriteOp {
/// Change operations into a String.
fn write_operation(&self) -> String;
}
impl WriteOp for ast::BinaryOperator {
fn write_operation(&self) -> String {
match self {

View File

@@ -157,21 +157,3 @@ impl WriteLine for (&BlockId, &Block) {
Ok(())
}
}
impl WriteString for Instruction {
fn write_string(&self) -> String {
format!("{self}")
}
}
impl WriteString for Operand {
fn write_string(&self) -> String {
format!("{self}")
}
}
impl WriteString for BlockExit {
fn write_string(&self) -> String {
format!("{self}")
}
}