ORCA-C/Asm.pas

1 line
20 KiB
ObjectPascal
Raw Normal View History

{$optimize 7} {---------------------------------------------------------------} { } { Asm } { } { This unit implements the built-in assembler and } { disassembler. } { } { External Subroutines: } { } { AsmFunction - assemble an assembly language function } { AsmStatement - assemble some in-line code } { InitAsm - initialize the assembler } { } {---------------------------------------------------------------} unit Asm; interface {$LibPrefix '0/obj/'} uses CCommon, Table, CGI, Scanner, Symbol, MM, Expression; {$segment 'cc'} procedure AsmFunction (variable: identPtr); { Assemble an assembly language function } { } { parameters: } { variable - pointer to the function variable } procedure AsmStatement; { Assemble some in-line code } procedure InitAsm; { Initialize the assembler } {---------------------------------------------------------------} implementation {---------------------------------------------------------------} var doingAsmFunction: boolean; {was AsmStatement called from AsmFunction?} {- Imported from the parser: -----------------------------------} procedure Match (kind: tokenEnum; err: integer); extern; { insure that the next token is of the specified type } { } { parameters: } { kind - expected token kind } { err - error number if the expected token is not found } {- Private routines --------------------------------------------} function FindLabel (name: stringPtr; definition: boolean): integer; { Find a label in the label list. If none exists, create one. } { } { parameters: } { name - name of the label } { definition - is this the defining point? } label 1; var lb: gotoPtr; {work pointer} lnum: integer; {label number} begin {FindLabel} lb := gotoList; {try to find an existing label} while lb <> nil do begin if lb^.name^ = name^ then begin lnum := lb^.lab; goto 1; end; lb := lb^.next; end; {while} lb := pointer(Malloc(sizeof(gotoRecord))); {no label record exists: create one} lb^.next := gotoList; gotoList := lb; lb^.name := name; lnum := GenLabel; lb^.lab := lnum; lb^.defined := false; 1: if definition then begin if lb^.defined then Error(77) else begin lb^.defined := true; Gen1(dc_lab, lb^.lab); end; {else} end; {if} FindLabel := lnum; end; {FindLabel} {- Global routines ---------------------------------------------} procedure AsmFunction {variable: identPtr}; { Assemble an assembly language function } { } { parameters: } { variable - pointer to the function variable } var tl: tempPtr; {work pointer} begin {AsmFunction} {process the statements} doingAsmFunction := true; AsmStatement; doingAsmFunction := false; {finish the subroutine} Gen0 (dc_enp); {finish t