Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!hplabs!hpl-opus!hpnmdla!darrylo From: darrylo@hpnmdla.sr.hp.com (Darryl Okahata) Newsgroups: comp.sys.handhelds Subject: Re: Chipper source & stuff Message-ID: <1570032@hpnmdla.sr.hp.com> Date: 7 Jun 91 03:57:29 GMT References: <1991Jun6.145732.14924@ugle.unit.no> Organization: HP Network Measurements Div, Santa Rosa, CA Lines: 93 In comp.sys.handhelds, egeberg@solan.unit.no (Christian Egeberg) writes: > Even though I thought I was through with Chip, I suspect > I will give in, and port it to Kernighan-Richie style C. > New mnemonics will be included, and propably conditional > assembly. The program will be tested on some Sun workstation, > SCO 386 Unix, and Microsoft C for MS-DOS. Why don't you run Chipper through Dave Gillespie's excellent p2c program (a Unix-based Pascal-to-C translator)? It won't be perfect, but it'll be a starting point. Just as a test, I ran Chipper though p2c, and it took all of nine seconds. There's a fair amount of work that needs to be done before it can be functional (mainly dealing with FExpand(), FSplit(), and assign()), but it's much easier than hand-translating the code. Here's an example of the translated code. Before: ------------------------------------------------------------------------------- PROCEDURE EncodeDwToken( Instruct: InstPointer; Reg, Symb: SymbolPointer); VAR Param: ParamPointer; Value: LongInt; This: Byte; BEGIN This:= 0; Value:= 0; WITH Instruct^ DO BEGIN Param:= Params; WHILE Param <> NIL DO BEGIN IF NOT ResolveExpression( Param^.Param, Value, Symb) THEN RunWarning( UndefinedWarning); IF RangeCheck( Value, 0, WordMask, RangeWarning) THEN Value:= Value AND WordMask; Memory[ Address + This]:= Value DIV 256; Memory[ Address + Succ( This)]:= Value MOD 256; Inc( This, 2); Param:= Param^.Next; END; ListInstruction( Address, 2 * Count, Instruct, Count); END; END; ------------------------------------------------------------------------------- and after: ------------------------------------------------------------------------------- Static Void EncodeDwToken(Instruct, Reg, Symb) InstRecord *Instruct; SymbolRecord *Reg, *Symb; { ParamRecord *Param; int Value; uchar This; This = 0; Value = 0; Param = Instruct->Params; while (Param != NULL) { if (!ResolveExpression(Param->Param, &Value, Symb)) RunWarning(UndefinedWarning); if (RangeCheck(Value, 0, WordMask, RangeWarning)) Value &= WordMask; Memory[Instruct->Address + This - StartAddress] = Value / 256; Memory[Instruct->Address + This - StartAddress + 1] = Value & 255; This += 2; Param = Param->Next; } ListInstruction(Instruct->Address, Instruct->Count * 2, Instruct, Instruct->Count); } ------------------------------------------------------------------------------- It's very nice. -- Darryl Okahata Internet: darrylo%sr@relay.hp.com P.S. -- For those people who would like a version of p2c that runs under MSDOS: don't ask me about it. While it might be possible if p2c was compiled using a DOS extender, it would be a lot of work, take up enourmous amounts of memory (a 386 would be a MUST), and it would not work under Windows 3.0 (it would have to use extended -- not expanded -- memory). DISCLAIMER: this message is the author's personal opinion and does not constitute the support, opinion or policy of Hewlett-Packard or of the little green men that have been following him all day.