[Vm-dev] VM Maker: ImageFormat-dtl.42.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Jul 26 18:09:55 UTC 2020


David T. Lewis uploaded a new version of ImageFormat to project VM Maker:
http://source.squeak.org/VMMaker/ImageFormat-dtl.42.mcz

==================== Summary ====================

Name: ImageFormat-dtl.42
Author: dtl
Time: 26 July 2020, 2:09:13.1382 pm
UUID: 58998f37-e8f3-47a5-81c1-5f7e00cc5b5c
Ancestors: ImageFormat-eem.41

Suggestion from David Stes - Let the ckformat program print information about known version numbers. When run with no argument, print usage and help information. Also change the wording in format descriptions from 'Sista' to 'multiple bytecode sets' which is more wordy but techncally more accurate.

=============== Diff against ImageFormat-eem.41 ===============

Item was changed:
  ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') -----
  generateCkFormatProgram: programName on: stream
  	"Generate source code for an image format version reader. The program
  	is intended for testing image file format from a unix shell script such that
  	the shell script can decide what VM to run based on image requirements."
  
  	| formatNumber |
  	stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr;
  			nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr;
  			nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr;
  			nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr;
  			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr;
  			nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr;
  			nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr;
  			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr;
  			nextPutAll: '#include <stdio.h>'; cr;
  			nextPutAll: '#include <stdlib.h>'; cr;
  			nextPutAll: '#include <string.h>'; cr; cr;
  			nextPutAll: 'int main(int argc, char **argv) {'; cr;
  			tab; nextPutAll: 'FILE *f;'; cr;
  			tab; nextPutAll: 'unsigned char buf[8];'; cr;		
  			tab; nextPutAll: 'int formatNumber;'; cr;		
  			tab; nextPutAll: 'unsigned char c;'; cr;		
  			tab; nextPutAll: 'int match;'; cr;		
  			tab; nextPutAll: 'if (argc !!= 2) {'; cr;
  			tab; tab; nextPutAll: 'printf("usage: ', programName,  ' imageFileName\n");'; cr;
+ 			tab; tab; nextPutAll: 'printf("answer the image format number for an image file or 0 if not known\n");'; cr;
+ 			tab; tab; nextPutAll: 'printf("known image formats:\n");'; cr.
+ 	KnownVersionNumbers do: [ :e | | s |
+ 		s := String streamContents: [ :strm |
+ 			strm nextPutAll: e asString, ': '.
+ 			(self fromInteger: e) printDescriptionOn: strm withVersionNumber: false ].
+ 			stream tab; tab; nextPutAll: 'printf("', s, '\n");'; cr ].
+ 	stream
  			tab; tab; nextPutAll: 'exit(1);'; cr;
  			tab; nextPutAll: '}'; cr;
  			tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr;
  			tab; nextPutAll: 'if (f == NULL) {'; cr;
  			tab; tab; nextPutAll: 'perror(argv[1]);'; cr;
  			tab; tab; nextPutAll: 'exit(2);'; cr;
  			tab; nextPutAll: '}'; cr.
  	{ 0. 512 } do: [:offset |
  		stream
  			tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr;
  			tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr;
  			tab; tab; nextPutAll: 'exit(3);'; cr;
  			tab; nextPutAll: '}'; cr;
  			tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; cr;
  			tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr;
  			tab; tab; nextPutAll: 'exit(3);'; cr;
  			tab; nextPutAll: '}'; cr.
  		self versionNumberByteArrays withIndexDo: [ :v :tag | | b |
  			formatNumber := (self fromBytes: v) asInteger.
  			b := 'b_', formatNumber asString, '_', tag asString.
  			stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '.
  			v inject: true into: [:first : elem |
  				first ifFalse: [stream nextPutAll: ', '].
  				stream nextPutAll: elem asString.
  				false].
  			stream nextPutAll: '};'; cr;
  					tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr;
  					tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr;
  					tab; tab; nextPutAll: 'exit(0);'; cr;
  					tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]].
  	stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr;
  			tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr;
  			nextPutAll: '}'; cr
  !

Item was removed:
- ----- Method: ImageFormat class>>storeCkstatusOnFile: (in category 'ckformat') -----
- storeCkstatusOnFile: fileName
- 	"Deprecated 07-Dec-2012, use storeCkFormatOnFile:"
- 	^self storeCkFormatOnFile: fileName
- !

