[m-rev.] uncommitted diff: find the sha1 hash of an assembly.

Peter Ross peter.ross at miscrit.be
Tue Aug 14 22:18:37 AEST 2001


Hi,

I won't commit this because it doesn't work, but the assembly_hash
executable might come in handy later.

===================================================================


Estimated hours taken: 4
Branches: main

compiler/ilasm.m:
util/Mmakefile:
util/assembly_hash.cs:
    Attempt to output .hash decls for .file decls.


Index: compiler/ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.19
diff -u -r1.19 ilasm.m
--- compiler/ilasm.m	13 Aug 2001 01:39:31 -0000	1.19
+++ compiler/ilasm.m	14 Aug 2001 12:15:40 -0000
@@ -432,7 +432,17 @@
 
 ilasm__output_decl(file(FileName), Info, Info) --> 
 	io__write_string(".file "),
-	output_id(FileName).
+	output_id(FileName),
+	get_hash_token(FileName, Result),
+	( { Result = ok(AssemblyDecl) },
+		io__write_string("\t"),
+		output_assembly_decl(AssemblyDecl),
+		io__nl
+	; { Result = error(String) },
+		io__write_string("Error: " ++ String),
+		io__set_exit_status(1),
+		io__nl
+	).
 
 ilasm__output_decl(extern_module(ModName), Info, Info) --> 
 	io__write_string(".module extern "),
@@ -1636,5 +1646,37 @@
 escape_special_char('\b', 'b').
 
 
+:- type result
+	--->	ok(assembly_decl)
+	;	error(string).
+
+:- import_module passes_aux.
+
+:- pred get_hash_token(string::in, ilasm__result::out,
+		io__state::di, io__state::uo) is det.
+
+get_hash_token(AssemblyName, Result) -->
+	io__make_temp(TmpFileName),
+	{ SystemCommand = "assembly_hash "
+			++ AssemblyName ++ " > " ++ TmpFileName },
+	invoke_shell_command(SystemCommand, _Succeeded),
+	io__see(TmpFileName, SeeResult),
+	( { SeeResult = ok },
+		io__read(AssemblyDeclResult),
+		{ AssemblyDeclResult = ok(AssemblyDecl),
+			Result = ok(AssemblyDecl)
+		; AssemblyDeclResult = eof,
+			Result = error("Unexpected eof while reading "
+					++ TmpFileName)
+		; AssemblyDeclResult = error(Msg, _),
+			Result = error("While reading " ++ TmpFileName ++
+					": " ++ Msg)
+		},
+		io__seen
+	; { SeeResult = error(_Error) },
+		{ Result = error("Error: Unable to open hash token file : " ++
+				TmpFileName) }
+	),
+	io__remove_file(TmpFileName, _).
 
 :- end_module ilasm.
Index: util/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/util/Mmakefile,v
retrieving revision 1.13
diff -u -r1.13 Mmakefile
--- util/Mmakefile	5 Jun 2001 13:25:55 -0000	1.13
+++ util/Mmakefile	14 Aug 2001 12:15:46 -0000
@@ -20,10 +20,19 @@
 # we need -I ../runtime for "mercury_std.h", etc.
 # the -O0 is to get around a stupid compiler bug in gcc 2.7.2.3 on cyclone
 
-PROGS=mkinit mdemangle info_to_mdb
+CPROGS=mkinit mdemangle info_to_mdb
+CSPROGS=assembly_hash
+
+ifeq ($(MS_ILASM), "")
+	PROGS= $(CPROGS)
+else
+	PROGS= $(CPROGS) $(CSPROGS)
+endif
+
 PROGFILENAMES=$(PROGS:%=%$(EXT_FOR_EXE))
 SRC=$(PROGS:%=%.c)
 
+
 GETOPT_SRC=$(RUNTIME_DIR)/GETOPT/getopt.c $(RUNTIME_DIR)/GETOPT/getopt1.c
 
 # mkinit.c needs `struct stat'
@@ -36,6 +45,9 @@
 .c:
 	$(MGNUC) $(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ $< $(GETOPT_SRC)
 
+.cs:
+	$(MS_CSC) $<
+
 tags:
 	ctags $(SRC)
 
@@ -48,7 +60,7 @@
 
 .PHONY: uninstall
 uninstall:
-	-cd $(INSTALL_BINDIR) && rm $(PROGS)
+	-cd $(INSTALL_BINDIR) && rm $(PROGFILENAMES)
 
 #-----------------------------------------------------------------------------#
 
Index: util/assembly_hash.cs
===================================================================
RCS file: util/assembly_hash.cs
diff -N util/assembly_hash.cs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ util/assembly_hash.cs	14 Aug 2001 12:15:46 -0000
@@ -0,0 +1,45 @@
+//---------------------------------------------------------------------------//
+//---------------------------------------------------------------------------//
+// Module:	sha1
+// Authors:	petdr
+//
+// Output the hash token which describes an assembly for consumption by
+// Mercury compiler.
+//---------------------------------------------------------------------------//
+//---------------------------------------------------------------------------//
+
+using System.Security.Policy;
+using System.Reflection;
+using System;
+
+public class sha1 {
+
+public static void Main(string[] args) {
+
+	if (args.Length != 1) {
+		Console.Write("Usage: sha1 <assembly name>\n");
+	}
+
+	Assembly asm = Assembly.LoadFrom(args[0]);
+	Hash h = new Hash(asm);
+
+	Console.Write("hash([");
+	WriteInt8(h.SHA1[0]);
+	for (int i = 1; i < h.SHA1.Length; i++) {
+		Console.Write(", ");
+		WriteInt8(h.SHA1[i]);
+	}
+	Console.Write("]).\n");
+}
+
+public static void WriteInt8(Byte b)
+{
+	Console.Write("int8(");
+	// Console.Write("0x");
+	// Console.Write(b.ToString("X"));
+	Console.Write(b);
+	Console.Write(")");
+}
+
+} // end of class
+// vim: ts=8 sw=8 noexpandtab

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list