[gccsdk] Objasm record layouts revisited
Christopher Martin
belles at internode.on.net
Sat Oct 31 04:59:24 PDT 2009
A month ago, I offered a tiny patch to objasm intended to allow
expressions with record layout symbols. At the time, I did not
appreciate all the issues with record layouts.
I have since revisited the code and made another attempt to resolve the
long-outstanding issues. More work is probably required, but I think
this attempt is a good start. Sorry it has taken a month to get this
far. It has been many years since I had such difficulty understanding
another's code.
I have attached a diff file and a zip archive of my modified objasm
sources from the 4.1.1 1b release. Note that my files are organised
according to RISC OS convention; I hope this is okay.
--
Regards, Chris.
-------------- next part --------------
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.c.code patched.objasm.c.code
206a207,229
> /* Addition by CPM. Probably needs more work */
> void codeValue(const Value * value)
> {
> switch (value->Tag.t) {
> case ValueInt: codeInt (value->ValueInt.i); break;
> case ValueFloat: codeFloat (value->ValueFloat.f); break;
> case ValueString: codeString (value->ValueString.len, value->ValueString.s); break;
> case ValueBool: codeBool (value->ValueBool.b); break;
> case ValueCode:
> switch (value->ValueCode.c->Tag) {
> case CodeSymbol: codePosition (value->ValueCode.c->CodeSymbol.symbol); break;
> default: error (ErrorSerious, FALSE, "code::codeValue received a non-CodeSymbol ValueCode");
> };
> break;
> case ValueLateLabel:
> codeSymbol (value->ValueLate.late->symbol);
> codeInt (value->ValueLate.i);
> codeOperator (Op_add);
> break;
> case ValueAddr: codeInt (value->ValueAddr.i); break;
> default: error (ErrorSerious, FALSE, "code::codeValue received a Value of unhandled type");
> }
> }
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.c.eval patched.objasm.c.eval
126c126,127
< if (lvalue->Tag.t == ValueAddr && rvalue->Tag.t == ValueInt)
---
> /* Modification by CPM: Allow more flexible operations with ValueAddr labels */
> if ((lvalue->Tag.t & (ValueInt | ValueAddr)) && (rvalue->Tag.t & (ValueInt | ValueAddr)))
128c129,136
< lvalue->ValueAddr.i += rvalue->ValueInt.i;
---
> /* ValueInt and ValueAddr have field i in the same place */
> lvalue->ValueInt.i += rvalue->ValueInt.i;
> if (lvalue->Tag.t == ValueInt && rvalue->Tag.t == ValueAddr)
> {
> /* Transform lvalue from a ValueInt into a ValueAddr like rvalue */
> lvalue->Tag.t = ValueAddr;
> lvalue->ValueAddr.r = rvalue->ValueAddr.r;
> }
129a138
> /* Note that I have relaxed the requirement for identical base registers */
163c172,173
< if (lvalue->Tag.t == ValueAddr && (rvalue->Tag.t & (ValueInt | ValueAddr)))
---
> /* Modification by CPM: Allow more flexible operations with ValueAddr labels */
> if ((lvalue->Tag.t & (ValueInt | ValueAddr)) && (rvalue->Tag.t & (ValueInt | ValueAddr)))
165,170c175,182
< if (rvalue->Tag.t == ValueAddr &&
< lvalue->ValueAddr.r != rvalue->ValueAddr.r)
< return FALSE;
< lvalue->ValueAddr.i -= rvalue->ValueInt.i;
< if (rvalue->Tag.t == ValueAddr)
< lvalue->Tag.t = ValueInt;
---
> /* ValueInt and ValueAddr have field i in the same place */
> lvalue->ValueInt.i -= rvalue->ValueInt.i;
> if (lvalue->Tag.t == ValueInt && rvalue->Tag.t == ValueAddr)
> {
> /* Transform lvalue from a ValueInt into a ValueAddr like rvalue */
> lvalue->Tag.t = ValueAddr;
> lvalue->ValueAddr.r = rvalue->ValueAddr.r;
> }
171a184
> /* Note that I have relaxed the requirement for identical base registers */
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.c.m_cpuctrl patched.objasm.c.m_cpuctrl
241c241
< ir |= LHS_OP (15) | IMM_RHS; /* pc */
---
> ir |= LHS_OP (15) | IMM_RHS; /* pc */ /* Note by CPM: May have to undo this later */
251c251,267
< codePosition (areaCurrent); /* It's relative */
---
> /* Modification by CPM: We no longer assume PC relativity. Instead, we first look
> at what we get by evaluating the label alone. If it turns out to be a ValueAddr
> then we don't do the PC-relative transformation.
> */
> im = exprEval (ValueInt | ValueCode | ValueLateLabel | ValueAddr);
> if (im.Tag.t == ValueAddr)
> {
> if (im.ValueAddr.r != 15) {ir &= ~ LHS_OP (15); ir |= LHS_OP (im.ValueAddr.r);}
> }
> else
> {
> /* Only now that we know we don't have a ValueAddr
> do we perform the PC-relative transformation.
> */
> codeInit ();
> codeValue (&im); /* New function added to <code.c>. Probably needs more work */
> codePosition (areaCurrent);
255a272
> }
258c275
< case ValueInt:
---
> case ValueInt: case ValueAddr: /* Exploiting the common position of field i */
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.c.m_cpumem patched.objasm.c.m_cpumem
206a207,218
> /* Modification by CPM: We no longer assume PC relativity. Instead, we first look
> at what we get by evaluating the label alone. If it turns out to be a ValueAddr
> then we don't do the PC-relative transformation.
> */
> offset = exprEval (ValueInt | ValueCode | ValueLateLabel | ValueAddr);
> if (offset.Tag.t != ValueAddr)
> {
> /* Modification by CPM: Only now that we know we don't have a ValueAddr
> do we perform the PC-relative transformation.
> */
> codeInit ();
> codeValue (&offset); /* New function added to <code.c>. Probably needs more work */
211c223,224
< offset = exprEval (ValueInt | ValueCode | ValueLateLabel | ValueAddr);
---
> offset = exprEval (ValueInt | ValueCode | ValueLateLabel);
> }
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.c.value patched.objasm.c.value
260c260
< printf("(code)\n");
---
> printf("<%d , %p> (code)\n", v->ValueCode.len, v->ValueCode.c);
263c263,269
< printf("(late label)\n");
---
> printf("<%d , %p: <%d , %p: <&%x , %d , %d , %.*s>>> (late label)\n",
> v->ValueLate.i, v->ValueLate.late,
> v->ValueLate.late->factor, v->ValueLate.late->symbol,
> v->ValueLate.late->symbol->type, v->ValueLate.late->symbol->declared, v->ValueLate.late->symbol->used,
> v->ValueLate.late->symbol->len, v->ValueLate.late->symbol->str);
> printf("\t");
> valuePrint(&v->ValueLate.late->symbol->value);
266c272
< printf("(addr)\n");
---
> printf("<r%d,#%d> (addr)\n", v->ValueAddr.r, v->ValueAddr.i);
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.h.code patched.objasm.h.code
71a72,74
> /* Addition by CPM. Probably needs more work */
> void codeValue(const Value * value);
>
diff --minimal --speed-large-files -E -b -B --strip-trailing-cr -t -T -r gccsdk-riscos-tools-src-4/1/1-rel1b.objasm.h.value patched.objasm.h.value
124a125,127
> #else
> /* Modification by CPM: Allows valuePrint calls to not need DEBUG wrapping */
> #define valuePrint(v)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: objasm_411_patched_files.zip
Type: application/compress
Size: 17858 bytes
Desc: not available
URL: <http://www.riscos.info/pipermail/gcc/attachments/20091031/b2156b11/attachment-0001.bin>
More information about the gcc
mailing list