how to specify CIL_MACHINE for Apple M1 processsor? - apple-m1

Does anyone know what values to use when specifying CIL_MACHINE for Apple's M1 chip?
I have a start of a C program which outputs most of what I hope are the correct values, but I don't know how to find the commented-out values. Any help appreciated!
This page describes the format: https://people.eecs.berkeley.edu/~necula/cil/cil007.html
#include<stdio.h>
#ifdef __builtin_va_list
#define builtin_bool "true"
#else
#define builtin_bool "false"
#endif
#ifdef __thread
#define thread_keyword "true"
#else
#define thread_keyword "false"
#endif
#define underscore_name "true"
typedef int(*fn)(int,int);
fn func_pointer;
enum my_enum {Monday,Tuesday} my_enum;
int main(){
printf("bool=%lu,%lu ", sizeof(_Bool), __alignof(_Bool));
printf("short=%lu,%lu ",sizeof(short),__alignof(short));
printf("int=%lu,%lu ",sizeof(int),__alignof(int));
printf("long=%lu,%lu ", sizeof(long),__alignof(long));
printf("long_long=%lu,%lu ",sizeof(long long),__alignof(long long));
printf("float=%lu,%lu ",sizeof(float),__alignof(float));
printf("double=%lu,%lu ",sizeof(double),__alignof(double));
printf("long_double=%lu,%lu ",sizeof(long double),__alignof(long double));
printf("pointer=%lu,%lu ",sizeof(void*),__alignof(void*));
printf("enum=%lu,%lu ",sizeof(my_enum),__alignof(my_enum));
printf("fun=%lu,%lu ",sizeof(func_pointer),__alignof(func_pointer));
printf("alignof_string=%lu ",__alignof("a string constant"));
/* printf("max_alignment=16? "); */
/* printf("size_t=%lu ",size_t); */
/* printf("wchar_t=%lu ",wchar_t); */
/* printf("char_signed=%lu,%lu ",true if char is signed); */
printf("big_endian=true ");
/* printf("const_string_literals=true "); */
printf("__thread_is_keyword=%s ", thread_keyword);
printf("__builtin_va_list=%s ", builtin_bool);
printf("underscore_name=%s ", underscore_name);
return 0;
}

Related

How can I guarantee one #define is larger than another?

#define MY_CONST 20
#define OTHER_CONST 10
My code only makes sense if MY_CONST > OTHER_CONST. How can I guarantee this with the preprocessor? Is there any command like this?
#assert MY_CONST < OTHER_CONST
Is there any command like this?
#assert MY_CONST < OTHER_CONST
#if OTHER_CONST >= MY_CONST
#error "Error, OTHER_CONST >= MY_CONST"
#endif
as #attersson said #if will do it.
(as a good habbit try to parenthesize your macros to guarantee order of evaluation for more complex expressions. this answer shows why.)
#include <stdio.h>
#define A 10
#define B 11
#if (A) > (B)
#define RES "yes"
#else
#define RES "no"
#endif
int
main(int argc, char *argv[])
{
printf("is A larger? %s\n", RES);
return 0;
}

arduino code compile issue trying to store serial data from certain lables as a variable

