]>
Witch of Git - jade-rose/blob - toolchain/src/bin/assembler.rs
1 use std
::io
::{self, BufRead
};
2 use toolchain
::inst
::{encode
::Encode
, parse
::parse_inst
};
4 macro_rules
! other_err
{
5 ($fmt
:expr $
(, $arg
:expr
)* $
(,)?
) => {
6 io
::Error
::new(io
::ErrorKind
::Other
, format
!($fmt
, $
($arg
),*))
10 fn main() -> io
::Result
<()> {
11 let mut cursor
= io
::Cursor
::new(Vec
::new());
12 for (i
, line
) in io
::stdin().lock().lines().enumerate() {
13 let line
= line
.map_err(|_
| other_err
!("Error reading line {}", i
+ 1))?
;
14 let line
= line
.trim();
18 let inst
= parse_inst(&line
)
19 .ok_or_else(|| other_err
!("Error parsing instruction on line {}", i
+ 1))?
;
20 inst
.encode(&mut cursor
)?
;
22 for line
in cursor
.into
_inner
().chunks(40) {
24 print
!("{:02x}", byte
);