Skip to content

Commit

Permalink
DREAMWEB: added unused label elimination. Does not work for some labe…
Browse files Browse the repository at this point in the history
…ls, but the most ones are gone.
  • Loading branch information
whoozle committed Jun 15, 2011
1 parent 3b85ded commit c1b9adb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
26 changes: 25 additions & 1 deletion devtools/tasmrecover/tasm/proc.py
Expand Up @@ -16,6 +16,16 @@ def __init__(self, name):
def add_label(self, label):
self.stmts.append(op.label(label))
self.labels.add(label)

def remove_label(self, label):
try:
self.labels.remove(label)
except:
pass
for l in self.stmts:
if isinstance(l, op.label) and l.name == label:
self.stmts.remove(l)
return

def optimize(self):
print "optimizing..."
Expand Down Expand Up @@ -47,7 +57,21 @@ def optimize(self):
self.stmts.pop(i)
else:
i += 1
#fixme: add local?

#eliminating unused labels
for s in list(self.stmts):
if not isinstance(s, op.label):
continue
print "checking label %s..." %s.name
used = False
for j in self.stmts:
if isinstance(j, op.basejmp) and j.label == s.name:
print "used"
used = True
break
if not used:
print self.labels
self.remove_label(s.name)

def add(self, stmt):
#print stmt
Expand Down
28 changes: 0 additions & 28 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -907,7 +907,6 @@ void helicopter(Context &context) {
showgamereel(context);
context.al = context.data.byte(kMapx);
context.es.byte(context.bx+1) = context.al;
helicombatend:
context.ax = context.es.word(context.bx+3);
context._cmp(context.ax, 9);
if (!context.flags.c()) goto notwaitingheli;
Expand Down Expand Up @@ -2807,7 +2806,6 @@ void walking(Context &context) {
context.ax = context.es.word(context.bx);
context.bx = context.pop();
context.es = context.pop();
stillline:
context.es.word(context.bx+10) = context.ax;
return;
endofline:
Expand Down Expand Up @@ -4252,7 +4250,6 @@ void zoom(Context &context) {
zoomswitch:
context._cmp(context.data.byte(kCommandtype), 199);
if (context.flags.c()) goto zoomit;
cantzoom:
putunderzoom(context);
return;
zoomit:
Expand Down Expand Up @@ -5140,7 +5137,6 @@ void greyscalesum(Context &context) {
context.ah = context.data.byte(kAddtored);
context._cmp(context.al, 0);
context._add(context.al, context.ah);
noaddr:
context._stosb();
context.ah = context.data.byte(kAddtogreen);
context.al = context.bl;
Expand Down Expand Up @@ -5805,7 +5801,6 @@ void printslow(Context &context) {
if (!context.flags.z()) goto finishslow2;
keepgoing:
waitframes(context);
noslow:
context._cmp(context.ax, 0);
if (context.flags.z()) goto afterslow;
context._cmp(context.ax, context.data.word(kOldbutton));
Expand Down Expand Up @@ -8816,7 +8811,6 @@ void calcfrframe(Context &context) {
context.ah = 0;
context.data.word(kOffsety) = context.ax;
return;
nullframe:
context.ax = context.pop();
context.cx = 0;
context.data.word(kSavesize) = context.cx;
Expand Down Expand Up @@ -9054,7 +9048,6 @@ void talk(Context &context) {
checkcoords(context);
context._cmp(context.data.byte(kGetback), 0);
if (context.flags.z()) goto waittalk;
finishtalk:
context.bx = context.data.word(kPersondata);
context.es = context.cs;
context._cmp(context.data.byte(kTalkpos), 4);
Expand Down Expand Up @@ -9533,7 +9526,6 @@ void lookatplace(Context &context) {
worktoscreenm(context);
context.cx = 500;
hangonp(context);
afterinfo:
context.data.byte(kPointermode) = 0;
context.data.byte(kPointerframe) = 0;
putundercentre(context);
Expand Down Expand Up @@ -9653,7 +9645,6 @@ void showarrows(Context &context) {

void nextdest(Context &context) {
STACK_CHECK(context);
duok:
context._cmp(context.data.byte(kCommandtype), 218);
if (context.flags.z()) goto alreadydu;
context.data.byte(kCommandtype) = 218;
Expand Down Expand Up @@ -9692,7 +9683,6 @@ void nextdest(Context &context) {

void lastdest(Context &context) {
STACK_CHECK(context);
ddok:
context._cmp(context.data.byte(kCommandtype), 219);
if (context.flags.z()) goto alreadydd;
context.data.byte(kCommandtype) = 219;
Expand Down Expand Up @@ -9904,7 +9894,6 @@ void usemon(Context &context) {
execcommand(context);
context._cmp(context.al, 0);
if (context.flags.z()) goto moreinput;
endmon:
getridoftemp(context);
getridoftempcharset(context);
context.es = context.data.word(kTextfile1);
Expand Down Expand Up @@ -10522,7 +10511,6 @@ void signon(Context &context) {
if (context.flags.z()) goto passpassed;
context._cmp(context.al, context.ah);
if (context.flags.z()) goto checkpass;
passerror:
context.bx = context.pop();
context.es = context.pop();
scrollmonitor(context);
Expand Down Expand Up @@ -11073,7 +11061,6 @@ void delcurs(Context &context) {
context.bx = context.pop();
context.di = context.pop();
multidump(context);
finishcurdel:
context.si = context.pop();
context.dx = context.pop();
context.ds = context.pop();
Expand Down Expand Up @@ -13393,7 +13380,6 @@ void dochange(Context &context) {
if (context.flags.z()) goto object;
context._cmp(context.ch, 1);
if (context.flags.z()) goto freeobject;
path:
context.push(context.cx);
context.ah = 0;
context._add(context.ax, context.ax);
Expand All @@ -13411,7 +13397,6 @@ void dochange(Context &context) {
context.es = context.data.word(kReels);
context.cx = context.pop();
context.es.byte(context.bx+6) = context.cl;
nopath:
return;
object:
context.push(context.cx);
Expand Down Expand Up @@ -14395,7 +14380,6 @@ void usemenu(Context &context) {
restorereels(context);
worktoscreenm(context);
return;
menulist:
return;
}

Expand Down Expand Up @@ -15228,7 +15212,6 @@ void usediary(Context &context) {
redrawmainscrn(context);
worktoscreenm(context);
return;
diarylist:
return;
}

Expand Down Expand Up @@ -15899,7 +15882,6 @@ void checkinput(Context &context) {
context.es.byte(context.bx+1) = 1;
goto afterkey;
nodel2:
spacepress:
context._cmp(context.data.byte(kCursorpos), 14);
if (context.flags.z()) goto nokeypress;
getnamepos(context);
Expand Down Expand Up @@ -16205,7 +16187,6 @@ void saveposition(Context &context) {
context.ds = context.dx;
context.dx = 534;
saveseg(context);
fquit:
closefile(context);
}

Expand Down Expand Up @@ -16769,7 +16750,6 @@ void domix(Context &context) {
context._inc(context.bx);
context._cmp(context.al, context.dh);
if (!context.flags.c()) goto toplot;
botlot:
context._cmp(context.ah, context.dh);
if (!context.flags.c()) goto nodistort;
context._add(context.al, context.ah);
Expand Down Expand Up @@ -16815,7 +16795,6 @@ void domix(Context &context) {
context._inc(context.bx);
context._cmp(context.al, context.dh);
if (!context.flags.c()) goto toplotv;
botlotv:
context._cmp(context.ah, context.dh);
if (!context.flags.c()) goto nodistortv;
context._add(context.al, context.ah);
Expand Down Expand Up @@ -17736,7 +17715,6 @@ void walkandexamine(Context &context) {
diff:
context.data.byte(kCommand) = context.al;
context.data.byte(kCommandtype) = context.ah;
diff2:
context._cmp(context.data.byte(kLinepointer), 254);
if (!context.flags.z()) goto middleofwalk;
context._cmp(context.data.word(kWatchingtime), 0);
Expand Down Expand Up @@ -17851,7 +17829,6 @@ void checkcoords(Context &context) {
if (!context.flags.l()) goto over045;
context.ax = context.cs.word(context.bx+8);
__dispatch_call(context, context.ax);
finished:
context.ax = context.pop();
return;
over045:
Expand Down Expand Up @@ -18472,7 +18449,6 @@ void obname(Context &context) {
diff:
context.data.byte(kCommand) = context.al;
context.data.byte(kCommandtype) = context.ah;
diff2:
context._cmp(context.data.byte(kLinepointer), 254);
if (!context.flags.z()) goto middleofwalk;
context._cmp(context.data.word(kWatchingtime), 0);
Expand Down Expand Up @@ -19004,7 +18980,6 @@ void workoutframes(Context &context) {
context._add(context.ax, 32);
context._sub(context.bx, context.ax);
if (context.flags.c()) goto isinright;
isinleft:
context.cx = context.data.word(kLinestarty);
context._add(context.cx, 32);
context.ax = context.data.word(kLineendy);
Expand Down Expand Up @@ -19057,7 +19032,6 @@ void copyname(Context &context) {
findobname(context);
context.di = context.pop();
context.es = context.cs;
copytext:
context.cx = 28;
make:
context._lodsb();
Expand Down Expand Up @@ -19782,7 +19756,6 @@ void animpointer(Context &context) {
if (context.flags.z()) goto gothand;
context._cmp(context.data.byte(kPointerfirstpath), 0);
if (context.flags.z()) goto gothand;
arrow:
getflagunderp(context);
context._cmp(context.cl, 2);
if (context.flags.c()) goto gothand;
Expand Down Expand Up @@ -20643,7 +20616,6 @@ void dreamweb(Context &context) {
context.data.byte(kCommandtype) = 255;
worktoscreenm(context);
goto mainloop;
alreadyloaded:
context.data.byte(kNewlocation) = 255;
clearsprites(context);
initman(context);
Expand Down

0 comments on commit c1b9adb

Please sign in to comment.