Item was changed:
  ----- Method: ImageFormat>>printDescriptionOn: (in category 'printing') -----
  printDescriptionOn: stream
  "
  The classic squeak image, aka V3, is 32-bit with magic 6502. The first 64-bit
  Squeak image was generated from V3 image made by Dan Ingalls and Ian Piumarta
  in 2005. Later, the magic code was changed to 68000.
  
  After full closure support came to Squeak, the magic code changed to 6504 for
  32-bit and 68002 for 64-bit images by setting a capability bit.
  
  Cog VM introduced a native order for floats under 6505 magic code.  Its
  corresponding 64b code would have been 68003 but no such image was produced.
  Older Interpreter VMs would simply load 6505 by flipping word order back.
  
  Cog VM also introduced a new object layout for 64-bit images called Spur layout
  under a new magic code - 68021. A few images were also generated with 68019,
  but this magic is now considered obsolete and deprecated.
  "
+ 	^ self printDescriptionOn: stream withVersionNumber: true.
- 	stream nextPutAll: 'a ';
- 		nextPutAll: (wordSize * 8) asString;
- 		nextPutAll: '-bit ';
- 		nextPutAll: (self requiresSpurSupport
- 			ifTrue: [ 'Spur' ]
- 			ifFalse: [ 'V3' ]);
- 		nextPutAll: ' image with '.
- 	self requiresClosureSupport ifFalse: [stream nextPutAll: 'no '].
- 	stream nextPutAll: 'closure support and '.
- 	self requiresNativeFloatWordOrder
- 		ifTrue: [stream nextPutAll: 'float words stored in native platform order']
- 		ifFalse: [stream nextPutAll: 'no native platform float word order requirement'].
- 	self requiresSpurSupport
- 		ifTrue: [stream nextPutAll: ' using Spur object format'.
- 			(self is64Bit and: [self requiresNewSpur64TagAssignment not])
- 				ifTrue: [stream nextPutAll: ' (obsolete)']].
- 	self requiresMultipleBytecodeSupport
- 		ifTrue: [ stream nextPutAll: ' and Sista ' ].
- 	stream nextPutAll: ' (';
- 		nextPutAll: self asInteger asString;
- 		nextPut: $).
- 	^ stream
  !

Item was added:
+ ----- Method: ImageFormat>>printDescriptionOn:withVersionNumber: (in category 'printing') -----
+ printDescriptionOn: stream withVersionNumber: aBoolean
+ "
+ The classic squeak image, aka V3, is 32-bit with magic 6502. The first 64-bit
+ Squeak image was generated from V3 image made by Dan Ingalls and Ian Piumarta
+ in 2005. Later, the magic code was changed to 68000.
+ 
+ After full closure support came to Squeak, the magic code changed to 6504 for
+ 32-bit and 68002 for 64-bit images by setting a capability bit.
+ 
+ Cog VM introduced a native order for floats under 6505 magic code.  Its
+ corresponding 64b code would have been 68003 but no such image was produced.
+ Older Interpreter VMs would simply load 6505 by flipping word order back.
+ 
+ Cog VM also introduced a new object layout for 64-bit images called Spur layout
+ under a new magic code - 68021. A few images were also generated with 68019,
+ but this magic is now considered obsolete and deprecated.
+ "
+ 	stream nextPutAll: 'a ';
+ 		nextPutAll: (wordSize * 8) asString;
+ 		nextPutAll: '-bit ';
+ 		nextPutAll: (self requiresSpurSupport
+ 			ifTrue: [ 'Spur' ]
+ 			ifFalse: [ 'V3' ]);
+ 		nextPutAll: ' image with '.
+ 	self requiresClosureSupport ifFalse: [stream nextPutAll: 'no '].
+ 	stream nextPutAll: 'closure support and '.
+ 	self requiresNativeFloatWordOrder
+ 		ifTrue: [stream nextPutAll: 'float words stored in native platform order']
+ 		ifFalse: [stream nextPutAll: 'no native platform float word order requirement'].
+ 	self requiresSpurSupport
+ 		ifTrue: [stream nextPutAll: ' using Spur object format'.
+ 			(self is64Bit and: [self requiresNewSpur64TagAssignment not])
+ 				ifTrue: [stream nextPutAll: ' (obsolete)']].
+ 	self requiresMultipleBytecodeSupport
+ 		ifTrue: [ stream nextPutAll: ' and multiple bytecode sets ' ].
+ 	aBoolean ifTrue: [
+ 		stream nextPutAll: ' (';
+ 			nextPutAll: self asInteger asString;
+ 			nextPut: $)].
+ 	^ stream
+ !



More information about the Vm-dev mailing list