I am trying to build a code in arduino, and am having an issue with getting it to compile. I am trying to build a monitor for my MPPT controller, it outputs via serial. i am able to receive the serial data to the pc through the arduino, and am now having an issue getting it to save values from the incomming serial information and store its value as a variable that i can call to perform other functions.
the serial data incomming into the pc is always the same, and is formatted like this
PID 0xA042
FW 123
SER# HQ155154LPY
V 0
I 0
VPV 0
PPV 0
CS 0
ERR 0
LOAD OFF
IL 0
H19 4438
H20 0
H21 0
H22 38
H23 136
HSDS 74
Checksum
and i need the values from the following fields
V, I,VPV,PPV,LOAD,H19,IL
the information is sent from the controller like this
Message format
The device transmits blocks of data at 1 second intervals. Each field is sent using the following format:
<Newline><Field-Label><Tab><Field-Value>
The identifiers are defined as follows:
Identifier Meaning
<Newline> A carriage return followed by a line feed (0x0D, 0x0A).
<Field-Label> An arbitrary length label that identifies the field. Where applicable, this will be the same as the label that is used on the LCD.
<Tab> A horizontal tab (0x09).
<Field-Value> The ASCII formatted value of this field. The number of characters transmitted depends on the magnitude and sign of the value.
Data integrity
The statistics are grouped in blocks with a checksum appended. The last field in a block will always be "Checksum". The value is a single byte, and will not necessarily be a printable ASCII character. The modulo 256 sum of all bytes in a block will equal 0 if there were no transmission errors. Multiple blocks are sent containing different fields.
this is the first time i have actualy tried to use serial for something other than simple debug/operation messages running in the code.
the code
/*
Odroid-SHOW MPPT Intrface Module
Reads information from MPPT controllers and displays it on the LCD, also outputs the information via SERIAL # 9600 BAUD
* **********PINOUTS********
MPPT Controller:
________________________
| 4 3 2 1 |
| . . . . |
| VCC TX RX GND |
| (RED) (YEL)(WHI)(BLK) |
| _______ |
|_______| |________|
Odroid SHOW:
5V - To VCC (RED) Pin (4)
A4 - To TX (YEL) Pin (3)
A5 - To RX (WHI) Pin (2)
GND - To GND (BLK) Pin (1)
*/
const char version[] = {"1.0 27/04/2017"};
//Below is the required Library inclusions
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Wire.h>
#include "TimerOne.h"
#include <Adafruit_GFX.h>
#include <ODROID_Si1132.h>
#include <ODROID_Si70xx.h>
#include <Adafruit_ILI9340.h>
//Below is the required Pin Defines and links for the TFT
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
ODROID_Si70xx si7020;
ODROID_Si1132 si1132;
// Settings below are to control the Backlight brightness and rotation of the Odroid-SHOW LCD Display
uint8_t ledPin = 5;
uint8_t pwm = 255;
uint8_t textSize = 2;
uint8_t rotation = 1; //0 = Portrait, 1 = Landscape
//Below sets up the SoftwareSerial ports so that the arduino can receive information from the MPPT Controller aswell as pass its information through to the hardware UART
SoftwareSerial MPPTSERIAL(A4, A5); // RX, TX
void setup() {
// initialize the TFT and the digital pins for TFT backlight control
tft.begin();
si1132.begin();
initPins();
delay(50);
// Open serial communications on hardware UART and wait for port to open:
Serial.begin(9600);
delay(50);
//Below Prints the module Version information to both the Serial monitor and the TFT
Serial.println("Odroid-SHOW MPPT Intrface Module");
Serial.print("Module Firmware Version ");
Serial.println(version);
tft.fillScreen(ILI9340_BLACK);
tft.setRotation(rotation);
tft.setTextSize(textSize);
tft.setCursor(25, 25);
tft.print("Odroid-SHOW");
tft.setCursor(25, 45);
tft.print("MPPT Intrface Module");
tft.setCursor(25, 85);
tft.print("Module Firmware Version");
tft.setCursor(25, 105);
tft.print(version);
delay(2500);
// set the data rate for the SoftwareSerial port and print to TFT when initialized
MPPTSERIAL.begin(19200);
Serial.println("MPPT Serial Connection Initialized");
tft.setRotation(rotation);
tft.setTextSize(textSize);
tft.setCursor(25, 145);
tft.print("MPPT Serial");
tft.setCursor(25, 165);
tft.print("Connection Initialized");
delay(2500);
tft.fillScreen(ILI9340_BLACK);
}
void loop() {
if (MPPTSERIAL.available())
{
char inComing = MPPTSERIAL.read(); //read the available byte into a variable
String BattVoltage = getValue(inComing, "/n", 3).toString();
String PVCurrent = getValue(inComing, "/n", 4).toString();
String PVVoltage = getValue(inComing, "/n", 5).toString();
Serial.println(BattVoltage); //output the Battery Voltage to Serial Monitor
Serial.println(PVCurrent); //output the PV Charge Current to Serial Monitor
Serial.println(BattVoltage); //output the PV Voltage to Serial Monitor
tft.setRotation(rotation);
tft.setTextSize(textSize);
tft.setCursor(25, 25);
tft.print("Battery Voltage:")(BattVoltage); //output Battery Voltage to TFT
tft.setCursor(25, 145);
tft.print ("PV Current:")(PVCurrent); //output PV Charge Current to TFT
tft.setCursor(25, 165);
tft.print("PV Voltage:")(PVVoltage); //output PV Voltage to TFT
tft.fillScreen(ILI9340_BLACK);
}
if (Serial.available()) {
MPPTSERIAL.write(Serial.read());
}
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
//Below is the various Function Calls
//This is the Backlight PWM control pin settings
void initPins(){
pinMode(ledPin, OUTPUT);
analogWrite(ledPin, pwm);
}
The IDE highlights these lines as the source of the error
String BattVoltage = getValue(inComing, "/n", 3).toString();
String PVCurrent = getValue(inComing, "/n", 4).toString();
String PVVoltage = getValue(inComing, "/n", 5).toString();
and that is giving me this error
converting to 'String' from initializer list would use explicit constructor 'String::String(char)'
from what i can gather, i may need to change it from a srting to an INT or a CHAR, but all the examples i have tried and just guessed out of hope have failed.
any pointers?
Jason

Writing ttyUSB snooper failing

Summary: I am writing a ttyUSB snooper. The code is supposed to read(2) data from a serial port and write(2) it over to another serial port. Reading from the serial port works great with /bin/cat but fails with my code.
Hardware Setup is: I made an FTDI cross-over cable, and put one end in the Windows XP machine as Com2 and the other end in a modern Linux machine as /dev/ttyUSB0. The Linux machine has a USB to Serial cable that shows up as /dev/ttyUSB1. It is connected to the actual hardware unit I am trying to snoop. I verified, the hardware works great.
This part works: I will "cat /dev/ttyUSB0 > /tmp/data" and then have the WinXP machine issue the "read from the device over Com2", and the following six (6) bytes data will be sent over.
\x02\x01\x40\x00\x0a\x9e
This "packet" is sent 4 times or so with a very slight delay, this appears to be the WinXP code just trying a few times. If I replay this just once, it works.
If I simply do "cat /tmp/data > /dev/ttyUSB1", the hardware device will respond properly suggesting that it received the command. Great!
Problem and My Code: I am writing some code to be run on the Linux machine that will read(2) from /dev/ttyUSB0 and write it over to /dev/ttyUSB1 and vice versa. However, for some unknown reason it will only receive 4 bytes in the first "packet", then 5 in the subsequent 3 attempts. Sometimes, the 5 bytes appear slightly "damaged", meaning I see \xffffff for the last or second to last byte. Here is my code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <strings.h>
void hexdump(char *data, int size) {
for (size_t i = 0; i < size; ++i)
printf("%02x ", data[i]);
putchar('\n');
}
int main() {
int fdzero;
int fdone;
int maxfd;
fd_set sockrd;
struct timeval timer;
char data[10];
int size;
char tmp;
fdzero = open("/dev/ttyUSB0", O_RDWR);
if (fdzero == -1) {
perror("Failed to open /dev/ttyUSB0");
return 1;
}
fdone = open("/dev/ttyUSB1", O_RDWR);
if (fdone == -1) {
perror("Failed to open /dev/ttyUSB1");
return 1;
}
if (fdzero > fdone)
maxfd = fdzero;
else
maxfd = fdone;
printf("Enter loop\n");
for(;;) {
bzero(data, 10);
// fflush(NULL);
FD_ZERO(&sockrd);
FD_SET(fdzero, &sockrd);
FD_SET(fdone, &sockrd);
timer.tv_sec = 60;
timer.tv_usec = 0;
select(maxfd+1, &sockrd, NULL, NULL, &timer);
if (FD_ISSET(fdzero, &sockrd)) {
size = read(fdzero, data, 10);
if (size == -1) {
perror("Failed to read /dev/ttyUSB0");
break;
}
size = write(fdone, data, size);
if (size == -1) {
perror("Failed to write to /dev/ttyUSB1");
break;
}
printf("ttyUSB0 -> ttyUSB1: %d\n", size);
}
// This portion does not trigger yet, but its a mirror
// Yes, I know...bad code :(
else {
size = read(fdone, data, 10);
if (size == -1) {
perror("Failed to read /dev/ttyUSB1");
break;
}
size = write(fdzero, data, size);
if (size == -1) {
perror("Failed to write to /dev/ttyUSB0");
break;
}
printf("ttyUSB1 -> ttyUSB0: %d\n", size);
}
// Used to monitor what is read()/write()
hexdump(data, size);
}
return 0;
}
When I actually run this code, I see this:
# cc snoop.c -o snoop
# ./snoop
Enter loop
ttyUSB0 -> ttyUSB1: 4
02 00 40 ffffff9e
ttyUSB0 -> ttyUSB1: 4
02 00 40 ffffff9e
ttyUSB0 -> ttyUSB1: 4
02 00 40 ffffff9e
ttyUSB0 -> ttyUSB1: 5
01 02 00 40 ffffff9e
ttyUSB0 -> ttyUSB1: 5
01 02 00 40 ffffff9e
ttyUSB0 -> ttyUSB1: 5
01 02 00 40 ffffff9e
Notice that only 4 or 5 bytes are being received and subsequently sent over at any given time. Not 6. Also, notice that the "packet" is distorted. What in the world would cause that???
Rationality if you're interested: I have old software that ONLY runs on Windows XP and will NOT work in a VM (this is a known issue). I would love to capture the traffic going over the serial port. I purchased a WinXP machine just to do this.
Okay, so your two questions here:
Sometimes, the 5 bytes appear slightly "damaged", meaning I see \xffffff for the last or second to last byte.
This is because of how printf interprets the data coming in(this may be of interest). It is being passed in as a char, which is signed. The high-order bits are being interpreted in this case. To fix this part, your hexdump(char* data, int len) should be either hexdump(unsigned char* data, int len) or use a byte-sized type such as uint8_t, so that your signature looks like hexdump(uint8_t* data, int len).
However, for some unknown reason it will only receive 4 bytes in the first "packet", then 5 in the subsequent 3 attempts.
This is almost certainly due to the fact that you do not set any settings on the serial port. One of the characters that you have is 0x0A, which is the linefeed character. This is either being ignored by the serial port driver, or translated into a different character all together. To fix this, you must set the serial port settings to be raw and not translate any characters that come in. I generally do something like the following:
struct termios newio;
if( tcgetattr( fd, &newio ) < 0 ){ /* error handling here */ }
/* Set some default settings */
newio.c_iflag |= IGNBRK;
newio.c_iflag &= ~BRKINT;
newio.c_iflag &= ~ICRNL;
newio.c_oflag = 0;
newio.c_lflag = 0;
newio.c_cc[VTIME] = 0;
newio.c_cc[VMIN] = 1;
/* Set our baud rate */
cfsetospeed( &newio, B9600 );
cfsetispeed( &newio, B9600 );
/* Character size = 8 */
newio.c_cflag &= ~CSIZE;
newio.c_cflag |= CS8;
/* One stop bit */
newio.c_cflag &= ~CSTOPB;
/* Parity = none */
newio.c_iflag &= ~IGNPAR;
newio.c_cflag &= ~( PARODD | PARENB );
newio.c_iflag |= IGNPAR;
/* No flow control */
newio.c_iflag &= ~( IXON | IXOFF | IXANY );
/* Set our serial port settings */
if( tcsetattr( fd, TCSANOW, &newio ) < 0 ) { /* error handling code here */ }
If you don't want to set the serial port settings this way, I've written a small library which should abstract the small details out for you.

Where is defined lispobj struct in SBCL sources

My question is self-explanatory. I'm grepping for ages and I can't find it ...
-------------------------------------------------------------------------------
lispobj is not a struct, just a typedef. It is defined in src/runtime/runtime.h currently after line 234:
#if 64 == N_WORD_BITS
#define LOW_WORD(c) ((pointer_sized_uint_t)c)
#define OBJ_FMTX "lx"
typedef uintptr_t lispobj;
#else
#define OBJ_FMTX "x"
#define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
/* fake it on alpha32 */
typedef unsigned int lispobj;
#endif

Use Inno Setup PreProcessor to get the files and size of the source path and its subdirs

Can I use Inno Setup PreProcessor to get the files and size of the source path and its subdirs?,
I am doing a Batch Compiler and I need the size to auto-set in [Setup] DiskSpanning True or False
Only can get the size of source,
Somebody can help me?
#define FindHandle
#define FindResult
#define Mask "*.*"
#define size 0
#define allfiles ""
#sub ProcessFoundFile
#define FileName FindGetFileName(FindHandle)
#if direxists(Filename) && Filename!="." && Filename!=".."
#Define Public Mask AddBackSlash(Filename)+"*.*"
#else
#Define Mask "*.*"
#endif
#define public allfiles allfiles + " - " +Filename
#define public size size + FileSize(FileName)
#endsub
#for {FindHandle = FindResult = FindFirst(Mask, faDirectory); FindResult; FindResult = FindNext(FindHandle)} ProcessFoundFile
#if FindHandle
; FindClose(FindHandle)
#endif
#IF Size > 2100000000
#DEFINE Span "True"
#ELSE
#DEFINE Span "False"
#ENDIF
[Setup]
DiskSpanning={#Span}
InternalCompressLevel=ultra
DiskClusterSize=2048
CompressionThreads=2
Compression=lzma2/ultra64
SolidCompression=no
Ok, so this is a bit old but I want to share my solution though because I came across the same problem and found some kind of a solution:
#define FindHandle
#define FindResult
#dim InnerMask[65536]
#define InnerMask[0] ""
#define size 0
#sub ProcessFoundFile
#define InnerFileName FindGetFileName(FindHandle)
#define fileName InnerMask[InnerMaskWorkPosition] + InnerFileName
#if InnerFileName!="." && InnerFileName!=".."
#if direxists(FileName)
#define Public InnerMask[InnerMaskPosition] FileName+"\"
#define Public InnerMaskPosition InnerMaskPosition + 1
#else
#define Public size size + FileSize(FileName)
#endif
#endif
#endsub
#sub ProcessInnerMaskPosition
#for {FindHandle = FindResult = FindFirst(InnerMask[InnerMaskWorkPosition]+"*", faAnyFile); FindResult; FindResult = FindNext(FindHandle)} ProcessFoundFile
#if FindHandle
#expr FindClose(FindHandle)
#endif
#endsub
#sub RunSizeScan
#define Public InnerMaskPosition 1
#define Public InnerMaskWorkPosition 0
#expr size=0
#for {InnerMaskWorkPosition = 0; InnerMaskWorkPosition < InnerMaskPosition; InnerMaskWorkPosition++} ProcessInnerMaskPosition
#undef Public InnerMaskPosition
#undef Public InnerMaskWorkPosition
#endsub
#expr InnerMask[0]="some-dir-name-you-want-the-size-of\"
#expr RunSizeScan
#if size > 2100000000
#define Span "True"
#else
#define Span "False"
#endif
What it does is to scan the given directories in the array "InnerMask" for everything which isn't "." or "..". Files are added to the already calculated size and directories are added to the array "InnerMask". This Process will end once there are no more subdirectories to evaluate.
Note: As the limitation of the array is set to 65536, you should not have more than this amount of folders nested in you scanned directory. Otherwise you could try to reuse the first already processed array slots or work with multiple arrays.
Here's the recursive version, broken into several macros for readability:
#define private CalcDirSize(str path, int size = 0) \
CalcFileSize(path, FindFirst(AddBackSlash(path) + '*.*', faAnyFile), size)
#define private CalcFileSize(str path, int handle, int size) \
handle ? CalcFileSizeFilterPath(path, handle, size) : size
#define private CalcFileSizeFilterPath(str path, int handle, int size) \
FindGetFilename(handle) == '.' || FindGetFilename(handle) == '..' ? \
GoToNextFile(path, handle, size) : \
CalcFileSizeTestIfDir(path, handle, size, AddBackSlash(path) + FindGetFilename(handle))
#define private GoToNextFile(str path, int handle, int size) \
FindNext(handle) ? CalcFileSizeFilterPath(path, handle, size) : size
#define private CalcFileSizeTestIfDir(str path, int handle, int size, str filename) \
DirExists(filename) ? CalcDirSize(filename) + GoToNextFile(path, handle, size) : \
GoToNextFile(path, handle, size + FileSize(filename))
Doesn't support too many files (poor ISPP will run out of memory) or large sizes (>2gb), but it should work well for smaller setups.

Resources