Sfoglia il codice sorgente

work on assembler

master
Isabelle L. 5 anni fa
parent
commit
c7fec83d7d
2 ha cambiato i file con 36 aggiunte e 15 eliminazioni
  1. +31
    -12
      ceres-asm/src/lib.rs
  2. +5
    -3
      test.asm

+ 31
- 12
ceres-asm/src/lib.rs Vedi File

@@ -1,28 +1,45 @@
use logos::Logos;

#[derive(Logos, Debug, PartialEq)]
enum Token {
pub enum Token {
// general stuff
#[regex(";.+")]
Comment,
#[token("@")]
At,
#[regex("/[a-z-_]+:/g")]
Label,
// registers
#[token("$t0")]
#[token("$0")]
ZeroRegister,
#[token("$gp")]
#[token("$1")]
GlobalPointer,
#[token("$pc")]
ProgramCounter,
#[token("$sp")]
#[token("$2")]
StackPointer,
#[token("$ra")]
ReturnAddress,
#[token("$a0")]
ArgumentZero,
#[token("$a1")]
ArgumentOne,
#[token("$a2")]
ArgumentTwo,
#[token("$v0")]
ReturnOne,
#[token("$v1")]
ReturnTwo,
#[regex("\\$t[0-6]")]
TemoraryRegister,
#[regex("\\$[0-9]+")]
RegisterIndex,

// literals
#[regex("0x[a-fA-F0-9]+")]
HexLiteral,
#[regex("0b[0-1]+")]
BinaryLiteral,
#[regex("[0-9]+")]
DecimalLiteral,
#[regex("0x[a-fA-F0-9]+", |lex| u16::from_str_radix(&lex.slice()[2..], 16).unwrap() )]
HexLiteral(u16),
#[regex("0b[0-1]+", |lex| u16::from_str_radix(&lex.slice()[2..], 2).unwrap())]
BinaryLiteral(u16),
#[regex("[0-9]+", |lex| lex.slice().parse::<u16>())]
DecimalLiteral(u16),

// instructions
#[token("add")]
@@ -33,6 +50,8 @@ enum Token {
Mul,
#[token("div")]
Div,
#[token("jmp")]
Jmp,

// logos error
#[error]


+ 5
- 3
test.asm Vedi File

@@ -1,3 +1,5 @@
; this is a comment
store $t0 pram:0x5a5a
load
; a simple test application
main:
load $t0 0xcccc
load $t1 0xaaaa
sub $t0 $t1 $t3

Caricamento…
Annulla
Salva