mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-16 07:28:52 +00:00
Update
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user