- 论坛徽章:
- 0
|
#!/usr/bin/perl
###### data format sample
#R1 <- R2
# opcode op_ld_12
# comment proc_opcode := "00000101"; -- R1 <- R2
# 0: MDR <- mem[PC], PC <- PC + 1
# 1: IR <- MDR, ALUs2 <- R2
# 2: ALU_FUNC = alu_pass_s2, ALUOUT_DEST = R1, ALUOUT <- ALU_OUT
# 3: R1 <- ALUOUT
# a: MDR <- mem[PC], PC <- PC + 1
# b: ALUs2 <- R2, ALU_FUNC <- alu_pass_s2, ALUOUT_DEST <- R1, ALUOUT_LOAD <- 1
# c: WB_DEST <- R1, REG_LOAD <- 1
#
$maxstage = 0;
while(<> {
chop;
if( /^#/ ){
next;
}
if( /^ opcode *(.*)/ ){
$opcode = $1;
next;
}
if( /^ comment *(.*)/ ){
$comment = $1;
$Comment{$opcode} = $comment;
next;
}
if( /^ ([a-z]): *(.*)/ ){
$stage = ord($1) - ord('a');
$microoperations = $2;
#printf( "\$stage=%d, \$microoperations=%s\n", $stage, $microoperations );
$maxstage = $stage if( $maxstage < $stage );
# we skip the first control stage (stage 'a')
next if( $stage == 0 );
@operations = split( /, */, $microoperations );
for( $i=0 ; $i<=$#operations ; $i++ ){
if( $operations[$i] =~ /([^ ]*)[ ]*<-[ ]*([^ ]*)/ ){
$dest = $1;
$value = $2;
$instruction{$opcode}[$stage]{$dest} = $value;
}
}
}
} |
|