Ejemplo n.º 1
0
def FindPtrs(R, typ, adr):
    # VAR fld: ORB.Object; i, s: LONGINT;
    if (typ.form == ORB.Pointer) or (typ.form == ORB.NilTyp):
        Files.WriteInt(R, adr)
    elif typ.form == ORB.Record:
        fld = typ.dsc
        while fld != None:
            FindPtrs(R, fld.type_, fld.val + adr)
            fld = fld.next
    elif typ.form == ORB.Array:
        s = typ.base.size
        for i in range(typ.len_):
            FindPtrs(R, typ.base, i * s + adr)
Ejemplo n.º 2
0
def Close(modid, key, nofent):
    ##  VAR obj: ORB.Object;
    ##    i, comsize, nofimps, nofptrs, size: LONGINT;
    ##    name: ORS.Ident;
    ##    F: Files.File; R: Files.Rider;

    #  (*exit code*)
    if version == 0:
        Put1(Mov, 0, 0, 0)
        Put3(BR, 7, 0)  # (*RISC-0*)
    else:
        Put2(Ldr, LNK, SP, 0)
        Put1(Add, SP, SP, 4)
        Put3(BR, 7, LNK)

    obj = ORB.topScope.next
    nofimps = 0
    comsize = 4
    nofptrs = 0

    while obj != None:
        if (obj.class_ == ORB.Mod) and (obj.dsc != ORB.system):
            nofimps += 1  # (*count imports*)
        elif ((obj.exno != 0) and (obj.class_ == ORB.Const)
              and (obj.type_.form == ORB.Proc) and (obj.type_.nofpar == 0)
              and (obj.type_.base == ORB.noType)):
            i = len(obj.name)  # (*count commands*)
            ##      while obj.name[i] != 0x0:
            ##        i += 1
            i = (i + 4) / 4 * 4
            comsize += i + 4
        elif obj.class_ == ORB.Var:
            nofptrs += NofPtrs(obj.type_)  # (*count pointers*)

        obj = obj.next

    size = varsize + strx + comsize + (
        pc + nofimps + nofent + nofptrs +
        1) * 4  # (*varsize includes type_ descriptors*)

    name = ORB.MakeFileName(modid, ".rsc")  # (*write code file*)

    R = Files.New(name)
    ##  Files.Set(R, F, 0)
    Files.WriteString(R, modid)
    Files.WriteInt(R, key)
    Files.WriteByte(R, version)
    Files.WriteInt(R, size)

    obj = ORB.topScope.next
    while (obj != None) and (obj.class_ == ORB.Mod):  # (*imports*)
        if obj.dsc != ORB.system:
            Files.WriteString(R, obj.orgname)  # removed cast : (ORB.Module)
            Files.WriteInt(R, obj.val)
        obj = obj.next

    Files.Write(R, 0x0)
    Files.WriteInt(R, tdx * 4)

    i = 0
    while i < tdx:
        Files.WriteInt(R, data[i])
        i += 1  # (*type_ descriptors*)

    Files.WriteInt(R, varsize - tdx * 4)  # (*data*)
    Files.WriteInt(R, strx)

    for i in range(strx):
        Files.WriteString(R, str_[i])  # (*strings*)

    Files.WriteInt(R, pc)  # (*code len_*)
    for i in range(pc):
        Files.WriteInt(R, code[i])  # (*program*)

    obj = ORB.topScope.next
    while obj != None:  # (*commands*)
        if ((obj.exno != 0) and (obj.class_ == ORB.Const)
                and (obj.type_.form == ORB.Proc) and (obj.type_.nofpar == 0)
                and (obj.type_.base == ORB.noType)):
            Files.WriteString(R, obj.name)
            Files.WriteInt(R, obj.val)
        obj = obj.next

    Files.Write(R, 0x0)
    Files.WriteInt(R, nofent)
    Files.WriteInt(R, entry)

    obj = ORB.topScope.next
    while obj != None:  # (*entries*)
        if obj.exno != 0:
            if (obj.class_ == ORB.Const) and (obj.type_.form == ORB.Proc) or (
                    obj.class_ == ORB.Var):
                Files.WriteInt(R, obj.val)
            elif obj.class_ == ORB.Typ:
                if obj.type_.form == ORB.Record:
                    Files.WriteInt(R, obj.type_.len_ % 0x10000)
                elif (obj.type_.form
                      == ORB.Pointer) and ((obj.type_.base.typobj == None) or
                                           (obj.type_.base.typobj.exno == 0)):
                    Files.WriteInt(R, obj.type_.base.len_ % 0x10000)

        obj = obj.next

    obj = ORB.topScope.next
    while obj != None:  # (*pointer variables*)
        if obj.class_ == ORB.Var:
            FindPtrs(R, obj.type_, obj.val)
        obj = obj.next

    Files.WriteInt(R, -1)
    Files.WriteInt(R, fixorgP)
    Files.WriteInt(R, fixorgD)
    Files.WriteInt(R, fixorgT)
    Files.WriteInt(R, entry)
    Files.Write(R, "O")
