Compare commits
No commits in common. "8f45c8cf92867e5705fbb987a39778b797cd4b9c" and "64418635a5d3372489a2b3e4c1596505afbedde3" have entirely different histories.
8f45c8cf92
...
64418635a5
@ -105,24 +105,12 @@ impl BlockHolder {
|
||||
}
|
||||
writeln!(f, "{} ({:?}):", self.data.name, self.value)?;
|
||||
|
||||
for instr in &self.instructions {
|
||||
let mut state = Default::default();
|
||||
let mut inner = PadAdapter::wrap(f, &mut state);
|
||||
|
||||
for instr in &self.instructions {
|
||||
instr.builder_fmt(&mut inner, builder, debug)?;
|
||||
}
|
||||
|
||||
if let Some(terminator) = &self.data.terminator {
|
||||
terminator.builder_fmt(&mut inner, builder, debug)?;
|
||||
}
|
||||
if let Some(location) = self.data.terminator_location {
|
||||
writeln!(
|
||||
inner,
|
||||
" ^ (At {}) ",
|
||||
debug.as_ref().unwrap().get_location(location)
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -167,24 +155,6 @@ impl InstructionHolder {
|
||||
}
|
||||
}
|
||||
|
||||
impl TerminatorKind {
|
||||
fn builder_fmt(
|
||||
&self,
|
||||
f: &mut impl std::fmt::Write,
|
||||
builder: &Builder,
|
||||
debug: &Option<DebugInformation>,
|
||||
) -> std::fmt::Result {
|
||||
match self {
|
||||
TerminatorKind::Ret(instr) => writeln!(f, "ret {:?}", instr),
|
||||
TerminatorKind::RetVoid => writeln!(f, "ret void"),
|
||||
TerminatorKind::Br(block) => writeln!(f, "br {:?}", block),
|
||||
TerminatorKind::CondBr(instr, lhs, rhs) => {
|
||||
writeln!(f, "condbr {:?}, {:?} or {:?}", instr, lhs, rhs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugMetadataValue {
|
||||
fn hr(&self, debug: &DebugInformation) -> String {
|
||||
let kind = match debug.get_metadata(*self) {
|
||||
|
@ -25,7 +25,6 @@ struct String {
|
||||
inner: *char,
|
||||
length: u64,
|
||||
max_length: u64,
|
||||
must_be_freed: bool,
|
||||
}
|
||||
|
||||
pub fn new_string() -> String {
|
||||
@ -33,7 +32,6 @@ pub fn new_string() -> String {
|
||||
inner: allocate(0),
|
||||
length: 0,
|
||||
max_length: 0,
|
||||
must_be_freed: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,8 +42,7 @@ pub fn from_str(str: *char) -> String {
|
||||
return String {
|
||||
inner: cloned,
|
||||
length: length,
|
||||
max_length: length,
|
||||
must_be_freed: false,
|
||||
max_length: length
|
||||
};
|
||||
}
|
||||
|
||||
@ -54,12 +51,9 @@ pub fn add_char(string: &mut String, c: char) {
|
||||
let new = allocate((*string).max_length + 4) as *char;
|
||||
copy_bits((*string).inner, new, 0, (*string).max_length);
|
||||
|
||||
if (*string).must_be_freed == true {
|
||||
free((*string).inner as *u8);
|
||||
}
|
||||
(*string).max_length = (*string).max_length + 4;
|
||||
(*string).inner = new;
|
||||
(*string).must_be_freed = true;
|
||||
}
|
||||
|
||||
(*string).inner[(*string).length] = c;
|
||||
@ -67,12 +61,6 @@ pub fn add_char(string: &mut String, c: char) {
|
||||
(*string).length = (*string).length + 1;
|
||||
}
|
||||
|
||||
pub fn set_char(string: &mut String, c: char, position: u64) {
|
||||
if position <= (*string).length {
|
||||
(*string).inner[position] = c;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn free_string(string: &mut String) {
|
||||
free((*string).inner as *u8);
|
||||
}
|
||||
@ -86,21 +74,8 @@ fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
|
||||
}
|
||||
|
||||
fn str_length(string: *char, position: u32) -> u32 {
|
||||
if (string[position] == '\0') {
|
||||
if ((string[position] as u8) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return str_length(string, position + 1) + 1;
|
||||
}
|
||||
|
||||
pub fn add_num_to_str(string: &mut String, num: u64) {
|
||||
if num == 0 { add_char(string, '0'); }
|
||||
else { if num == 1 { add_char(string, '1'); }
|
||||
else { if num == 2 { add_char(string, '2'); }
|
||||
else { if num == 3 { add_char(string, '3'); }
|
||||
else { if num == 4 { add_char(string, '4'); }
|
||||
else { if num == 5 { add_char(string, '5'); }
|
||||
else { if num == 6 { add_char(string, '6'); }
|
||||
else { if num == 7 { add_char(string, '7'); }
|
||||
else { if num == 8 { add_char(string, '8'); }
|
||||
else { if num == 9 { add_char(string, '9'); } } } } } } } } } }
|
||||
}
|
@ -1135,7 +1135,7 @@ impl mir::IfExpression {
|
||||
if let Some(debug) = &scope.debug {
|
||||
let before_location = self.0 .1.into_debug(scope.tokens, debug.scope).unwrap();
|
||||
let before_v = debug.info.location(&debug.scope, before_location);
|
||||
scope.block.set_terminator_location(before_v).ok();
|
||||
scope.block.set_terminator_location(before_v).unwrap();
|
||||
|
||||
let then_location = self
|
||||
.1
|
||||
@ -1177,9 +1177,8 @@ impl mir::IfExpression {
|
||||
|
||||
let opt = else_block.codegen(&mut else_scope, state);
|
||||
|
||||
else_scope.block.terminate(Term::Br(after_bb)).ok();
|
||||
|
||||
if let Some(ret) = opt {
|
||||
else_scope.block.terminate(Term::Br(after_bb)).ok();
|
||||
Some(ret)
|
||||
} else {
|
||||
None
|
||||
|
@ -167,7 +167,7 @@ impl<'a, 'b> TokenStream<'a, 'b> {
|
||||
match T::parse(clone) {
|
||||
Ok(res) => {
|
||||
#[cfg(debug_assertions)]
|
||||
// dbg!(&res);
|
||||
dbg!(&res);
|
||||
let new_pos = ref_pos.max(self.position);
|
||||
Ok((res, new_pos))
|
||||
}
|
||||
|
@ -1,17 +1,11 @@
|
||||
import std::print;
|
||||
import std::from_str;
|
||||
import std::add_char;
|
||||
import std::set_char;
|
||||
import std::free_string;
|
||||
import std::add_num_to_str;
|
||||
|
||||
fn main() -> i32 {
|
||||
let mut test = from_str("hello world");
|
||||
|
||||
add_char(&mut test, '!');
|
||||
set_char(&mut test, 'B', 0);
|
||||
add_num_to_str(&mut test, 7);
|
||||
|
||||
print(&test);
|
||||
|
||||
free_string(&mut test);
|
||||
|
Loading…
Reference in New Issue
Block a user