+void FreeImport (Import* I)
+/* Free an import. NOTE: This won't remove the import from the exports table,
+ * so it may only be called for unused imports (imports from modules that
+ * aren't referenced).
+ */
+{
+ /* Safety */
+ PRECONDITION ((I->Flags & IMP_INLIST) == 0);
+
+ /* Free the struct */
+ xfree (I);
+}
+
+
+
+Import* ReadImport (FILE* F, ObjData* Obj)
+/* Read an import from a file and return it */
+{
+ Import* I;
+
+ /* Read the import address size */
+ unsigned char AddrSize = Read8 (F);
+
+ /* Create a new import */
+ I = NewImport (AddrSize, Obj);
+
+ /* Read the name */
+ I->Name = MakeGlobalStringId (Obj, ReadVar (F));
+
+ /* Read the file position */
+ ReadFilePos (F, &I->Pos);
+
+ /* Check the address size */
+ if (I->AddrSize == ADDR_SIZE_DEFAULT || I->AddrSize > ADDR_SIZE_LONG) {
+ /* Beware: This function may be called in cases where the object file
+ * is not read completely into memory. In this case, the file list is
+ * invalid. Be sure not to access it in this case.
+ */
+ if (ObjHasFiles (I->Obj)) {
+ Error ("Invalid import size in for `%s', imported from %s(%lu): 0x%02X",
+ GetString (I->Name),
+ GetSourceFileName (I->Obj, I->Pos.Name),
+ I->Pos.Line,
+ I->AddrSize);
+ } else {
+ Error ("Invalid import size in for `%s', imported from %s: 0x%02X",
+ GetString (I->Name),
+ GetObjFileName (I->Obj),
+ I->AddrSize);
+ }
+ }
+
+ /* Return the new import */
+ return I;
+}
+
+
+
+Import* GenImport (const char* Name, unsigned char AddrSize)
+/* Generate a new import with the given name and address size and return it */
+{
+ /* Create a new import */
+ Import* I = NewImport (AddrSize, 0);
+
+ /* Read the name */
+ I->Name = GetStringId (Name);
+
+ /* Check the address size */
+ if (I->AddrSize == ADDR_SIZE_DEFAULT || I->AddrSize > ADDR_SIZE_LONG) {
+ /* Beware: This function may be called in cases where the object file
+ * is not read completely into memory. In this case, the file list is
+ * invalid. Be sure not to access it in this case.
+ */
+ if (ObjHasFiles (I->Obj)) {
+ Error ("Invalid import size in for `%s', imported from %s(%lu): 0x%02X",
+ GetString (I->Name),
+ GetSourceFileName (I->Obj, I->Pos.Name),
+ I->Pos.Line,
+ I->AddrSize);
+ } else {
+ Error ("Invalid import size in for `%s', imported from %s: 0x%02X",
+ GetString (I->Name),
+ GetObjFileName (I->Obj),
+ I->AddrSize);
+ }
+ }
+
+ /* Return the new import */
+ return I;
+}
+
+
+