[Vm-dev] CCodeGenerator>>emitCHeaderOn:

David T. Lewis lewis at mail.msen.com
Thu Mar 11 04:12:32 UTC 2010


On Wed, Mar 10, 2010 at 12:02:58AM -0800, Andreas Raab wrote:
> 
> I'd like to propose to REMOVE the inline definition of void error(char*) 
> from CCodeGenerator>>emitCHeaderOn:.
> 
> Rationale:
> Allow the support code to handle fatal errors and provide proper 
> feedback. Currently a fatal error will cause the VM to silently quit 
> instead of telling the user that a fatal error happened. It also 
> prevents gathering additional information that the VM could other 
> provide (such as the crash.dmp on Windows).

Andreas,

Attached is a patch for VMMaker that should enable a replacement
error() function without requiring updates to existing platform
support code (RiscOS, unix, etc).

You can implement the replacement error() function in platform
code, e.g. win32ErrorProc(char *), then:
   '#define error(str) win32ErrorProc(str)'
in the platforms/win32/vm/config.h header file.

If this approach makes sense, I'll add it to VMMaker.

Note, I have not built a win32 VM with this, so mistakes are
possible.

Cheers,
Dave

-------------- next part --------------
'From Squeak3.11alpha of 8 March 2010 [latest update: #9639] on 10 March 2010 at 10:48:10 pm'!
"Change Set:		Interpreter-defaultErrorProc-dtl
Date:			10 March 2010
Author:			David T. Lewis

The error() function called from Interpreter was generated in line by CCodeGenerator>>emitCHeaderOn. Change this to permit support code to implement better error handlers.

Changes are:
  - Rename error() as defaultErrorProc().
  - Add CPP macro in generated vm/interp.h to define error() as defaultErrorProc() by default.

Replacement error() function may be implemented in platform support code, e.g. win32ErrorProc(char *), then '#define error(str) win32ErrorProc(str)' in platforms/win32/vm/config.h header file.
"!


!CCodeGenerator methodsFor: 'C code generator' stamp: 'dtl 3/10/2010 22:14'!
emitCHeaderOn: aStream
	"Write a C file header onto the given stream."

	aStream nextPutAll: '/* '.
	aStream nextPutAll: VMMaker headerNotice.
	aStream nextPutAll: ' */'; cr; cr.
	self emitGlobalStructFlagOn: aStream.
	aStream nextPutAll: '#include "sq.h"'; cr.

	"Additional header files"
	headerFiles do:[:hdr|
		aStream nextPutAll:'#include '; nextPutAll: hdr; cr].

	aStream nextPutAll: '
#include "sqMemoryAccess.h"

sqInt printCallStack(void);
void defaultErrorProc(char *s) {
	/* Print an error message and exit. */
	static sqInt printingStack = false;

	printf("\n%s\n\n", s);
	if (!!printingStack) {
		/* flag prevents recursive error when trying to print a broken stack */
		printingStack = true;
		printCallStack();
	}
	exit(-1);
}
'.
	aStream cr.! !

!CCodeGenerator methodsFor: 'C code generator' stamp: 'dtl 3/10/2010 22:13'!
writeDefaultMacrosOn: aStream
	"Write macros to provide default implementations of certain functions used by
	the interpreter. If not previously defined in config.h they will be defined here.
	The definitions will be available to any module that includes sqMemoryAccess.h.
	The default macros are chosen for backward compatibility with existing platform
	support code."

	aStream cr;
		nextPutAll: '#ifndef allocateMemoryMinimumImageFileHeaderSize'; cr;
		nextPutAll: ' /* Called by Interpreter>>allocateMemory:minimum:imageFile:headerSize: */'; cr;
		nextPutAll: ' /* Default definition if not previously set in config.h */'; cr;
		nextPutAll: ' #define allocateMemoryMinimumImageFileHeaderSize(',
						'heapSize, minimumMemory, fileStream, headerSize) \'; cr;
		nextPutAll: '    sqAllocateMemory(minimumMemory, heapSize)'; cr;
		nextPutAll: '#endif'; cr; cr;

		nextPutAll: '#ifndef sqImageFileReadEntireImage'; cr;
		nextPutAll: ' /* Called by Interpreter>>sqImage:read:size:length: */'; cr;
		nextPutAll: ' /* Default definition if not previously set in config.h */'; cr;
		nextPutAll: ' #define sqImageFileReadEntireImage(memoryAddress, ',
						'elementSize,  length, fileStream) \'; cr;
		nextPutAll: '    sqImageFileRead(memoryAddress, elementSize,  length, fileStream)'; cr;
		nextPutAll: '#endif'; cr; cr;

		nextPutAll: '#ifndef error'; cr;
		nextPutAll: ' /* error() function called from Interpreter */'; cr;
		nextPutAll: ' /* Default definition if not previously set in config.h */'; cr;
		nextPutAll: ' #define error(str) defaultErrorProc(str)'; cr;
		nextPutAll: '#endif'; cr; cr

! !



More information about the Vm-dev mailing list