2 /* --------------------------------------------------------------------------
3 * GHC interface file processing for Hugs
5 * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
6 * All rights reserved. See NOTICE for details and conditions of use etc...
7 * Hugs version 1.4, December 1997
9 * $RCSfile: interface.c,v $
11 * $Date: 1999/11/29 18:59:28 $
12 * ------------------------------------------------------------------------*/
16 * o use vectored CONSTR_entry when appropriate
17 * o generate export list
19 * Needs GHC changes to generate member selectors,
20 * superclass selectors, etc
22 * o dictionary constructors ?
24 * o Get Hugs/GHC to agree on what interface files look like.
25 * o figure out how to replace the Hugs Prelude with the GHC Prelude
34 #include "Assembler.h" /* for wrapping GHC objects */
38 #define VERBOSITY TRUE
40 extern void print ( Cell, Int );
42 /* --------------------------------------------------------------------------
43 * The "addGHC*" functions act as "impedence matchers" between GHC
44 * interface files and Hugs. Their main job is to convert abstract
45 * syntax trees into Hugs' internal representations.
47 * The main trick here is how we deal with mutually recursive interface
50 * o As we read an import decl, we add it to a list of required imports
51 * (unless it's already loaded, of course).
53 * o Processing of declarations is split into two phases:
55 * 1) While reading the interface files, we construct all the Names,
56 * Tycons, etc declared in the interface file but we don't try to
57 * resolve references to any entities the declaration mentions.
59 * This is done by the "addGHC*" functions.
61 * 2) After reading all the interface files, we finish processing the
62 * declarations by resolving any references in the declarations
63 * and doing any other processing that may be required.
65 * This is done by the "finishGHC*" functions which use the
66 * "fixup*" functions to assist them.
68 * The interface between these two phases are the "ghc*Decls" which
69 * contain lists of decls that haven't been completed yet.
71 * ------------------------------------------------------------------------*/
73 /* --------------------------------------------------------------------------
75 * ------------------------------------------------------------------------*/
77 static List ghcVarDecls;
78 static List ghcConstrDecls;
79 static List ghcSynonymDecls;
80 static List ghcClassDecls;
81 static List ghcInstanceDecls;
83 /* --------------------------------------------------------------------------
84 * local function prototypes:
85 * ------------------------------------------------------------------------*/
87 static List local addGHCConstrs Args((Int,List,List));
88 static Name local addGHCSel Args((Int,Pair));
89 static Name local addGHCConstr Args((Int,Int,Triple));
92 static Void local finishGHCVar Args((Name));
93 static Void local finishGHCConstr Args((Name));
94 static Void local finishGHCSynonym Args((Tycon));
95 static Void local finishGHCClass Args((Class));
96 static Void local finishGHCInstance Args((Inst));
97 static Void local finishGHCImports Args((Triple));
98 static Void local finishGHCExports Args((Pair));
99 static Void local finishGHCModule Args((Module));
101 static Kinds local tvsToKind Args((List));
102 static Int local arityFromType Args((Type));
103 static Int local arityInclDictParams Args((Type));
106 static List local ifTyvarsIn Args((Type));
108 static Type local tvsToOffsets Args((Int,Type,List));
109 static Type local conidcellsToTycons Args((Int,Type));
111 static Void local resolveReferencesInObjectModule Args((Module,Bool));
112 static Bool local validateOImage Args((void*, Int, Bool));
113 static Void local readSyms Args((Module,Bool));
115 static void* local lookupObjName ( char* );
118 /* --------------------------------------------------------------------------
120 * ------------------------------------------------------------------------*/
122 List ifImports; /* [ConId] -- modules imported by current interface */
124 List ghcImports; /* [(Module, Text, [ConId|VarId])]
125 each (m1, m2, names) in this list
126 represents 'module m1 where ... import m2 ( names ) ...'
127 The list acts as a list of names to fix up in
131 List ghcExports; /* [(ConId, -- module name
132 [ ConId | VarId | pair(ConId,[ConId|VarId])] )]
136 List ghcModules; /* [Module] -- modules of the .his loaded in this group */
138 Void addGHCExports(mod,stuff)
141 ghcExports = cons( pair(mod,stuff), ghcExports );
144 static Void local finishGHCExports(paire)
146 Text modTxt = textOf(fst(paire));
147 List entities = snd(paire);
148 Module mod = findModule(modTxt);
150 ERRMSG(0) "Can't find module \"%s\" mentioned in export list",
154 fprintf(stderr, "----------------------------------finishexports\n");
155 /* Assume that each .hi file only contains one export decl */
156 if (nonNull(module(mod).exports))
157 internal("finishGHCExports: non-empty export list");
159 /* Run along what the parser gave us and make export list entries */
160 for (; nonNull(entities); entities=tl(entities)) {
161 Cell ent = hd(entities);
164 switch (whatIs(ent)) {
165 case VARIDCELL: /* variable */
166 c = findName ( snd(ent) );
168 fprintf(stderr, "var %s\n", textToStr(name(c).text));
169 module(mod).exports = cons(c, module(mod).exports);
171 case CONIDCELL: /* non data tycon */
172 c = findTycon ( snd(ent) );
174 fprintf(stderr, "non data tycon %s\n", textToStr(tycon(c).text));
175 module(mod).exports = cons(c, module(mod).exports);
177 default: /* data T = C1 ... Cn or class C where f1 ... fn */
178 if (!isPair(ent)) internal("finishExports(2)");
181 c = findTycon ( snd(ent) );
184 fprintf(stderr, "data %s = ", textToStr(tycon(c).text));
185 module(mod).exports = cons(pair(c,DOTDOT), module(mod).exports);
186 for (; nonNull(subents); subents = tl(subents)) {
187 Cell ent2 = hd(subents);
189 c = findName ( snd(ent2) );
190 fprintf(stderr, "%s ", textToStr(name(c).text));
192 module(mod).exports = cons(c, module(mod).exports);
194 fprintf(stderr, "\n" );
197 c = findClass ( snd(ent) );
199 fprintf(stderr, "class %s where ", textToStr(cclass(c).text));
200 module(mod).exports = cons(pair(c,DOTDOT), module(mod).exports);
202 for (; nonNull(subents); subents = tl(subents)) {
203 Cell ent2 = hd(subents);
205 c = findName ( snd(ent2) );
206 fprintf(stderr, "%s ", textToStr(name(c).text));
208 module(mod).exports = cons(c, module(mod).exports);
210 fprintf(stderr, "\n" );
218 static Void local finishGHCImports(triple)
221 Module dstMod = fst3(triple); // the importing module
222 Text srcTxt = snd3(triple);
223 List names = thd3(triple);
224 Module srcMod = findModule ( srcTxt );
225 Module tmpCurrentModule = currentModule;
231 //fprintf(stderr, "finishGHCImports: dst=%s src=%s\n",
232 // textToStr(module(dstMod).text),
233 // textToStr(srcTxt) );
236 /* for each nm in names
237 nm should be in module(src).exports -- if not, error
238 if nm notElem module(dst).names cons it on
241 if (isNull(srcMod)) {
242 /* I don't think this can actually ever happen, but still ... */
243 ERRMSG(0) "Interface for module \"%s\" imports unknown module \"%s\"",
244 textToStr(module(dstMod).text),
248 //printf ( "exports of %s are\n", textToStr(module(srcMod).text) );
249 //print( module(srcMod).exports, 100 );
252 setCurrModule ( srcMod ); // so that later lookups succeed
254 for (; nonNull(names); names=tl(names)) {
256 /* Check the exporting module really exports it. */
258 for (exps=module(srcMod).exports; nonNull(exps); exps=tl(exps)) {
260 //if (isPair(c)) c=fst(c);
261 assert(whatIs(c)==CONIDCELL || whatIs(c)==VARIDCELL);
262 assert(whatIs(nm)==CONIDCELL || whatIs(nm)==VARIDCELL);
263 //printf( " compare `%s' `%s'\n", textToStr(textOf(c)), textToStr(textOf(nm)));
264 if (textOf(c)==textOf(nm)) { found=TRUE; break; }
267 ERRMSG(0) "Interface for module \"%s\" imports \"%s\" from\n"
268 "module \"%s\", but the latter doesn't export it",
269 textToStr(module(dstMod).text), textToStr(textOf(nm)),
270 textToStr(module(srcMod).text)
273 /* Ok, it's exported. Now figure out what it is we're really
280 if (!cellIsMember(x,module(dstMod).names))
281 module(dstMod).names = cons(x, module(dstMod).names);
287 if (!cellIsMember(x,module(dstMod).tycons))
288 module(dstMod).tycons = cons(x, module(dstMod).tycons);
294 if (!cellIsMember(x,module(dstMod).classes))
295 module(dstMod).classes = cons(x, module(dstMod).classes);
299 fprintf(stderr, "\npanic: Can't figure out what this is in finishGHCImports\n"
300 "\t%s\n", textToStr(tnm) );
301 internal("finishGHCImports");
304 setCurrModule(tmpCurrentModule);
308 Void loadInterface(String fname, Long fileSize)
311 parseInterface(fname,fileSize);
312 if (nonNull(ifImports))
317 Void finishInterfaces ( void )
319 /* the order of these doesn't matter
320 * (ToDo: unless synonyms have to be eliminated??)
322 mapProc(finishGHCVar, ghcVarDecls);
323 mapProc(finishGHCConstr, ghcConstrDecls);
324 mapProc(finishGHCSynonym, ghcSynonymDecls);
325 mapProc(finishGHCClass, ghcClassDecls);
326 mapProc(finishGHCInstance, ghcInstanceDecls);
327 mapProc(finishGHCExports, ghcExports);
328 mapProc(finishGHCImports, ghcImports);
329 mapProc(finishGHCModule, ghcModules);
331 ghcConstrDecls = NIL;
332 ghcSynonymDecls = NIL;
334 ghcInstanceDecls = NIL;
341 static Void local finishGHCModule(mod)
343 // do the implicit 'import Prelude' thing
344 List pxs = module(modulePrelude).exports;
345 for (; nonNull(pxs); pxs=tl(pxs)) {
348 switch (whatIs(px)) {
353 module(mod).names = cons ( px, module(mod).names );
356 module(mod).tycons = cons ( px, module(mod).tycons );
359 module(mod).classes = cons ( px, module(mod).classes );
362 fprintf(stderr, "finishGHCModule: unknown tag %d\n", whatIs(px));
367 // Last, but by no means least ...
368 resolveReferencesInObjectModule ( mod, FALSE );
376 Module m = findModule(t);
379 printf ( "new module %s\n", textToStr(t) );
380 } else if (m != modulePrelude) {
381 ERRMSG(0) "Module \"%s\" already loaded", textToStr(t)
385 // sizeObj and nameObj will magically be set to the right
386 // thing when we arrive here.
387 // All this crud should be replaced with mmap when we do this
389 img = malloc ( sizeObj );
391 ERRMSG(0) "Can't allocate memory to load object file for module \"%s\"",
395 f = fopen( nameObj, "rb" );
397 // Really, this shouldn't happen, since makeStackEntry ensures the
398 // object is available. Nevertheless ...
399 ERRMSG(0) "Object file \"%s\" can't be opened to read -- oops!",
403 if (sizeObj != fread ( img, 1, sizeObj, f)) {
404 ERRMSG(0) "Read of object file \"%s\" failed", nameObj
407 if (!validateOImage(img,sizeObj,VERBOSITY)) {
408 ERRMSG(0) "Validation of object file \"%s\" failed", nameObj
412 assert(!module(m).oImage);
413 module(m).oImage = img;
415 readSyms(m,VERBOSITY);
417 if (!cellIsMember(m, ghcModules))
418 ghcModules = cons(m, ghcModules);
424 Void addGHCImports(line,mn,syms)
426 Text mn; /* the module to import from */
427 List syms; { /* [ConId | VarId] -- the names to import */
431 printf("\naddGHCImport %s\n", textToStr(mn) );
434 // Hack to avoid chasing Prel* junk right now
435 if (strncmp(textToStr(mn), "Prel",4)==0) return;
438 for (t=ifImports; nonNull(t); t=tl(t)) {
439 if (textOf(hd(t)) == mn) {
445 ifImports = cons(mkCon(mn),ifImports);
446 ghcImports = cons( triple(currentModule,mn,syms), ghcImports );
450 void addGHCVar(line,v,ty)
458 /* if this var is the name of a ghc-compiled dictionary,
459 ie, starts zdfC where C is a capital,
464 printf("\nbegin addGHCVar %s\n", s);
466 if (s[0]=='z' && s[1]=='d' && s[2]=='f' && isupper((int)s[3])) {
468 printf(" ignoring %s\n", s);
474 ERRMSG(0) "Attempt to redefine variable \"%s\"", textToStr(v)
479 tvs = nubList(ifTyvarsIn(ty));
480 for (tmp=tvs; nonNull(tmp); tmp=tl(tmp))
481 hd(tmp) = pair(hd(tmp),STAR);
483 ty = mkPolyType(tvsToKind(tvs),ty);
485 ty = tvsToOffsets(line,ty,tvs);
487 /* prepare for finishGHCVar */
489 name(n).arity = arityInclDictParams(ty);
491 ghcVarDecls = cons(n,ghcVarDecls);
493 printf("end addGHCVar %s\n", s);
497 static Void local finishGHCVar(Name n)
499 Int line = name(n).line;
500 Type ty = name(n).type;
502 fprintf(stderr, "\nbegin finishGHCVar %s\n", textToStr(name(n).text) );
504 setCurrModule(name(n).mod);
505 name(n).type = conidcellsToTycons(line,ty);
507 fprintf(stderr, "end finishGHCVar %s\n", textToStr(name(n).text) );
511 Void addGHCSynonym(line,tycon,tvs,ty)
513 Cell tycon; /* ConId */
514 List tvs; /* [(VarId,Kind)] */
516 /* ToDo: worry about being given a decl for (->) ?
517 * and worry about qualidents for ()
519 Text t = textOf(tycon);
520 if (nonNull(findTycon(t))) {
521 ERRMSG(line) "Repeated definition of type constructor \"%s\"",
525 Tycon tc = newTycon(t);
526 tycon(tc).line = line;
527 tycon(tc).arity = length(tvs);
528 tycon(tc).what = SYNONYM;
529 tycon(tc).kind = tvsToKind(tvs);
531 /* prepare for finishGHCSynonym */
532 tycon(tc).defn = tvsToOffsets(line,ty,tvs);
533 ghcSynonymDecls = cons(tc,ghcSynonymDecls);
537 static Void local finishGHCSynonym(Tycon tc)
539 Int line = tycon(tc).line;
541 setCurrModule(tycon(tc).mod);
542 tycon(tc).defn = conidcellsToTycons(line,tycon(tc).defn);
544 /* ToDo: can't really do this until I've done all synonyms
545 * and then I have to do them in order
546 * tycon(tc).defn = fullExpand(ty);
550 Void addGHCDataDecl(line,ctx0,tycon,ktyvars,constrs0)
552 List ctx0; /* [(QConId,VarId)] */
553 Cell tycon; /* ConId */
554 List ktyvars; /* [(VarId,Kind)] */
555 List constrs0; /* [(ConId,[(Type,Text)],NIL)]
556 The NIL will become the constr's type
557 The Text is an optional field name */
558 /* ToDo: worry about being given a decl for (->) ?
559 * and worry about qualidents for ()
562 Type ty, resTy, selTy, conArgTy;
563 List tmp, conArgs, sels, constrs, fields, tyvarsMentioned;
567 Pair conArg, ctxElem;
570 Text t = textOf(tycon);
572 fprintf(stderr, "\nbegin addGHCDataDecl %s\n",textToStr(t));
574 if (nonNull(findTycon(t))) {
575 ERRMSG(line) "Repeated definition of type constructor \"%s\"",
579 Tycon tc = newTycon(t);
581 tycon(tc).line = line;
582 tycon(tc).arity = length(ktyvars);
583 tycon(tc).kind = tvsToKind(ktyvars);
584 tycon(tc).what = DATATYPE;
586 /* a list to accumulate selectors in :: [(VarId,Type)] */
589 /* make resTy the result type of the constr, T v1 ... vn */
591 for (tmp=ktyvars; nonNull(tmp); tmp=tl(tmp))
592 resTy = ap(resTy,fst(hd(tmp)));
594 /* for each constructor ... */
595 for (constrs=constrs0; nonNull(constrs); constrs=tl(constrs)) {
596 constr = hd(constrs);
597 conid = fst3(constr);
598 fields = snd3(constr);
599 assert(isNull(thd3(constr)));
601 /* Build type of constr and handle any selectors found.
602 Also collect up tyvars occurring in the constr's arg
603 types, so we can throw away irrelevant parts of the
607 tyvarsMentioned = NIL; /* [VarId] */
608 conArgs = reverse(fields);
609 for (; nonNull(conArgs); conArgs=tl(conArgs)) {
610 conArg = hd(conArgs); /* (Type,Text) */
611 conArgTy = fst(conArg);
612 conArgNm = snd(conArg);
613 tyvarsMentioned = dupListOnto(ifTyvarsIn(conArgTy),
615 ty = fn(conArgTy,ty);
616 if (nonNull(conArgNm)) {
617 /* a field name is mentioned too */
618 selTy = fn(resTy,conArgTy);
619 if (whatIs(tycon(tc).kind) != STAR)
620 selTy = pair(POLYTYPE,pair(tycon(tc).kind, selTy));
621 selTy = tvsToOffsets(line,selTy, ktyvars);
623 sels = cons( pair(conArgNm,selTy), sels);
627 /* Now ty is the constructor's type, not including context.
628 Throw away any parts of the context not mentioned in
629 tyvarsMentioned, and use it to qualify ty.
632 for (ctx=ctx0; nonNull(ctx); ctx=tl(ctx)) {
633 ctxElem = hd(ctx); /* (QConId,VarId) */
634 if (nonNull(cellIsMember(textOf(snd(ctxElem)),tyvarsMentioned)))
635 ctx2 = cons(ctxElem, ctx2);
638 ty = ap(QUAL,pair(ctx2,ty));
640 /* stick the tycon's kind on, if not simply STAR */
641 if (whatIs(tycon(tc).kind) != STAR)
642 ty = pair(POLYTYPE,pair(tycon(tc).kind, ty));
644 ty = tvsToOffsets(line,ty, ktyvars);
646 /* Finally, stick the constructor's type onto it. */
647 thd3(hd(constrs)) = ty;
650 /* Final result is that
651 constrs :: [(ConId,[(Type,Text)],Type)]
652 lists the constructors and their types
653 sels :: [(VarId,Type)]
654 lists the selectors and their types
656 tycon(tc).defn = addGHCConstrs(line,constrs0,sels);
659 fprintf(stderr, "end addGHCDataDecl %s\n",textToStr(t));
664 static List local addGHCConstrs(line,cons,sels)
666 List cons; /* [(ConId,[(Type,Text)],Type)] */
667 List sels; { /* [(VarId,Type)] */
669 Int conNo = 0; /* or maybe 1? */
670 for(cs=cons; nonNull(cs); cs=tl(cs), conNo++) {
671 Name c = addGHCConstr(line,conNo,hd(cs));
674 for(ss=sels; nonNull(ss); ss=tl(ss)) {
675 hd(ss) = addGHCSel(line,hd(ss));
677 return appendOnto(cons,sels);
680 static Name local addGHCSel(line,sel)
682 Pair sel; /* (VarId,Type) */
684 Text t = textOf(fst(sel));
685 Type type = snd(sel);
687 Name n = findName(t);
689 ERRMSG(line) "Repeated definition for selector \"%s\"",
696 name(n).number = SELNAME;
700 /* prepare for finishGHCVar */
702 ghcVarDecls = cons(n,ghcVarDecls);
707 static Name local addGHCConstr(line,conNo,constr)
710 Triple constr; { /* (ConId,[(Type,Text)],Type) */
711 /* ToDo: add rank2 annotation and existential annotation
712 * these affect how constr can be used.
714 Text con = textOf(fst3(constr));
715 Type type = thd3(constr);
716 Int arity = arityFromType(type);
717 Name n = findName(con); /* Allocate constructor fun name */
719 n = newName(con,NIL);
720 } else if (name(n).defn!=PREDEFINED) {
721 ERRMSG(line) "Repeated definition for constructor \"%s\"",
725 name(n).arity = arity; /* Save constructor fun details */
727 name(n).number = cfunNo(conNo);
729 /* prepare for finishGHCCon */
731 ghcConstrDecls = cons(n,ghcConstrDecls);
736 static Void local finishGHCConstr(Name n)
738 Int line = name(n).line;
739 Type ty = name(n).type;
740 setCurrModule(name(n).mod);
742 printf ( "\nbegin finishGHCConstr %s\n", textToStr(name(n).text));
744 name(n).type = conidcellsToTycons(line,ty);
746 printf ( "end finishGHCConstr %s\n", textToStr(name(n).text));
751 Void addGHCNewType(line,ctx0,tycon,tvs,constr)
753 List ctx0; /* [(QConId,VarId)] */
754 Cell tycon; /* ConId | QualConId */
755 List tvs; /* [(VarId,Kind)] */
756 Cell constr; { /* (ConId,Type) */
757 /* ToDo: worry about being given a decl for (->) ?
758 * and worry about qualidents for ()
762 Text t = textOf(tycon);
763 if (nonNull(findTycon(t))) {
764 ERRMSG(line) "Repeated definition of type constructor \"%s\"",
768 Tycon tc = newTycon(t);
769 tycon(tc).line = line;
770 tycon(tc).arity = length(tvs);
771 tycon(tc).what = NEWTYPE;
772 tycon(tc).kind = tvsToKind(tvs);
773 /* can't really do this until I've read in all synonyms */
775 assert(nonNull(constr));
776 if (isNull(constr)) {
777 tycon(tc).defn = NIL;
779 /* constr :: (ConId,Type) */
780 Text con = textOf(fst(constr));
781 Type type = snd(constr);
782 Name n = findName(con); /* Allocate constructor fun name */
784 n = newName(con,NIL);
785 } else if (name(n).defn!=PREDEFINED) {
786 ERRMSG(line) "Repeated definition for constructor \"%s\"",
790 name(n).arity = 1; /* Save constructor fun details */
792 name(n).number = cfunNo(0);
793 name(n).defn = nameId;
794 tycon(tc).defn = singleton(n);
796 /* prepare for finishGHCCon */
797 /* ToDo: we use finishGHCCon instead of finishGHCVar in case
798 * there's any existential quantification in the newtype -
799 * but I don't think that's allowed in newtype constrs.
800 * Still, no harm done by doing it this way...
803 /* make resTy the result type of the constr, T v1 ... vn */
805 for (tmp=tvs; nonNull(tmp); tmp=tl(tmp))
806 resTy = ap(resTy,fst(hd(tmp)));
807 type = fn(type,resTy);
809 type = ap(QUAL,pair(ctx0,type));
811 type = tvsToOffsets(line,type,tvs);
814 ghcConstrDecls = cons(n,ghcConstrDecls);
819 Void addGHCClass(line,ctxt,tc_name,tv,mems0)
821 List ctxt; /* [(QConId, VarId)] */
822 Cell tc_name; /* ConId */
824 List mems0; { /* [(VarId, Type)] */
825 List mems; /* [(VarId, Type)] */
826 List tvsInT; /* [VarId] and then [(VarId,Kind)] */
827 List tvs; /* [(VarId,Kind)] */
828 Text ct = textOf(tc_name);
829 Pair newCtx = pair(tc_name, tv);
831 printf ( "\nbegin addGHCclass %s\n", textToStr(ct) );
833 if (nonNull(findClass(ct))) {
834 ERRMSG(line) "Repeated definition of class \"%s\"",
837 } else if (nonNull(findTycon(ct))) {
838 ERRMSG(line) "\"%s\" used as both class and type constructor",
842 Class nw = newClass(ct);
843 cclass(nw).text = ct;
844 cclass(nw).line = line;
845 cclass(nw).arity = 1;
846 cclass(nw).head = ap(nw,mkOffset(0));
847 cclass(nw).kinds = singleton(STAR); /* absolutely no idea at all */
848 cclass(nw).instances = NIL; /* what the kind should be */
849 cclass(nw).numSupers = length(ctxt);
851 /* Kludge to map the single tyvar in the context to Offset 0.
852 Need to do something better for multiparam type classes.
854 cclass(nw).supers = tvsToOffsets(line,ctxt,
855 singleton(pair(tv,STAR)));
857 for (mems=mems0; nonNull(mems); mems=tl(mems)) {
859 Type memT = snd(mem);
860 Text mnt = textOf(fst(mem));
863 /* Stick the new context on the member type */
864 if (whatIs(memT)==POLYTYPE) internal("addGHCClass");
865 if (whatIs(memT)==QUAL) {
867 pair(cons(newCtx,fst(snd(memT))),snd(snd(memT))));
870 pair(singleton(newCtx),memT));
873 /* Cook up a kind for the type. */
874 tvsInT = nubList(ifTyvarsIn(memT));
876 /* ToDo: maximally bogus */
877 for (tvs=tvsInT; nonNull(tvs); tvs=tl(tvs))
878 hd(tvs) = pair(hd(tvs),STAR);
880 memT = mkPolyType(tvsToKind(tvsInT),memT);
881 memT = tvsToOffsets(line,memT,tvsInT);
883 /* Park the type back on the member */
886 /* Bind code to the member */
890 "Repeated definition for class method \"%s\"",
894 mn = newName(mnt,NIL);
897 cclass(nw).members = mems0;
898 cclass(nw).numMembers = length(mems0);
899 ghcClassDecls = cons(nw,ghcClassDecls);
902 * cclass(nw).dsels = ?;
903 * cclass(nw).dbuild = ?;
904 * cclass(nm).dcon = ?;
905 * cclass(nm).defaults = ?;
909 printf ( "end addGHCclass %s\n", textToStr(ct) );
913 static Void local finishGHCClass(Class nw)
916 Int line = cclass(nw).line;
917 Int ctr = - length(cclass(nw).members);
920 printf ( "\nbegin finishGHCclass %s\n", textToStr(cclass(nw).text) );
923 setCurrModule(cclass(nw).mod);
925 cclass(nw).level = 0; /* ToDo: 1 + max (map level supers) */
926 cclass(nw).head = conidcellsToTycons(line,cclass(nw).head);
927 cclass(nw).supers = conidcellsToTycons(line,cclass(nw).supers);
928 cclass(nw).members = conidcellsToTycons(line,cclass(nw).members);
930 for (mems=cclass(nw).members; nonNull(mems); mems=tl(mems)) {
931 Pair mem = hd(mems); /* (VarId, Type) */
932 Text txt = textOf(fst(mem));
934 Name n = findName(txt);
936 name(n).line = cclass(nw).line;
938 name(n).number = ctr++;
942 printf ( "end finishGHCclass %s\n", textToStr(cclass(nw).text) );
946 Void addGHCInstance (line,ctxt0,cls,var)
948 List ctxt0; /* [(QConId, Type)] */
949 Pair cls; /* (ConId, [Type]) */
950 Text var; { /* Text */
954 printf ( "\nbegin addGHCInstance\n" );
957 /* Make tvs into a list of tyvars with bogus kinds. */
958 tvs = nubList(ifTyvarsIn(snd(cls)));
960 for (tmp = tvs; nonNull(tmp); tmp=tl(tmp)) {
961 hd(tmp) = pair(hd(tmp),STAR);
965 inst(in).line = line;
966 inst(in).implements = NIL;
968 inst(in).specifics = tvsToOffsets(line,ctxt0,tvs);
969 inst(in).numSpecifics = length(ctxt0);
970 inst(in).head = tvsToOffsets(line,cls,tvs);
972 Is this still needed?
974 Name b = newName(inventText(),NIL);
976 name(b).arity = length(ctxt); /* unused? */
977 name(b).number = DFUNNAME;
978 inst(in).builder = b;
979 bindNameToClosure(b, lookupGHCClosure(inst(in).mod,var));
982 ghcInstanceDecls = cons(in, ghcInstanceDecls);
984 printf ( "end addGHCInstance\n" );
988 static Void local finishGHCInstance(Inst in)
990 Int line = inst(in).line;
991 Cell cl = fst(inst(in).head);
994 printf ( "\nbegin finishGHCInstance\n" );
997 setCurrModule(inst(in).mod);
998 c = findClass(textOf(cl));
1000 ERRMSG(line) "Unknown class \"%s\" in instance",
1001 textToStr(textOf(cl))
1004 inst(in).head = conidcellsToTycons(line,inst(in).head);
1005 inst(in).specifics = conidcellsToTycons(line,inst(in).specifics);
1006 cclass(c).instances = cons(in,cclass(c).instances);
1008 printf ( "end finishGHCInstance\n" );
1012 /* --------------------------------------------------------------------------
1014 * ------------------------------------------------------------------------*/
1016 /* This is called from the addGHC* functions. It traverses a structure
1017 and converts varidcells, ie, type variables parsed by the interface
1018 parser, into Offsets, which is how Hugs wants to see them internally.
1019 The Offset for a type variable is determined by its place in the list
1020 passed as the second arg; the associated kinds are irrelevant.
1022 static Type local tvsToOffsets(line,type,ktyvars)
1025 List ktyvars; { /* [(VarId|Text,Kind)] */
1026 switch (whatIs(type)) {
1034 return ap( tvsToOffsets(line,fun(type),ktyvars),
1035 tvsToOffsets(line,arg(type),ktyvars) );
1039 tvsToOffsets(line,monotypeOf(type),ktyvars)
1043 return pair(QUAL,pair(tvsToOffsets(line,fst(snd(type)),ktyvars),
1044 tvsToOffsets(line,snd(snd(type)),ktyvars)));
1045 case DICTAP: /* bogus ?? */
1046 return ap(DICTAP, tvsToOffsets(line,snd(type),ktyvars));
1047 case VARIDCELL: /* Ha! some real work to do! */
1049 Text tv = textOf(type);
1050 for (; nonNull(ktyvars); i++,ktyvars=tl(ktyvars)) {
1051 Cell varid = fst(hd(ktyvars));
1052 Text tt = isVar(varid) ? textOf(varid) : varid;
1053 if (tv == tt) return mkOffset(i);
1055 ERRMSG(line) "Undefined type variable \"%s\"", textToStr(tv)
1060 fprintf(stderr, "tvsToOffsets: unknown stuff %d\n", whatIs(type));
1062 fprintf(stderr,"\n");
1066 return NIL; /* NOTREACHED */
1070 /* This is called from the finishGHC* functions. It traverses a structure
1071 and converts conidcells, ie, type constructors parsed by the interface
1072 parser, into Tycons (or Classes), which is how Hugs wants to see them
1073 internally. Calls to this fn have to be deferred to the second phase
1074 of interface loading (finishGHC* rather than addGHC*) so that all relevant
1075 Tycons or Classes have been loaded into the symbol tables and can be
1078 static Text kludgeGHCPrelText ( Text m )
1080 if (strncmp(textToStr(m), "Prel", 4)==0)
1081 return textPrelude; else return m;
1084 static Type local conidcellsToTycons(line,type)
1087 switch (whatIs(type)) {
1096 Text m = kludgeGHCPrelText(qmodOf(type));
1097 Text v = qtextOf(type);
1098 Module mod = findModule(m);
1099 //printf ( "lookup qualident " ); print(type,100); printf("\n");
1102 "Undefined module in qualified name \"%s\"",
1107 for (t=module(mod).tycons; nonNull(t); t=tl(t))
1108 if (v == tycon(hd(t)).text) return hd(t);
1109 for (t=module(mod).classes; nonNull(t); t=tl(t))
1110 if (v == cclass(hd(t)).text) return hd(t);
1112 "Undefined qualified class or type \"%s\"",
1120 tc = findQualTycon(type);
1121 if (nonNull(tc)) return tc;
1122 cl = findQualClass(type);
1123 if (nonNull(cl)) return cl;
1125 "Undefined class or type constructor \"%s\"",
1131 return ap( conidcellsToTycons(line,fun(type)),
1132 conidcellsToTycons(line,arg(type)) );
1136 conidcellsToTycons(line,monotypeOf(type))
1140 return pair(QUAL,pair(conidcellsToTycons(line,fst(snd(type))),
1141 conidcellsToTycons(line,snd(snd(type)))));
1142 case DICTAP: /* bogus?? */
1143 return ap(DICTAP, conidcellsToTycons(line, snd(type)));
1145 fprintf(stderr, "conidcellsToTycons: unknown stuff %d\n",
1148 fprintf(stderr,"\n");
1152 return NIL; /* NOTREACHED */
1156 /* --------------------------------------------------------------------------
1159 * None of these do lookups or require that lookups have been resolved
1160 * so they can be performed while reading interfaces.
1161 * ------------------------------------------------------------------------*/
1163 static Kinds local tvsToKind(tvs)
1164 List tvs; { /* [(VarId,Kind)] */
1167 for (rs=reverse(tvs); nonNull(rs); rs=tl(rs)) {
1168 r = ap(snd(hd(rs)),r);
1174 static Int local arityInclDictParams ( Type type )
1177 if (isPolyType(type)) type = monotypeOf(type);
1179 if (whatIs(type) == QUAL)
1181 arity += length ( fst(snd(type)) );
1182 type = snd(snd(type));
1184 while (isAp(type) && getHead(type)==typeArrow) {
1191 /* arity of a constructor with this type */
1192 static Int local arityFromType(type)
1195 if (isPolyType(type)) {
1196 type = monotypeOf(type);
1198 if (whatIs(type) == QUAL) {
1199 type = snd(snd(type));
1201 if (whatIs(type) == EXIST) {
1202 type = snd(snd(type));
1204 if (whatIs(type)==RANK2) {
1205 type = snd(snd(type));
1207 while (isAp(type) && getHead(type)==typeArrow) {
1215 static List local ifTyvarsIn(type)
1217 List vs = typeVarsIn(type,NIL,NIL,NIL);
1219 for (; nonNull(vs2); vs2=tl(vs2)) {
1221 if (whatIs(v)==VARIDCELL || whatIs(v)==VAROPCELL) {
1222 hd(vs2) = textOf(hd(vs2));
1224 internal("ifTyvarsIn");
1231 /* --------------------------------------------------------------------------
1233 * ------------------------------------------------------------------------*/
1235 #if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS)
1239 static char* local findElfSection ( void* objImage, Elf32_Word sh_type )
1242 char* ehdrC = (char*)objImage;
1243 Elf32_Ehdr* ehdr = ( Elf32_Ehdr*)ehdrC;
1244 Elf32_Shdr* shdr = (Elf32_Shdr*) (ehdrC + ehdr->e_shoff);
1246 for (i = 0; i < ehdr->e_shnum; i++) {
1247 if (shdr[i].sh_type == sh_type &&
1248 i != ehdr->e_shstrndx) {
1249 ptr = ehdrC + shdr[i].sh_offset;
1257 static Void local resolveReferencesInObjectModule_elf ( Module m,
1260 char symbol[1000]; // ToDo
1262 Elf32_Sym* stab = NULL;
1264 char* ehdrC = (char*)(module(m).oImage);
1265 Elf32_Ehdr* ehdr = (Elf32_Ehdr*) ehdrC;
1266 Elf32_Shdr* shdr = (Elf32_Shdr*) (ehdrC + ehdr->e_shoff);
1268 // first find "the" symbol table
1269 // why is this commented out???
1270 stab = findElfSection ( ehdrC, SHT_SYMTAB );
1272 // also go find the string table
1273 strtab = findElfSection ( ehdrC, SHT_STRTAB );
1275 if (!stab || !strtab)
1276 internal("resolveReferencesInObjectModule_elf");
1278 for (i = 0; i < ehdr->e_shnum; i++) {
1279 if (shdr[i].sh_type == SHT_REL ) {
1280 Elf32_Rel* rtab = (Elf32_Rel*) (ehdrC + shdr[i].sh_offset);
1281 Int nent = shdr[i].sh_size / sizeof(Elf32_Rel);
1282 Int target_shndx = shdr[i].sh_info;
1283 Int symtab_shndx = shdr[i].sh_link;
1284 stab = (Elf32_Sym*) (ehdrC + shdr[ symtab_shndx ].sh_offset);
1285 targ = (Elf32_Word*)(ehdrC + shdr[ target_shndx ].sh_offset);
1288 "relocations for section %d using symtab %d\n",
1289 target_shndx, symtab_shndx );
1290 for (j = 0; j < nent; j++) {
1291 Elf32_Addr offset = rtab[j].r_offset;
1292 Elf32_Word info = rtab[j].r_info;
1294 Elf32_Addr P = ((Elf32_Addr)targ) + offset;
1295 Elf32_Word* pP = (Elf32_Word*)P;
1299 if (verb) fprintf ( stderr, "Rel entry %3d is raw(%6p %6p) ",
1300 j, (void*)offset, (void*)info );
1302 if (verb) fprintf ( stderr, " ZERO\n" );
1305 if (stab[ ELF32_R_SYM(info)].st_name == 0) {
1306 if (verb) fprintf ( stderr, "(noname) ");
1307 /* nameless (local) symbol */
1308 S = (Elf32_Addr)(ehdrC
1309 + shdr[stab[ELF32_R_SYM(info)].st_shndx ].sh_offset
1310 + stab[ELF32_R_SYM(info)].st_value
1312 strcpy ( symbol, "(noname)");
1314 strcpy ( symbol, strtab+stab[ ELF32_R_SYM(info)].st_name );
1315 if (verb) fprintf ( stderr, "`%s' ", symbol );
1316 S = (Elf32_Addr)lookupObjName ( symbol );
1318 if (verb) fprintf ( stderr, "resolves to %p\n", (void*)S );
1320 fprintf ( stderr, "link failure for `%s'\n",
1321 strtab+stab[ ELF32_R_SYM(info)].st_name );
1325 //fprintf ( stderr, "Reloc: P = %p S = %p A = %p\n\n",
1326 // (void*)P, (void*)S, (void*)A );
1327 switch (ELF32_R_TYPE(info)) {
1328 case R_386_32: *pP = S + A; break;
1329 case R_386_PC32: *pP = S + A - P; break;
1330 default: fprintf(stderr,
1331 "unhandled ELF relocation type %d\n",
1332 ELF32_R_TYPE(info));
1339 if (shdr[i].sh_type == SHT_RELA) {
1340 fprintf ( stderr, "RelA style reloc table -- not yet done" );
1347 static Bool local validateOImage_elf ( void* imgV,
1353 int i, j, nent, nstrtab, nsymtabs;
1357 char* ehdrC = (char*)imgV;
1358 Elf32_Ehdr* ehdr = ( Elf32_Ehdr*)ehdrC;
1360 if (ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
1361 ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
1362 ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
1363 ehdr->e_ident[EI_MAG3] != ELFMAG3) {
1364 if (verb) fprintf ( stderr, "Not an ELF header\n" );
1367 if (verb) fprintf ( stderr, "Is an ELF header\n" );
1369 if (ehdr->e_ident[EI_CLASS] != ELFCLASS32) {
1370 if (verb) fprintf ( stderr, "Not 32 bit ELF\n" );
1373 if (verb) fprintf ( stderr, "Is 32 bit ELF\n" );
1375 if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB) {
1376 if (verb) fprintf ( stderr, "Is little-endian\n" );
1378 if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB) {
1379 if (verb) fprintf ( stderr, "Is big-endian\n" );
1381 if (verb) fprintf ( stderr, "Unknown endiannness\n" );
1385 if (ehdr->e_type != ET_REL) {
1386 if (verb) fprintf ( stderr, "Not a relocatable object (.o) file\n" );
1389 if (verb) fprintf ( stderr, "Is a relocatable object (.o) file\n" );
1391 if (verb) fprintf ( stderr, "Architecture is " );
1392 switch (ehdr->e_machine) {
1393 case EM_386: if (verb) fprintf ( stderr, "x86\n" ); break;
1394 case EM_SPARC: if (verb) fprintf ( stderr, "sparc\n" ); break;
1395 default: if (verb) fprintf ( stderr, "unknown\n" ); return FALSE;
1400 "\nSection header table: start %d, n_entries %d, ent_size %d\n",
1401 ehdr->e_shoff, ehdr->e_shnum, ehdr->e_shentsize );
1403 assert (ehdr->e_shentsize == sizeof(Elf32_Shdr));
1405 shdr = (Elf32_Shdr*) (ehdrC + ehdr->e_shoff);
1407 if (ehdr->e_shstrndx == SHN_UNDEF) {
1408 if (verb) fprintf ( stderr, "No section header string table\n" );
1412 if (verb) fprintf ( stderr,"Section header string table is section %d\n",
1414 sh_strtab = ehdrC + shdr[ehdr->e_shstrndx].sh_offset;
1417 for (i = 0; i < ehdr->e_shnum; i++) {
1418 if (verb) fprintf ( stderr, "%2d: ", i );
1419 if (verb) fprintf ( stderr, "type=%2d ", shdr[i].sh_type );
1420 if (verb) fprintf ( stderr, "size=%4d ", shdr[i].sh_size );
1421 if (verb) fprintf ( stderr, "offs=%4d ", shdr[i].sh_offset );
1422 if (verb) fprintf ( stderr, " (%p .. %p) ",
1423 ehdrC + shdr[i].sh_offset,
1424 ehdrC + shdr[i].sh_offset + shdr[i].sh_size - 1);
1426 if (shdr[i].sh_type == SHT_REL && verb) fprintf ( stderr, "Rel " ); else
1427 if (shdr[i].sh_type == SHT_RELA && verb) fprintf ( stderr, "RelA " ); else
1428 if (verb) fprintf ( stderr, " " );
1429 if (sh_strtab && verb)
1430 fprintf ( stderr, "sname=%s", sh_strtab + shdr[i].sh_name );
1431 if (verb) fprintf ( stderr, "\n" );
1434 if (verb) fprintf ( stderr, "\n\nString tables\n" );
1437 for (i = 0; i < ehdr->e_shnum; i++) {
1438 if (shdr[i].sh_type == SHT_STRTAB &&
1439 i != ehdr->e_shstrndx) {
1441 fprintf ( stderr, " section %d is a normal string table\n", i );
1442 strtab = ehdrC + shdr[i].sh_offset;
1447 if (verb) fprintf ( stderr, "WARNING: no string tables, or too many\n" );
1452 if (verb) fprintf ( stderr, "\n\nSymbol tables\n" );
1453 for (i = 0; i < ehdr->e_shnum; i++) {
1454 if (shdr[i].sh_type != SHT_SYMTAB) continue;
1455 if (verb) fprintf ( stderr, "section %d is a symbol table\n", i );
1457 stab = (Elf32_Sym*) (ehdrC + shdr[i].sh_offset);
1458 nent = shdr[i].sh_size / sizeof(Elf32_Sym);
1459 if (verb) fprintf ( stderr, " number of entries is apparently %d (%d rem)\n",
1461 shdr[i].sh_size % sizeof(Elf32_Sym)
1463 if (0 != shdr[i].sh_size % sizeof(Elf32_Sym)) {
1464 if (verb) fprintf ( stderr, "non-integral number of symbol table entries\n");
1467 for (j = 0; j < nent; j++) {
1468 if (verb) fprintf ( stderr, " %2d ", j );
1469 if (verb) fprintf ( stderr, " sec=%-5d size=%-3d val=%-5p ",
1470 (int)stab[j].st_shndx,
1471 (int)stab[j].st_size,
1472 (char*)stab[j].st_value );
1474 if (verb) fprintf ( stderr, "type=" );
1475 switch (ELF32_ST_TYPE(stab[j].st_info)) {
1476 case STT_NOTYPE: if (verb) fprintf ( stderr, "notype " ); break;
1477 case STT_OBJECT: if (verb) fprintf ( stderr, "object " ); break;
1478 case STT_FUNC : if (verb) fprintf ( stderr, "func " ); break;
1479 case STT_SECTION: if (verb) fprintf ( stderr, "section" ); break;
1480 case STT_FILE: if (verb) fprintf ( stderr, "file " ); break;
1481 default: if (verb) fprintf ( stderr, "? " ); break;
1483 if (verb) fprintf ( stderr, " " );
1485 if (verb) fprintf ( stderr, "bind=" );
1486 switch (ELF32_ST_BIND(stab[j].st_info)) {
1487 case STB_LOCAL : if (verb) fprintf ( stderr, "local " ); break;
1488 case STB_GLOBAL: if (verb) fprintf ( stderr, "global" ); break;
1489 case STB_WEAK : if (verb) fprintf ( stderr, "weak " ); break;
1490 default: if (verb) fprintf ( stderr, "? " ); break;
1492 if (verb) fprintf ( stderr, " " );
1494 if (verb) fprintf ( stderr, "name=%s\n", strtab + stab[j].st_name );
1498 if (nsymtabs == 0) {
1499 if (verb) fprintf ( stderr, "Didn't find any symbol tables\n" );
1507 static void readSyms_elf ( Module m, Bool verb )
1512 char* ehdrC = (char*)(module(m).oImage);
1513 Elf32_Ehdr* ehdr = (Elf32_Ehdr*)ehdrC;
1514 char* strtab = findElfSection ( ehdrC, SHT_STRTAB );
1515 Elf32_Shdr* shdr = (Elf32_Shdr*) (ehdrC + ehdr->e_shoff);
1516 char* sh_strtab = ehdrC + shdr[ehdr->e_shstrndx].sh_offset;
1518 if (!strtab) internal("readSyms_elf");
1521 for (i = 0; i < ehdr->e_shnum; i++) {
1523 /* make a HugsDLSection entry for relevant sections */
1524 DLSect kind = HUGS_DL_SECTION_OTHER;
1525 if (0==strcmp(".data",sh_strtab+shdr[i].sh_name) ||
1526 0==strcmp(".data1",sh_strtab+shdr[i].sh_name))
1527 kind = HUGS_DL_SECTION_RWDATA;
1528 if (0==strcmp(".text",sh_strtab+shdr[i].sh_name) ||
1529 0==strcmp(".rodata",sh_strtab+shdr[i].sh_name) ||
1530 0==strcmp(".rodata1",sh_strtab+shdr[i].sh_name))
1531 kind = HUGS_DL_SECTION_CODE_OR_RODATA;
1532 if (kind != HUGS_DL_SECTION_OTHER)
1535 ehdrC + shdr[i].sh_offset,
1536 ehdrC + shdr[i].sh_offset + shdr[i].sh_size - 1,
1540 if (shdr[i].sh_type != SHT_SYMTAB) continue;
1542 /* copy stuff into this module's object symbol table */
1543 stab = (Elf32_Sym*) (ehdrC + shdr[i].sh_offset);
1544 nent = shdr[i].sh_size / sizeof(Elf32_Sym);
1545 for (j = 0; j < nent; j++) {
1546 if ( ( ELF32_ST_BIND(stab[j].st_info)==STB_GLOBAL ||
1547 ELF32_ST_BIND(stab[j].st_info)==STB_LOCAL
1550 ( ELF32_ST_TYPE(stab[j].st_info)==STT_FUNC ||
1551 ELF32_ST_TYPE(stab[j].st_info)==STT_OBJECT )
1553 char* nm = strtab + stab[j].st_name;
1555 + shdr[ stab[j].st_shndx ].sh_offset
1560 fprintf(stderr, "addOTabName: %10p %s %s\n",
1561 ad, textToStr(module(m).text), nm );
1562 addOTabName ( m, nm, ad );
1569 #endif /* defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) */
1572 /* --------------------------------------------------------------------------
1573 * Arch-independent interface to the runtime linker
1574 * ------------------------------------------------------------------------*/
1576 static Bool local validateOImage ( void* img, Int size, Bool verb )
1578 #if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS)
1580 validateOImage_elf ( img, size, verb );
1582 internal("validateOImage: not implemented on this platform");
1587 static Void local resolveReferencesInObjectModule ( Module m, Bool verb )
1589 #if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS)
1590 resolveReferencesInObjectModule_elf ( m, verb );
1592 internal("resolveReferencesInObjectModule: not implemented on this platform");
1597 static Void local readSyms ( Module m, Bool verb )
1599 #if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS)
1600 readSyms_elf ( m, verb );
1602 internal("readSyms: not implemented on this platform");
1607 /* --------------------------------------------------------------------------
1608 * General object symbol query stuff
1609 * ------------------------------------------------------------------------*/
1611 /* entirely bogus claims about types of these symbols */
1612 extern int stg_gc_enter_1;
1613 extern int stg_chk_0;
1614 extern int stg_chk_1;
1615 extern int stg_update_PAP;
1616 extern int __ap_2_upd_info;
1617 extern int MainRegTable;
1618 extern int Upd_frame_info;
1622 { "stg_gc_enter_1", &stg_gc_enter_1 },
1623 { "stg_chk_0", &stg_chk_0 },
1624 { "stg_chk_1", &stg_chk_1 },
1625 { "stg_update_PAP", &stg_update_PAP },
1626 { "__ap_2_upd_info", &__ap_2_upd_info },
1627 { "MainRegTable", &MainRegTable },
1628 { "Upd_frame_info", &Upd_frame_info },
1633 void* lookupObjName ( char* nm )
1643 strncpy(nm2,nm,200);
1645 // first see if it's an RTS name
1646 for (k = 0; rtsTab[k].nm; k++)
1647 if (0==strcmp(nm2,rtsTab[k].nm))
1648 return rtsTab[k].ad;
1650 // if not an RTS name, look in the
1651 // relevant module's object symbol table
1652 pp = strchr(nm2, '_');
1653 if (!pp) goto not_found;
1655 t = unZcodeThenFindText(nm2);
1657 if (isNull(m)) goto not_found;
1658 a = lookupOTabName ( m, nm );
1663 "lookupObjName: can't resolve name `%s'\n",
1669 int is_dynamically_loaded_code_or_rodata_ptr ( char* p )
1672 lookupDLSect(p) == HUGS_DL_SECTION_CODE_OR_RODATA;
1676 int is_dynamically_loaded_rwdata_ptr ( char* p )
1679 lookupDLSect(p) == HUGS_DL_SECTION_RWDATA;
1683 int is_not_dynamically_loaded_ptr ( char* p )
1686 lookupDLSect(p) == HUGS_DL_SECTION_OTHER;
1690 /* --------------------------------------------------------------------------
1692 * ------------------------------------------------------------------------*/
1694 Void interface(what)
1701 ghcConstrDecls = NIL;
1702 ghcSynonymDecls = NIL;
1703 ghcClassDecls = NIL;
1704 ghcInstanceDecls = NIL;
1712 mark(ghcConstrDecls);
1713 mark(ghcSynonymDecls);
1714 mark(ghcClassDecls);
1715 mark(ghcInstanceDecls);
1723 /*-------------------------------------------------------------------------*/