Ejemplo n.º 3
0
def Export(modid, newSF, key):
    global Ref
    Ref = Record + 1
    filename = MakeFileName(modid, ".smb")
    R = Files.New(filename)
    #  Files.Set(R, F, 0)
    Files.WriteInt(R, 0)  #(*placeholder*)
    Files.WriteInt(R, 0)  #(*placeholder for key to be inserted at the end*)
    Files.WriteString(R, modid)
    Write(R, versionkey)

    obj = topScope.next
    while obj != None:
        if obj.expo:
            Write(R, obj.class_)
            Files.WriteString(R, obj.name)
            OutType(R, obj.type_)
            if obj.class_ == Typ:
                if obj.type_.form == Record:
                    obj0 = topScope.next  # (*check whether this is base of previously declared pointer types*)
                    while obj0 != obj:
                        if (obj0.type_.form == Pointer) and (
                                obj0.type_.base
                                == obj.type_) and (obj0.type_.ref > 0):
                            Write(R, obj0.type_.ref)
                        obj0 = obj0.next

                Write(R, 0)

            elif obj.class_ == Const:
                if obj.type_.form == Proc:
                    Files.WriteNum(R, obj.exno)
                elif obj.type_.form == Real:
                    Files.WriteInt(R, obj.val)
                else:
                    Files.WriteNum(R, obj.val)

            elif obj.class_ == Var:
                Files.WriteNum(R, obj.exno)
                if obj.type_.form == String:
                    Files.WriteNum(R, obj.val / 0x10000)
                    obj.val = obj.val % 0x10000

        obj = obj.next

    Write(R, 0)
    ##  while True:
    ##    Write(R, 0)
    ##    if Files.Length(F) % 4 == 0:
    ##      break

    for r in range(Record + 1, maxTypTab):  # Double check range! FIXME
        typtab[r] = None


##  Files.Set(R, F, 0)
##  sum = 0; # (* compute key (checksum) *)
##  while not R.eof:
##    Files.ReadInt(R, x)
##    sum = sum + x
##
##  F1 = Files.Old(filename)  # (*sum is new key*)
##  if F1 != None:
##    Files.Set(R1, F1, 4)
##    Files.ReadInt(R1, oldkey)
##  else:
##    oldkey = sum+1
##
##  if sum != oldkey:
##    if newSF:
##      key = sum
##      Files.Set(R, F, 4)
##      Files.WriteInt(R, sum)
##      Files.Register(F) # (*insert checksum*)
##    else:
##      ORS.Mark("new symbol file inhibited")
##
##  else:
##    newSF = False
##    key = sum

    return modid, newSF, key
Ejemplo n.º 4
0
def OutType(R, t):
    global Ref

    def OutPar(R, par, n):
        if n > 0:
            OutPar(R, par.next, n - 1)
            cl = par.class_
            Write(R, cl)
            if par.rdo:
                Write(R, 1)
            else:
                Write(R, 0)
            OutType(R, par.type_)

    def FindHiddenPointers(R, typ, offset):
        if (typ.form == Pointer) or (typ.form == NilTyp):
            Write(R, Fld)
            Write(R, 0)
            Files.WriteNum(R, offset)
        elif typ.form == Record:
            fld = typ.dsc
            while fld != None:
                FindHiddenPointers(R, fld.type_, fld.val + offset)
                fld = fld.next
        elif typ.form == Array:
            i = 0
            n = typ.len_
            while i < n:
                FindHiddenPointers(R, typ.base, typ.base.size * i + offset)
                i += 1

    if t.ref > 0:  # (*type was already output*)
        Write(R, -t.ref)
    else:
        obj = t.typobj
        if obj != None:
            Write(R, Ref)
            t.ref = Ref
            Ref += 1
        else:  # (*anonymous*)
            Write(R, 0)

        Write(R, t.form)
        if t.form == Pointer:
            if t.base.ref > 0:
                Write(R, -t.base.ref)
            elif (t.base.typobj
                  == None) or not t.base.typobj.expo:  # (*base not exported*)
                Write(R, -1)
            else:
                OutType(R, t.base)

        elif t.form == Array:
            OutType(R, t.base)
            Files.WriteNum(R, t.len_)
            Files.WriteNum(R, t.size)

        elif t.form == Record:
            if t.base != None:
                OutType(R, t.base)
            else:
                OutType(R, noType)

            if obj != None:
                Files.WriteNum(R, obj.exno)
            else:
                Write(R, 0)
            Files.WriteNum(R, t.nofpar)
            Files.WriteNum(R, t.size)
            fld = t.dsc
            while fld != None:  # (*fields*)
                if fld.expo:
                    Write(R, Fld)
                    Files.WriteString(R, fld.name)
                    OutType(R, fld.type_)
                    Files.WriteNum(R, fld.val)
                else:
                    FindHiddenPointers(R, fld.type_, fld.val)

                fld = fld.next

            Write(R, 0)  # indentation!?

        elif t.form == Proc:
            OutType(R, t.base)
            OutPar(R, t.dsc, t.nofpar)
            Write(R, 0)

        if (t.mno > 0) and (obj != None):  # (*re-export, output name*)
            mod = topScope.next
            while (mod != None) and (mod.lev != t.mno):
                mod = mod.next
            if mod != None:
                Files.WriteString(R, mod.name)
                Files.WriteInt(R, mod.val)
                Files.WriteString(R, obj.name)
            else:
                ORS.Mark("re-export not found")
                Write(R, 0)
        else:
            Write(R, 0)