[M3devel] representing word size in IR target-independently?

Jay K jay.krell at cornell.edu
Sat Jul 18 10:48:09 CEST 2015

 Ideally there would be one target-independent IR for, for example: 

 VAR a := BYTESIZE(INTEGER);   VAR b := BITSIZE(INTEGER) = 64;   TYPE T1 = RECORD a,b:INTEGER END;   CONST pt1: REF T1 = NIL;   VAR offset_of_b := LOOPHOLE(INTEGER, ADR(pt1.b));  

 so that it could be translated to target-independent C something like: 

 #if ...almost always true...   typedef ptrdiff_t INTEGER;  #else  ...  #endif   INTEGER a = sizeof(INTEGER);  typedef unsigned char BOOLEAN;   BOOLEAN b = (sizeof(INTEGER) * 8) == 64;   typedef struct { a,b:INTEGER; } T1;  T1* pt1;  // ideal but unlikely:  INTEGER offset_of_b = offsetof(T1, b);  // more likely:   INTEGER offset_of_b;  void module_initializer()  {    offset_of_b = (INTEGER)&pt1->b;  } 
Is this feasible?

 Can instances of "INTEGER" somehow be left higher level for resolution  by the backend? Or can they be left "dual", both "resolved" and "symbolic"?  Or would this require too much change?
 I would be very reluctantly satisfied if the frontend ran  a certain portion of itself twice, once for each word size, indicating  the start/end of the passes to the backend, so the generated C would  be doubled up with an #if something like: 

#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) ...
 ... everything ... 
 #else // 32 bit 
 ... everything ... 

The agenda is target-independent C output from the C backend,as a portable redistributable form.This is approximately one of the three problems to solve to achieve that.

Thanks, - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20150718/68359d67/attachment-0001.html>

More information about the M3devel mailing list