Added custom builtin type always parsed as short

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Added custom builtin type always parsed as short

This post has NOT been accepted by the mailing list yet.

I'm trying to add custom integer width specifier, like short/long but with bitwidth of 1. What i managed so far is to implement a new keyword for it, and its properly tokenized as "bit", next i tried adding new builting type for it by trying to search for usages of unisgned long and unsigned short in source, and where ever i found usages i wrote code that would represent my type. Places i added my code is:

TokenKinds.def where i added new keyword that would represent my type, and added all cases for kw_bit in ParseDecl.cpp, ParseExpr.cpp, SemaDecl.cpp

Then i introduced new TSW_bit in enum Specifiers::TypeSpecifierWidth and cases in DeclSpec.cpp, and SemaType.cpp. one in SemaType sets Result to Context.BitTy.

Then i added UNISGNED_TYPE(Bit, BitTy) in BuiltinTypes.def, and introduced new CanQualType BitTy, and InitBuiltinType(BitTy, BuiltinType::Bit). then i added cases in ASTContext, SemaType and SemaDecl.

Added case to CodeGenTypes
   ResultType = llvm::Type::getInt1Ty(getLLVMContext());

Even hardcoded  width=1, align=1 in case in ASTContext, note that align is experimental, it should be 0 since MCU has bit addressable space of 2 bytes, so i should be able to store 16 of these bits inside that (stinking 8051 :D )

Problem i have is:
It parses, compiles without errors, but my new keyword is always parsed as short, no matter what i do, its always short in clang ast dump, and inside llvm IR its generated as i16 which is fine for short. I dont know what im missing. So if anyone have ideas or maybe some other approach  to make this type i would be very grateful. Sorry for the long post, but im trying to explain what i did best as i can.