<> <> <> <> DIRECTORY RiscAssemblerAGDef, RiscAssemblerBaseDef, RiscAssembler, RiscAssemblerATDef, ThreeC4Support, RedBlackTree; RiscAssemblerDoitImpl: CEDAR PROGRAM IMPORTS RiscAssemblerBaseDef, RiscAssembler, ThreeC4Support EXPORTS RiscAssemblerAGDef= BEGIN OPEN RiscAssemblerAGDef, RiscAssemblerBaseDef, RiscAssembler, RiscAssemblerATDef, ThreeC4Support, RedBlackTree; ProgramlistProdAssemble: PUBLIC PROC[ref: REF ANY] RETURNS[temp0: EncodingSequence, temp1: Table, temp2: INT] = BEGIN tree: ProgramNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ProgramlistProdData _ NARROW[tree.data]; BEGIN codeBody: EncodingSequence; symbolTable: Table; nextAddress: INT; initialAddress: INT; initialTable: Table; initialTable _ InitialSymbolTable[]; initialAddress _ CodeOrigin[]; [symbolTable, nextAddress] _ treeData.List.procs.SymbolTable[treeData.List, initialTable, initialAddress]; codeBody _ treeData.List.procs.CodeSequence[treeData.List, symbolTable]; temp2 _ nextAddress; temp1 _ symbolTable; temp0 _ codeBody; END; END END; ListstatementProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListstatementProdData _ NARROW[tree.data]; temp0 _ treeData.Statement.procs.CodeSequence[treeData.Statement, symbolTable]; END END; ListstatementProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListstatementProdData _ NARROW[tree.data]; [temp0, temp1] _ treeData.Statement.procs.SymbolTable[treeData.Statement, initialTable, initialAddress]; END END; ListdangleProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListdangleProdData _ NARROW[tree.data]; temp0 _ treeData.Statement.procs.CodeSequence[treeData.Statement, symbolTable]; END END; ListdangleProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListdangleProdData _ NARROW[tree.data]; [temp0, temp1] _ treeData.Statement.procs.SymbolTable[treeData.Statement, initialTable, initialAddress]; END END; ListconsProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListconsProdData _ NARROW[tree.data]; BEGIN rest: EncodingSequence; first: EncodingSequence; first _ treeData.Statement.procs.CodeSequence[treeData.Statement, symbolTable]; rest _ treeData.List.procs.CodeSequence[treeData.List, symbolTable]; temp0 _ CodeConcat[first, rest]; END; END END; ListconsProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: ListNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: ListconsProdData _ NARROW[tree.data]; BEGIN newTable: Table; nextAddress: INT; [newTable, nextAddress] _ treeData.Statement.procs.SymbolTable[treeData.Statement, initialTable, initialAddress]; [temp0, temp1] _ treeData.List.procs.SymbolTable[treeData.List, newTable, nextAddress]; END; END END; StatementlabelProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementlabelProdData _ NARROW[tree.data]; temp0 _ treeData.Statement.procs.CodeSequence[treeData.Statement, symbolTable]; END END; StatementlabelProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementlabelProdData _ NARROW[tree.data]; BEGIN newTable: Table; entry: LabelInstance; nextAddress: INT; definedAt: INT; len: INT; len _ treeData.Label.length; definedAt _ treeData.Label.position; nextAddress _ Succ[initialAddress]; entry _ treeData.Label.procs.NotePosition[treeData.Label, initialAddress, definedAt]; newTable _ SymbolConcat[initialTable, entry]; [temp0, temp1] _ treeData.Statement.procs.SymbolTable[treeData.Statement, newTable, nextAddress]; END; END END; StatementopProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementopProdData _ NARROW[tree.data]; BEGIN segment: Encoding; segment _ treeData.Op.procs.Instruction[treeData.Op]; temp0 _ InstructionSequence[segment]; END; END END; StatementopProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementopProdData _ NARROW[tree.data]; BEGIN newTable: Table; nextAddress: INT; nextAddress _ Succ[initialAddress]; newTable _ SymbolCopy[initialTable]; temp1 _ nextAddress; temp0 _ newTable; END; END END; StatementoprandProdCodeSequence: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: EncodingSequence] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementoprandProdData _ NARROW[tree.data]; BEGIN segment: Encoding; label: LabelInstance; label _ treeData.Rand.procs.Index[treeData.Rand, symbolTable]; segment _ treeData.Op.procs.InstructionRand[treeData.Op, label]; temp0 _ InstructionSequence[segment]; END; END END; StatementoprandProdSymbolTable: PUBLIC PROC[ref: REF ANY, initialTable: Table, initialAddress: INT] RETURNS[temp0: Table, temp1: INT] = BEGIN tree: StatementNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: StatementoprandProdData _ NARROW[tree.data]; BEGIN newTable: Table; nextAddress: INT; nextAddress _ Succ[initialAddress]; newTable _ SymbolCopy[initialTable]; temp1 _ nextAddress; temp0 _ newTable; END; END END; LabelidProdNotePosition: PUBLIC PROC[ref: REF ANY, address: INT, definedAt: INT] RETURNS[temp0: LabelInstance] = BEGIN tree: LabelNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: LabelidProdData _ NARROW[tree.data]; temp0 _ NewLabel[treeData.id, address, definedAt]; END END; OpnoopProdInstructionRand: PUBLIC PROC[ref: REF ANY, index: LabelInstance] RETURNS[temp0: Encoding] = BEGIN tree: OpNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; temp0 _ CodeRandFirewall[Opcode.noop, index]; END END; OpnoopProdInstruction: PUBLIC PROC[ref: REF ANY] RETURNS[temp0: Encoding] = BEGIN tree: OpNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; temp0 _ Code[Opcode.noop]; END END; OpgotoProdInstructionRand: PUBLIC PROC[ref: REF ANY, index: LabelInstance] RETURNS[temp0: Encoding] = BEGIN tree: OpNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; temp0 _ CodeRand[Opcode.goto, index]; END END; OpgotoProdInstruction: PUBLIC PROC[ref: REF ANY] RETURNS[temp0: Encoding] = BEGIN tree: OpNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; temp0 _ CodeFirewall[Opcode.goto]; END END; RandidProdIndex: PUBLIC PROC[ref: REF ANY, symbolTable: Table] RETURNS[temp0: LabelInstance] = BEGIN tree: RandNode_ NARROW[ref]; BEGIN ENABLE ThreeC4Support.GetSourceInfo => RESUME[tree.position, tree.length]; treeData: RandidProdData _ NARROW[tree.data]; temp0 _ SymbolIndex[symbolTable, treeData.id]; END END; END..