[Exspiminator-commits] CVS: exspiminator/base NewAssembler.java,1.4,1.5
Status: Alpha
Brought to you by:
nphillips
|
From: Nigel P. <nph...@us...> - 2001-11-22 12:08:03
|
Update of /cvsroot/exspiminator/exspiminator/base
In directory usw-pr-cvs1:/tmp/cvs-serv29304/base
Modified Files:
NewAssembler.java
Log Message:
Add .set
Index: NewAssembler.java
===================================================================
RCS file: /cvsroot/exspiminator/exspiminator/base/NewAssembler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** NewAssembler.java 2001/11/20 12:17:49 1.4
--- NewAssembler.java 2001/11/22 12:01:07 1.5
***************
*** 12,19 ****
+ e.g. A0... this will probably need going over line by line.
- check disp(rX) handling
+ implement the back-patching required for a single pass assembler (or hook up Preprocessor)
- write .align, .byte, .double, .float, .long, .llong, .quad (?), .set (?), .short, .space, .string, .vbyte (?)
- hook it all up to the gui and test
! - remove old assembler stuff that's no longer used (Assembler, Assembling prefs, Glue, PowerPCAssemblingPrefs, Preprocessor (?)
- document (inc release notes?)
- release!
--- 12,21 ----
+ e.g. A0... this will probably need going over line by line.
- check disp(rX) handling
+ - allow stuff like "bdnzt eq, target" i.e. make cr bit index aliases - but how to do other crfs "bdnzt 4*cr5+eq, target"?
+ (see prog-env appendix F)
+ implement the back-patching required for a single pass assembler (or hook up Preprocessor)
- write .align, .byte, .double, .float, .long, .llong, .quad (?), .set (?), .short, .space, .string, .vbyte (?)
- hook it all up to the gui and test
! + remove old assembler stuff that's no longer used (Assembler, Assembling prefs, Glue, PowerPCAssemblingPrefs, Preprocessor (?)
- document (inc release notes?)
- release!
***************
*** 21,26 ****
public class NewAssembler
{
! static final String LONG=".long", BYTE=".byte", ALIGN=".align", SPACE=".space", SHORT=".short";
! static final String[] directives={LONG, BYTE, ALIGN, SPACE, SHORT};
/** Warning levels.*/
static final int IGNORE=0, WARN=1, ERROR=2;
--- 23,28 ----
public class NewAssembler
{
! static final String LONG=".long", BYTE=".byte", ALIGN=".align", SPACE=".space", SHORT=".short", SET=".set";
! static final String[] directives={LONG, BYTE, ALIGN, SPACE, SHORT, SET};
/** Warning levels.*/
static final int IGNORE=0, WARN=1, ERROR=2;
***************
*** 34,37 ****
--- 36,40 ----
Parser parser;
StringBuffer warnings;
+ Map aliases;
public NewAssembler(InstructionSet is)
***************
*** 41,44 ****
--- 44,48 ----
this.encoder=new PowerPCInstructionEncoder(this);
instructions=new HashMap(is.instructions.size()*2);
+ aliases=new HashMap();
for (int i=0; i<is.instructions.size(); i++)
{
***************
*** 64,68 ****
}
- /** Modify to allow alises at some point?*/
int parseInt(String s) throws OperandFormatException
{
--- 68,71 ----
***************
*** 79,84 ****
/** This performs the label substitution or literal parsing for branch targets.
! Also used to allow things like <code>li rA, label</code> and <code>la rA, label(rB)</code>.
! BUG: remember we'll have to deal with aliases too at some point.*/
int resolveLabelOrInt(String target) throws OperandFormatException
{
--- 82,86 ----
/** This performs the label substitution or literal parsing for branch targets.
! Also used to allow things like <code>li rA, label</code> and <code>la rA, label(rB)</code>.*/
int resolveLabelOrInt(String target) throws OperandFormatException
{
***************
*** 166,169 ****
--- 168,179 ----
}
+ /** Returns the aliased value if the argument has been set as an alias, otherwise it returns the argument.*/
+ String replaceAliases(String s)
+ {
+ String r=(String) aliases.get(s);
+ return r!=null ? r : s;
+ }
+
+
/** Returns true if the string is empty, the first character is a digit, or it's
a mnemonic in the current instruction set (since that would mess up our crappy address
***************
*** 208,212 ****
for (int i=0; i<it.getNumOperands(); i++)
{
! opcode=encoder.insertField(opcode, it.getOperandField(i), line.getOperand(i));
//System.err.println("Inserting operand " + i + " which is " + line.getOperand(i));
}
--- 218,223 ----
for (int i=0; i<it.getNumOperands(); i++)
{
! opcode=encoder.insertField(opcode, it.getOperandField(i),
! replaceAliases(line.getOperand(i)));
//System.err.println("Inserting operand " + i + " which is " + line.getOperand(i));
}
***************
*** 239,243 ****
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeInt(parseInt(line.getOperand(i)));
currentAddress+=4;
}
--- 250,254 ----
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeInt(parseInt(replaceAliases(line.getOperand(i))));
currentAddress+=4;
}
***************
*** 247,251 ****
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeByte(parseInt(line.getOperand(i)));
currentAddress+=1;
}
--- 258,262 ----
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeByte(parseInt(replaceAliases(line.getOperand(i))));
currentAddress+=1;
}
***************
*** 259,263 ****
+ currentLineNum);
}
! int operand=parseInt(line.getOperand(0));
if (operand<0 || operand>3)
{
--- 270,274 ----
+ currentLineNum);
}
! int operand=parseInt(replaceAliases(line.getOperand(0)));
if (operand<0 || operand>3)
{
***************
*** 286,290 ****
+ currentLineNum);
}
! int operand=parseInt(line.getOperand(0));
while (operand>0)
{
--- 297,301 ----
+ currentLineNum);
}
! int operand=parseInt(replaceAliases(line.getOperand(0)));
while (operand>0)
{
***************
*** 298,305 ****
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeShort(parseInt(line.getOperand(i)));
currentAddress+=2;
}
}
// else we don't handle it yet
}
--- 309,329 ----
for (int i=0; i<line.getNumOperands(); i++)
{
! output.writeShort(parseInt(replaceAliases(line.getOperand(i))));
currentAddress+=2;
}
}
+ else if (directive==SET)
+ {
+ if (line.getNumOperands()!=2)
+ {
+ throw new AssemblerException("Wrong number of operands ("
+ + line.getNumOperands() + " found, 2 expected) at line "
+ + currentLineNum);
+ }
+ if (aliases.put(line.getOperand(0), replaceAliases(line.getOperand(1)))!=null)
+ {
+ throw new AssemblerException("Duplicate alias at line " + currentLineNum);
+ }
+ }
// else we don't handle it yet
}
***************
*** 317,320 ****
--- 341,345 ----
warnings.setLength(0);
labelTable=labels;
+ aliases.clear();
List incompletes=new ArrayList(100);
ByteArrayOutputStream buffy=new ByteArrayOutputStream();
|